Add per-routine target heart rate with live in-run indicator

Endurance routines (HIIT, cardio, cycling) can carry an optional target bpm
(RoutineDocument.targetHeartRate, not schema-bumped — same preference-field
rationale as restSeconds/autoAdvance), snapshotted onto the WorkoutDocument at
plan time like the other pacing fields.

During a run, the watch streams its live HR sample to the phone over a new
best-effort liveHeartRate message — deliberately outside the LiveProgress
machinery (no version bump, no staging/retry; a gauge, not a record), throttled
to changed-bpm-or-10s in the watch bridge. LiveRunState holds the sample with a
30s staleness auto-clear so a dead stream never shows a frozen number.

Both run screens show the reading only when the run carries a target: the
phone's ExerciseProgressView as a top pill, the watch's in the top-trailing
toolbar slot, each tinted by a shared ±5 bpm HeartRateBand with an arrow cue to
push harder (low) or ease off (high) — e.g. dialing in a treadmill incline to
hold a steady effort.

Claude-Session: https://claude.ai/code/session_01Y7ZhkCYWNiTSAFhFCGnJ8n
This commit is contained in:
2026-07-11 19:51:44 -04:00
parent b06a44eb40
commit 8854ad59d5
17 changed files with 283 additions and 10 deletions
+12
View File
@@ -11,6 +11,16 @@ import SwiftData
// SwiftData PersistentIdentifier). Computed helpers preserve the API the views
// used against the old Core Data classes.
extension PersistentModel {
/// True while this model is registered with a live context. Reading a persisted
/// property on a dead model traps, and any entity can die under a view that
/// retains it (remote delete, reconcile prune the cache is rebuildable). Check
/// this before every such read: `isDeleted` alone misses the unregistered state
/// after the deletion saves, when `isDeleted` reads false again but reads still
/// trap (see `WorkoutDocument.init?(fromLive:)`).
var isLive: Bool { !isDeleted && modelContext != nil }
}
// MARK: - Routine
@Model
@@ -26,6 +36,7 @@ final class Routine {
var activityTypeRaw: Int = 0
var restSeconds: Int?
var autoAdvance: Bool?
var targetHeartRate: Int?
@Relationship(deleteRule: .cascade, inverse: \Exercise.routine)
var exercises: [Exercise] = []
@@ -152,6 +163,7 @@ final class Workout {
var deletedLogIDs: [String: Date]?
var restSeconds: Int?
var autoAdvance: Bool?
var targetHeartRate: Int?
@Relationship(deleteRule: .cascade, inverse: \WorkoutLog.workout)
var logs: [WorkoutLog] = []