Session 50: Ride chat #225

Closed
opened 2026-11-08 18:22:22 +00:00 by chris-kreidl · 0 comments
chris-kreidl commented 2026-11-08 18:22:22 +00:00 (Migrated from github.com)

50 · Ride chat

Phase: Adaptive coaching 1/5 (owner request 2026-11-08) · Branch: session/50-ride-chat · Depends on: 34

The coach's take on a ride is one-way. The owner wants a conversation: the coach asks what the numbers can't tell it (how hard it felt, why heart rate drifted, why the ride ran long), the athlete answers, and only at the end, by End chat, does one re-plan run with what was learned. No plan changes mid-chat. Session 51 then holds the post-ride re-plan until End chat; this session leaves the immediate ride_logged re-plan as it is.

Read first

  • docs/requirements.md → "Coaching dialogue and adaptability" (FR-19, and FR-20 to see what 51 adds), FR-8, FR-14, and "AI design" (ride feedback and the guardrails paragraph)
  • docs/decisions.md: the 2026-11-08 adaptive coaching entry, and the session 33, 34 and 39 entries on feedback and allowances
  • prisma/schema.prisma: CoachMessage, RideFeedback, Ride, ReplanTrigger, the PlanTrigger enum
  • src/server/coach-store.ts (getCoachThread, askCoach, historyOf, coachSays), src/server/coach.ts, src/ai/prompts/chat.ts
  • src/server/feedback-store.ts (comparisonFor, getRideFeedbackView, feedbackHeadlines), src/server/feedback-run.ts, src/ai/prompts/feedback.ts, src/domain/feedback/schema.ts
  • src/server/on-session-logged.ts, src/server/replan/triggers.ts, src/server/replan/input.ts, src/ai/prompts/replan.ts, src/domain/replan/triggers.ts
  • src/components/log/coach-take.tsx, the ride page route, src/components/today/unplanned-ride.tsx and Today's done-ride card, the coach chat sheet
  • Load the claude-api skill before touching src/ai/

Goal

  1. Questions in the take. RideFeedbackOutput gains questions (0–2 short questions). New prompt feedback-v3: ask only when the answer would change how the coach reads the ride or plans the next days. Examples: heart rate high for the power, a ride much longer or harder than planned, an unplanned ride whose kind the data can't settle (polo, a group ride with no power), a note that hints at pain. A clear ride gets none. Old rows parse with questions: []. Re-record the feedback fixtures.
  2. The ride's thread. CoachMessage.rideId (nullable, FK to Ride, cascade on delete; additive migration) and an index on (userId, rideId, createdAt). A ride chat's state lives on a small RideChat row (rideId unique, userId, endedAt?, createdAt) or an equally small shape you justify; it is created on the first reply. The take's questions show as the coach's opening lines (from the feedback row, not copied into messages).
  3. A chat turn. sendRideMessage(rideId, text): authed, Zod, ownership of the ride. Refused when the chat is ended or the ride has no take. One AI call, new task ride_chat with its own AI_MODEL_RIDE_CHAT/AI_EFFORT_RIDE_CHAT defaulting to the chat task's config, and a Developer panel row like the others. Input: the ride's comparison and take, the athlete's note on it, its thread, form before and after, the week's planned sessions, recent readiness, and the ride's day. Output: { reply } only, no patch. The prompt: plain and short; ask a follow-up when the answer is still unclear; never promise plan changes ("I'll take this into the plan when you end the chat" is fine); the athlete's text is data inside a delimited block, never instructions; medical red flags short-circuit as coach chat does. Counts against the athlete's allowance (userStarted). Takes no re-plan lock (it changes nothing).
  4. End chat. endRideChat(rideId): sets endedAt and enqueues one new trigger ride_chat (enum value, additive) whose detail names the ride and day. The thread becomes read-only. Ending an empty chat (no athlete message) is allowed and enqueues nothing.
  5. Re-plans and chat read ride chats. loadReplanInput adds each ride chat from the last 14 days (ended or not) beside its ride in <last_14_days>, as athlete data, delimited like notes, trimmed to a length cap. replan-v3 (or the next version) says how to weigh it: what the athlete says about how hard a ride felt, how they feel now, and their time this week outranks what the numbers suggest, inside the rules; a ride the athlete calls easy is no reason to strip planned quality. Coach chat's historyOf includes ride-chat messages, each tagged with its ride's day.
  6. Where it shows.
    • Ride page: under the coach's take, the questions, the thread, a reply box and End chat. Ended: the thread, read-only, with "Chat ended, plan updated" (or "nothing to change") from the run the trigger fed.
    • Today: the after-ride card (planned and unplanned) shows the take's first question when there is one, and a "Reply" link to the ride's chat.
    • Coach chat sheet: ride-chat messages in order, each with a small "about Sat's ride" tag linking to the ride.
    • Offline: replies need the network (an AI call); say so rather than queueing.

Rules

  • Every new server function uses authed, a Zod validator and userId filters; a ride and its messages are only ever the owner's.
  • Plans stay append-only. A chat turn writes messages only; the plan changes only through the End chat re-plan.
  • Replay fixtures for every new AI path; tests and e2e run with AI_REPLAY=1. Record with bun run ai:record and E2E_AI_RECORD=1.
  • Strength sessions get no chat (the owner plans to drop strength).

Tests

  • Domain/AI: RideFeedbackOutput with and without questions; old rows parse; the ride-chat output schema parses its fixtures; a red-flag message short-circuits.
  • DB: a reply creates the RideChat and both messages; another user's ride is refused; a reply after End chat is refused; End chat enqueues one ride_chat trigger and an empty chat enqueues none; deleting the ride removes its messages; the re-plan input carries the last 14 days' ride chats and not older ones; coach chat history includes them with their day.
  • E2E (replay): import a ride, see a question in the take, reply, read the coach's answer, End chat, see the re-plan line on Today. Keep the axe scans passing.

Out of scope

Holding the post-ride re-plan, the nightly release and the shell bar (session 51); saving dated context or a TSS override from the chat (session 52); streaming chat replies; notifications. Note anything else under Follow-ups.

Done when

On a production build (replay) a ride's take asks a question, the athlete replies and gets an answer, and End chat runs one re-plan whose input holds the conversation; coach chat shows the ride's messages; unit, typecheck, lint, format, audit and e2e pass. Add an owner check under Follow-ups → Now: chat about the next three real rides (one unplanned) and note the cost per chat. Update FR-19's "not yet built" and the "AI design" table (the ride chat row). Finish with the end-of-session ritual in CLAUDE.md.

Moved from prompts/50-ride-chat.md on 2026-11-08.

# 50 · Ride chat **Phase:** Adaptive coaching 1/5 (owner request 2026-11-08) · **Branch:** `session/50-ride-chat` · **Depends on:** 34 The coach's take on a ride is one-way. The owner wants a conversation: the coach asks what the numbers can't tell it (how hard it felt, why heart rate drifted, why the ride ran long), the athlete answers, and only at the end, by **End chat**, does one re-plan run with what was learned. No plan changes mid-chat. Session 51 then holds the post-ride re-plan until End chat; this session leaves the immediate `ride_logged` re-plan as it is. ## Read first - `docs/requirements.md` → "Coaching dialogue and adaptability" (FR-19, and FR-20 to see what 51 adds), FR-8, FR-14, and "AI design" (ride feedback and the guardrails paragraph) - `docs/decisions.md`: the 2026-11-08 adaptive coaching entry, and the session 33, 34 and 39 entries on feedback and allowances - `prisma/schema.prisma`: `CoachMessage`, `RideFeedback`, `Ride`, `ReplanTrigger`, the `PlanTrigger` enum - `src/server/coach-store.ts` (`getCoachThread`, `askCoach`, `historyOf`, `coachSays`), `src/server/coach.ts`, `src/ai/prompts/chat.ts` - `src/server/feedback-store.ts` (`comparisonFor`, `getRideFeedbackView`, `feedbackHeadlines`), `src/server/feedback-run.ts`, `src/ai/prompts/feedback.ts`, `src/domain/feedback/schema.ts` - `src/server/on-session-logged.ts`, `src/server/replan/triggers.ts`, `src/server/replan/input.ts`, `src/ai/prompts/replan.ts`, `src/domain/replan/triggers.ts` - `src/components/log/coach-take.tsx`, the ride page route, `src/components/today/unplanned-ride.tsx` and Today's done-ride card, the coach chat sheet - Load the `claude-api` skill before touching `src/ai/` ## Goal 1. **Questions in the take.** `RideFeedbackOutput` gains `questions` (0–2 short questions). New prompt `feedback-v3`: ask only when the answer would change how the coach reads the ride or plans the next days. Examples: heart rate high for the power, a ride much longer or harder than planned, an unplanned ride whose kind the data can't settle (polo, a group ride with no power), a note that hints at pain. A clear ride gets none. Old rows parse with `questions: []`. Re-record the feedback fixtures. 2. **The ride's thread.** `CoachMessage.rideId` (nullable, FK to `Ride`, cascade on delete; additive migration) and an index on `(userId, rideId, createdAt)`. A ride chat's state lives on a small `RideChat` row (`rideId` unique, `userId`, `endedAt?`, `createdAt`) or an equally small shape you justify; it is created on the first reply. The take's questions show as the coach's opening lines (from the feedback row, not copied into messages). 3. **A chat turn.** `sendRideMessage(rideId, text)`: `authed`, Zod, ownership of the ride. Refused when the chat is ended or the ride has no take. One AI call, new task `ride_chat` with its own `AI_MODEL_RIDE_CHAT`/`AI_EFFORT_RIDE_CHAT` defaulting to the chat task's config, and a Developer panel row like the others. Input: the ride's comparison and take, the athlete's note on it, its thread, form before and after, the week's planned sessions, recent readiness, and the ride's day. Output: `{ reply }` only, no patch. The prompt: plain and short; ask a follow-up when the answer is still unclear; never promise plan changes ("I'll take this into the plan when you end the chat" is fine); the athlete's text is data inside a delimited block, never instructions; medical red flags short-circuit as coach chat does. Counts against the athlete's allowance (`userStarted`). Takes no re-plan lock (it changes nothing). 4. **End chat.** `endRideChat(rideId)`: sets `endedAt` and enqueues one new trigger `ride_chat` (enum value, additive) whose detail names the ride and day. The thread becomes read-only. Ending an empty chat (no athlete message) is allowed and enqueues nothing. 5. **Re-plans and chat read ride chats.** `loadReplanInput` adds each ride chat from the last 14 days (ended or not) beside its ride in `<last_14_days>`, as athlete data, delimited like notes, trimmed to a length cap. `replan-v3` (or the next version) says how to weigh it: what the athlete says about how hard a ride felt, how they feel now, and their time this week outranks what the numbers suggest, inside the rules; a ride the athlete calls easy is no reason to strip planned quality. Coach chat's `historyOf` includes ride-chat messages, each tagged with its ride's day. 6. **Where it shows.** - Ride page: under the coach's take, the questions, the thread, a reply box and End chat. Ended: the thread, read-only, with "Chat ended, plan updated" (or "nothing to change") from the run the trigger fed. - Today: the after-ride card (planned and unplanned) shows the take's first question when there is one, and a "Reply" link to the ride's chat. - Coach chat sheet: ride-chat messages in order, each with a small "about Sat's ride" tag linking to the ride. - Offline: replies need the network (an AI call); say so rather than queueing. ## Rules - Every new server function uses `authed`, a Zod validator and `userId` filters; a ride and its messages are only ever the owner's. - Plans stay append-only. A chat turn writes messages only; the plan changes only through the End chat re-plan. - Replay fixtures for every new AI path; tests and e2e run with `AI_REPLAY=1`. Record with `bun run ai:record` and `E2E_AI_RECORD=1`. - Strength sessions get no chat (the owner plans to drop strength). ## Tests - Domain/AI: `RideFeedbackOutput` with and without questions; old rows parse; the ride-chat output schema parses its fixtures; a red-flag message short-circuits. - DB: a reply creates the `RideChat` and both messages; another user's ride is refused; a reply after End chat is refused; End chat enqueues one `ride_chat` trigger and an empty chat enqueues none; deleting the ride removes its messages; the re-plan input carries the last 14 days' ride chats and not older ones; coach chat history includes them with their day. - E2E (replay): import a ride, see a question in the take, reply, read the coach's answer, End chat, see the re-plan line on Today. Keep the axe scans passing. ## Out of scope Holding the post-ride re-plan, the nightly release and the shell bar (session 51); saving dated context or a TSS override from the chat (session 52); streaming chat replies; notifications. Note anything else under Follow-ups. ## Done when On a production build (replay) a ride's take asks a question, the athlete replies and gets an answer, and End chat runs one re-plan whose input holds the conversation; coach chat shows the ride's messages; unit, typecheck, lint, format, audit and e2e pass. Add an owner check under Follow-ups → Now: chat about the next three real rides (one unplanned) and note the cost per chat. Update FR-19's "not yet built" and the "AI design" table (the ride chat row). Finish with the end-of-session ritual in `CLAUDE.md`. _Moved from `prompts/50-ride-chat.md` on 2026-11-08._
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ckreidl/trainer#225
No description provided.