Skip to content

TriIQ — Open Knowledge Format

1. Specification

What it is

TriIQ is a client-only mobile/desktop app that connects an athlete's Intervals.icu training data to an LLM (Claude; Ollama — Ollama Cloud by default, or a local/self-hosted server; or any OpenAI-compatible server), so the athlete can:

  • see today's training and load metrics at a glance,
  • browse a calendar of planned vs. completed training,
  • review long-term statistics (training stress, volume),
  • chat with an AI agent about their own data — progress, readiness, and training-plan questions.

Design principles

  • No custom backend. The app talks directly to Intervals.icu and to whichever LLM provider the user configures. There is no TriIQ-operated server in the loop.
  • Local-first. Training data fetched from Intervals.icu is cached in a local SQLite database, so screens read from disk and the app stays usable (for previously-synced data) without a live connection.
  • LLM-agnostic. The user picks Claude, Ollama or an OpenAI-compatible server in Settings; the agent layer is provider-agnostic via LangChain.dart, and lib/agent/chat_model_factory.dart is the only file that names a provider's chat model.
  • The generated API client is a dependency, not hand-written code. lib/client/intervalls/ is produced from openapi.json and should be regenerated, not edited (two documented exceptions aside — see CLAUDE.md).

External dependencies

Dependency Purpose Auth
Intervals.icu API (openapi.json) Source of truth for activities, wellness, workouts HTTP Basic: username API_KEY, password = the user's Intervals.icu API key
LLM provider (Claude API; Ollama — Ollama Cloud by default, or a local/self-hosted server; or an OpenAI-compatible server) Powers the chat/agent Claude: API key. Ollama Cloud: API key (ollama.com/settings/keys). Local Ollama: none. OpenAI-compatible: optional API key (OpenAI, OpenRouter, Azure-style proxies, LiteLLM need one; LM Studio, vLLM, llama.cpp usually none)
langchain_openai (+ openai_dart) The chat model behind the OpenAI-compatible provider (ChatOpenAI, Chat Completions, configurable baseUrl) — (the provider's key is passed to it)
langchain_anthropic, langchain_ollama The chat models behind the Claude and Ollama providers —
package_info_plus The running app's version and build number, shown in Settings and on the Info screen (lib/info/app_info.dart); tests use PackageInfo.setMockInitialValues —

Status matrix

Area Status
Navigation shell (top bar, bottom nav) ✅ Implemented — the bottom bar is the athlete's to arrange (Arrange the menu): reorder it, pin More entries to it, move tabs into More; More is always last
Intervals.icu connection (Profile) ✅ Implemented — two ways in: Log in with Intervals.icu (OAuth 2 with PKCE as a public client: the browser opens Intervals.icu's page, the app gets a bearer token back, no secret and no password in the app) or a pasted API key. Either is auth-tested against Intervals.icu, then persisted to secure storage and restored on relaunch (IntervalsSession.connect / connectWithToken; one credential at a time). Disconnect forgets it, and revokes the token at Intervals.icu for an OAuth login
Local SQLite cache + sync ✅ Implemented (Today auto-sync, manual Sync screen, closed-app background sync on Android — nightly by default, or every 15 min / 1 h / 6 h — with a notification when something new arrived)
Today screen ✅ Real data once connected — one hero card (today_hero_card.dart: date, status — "Ready to train", or "Train with care" / "Take it easy today" in the readiness colour —, the readiness ring (tap: a bottom sheet explaining each signal), today's session(s), one primary action that fits the day — Start (the session's steps), Swap for easier (Train now's Find alternative, on Caution / Back off with a hard session), Log how it felt once done (the button disappears once fatigue or soreness is logged), Propose training when nothing is planned —, a result view after the session (planned vs. actual, performance-trend arrow, feel), "Ask the trainer about today", and a tomorrow strip); swipe today's session right to log the feel, left to move it to tomorrow (calendar rule warnings, Undo; also in ⋯ and as screen-reader actions); hold a session's icon (planned or completed) to peek at its details, tap a completed session to open the activity — the card itself has no long-press menu, the ⋯ button opens the quick actions (sync, Train now, log feel, move, open Intervals.icu, customize); an attention stack (illness return ramp, fatigue warning, plan adjustments, race countdown, threshold suggestions — only when they have something to say, most important first, two open, "+N more", each hidden for the day by a swipe or ×); This week (TSS against plan, sessions done / planned, hours per sport against the weekly targets, the year goals as one line); a Mon–Sun week ribbon (done / planned / missed / rest, tap opens the Calendar on that day, hold peeks at the day — see Hold to peek); load tiles as a row of three (CTL, ATL, Form, "More metrics" for all six, or all six always via Customize Today), each with sparkline, trend arrow and its chart; race week (≤ 7 days to the plan's event) puts a header with countdown, taper phase and race-day form forecast in place of the tiles; a sick / injured day hides the training cards and shows the return-to-training plan; before the watch data is in the readiness slot says "Waiting for watch data" with a refresh. Hero and This week fit a 360 × 780 dp phone without scrolling (tested)
Athlete details ✅ Implemented — profile picture, location/age, body stats and per-sport thresholds (FTP, LTHR, max HR, threshold pace) from the live Intervals.icu athlete record
Activities screen ✅ Implemented — every cached activity, filterable by sport (from Statistics), tap through to detail with an evaluation against the plan, the streams over time with intervals, "Ask the trainer" and "Open in Intervals.icu"; insights (personal bests, efficiency trend, recovery hint); Weekly review in More
New-training pop-up ✅ Implemented — after the open-time sync, today's sessions not yet seen pop up once (one page each, OK marks them seen); switchable in Settings → App → Notifications
Calendar screen ✅ Implemented — year / month / week / day levels (drill down by tap, pinch, the level buttons or the breadcrumb 2026 › November › Week 46 › Fri 13; level and date remembered; zoom animation off under reduced motion), swipe to change period, swipe down on the header for today; drag a planned session to another day (plan rules warn, Undo), swipe a session in the day list (left = delete with undo, right = "How did it feel?"), "Move to…" as the gesture-free path; richer cells (load fill, per-sport minutes bar, readiness dot, key/strength badges, week-number column, compact/comfortable density); filter chips (sport, planned/completed) and the period's TSS / hours / sessions / CTL change in the header (hold the year or month crumb for the month's and the year's per-sport statistics) — lib/screens/calendar/; of TriIQ plan sessions, Intervals.icu planned events (copying switchable in Settings) and completed activities from the cache, colour-coded, tap-through to detail; completed activities in the day list show a small trending-up/down icon when their efficiency factor (Intervals.icu EF) is ≥2% above/below the mean of the previous ≤8 same-sport sessions in the last 42 days (needs ≥3, ≥20 min; otherwise no icon — lib/evaluation/performance_trend.dart)
Insights (was Statistics) ✅ Implemented — the Insights hub (bottom-nav tab, lib/screens/statistics/): a compact grid of every analysis view, one tap each and accented by group — Fitness (Training analytics, Metric explorer — formerly "Analysis" in More —, Load heatmap), Performance (Performance curves, Best efforts, Durability), Health (Wellness trends), Compare, Review (Weekly review, Activities) — with the sync status and the range option in one slim row above and the overview charts right below, so the first chart is on the first screen. Hold a tile (long press, or hold the mouse button) to peek: a card floats over the dimmed screen — above the tile when there is room, else below — with the destination's name, a line on what it is and a small chart or a few figures from your own cached data (HoldPreview, lib/widgets/hold_preview.dart; content in insight_previews.dart): CTL/ATL and form for Training analytics, weekly load bars for Metric explorer, a 12-week grid for Load heatmap, season or six-week best power for Performance curves and Best efforts, the count of long rides for Durability, the HRV trend with resting HR and sleep for Wellness trends, the last four weeks against the four before for Compare, last week against the week before for Weekly review, and the latest sessions for Activities. Letting go (or a touch that turns into a scroll) hides it again; a quick tap still opens the screen. Peeks read the local cache only, so they are instant and work offline. Then: CTL/ATL trend, completed-vs-planned load per week, week/month/year volume and a per-sport breakdown, all from the cache; Performance sub-screen (content centred and capped at 840 px on wide windows; the model card shows FTP / CP / W′ / Pmax and the settings value as tiles across its width, with the model-vs-settings gap beneath) with power/pace/HR curves per sport (season vs season, key efforts, model fit vs settings), fetched on open and cached; threshold suggestions (derived ride FTP / run / swim threshold pace, Review/Dismiss, a confirm sheet that writes the one changed field to Intervals.icu on Apply, with Undo)
Fatigue early warning ✅ Implemented — a Today card (and get_fatigue_warning) when HRV, resting HR, sleep, form, CTL ramp or the fatigue/soreness scores stay off on enough of the last 5 days: watch (two signals) or warning (three, or HRV/resting HR plus a load or feel signal); "Ask the trainer" or "Not now" (hidden for the day unless it worsens)
Morning briefing ✅ Implemented (Android/iOS) — Settings → App → Notifications: a notification at a chosen time with today's sessions, readiness (only if the watch data is already in), fatigue level, illness note and form/CTL; prepared from the last sync and re-armed after syncs, plan changes and the nightly background sync
Weekly review notification ✅ Implemented (Android/iOS scheduled; Windows on the next start after the time; web no-op) — Settings → App → Notifications, off by default: a weekly notification (default Sunday 19:00, day and time selectable) with load vs the plan week's target TSS and time per sport vs the weekly targets, planned / done / missed sessions and whether the key session was done, CTL change, form at week end, a "ramp above usual" flag, ready / caution / back-off day counts with the HRV and resting-HR direction, and next week's target TSS, phase, 1–2 key sessions and races. Big-text style; tapping it opens Weekly review on that week. Optional Include trainer comment (off by default, offered only with an LLM provider set up): one sentence from the provider, given only the computed figures, 15 s timeout, silently left out on failure. Computed from the cache by WeeklyReviewSummaryLoader (lib/evaluation/weekly_review_summary.dart), composed and armed by WeeklyReviewScheduler (lib/notifications/weekly_review_notification.dart) wherever the morning briefing is re-armed; the trainer reads the same summary with get_weekly_review
Training analytics (Insights → Training analytics) ✅ Implemented — all from the local cache, maths in lib/evaluation/training_analytics.dart: fitness by sport (CTL or ATL per swim/ride/run from each sport's own daily TSS with the 42/7-day model, 180 days of warm-up, plus the total) and a stacked weekly where your load comes from chart with per-sport shares; intensity distribution (weekly/monthly share of easy / threshold / hard zone time via intensityOf, labelled polarized / pyramidal / threshold-heavy / high-intensity with Treff's polarization index, needs ≥ 1 h of zone time); load safety (acute:chronic load ratio 7 d/28 d — safe 0.8–1.3, risky ≤ 1.5, too fast above; CTL ramp rate — safe ≤ 5/week, risky ≤ 8; Foster monotony and strain over 7 days — safe ≤ 1.5, risky ≤ 2); aerobic base (EF and Pa:HR decoupling for ride/run sessions ≥ 60 min with ≥ 70 % easy zone time, EF least-squares trend per month, decoupling < 5 % solid / 5–10 % developing / > 10 % drifting)
Compare (Insights → Compare, or "Compare with…" on a run/ride's page) ✅ Implemented — running and cycling only; maths in lib/evaluation/compare.dart. Activities tab: pick two activities of the same sport; one chart per stream (power, heart rate, speed/pace, cadence, altitude) overlays both on a shared distance or time axis (blue = A, orange = B; distance is unavailable when either lacks a distance stream, fetched on demand by ActivityStreamsRepository.loadForCompare), both courses on one map in the two colours, and a side-by-side table of the same figures. A shared tracker: touching the chart moves a labelled dot for each activity on the map (the position of each at that distance/time), and tapping the map moves the chart's cursor to the nearest point of the closest course; switching axis keeps the tracker on the same moment. Periods tab: this block against the previous block of 7/14/28/56 days for runs or rides — sessions, distance, time, elevation, load, pace/speed, power, heart rate, EF, decoupling, easy share with the change between them, plus cumulative distance/time/load by day for both blocks
Readiness signals (long-press the readiness card, or the options icon on its detail screen) ✅ Implemented — choose which of HRV, resting HR, sleep, form, fatigue/soreness, load and the device's own readiness count toward readiness (ReadinessSettings, lib/evaluation/readiness_settings.dart, stored on the device in shared_preferences as the switched-off signals; at least one stays on). A switched-off signal is rated excluded: it moves neither the status nor the 0–100 score, its pill disappears from the card, and the detail screen lists it greyed as "Not used". ReadinessService applies the choice everywhere it is used — Today, the detail screen, the morning briefing, plan adjustments — and the get_readiness tool reports only signals_used (naming signals_switched_off) so the trainer does not base readiness advice on them. The same sheet picks the HRV / resting-HR smoothing window — the median of the last 3 (default) or 5 days with data (ReadinessSettings.smoothingDays, readiness.smoothing_days; unset follows okf-rules smoothingDays)
Durability (Insights → Durability, rides and runs) ✅ Implemented — how much of your fresh power or pace is left after a lot of work. Intervals.icu only serves two predefined fatigued curves, so the levels are computed in lib/evaluation/durability.dart from the sessions' own streams: for rides the best 5 s / 1 min / 5 min / 20 min / 1 h power of efforts that started after 1,000 / 2,000 / 3,000 kJ of work, for runs the fastest 1 / 3 / 5 / 10 km after 10 / 20 / 30 km already run, taken across the most recent long sessions (rides ≥ 1,000 kJ or 1.5 h, runs ≥ 10 km; last 90/180/365 days, at most 40 sessions, streams fetched once and cached). The fresh reference is the season curve (else last 42 days) from the Performance curves; the screen plots all levels, shows the value and the share kept per point, and says how many sessions it was based on. Below the line chart a radar (spider) chart shows the share of the fresh value kept: one axis per duration (rides: 5 s … 1 h) or distance (runs: 1 … 10 km), rings at 25/50/75/100 % (the outer ring is the fresh reference), one semi-transparent polygon per fatigue level told apart by colour, dash pattern and marker shape. A missing point is a gap (never 0) and an axis no visible level has data for is labelled "no data". Tap or hover a vertex or spoke for the value (W or pace), the share kept and the source session, with Open session; tap a legend entry to show or hide a level; the table of values sits behind Show table (collapsed by default). See Radar chart under Charts
Wellness trends (Insights → Wellness trends, or "Longer trends" on the readiness screen) ✅ Implemented — HRV, resting HR, sleep (hours) and weight over 30/90/180/365 days from the wellness cache (lib/evaluation/wellness_trends.dart): the daily values, a 7-day trailing average that carries through missing days, a shaded band of the usual range (median ± 1 MADσ over the period after dropping outliers — the shared robust baseline of wellness_baseline.dart — needs 21 values), and latest / 7-day average / change against a week earlier with a below / within / above-range note. Metrics can be hidden in the options sheet; a metric with no data has no card
Energy (Insights → Energy) ✅ Implemented — read-only calories from the cache (lib/evaluation/energy_balance.dart, lib/screens/statistics/energy_screen.dart): eaten per day as logged in Intervals.icu wellness (kcalConsumed, carbohydrates, protein, fat — usually from a connected food app) next to training calories from activities (calories), plus carbs used and taken in during sessions, over 7/28/90 days. Averages of eaten count only logged days. Resting burn is not recorded or estimated, so it is not an energy balance; a hint counts days where training burned more than half of what was logged. No targets, no deficit, no diet advice; a care note points to a dietitian or doctor. The trainer reads the same data with get_nutrition, which describes and never sets calorie or weight targets. Nothing new is stored and nothing is logged in TriIQ
Best efforts (Insights → Best efforts, rides and runs) ✅ Implemented — the best 5 s / 1 min / 5 min / 20 min power (rides) or fastest 1 / 5 / 10 km (runs) of every session over the last year, from Intervals.icu's per-activity curves (activity-power-curves / activity-pace-curves, lib/evaluation/best_efforts.dart; cached 6 h in SQLite, the last copy used offline). One line of the best per 30-day window (12 windows) with a second line of the best of the 90 days up to each, for the effort chosen in the options sheet, and a table of the last 30 days against the best of the 90 days before them with the change (green better, red worse; for pace a lower time is better). The pace response is not documented, so it is parsed defensively and not yet checked against the live API
Load heatmap (Insights → Load heatmap) ✅ Implemented — daily TSS, one square per day, coloured in five steps against the 90th percentile of training days (lib/evaluation/load_heatmap.dart). Three layouts, chosen under the options button and remembered (shared_preferences heatmap.style): Year grid — the contribution graph, Monday first, cells sized from the available width so a year fits without sideways scrolling; on a narrow phone (360 dp) it turns into weeks-as-rows (seven columns, month labels on the left), and only a tiny width or very large text falls back to scrolling (HeatmapGridLayout.fit); Months — a small calendar per month, 2–4 across; Week table — weeks × weekdays with each week's total (over a bar of its share of the busiest week) and each weekday's total. Colour scale: theme colour or Viridis (heatmap.scale; ordered so more load always stands out further from the background, in light and dark). Views in lib/screens/statistics/heatmap_views.dart. Last 12 months, this year or last year, all sports or swim / ride / run; tap a day for its TSS and sessions; total load, training days, longest streak and busiest week below
Effort profile (activity page, runs and rides) ✅ Implemented — from the streams the session diagram already loaded (shared in-flight, no extra download): the variability index (Intervals.icu's figure for rides, else normalized over average from the stream; steady ≤ 1.05, some surges ≤ 1.15, very variable beyond), a histogram of time at power (25 W bands, 50 W for big sprints) or pace (0.25 m/s bands) with a tap readout and the time not pedalling or stopped, and an interval table with duration, power or pace, heart rate, drift inside the interval (second half against first, intervals of 2 min or more) and fade against the first work interval (lib/evaluation/activity_extras.dart)
Consent & your rights (Settings → Data & privacy → Consent & your rights) ✅ Implemented — the in-app privacy notice (what is processed incl. health data, where it is stored, recipients, transfers outside the EU/EEA, legal basis, retention, rights, contact; mirrored in docs/privacy.md) with the controls that apply it: AI consent (PrivacySettings, lib/data/privacy_settings.dart, stored with the date on the device) — a configured provider is not usable until the athlete agrees, LlmSettings.isConfigured requires it, a consent card appears in Chat and Settings, and withdrawing switches the AI off at once; map tiles from OpenStreetMap can be switched off (routes then draw without a map); Delete all data (DataEraser: every table emptied, saved keys and preferences removed, Intervals.icu disconnected). Export is Settings → Data & privacy → Backup
Skeletons, undo and sync status ✅ Implemented — skeleton loading (lib/widgets/skeleton.dart): the statistics screens, Analytics, Wellness trends, Load heatmap, Best efforts, Weekly review, the Compare periods tab and the Activities list show pulsing placeholders in the shape of their content instead of a spinner (steady when the system asks for reduced motion). Undo: deleting a single planned session hides it at once (PendingDeletes, honoured by every calendar list) and offers Undo for 6 s; only when the snackbar goes away is it deleted for real (Intervals.icu, cache, plan), and a failed delete brings it back. Nothing is written inside the window, so quitting the app keeps the session. Deleting a whole day's sessions still asks first. Replacing a session in Train now offers Undo for 8 s, which swaps the old session back through the same replace. Sync status chip (SyncStatusChip) on Today (on the hero card, next to "Ask the trainer about today") and Statistics: "Synced 5 min ago", "3 waiting to send", "2 failed to send" or "Not connected"; amber when over a day old or needing attention; tap opens Sync
App search (More → search field) ✅ Implemented — one search over every tab, Insights view, More entry, Settings group and section (and the three scheduled notifications): type a few words in English or German and tap a result to go there. Each result shows its icon, title, breadcrumb (e.g. "Insights › Durability", "Settings › App › Notifications › Weekly review") and a one-line description. Matches titles, synonyms (e.g. "dark mode" → Appearance, "Ruhepuls" → Wellness trends), descriptions and this document's user-facing text, tolerating a typo or two ("durabilty"), umlauts typed or not ("Müdigkeit" / "mudigkeit") and the filler of a question ("where is the heatmap"). No recent-searches list yet. The trainer uses the same search (search_app_features)
More tab ✅ Implemented — a search field at the top (App search, above), then three groups with headers: Plan (Training plans, Season, Events), Trainer (Trainer memory, Knowledge library), Data (Sync — also one tap from the sync status chip on Today and Insights —, and Info). The analysis screens and the Activities list moved to Insights; the "Gear – coming soon" placeholder is gone. That is the default: More lists whatever is not in the bottom bar, in the athlete's order, with Customize navigation at its top right (Arrange the menu)
Offline-first write queue ✅ Implemented — moving or deleting a sent session, deleting a planned workout, and sending a plan to Intervals.icu while it is unreachable are applied locally at once and stored (SQLite v8 pending_writes), replayed in order before every sync, with a "N changes waiting to sync" card on Today and Sync (Send now / Retry / Discard). "Replace with alternative" too: offline it shows the new session at once and queues create-new + delete-old (a retry never creates twice)
Home-screen widget (Android) ✅ Implemented, not yet device-tested — today's planned sessions (two lines, "+N"), completed TSS, form and CTL/ATL, and a ring per sport with a weekly target (swim/ride/run, percent and hours done of the target; the ring stops at 100 %); resizable from 4×1 (one row: session + form) and 2×2 (session + form) up to 4×2 (adds the details) and 4×3+ (adds the target rings), with a layout chosen per size; tap opens the app; refreshed at start, after syncs, on plan changes and after the nightly background sync
Trainer memory (More → Trainer memory) ✅ Implemented — standing preferences ("no hard sessions on Fridays", "swim only mornings") kept on the device and added to the trainer's context every turn; add/remove them in the app, or the trainer saves/removes one via remember_preference / forget_preference only when you ask it to (marked "saved by the trainer"). Prompt-level: the plan engine does not enforce them
Backup (Settings → Data & privacy → Backup) ✅ Implemented — export synced data, plans, knowledge library and settings as one JSON file (share sheet on phones, save dialog on desktop), restore on another device; secrets are never included
Season (More → Season) ✅ Implemented — fitness forecast (CTL/ATL/form projected from the planned sessions, with "form on race day" per race), season timeline (build / taper / race / recovery blocks across all RACE_A/B/C events and the goal's event date, with a conflict check), the illness / injury mode card, and the race predictor
Race predictor ✅ Implemented — finish time per leg from the pace curves (Riegel) and power curve (race-intensity fraction + physics model), a CTL / race-day-form allowance, a pacing plan and a fuelling plan; swim/ride/run presets from 5 km to 140.6
Illness / injury mode ✅ Implemented — a SICK / INJURED Intervals.icu event reshapes the plan: rest (sick) or cross-training (injury), then a graded return ramp; shown on Today and Season, applied only after confirming
Route map (activity detail) ✅ Implemented — outdoor runs and rides show their GPS track on a still flutter_map map (start green, finish red) in Activities → detail only; tap for a full-screen map you can pan and zoom. The track is fetched once (latlng stream, thinned to ≤ 1200 points) and cached; indoor/virtual rides, other sports and activities without GPS show nothing
Brick / transition tracking ✅ Implemented — a bike→run or swim→bike pair on one day gets a card on Activity detail: transition time, how fast the legs settled, early speed/HR cost
Chat screen ✅ Talks to the agent — streams replies, renders them as formatted markdown (incl. tables), shows which tool is running, starter questions on the empty state, New chat to start over; reads the training plan and proposes graph, plan and session changes as cards you Apply or Dismiss
"Train now" ✅ Implemented — shows today's planned sessions; Find alternative (today's session as reference, replace it or add alongside) or Propose training when nothing is planned; the agent uses the last 7 days of TSS/CTL/ATL plus the day's done/other-planned TSS and the next day's planned TSS. Change training (Calendar plan-session sheet, planned-workout detail) opens it on that session's day with the session preselected
Create a planned workout on Intervals.icu ✅ Implemented — "Create in Intervals.icu" turns the proposal into a structured workout on today's calendar, after a preview
Accessibility ✅ Implemented — screen readers get a summary of every chart: line charts per series ("CTL: latest 64, +3 over the range") and the selected point, bar and stacked charts (count, latest, highest), the session stream chart (which streams), the load heatmap (training days, total TSS, longest streak, the layout, and the busiest weekday in the week table), the chart overview strip (the range shown) and tappable legend entries (toggle buttons: "CTL: shown. Tap to hide."), the readiness gauge ("Readiness 72 of 100"), the weekly target rings ("Swim: 1.2 / 2.0 h, 60 %"), Today's hero card as one summary (status, readiness, today's session, tomorrow) and each week-ribbon day ("Wed, Nov 4: done. Open in the calendar."). Every Today gesture has a button or menu path (swipe → screen-reader actions and the ⋯ menu; attention cards → ×). Nothing relies on colour alone: deltas carry +/−, readiness signal pills a rating icon (check, warning, error) and a spoken rating, risk tiles a text label, Compare's B line is dashed (ChartSeries.dashed, in the legend too). Today, Insights and the activity page are tested at 1.3× and 2× text (test/accessibility_test.dart, Today at 360 dp and 2× in test/today_states_test.dart; the activity stat grid grows with the text), and the small icon buttons keep a 48 dp touch target
Error and empty states ✅ Implemented — one StatusMessage (lib/widgets/status_message.dart): icon, short title, plain reason, one action. describeError maps failures to text you can act on — offline (no response, socket, timeout) → "You're offline" + Retry; HTTP 401/403 → "Intervals.icu refused the request" + Open Profile; not connected → Open Profile; 429 / 5xx → wait and retry; SQLite → local data; else "Something went wrong". The exception text only behind an expandable Details. Empty states (StatusMessage.needsSync) say what is missing and offer Open Sync. Used on Insights, Performance curves, Durability, Best efforts, Compare periods, Wellness trends, the load heatmap, Weekly review, Activities and the activity page's chart
First-run onboarding ✅ Implemented — a fresh install opens OnboardingScreen (lib/onboarding/) once over the shell: welcome (with Privacy & data), connect Intervals.icu (API key, "where do I find it?", test, then this month syncs with a progress bar), sync more history (this month / this year / everything; afterwards a hint if activities come only as Strava stubs the API cannot read — connect Garmin, Polar, Suunto or Wahoo to Intervals.icu directly — and a hint for sports without FTP or threshold pace), sports and weekly hours (saved to WeeklyTargetsSettings), year goals (YearGoalsSettings), races and events (the event editor), AI trainer (Claude key, Ollama server, or OpenAI-compatible URL + model + optional key, then the AI-consent question), done. Every step has Skip this step; Skip setup leaves at once and Today's "Finish setting up" banner covers the rest. The same flow runs from Settings → Guided setup (guided: true) with current values filled in and kept by clicking Next. OnboardingSettings marks it done; an install that already has preferences or a saved Intervals.icu key is marked done without showing it
Info / version / SBOM ✅ Implemented — More → Info (and Settings → Info, plus the version in small type at the bottom of Settings): InfoScreen (lib/screens/info/) shows TriIQ 0.9.6 (build 1) read at runtime with package_info_plus, the platform, OS and Dart version, links (GitHub, Releases, the in-app privacy screen, the licence), Flutter's open-source licenses page, a Copy version info button (version, build, platform, OS, locale, theme — no personal data) and the SBOM: assets/sbom/triiq.cdx.json, a CycloneDX 1.5 list of every Dart/Flutter package, generated by tool/pubspec_lock_to_cdx.py from pubspec.lock and kept in sync by test/info/sbom_sync_test.dart and the SBOM workflow. SbomScreen shows the counts (direct / dev / transitive), a searchable list, a details sheet per package with a pub.dev link and Share / export SBOM (JSON) (share sheet on phones, save dialog on desktop, like Backup). Not covered: native Android (Gradle) libraries and the Flutter engine
Settings hub ✅ Implemented — SettingsScreen (lib/screens/settings/settings_hub.dart) is a search field and four groups: Training (weekly targets, year goals, how you feel), AI trainer (provider, model, consent), Data & privacy (sync, calendar, backup, privacy), App (appearance, language, notifications). Below the groups: an Info row and the version in small type, both opening the Info screen. Each group opens a SettingsGroupScreen; search matches titles and English + German keywords and jumps to the section. AI-setup links elsewhere open the AI trainer page directly
Appearance (system/light/dark/developer theme) ✅ Implemented — Settings → App → Appearance, applies instantly, persisted
Settings — Models (LLM providers) ✅ Implemented — an ordered list of model entries (any mix of Claude / Ollama / OpenAI-compatible) with priority failover (LlmGateway), per-entry keys in the vault, drag / Up / Down reorder, on/off, Test, Edit, Delete and status (OK / needs attention / paused); the editor has the provider chips, models, URLs, keys, live model list + connection test ("Load models" for OpenAI-compatible)
LangChain agent ✅ Implemented — tool-calling loop over the local cache (lib/agent)
Knowledge library ✅ Implemented — More → Knowledge library (Android/Windows): import Markdown/text documents, searched by get_training_guidance alongside the optional bundled reference, each match naming its source document; okf-* blocks stripped on import so imported text never reaches the plan engine
MCP server/client ❌ Not started — the agent calls its tools in-process instead
Training-plan calculation ✅ Implemented — More → Training plan: goal (Run, Ride or Triathlon with a swim/bike/run mix), 2-16 weeks, a draggable load graph on a TSS axis (80-120% of a proposed +10%/week ramp), a Monday-Sunday calendar per week; a taper and race week when the plan ends at the goal's event, with a race countdown on Today; deterministic engine (lib/plan) decides every number and date, including a swim technique session every other build/peak week; its content (a short description plus the detailed, set-by-set text) is then written by the athlete's configured LLM provider when one is set up, lib/plan/session_content.dart, falling back to plain deterministic text otherwise or on any failure; Take as plan saves locally and opens the Calendar, sending to Intervals.icu is optional (Settings → Data & privacy → Calendar); plan adjustments on Today (missed sessions, a week far off its target load, hard sessions on low-readiness days) as Apply / Dismiss cards (lib/plan/plan_adaptation.dart)
Strength & mobility block ✅ Implemented — goal option (0/1/2 sessions a week, preferred days; new goals default 1, goals saved before it load as 0); the engine adds WeightTraining sessions by phase (heavy in build weeks, maintenance before the taper, mobility in recovery/taper weeks, none in race week), never the day before a key session; exercise content with sets × reps and purpose (default, or LLM-written); load counted apart from the endurance target and 80/20; done/missed tracking, Weekly review count, adaptation (lib/plan/strength.dart)
LLM credential persistence ✅ Implemented — Claude key in the OS vault, the rest in shared preferences
Notifications ✅ Implemented on Android/iOS (incl. daily reminder) and Windows (sync/agent only, no reminder); no-op on web
Web platform ⚠️ Local storage unsupported (SQLite has no web backend wired up yet); UI renders fine

2. Architecture

Layers

 UI (lib/screens, lib/widgets)
   │  reads/writes via
   ▼
 Data layer (lib/data)
   │  IntervalsSession (auth/session + athlete record)
   │  SyncService (orchestrates fetch + cache)
   │  IntervalsWorkoutService (the one upward write: create a planned workout)
   │  Repositories (SQLite CRUD)
   ▼
 Generated API client (lib/client/intervalls) ──▶ Intervals.icu (HTTPS)

 Chat screen ──▶ TrainingAgent (lib/agent)
                   │
                   ├─▶ LangChain chat model ──▶ Claude API / Ollama server / OpenAI-compatible server
                   │
                   └─▶ TrainingDataTools ──┬─▶ Repositories ──▶ SQLite cache
                                           └─▶ SyncService ──▶ Intervals.icu

Today's screens call into lib/data/, never into lib/client/intervalls/ directly — that keeps the generated client swappable and the SQLite cache as the single read path for the UI.

MainShell (lib/widgets/main_shell.dart) is a Scaffold with: - a top AppBar whose right-corner avatar button — the athlete's own Intervals.icu profile picture once connected, their initial otherwise — pushes ProfileScreen (connect/disconnect Intervals.icu, link to Settings); - the destinations of the athlete's NavigationLayout (below) — by default Today, Calendar, Chat, Insights, More — each built the first time it is shown and then kept alive via IndexedStack: a bottom NavigationBar on phones, a NavigationRail from 840 px wide (railBreakpoint), extended with labels from 1,200 px (Windows, tablets); - wide windows: Today goes two columns from 900 px (what to do today on the left, figures and the rest on the right), Insights lays its charts out two by two (ResponsiveColumns, lib/widgets/responsive.dart), Chat and More are capped in width (ContentWidth); - More is grouped into Plan, Trainer and Data, under a search over the whole app.

Configurable navigation (lib/navigation/navigation_layout.dart, nav_items.dart, shell_tab.dart, lib/screens/more/customize_navigation_sheet.dart). Destinations are named by id, never by position: the core tabs today, calendar, chat, insights, the fixed more, and every More entry id (plan, season, events, memory, knowledge, sync — taken from moreEntries, so a new entry is arrangeable by construction). NavigationLayout (a ChangeNotifier singleton like ThemeController, load() in main.dart, forTesting() for tests) holds two ordered lists, bar and more; every arrangeable id is in exactly one of them, More is in neither — it is always the bar's last item. The bar holds 2–4 items besides More (minBar / maxBar, 3–5 slots in all; five is what a 360 dp phone fits with labels). place(id, inBar:, index:) is the one move (drag, Up / Down, Move to More, Pin to bar all go through it) and returns barFull / barMinimum instead of breaking a limit. Persisted as two string lists in shared preferences (nav.bar, nav.more); nothing is written until the athlete changes something, so the default is exactly the five tabs that shipped before. normalize repairs whatever is stored (or restored): unknown and duplicate ids are dropped, an id new in this version joins the bar if it is a core tab and there is room (else the top of More), a new More entry is appended to More, a bar over 4 spills onto More and one under 2 takes More's first core tab back. Pinned entries leave More's list rather than showing there with a marker — one place per item is easier to read and to drag. A core tab moved out of the bar shows in More (group Main sections); More keeps its group headers while each group's items stay together, and becomes one plain list once the athlete mixes them.

MainShell builds the bar, the rail and the IndexedStack from the layout, each child keyed by id, so the selection follows the item when the bar is reordered. An item moved out of the bar while selected hands the selection to More (where it now lives); before the athlete picked a tab the shell sits on the bar's first item. Routing: MainNavigation.openTab(id) / openCalendar(date) (ids, not indices — todayTab … moreTab are the id constants) select the tab when the item is in the bar, and otherwise the shell pops to its root and pushes the item's page (NavItem.route()). The app search registry, the trainer's Open … card, More's own tiles and the Settings tile use openNavItem(context, id), which does the same from a BuildContext (in the bar: back to the shell, switch; in More: push). So Take as plan → Calendar, Ask the trainer → Chat, the week ribbon and the Today hero's calendar links reach their page wherever it lives; a core tab opened from More gets a plain top bar with a back button (Calendar and Chat are then fresh instances — Chat's conversation lives in the agent, the draft hand-off in ChatHandoff is taken on open). The weekly-review notification opens an Insights sub-page (pushed, not a nav item), so it is unaffected; the Android home-screen widget only launches the app (no deep link), which then opens on the bar's first item.

Every More entry can be pinned. Each of their screens is a Scaffold with its own AppBar and only pops its own dialogs, never itself (Navigator.pop calls are all inside dialogs; popUntil(isFirst) in Take as plan works from a tab too). Shown as a tab, the page is wrapped in ShellTabScope: the shell hides its own top bar (no double bar), the page's AppBar has no back button (the shell is the root route) and appends shellTabActions(context) — the profile button the shell normally shows — so every tab has it in the same corner. The Knowledge library is not on web, so it is not arrangeable there. Bar labels use short names for More entries (Plan, Season, Events, Memory, Library, Sync, Info; full titles elsewhere). Info is pinnable like the rest: its page is a Scaffold with its own AppBar and shellTabActions.

The arranger opens from three places: the swap icon at the top right of More, Settings › App › Navigation, and a long-press on the bottom bar (or rail; the destinations carry no tooltips so the long-press is free; screen readers get it as the bar's long-press action). It mirrors Customize Today: one ReorderableListView with the sections In the bottom bar and In More (dragging across the section header moves an item between them), a live, non-interactive preview of the bar, the slots used, and an inline message (live region) when a move would break a limit. Every row has Up / Down / Move to More (or Pin to bar) buttons (48 dp) and the same as screen-reader custom actions, a label with its section and position, and Reset to default.

Destinations registry and app search (lib/navigation/). Every place the app search and the trainer can send the athlete is one AppDestination in app_destinations.dart: a stable id (tab.today, insights.durability, more.plan, settings.notifications, …), how to open it (openNavItem for tabs and More entries — wherever the athlete put them —, push a screen, or openSettingsSection), the localized title and breadcrumb, English + German keywords, and an okf anchor — the passage of this file that describes it. The registry is the source of truth for navigation and is built from the same lists the UI draws (insightsDestinations, moreEntries, SettingsGroup / SettingsSection), so a new tile shows up in search by construction. This file is the source of truth for what a destination is: OkfIndex (okf_index.dart) parses the bundled docs/okf.md (already an asset for the plan engine — ~190 KB, read once per run, no derived copy to keep in sync) and indexes only the user-facing parts: the status matrix rows (anchor status:<area prefix>) and section 3's headings (<heading>) and bold-led paragraphs / bullets inside them (<heading>#<bold term>). Sections 2, 4 and 5 are never indexed, and source-file references are stripped from excerpts. app_search.dart ranks: per query word the best hit over title (weight 10), keywords (7), breadcrumb (3), description (3) and okf text (1) — exact, prefix, compound part, or within 1–2 edits — in both languages, after folding case and umlauts and dropping question filler; at least half the words must hit. test/navigation/app_destinations_test.dart fails when an anchor resolves to nothing or a tile / entry / group is missing from the registry. Info is a More entry (more.info, anchor About / Info and the SBOM), so it is searchable (version, build, sbom, licenses, open source …) and pinnable like the others; the Settings row and version footer are plain shortcuts to the same screen, not separate destinations.

Session & sync

  • IntervalsSession (lib/data/intervals_session.dart) is a singleton ChangeNotifier holding the authenticated IntervallsClient plus athlete id/name once connect(apiKey) succeeds. connect is the auth test: it builds a client with the given key and calls getAthleteProfile(id: '0') (the "current athlete" alias) — an actual data fetch, not just a request-shape check. Only on success is the key handed to SecureKeyStore (see Credential storage below). restore() runs once at app startup (fire-and-forget from main.dart, after WidgetsFlutterBinding.ensureInitialized()): it reads any saved key and re-runs the same auth test. A key Intervals.icu actively rejects (401/403 — revoked or regenerated) is deleted rather than left stale, but a network error is not treated as a bad key: the key is kept and retried next launch, so starting the app offline doesn't cost the user a re-entry. isRestoring lets the UI (Profile, Today) show a neutral "checking" state instead of flashing "not connected" first. disconnect() clears both the in-memory session and the stored key.
  • Once connected, the session also loads the full athlete record (getAthlete(id: '0') → WithSportSettings) into IntervalsSession.athlete: profile picture, city/country, date of birth, current weight and resting HR, and the per-sport settings (FTP, indoor FTP, W', LTHR, max HR, threshold pace, zones). It is deliberately best-effort — a failure logs and leaves the session connected, because none of it is needed to sync. athleteAvatarUrl resolves the picture (Intervals.icu returns either an absolute URL or a site-relative path) and settingsForSport('Ride') looks up one sport's settings. AthleteAvatar (lib/widgets/athlete_avatar.dart) renders it anywhere an avatar is shown — app bar, Today, athlete details — falling back to the athlete's initial.
  • SyncService (lib/data/sync/sync_service.dart) fetches listWellnessRecords / listActivities for a date range and upserts them via the repositories. SyncScope is today | month | year | all, each anchored on today's date (all uses a fixed 2000-01-01 start — Intervals.icu just returns whatever exists in range).
  • Planned calendar entries (listEvents) are synced alongside wellness and activities, into an events table. They are written with EventsRepository.replaceRange, not upserted: a coach reshuffling the week deletes sessions upstream, and a plain upsert would leave those ghosts cached forever.
  • The Today screen syncs SyncService.todayWindow() — Monday..Sunday of the current week, extended to tomorrow when today is Sunday. One round-trip covers the week's TSS total and tomorrow's session. On open (and on any connection change) it uses syncTodayWindowIfMissing(), a no-op once today's wellness row is cached; pull-to-refresh and the refresh button in the header use refreshMonthWindow(), which widens the range to the whole current month (SyncService.monthWindow() — the month, extended when the current week or tomorrow spills past its edges). The Calendar and Statistics tabs stay alive next to Today in the shell's IndexedStack, so a refresh that actually fetched also calls AutoSyncService.notifyCacheChanged() and both reload from the freshly filled cache instead of showing last hour's month. A failed fetch does not blank the screen — it falls through to the cache and shows the error alongside.
  • Pull-to-refresh is bounded (refreshRange(), used by Today and Statistics): at most one fetch per SyncService.refreshMinGap (10s) app-wide, and the gesture stops waiting after refreshTimeout (10s) rather than spinning on a connection that never answers. The request it gave up on carries on in the background and its rows still land in the cache for the next load. A throttled-away refresh is not an error: it returns false, the screen re-reads the cache, and nothing is announced to the other tabs.
  • No two syncs run at once. Every screen holds its own SyncService, so syncRange() coordinates through static state: a request for a range already in flight joins that fetch instead of issuing a second one, and a request for a different range queues behind whatever is running. Without it, a pull-to-refresh landing on top of the background auto-sync would fire the same three requests twice over.
  • The Calendar screen syncs the range it is showing (the whole year at the year level, the six-week grid for a month, the week for the week and day levels). Navigating between months uses syncRangeIfMissing() (a month already looked at is free); switching to the tab uses syncRangeIfStale(), which refetches unless the cache was refreshed within SyncService.staleAfter (1 minute), so arriving on the calendar shows current data without a round-trip per tab bounce; the refresh button in the header always refetches. The screen learns it became visible from the active flag MainShell passes it — IndexedStack keeps it alive, so nothing else would tell it.
  • AutoSyncService (lib/data/sync/auto_sync_service.dart) keeps an open app fresh: while it's in the foreground it re-syncs the current month on a timer, throttled to SyncSettings.autoSyncIntervalMinutes (Settings → Sync, default 5). It stops while backgrounded — there's no reliable way to wake a closed app on this schedule; closed-app refreshes are the background sync below. It's a ChangeNotifier as well as a WidgetsBindingObserver, because the screens IndexedStack keeps alive (Today, Calendar, Statistics) don't re-run their own load on a tab switch and need telling when fresh data landed behind their back.
  • Opening the app syncs today at once. On start, on every resume and — for a cold start, where the saved key is still being checked — the moment the session connects, AutoSyncService.syncToday() fetches today's wellness, activities and events, ignoring the interval and stale throttles (it still joins an identical fetch in flight). It does not stamp the month throttle, because today alone doesn't refresh the month.
  • Background sync (Android): "Keep syncing in background". lib/data/sync/background_sync.dart registers one WorkManager periodic job with NetworkType.connected and requiresBatteryNotLow. Its period is SyncSettings.backgroundSyncInterval (BackgroundSyncInterval: 15 min — WorkManager's minimum —, 1 h, 6 h, or nightly, the default). Nightly keeps the original shape: 24 h period, 3 h flex, so it runs between about 02:00 and 05:00 local time; the other intervals have no flex and no initial delay. BackgroundSync.apply() runs at every launch and after every change in Settings; it registers with ExistingPeriodicWorkPolicy.keep (so reopening the app never pushes the schedule back) and remembers the interval it scheduled (sync.background_scheduled_interval) — when the choice differs it cancels the old job first so the new period takes effect. Switching the toggle off cancels the job. BackgroundSyncRunner (the testable core, wired to real storage by BackgroundSyncRunner.live() in the background isolate — no app singletons are assumed loaded) syncs SyncService.todayWindow() — the Monday–Sunday week, plus Monday when today is Sunday — unless the cache was refreshed within the interval's freshFor (nightly 6 h, 6 h → 3 h, 1 h → 30 min, 15 min → 10 min), in which case it makes no request. The year-long events horizon is fetched on every nightly run, but at most every 6 hours on the shorter intervals. It restores the stored key itself; a network error keeps the key, a 401/403 does not. Outcomes and a consecutive-failure counter go to SyncSettings (Settings → Data & privacy → Sync shows the last run and result). The athlete is notified once after three failures in a row, and once when the key is rejected; the job always reports success to WorkManager so a dead network or revoked key is retried at the next scheduled run, not with backoff. "New data" notification: before and after the fetch the runner takes a BackgroundSnapshot of the cache — activity ids in the week window, and a fingerprint (date, type, name, description, planned load/time/distance, indoor) of every planned WORKOUT from today on (none when copying planned events is off). If the diff (BackgroundChanges) has new activities or new/changed sessions, it shows one localised notification (NotificationService.showBackgroundUpdate, id 6) — only when the master notifications switch is on, never on a failed or skipped run, never for a deletion alone, and never on the very first fill of an empty cache. The toggle is in Settings → Data & privacy → Sync (default on, nightly). Windows, iOS and web have no closed-app wake: the toggle is replaced by a note and sync stays foreground-only. A foreground service (to survive aggressive OEM battery savers) is not implemented; Settings instead hints at setting the app's battery usage to "Unrestricted".
  • Coming back to the app is the moment staleness is most visible (the athlete just finished a ride and opened TriIQ), so didChangeAppLifecycleState re-syncs the current month whenever the last sync is older than AutoSyncService.resumeStaleAfter (5 minutes) — independently of a longer configured interval. On a cold start the in-memory timestamp is empty, so the check falls back to SyncStateRepository's last_synced_at: relaunching inside the window doesn't cost a fetch the interval has already ruled out.
  • Creating a workout from Train now writes upstream and then pulls back down the whole month the session landed in (SyncService.syncMonth), plus the Today window when that reaches past the month's edge, and calls AutoSyncService.notifyCacheChanged() so the live Today and Calendar screens reload from the cache instead of waiting for the next timer tick.
  • The Sync screen (More → Sync) exposes the same scopes as manual buttons, showing the cached activities date range from SyncStateRepository.

The training agent

lib/agent/ is the chat brain: a LangChain.dart chat model, a set of tools over the local cache, and the loop that lets the model call them until it can answer.

File Role
llm_provider.dart, llm_model_entry.dart LlmProvider, and LlmModelEntry — one configured model (id, name, provider, model, base URL, enabled, vault key) with its JSON / backup forms and restoreModelEntries()
llm_settings.dart The ordered model list (priority) and each entry's key, persisted and shared with Settings; migration from the single-model app; the single-model API on the primary entry; consent per entry
llm_gateway.dart The one entry point for every LLM call (chat agent, session content, weekly-review sentence): tries entries in priority order with per-attempt timeouts and fails over
failover_policy.dart, model_health.dart Which failures fail over (pure table over LlmFailureKind), and the per-entry circuit breaker (2 failures → 5-minute cooldown)
model_connection.dart testModelConnection() — the free Test / Load models check for any provider (Claude GET /v1/models, Ollama /api/tags, OpenAI-compatible /models)
chat_model_factory.dart createChatModelFor(entry) builds an entry's BaseChatModel with the tools bound (ChatAnthropic / ChatOllama / ChatOpenAI), and classifyLlmError() maps every provider's exceptions to an LlmFailureKind. The only file that names a provider's chat model or exception types
openai_connection.dart OpenAI-compatible helpers: checkOpenAiBaseUrl() (https for any host, http:// only for localhost/private/LAN), isLocalServerUrl(), fetchOpenAiModels() (GET {base}/models), parseOpenAiModelList(), and LlmFailureKind (401/404/429/5xx/tools/unreachable). Used by Settings, onboarding, the factory and backup restore
ollama_connection.dart fetchOllamaModels() — hits /api/tags to test a URL/key and list real models. Used by Settings, not by the agent path
system_prompt.dart The standing instructions, plus the per-message runtime context block
tools/training_data_tools.dart The tools the model can call (with tools/season_tools.dart, tools/plan_assistant_tools.dart, tools/app_feature_tools.dart)
training_agent.dart The tool-calling loop and the event stream the Chat screen renders

Why the loop is hand-written. LangChain.dart 0.9 ships an AgentExecutor, but it drives a BaseActionAgent and the concrete implementations of that were provider-tied and are no longer in the package. Running the loop directly is ~40 lines, keeps the conversation in native ChatMessages (so each provider's own tool-call format is used instead of a stringified scratchpad), and lets partial replies stream to the UI. It stops after maxIterations (8) model turns and carries at most 40 messages of history, never cutting a tool result away from the assistant turn that asked for it — both providers reject an orphaned tool result.

Several models: the gateway and failover

The athlete keeps an ordered list of model entries (LlmSettings.entries, any mix of providers); the order is the priority. No caller builds a model itself: everything goes through LlmGateway — the agent loop via gateway.stream(), SessionContentGenerator and WeeklyReviewComment via gateway.invoke() (their outer 20 s / 15 s timeouts still bound the whole call).

  • Candidates: enabled entries in list order; entries in their cooldown move to the back (tried only as a last resort, so the trainer is never locked out), entries that already failed in this agent turn are left out. An entry whose host lacks consent is skipped without sending anything.
  • Attempt: createChatModelFor (an incomplete entry throws LlmNotConfiguredException before any request), then stream(). The first chunk must arrive within 90 s, each next one within 60 s — otherwise the SDKs' own 10-minute default would make failover useless.
  • Policy (FailoverPolicy, pure, tested as a table): fail over on unreachable / DNS / TLS / timeouts / 408, 429, 5xx incl. Anthropic's 529 "overloaded"; also — flagged needs attention — on a missing key/URL/model, 401/403, 404 (model or URL), "model can't use tools" and an unparseable reply. No failover (surfaced as is) on a cancelled request, a content-policy refusal, context length exceeded / 413, any other 4xx, and errors the classifier does not know (most likely our own bug) — those would repeat identically elsewhere and only cost money.
  • Circuit breaker (ModelHealth, in memory, per entry): 2 consecutive failover-worthy failures → skipped for 5 minutes; a success, Test in Settings or editing the entry's endpoint clears it.
  • Result: with exactly one failure its own exception is rethrown (a one-model setup reads exactly as before); with several, AllModelsFailedException lists each entry and reason, worded by describeAgentError ("No model answered. • Claude Sonnet: Can't reach…").

Mid-turn safety. Tools only run after a model call has completed, and they are read-only or create proposals the athlete applies by hand, so retrying the failed model call on the next entry with the same history repeats no side effect. The agent emits AgentModelAnswering(entry) before each attempt and AgentModelSwitched(from, to, reason, discardedText) on a switch; AgentReplyBuffer (used by Chat and Train now) drops the text streamed since the last AgentModelAnswering, so a half sentence is never followed by the full answer. The partial AIChatMessage is never added to history. The runtime context (provider/model, small-model hints) is built per entry, so the next model is told who it is. Chat shows a subtle note ("Switched to Ollama gpt-oss — Claude Sonnet: Can't reach the AI server") and an "answered by" chip under the reply (also as a Semantics label).

The tools read the cache, not the API. Answering a question costs no Intervals.icu round-trips and works offline. sync_from_intervals is the exception, and the model is told to reach for it only when get_athlete_context shows the dates it needs aren't cached; get_performance_curve also fetches, but only the first time a sport/metric is asked for or after a newer activity of that sport was synced.

Tool Returns
get_athlete_context Today's date, athlete identity, cached date ranges, and current thresholds per sport
get_daily_metrics Per day: CTL, ATL, TSB, ramp rate, resting HR, HRV, sleep, weight, subjective scores
get_plan_adjustments The current plan adjustments (missed sessions, week load, readiness conflicts) as proposals — the same keyed cards Today shows, so one Apply resolves both
get_weekly_review One Monday–Sunday week against its plan (defaults to the current one; week_of picks another) — load vs target TSS, time per sport vs weekly targets, planned / done / missed sessions and the key session, CTL change, form at week end, ramp-above-usual flag, readiness day counts, HRV / resting-HR direction and next week's target, phase, key sessions and races. The same WeeklyReviewSummary the weekly-review notification is composed from, so "how was my week" in chat and in the notification agree
get_readiness Today's readiness status, its reasons, each signal's value / baseline / rating and the missing-data state (HRV / resting HR: the smoothed value, today's raw reading, the median / MADσ baseline and how many baseline days it has) — computed by the same rules as the readiness ring on Today (lib/evaluation/readiness.dart)
get_activities Completed sessions with load, IF, HR, power, decoupling, RPE and time per intensity domain
get_planned_workouts Calendar entries: prescribed workouts, races, notes, illness markers
get_training_summary Weekly/monthly aggregates: completed vs planned load, per-sport totals, intensity split, CTL/ATL/TSB
get_training_guidance Matching sections of the optional bundled reference and every enabled document the athlete imported under More → Knowledge library, each tagged with the document it came from
get_performance_curve Best efforts per duration (power, HR) or distance (pace) for one sport — this season, last season, last 42 days — at fixed key points with the session that set each, the model fit (FTP/CP/W'/Pmax or critical speed/D') and its gap to the settings threshold. Fetches from Intervals.icu only when nothing is cached or a newer activity of that sport arrived
get_threshold_suggestions Current ride FTP / run / swim threshold-pace suggestions: current and candidate value, percent change, direction and what it's based on. Read-only — the agent explains a suggestion and points the athlete to Insights → Performance curves to review and apply it; it cannot apply or dismiss one itself
sync_from_intervals Fetches a date range into the cache
search_app_features Up to 5 app pages / settings matching a query (the same search as More's search field): id, localized title, breadcrumb path and the matching okf passage (docs, trimmed to ~600 characters, developer references stripped) — for "how do I… / where is…" questions
open_app_page A navigation offer for one destination id: the chat shows an "Open …" card under the reply, and the page opens only when the athlete taps it (an AgentNavigation event, like AgentProposal)
get_training_plan The saved goal, the load graph per week (proposed/target TSS, share, allowed range, phase, limits exceeded) and the current plan's weeks and sessions with their session_id
generate_training_plan A plan built by the engine from the goal (and any weeks / load factors / sport mix passed) — plus a proposal to take it
propose_load_curve A proposal for the load graph: week TSS or percent (inside each week's band), recovery weeks, plan length, sport mix, weekly increase (ramp_percent), hold weeks, reset — with the resulting graph, or an error naming the allowed range
propose_session_change A proposal to move a plan session to another date in the plan, or remove it (today onwards only)
get_session_template The template behind a plan session, and the block rules

Proposals, not writes. The three proposing tools never change anything: they register a proposal (lib/agent/plan_proposals.dart, in memory for this app run) and return its proposal_id. The agent loop then emits an AgentProposal event and the chat shows a card. Only the athlete's Apply makes the change, through PlanActions (lib/plan/plan_actions.dart) — Intervals.icu first, the local plan on success — or, for a plan, the same preview → Take as plan flow as the Plan screen. Each proposal records a fingerprint of the goal and plan it was made from; if either changed since, Apply refuses it as out of date. What the athlete did with each proposal is prepended to their next message so the model builds on the real state.

Threshold suggestions follow the same never-from-chat rule by a different route: get_threshold_suggestions is read-only, and there is no agent tool that writes a threshold — only the Performance screen's confirm sheet (Apply) does, through SportSettingsService (lib/data/sport_settings_service.dart). It's the first TriIQ write that changes Intervals.icu settings rather than calendar data, so the payload is deliberately minimal (only the one changed field) — see Insights → Performance curves above for the full flow and why that's safe.

Thresholds are a case worth calling out: they aren't cached in their own right, but every activity carries the FTP/LTHR/max-HR/pace and zone boundaries that were in force when it was analysed, so the newest activity per sport is the athlete's current setup — no extra API call needed.

Tool results are JSON with nulls and empty collections stripped: an activity has ~180 possible fields and shipping the empty ones would cost more context than the data. Bad arguments (a malformed date, a range longer than the tool returns) come back as an error string rather than an exception, because a sentence is something the model can read and retry around. Every tool caps its range, and get_activities caps its row count, so one call can't blow the context window.

Intensity distribution is the one derived figure. Intervals.icu reports time-in-zone against the athlete's own 3–7 zone setup; the tools fold that into the three-domain model the training reference uses (low / moderate / high), preferring power zone times, then heart rate, then pace. Sessions with no zone data at all are counted separately rather than silently dropped, and a bucket where nothing had zone data says the distribution can't be checked — an 80/20 answer computed from load alone would be invented.

The system prompt

Two system messages per request. The first, trainingAgentSystemPrompt, is fixed and deliberately about epistemics rather than physiology:

  • Never state a number that didn't come from a tool in this conversation — no estimates, no remembered examples, no filling gaps with typical values.
  • Call get_athlete_context first. Never assume today's date or the athlete's thresholds.
  • Ask for the smallest range, and prefer the summary tool over raw activities.
  • Name the gaps — missing wellness days, rides without power, sessions without zone times — rather than answering as if they weren't there.
  • Read the metrics carefully: CTL is context, not a target; TSB is not an overtraining diagnostic; ramp rate has no universally safe value; load isn't comparable across sports; a single day of HRV means little, and only a convergence of signals over several days does.
  • Answer short: lead with the answer, then the evidence with units and dates, one recommendation, inference labelled as inference.
  • Boundaries: not a doctor; symptoms, suspected injury, disordered eating or low energy availability go to a professional.

The physiology itself is not in the prompt — it lives in assets/knowledge/training-philosophy.md (an optional, user-supplied asset that is not in the repository; see assets/knowledge/README.md) and/or whatever the athlete imported under More → Knowledge library — reached through get_training_guidance. That keeps it editable without touching code, and keeps a long reference off every single request, which matters most for the small local models Ollama users run. With neither installed nor imported, the tool says so and mentions where to import one. Every match carries the title of the document it came from, and the prompt tells the model to name it (especially an imported one, so the athlete can tell it's their own material) and to treat the returned text as information to read, never as instructions — imported documents are athlete-supplied and therefore untrusted the same way any other tool result is.

The second message, buildRuntimeContext, is regenerated per message and carries today's date and weekday, the athlete identity, whether Intervals.icu is connected, which ranges are cached, and the active provider/model. On Ollama it appends a note to keep tool arguments strict — small local models drift there far more than Claude does. The rule for the OpenAI-compatible provider: the same note is appended only when its base URL is local (isLocalServerUrl: loopback, private RFC 1918 / link-local address, single-label host or .local/.lan/.home.arpa/.internal name — LM Studio, llama.cpp on the LAN), not for a hosted service (OpenAI, OpenRouter…). The caller passes localModel: entry.isLocal for the entry being asked (the context is rebuilt per failover attempt).

Credential storage

SecureKeyStore (lib/data/secure_key_store.dart) wraps flutter_secure_storage and is the only place a secret is written. One named secret per instance:

Vault name Secret
intervals_api_key Intervals.icu key / OAuth token
llm_model_key_<entry id> The API key of one model entry added in Settings (Claude, Ollama Cloud, OpenAI-compatible — optional for the last)
claude_api_key, ollama_api_key, openai_api_key The single-model app's keys; the entry an existing install was migrated into keeps using its provider's name (LlmModelEntry.legacyKey), so nothing is copied

LLM keys are cleared by Delete all data (LlmSettings.eraseAllKeys: every entry's plus the three old names), deleted with their entry, never in shared_preferences, never in a backup, never logged. Non-secrets — the ordered model list with providers, names, model names and URLs (llm.models) — go to shared_preferences instead, because encrypting a hostname buys nothing and the vault is the thing most likely to be unavailable. Each platform gets the OS credential vault rather than a file or shared preferences, and the ciphertext is bound to this app and this OS user:

Platform Backend
Android EncryptedSharedPreferences — AES-256-GCM under an Android Keystore key (encryptedSharedPreferences: true; off by default in the plugin, which would otherwise use its own older scheme). App backup is disabled (android:allowBackup="false" plus res/xml/data_extraction_rules.xml) because a Keystore-encrypted blob restored onto another device cannot be decrypted anyway
Windows Credential Manager (CredWriteW), DPAPI-encrypted under the logged-in Windows account
iOS Keychain, kSecClassGenericPassword, with first_unlock_this_device accessibility (readable after the first unlock since boot, never migrated to another device) and synchronizable: false (no iCloud Keychain)
Web nothing is persisted — see below

Reads, writes and deletes never throw. A vault can be unavailable, locked, or hold ciphertext that no longer decrypts (Keystore reset); all of those surface as "nothing stored", because the recovery is always the same — ask the user for the key again.

On web the key is held in memory for the lifetime of the tab and nothing is written to browser storage. Browsers have no keychain equivalent: flutter_secure_storage's web backend AES-GCM-encrypts the value into localStorage but stores the raw AES key in localStorage beside it, so anything that can read one can read the other — obfuscation, not storage security, against XSS, a malicious extension, or anyone with devtools open. A HttpOnly cookie would be the real answer, but that needs a backend to set it and the app talks to Intervals.icu directly. Profile's help text changes to say so when IntervalsSession.remembersApiKey is false.

LLM providers and the model list

LlmSettings holds List<LlmModelEntry> (pref llm.models, JSON): id, name (optional display name), provider, model, base_url (Ollama / OpenAI-compatible), enabled, legacy_key. Order = priority (see the gateway above). Per entry: problemOf() (missing key / unusable URL / no model), isUsable() (enabled and complete), isConsented() (consent covers its host). hasProvider = some usable entry; isConfigured = some usable and consented entry; needsConsent = some usable entry awaits consent (card shows); blockedByConsent = nothing usable is consented (chat cannot send).

  • Migration (first load() without llm.models, idempotent because the list is then written): the old llm.provider, that provider's model and URL become one entry primary with legacy_key: true, so its key is read from the old vault name — no visible change. A fresh install gets the same thing the old app showed (Claude, no key). An existing consent is recorded as covering that entry's host (adoptLegacyConsentHosts).
  • Single-model API: provider, activeModel, claudeModel, setOllamaBaseUrl, setOpenAiApiKey… read/edit the primary entry (the first), or the first entry of that provider; setProvider switches the primary entry's provider (defaults + that provider's old vault name). Onboarding uses it, so its simple one-model setup edits the first entry.
  • Consent per host: PrivacySettings records the third-party hosts the consent was given for (privacy.ai_consent_hosts, device-only, never in a backup). askAiConsent names every usable entry still waiting (one name as before, or a list "Claude (Anthropic) (api.anthropic.com), Ollama Cloud (ollama.com) and …"), and records all usable entries' hosts. Adding, enabling or editing an entry onto an uncovered third-party host asks right away; until then that entry is skipped and the card shows. Local hosts (isLocalServerUrl) are covered by the consent itself. Withdrawing clears all hosts.
  • Backup: llm.models is exported as toBackupJson() (no ids, no vault names, no keys). restoreModelEntries drops entries whose URL fails checkOpenAiBaseUrl (Ollama included), assigns fresh ids, and reuses an on-device entry's id/key only for the same provider + URL + model, so a file can never steer a stored key to another host. The old llm.openai_base_url / llm.openai_model no longer travel. A reload after restore deletes the keys of entries that went away.

OpenAI-compatible provider

LlmProvider.openai talks to any server that speaks the Chat Completions API (OpenAI, OpenRouter, Azure-style proxies, LM Studio, vLLM, llama.cpp's server, LiteLLM…) through langchain_openai's ChatOpenAI(baseUrl, apiKey, defaultOptions: model, temperature 0.2, tools). Per model entry (editor): Base URL (default https://api.openai.com/v1), Model name (free text, default gpt-4o-mini; Load models does GET {base}/models and replaces the suggestion chips with the server's list) and an optional API key (vault, the entry's key). A single-model install's llm.openai_* values and openai_api_key became its migrated entry.

  • URL rule (checkOpenAiBaseUrl): https:// for any host; http:// only for localhost, private/LAN addresses and local names (Settings shows the plain-text warning); http:// to a public host, a URL with user:pass@ or a malformed URL is rejected with a message, hasProvider is false and createChatModel throws LlmNotConfiguredException. The key goes only to the configured URL, never logged, and is omitted when empty (no Authorization header).
  • Consent / privacy: it counts as a third-party cloud provider unless the host is local (LlmSettings.isOpenAiLocal). The consent dialog and card name the host ("llm.example.com (an OpenAI-compatible service)") with the usual wording; for a local host they say "your local model server (192.168.1.5)" and that the data stays on the network (pvConsentDialogBodyLocal).
  • Tool calling is assumed. If the server rejects tools (a 400/422 that mentions tools or functions) the chat shows "This model can't use tools" with advice to pick another model, instead of a raw exception. Reasoning models (o…, gpt-5…) get no custom temperature, which they reject.
  • Errors: classifyLlmError maps openai_dart exceptions and describeError words them for this provider: 401/403 → key, 404 → base URL or model, 429 → rate limit/quota, 5xx → server trouble, no answer → unreachable. The chat screen uses the same text (describeAgentError).
  • Backup: as part of the model list (see above) — URL and model travel, the key never; a restored URL must pass the same check. session_content.dart and the weekly-review note go through LlmGateway, like the chat.

Ollama: cloud vs. local, and the connection test

LlmSettings.defaultOllamaBaseUrl is https://ollama.com (Ollama Cloud), not a local server — isOllamaCloud checks the URL's host and is what Settings and isConfigured key off of. Cloud needs the API key from ollama.com/settings/keys (Settings has a "Get a key" link straight there, shown only when isOllamaCloud); pointed at a local/self-hosted server instead, no key is needed and isConfigured doesn't require one.

Unlike Claude — whose only cheap way to validate a key is spending tokens on a real message, so its key just gets saved unconditionally — Ollama's /api/tags is a free connectivity check. fetchOllamaModels() (ollama_connection.dart) calls it, so Settings can: - test before saving: pressing "Save key" tests first and only persists the key if /api/tags succeeds — a bad key is never stored, same principle as IntervalsSession.connect; - list real models: a successful test replaces the static suggestion chips (LlmSettings.ollamaModelSuggestions, headlined by the default, gpt-oss:120b) with whatever the server actually reports, via map['model']/map['name'] from each entry in the response; - "Test connection": a separate button runs the same check without saving anything, for a local server (no key to save) or to refresh the model list later. Settings also fires this silently (no error surfaced) once on open if a connection already looks configured, so a returning visit shows live models without the user pressing anything.

An empty-but-200 response (server reachable, nothing pulled yet) is treated as success, not failure — the distinction that matters here is "reachable" vs. "not", not "has models".

Sync verification

test/sync_live_test.dart runs the real thing against the live Intervals.icu API — connect, sync, then read back out of SQLite rather than trusting the in-memory result — and covers the full-history "Everything" sync. It skips unless a key is passed, so plain flutter test stays offline:

flutter test --dart-define=INTERVALS_API_KEY=<key>

Sync is verified working on Windows: a full-history sync of the test account pulled 586 activities and 413 wellness records into SQLite, and re-syncing a range updates rows in place rather than duplicating them (primary keys are the activity id and the wellness date).

Local storage

SQLite via sqflite (Android native) + sqflite_common_ffi + sqlite3_flutter_libs (Windows). Schema v2 (wellness, activities, events, sync_state); v1 caches upgrade in place by creating events empty. See lib/data/db/app_database.dart for the storage-path logic (desktop: ./triiq.db in the process's working directory; mobile: app documents directory; web: unsupported, throws).

Schema (version 1):

CREATE TABLE wellness (
  date TEXT PRIMARY KEY,     -- ISO day, e.g. 2026-08-30
  ctl REAL,
  atl REAL,
  ctl_load REAL,
  atl_load REAL,
  ramp_rate REAL,
  raw TEXT NOT NULL,         -- full Wellness API response as JSON
  synced_at INTEGER NOT NULL
);

CREATE TABLE activities (
  id TEXT PRIMARY KEY,
  date TEXT NOT NULL,        -- start_date_local, truncated to the day
  type TEXT,
  name TEXT,
  moving_time INTEGER,
  distance REAL,
  training_load INTEGER,     -- Intervals.icu's TSS-equivalent for the activity
  raw TEXT NOT NULL,         -- full Activity API response as JSON
  synced_at INTEGER NOT NULL
);
CREATE INDEX idx_activities_date ON activities(date);

CREATE TABLE sync_state (
  scope TEXT PRIMARY KEY,        -- 'wellness' | 'activities'
  oldest_synced TEXT NOT NULL,
  newest_synced TEXT NOT NULL,
  last_synced_at INTEGER NOT NULL
);

Later versions add tables without migrating data (each upgrade creates the new table empty): events (v2), plans / plan_sessions (v3), activity_streams (v4), performance_curves (v5: one row per sport|metric holding the raw curves response, the newest cached activity id of that sport at fetch time — a different newest id means stale — and fetched_at) and knowledge_docs / knowledge_sections (v6: the knowledge library — see below). Curves are fetched with a raw GET /api/v1/athlete/0/{power,pace,hr}-curves.json?type=…&curves=s0,s1,42d through the client's dio rather than the generated listAthlete*Curves, which demand three filter lists and deserialize strictly.

Every cached row keeps the full API response in raw (JSON), so new UI features can read additional fields without a schema migration — only promote a field to its own column when it needs to be queried/filtered on.

Knowledge library (knowledge_docs, knowledge_sections, v6) holds the athlete's imported coaching documents, nothing from Intervals.icu: one row per document (title, file_name, imported_at, enabled, byte_size) and one row per heading-delimited section (doc_id, position, title, body), split once at import (lib/agent/knowledge_sections.dart, splitGuidanceSections — shared with the bundled-reference loader so both follow the same heading rule) so search stays cheap. okf-* fenced blocks are stripped at import (stripOkfFences) and never stored: imported documents are agent-only and can never reach the plan engine. See lib/data/repositories/knowledge_library_repository.dart and the Training agent and More sections below.

Theming

lib/app.dart defines one Material 3 theme spec — built twice, for Brightness.light and Brightness.dark — from a single seeded ColorScheme and shared component styling (rounded cards/inputs/nav bar/buttons). UI code should pull colors from Theme.of(context).colorScheme rather than hardcoding Colors.*.

Which one is active is controlled by ThemeController (lib/theme_controller.dart), a singleton ChangeNotifier holding a AppThemeChoice (system | light | dark | developer, default system; developer is a terminal-style theme — black, monospace, green/amber/cyan, square corners — served as the dark theme). TriiqApp wraps MaterialApp in a ListenableBuilder on it, so changing the mode (from Settings → App → Appearance) re-themes the whole app immediately. The choice is persisted in shared_preferences (theme.choice) and loaded at startup in main.dart.

App icon

assets/icon/ holds the source design — hand-authored SVG, not a third-party asset: - icon.svg / icon.png (1024×1024, full-bleed) — a white heartbeat/pulse glyph on the same primary → tertiary diagonal gradient (#6750E4 → #F45B8D) used for the hero cards on Today/Profile. Used as the source for iOS, Windows, and web. - icon_foreground.svg / icon_foreground.png (1024×1024, transparent) — the same glyph scaled down so it stays inside Android's adaptive-icon safe zone (the center ~66%, since circular launcher masks crop the most). Paired with adaptive_icon_background: "#6750E4" (solid, not the gradient — Android's parallax effect on adaptive-icon layers reads badly with gradients, so this is a deliberate simplification for that platform only).

Platform assets (Android mipmap/drawable + colors.xml, iOS AppIcon.appiconset, Windows app_icon.ico, web icons/ + favicon.png + manifest.json) are generated, not hand-edited — from the PNGs, via flutter_launcher_icons (config lives under the flutter_launcher_icons: key in pubspec.yaml). The PNGs are rendered from the SVGs with sharp (Node; a local install, not a project dependency — no Dart-ecosystem SVG rasterizer was available). There's no macos/ or linux/ platform folder in this project currently, so those icon targets are skipped; re-run dart run flutter_launcher_icons after any of: - editing assets/icon/*.svg (re-render to PNG first — see below), - adding those platform folders back, - flutter create . regenerating platform folders (it resets icons to the Flutter default).

To re-render the PNGs after editing an SVG (from the repo root, with Node available):

node -e "
const sharp = require('sharp');
sharp('assets/icon/icon.svg', {density: 384}).resize(1024,1024).png().toFile('assets/icon/icon.png');
sharp('assets/icon/icon_foreground.svg', {density: 384}).resize(1024,1024).png().toFile('assets/icon/icon_foreground.png');
"
dart run flutter_launcher_icons

(npm install sharp first, in whatever directory you run that from — it doesn't need to be inside this repo.)

Notifications

lib/notifications/ — sync completion, agent replies, and a daily training reminder. Same per-platform-backend pattern as SecureKeyStore, because no single plugin covers this app's platforms:

  • notification_service.dart — NotificationService.instance picks the backend at construction: flutter_local_notifications on Android/iOS (all three notification kinds, including the daily reminder — scheduled through the OS alarm system via zonedSchedule, so it fires even with the app closed); local_notifier on Windows (immediate notifications only — sync/agent — since there's no reliable way to wake a closed desktop app on a schedule without native work well beyond this feature's weight); a no-op elsewhere (web). supportsScheduledReminder tells the UI whether to offer the reminder toggle at all.
  • The daily reminder's "local time" is a tz.Location built from DateTime.now().timeZoneOffset at init, not a real IANA zone — flutter_timezone, the obvious package for that, currently fails to build on Android under this project's AGP version (a project-evaluation-order clash in its Gradle setup). A fixed offset is wrong only in the narrow window right as DST flips, self-correcting on the next app start, which is an acceptable trade against a dependency that doesn't build. Worth revisiting if a fixed version resolves it.
  • notification_settings.dart — NotificationSettings.instance (ChangeNotifier + shared_preferences, same shape as the non-secret half of LlmSettings): whether notifications are enabled at all, and the daily reminder's enabled flag + time.
  • app_lifecycle_tracker.dart — a WidgetsBindingObserver registered in main(), so isForeground is readable from plain Dart code. The agent- reply notification only fires when this is false — otherwise the reply is already visible in the chat bubble and a notification would just be noise.
  • Settings → App → Notifications**: the master toggle calls requestPermission() (the actual OS prompt on Android 13+/iOS; a no-op true elsewhere) before persisting enabled; a denied prompt leaves the toggle off with an explanatory SnackBar. The daily-reminder sub-toggle and time picker only render when both enabled and supportsScheduledReminder are true.
  • Trigger points: SyncScreen._run() fires showSyncComplete after a manual sync; ChatScreen._finish() fires showAgentReply when a reply completes without error, the app isn't foreground, and notifications are enabled. BackgroundSyncRunner (Android background sync, see Sync & local cache) fires showBackgroundUpdate — text composed and localised by the caller via lookupAppLocalizations, since the background isolate has no widget tree — when a run brought new activities or new/changed planned sessions, and showSyncProblem after repeated failures or a rejected key; both only with the master toggle on.

  • Weekly review (weekly_review_notification.dart): mirrors the morning briefing. WeeklyReviewScheduler.refresh() runs at start, from _keepBriefingFresh (syncs, plan changes, settings changes) and after the nightly background sync; it loads WeeklyReviewSummary from the cache, composes the text with lookupAppLocalizations (no BuildContext, so it works in the background isolate) and arms one notification (id 7, weekly_review_channel, big-text style) at the next chosen weekday/time, or cancels it when it is off, the master toggle is off, or the week has nothing done or planned. A review due Friday–Sunday covers that week; Monday–Thursday covers the week before. nextDue builds the date from calendar fields and the mobile service schedules it as a UTC instant, so it stays on the chosen wall-clock time across a DST change (the morning briefing now uses the same _instant conversion). Settings: notifications.weekly_review, _weekday (default 7 = Sunday), _hour / _minute (19:00), _comment (trainer sentence, off). The trainer sentence (WeeklyReviewComment) is only asked for within 48 h of the due time, cached per figures, and dropped on any error or after 15 s. Tap routing: the notification carries the payload weekly_review:<monday>; NotificationTaps (notification_taps.dart) receives it from onDidReceiveNotificationResponse or the launch details, and main.dart pushes WeeklyReviewScreen(initialWeek: …) through rootNavigatorKey. Windows can't schedule, so showsMissedOnStart is true there: on refresh, if the last due time passed since it was last shown (notifications.weekly_review_last_shown), it is shown at once (clicking it opens Weekly review); switching it on only records the moment, so an older review never pops up. Web: no-op.

Android manifest additions this needed: POST_NOTIFICATIONS (the permission the runtime prompt is asking about), RECEIVE_BOOT_COMPLETED plus flutter_local_notifications's two receivers (so the reminder alarm survives a reboot), and android/app/build.gradle.kts needed isCoreLibraryDesugaringEnabled = true + a coreLibraryDesugaring dependency (flutter_local_notifications requires it). The reminder is scheduled inexactAllowWhileIdle specifically to avoid needing SCHEDULE_EXACT_ALARM, a user-granted special permission that's overkill for a training reminder's precision needs.

Not yet done: Windows build untested (Android is — a debug APK with this feature builds and the manifest/Gradle changes above are what made it work); iOS untested on either count, consistent with iOS's general status in this repo (builds, isn't a focus).

Activities

lib/screens/activities/ — the full activity list and the detail view, both reading straight from the SQLite cache (no separate network call).

  • activities_screen.dart — ActivitiesScreen: ActivitiesRepository.getAll() (added alongside the existing getByDate/getRange), most recent first, rendered as ListTile rows rather than a literal DataTable — a table widget doesn't fit this app's card/list visual language or a phone width, and a ListTile row (icon, name, date · distance · duration, trailing TSS) carries the same information at a glance. A search field in the app bar narrows by name as you type (250 ms debounce); the options icon opens filters (sport, this week / this month / last 3 months / custom dates, distance and duration ranges, has power, has GPS) and sort (date, distance, duration, load). Active filters show as removable chips with the result count. All of it is ActivityFilter (activity_filter.dart), applied to the local cache only. Tapping a row pushes ActivityDetailScreen.
  • Year per sport — YearStatsService (lib/evaluation/year_stats_service.dart) is the single source of "this year per sport" for the Calendar header peek, the activity detail's This year card (year_sport_widgets.dart: YearSportCard, YearContextLine) and the context lines: it reads the cached activities of the year and the one before plus the sync coverage once per (year, day), keeps the result in memory (YearSnapshot: YearStats + light StatRows for ranking) and forgets it — notifying its listeners so open cards reload — when AutoSyncService.notifyCacheChanged or a sync announces a cache change. The peek asks for a fresh read. Pure maths: lib/evaluation/period_stats.dart.
  • activity_detail_screen.dart — ActivityDetailScreen(activity: LocalActivity). Layout: a summary header (name, date, sport, key figures) above a pinned tab bar — Overview (verdict against the plan, stat grid, zones, brick, insights), Charts (session diagram + effort profile), Intervals (the one interval table; tapping a row jumps to Charts zoomed to it — only for run/ride/swim) and Map (outdoor runs/rides). Compare sits in the app bar; "How did it feel?" and "Open intervals.icu" in its overflow menu. From 900 px wide the tabs give way to two columns (overview | charts, intervals, map). The chart and the interval table share one ChartViewport; the diagram no longer repeats the interval list. LocalActivity only promotes a handful of fields to SQLite columns (see Local storage); this screen needs far more (HR, power, elevation, zone times), so it calls LocalActivity.toActivity() — Activity.fromJson(raw) — to get the entire API response back as a typed Activity, rather than either widening the schema or hand-parsing JSON keys. _StatGrid builds its tiles from whichever of those fields are actually non-null (a swim has no power, a strength session has no distance), and _ZoneTimeChart is a small hand-rolled horizontal-bar widget — this app has no charting package, and one bar shape didn't justify adding one — fed from icuZoneTimes (self-labelled) falling back to icuHrZoneTimes (plain seconds-per-zone, labelled generically Z1..Zn) when present.
  • Open in Intervals.icu: launchUrl('https://intervals.icu/activities/{id}', mode: LaunchMode.externalApplication) via url_launcher. Deliberately externalApplication, not the default: that mode hands the link to the OS the same way tapping it anywhere else would, so it opens the Intervals.icu app if one's installed and registered for that link (Android App Links / iOS Universal Links), and the browser otherwise — this app doesn't need to know which.
  • Fatigue & soreness: a button next to Open in Intervals.icu opens showFeelDialog (feel_dialog.dart) — two 1-4 fields, "1 good, 4 bad", prefilled from the activity's day's cached wellness when already set. Saving calls WellnessActions.setFeel, a partial PUT /wellness/{date} that only touches those two fields, then refreshes the local wellness cache from the response so Readiness picks it up without a resync. Needs an Intervals.icu connection (Wellness lives only there); the button is disabled otherwise. Settings → Fatigue & soreness (FeelSettings, on by default) controls whether this dialog also opens by itself the first time a recent (today or yesterday) activity's detail screen opens, when that day has nothing set yet — shown at most once per activity (FeelPromptStore, the ids already prompted), regardless of whether it's saved or cancelled. Turning that setting off only stops the automatic prompt; the button keeps working.
  • Reached from Insights → Activities, from tapping any activity in Today's "Today's activities" card (_TodayActivities in today_screen.dart), and from a sport row on Statistics, which passes ActivitiesScreen(initialType: ...) to open the list filtered to that sport. The filter is in-memory over the cached rows and shows as a chip under the app-bar title; clearing the chip goes back to every sport.
  • activity_icons.dart — shared formatting/icon helpers (activityTypeIcon, formatIsoDate, formatDurationSecs, formatDistanceMeters) used by both screens and by Today, so the three don't drift.
  • Insights (lib/evaluation/insights.dart, lib/screens/insights/). personalBests(raw) reads icu_achievements defensively (unknown shapes are dropped, a power best needs its duration); efficiencyTrend compares an easy session's icu_efficiency_factor with the median of the same sport's easy sessions over the last 42 days (needs ≥ 4); recoveryHint maps TSS to hours via the knowledge recoveryHours bands, adds 12 h when form is below recoveryFormPenaltyBelow, caps at 72 h and flags a conflict when recovery runs past 10:00 tomorrow and tomorrow's planned session is hard (only for today's session). SessionInsightsLoader gathers the inputs; InsightsCard renders them under the diagram on ActivityDetailScreen, which also marks today's session as seen.
  • New-training pop-up. AutoSyncService.openSyncDone fires after the today-sync run on start, connect and resume (not after periodic syncs). NewTrainingTrigger (wrapping MainShell) then asks NewTrainingInsights.unseenToday() — today's activities minus SeenSessionsStore (prefs insights.seen, today's ids only, reset on a new day) — and, if any and the shell's route is current, shows NewTrainingSheet: one page per session, newest first, with the evaluation and insights. Closing it marks every shown session as seen. Details opens the activity; Find alternative (recovery conflict) opens Train Now for tomorrow (TrainNowScreen(today: ...)).

Charts

There is no charting package. The shapes the app needs all live in lib/widgets/charts/:

  • SimpleBarChart (bar_chart.dart) — vertical bars with an optional translucent "ghost" bar behind each one for a target, tap/drag selection, and an x-label every n-th bar. Used for daily TSS (42 bars, weekly labels) and weekly completed-vs-planned load.
  • MetricLineChart (line_chart.dart) — one or more series on a shared y-scale, with gridlines and their values, an optional filled area under the lead series, an optional rule at zero (Form and ramp rate cross it), and selection. null entries are gaps, not zeroes: a day with no wellness record is not a day of zero fitness, and joining across it would draw a slope that never happened. ChartLegend renders the key.
  • RadarChart (radar_chart.dart) — a spider chart for Durability: one spoke per axis, rings at 25/50/75/100 %, one filled polygon per RadarSeries (colour + dash pattern + RadarMarker, so never colour alone). Values are 0..1 of the outer ring (above 1 is clamped to the ring; the tooltip shows the real figure); null is a gap: the outline breaks and the point is omitted, and an axis with no data in any visible series is labelled "no data". Colours and label style come from ChartTheme, so light, dark and Developer themes follow. The draw-in animation is skipped under reduced motion. Tap/hover reports a RadarSelection (vertex or nearest spoke); the screen shows the value, share kept and source session below the chart. The semantics label summarises each level ("After 2000 kJ: 5m 92 %, …"); the legend entries are 48 dp toggle buttons. DurabilityLevel.sources carries the session each best value came from.
  • DurationCurveChart (duration_curve_chart.dart) — performance curves on a log x-axis (duration for power/HR, distance for pace) with fixed ticks, axis titles with units, several periods as series, and tap/drag selection that snaps to the nearest point. Pace is plotted as speed so faster sits higher and labelled back as min/km or min/100 m. Points are thinned to ~200 log-spaced buckets (downsampleLog) before painting.

  • ChartTheme (chart_theme.dart) — the one chart theme object: every chart above (and the stream chart, load curve editor and heatmap) takes its grid, axis, label style, tooltip, brush, categorical and heat-ramp colours from ChartTheme.of(context), derived from the active ColorScheme plus the text theme's font (so the Developer theme's monospace reaches the axis labels) and the platform's reduce-motion flag. HeatScale.theme / HeatScale.viridis are its heat ramps.

  • ChartOverview (chart_overview.dart) — the D3 focus + context strip: the whole series as a thin line with the visible window over it; horizontal drag brushes a new window, drag inside moves it, tap centres it. Built on ChartViewport.

MetricLineChart extras (all opt-in or invisible to existing callers): mouse hover shows a crosshair — vertical rule, a dot per series, a multi-series tooltip and the x value as a chip on the axis — without changing the selection; overview: true adds the context strip; brushZoom: true lets hold-and-drag on the plot brush a range to zoom to (ChartInteraction.brushable; off by default because some cards open their options on a hold); hiddenSeries + ChartLegend(hidden:, onToggle:) make the legend toggle series; series draw in left to right one after another on first show (animate, skipped under reduced motion), with averages and extremes fading in after. Training analytics' per-sport fitness chart uses the overview and the toggling legend.

A package would be a dependency, a theme to fight and a licence to check for something that is a few dozen lines of CustomPainter either way. All take their colours from the active ColorScheme, so they follow the app theme (and dark mode) without a second palette to maintain. The older _ZoneTimeChart on the activity detail screen predates these and stays where it is — it's a horizontal one-off.

Load metric screens

Every tile on Today opens something:

Tile Opens Shows
TSS today TssHistoryScreen 42 daily bars, completed against planned, with total / avg per day / avg per week
TSS week WeeklyLoadScreen 12 weekly bars, completed against planned, this week's total, 12-week average, 4-week trend
CTL, ATL, Form, Ramp MetricHistoryScreen(metric:) the metric over 30/90/365 days as a line (CTL and ATL charted against each other), with current / change / average / low–high, and a plain-language note on what the metric does and doesn't say

MetricHistoryScreen is one screen for four metrics (LoadMetric), and Form is derived (CTL - ATL) rather than stored — Intervals.icu doesn't return a TSB field. The range picker changes only what is charted; nothing on these screens fetches, so they are instant and work offline.

Creating workouts on Intervals.icu

IntervalsWorkoutService (lib/data/intervals_workout_service.dart) is the only place in the app that creates something upstream — everything else syncs downwards — which is why it sits apart from SyncService. It POSTs an EventEx (category: WORKOUT, today's date at local midnight, sport, name, description, duration, load) via createEvent(upsertOnUid: false).

The workout itself goes in description in Intervals.icu's native step syntax (- 15m 60%, 3x, …), which Intervals.icu parses server-side into a structured workout; anything it can't parse it keeps as the session's description, so an odd line degrades to a note instead of failing the request. The app deliberately does not try to validate that syntax locally.

Getting there from a prose proposal is two steps, in TrainNowScreen:

  1. workoutStructuringPrompt (lib/agent/workout_draft_parser.dart) asks the same agent conversation to re-express what it just proposed as one JSON object, with the workout in step syntax. A second turn rather than part of the original prompt: the athlete reads the prose first and only pays for this if they decide to keep it.
  2. parseWorkoutDraft locates the JSON object in the reply — models wrap it in prose or a code fence more often than not, so it scans for the outermost {…}, tracking brace depth and ignoring braces inside strings — and returns null rather than a guess when there's nothing usable.

The draft is then shown in full (name, targets, every line of the workout) in a bottom sheet before anything is written: creating an entry in someone's training log isn't undoable from this app, and the step syntax is the agent's work, not the athlete's. After a successful create, the Today window is re-synced so the new session appears immediately.

3. User documentation

Connecting your Intervals.icu account

Log in with Intervals.icu (Android and Windows): tap the profile icon (top-right) → Log in with Intervals.icu. Your browser opens Intervals.icu's page asking you to allow TriIQ (activities, wellness, calendar and settings, read and write where the app writes back); agree and the browser returns to the app, which is then connected. TriIQ never sees your password and stores no client secret: the login uses OAuth with PKCE (lib/data/oauth/). The same button is on the Connect step of the first-run flow. Saying no in the browser just cancels. On the web preview and iOS only the API key is offered.

Or with an API key:

  1. Tap the profile icon (top-right).
  2. Find your API key on intervals.icu under Settings.
  3. Paste it into Intervals.icu API key and tap Connect. This validates the key live against Intervals.icu (an actual data fetch, not just a format check) and shows your athlete name once successful. Only a working key is saved — a rejected one is never written to storage.
  4. Once connected, the key is remembered in your operating system's own credential store (Keystore-encrypted storage on Android, Credential Manager on Windows) across app restarts — the app re-validates it on every launch and reconnects automatically. Disconnect clears both the session and the saved key (or token — for an OAuth login it also removes TriIQ from your connected apps at Intervals.icu). Profile says which way you are connected.

How the browser login is wired. IntervalsOAuth builds https://intervals.icu/oauth/authorize?client_id=…&redirect_uri=…&scope=…&state=…&code_challenge=…&code_challenge_method=S256 (the verifier is 64 URL-safe characters, S256 is the only method Intervals.icu supports), opens it with url_launcher, waits for the redirect (?code=…&state=…, or ?error=access_denied), checks state, and within two minutes POSTs form data client_id, code and code_verifier — no secret, as for a public client — to https://intervals.icu/api/oauth/token. The answer (token_type, access_token, granted scope, athlete {id, name}) gives the bearer token (AccessToken scheme of the generated client); API calls use 0 as the athlete id, which means the token's athlete. Disconnect sends DELETE /api/v1/disconnect-app with the token. The redirect comes back differently per platform: Android registers triiq://oauth/callback in the manifest and MainActivity passes it to Dart over the triiq/oauth channel; Windows listens on http://127.0.0.1:<free port>/callback while the login is open (Intervals.icu ignores the port of a registered localhost redirect).

One-time setup at Intervals.icu (as the athlete who owns the app, on the app's management page): the app must be approved (it shows "Pending" until then and the flow does not work), flagged a public client, and have these redirect URIs registered exactly: triiq://oauth/callback and http://127.0.0.1/callback. "Require PKCE" can be ticked, since every build uses PKCE. The client id is 1727; a build can use another client or redirect with --dart-define=INTERVALS_CLIENT_ID=… and --dart-define=INTERVALS_REDIRECT_URI=…. The token is stored like the API key (Keystore-encrypted storage / Credential Manager), is only saved after it has loaded the athlete profile, and is dropped when Intervals.icu answers 401/403. Scopes requested (WRITE implies READ, so each at the level the app uses it): ACTIVITY:READ (activities, power and pace curves), WELLNESS:WRITE (wellness and the fatigue/soreness written back), CALENDAR:WRITE (planned workouts and events), SETTINGS:WRITE (athlete settings, and the thresholds you apply from a suggestion). The athlete can untick scopes on Intervals.icu's page; the features that need a missing one then fail with a 403. In the browser build the key is only kept for that tab: browsers have no comparable secure store, so you re-enter it after a reload.

Charts

The hand-painted charts in lib/widgets/charts are interactive. Line charts (MetricLineChart: CTL/ATL/form history, Statistics, readiness) and the session stream chart zoom by pinch, double tap (3×, again to reset) or Ctrl + mouse wheel; the y-scale refits to the visible window, one finger scrubs a tooltip and pans once zoomed, and a button resets. Every series gets a dashed Ø average line over the visible window (streams also show their averages above the chart); curves are monotone-smoothed. Bar charts draw a dashed Ø line at the mean. The shared zoom/pan logic is chart_viewport.dart.

With a mouse, hovering a line chart shows a crosshair with every series' value at that point. Under the per-sport fitness chart (Training analytics) a small overview shows the whole range: drag across it to zoom to that stretch, drag the window to move it, tap to jump. Tap a legend entry to hide or show that series. Lines draw in briefly when a chart first appears, unless the system asks for reduced motion.

Load heatmap layouts. Options → Layout: Year grid (fits the screen: weeks as columns on a wide window, as rows on a phone), Months (a small calendar per month) or Week table (weekdays across, a total per week and per weekday). Colours: theme or Viridis. Both are remembered.

Activity chart. The session diagram on an activity (StreamChart) has labelled axes: the first selected stream on the left, the second on the right (round tick values, in the stream's colour), a time axis, dashed Ø lines, a peak marker and a crosshair with a time chip. Zoom with pinch, double tap, Ctrl + wheel or the +/− buttons; an overview strip under the chart shows the window and moves it by tap or drag. Tapping a detected interval zooms to it, and a 10 s / 30 s smoothing switch calms noisy power (averages and the readout always use the raw samples).

Events

More → Events lists races (A/B/C), notes, holidays, sick/injured markers, targets and season starts from a month back to a year ahead (lib/screens/events). The + button and tapping an entry open the editor (type, name, date, optional end date for holiday/sick/injured/target, sport for races, description); the trash button deletes. Intervals.icu is the source of truth: IntervalsEventService (lib/data/intervals_event_service.dart) creates/updates/deletes there via createEvent / updateEvent / deleteEvent and mirrors the result into the events cache. SyncService.syncEventsHorizon() refetches that whole span (independent of "Copy planned events"); the background sync runs it after the week sync (BackgroundSyncRunner.syncEvents; every run when nightly, at most every 6 hours on the shorter intervals), opening the screen refreshes it when older than an hour, and pull-to-refresh forces it.

Deleting planned sessions

Deleting a planned session (the trash button in the Calendar day list or a left swipe on it, the detail screen, or the long-press on a day / Today's training) removes it everywhere (planned_workout_actions.dart): on Intervals.icu (already gone counts as deleted), in the event cache, and in the TriIQ plan — a plan session, or the plan session an Intervals.icu event was created from, so it cannot reappear as a local-only session. A plan session that was sent needs a connection; one that only lives in TriIQ can always be deleted. Afterwards the affected day is refetched from Intervals.icu (syncRange(day, day)), so the cache matches the calendar upstream.

Ask the trainer

Every "Ask the trainer" entry point hands Chat a ChatTopic through askTrainer() (lib/screens/chat/ask_trainer.dart): the topic's context goes to the agent as system context, its draft lands in the Chat input field ready to send or edit (never sent for the athlete), and the shell switches to the Chat tab. Entry points: an activity's evaluation, the weekly review, the readiness card, a Today tile's long-press sheet, and the Analysis screen's app-bar button (period, filters and per-metric statistics as context).

Analysis

More → Analysis (lib/screens/analysis) is a Power BI–style workbench over the cached data. Selectors: period (30/90 days, 6 months, 1 year, this year, custom range), sport (all/swim/ride/run — filters the activity metrics), resolution (day/week), rolling average (off/7/14/28 buckets), min/max markers, a ±1 σ band, and the metrics to chart (TSS, hours, distance, CTL, ATL, form, ramp rate, HRV, resting HR, sleep). Each metric is its own graph on one shared x-axis: zoom/pan (pinch, +/−, Ctrl+wheel) moves all graphs together (one ChartViewport), and tapping a point puts the crosshair at the same moment in every graph and lists all values in a card on top. Per graph: Ø, min and max with dates, σ, and Δ first→last (series_stats.dart). Activity metrics are summed per bucket (0 on rest days); wellness metrics are averaged (gap when missing). Week buckets start on Monday.

Year goals

Settings → Training → Year goals**: a yearly distance goal (km) per sport (swim, ride, run), stored by YearGoalsSettings (shared_preferences; blank = no goal). Right under the fields, and on Today as the "Year goals" section (switchable and reorderable; "Show on Today" in the same Settings card), a progress bar per sport shows km so far against the goal with a tick where an even pace would be today, the percentage, how far ahead/behind that pace is, and the year-end projection at the current pace (YearGoalsProgress). It counts the calendar year's activities cached on the device, so sync the year (Settings → Sync) for complete numbers.

Today

Today answers "what should I do today, and am I fit for it?" at the top, and keeps everything else a scroll or a tap away.

The hero card (TodayHeroCard, lib/screens/today/today_hero_card.dart) puts the day on one card: the date, the status, the readiness ring, today's planned session(s), one primary action, "Ask the trainer about today", and a strip for tomorrow ("Tomorrow: Long ride · 3h 00m · 120 TSS"; tap opens it, or the Calendar on tomorrow when nothing is planned). The status is "Ready to train" — or "Train with care" / "Take it easy today" in the readiness colour when readiness says Caution / Back off — until something is logged, then the count of today's activities; the line under it names what drives readiness ("Due to HRV, Sleep"). The primary action follows the day (heroActionFor):

  • Start — a session is planned and readiness doesn't object: opens its steps (the plan-session sheet for a TriIQ session, the planned-workout detail screen for an Intervals.icu one). Nothing is sent to a watch from here.
  • Swap for easier — Caution or Back off with an interval or long session still to do: Train now on that session, for Find alternative.
  • Log how it felt — today's sessions are done (or you are sick): the fatigue / soreness dialog, with a light haptic.
  • Propose training — nothing planned: Train now proposes one. On a rest day the card names the week's next key session instead of an empty line.

Once every planned session is matched by an activity (same sport, one to one, matchAll), the card flips to a result view: each activity with planned against actual ("1h 02m of 1h 05m · 80 of 78 TSS"), the performance-trend arrow, and what you logged for fatigue and soreness ("How did it feel? Not logged yet."). The flip animates unless the system asks for reduced motion.

Gestures, and the ways around them. Swipe today's session right to log the feel, left to move it to tomorrow — the calendar's move (moveWithUndo / CalendarMover: plan rules warn on the snackbar, offline queue, Undo moves it back). Both are also screen-reader actions on the row, and Move to tomorrow is in the ⋯ menu (long-press the card or ⋯: sync now, Train now, fatigue & soreness, move to tomorrow, open in Intervals.icu, customize Today). Tap the readiness ring for a bottom sheet that explains the score signal by signal (rating, today's value, "3-day median 54 bpm vs usual 48 ± 1"), with Details and trends (the full readiness screen) and the signal options. Before today's wearable data is in, the ring's place shows "Waiting for watch data" with Refresh instead of a score from incomplete data. "Ask the trainer about today" opens Chat with today's readiness, planned and done sessions and tomorrow attached as context, and a question in the input field to send or edit. A screen reader reads the card as one summary ("Ready to train. Ready, Readiness 78 of 100. Today: VO2 intervals · 1h 05m · 78 TSS. Tomorrow: Long ride · 3h 00m").

Needs attention (AttentionStack, attention_stack.dart): under the hero, only the cards that have something to say, most important first — the return-to-training ramp after an illness, the fatigue early warning (a warning before plan adjustments, a watch after), plan adjustments, the race countdown (more than a week out), threshold suggestions. Two are open, the rest behind "+N more". Swipe one away or tap its × to hide it for the rest of the day (AttentionDismissals, today.attention_dismissed, today's date only); each card's own buttons (Dismiss, Not now, Apply…) work as before.

This week (ThisWeekCard): the week's TSS against what is planned ("240 of 420 TSS this week · 180 to go", with a bar), sessions done of planned, the stacked hours bar against the summed weekly targets, one small ring per sport with a target (long-press lists that sport's activities), and the year goals as one line ("Year goals · Ride 62% ↗ · Run 48% ↘" — ahead of / behind an even pace). Sport rings and the goals line follow their Show on Today switches in Settings. Tap the header to fold it.

Week ribbon (WeekRibbon): Mon–Sun as seven marks — done (check), planned (ring), missed (cross, an earlier day with a planned session and no activity) or rest (dash), today highlighted; tap a day to open it in the Calendar, hold a day to peek at it (DayPeek, lib/widgets/day_peek.dart): the date, the planned sessions (sport, name, minutes, planned TSS), the completed activities (name, time, TSS, performance-trend arrow), done-versus- planned TSS on a thin bar, the day's readiness dot when the watch data is in, or "Empty day · Rest". Lists show three rows and "+N more". The ribbon passes the week Today already holds, so the card appears at once; only readiness is read (from the cache) while the card is up. DayPeekSource.load reads a whole day from the cache for other callers.

Race week and sick days. Within 7 days of the active plan's event, a race-week header (countdown, the plan's phase this week — Taper / Race week — and the season forecast's form on race day) takes the load tiles' place. While a SICK / INJURED event is on, Today hides the training cards (attention stack, This week, ribbon, load tiles, tomorrow), the hero says so and offers Log how it felt, and the return-to-training card (the same one as on Season, nothing applied without confirming) sits right under it. In the return ramp afterwards the card moves into the attention stack.

Weekly-target rings. Long-pressing a ring opens a sheet (week_activities_sheet.dart) listing this week's activities of that sport (date, duration, distance, TSS); the "All sports" chip widens it, and a row opens the activity.

Load tiles. By default one row of three — CTL, ATL and Form — with "More metrics" opening all six (TSS today / week, CTL, ATL, form, ramp rate); Show all six load tiles in Customize Today keeps the full grid. They are compact StatTiles (compact: true): icon badge beside label and figure, animated value changes, soft hover/press states. Resting a mouse on a tile opens a floating graph card automatically (HoverPreview + MetricPreview: 14 daily-load bars, 8 weekly bars, or a 30-day filled line with its Ø). Long-press (touch) opens a sheet with the plain-language explanation, the zoomable graph, "Show history" and "Open in Intervals.icu".

Customize / delete. The "Customize Today" button at the bottom opens a sheet (customize_today_sheet.dart) to drag the sections (hero, needs attention, This week, week ribbon, load tiles, activities, tomorrow's training, athlete) into any order and switch each off; stored by TodayLayoutSettings (shared_preferences). Two switches sit above the list: Order by time of day (off by default; in the morning the hero and the attention stack lead, from 17:00 the hero — by then today's result —, tomorrow and today's activities; contextualTodayOrder) and Show all six load tiles. A new install (and "Reset layout") shows hero, attention, This week, ribbon, tiles and activities; tomorrow and athlete are off. An existing install that never customized keeps every section on. A layout saved by an earlier version is migrated once (TodayLayoutSettings.migrate): readiness and today's training became the hero, adjustments and thresholds the attention stack, weekly targets and year goals This week — each takes the place of the first of its old sections, and is on when any of them was (today's training also keeps This week on, readiness the attention stack); the new week ribbon goes after This week; an order the athlete never changed takes the new default order. Folding This week, activities, tomorrow and athlete is stored too. Long-pressing today's planned training — or the selected day's card in the Calendar — offers to delete all of that day's Intervals.icu planned sessions (confirmAndDeleteDaysWorkouts); TriIQ plan sessions are left to the Plan screen.

Shows today's cached data. Pull to refresh (or the refresh button on the hero, which spins until every card has reloaded; the sync chip on the hero says when the last sync was) re-syncs the whole current month, so the Calendar and Statistics tabs are current too when you switch to them. Repeating the gesture is cheap: it never starts a second fetch next to one already running, does nothing at all within 10 seconds of the last one, and stops waiting after 10 seconds if the network doesn't answer. The first time this screen loads after connecting, it automatically fetches and caches today's data if it isn't already stored locally.

The tiles. TSS today and TSS week each show what was planned underneath ("of 420"); CTL, ATL, Form and Ramp each show how far they've moved since the same day last week. Tap any of them for the chart behind it — daily TSS bars, weekly completed-vs-planned bars, or the metric's own curve over 30, 90 or 365 days with a note explaining what it means. Nothing there fetches, so it all works offline.

Weekly targets. In This week, a ring per sport (swim/cycle/run) with a weekly target set in Settings → Training → Weekly targets, each showing this week's achieved training time against that target — percentage in the middle, hours below ("3.0 / 2.0 h"), coloured the same way the rest of the app colours that sport, and switching to a "done" colour once the target is met or passed (the ring itself never overshoots a full circle). A sport with no target shows no ring, and the whole row disappears when no sport has a target, or when Show on Today is off in Settings. Achieved time comes from this week's already-cached activities (the same ones behind the TSS-week tile), so it works offline and needs no training plan.

Plan adjustments. When the saved plan and what you did drift apart, a Plan adjustments card lists suggestions, each with Apply and Dismiss. Nothing changes until you apply one:

  • Missed session (an earlier day this week with no activity of that sport): an interval or long session can be caught up on the earliest later training day this week that isn't full and doesn't sit next to another hard day. If no day fits, or for a Z2 session, the suggestion is to let it go, which removes it from the plan (and from Intervals.icu if it was sent).
  • Week far off target (the week that just ended came in under 80 % or over 120 % of its target): next week's load-graph share drops so the ramp restarts from what you actually did, or so it doesn't climb past last week's target. It stays within the graph's 80-120 % band, and the card says when the 80 % floor held it up. The week's sessions change when you regenerate the plan.
  • Low readiness on a hard day (Caution or Back off with intervals or a long session today): swap it with the next Z2 session this week, or move it to the next fitting day.

A dismissed suggestion stays dismissed, even after a restart. A suggestion disappears by itself once it no longer applies, for example when a late watch upload shows you did the session after all. The chat's trainer offers the same cards when you say you missed something.

Readiness. The hero's ring and status say Ready, Caution or Back off for today and why ("Due to HRV, Sleep"). It is worked out on the device from today's Intervals.icu wellness record: HRV and resting HR against your own normal over the previous 60 days (a signal needs at least 21 days of values before it counts — until then it says "Building baseline (n/21 days)"; see below), last night's sleep, form (CTL − ATL), the fatigue/soreness you logged — from an activity's detail screen (see Activities above) or directly in Intervals.icu — and two signals that see today's training: Load (how much is already on the legs: today's training load against your usual daily load, i.e. CTL, and the acute:chronic ratio ATL ÷ CTL, both including a session once Intervals.icu has it) and Device (the 0–100 readiness figure your watch or app writes, when there is one — no pill without it). Any back-off signal, or two cautions, means Back off; one caution means Caution. The 0–100 score is half the average of the rated signals and half the weakest one, so a single signal that is off — a big session today, a low HRV — shows in the number instead of being averaged away; it never reads better than the status (at most 79 on Caution, 59 on Back off). The morning figures (HRV, resting HR, sleep) can't see a session you do later in the day; Load can. Hold a pill in the readiness sheet (tap the ring on Today; the same press-and-hold peek as the Insights tiles, ReadinessPeek in readiness_peek.dart) to see what is behind it while you hold: the signal's name and rating, what it measures, its last 30 days as a small chart (HRV and resting HR against your normal band; sleep, load and fatigue/soreness as daily bars; form around zero), today's figure and the normal range in words; the Fitness pill shows CTL over time and its change against a week ago. Letting go hides it. How HRV and resting HR are rated (lib/evaluation/wellness_baseline.dart, shared by readiness, the fatigue early warning, the wellness trends and the trainer's get_readiness tool, so they agree on "usual"):

  • Today's figure is the median of the last 3 days with a value (5 if you pick that under the readiness options — long-press the card, the options icon on the readiness screen, or Signal options in the ring's sheet; stored on the device, readiness.smoothing_days; the okf-rules default is smoothingDays). Today's own reading is still shown next to it. One odd morning — a +12 bpm spike — therefore never changes the rating; a change has to last two of three days.
  • Usual is the median and MADσ (median absolute deviation × 1.4826, which reads like a standard deviation) of the 60 days before the smoothing window, after dropping implausible readings (resting HR outside 25–120 bpm, HRV ≤ 0 or above 300 ms) and readings more than 4 MADσ from the median. It needs 21 values; the spread never counts as less than 1 bpm (resting HR) or 1 ms / 3 % of the median (HRV).
  • Resting HR is a caution at median + max(3 bpm, 1.5 MADσ) and back off at median + max(6 bpm, 2.5 MADσ). HRV is a caution 1 MADσ and back off 2 MADσ below the median.
  • Hysteresis: a level is reached as soon as the smoothed value crosses its threshold, but it only clears once the value has been back past the threshold by 1 bpm (resting HR) / 0.25 MADσ (HRV) on 2 days in a row. The previous 14 days are replayed from the stored records each time, so no state is kept and a value wobbling around a threshold doesn't flip the status every day.
  • Context cap: a high resting HR with HRV and sleep fine (and nothing bad logged) is capped at Caution — heat, caffeine or a late meal raise it too.
  • The detail screen and the peek spell it out: "Normal up to 51 bpm (avg 48 bpm) · 3-day median 54 bpm vs usual 48 ± 1 (40 days) · today 56 bpm".
  • Not done yet: detecting a device change (a lasting step in the values) and restarting the baseline instead of warning; for now a new strap shows as a sustained change until the baseline catches up.

Without a wearable you get "No wellness data" (and a status from form alone); before today's data has arrived, "Waiting for today's data". Tap the ring for the explanation sheet, and from there the detail screen with each signal's value, normal range and rating and a 30-day HRV / resting-HR trend (the sheet also carries the signal pills with their press-and-hold peek). When the status isn't Ready and today has an interval or long session, the hero's main button becomes Swap for easier; "Ask the trainer about today" opens the chat with the day filled in. Nothing changes the plan by itself. The thresholds are defaults in §5.1, not medical advice, and nothing in the app — readiness, the fatigue warning, plans, the trainer's answers or your own custom instructions — is guaranteed to be correct or safe: overtraining and health problems are easy to miss in numbers, so check against how you feel and see a doctor or coach when in doubt.

The athlete card shows your Intervals.icu profile picture and, once your sport settings have loaded, your ride and run FTP. Tap it for the full athlete view: picture, where you are, your age, your latest weight, resting HR and HRV, and your thresholds per sport — FTP, indoor FTP, W', LTHR, max HR and threshold pace. Each row says where the number came from: your current Intervals.icu sport settings, or the most recent activity that was analysed with it.

Tap any activity in "Today's activities" for its full detail view — see Activities below. Tap a planned session on the hero or in "Tomorrow's training" for its own detail view (PlannedWorkoutDetailScreen — prescribed duration/distance/TSS and the workout description, the not-yet-happened counterpart to an activity's detail screen). That screen also offers Add to Google Calendar (pre-filled, all-day unless the session has a time of day) and Delete, which removes it from Intervals.icu after a confirmation.

If Intervals.icu isn't connected and/or no LLM provider is configured yet, a Finish setting up card appears with a button straight to Profile and/or Settings — so a first launch isn't just a wall of "not connected" labels.

Hold to peek

Press and hold (finger or mouse button) on an item that opens a detail page to see what is behind it without leaving the list. A card floats over the dimmed screen and goes away the moment you let go (or if the touch turns into a scroll); a quick tap opens the page as always. Peeks read the local cache only, so they are instant and work offline. Where it works:

The rules for a hold. A hold is a shortcut, never the only way in:

  1. It means one of two things — a read-only peek, or a menu of actions. It never deletes, moves or changes anything by itself (a menu entry that deletes asks first); test/hold_peeks_test.dart fails on any onLongPress that deletes or removes directly.
  2. Every action reachable by a hold also has a visible route: a ⋯ button, a tap, or a button on the detail screen. On Today the week's target rings open their activities on tap, Tomorrow's training has a ⋯ button and a Plan this day… button, the Insights volume card has an Open in Intervals.icu icon, and the readiness options are one tap further (ring → Signal options, or the options icon on the readiness screen).
  3. A one-time tip on Today says items can be held to preview them (Got it dismisses it for good; HoldTipStore).

  4. Today: a day in the week ribbon (the day's plan, activities, load and readiness), the icon of a session on the hero card (planned: type, dates, notes; completed: key figures) and the rows of Today's activities (key figures).

  5. Today, load tiles: the CTL / ATL / Form tiles are labelled Fitness · CTL, Fatigue · ATL and Form, and carry a visible ⓘ beside the label that opens the metric's explainer (the same sheet a long-press opens). Form also shows its named zone — Very fresh, Fresh, Neutral, Optimal or Heavy — from form as a percentage of fitness ((CTL − ATL) / CTL: above +20 %, +5…+20 %, −10…+5 %, −30…−10 %, below −30 %; the Intervals.icu zones, lib/evaluation/form_zone.dart). One framing everywhere: Fitness (CTL) is the training load you have built up over about six weeks — a load measure, not a health measure.
  6. Today, year goals: the Year goals line on the This week card — per sport the goal, the distance so far, the % of it, how far ahead or behind an even pace you are, and the projected year-end.
  7. Insights: every tile of the hub.
  8. Calendar day view: the day's statistics card — the day's sessions planned against done, its fitness (CTL, ATL, form, ramp rate) and the week so far (TSS, hours, sessions, planned against done).
  9. Calendar year view: a month — per sport (swim / ride / run) the month's distance and time; with a year goal also the month's distance as a % of an even twelfth of the goal, and a 12-bar chart of the goal's cumulative progress to 100 % up to that month (a tick per bar marks an even pace, the held month is highlighted). A tap still opens the month.
  10. Calendar header: the year and the month crumb of the breadcrumb (2026 › November) — the month's and the year's statistics, see Calendar → Period statistics. A short tap still jumps up to that level.
  11. Readiness: the signal pills (see Today).
  12. Activities: every row (distance, time, TSS, average heart rate and power, climb, trend arrow, and one line of the sport's year so far).
  13. An activity's page: the Distance, Avg HR / Max HR and power tiles — a histogram of the time spent at each value from the activity's streams (heart rate in 5 bpm bins, power in 25 W bins, speed in 5 km/h bins or, for a run, pace), with min / avg / max, the most common range and its share, and the recorded time. Pauses longer than 10 s between samples are left out; a swim's distance has no peek. The streams come from the device's cache, or are loaded once (as the Charts tab does).
  14. Training plan: a session tile in a week (its steps).
  15. Events: an entry (type, dates, the start of its notes).
  16. Search (More): a result (the app documentation's passage on it).

Screen readers and keyboard users get the same card from the Show preview action on those items (a dialog, closed with Close). The card respects "reduce motion", is capped to the screen and truncates instead of growing, so it fits a 360 dp phone at 2x text.

For contributors: where not to add a peek. Never put a peek (HoldPreview / Peekable) on an item whose long press already does something, or a drag would be lost: Calendar day cells, week numbers and session cards (day actions, week actions, drag and drop; only the header's year and month crumbs, which had no long press, peek — through PeriodStatsCrumb, so calendar_screen.dart itself stays free of peeks), the Today hero card (only the icons of its sessions peek; the quick actions live behind its ⋯ button), Today's load tiles, the This week card and its sport rings and Weekly targets (details sheets), the readiness ring (options), tomorrow's plan (delete), Insights' "open in Intervals.icu" lines, chart brushes, the bottom bar (customise), and any list you can drag to reorder. Use Peekable (not a bare HoldPreview) so the "Show preview" action comes with it. test/hold_peeks_test.dart lists the excluded files and the files allowed to peek; add to its lists consciously.

Calendar

Add and agenda. A visible + in the header opens the day actions (including Add event) for the selected day, at every level. In Month, the agenda button swaps the grid for a list of only the days that have a session. Month cells tell sessions apart by shape as well as colour: done = filled circle, planned in Intervals.icu = outlined circle, TriIQ plan = outlined rounded square, with a legend under the grid. Chart and cell labels are never below 11 sp.

Pinned grid. In Month and Week the grid stays fixed at the top whatever the number of sessions on the selected day; only the day card below it scrolls (the grid scrolls on its own, capped at 65 % of the height, only when it can't fit, e.g. at very large text sizes).

Compact layout. The level buttons use a small single-line label (never wrapping, in English or German), the header rows and the month grid have tighter padding, and month cells are shorter, so the month grid plus the day card with three activities fit on a ~780 dp phone without scrolling (test/screens/calendar_drilldown_test.dart).

Levels. Four zoom levels — Year, Month, Week, Day — picked with the buttons at the top, by pinching (out = one level in, in = one level out), or by tapping: a month in the year view, a week number in the month grid, or a day (a tap only selects it and shows its card below; the card's header and ⤢ button, or Open day in the long-press menu, open it). The breadcrumb under the buttons (2026 › November › Week 46 › Fri 13) jumps back up to any part. The arrows, or a sideways swipe anywhere on the view, move one period (year, month, week or day); swipe down on the header, or the Today button, goes back to today. Level and date are kept across restarts (CalendarPrefs, shared_preferences calendar.level / calendar.date). Changing level zooms with a short scale-and-fade, off when the system asks for reduced motion.

  • Year (year_calendar_view.dart): twelve mini-months (1–4 across, fewer at large text), each day tinted by its TSS on the Load heatmap's colour scale (buildLoadHeatmap + ChartTheme.heatColorOf, theme or Viridis as chosen there), outlined for races (amber), sick/injured days (red) and holidays (blue); a coloured band beside each week shows the current plan's phase (build, recovery, peak, taper, race — legend below). Each month reads to a screen reader as "November: 640 TSS, 18 sessions".
  • Day selection: tapping a day in Month or Week only selects it (the card below follows); tapping it again does not open the day view. Open day is the first entry of the long-press day-actions sheet.
  • Day: readiness and wellness pills, then a statistics card like a month cell's, larger: done against planned load (TSS, with a % chip and a progress bar), time and sessions, the per-sport minutes bar (planned faint above, done solid below) and the week so far. A rest day says so in one line. Hold the card for the details (see Hold to peek). The card sits right under the header; the level change no longer centres a short day.
  • Month: the grid with an ISO week-number column (tap = open the week, long-press = week actions). Each cell: a fill for done against planned load (faint = planned, not done yet; stronger = partial < 80 % / done 80–120 %; tertiary = over 120 %; training on an unplanned day counts as done), session icons, a two-line per-sport bar (planned minutes faint above, done minutes solid below, both on one scale, sport colours as elsewhere), a readiness dot (green / amber / red from ReadinessService.loadDays, only for days up to today that had HRV, resting HR or sleep) and a badge — a star for a key session (intervals or a long session, isHardSession), a dumbbell for strength. The Compact chip in the filter row switches to taller cells (more icons). Sick and injured days still tint the cell.
  • Week: a summary card (planned vs. done TSS and hours, a ring per sport for done vs. planned minutes, ⋯ for the week actions), then a row per day with each session as a block sized by its duration, the day's load, badge, readiness dot and race countdown.
  • Day (day_calendar_view.dart): the day's readiness, HRV, resting HR, sleep and fatigue/soreness as pills, a race countdown, then the day card.

Header. Below the breadcrumb, the visible period's done / planned TSS, hours done, sessions done / planned and (for a year, month or week) the CTL change. The filter button opens filter chips: sports (swim, ride, run, strength, other — none selected = all) and Planned / Completed. Day events (sick days, races, …) are never filtered out.

Period statistics (hold the year or month crumb). Press and hold the year or the month in the breadcrumb for an overlay with the period's statistics (PeriodStatsPeek, lib/widgets/period_stats_peek.dart; a Peekable, so screen readers get the Show preview action too; the week and day crumbs do nothing on hold). From the local cache only:

  • Month (on top; absent when the year crumb of the Year level is held): TSS done / planned, hours, sessions done / planned, distance and CTL change — the same PeriodSummary maths as the header line — and per sport (swim, ride, run, other, strength) its sessions, hours and distance.
  • Year — the year to date (or the whole year for a past year) per sport: sessions, hours, distance and TSS, with the change in time against the same period last year (↑ / ↓ and percent; a 29 February compares with 28 February of a normal year), a Total row and, for the current year with year goals set, the one-line year-goals progress (YearGoalsProgress, compact). Strength & mobility (WeightTraining, Yoga, Pilates) is listed with sessions and time only and is not in the total, as in the weekly review. Sport grouping is the Calendar filter's (statSportOf).
  • Never misleading. Totals come from what is cached. If the sync state (SyncStateRepository, scope activities) says the cache starts after 1 January, the card says "Based on synced data since — sync the year in Settings → Data & privacy → Sync" and shows no comparison; if only last year is missing it says "No comparison: isn't fully synced."; a sport without sessions last year shows no percentage (never an invented one).
  • It reads as one summary to a screen reader ("Month November 2026: …; Year 2026 per sport: Swim: …"), fits 360 dp at 2x text (the card height cap of Hold to peek clips the year table's tail, never the month on top), and follows the theme and reduced motion like every peek.

The maths lives in lib/evaluation/period_stats.dart (pure, unit-tested: totalsBySport, computeYearStats, sessionYearContext); the cache read in YearStatsService (below) and PeriodStatsLoader.

Moving sessions. Long-press a planned session — in the day card, a week row, or a month cell's icon — and drag it to another day (month cell or week row); a week row previews the day's load after the drop. Without a gesture: the Move to… button on the row (also a screen-reader action) opens a date picker. Both go through PlanActions.movePlanned: a TriIQ plan session (or the Intervals.icu event a plan session was sent as) moves with moveSession (inside the plan, not into the past); any other Intervals.icu workout is moved upstream through QueuedWorkoutWriter (queued when offline) and in the event cache. A snackbar confirms and offers Undo (moves it back). Rules from plan adaptation are warned about, not enforced (moveWarnings): two hard sessions on neighbouring (or the same) days, a hard session the day after strength, strength the day before a hard session. Races, notes, past sessions and an event still waiting to reach Intervals.icu can't be dragged: a long-press says why.

Swipe actions in the day card: swipe a planned session left to delete it — the same undo window as the trash button (PendingDeletes), no dialog; swipe a completed one right for How did it feel? (fatigue/soreness). Both are also on the row (trash button; screen-reader actions).

Long-press menus. A day (cell, row or card): Propose training, Add event, Mark as sick, Mark as holiday (open the event editor preset — it creates the Intervals.icu event), Ask the trainer about this day (opens Chat with the day's sessions as context and a draft question), and Delete day's training. A week (its number in the month grid, or ⋯ on the week view): Open week, Weekly review (weeks that have started) and Ask the trainer about this week.

Accessibility. Every gesture has a button or menu (level buttons and breadcrumb for pinch, arrows for swipe, Today for swipe-down, Move to… for drag, trash / screen-reader actions for swipes, ⋯ for the week long-press). Day cells and week rows read as one summary ("Friday, November 13, 2 planned, 1 done, 50 / 110 TSS, Readiness: Ready, key session"), months in the year view as their load. Cell text is capped at 1.3× in the dense month grid (the summary carries the rest); the screen is tested at 360 dp with 2× text in light and dark themes.

Each day shows a tiny icon per session — tertiary-coloured for Intervals.icu planned events, secondary for TriIQ plan sessions, primary for completed activities — reading planned items from PlannedItemsRepository (lib/data/planned_items.dart: the current plan's sessions plus, when Settings → Data & privacy → Calendar copies them, the cached events; a sent session shows once, as its synced event) and completed ones from activities. Today and Statistics read planned load from the same source. A plan session in the day list says whether it was sent to Intervals.icu and opens its steps; it is managed on the Plan screen (no delete here). Data is read from the local cache the same way Today does, syncing the visible range from Intervals.icu if it isn't cached yet, and refetching it when it has gone stale (see the sync notes above; the header's refresh button forces it). On Today, long-pressing the "nothing planned" line of today's (or tomorrow's) training offers Propose training — Train now for that day — and opens it. Sick and injured days, holidays, notes, races, targets and season starts (Intervals.icu events) are shown on every day they cover — an icon in the month cell (sick/injured days tinted), a line in the week view, a row on the day card (tap to edit) — whatever the "copy planned events" setting. Long-press a day (cell or day card) for a sheet with Propose training, Add event (a second menu picks the kind — sick, injured, holiday, note, race A/B/C, target, season start — and opens the event editor with that day and kind preset) — Train now for that day, so the created session lands on it (future days and today) — next to Delete day's training. The day card is slim: the date (with a Today pill) and done-vs-planned TSS with a hairline progress bar, then one compact row per session — duration and load on every row, a check on a planned session a same-sport activity covers. Tap a day to see its planned and completed sessions below the grid/list; tap one of those to open its full detail (PlannedWorkoutDetailScreen or ActivityDetailScreen).

Planned sessions carry a delete button in that day list, and the same action sits on their detail screen — both go through confirmAndDeletePlannedWorkout (lib/screens/activities/planned_workout_actions.dart): a confirmation dialog, then IntervalsWorkoutService.deletePlannedWorkout (the API's others: false, so a session created as part of a plan doesn't take the rest of the batch with it), then EventsRepository.deleteById and AutoSyncService.notifyCacheChanged() so every live screen drops it without a refetch. Completed activities have no delete: they are a record of what happened, not a plan to change.

Chat

Starters. An empty chat offers up to two starters built from your data — "You missed Tuesday's session. Replan the week?" (a planned session in the past week with nothing done that day) and "Form is −28. Should I back off?" (CTL − ATL of −25 or lower) — plus one-tap chips: I'm sick, I'm travelling, Short on time. With nothing to say, the generic questions stay. When a session was missed the trainer asks why before replanning. With no AI set up, the empty chat shows Set up your trainer with a plain recommendation and the provider choices.

Ask the training agent about your own data — "how was last week", "am I recovered enough for intervals tomorrow", "is my intensity distribution actually 80/20". It answers from the locally cached Intervals.icu data, reading it through tools rather than guessing: while it works, a line under the transcript names what it's doing ("Reading your daily load and wellness…"), and the reply streams in as the model writes it.

Set up a model in Settings → AI trainer → Models first; until then the screen says so, with an Open Settings button straight there. What the agent can see is limited to what's been synced, so sync the range you want to ask about (it will offer to sync a missing range itself when connected). Replies render as formatted markdown — headings, lists, and tables with borders and bold headers — rather than raw source. An empty chat offers a few starter questions you can tap instead of typing.

The agent can also work on your training plan: ask "what's on this week?", "make week 4 a recovery week", "move Saturday's long ride to Sunday" or "build me a 10-week triathlon plan". It reads the plan first, then proposes the change — a card under its reply shows what would change (a small load graph with the changed weeks highlighted, or the session's old → new date) with Apply and Dismiss. Nothing changes until you tap Apply: a graph change is saved into your goal (the Plan screen updates at once), a session move or removal also changes it in Intervals.icu when it is there (that needs a connection and Send plan to Intervals.icu on), and a plan opens the plan preview, where you take it. A card made before you edited the graph or plan says it is out of date instead of overwriting your edit; a failed apply shows why and offers Retry. A load-graph card shows each changed week before → after (TSS, with the total) and, once applied, an Undo that puts the old goal back — offered only while nothing else has changed the plan since (otherwise it says so), and not for a removed session or a plan taken through the preview; a moved session and a swap can be undone too. An applied-then-undone change is reported to the trainer on the next turn.

The chat is kept. The conversation (and every unapplied proposal, with its before → after) is saved on the device (chat.transcript, newest 60 messages; ChatStore) and is back after a restart; a restored proposal still has to pass the same "plan unchanged" check, so one made from an older plan turns out of date instead of changing anything. A new agent is given the visible conversation as plain text, so a restored chat — or a changed provider — carries on in context. The saved chat never goes into a backup and goes with Erase all data.

What a reply says about itself. Under each answer: Based on: … — the data tools it actually used, in plain words (athlete profile, activities, readiness, …; tap to see how fresh the synced data was), or Based on nothing from your data: general advice when it used none; the chip with the model that answered; and the tokens it used with an estimated cost (local, free for a model on your own machine, price not set for a model with no known price). Stop (the send button while a reply streams) ends it and keeps what arrived. Tokens add up per month and per model under Settings → AI trainer → Usage (this device only, not in a backup), with a Set price per model (US dollars per million tokens; built-in prices only for a few Claude families, anything else shows tokens until you set one) and Reset. A stopped reply is still billed for what was generated.

Safety is enforced in code, not left to the model (lib/plan/proposal_safety.dart). A load-graph week beyond the plan's limits (80–120 % of its proposal, which already respects the weekly and CTL ramp) is limited to the edge — the card says so and the trainer is told; a hard session (intervals or long) is never proposed for the same day as, or next to, another hard one, nor for a day you are logged sick or injured (or in the return ramp) — the trainer is told why and offers rest or an easy session. Words in your message that suggest chest pain, fainting, trouble breathing or heart palpitations (English and German) bring a Please get this checked card under it at once — no training until a doctor has looked, emergency number if sudden or severe — and the trainer still answers. The multi-day fatigue warning shows above the chat when it says watch or warning. None of this is a diagnosis; TriIQ is not a doctor.

New chat (top right of the transcript) clears the conversation and the agent's own memory of it, after asking — the next question starts from scratch, and the saved chat is deleted.

Train now

From Today, tap Train now. If anything is planned for today — a TriIQ plan session or (when copied) an Intervals.icu event — it is shown first under Planned today: sport, name, duration, TSS, where it comes from (TriIQ plan with a sent / only-in-TriIQ icon, or Intervals.icu) and its steps (long ones collapse; Show all steps). With two or more, tap one to choose which you want an alternative for. The main button then reads Find alternative: sport, duration and intensity start from the chosen session (you can change them), and the agent gets that session as its reference — aim for a similar training effect and load, unless your recent load says otherwise. With nothing planned the button reads Propose training and works as before.

Change Training reaches the same screen, preselected on one specific session, from wherever that session is shown: Calendar's day detail, the Plan screen's week grid (any week, not just the current one), and Today's own "Today's Training" / "Tomorrow's Training" cards. For a TriIQ plan session, these open straight into a quick sheet with Change Training right there; a synced Intervals.icu event on Today still opens the fuller planned-workout screen first, which also has the button.

Otherwise, pick a sport (run/ride/swim/strength), duration and intensity (recovery/endurance/intervals) and a Detail level, then Propose training. Detailed (the default) asks for a coach-written session: a one-line purpose, then a section per block (Warm-up, Main set, Cool-down, plus Drills or Strength & mobility when exercises deserve their own block), each a two-column table — Exercise (named exercise, drill or interval type with its sets, reps or time/distance and the rest between) and How (target, cadence or stroke rate, equipment and a coaching cue) — and a closing load and rationale. The exercises follow the sport (run: leg swings, A-skips, strides, calf raises; ride: spin-ups, single-leg pedalling, cadence blocks; swim: catch-up, fingertip drag, kick and pull sets), see exerciseMenu in lib/agent/training_detail.dart. Short keeps the old compact table, one row per segment. The same level carries into Create in Intervals.icu: a detailed session keeps each exercise as its own step with its cue, rest between repeats as steps, and a plain-text purpose line (workoutStructuringPromptFor). TriIQ plan sessions (the plan generator's description, now up to 2,600 characters) are asked for the same: named exercises, reps and rest per set, and a form cue per step. This sends the same training agent a prompt built from those choices, instructed to check the last 7 days of TSS/CTL/ATL/ramp rate with its own tools before proposing — so a fatigued week gets a lighter prescription, not a canned template. The proposal streams in as markdown, same rendering as Chat (below); Ask again re-runs it. Needs an LLM provider configured, same as Chat.

Formatting. Markdown from the trainer (Chat, Train now, the weekly review) is drawn by MarkdownReply with the app's own look: ## headings carry an accent bar, ### headings are small letter-spaced labels, bullets are accent diamonds and numbered lists get round badges, tables are one rounded card with an accent header row, quotes are callouts, and a single newline is a line break. Workout text in Intervals.icu step syntax (the create preview, a planned workout's detail) is drawn by WorkoutDescription (lib/widgets/workout_steps.dart): the purpose as an italic lead-in, each step as its duration, a target chip and the exercise with its cue, repeat blocks under a "3 ×" header, and a colour bar per step by intensity (grey for recovery, green, yellow, orange, red, purple above 120 %). Text with no steps (a coach's note) is shown as written.

Once a session has been proposed there are two ways to keep it:

  • Create in Intervals.icu puts it on today's calendar as a real planned workout. The agent first converts what it proposed into Intervals.icu's workout syntax, and you get to see the whole thing — name, sport, duration, estimated TSS and every step — before anything is written; Create does it, anything else cancels. Intervals.icu turns those steps into a structured workout, and whatever it can't parse stays as the description. Afterwards the app re-syncs, so the session appears on Today and Calendar straight away. Needs Intervals.icu connected.

For an alternative, the preview also asks Replace today's session (default) or Add alongside. Replacing a TriIQ plan session changes that session in place — same plan, week and date — so the Plan screen and Calendar show the new one; if it was in Intervals.icu, the new workout is created there and the old event deleted (this needs a connection and Send plan to Intervals.icu on, otherwise it is refused rather than leave the old one behind). A session that is only in TriIQ is changed locally, also offline. Replacing an Intervals.icu event creates the new workout, then deletes the old one; if that delete fails you are told both now exist. When the agent's workout has no TSS, the session keeps its old TSS, marked as estimated. Add alongside leaves the planned session as it is. - Add to Google Calendar opens a pre-filled event in your browser instead, for when you just want it in your day.

Strength (bodyweight). Picking Strength in Train now swaps the intensity choice for Strength for — swim, ride and/or run (at least one). The trainer is asked for a bodyweight-only session (no weights, bands or machines; floor, wall and a chair are fine — kneeling and half-kneeling variations included) whose exercises carry over to those sports, e.g. push-ups and Y-T-W raises for swimming, squats, wall sits and kneeling hip hinges for cycling, single-leg calf raises, split squats and pogo hops for running. It is created as an Intervals.icu WeightTraining session.

The same is in the Calendar: long-press a day (today or later) → Add strength training. Pick the sports and 20 / 30 / 45 min; the sheet lists the exercises (warm-up, the sports' exercises in turn, a dead-bug core finisher; 2 rounds at 20 min, else 3) with sets × reps and a cue. Add to calendar writes it straight to Intervals.icu (needs a connection) — no LLM involved (lib/plan/bodyweight_strength.dart); Let the trainer propose opens Train now on that day with Strength and the same sports preselected.

Statistics

Everything over a window you choose — 30 days, 90 days or a year:

  • Fitness trend — your CTL and ATL curves against each other.
  • Completed vs planned — one bar per week, actual load in front of the planned load behind it. Tap a bar for that week's numbers.
  • Volume — distance and time for this week, this month and this year to date.
  • By sport — sessions, time, distance and load per sport over the window, with each sport's share of your total training time. Tap a sport to open the Activities list filtered to it (rows for activities with no type don't open anything — there is nothing to filter by).

It all reads the local cache, so the range picker is instant and works offline; pull to refresh to re-sync the current month first. If a chart is empty, the range simply hasn't been synced yet — use More → Sync to fetch more history.

Performance (the card at the top of Statistics) answers "am I getting faster?". Pick Ride, Run or Swim and a metric — power and heart rate are your best average over every duration, pace your fastest time over every distance (running power only shows if you have any). The chart compares this season, last season and the last 42 days on a log axis; tap or drag it to read the value at a point, with the date and name of the session that set it and Open session. Key efforts lists 5 s / 1 min / 5 min / 20 min / 60 min (run pace: 400 m … half marathon; swim: 100 … 1500 m) per season with the change; an empty cell means no effort that long, nothing is interpolated. Model fit shows what Intervals.icu fits to this season (FTP, CP, W', Pmax — or critical speed and D' for pace) next to the threshold in your Intervals.icu settings, and the gap.

Curves are fetched from Intervals.icu the first time you open a sport and metric, then kept on the device: they are fetched again only once a newer activity of that sport has been synced (or with the refresh button). A failed fetch keeps the saved curves on screen with Retry.

Threshold suggestions, above the sport/metric picker, turns that gap into something you can act on. From the cached curves it derives a candidate ride FTP (this season's power-curve model fit), run threshold pace (your best ~60-minute effort, or the ~40-minute effort scaled toward a sustainable pace when that's all there is) and swim CSS ((t400 − t200) / 2 per 100 m from your 400 m and 200 m bests) — only ever from efforts in the last 90 days. A card appears when a candidate beats your current setting by 3% or more (raise it), or when the last 42 days' own data is at least 5% below it (likely dropped) — never from missing or sparse data. Dismiss hides it for 30 days, unless the underlying number moves a further 3% in the meantime, in which case it comes back. Review opens a sheet with the current and new value, the zone ranges each implies, an opt-in to also recalculate HR zones, and a note that past activities keep their recorded load; nothing is sent until you tap Apply. A failed update keeps the old value and says so; a successful one offers Undo, which writes the previous value back the same way. The write itself sends only the one changed field — proven safe by a live test (test/sync_live_test.dart) that checks Intervals.icu treats the request as a partial update, not a full replace, before this shipped. The same cards (minus Review/Dismiss specifics) appear on Today when a suggestion exists. Indoor FTP is never touched; the sheet says so when you have one set.

More

A search field over the whole app (see Search the app), then three groups: Plan (Training plans, Season, Events), Trainer (Trainer memory, Knowledge library — hidden on web) and Data (Sync, Info). Settings is the first row of More (one tap), and also behind your avatar in the top bar, next to Profile; the analysis views and Activities live under Insights. What More lists is everything that is not in the bottom bar, in your order — see Arrange the menu to pin a page to the bar or move a tab into More.

Knowledge library (More, Android/Windows only) lets you import your own Markdown or plain-text coaching documents — swim sets, taper notes, articles you trust — from the device's file picker, so the chat agent can search them alongside (or instead of) the bundled reference, without a rebuild. Import (toolbar) splits each file into sections at # headings, the same rule the bundled reference follows; a file with none becomes one section named after the file. The result says how many sections were added and how many structured (okf-*) blocks were dropped — those never affect your plan, only the chat's reference material. A file over 512 KB, not valid UTF-8, or empty is rejected with the reason and nothing changes. Importing a file with the same name as an existing document asks Replace or Keep both (suffixing the new one with the import date). Each document in the list shows its title, source file, section count and import date, with a switch to turn it off (kept, just not searched) and a delete button (confirms first). An empty library explains what it's for. On web there's no local database yet, so the entry is hidden and the agent uses the bundled reference only.

Weekly review (Insights → Weekly review) takes one week at a time (arrows to move): each day's planned and done sessions with missed ones marked, the share of planned sessions done and the planned versus done TSS, the week's 80/20 split with a flag when easy time is below the tolerance (and how many sessions had no zone data), the load against the 4-week average and the CTL / ATL / form change. It is computed from the cache and works offline. With an LLM provider set up, a short Next week note from the trainer follows, labelled as an inference; Discuss in Chat carries the week's figures over.

Search the app

Type in the search field at the top of More — in English or German — and every matching page, Insights view and setting is listed with its icon, name, where it lives ("Insights › Durability", "Settings › App › Notifications › Weekly review") and one line on what it is. Tap a result to go straight there; a setting opens its Settings page scrolled to it. Synonyms count ("dark mode" finds Appearance, "HRV" finds Wellness trends, "FTP" finds Performance curves), so do small typos and umlauts typed without dots. Clear the field (×) to get the More list back. The path follows your menu: a page you pinned to the bottom bar shows without "More ›", a tab you moved into More with it.

Arrange the menu

The bottom bar is yours to arrange. Open Customize navigation with the swap icon at the top right of More, from Settings › App › Navigation, or by long-pressing the bottom bar.

  • Reorder: drag an item by its handle (or long-press the row and drag), or use its Up / Down buttons.
  • Move between the bar and More: drag an item across the In More header, or use Move to More / Pin to bar. Any More page can go in the bar — Training plans, Season, Events, Trainer memory, Knowledge library, Sync, Info — and Today, Calendar, Chat or Insights can go into More; nothing becomes unreachable. A page in the bar opens as a tab (with the profile button in its top bar); one in More opens on top with a back button.
  • Limits: the bar holds 2 to 4 items plus More, which is always last and can't be moved. A move that would break that is refused with a note saying why — make room first.
  • The preview at the top shows the bar as it will look; Reset to default brings back Today, Calendar, Chat, Insights, More.
  • The order of More is yours too: its group headers stay while you keep each group together.
  • Search, the trainer's Open … buttons and links such as "Open calendar" go to a page wherever it lives. Your arrangement is kept across restarts and included in a backup.

Ask the trainer where something is

Ask Chat things like "where do I see my durability?", "how do I turn on the weekly review notification?" or "wo stelle ich das dunkle Design ein?". The trainer looks it up in the app's own documentation (the text you are reading), answers from it with the place in the app, and puts an Open … button under its reply. Nothing opens until you tap the button. If the app has no such feature, the trainer says so rather than guessing.

Season, forecast, race predictor, illness mode and bricks

More → Season has three cards. Fitness forecast runs the standard 42-day CTL / 7-day ATL model forward from the last synced values over the planned sessions (TriIQ plan sessions and Intervals.icu events; empty days are rest), and — beyond the last planned session, where the calendar is empty — assumes you keep training at your current fitness (daily load = CTL) so fitness does not decay to zero; it says from which date. It states form on race day for every upcoming race with a plain-language reading (still loaded / balanced / fresh / fading). Season timeline lays out each race (Intervals.icu RACE_A/B/C, plus the training goal's event date as an A race): a taper before it (A 14 d, B 7 d, C 2 d), the race day and a recovery after it (10 / 5 / 2 d), with build between. The conflict check flags two A races under 42 days apart, a race inside another's taper or recovery window, two races on one day, and a race inside a logged illness / injury. Race predictor opens the predictor.

Race predictor (lib/season/race_predictor.dart). Run and swim times come from your best efforts on the pace curves (Riegel, exponent 1.06; open-water +3 % in a triathlon). The ride finds the duration at which the power curve's best effort, scaled by a race fraction (97 % up to 1 h, 72 % by 6+ h, a further −7 % in a triathlon), produces the speed that takes that long (CdA 0.32, Crr 0.005, 9 kg bike, climbing work from elevation gain). The run after a ride is 3–12 % slower. Past ~1.5 h an allowance of up to 15 % applies when CTL is far below what the event needs, plus 1–1.5 % for arriving very loaded or very rested. Legs without curve data are named, never guessed. The pacing plan starts 3–5 % easier and (≤ 12 km) finishes slightly faster; the fuelling plan gives carbs/fluid/sodium per hour by duration (0 under ~45 min up to 85 g/h over 3 h), the day-before and pre-race carbs per kg, and an intake schedule (bike every 20 min, run every 30). It is a model estimate, not a promise.

Illness / injury mode (lib/season/illness_mode.dart). Log a SICK or INJURED event in More → Events (with an end date once it is over). While it lasts and for a graded return afterwards (3 / 7 / 14 / 21 days by length, ×1.5 for an injury) TriIQ proposes: sick — rest instead of every planned session; injured — the affected sport becomes easy cross-training (45 TSS/h); return — load climbs linearly from 50 % to 100 %, hard sessions in the first half become easy. Races are never touched. Nothing happens until you press Apply (Today banner or Season); changes go upstream to Intervals.icu first and fail safe. The chat agent can read the proposals (get_health_status) but not apply them.

Bricks (lib/season/brick_analysis.dart). A bike→run or swim→bike on the same day, with the second starting within 45 min of the first ending, is a brick. Activity detail shows the transition time, and for bike→run — from the run's stream — how long the legs took to reach 95 % of steady speed, the first 10 min against the rest, and the heart-rate cost per speed early on, as a good / decent / rough verdict with reasons (e.g. a hard bike). Chat tools: get_fitness_forecast, get_health_status, get_race_prediction, get_bricks.

Trainer memory and backup

Edit, switch off, tone. Each memory item has an edit button (the item keeps its id and date). Use memory in chats switches the whole memory off for the trainer; the items stay listed. Tone (balanced, direct, encouraging, analytical) and Check-ins (only when I ask, weekly review, after hard sessions) are stored on the device and sent with every turn as style preferences that never change the trainer's rules or safety limits.

Trainer memory (lib/agent/agent_memory.dart, More → Trainer memory). Up to 30 short preferences (200 characters each, duplicates ignored) in shared preferences. Every chat turn gets them as a system block of preferences, not instructions: the trainer respects them when suggesting or changing training, says so when one shapes an answer, and flags a clash with safety or the data instead of ignoring it. The trainer saves one only when you state or ask for it, says it did, and it appears in the list tagged "saved by the trainer"; you can delete any item or all of them. The screen carries a use-with-care note: preferences can push training further than is wise, the trainer can be wrong and guarantees no plan is safe or correct (watch for overtraining and health problems; see a doctor or coach when in doubt), and the trainer's memory block tells it not to push training further because of a preference when the data points to overtraining, illness or injury. It is advice-level: the plan engine and adaptation rules do not enforce a preference (set training days and long/interval days in the goal for that).

Backup (lib/data/backup/, Settings → Data & privacy → Backup). Export writes one JSON file (format: triiq-backup, version: 1) with the tables wellness, activities, sync_state, events, plans, plan_sessions, knowledge_docs and knowledge_sections, plus the settings stored in shared preferences (goal, targets, theme, language, trainer memory, …) — except the LLM connection settings (llm.*: provider, server URLs, models), which are device setup and must never be redirected by a backup file; the one exception is the OpenAI-compatible base URL and model (BackupService.portableLlmPrefs), restored only if the URL passes checkOpenAiBaseUrl; optionally the re-fetchable chart caches (activity streams, performance curves). Excluded always: the Intervals.icu key and the AI keys (OS vault) and device-runtime keys (background-sync status). On phones the file goes to the share sheet (Drive, Files, mail); on desktop to a save dialog. Restore validates the file (format, version not newer than the app, core tables present, only plain values), shows what it holds, and after confirmation replaces the synced data, plans and knowledge library in one database transaction — a bad row rolls everything back. Unknown columns from a newer schema are skipped. Settings are applied afterwards; restart the app to pick them up, and reconnect Intervals.icu (Profile) on the new device. The menu arrangement (nav.bar, nav.more, non-secret) travels too; on restore it is repaired like at start (NavigationLayout.normalize: unknown ids dropped, limits enforced, a value of the wrong type discarded) and applied at once.

Offline queue and home-screen widget

Offline queue (lib/data/pending_writes.dart). QueuedWorkoutWriter wraps the Intervals.icu writer. When a delete or move cannot reach the server (no network, timeout, no connection) it is stored and the caller carries on — the local plan or cache already shows the change. Plan sends are queued too (PlanWriter reports them as queued, not failed); at send time the queued create re-reads the plan session, so a session moved or deleted meanwhile is sent as it is now, or dropped. PendingWritesService.flush() runs before every sync (so the fetch that follows reflects it), stops at the first write that still cannot reach the server, retries a rejected write up to 5 times (4xx other than 408/429 fails at once) and then parks it as failed for Retry or Discard. A 404 on delete/move counts as done. Events with a delete waiting are kept out of sync results so they don't reappear. Not queued: replacing a session with an alternative and Train Now's create — they need the created event back, so they still ask for a connection.

Home-screen widget (Android; lib/data/home_widget_data.dart, TriiqWidgetProvider.kt, res/layout/triiq_widget.xml). Long-press the home screen → Widgets → TriIQ. It shows today's planned workouts, what was done (TSS), form (CTL − ATL) with CTL/ATL, and the update time; tapping opens the app. Settings → App → Home-screen widget (home_widget_settings.dart) switches each block on or off; Flutter writes the strings plus w_show_* flags through the home_widget plugin and the native provider only lays them out, dropping views whose flag is 0.

Fatigue early warning and morning briefing

Fatigue early warning (lib/evaluation/fatigue_warning.dart). Where readiness rates one day, this asks whether the same signals have stayed off. Over the last 5 days a signal fires when: HRV is more than 1 MADσ below your 60-day baseline median, or resting HR 4+ bpm above it, on 3 days (the same robust baseline readiness uses, wellness_baseline.dart; each day is judged on its own reading — the 3-of-5 count is the smoothing here); sleep is under 6.5 h on 3 nights; form is −25 or lower on 3 days; CTL ramps 8+/week on 2 days; or fatigue/soreness is rated 3–4 on 2 days. Days with no value (a wearable's 0) don't count, and a signal needs 3 days of data (HRV/resting HR also 21 days of baseline). Warning — three signals, or HRV/resting HR together with a load or feel signal; watch — two signals, or HRV/resting HR alone on four days. One bad night never triggers it.

Morning briefing (lib/notifications/morning_briefing.dart). Enable under Settings → App → Notifications (needs notifications on; Android/iOS). Android/iOS can only fire a pre-written notification, so the text is a snapshot of the cache when it was armed — at app start, after every sync, on plan changes and after the nightly background sync. It lists the day's planned workouts, readiness (only when today's wearable data is already in and the briefing is for today), the fatigue level, a note if you are logged sick or injured, and form with CTL.

Weekly review notification (lib/notifications/weekly_review_notification.dart). Enable under Settings → App → Notifications (needs notifications on; off by default). Pick the day (default Sunday) and time (default 19:00). It sums up the week against the plan — load vs target, time per sport vs your weekly targets, sessions done / missed and the key session, CTL change and form at week end (with a note when CTL rose faster than usual: 8+ in the week, or 3+ and more than 3 above your average of the four weeks before), how many days readiness was ready / caution / back off and which way HRV and resting HR moved — and previews next week: target TSS, phase, key sessions and any race. Like the briefing, the text is a snapshot of the cache when it was armed. Tap it to open Weekly review. With an AI provider set up you can add one sentence from the trainer; the numbers never come from it, and when the provider doesn't answer in time the notification goes out without it. On Windows it appears the next time you open TriIQ after the chosen time. Ask the trainer "how was my week?" for the same figures (get_weekly_review).

The work intervals under the session diagram are collapsed ("Intervals (n)"); tap the header to open the list, tap an interval to zoom the diagram to it.

Route map

The activity detail of an outdoor run or ride (hasRouteMap: run or ride family, not virtual / trainer / treadmill) shows a Route card after the session diagram: the GPS track from Intervals.icu's latlng stream drawn with flutter_map over OpenStreetMap tiles (© OpenStreetMap contributors shown on the map). The card's map is a still picture so it never steals the page scroll; tapping opens a full-screen map with pan and zoom. The track is fetched the first time (not as part of sync), thinned to ≤ 1200 points and cached in SQLite beside the diagram streams (route:<id>; an activity with no GPS is remembered as empty). Moving the mouse (or dragging a finger) over the session diagram marks the same moment on the map with a highlighted dot — the track is stored with the elapsed seconds of each point (time stream), and a track cached before that is fetched once more. Offline, or without GPS, the card simply doesn't appear. Tiles come from tile.openstreetmap.org with the app's user agent; that server is for light use, so if TriIQ is distributed widely point _tileUrl in route_card.dart at a tile provider with an API key.

About / Info and the SBOM

Info answers "which TriIQ is this?". Open it from More → Info, from the Info row at the bottom of Settings, or by tapping the version line in small type under it ("TriIQ 0.9.6 (build 1) · Android"). Like every More entry it can be pinned to the bottom bar (Arrange the menu).

  • App: name, version, build number, platform, operating system and the Dart version. Copy version info puts exactly that — plus the language and the active theme — on the clipboard, ready to paste into a bug report. It holds nothing about you, your account or your training.
  • Links: the source code and the releases page on GitHub, the in-app privacy screen (Consent & your rights) and the licence of TriIQ.
  • Open-source licenses: the licence text of every library TriIQ is built from, on Flutter's standard licence page.
  • Software Bill of Materials (SBOM): the list of packages this version was built from, in the CycloneDX 1.5 format that security and licence tools read. The SBOM screen opens with a summary ("187 packages: 37 direct, 6 dev, 144 transitive", the format and the app version it was generated for), then a search field and the list — name, version, source and a chip that says Direct, Dev (only used to build and test, never shipped) or Transitive (pulled in by another package). Tap a package for its details (version, kind, source, scope, package URL, SHA-256 of the package) and Open on pub.dev. Share / export SBOM (JSON) hands the file out: the share sheet on a phone (Drive, Files, mail), a save dialog on Windows. It does not cover the native Android (Gradle) libraries or the Flutter engine — the same as the SBOM the build pipeline publishes. If the bundled file cannot be read the screen says so and offers Try again; nothing else in the app is affected.

Releases

.github/workflows/android-release.yml builds the signed Android APK and publishes it as a GitHub release.

  • Merge to main → automatic pre-release, tagged v<version>-rc<short commit hash> (e.g. v0.9.6-rc1a2b3c4). <version> is the x.y.z of version: in pubspec.yaml (now 0.9.6+1); bump it there to start a new line. Put [skip release] in the merge commit message to skip it.
  • Your own tag (git tag v1.0.0 && git push origin v1.0.0) → a release for exactly that tag, built with that version; a tag containing - is a pre-release.
  • Manual run of the workflow → only an APK artifact, no tag or release.

Clean-up: .github/workflows/cleanup-prereleases.yml runs daily (03:17 UTC) and deletes the automatic v<x.y.z>-rc<hash> pre-releases published more than 3 days ago, together with their tags — the newest one always stays, however old. Pre-releases you tagged yourself (e.g. v1.0.0-beta1) and normal releases are never touched. Run it by hand to try it — "dry run" (the default for manual runs) only lists what it would delete.

The APK's version name is the tag without the v; its version code is the workflow run number. Signing secrets: see the header of the workflow.

Swim steps: m is minutes, mtr is metres

In Intervals.icu's step syntax a bare m after a number is minutes; metres are mtr. A swim written as - 300m Warm up is read as five hours (a 30-minute session came out as 19 h). The structuring prompt and the plan-content prompt now tell the model to write swim distances as mtr, and as a safety net fixSwimDistanceUnits (lib/data/intervals_steps.dart) rewrites 300m → 300mtr for swims — when the description is parsed (Train now / the trainer) and again right before any workout is created in Intervals.icu — but only when reading the m as minutes would make the steps add up to far more than the session's duration (or, without a duration, when a single step would be 100+ minutes). Minute-based swims (the plan engine's templates) and paces such as 1:45/100m are never touched, and mtr is never converted twice.

Where data lives, and where keys go

  • Database: on Android/iOS in the app's documents folder; on Windows in the per-user app-data folder (getApplicationSupportDirectory, e.g. %APPDATA%\…\triiq\triiq.db). Earlier versions wrote triiq.db into the working directory, which depends on how the app is started (a shortcut can make it the read-only install folder); on first start the old file is moved over once, and an existing database is never overwritten.
  • Keys: Intervals.icu, Claude, Ollama and OpenAI-compatible keys are kept in the OS vault. The OpenAI-compatible key is optional and goes only to the base URL you configured (https, or http:// on your own network); a public http:// URL is refused. The Ollama key is an Ollama Cloud key and is only ever sent to https://ollama.com — never to a self-hosted server and never over plain http (saving a key for another server URL is refused with an explanation).
  • Plain http: on Android cleartext is allowed only so a self-hosted Ollama server on your own network (http://192.168.…:11434) works (res/xml/network_security_config.xml); Intervals.icu, Anthropic, Ollama Cloud and OpenStreetMap stay https-only. Settings warns under the server URL when it is http://.
  • Offline writes belong to an account: each queued write is tagged with the Intervals.icu athlete it was made for (the connected one, or the last one connected on this device). Without a known account nothing is queued and the error shows; a write for another account is dropped instead of sent; disconnecting in Profile clears the queue.
  • Charts select on touch-down, so a quick tap no longer waits ~300 ms for the double-tap (zoom) window.

Training plan

More → Training plan. Set a goal first: target (long distance or short event), sport (Run, Ride or Triathlon), training days, weekly hours, an optional event date, and the plan length (2-16 weeks; by default 8, or the weeks up to and including the event week; a chosen length can't run past the event, and an event in the starting week is too close for a new plan). For triathlon, set the sport mix — each sport's share of the weekly load in 5% steps, totalling 100% (default Swim 15 / Bike 50 / Run 35). A sport at 0% gets no sessions.

Weekly load is a graph with one point per week on a TSS axis. The dashed line is the proposed load: a ramp from your recent weekly load (mean of the last 4 weeks), held flat when it would need more than your weekly hours or raise CTL faster than the ramp limit. Set the weekly increase with the slider above the graph (0–15%, default 10%); with Hold every 4th week on (the default) weeks 4, 8, 12… keep the previous week's load instead of ramping. Both redraw the proposal at once and are saved in the goal; weeks you dragged keep their share of the new proposal. No recovery dips are added for you. Each week has a shaded band — 80% to 120% of its proposal — that it can be moved within.

Taper and race week. When the plan ends in the event week, its last weeks step down from the last build week — two weeks at 70% and 50% for long distance, one at 60% for a short event — and the graph labels them Taper and Race (no ramp or CTL warning for the drop; you can still move them 80-120%). Taper weeks keep the interval session, shorter, and cut the long session most. In the race week nothing is planned on the event day or after it, and the day before gets short Race openers when it is a training day. Today shows Race in N days while the plan is active. An event more than 16 weeks away gets a 16-week block without a taper, and the load graph says when a taper block can be made.

The goal editor also sets the session mix — Z2 / Intervals / Long shares of each sport's weekly load (5% steps, total 100%; by default the goal type's mix, with a button to go back to it). An interval session never grows beyond what its template's repeats allow, and a hard mix shows up in the week's 80/20 warning. Preferences: a long-session day per sport (long ride and long run on different days), preferred interval days, and the most sessions per day (1 or 2). Unticking a training day drops the preferences on it. Placement uses preferred days when they are free; when a week can't, its card says which preference it missed.

  • Drag anywhere in a week's column, up or down. The point moves with your finger (it doesn't jump to it), snaps to 5 TSS with a small vibration, and a label shows the week, TSS, share of the proposal and the change from the week before. On a phone with many weeks the graph scrolls sideways; a sideways swipe scrolls, an up/down drag edits.
  • Tap a week to select it, then use −/+ (5 TSS each) or the arrow keys on Windows (5 TSS, Shift 25 TSS; left/right to change week). Undo reverts the last change; Reset (after a confirmation) puts every week back on the proposal.
  • A week more than 10% below the week before it becomes a recovery week (recovery sessions, shorter long session).
  • A week you push above the weekly ramp, the CTL ramp limit or your hours turns red and says which; it is a warning, not a block. Returning to the proposal after a dip is not counted as a jump.

The graph is saved into the goal (as each week's share of the proposal) as you edit it, so a sync that changes your baseline moves the TSS with it. Generate plan builds exactly what the graph shows and opens a preview of every session; nothing is saved until you tap Take as plan. That stores the plan in TriIQ, closes the Plan screen and opens the Calendar tab at the plan's first week, where the sessions show straight away (marked TriIQ plan). With Send plan to Intervals.icu on (Settings → Calendar) they are then created there in the background; a snackbar reports the result and offers Retry for any that failed. Planning works without an Intervals.icu connection: enter a typical weekly load in the goal and the plan stays in TriIQ. Each plan week then shows its target against planned (or done) TSS, the load per sport for triathlon, the 80/20 split, any warnings, and a Monday-Sunday row of its sessions as sport-coloured tiles (minutes and TSS; tap one for its steps). Triathlon weeks hold at most two sessions a day by default (your limit if you set one) with the long ride and long run on different days; with few training days Z2 sessions are dropped first.

Strength & mobility. The goal editor's Strength & mobility option asks for 0, 1 or 2 sessions a week (a new goal starts at 1; a goal saved before the option existed keeps 0, so its plan doesn't change) and, optionally, preferred days. The engine then adds them as their own sessions (Intervals.icu type WeightTraining, shown with a dumbbell):

Week Strength
Build up to 2 × Strength (40 min): heavy, low reps, plyometrics
The 2 build weeks before a taper (peak) 1 × Strength maintenance (30 min)
Recovery and taper weeks 1 × Mobility (20 min)
Race week none

They go on training days only, after the endurance sessions are placed (which never move for them): never on a day that already holds two sessions, never the day before an interval, long or openers session (also across a week's end), never on a taper week's key-session day, and never on consecutive days. Preferred strength days come first, then days with an easy session, then free days; a long or interval day is the last resort. A session that finds no day is left out and the week says so.

Each session lists its exercises with sets × reps and what they do (squat, Romanian deadlift, split squats, step-ups, single-leg work, jumps, calf raises, core; mobility flows and hip/glute activation in mobility weeks) — the engine's default text, or the LLM's version when a provider is set. It is plain text, not step syntax, and is sent to Intervals.icu like any other session.

Load accounting. A strength session carries a small fixed TSS estimate (25 / 15 / 5), shown on its tile, but it is counted apart: it is not in the week's TSS target or planned TSS, the load graph, the projected CTL, the weekly-hours budget or the 80/20 share. The week card shows it on its own line ("2 strength & mobility sessions · 80 min, outside the TSS target"). Completed WeightTraining (also Yoga/Pilates) activities count as done for a planned strength session, are judged on duration only, and are left out of the week's actual endurance load and the Weekly review's 80/20 split; the Weekly review shows Strength & mobility: N of M sessions. A missed strength session is moved to the next day that keeps the same rules (never onto or before a hard day), or let go; a moved key session never lands the day after a strength session.

AI-authored session content. Every number — date, sport, slot, minutes, load — is always the deterministic engine's; separately, each session's name and description (a short one-line summary, shown next to the name where the preview and the week grid otherwise show only it, and a detailed set-by-set description, as today) are written by whichever LLM provider you've configured in Settings → AI trainer → Models (Claude, Ollama or OpenAI-compatible servers, with failover). No provider configured, a slow or failing one, or a response that doesn't parse: generation still succeeds, and the affected sessions keep the engine's own plain text instead — nothing about plan generation requires an LLM. In a swim-including plan, the swim Z2 session on every other build/ build_plus/peak week is a technique session (named drills — catch-up drill, fingertip drag, bilateral breathing, high-elbow catch — instead of plain effort percentages); which weeks get one is always the engine's choice, never the model's.

Activities

Every cached activity, most recent first — filtered to one sport when you arrive from a sport row on Statistics, with a chip you can clear to see the rest. Tap one for distance, duration, TSS, elevation, heart rate, power, calories (whichever of those the activity actually has), and a time-in-zone chart when zone data is present. Open in Intervals.icu at the bottom goes to that activity's full page on intervals.icu — for what this screen doesn't show (the map, power curves, comments).

This year (Overview tab). Under the figures, a compact card "This year · Ride" (YearSportCard) puts the session in its year: the sport's sessions, hours, distance and TSS so far (a past year: the whole year), what share of the sport's distance this session is ("This session is 3 % of your 4,210 km"; for strength, or a session without distance, of the time), where it ranks among the year's sessions of that sport by distance (by TSS without distance) when it is in the top ten ("No. 4 of 31 by distance this year"), and the change in time against the same date last year. A year that isn't fully synced says so instead of comparing. The planned session's detail screen and the plan session sheet carry a one-line version ("Run this year: 82 h · 1,034 km"), and the hold-peek of an Activities row too (left out there when the year isn't fully synced, to keep the card small).

Evaluation. Above the time series, the session is judged against the planned session it matches (same day and sport; of several, the nearest in duration): On target, Too hard, Too easy or Cut short, always with the figures behind it — e.g. "45 of 60 planned minutes", or "planned easy, but 33% of the time was above the first threshold (limit 25%)" — and planned versus actual minutes and TSS. The intensity split folds the zone times into low / moderate / high (the same folding the agent uses); without zone times it says the split can't be assessed rather than guess. Aerobic decoupling is shown only for a steady session of an hour or more. All of this is code (lib/evaluation/session_evaluator.dart); thresholds follow the 80/20 rule in the training knowledge. Ask the trainer opens Chat with the session and its evaluation attached (shown as an "About: …" chip, not as a message).

Over time. The power, heart-rate, speed, cadence and altitude streams are fetched from Intervals.icu the first time you open an activity and cached in SQLite (activity_streams), so later opens work offline. Toggle streams with the chips; each is drawn on its own scale, work intervals are shaded, and pressing or dragging shows every stream's value at that moment. Long rides are downsampled before painting. Detected intervals are listed with duration and average power / HR / pace. A manual entry without streams says so; a failed fetch offers Retry. A planned session's detail screen shows Done: … with planned versus actual when an activity matched it.

Insights. Below the diagram: new personal bests from this session (with the previous best when known), for an easy session its efficiency against your recent easy sessions of the same sport ("+4% vs. the last 6 weeks", or too few sessions to say), and for today's session roughly how long recovery takes. When that runs into a hard session planned for tomorrow, Find alternative opens Train now for tomorrow.

New training pop-up. When you open the app and the sync brings in a session from today you haven't looked at, it pops up once: one page per session (swipe between them) with its evaluation and insights. OK closes it and it won't show again; opening the session's detail counts too. Turn it off under Settings → App → Notifications.

Settings

  • Guided setup (top of Settings): the first-run guide, run again with what is already set filled in — connect Intervals.icu (skipped when connected), sync your data (this month / this year / everything, with the counts that came in), sports and weekly hours, year goals (km per sport chosen), races and events (opens the event editor on an A race or any event; needs a connection) and the AI trainer (an existing setup is kept unless you change the provider, its server or enter a new key). Clicking Next through a step keeps its values; Close leaves at once. Ends with Back to Settings.
  • Appearance: pick System, Light, or Dark. Applies instantly across the whole app and is remembered across restarts (ThemeController, shared_preferences).
  • Language: System (follows the device), English or Deutsch. Applies instantly and is remembered across restarts.
  • Fatigue & soreness: whether opening a recent activity asks once how the day felt (fatigue and soreness), when that day has nothing logged yet. Logging it by hand from any activity's page works either way.
  • Navigation: what the bottom bar holds now, and Customize navigation to arrange it (see Arrange the menu).
  • Info: below the four groups, an Info row and the version in small type ("TriIQ 0.9.6 (build 1) · Android"). Both open About / Info and the SBOM.
  • Home-screen widget: choose what the Android widget shows — today's sessions, completed TSS, form, CTL/ATL, the weekly target rings and the update time. All are on by default; a change reaches the widget at once. Widget sizes too small for a block leave it out anyway.
  • Notifications: the master toggle prompts for the OS notification permission (Android 13+/iOS) and, once granted, turns on sync-completion and training-agent-reply notifications. With it on and on a platform that supports scheduling (Android/iOS — not Windows), a daily training reminder toggle and time picker appear underneath.
  • Sync: how often the open app refreshes the current month, and (Android) the Keep syncing in background switch (on by default). With it on, TriIQ refreshes the current week and your planned sessions even when closed — only with a network and a battery that isn't low — at the interval you pick: every 15 min, hourly, every 6 h or nightly (the default, around 02:00–05:00). It shows when it last ran and how it went. With notifications on, you get a notification when a background run brought new activities or new or changed planned sessions — nothing when nothing changed. If Android skips runs, set TriIQ's battery usage to "Unrestricted" (Apps → TriIQ → Battery). Opening the app always fetches today straight away. On Windows, iOS and web the app only syncs while it is open.
  • Calendar: two independent switches, both on by default. Send plan to Intervals.icu — off keeps taken plans in TriIQ only; turning it back on offers to send the current plan's upcoming sessions that aren't there yet. Copy planned events from Intervals.icu — off stops every sync (manual, automatic, nightly) from fetching planned events and hides the cached ones (they are kept, not deleted); Calendar, Today and Statistics then show only TriIQ plan sessions and completed activities. Turning it on shows them again and syncs the current month.
  • Weekly targets: an independent weekly training-time goal, in hours, for swim, cycle and run — set any or all of them, or leave a field blank for no target on that sport. Show on Today controls whether the rings appear on Today at all, separately from the targets themselves. Both persist across restarts.
  • Models (AI trainer): the ordered list of models the trainer may use. Each row shows its name, provider, model and host, a status (Ready / OK · last answered 14:02 / Needs attention: no API key / Paused until 14:10 — reason / Waiting for your consent / Off), an on/off switch and Up, Down, Test, Edit, Delete (Delete asks first and removes the stored key). Drag the handle to reorder; screen readers get Move up / down / to start / to end. Add model opens the same editor as Edit: a name, the provider chips and that provider's fields below — nothing is stored until Save.
  • Use several models and fail over: put the one you prefer first. When it is unreachable, rate-limited, overloaded or misconfigured, the next enabled one answers the same message; the reply notes the switch and shows which model answered. A model that failed twice is paused for 5 minutes (Test resumes it). A new model on a third-party server asks for consent for that server. Per provider:
  • Claude needs an API key from console.anthropic.com. It's stored in your OS credential vault (same place as the Intervals.icu key) and sent only to Anthropic; usage is billed to your own Anthropic account.
  • Ollama defaults to Ollama Cloud (https://ollama.com), which needs an API key — Get a key next to the field opens ollama.com/settings/keys. Pressing Save key tests the connection first and only stores it if that succeeds; the model field's suggestion chips then switch from generic defaults to whatever's actually available on your account. Point the server URL at a local/self-hosted instance instead (e.g. http://localhost:11434) and no key is needed — use Test connection to check reachability and list its models the same way. Either way the model must support tool calling, or the agent can't read your training data at all; the default is gpt-oss:120b.
  • OpenAI-compatible works with OpenAI, OpenRouter, Azure-style proxies, LiteLLM, LM Studio, vLLM, llama.cpp and similar. Enter the Base URL (default https://api.openai.com/v1; usually ends in /v1), a Model name (or press Load models to pick from the server's list) and, if the server needs one, an API key (stored in the OS vault, sent only to that URL). https:// works for any server; plain http:// only for localhost or an address on your own network (192.168.x.x, 10.x.x.x, 172.16–31.x.x) — Settings explains why when you enter anything else. A server on your own network is treated as a local model (data stays with you); anything else is a third party, and the consent text names its address. The model must support tool calling; if the server rejects it the chat says so. All of this is remembered across restarts, and changing it takes effect on your next message. (The per-provider "Save key" buttons became the editor's single Save; an Ollama Cloud key is still tested before it is stored.)

Sync

Manually pull a range of history into the local cache:

Option Range
Today today only
This month 1st of the current month → today
This year Jan 1 of the current year → today
Everything (initial sync) 2000-01-01 → today

Each run shows how many wellness/activity records were synced, and the card at the top shows the currently cached date range.

4. Known gaps / next steps

  • Today follow-ups from issue #78 not built yet: a compact/comfortable density toggle in Customize Today, haptics beyond the light tap on "Log how it felt" and the move's selection click, recovery tips on rest days (the hero names the next key session instead), skeleton placeholders instead of the spinner while Today loads, and sending a session to the watch from Start (it opens the steps). The attention stack hides a card kind for the day as a whole; threshold suggestions no longer have their own on/off switch (they follow the attention section).

  • Calendar follow-ups from issue #73 not built yet: a plan overlay (ghost of the original plan vs. moved / missed / extra), an agenda/list mode with weekly totals, search ("my last long run"), a weather icon on the next 7 days, a tablet/desktop split view (month left, day timeline right), Copy day to…, Shift week by a day and Make recovery week in the week menu (needs a one-tap path to a recovery load curve), a "key sessions only" filter, and session steps inline on the day view (they open from the row). Drag-and-drop only reaches days on screen (month grid or week); farther moves go through Move to….

  • Chart follow-ups left out of the D3-style pass (issue #65): a radial (ring) load view, a sankey of sport → zone time, scatter and violin plots, and exporting a chart as PNG. Brush-to-zoom on the plot itself is wired nowhere yet (only the overview strip brushes), since hold already opens options on several cards.

  • Threshold suggestions: the ride FTP down-suggestion and the "within 90 days" window lean on the 42d/s0 curve periods Intervals.icu exposes rather than a precise custom rolling window (no per-effort date is tied to a model fit); the run ~40-minute-effort fallback's 1.02 scaling factor is a heuristic that may need tuning against real data; zone-percentage semantics in the confirm sheet's before/after table are inferred from the settings model, not confirmed against a live account.

  • Knowledge library: Markdown/plain-text only (no PDF/DOCX/HTML import); search is keyword/heading scoring, not semantic; documents don't sync across devices (they are included in the JSON backup, so Export / Restore is the way to move them); no in-app editing, only import/enable/disable/delete.
  • The workout step syntax sent by Create in Intervals.icu is written by the model and validated only server-side: if Intervals.icu can't parse a line it silently keeps it as description text instead of a step. A local parser (or reading back push_errors from the created event) would tell the athlete which it was.
  • "Train now" workouts always land on today (plan sessions have their own dates and can be moved in the plan preview).
  • Plan sessions can't be written to the phone's own calendar yet: the device_calendar plugin (3.9.0) fails to build under this project's Android Gradle Plugin (no namespace), the same problem as flutter_timezone. Each session's sheet offers Add to Google Calendar (a pre-filled link) instead.
  • Training plans: one event per goal (no B/C races or mini-tapers, no post-race recovery week), no brick sessions, one ramp cap for all sports. Swim templates use % of threshold swim pace and the engine's own TSS estimate, which is rougher than for ride and run. Sessions can't be edited individually in the week calendar (only moved in the preview).
  • AI-authored session content: like the step syntax Create in Intervals.icu writes, a technique session's drill text isn't parsed back against Intervals.icu's own step syntax, only sanity-checked locally (field length, roughly one line per 10 planned minutes). The short description shows in the generate-time preview and the week grid's accessibility label; the Calendar's day view still shows a plan session's name only — reaching it there would need a lookup back to the session's own row, not just the synced Intervals.icu event. Regenerating a session's content (e.g. after switching provider) needs regenerating the whole plan; a single already- sent session can't be re-authored on its own.
  • Persist chat history, so a conversation survives an app restart.
  • Expose the agent's tools over MCP as well as in-process, so an external client (Claude Desktop, an editor) could query the same cache. The tool layer is already a clean seam for it — TrainingDataTools has no Flutter dependency beyond loading the reference asset.
  • No token/cost accounting: a Claude conversation bills the user's own account with nothing in the UI saying how much.
  • Local SQLite storage on web (needs a wasm-backed sqflite variant).
  • Web has no local cache: sqflite needs a wasm-backed implementation there, so sync is Android/Windows only (see Sync & local cache).
  • Revisit flutter_timezone for the daily reminder once a version exists that builds under this project's AGP — the fixed-offset workaround in NotificationService is fine but not exact across a DST change.
  • No background sync on Windows (same missing closed-app wake as the daily reminder below); the periodic job is Android only. Follow-up: a Windows tray / Task Scheduler entry that keeps syncing (and notifying) with the window closed — deliberately not attempted yet.
  • No foreground service on Android for the background sync: WorkManager runs can be delayed or skipped by OEM battery savers. A battery- optimisation exemption button would need a new plugin or native code; Settings only explains where to change it.
  • No daily-reminder scheduling on Windows (see Notifications) — would need real background-wake support, e.g. a Task Scheduler entry, which is a separate, heavier piece of work.

5. Training knowledge

The rules and session templates the plan engine (lib/plan/) and the chat agent (get_session_template) read. This file is bundled as an app asset; the parser (KnowledgeRepository) reads only fenced blocks whose info string is okf-rules, okf-goal or okf-template. Everything else here is prose for humans. Each block is one JSON object (valid YAML as well). A block that fails to parse is skipped and reported; the engine falls back to built-in defaults rather than generate from half a rule set.

The numbers below are defaults, not universal truths — the multipliers, the ramp limits and the tolerance are starting points the athlete can override (per-goal ramp limits are editable on the Plan screen). Physiology background lives in the optional training reference (assets/knowledge/); this section only holds what the engine needs to be deterministic.

5.1 Block rules

A plan runs 2-16 weeks (default 8, or the weeks up to and including the event week; see Taper and race week under 5.3). Every non-recovery week has the same session types per sport (Z2 base, one interval session, one long session; swim has no long session); only the volume changes. The engine proposes a ramp from the athlete's baseline weekly load (the mean of the last 4 completed weeks): each week is at most maxWeeklyIncrease above the one before, and also held below maxCtlRamp (projected CTL gain per week) and the weekly hours budget; every holdEveryWeeksth week (default 4) keeps the previous week's load when the goal keeps the hold on. No recovery dips are inserted; the athlete shapes the curve in the load graph (80-120% of the proposal per week), and a week below recoveryThreshold of the week before it is built from recovery templates. weekPhases/weekMultipliers describe the classic 4-week shape for the agent's explanations; the curve does not use them. lowIntensityTarget is the 80/20 share of time spent at low intensity, lowIntensityTolerance how far below it a week may fall before it is flagged (more easy time than the target is not a problem). recoveryHours maps a session's TSS to recovery hours ([upTo, hours], null = above the last band); recoveryFormPenaltyBelow adds 12 h when form (CTL − ATL) is below it. readiness holds the daily readiness thresholds, each pair [caution, back off]: hrvSd (MADσ below the HRV baseline median), restingHrBpm and restingHrMad (resting HR at least this many bpm and this many MADσ above the baseline median — whichever is more), sleepHoursCaution (caution only), form, acwr (ATL ÷ CTL at or above), dayLoadVsCtl (today's load as a multiple of CTL, at or above), minCtl (below this CTL there is too little history for the two load ratios), deviceReadiness (the device's 0–100 figure, below), the baseline window (baselineDays, minBaselineDays values needed), smoothingDays (HRV and resting HR are rated by the median of this many latest days with a value; the athlete can override it with 3 or 5 in the readiness options), outlierMad (baseline readings this far from the median are dropped) and the hysteresis: a raised HRV / resting-HR level clears only after the smoothed value has been back past its threshold by restingHrClearBpm bpm / hrvClearSd MADσ on clearDays days in a row (see "How HRV and resting HR are rated" under Today). Defaults: acwr [1.3, 1.5], dayLoadVsCtl [1.5, 2.5], minCtl 10, deviceReadiness [50, 25]. Fatigue or soreness at 4, the worst of Intervals.icu's 1-4 scale, is a caution.

{
  "weekPhases": ["build", "build_plus", "peak", "recovery"],
  "weekMultipliers": [1.0, 1.08, 1.15, 0.6],
  "maxWeeklyIncrease": 0.10,
  "maxCtlRamp": 7.0,
  "lowIntensityTarget": 0.8,
  "lowIntensityTolerance": 0.05,
  "minHistoryWeeks": 4,
  "recoveryThreshold": 0.9,
  "holdEveryWeeks": 4,
  "recoveryHours": [[50, 12], [100, 24], [200, 36], [null, 48]],
  "recoveryFormPenaltyBelow": -20,
  "taper": {
    "long_distance": [0.7, 0.5],
    "short_event": [0.6]
  },
  "readiness": {
    "hrvSd": [1, 2],
    "restingHrBpm": [3, 6],
    "restingHrMad": [1.5, 2.5],
    "sleepHoursCaution": 6,
    "form": [-20, -30],
    "acwr": [1.3, 1.5],
    "dayLoadVsCtl": [1.5, 2.5],
    "minCtl": 10,
    "deviceReadiness": [50, 25],
    "baselineDays": 60,
    "minBaselineDays": 21,
    "smoothingDays": 3,
    "outlierMad": 4,
    "restingHrClearBpm": 1,
    "hrvClearSd": 0.25,
    "clearDays": 2
  }
}

Strength & mobility sessions are not part of these rules or of a goal's load split: their dose per phase, durations, fixed TSS and placement rules are built into the engine (lib/plan/strength.dart), see Training plan → Strength & mobility above.

5.2 Goals

A goal splits a week's load between its session slots. count is how many sessions of that slot per week; share is the slot's fraction of the week's load (shares sum to 1). When the athlete has fewer training days than sessions, Z2 sessions are dropped first.

{
  "id": "long_distance",
  "label": "Long distance",
  "slots": {
    "z2": { "count": 2, "share": 0.30 },
    "intervals": { "count": 1, "share": 0.30 },
    "long": { "count": 1, "share": 0.40 }
  }
}
{
  "id": "short_event",
  "label": "Short event (speed)",
  "slots": {
    "z2": { "count": 2, "share": 0.30 },
    "intervals": { "count": 1, "share": 0.40 },
    "long": { "count": 1, "share": 0.30 }
  }
}

5.3 Session templates

One template per goal, slot and phase. Duration is derived, not stored: slot load share x week load / tssPerHour. lowShare is the fraction of the session's time at low intensity (Z1-Z2) and feeds the 80/20 check. steps are a structure the engine turns into Intervals.icu step syntax:

  • {"kind": "fixed", "minutes": 10, "pct": 60} — a fixed step;
  • {"kind": "fill", "pct": 68} — takes whatever time is left;
  • {"kind": "repeat", "work": {...}, "rest": {...}, "min": 3, "max": 8} — as many work/rest pairs as fit the remaining time, between min and max.

pct is a number, or {"Ride": .., "Run": ..} when the same effort needs a different figure per sport (Ride: % of FTP; Run: % of threshold pace). sports lists the Intervals.icu sports a template is for; without it a template serves Ride and Run. Swim templates say "sports": ["Swim"] and use % of threshold swim pace (CSS).

{
  "id": "long_distance.z2",
  "goal": "long_distance", "slot": "z2",
  "phases": ["build", "build_plus", "peak", "recovery", "taper"],
  "name": "Z2 endurance",
  "tssPerHour": 50, "lowShare": 1.0,
  "steps": [
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "fill", "pct": {"Ride": 68, "Run": 82}},
    {"kind": "fixed", "minutes": 5, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "long_distance.intervals.build",
  "goal": "long_distance", "slot": "intervals",
  "phases": ["build"],
  "name": "Tempo-threshold intervals",
  "tssPerHour": 75, "lowShare": 0.5,
  "steps": [
    {"kind": "fixed", "minutes": 15, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "repeat", "min": 3, "max": 5,
     "work": {"minutes": 8, "pct": {"Ride": 90, "Run": 95}},
     "rest": {"minutes": 4, "pct": {"Ride": 50, "Run": 70}}},
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "long_distance.intervals.build_plus",
  "goal": "long_distance", "slot": "intervals",
  "phases": ["build_plus"],
  "name": "Threshold intervals",
  "tssPerHour": 75, "lowShare": 0.5,
  "steps": [
    {"kind": "fixed", "minutes": 15, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "repeat", "min": 3, "max": 5,
     "work": {"minutes": 10, "pct": {"Ride": 95, "Run": 98}},
     "rest": {"minutes": 4, "pct": {"Ride": 50, "Run": 70}}},
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "long_distance.intervals.peak",
  "goal": "long_distance", "slot": "intervals",
  "phases": ["peak"],
  "name": "Threshold and over-under intervals",
  "tssPerHour": 78, "lowShare": 0.5,
  "steps": [
    {"kind": "fixed", "minutes": 15, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "repeat", "min": 3, "max": 5,
     "work": {"minutes": 12, "pct": {"Ride": 98, "Run": 100}},
     "rest": {"minutes": 4, "pct": {"Ride": 50, "Run": 70}}},
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "long_distance.intervals.recovery",
  "goal": "long_distance", "slot": "intervals",
  "phases": ["recovery"],
  "name": "Easy aerobic with short strides",
  "tssPerHour": 55, "lowShare": 0.9,
  "steps": [
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "fill", "pct": {"Ride": 65, "Run": 80}},
    {"kind": "repeat", "min": 4, "max": 6,
     "work": {"minutes": 1, "pct": {"Ride": 110, "Run": 105}},
     "rest": {"minutes": 2, "pct": {"Ride": 50, "Run": 70}}},
    {"kind": "fixed", "minutes": 5, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "long_distance.long",
  "goal": "long_distance", "slot": "long",
  "phases": ["build", "build_plus", "peak", "recovery"],
  "name": "Long endurance",
  "tssPerHour": 58, "lowShare": 0.8,
  "steps": [
    {"kind": "fixed", "minutes": 15, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "fill", "pct": {"Ride": 70, "Run": 84}},
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "short_event.z2",
  "goal": "short_event", "slot": "z2",
  "phases": ["build", "build_plus", "peak", "recovery", "taper"],
  "name": "Z2 endurance",
  "tssPerHour": 50, "lowShare": 1.0,
  "steps": [
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "fill", "pct": {"Ride": 68, "Run": 82}},
    {"kind": "fixed", "minutes": 5, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "short_event.intervals",
  "goal": "short_event", "slot": "intervals",
  "phases": ["build", "build_plus", "peak"],
  "name": "VO2max intervals",
  "tssPerHour": 80, "lowShare": 0.55,
  "steps": [
    {"kind": "fixed", "minutes": 15, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "repeat", "min": 4, "max": 8,
     "work": {"minutes": 3, "pct": {"Ride": 115, "Run": 108}},
     "rest": {"minutes": 3, "pct": {"Ride": 45, "Run": 65}}},
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "short_event.intervals.recovery",
  "goal": "short_event", "slot": "intervals",
  "phases": ["recovery"],
  "name": "Easy aerobic with short strides",
  "tssPerHour": 55, "lowShare": 0.9,
  "steps": [
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "fill", "pct": {"Ride": 65, "Run": 80}},
    {"kind": "repeat", "min": 4, "max": 6,
     "work": {"minutes": 1, "pct": {"Ride": 110, "Run": 105}},
     "rest": {"minutes": 2, "pct": {"Ride": 50, "Run": 70}}},
    {"kind": "fixed", "minutes": 5, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "short_event.long",
  "goal": "short_event", "slot": "long",
  "phases": ["build", "build_plus", "peak", "recovery"],
  "name": "Long endurance",
  "tssPerHour": 58, "lowShare": 0.85,
  "steps": [
    {"kind": "fixed", "minutes": 15, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "fill", "pct": {"Ride": 70, "Run": 84}},
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 50, "Run": 70}}
  ]
}

Swim (triathlon)

A triathlon plan gives swim a Z2 and an interval session per week (no long swim); the shares of the goal's z2 and intervals slots are renormalised between the two.

{
  "id": "long_distance.swim.z2",
  "goal": "long_distance", "slot": "z2", "sports": ["Swim"],
  "phases": ["build", "build_plus", "peak", "recovery", "taper"],
  "name": "Aerobic swim",
  "tssPerHour": 40, "lowShare": 1.0,
  "steps": [
    {"kind": "fixed", "minutes": 5, "pct": 75},
    {"kind": "fill", "pct": 82},
    {"kind": "fixed", "minutes": 5, "pct": 72}
  ]
}
{
  "id": "long_distance.swim.intervals",
  "goal": "long_distance", "slot": "intervals", "sports": ["Swim"],
  "phases": ["build", "build_plus", "peak"],
  "name": "Threshold swim",
  "tssPerHour": 55, "lowShare": 0.55,
  "steps": [
    {"kind": "fixed", "minutes": 10, "pct": 75},
    {"kind": "repeat", "min": 4, "max": 10,
     "work": {"minutes": 3, "pct": 98},
     "rest": {"minutes": 1, "pct": 70}},
    {"kind": "fixed", "minutes": 5, "pct": 72}
  ]
}
{
  "id": "long_distance.swim.intervals.recovery",
  "goal": "long_distance", "slot": "intervals", "sports": ["Swim"],
  "phases": ["recovery"],
  "name": "Easy technique swim",
  "tssPerHour": 38, "lowShare": 0.9,
  "steps": [
    {"kind": "fixed", "minutes": 5, "pct": 75},
    {"kind": "fill", "pct": 80},
    {"kind": "repeat", "min": 4, "max": 6,
     "work": {"minutes": 1, "pct": 95},
     "rest": {"minutes": 1, "pct": 70}},
    {"kind": "fixed", "minutes": 5, "pct": 72}
  ]
}
{
  "id": "short_event.swim.z2",
  "goal": "short_event", "slot": "z2", "sports": ["Swim"],
  "phases": ["build", "build_plus", "peak", "recovery", "taper"],
  "name": "Aerobic swim",
  "tssPerHour": 40, "lowShare": 1.0,
  "steps": [
    {"kind": "fixed", "minutes": 5, "pct": 75},
    {"kind": "fill", "pct": 82},
    {"kind": "fixed", "minutes": 5, "pct": 72}
  ]
}
{
  "id": "short_event.swim.intervals",
  "goal": "short_event", "slot": "intervals", "sports": ["Swim"],
  "phases": ["build", "build_plus", "peak"],
  "name": "Speed swim",
  "tssPerHour": 60, "lowShare": 0.55,
  "steps": [
    {"kind": "fixed", "minutes": 10, "pct": 75},
    {"kind": "repeat", "min": 6, "max": 12,
     "work": {"minutes": 2, "pct": 103},
     "rest": {"minutes": 1, "pct": 70}},
    {"kind": "fixed", "minutes": 5, "pct": 72}
  ]
}
{
  "id": "short_event.swim.intervals.recovery",
  "goal": "short_event", "slot": "intervals", "sports": ["Swim"],
  "phases": ["recovery"],
  "name": "Easy technique swim",
  "tssPerHour": 38, "lowShare": 0.9,
  "steps": [
    {"kind": "fixed", "minutes": 5, "pct": 75},
    {"kind": "fill", "pct": 80},
    {"kind": "repeat", "min": 4, "max": 6,
     "work": {"minutes": 1, "pct": 95},
     "rest": {"minutes": 1, "pct": 70}},
    {"kind": "fixed", "minutes": 5, "pct": 72}
  ]
}

Taper and race week. When the goal has an event date and the plan's last week contains it, the last weeks are a taper: taper in the rules lists, per goal type, each taper week's load as a fraction of the last week before the taper (two weeks at 70 % and 50 % for long distance, one at 60 % for a short event). The interval session stays, shorter, so intensity is kept while volume drops; taper templates carry shareScale, which scales a slot's share of its sport's load before the sport is renormalised, so the long session (0.6) shrinks more than the week. Z2 templates serve the taper unchanged. In the event week nothing is placed on the event day or after it, and the day before gets the short openers session when it is a training day.

{
  "id": "long_distance.intervals.taper",
  "goal": "long_distance", "slot": "intervals",
  "phases": ["taper"],
  "name": "Taper threshold intervals",
  "tssPerHour": 75, "lowShare": 0.55, "shareScale": 1.2,
  "steps": [
    {"kind": "fixed", "minutes": 15, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "repeat", "min": 2, "max": 4,
     "work": {"minutes": 6, "pct": {"Ride": 98, "Run": 100}},
     "rest": {"minutes": 3, "pct": {"Ride": 50, "Run": 70}}},
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "long_distance.long.taper",
  "goal": "long_distance", "slot": "long",
  "phases": ["taper"],
  "name": "Taper endurance",
  "tssPerHour": 58, "lowShare": 0.85, "shareScale": 0.6,
  "steps": [
    {"kind": "fixed", "minutes": 15, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "fill", "pct": {"Ride": 70, "Run": 84}},
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "short_event.intervals.taper",
  "goal": "short_event", "slot": "intervals",
  "phases": ["taper"],
  "name": "Taper VO2max intervals",
  "tssPerHour": 78, "lowShare": 0.6, "shareScale": 1.2,
  "steps": [
    {"kind": "fixed", "minutes": 15, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "repeat", "min": 3, "max": 5,
     "work": {"minutes": 2, "pct": {"Ride": 115, "Run": 108}},
     "rest": {"minutes": 3, "pct": {"Ride": 45, "Run": 65}}},
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "short_event.long.taper",
  "goal": "short_event", "slot": "long",
  "phases": ["taper"],
  "name": "Taper endurance",
  "tssPerHour": 58, "lowShare": 0.85, "shareScale": 0.6,
  "steps": [
    {"kind": "fixed", "minutes": 15, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "fill", "pct": {"Ride": 70, "Run": 84}},
    {"kind": "fixed", "minutes": 10, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "long_distance.swim.intervals.taper",
  "goal": "long_distance", "slot": "intervals", "sports": ["Swim"],
  "phases": ["taper"],
  "name": "Taper threshold swim",
  "tssPerHour": 52, "lowShare": 0.6, "shareScale": 1.2,
  "steps": [
    {"kind": "fixed", "minutes": 10, "pct": 75},
    {"kind": "repeat", "min": 3, "max": 6,
     "work": {"minutes": 2, "pct": 98},
     "rest": {"minutes": 1, "pct": 70}},
    {"kind": "fixed", "minutes": 5, "pct": 72}
  ]
}
{
  "id": "short_event.swim.intervals.taper",
  "goal": "short_event", "slot": "intervals", "sports": ["Swim"],
  "phases": ["taper"],
  "name": "Taper race-pace swim",
  "tssPerHour": 55, "lowShare": 0.6, "shareScale": 1.2,
  "steps": [
    {"kind": "fixed", "minutes": 10, "pct": 75},
    {"kind": "repeat", "min": 3, "max": 6,
     "work": {"minutes": 2, "pct": 102},
     "rest": {"minutes": 1, "pct": 70}},
    {"kind": "fixed", "minutes": 5, "pct": 72}
  ]
}
{
  "id": "long_distance.openers",
  "goal": "long_distance", "slot": "intervals",
  "phases": ["openers"],
  "name": "Race openers",
  "tssPerHour": 55, "lowShare": 0.8,
  "steps": [
    {"kind": "fixed", "minutes": 12, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "repeat", "min": 3, "max": 3,
     "work": {"minutes": 1, "pct": {"Ride": 105, "Run": 103}},
     "rest": {"minutes": 2, "pct": {"Ride": 50, "Run": 70}}},
    {"kind": "fixed", "minutes": 5, "pct": {"Ride": 50, "Run": 70}}
  ]
}
{
  "id": "short_event.openers",
  "goal": "short_event", "slot": "intervals",
  "phases": ["openers"],
  "name": "Race openers",
  "tssPerHour": 55, "lowShare": 0.8,
  "steps": [
    {"kind": "fixed", "minutes": 12, "pct": {"Ride": 55, "Run": 75}},
    {"kind": "repeat", "min": 3, "max": 3,
     "work": {"minutes": 1, "pct": {"Ride": 110, "Run": 105}},
     "rest": {"minutes": 2, "pct": {"Ride": 50, "Run": 70}}},
    {"kind": "fixed", "minutes": 5, "pct": {"Ride": 50, "Run": 70}}
  ]
}