Apple Health Advisor
Use this skill when a user wants to analyze an Apple Health export ZIP. The ZIP is too large to fit directly into context, so the skill uses a local CLI pipeline to parse and structure the data first.
This is one skill that ships two complementary reports:
- Default (recommended): generate BOTH reports — health report + training report, rendered into the same
output/ folder and cross-linked via an in-page link in the topbar. prepare runs once, then render runs twice.
- Explicit health-only: user says "只要健康报告" / "health report only" / similar → skip training render.
- Explicit training-only: user says "只要运动报告" / "training report only" / similar → skip health render. Naming a sport without saying "only" still produces both reports and prioritizes that sport in the training narrative.
Language Detection
Detect the user's language from their message:
- If the user writes in Chinese, use
--lang zh
- For all other languages, use
--lang en
The narrative language must match the language declared in insights.json:
- Health report:
narrativeContext.language
- Training report:
training.narrativeContext.language
Intent Routing
Default: generate both health + training reports. Only drop one when the user is explicit.
- Default (both) examples:
Analyze my Apple Health export
帮我分析 Apple Health 导出
Generate a report from my Apple Health export
- Health-only examples (skip training render):
Only generate the health report
只要健康报告
不用生成运动报告
- Training-only examples (skip health render):
Only generate the training report
只要运动报告
只生成运动报告,重点分析拳击
Only generate the training report for running and cycling
- Named-sport examples that still default to both:
Ambiguous-but-lean-training keywords still default to both reports (the training report alone is rarely enough context). The keywords below only matter as hints — they do NOT suppress the health report unless the user also says "只" / "only":
training, workout, 运动, 训练, 专项
- named sports such as
boxing, running, cycling, walking, hiking, strength training, 拳击, 跑步, 骑行, 力量训练
Your Role
Two roles share the same pipeline:
- Health management advisor:
- Integrate sleep, recovery, activity, and body metrics into an overall health view
- Prioritize cross-metric reasoning over metric-by-metric reporting
- Training status advisor:
- Judge load, recovery support, consistency, and sport-specific trends
- Give actionable training-management advice without pretending to be Garmin or a coach writing a periodized plan
Workflow
- Confirm the input is an official Apple Health export ZIP and that the main XML has
HealthData as its root node.
- Run local
prepare once with the correct --lang, producing summary.json and insights.json.
Raw ZIP/XML parsing stays local. If the active agent uses a hosted model for
the narrative, the structured JSON it reads may be processed by that model
provider; follow the provider's data controls and the repository privacy notice.
- Read
summary.json, then insights.json.
- Decide which reports to produce (default = both unless the user is explicit; see Intent Routing).
- For each selected report, write the narrative JSON:
- health:
report.llm.json
- training:
training.report.llm.json
- Run
render for each selected report:
- health: default
render
- training:
render --type training
- Both HTML reports share the same
output/ folder. The topbar carries a cross-link between them, so the user can jump back and forth. File names are fixed (report.html ↔ training.report.html) — do not rename.
insights.json Keys You Must Use
Shared
| Key |
What it contains |
metadata |
tool, version, language, schemaVersion, generatedAt |
historicalContext |
Recent 30d, baseline 90d, trailing 180d, all-time context |
charts[] |
Health chart groups |
crossMetric |
Cross-metric health reasoning |
riskFlags[] |
Health risks with evidence |
notableChanges[] |
Significant changes |
dataGaps[] |
Missing or sparse data warnings |
sourceConfidence[] |
Device/source reliability signals |
Health report
| Key |
What it contains |
analysis.sleep |
Sleep duration, stages, timing, regularity |
analysis.recovery |
RHR, HRV, blood oxygen, respiratory rate, VO2 max |
analysis.activity |
Active energy, exercise minutes, stand hours, workouts |
analysis.bodyComposition |
Weight, body fat % |
analysis.menstrualCycle |
Cycle analysis if present |
narrativeContext |
Health-report audience, goal, schema version, boundaries |
Training report
| Key |
What it contains |
training.summary |
Training state, readiness, recent load, recovery support, primary sport |
training.summary.trainingLoad |
MET-minute EWMA load snapshot (42-day CTL baseline, 7-day ATL recent load, TSB load balance) + relative 30-day & 90-day changes; null when < 28 days of data or < 6 load-bearing workouts |
training.sports[] |
Top sports (dormant ones filtered, topSportCount configurable via --top-sports, default 5) with recent/baseline/trailing/all-time windows, recovery-after-workout, consistency, tags |
training.charts[] |
training_load (CTL/ATL monthly curve), training_recovery, and sport_<slug>_trend charts |
training.narrativeContext |
Training-report audience, goal, schema version, boundaries |
Commands
Default flow — prepare once, render twice so the folder contains both report sets. Pass --with-cross-link to both render calls so the topbar/footer cross-link lights up; omit it on single-report runs to avoid a dead link to a file that will not exist.
# 1. Prepare once (shared by both reports)
# Optional: --top-sports N to cap the training-report sport list (default 5)
npx apple-health-analyst prepare /path/to/export.zip --lang en --out ./output
# 2. Health render (fixed file name: report.html)
npx apple-health-analyst render \
--insights ./output/insights.json \
--narrative ./output/report.llm.json \
--with-cross-link \
--out ./output
# 3. Training render (fixed file name: training.report.html)
npx apple-health-analyst render \
--type training \
--insights ./output/insights.json \
--narrative ./output/training.report.llm.json \
--with-cross-link \
--out ./output
The two HTML files auto-link to each other via the topbar and footer only when --with-cross-link is set on both renders. Always write both into the same --out directory to keep the cross-links working.
Single-report mode: if the user is explicit about only wanting the health or the training report (see Intent Routing), run render once without --with-cross-link — otherwise the lone HTML will point at a companion file that never gets generated.
Health Narrative Framework
Use the existing health schema in references/report-llm-json.md.
Prioritize:
crossMetric.sleepRecoveryLink
crossMetric.sleepConsistency
crossMetric.activityRecoveryBalance
crossMetric.recoveryCoherence
crossMetric.patterns
riskFlags, notableChanges, and dataGaps
crossMetric.compositeAssessment remains in the output shape for compatibility,
but its scores are intentionally null: do not invent or narrate a composite
health score from heterogeneous consumer-device metrics.
Health writing rules:
- Every conclusion must cite concrete values or dates from
summary.json or insights.json
key_findings must be cross-metric, not single-metric trivia
actions_next_2_weeks must specify time, frequency, or numeric targets
questions_for_doctor must be data-driven and specific
- Use consumer-readable precision and do not repeat the same evidence across
assessment, overview, findings, and chart callouts
- Leave
when_to_seek_care and questions_for_doctor empty when there is no
risk, persistent change, or symptom-contingent follow-up supported by the data
Training Narrative Framework
Use the training schema in references/training-report-llm-json.md.
Prioritize:
training.summary.trainingState and training.summary.readiness
training.summary.trainingLoad — the scale-relative MET-minute EWMA trend; interpret together with recovery evidence
training.summary.loadTrend and training.summary.recoverySupport (legacy 30d-vs-90d views, use as corroboration)
training.sports[] in descending importance
training.charts[]
dataGaps[] and missing metric coverage
Training writing rules:
- Treat CTL as the 42-day personal load baseline, ATL as 7-day recent load, and TSB as their difference. Do not relabel them as fitness, fatigue, form, or readiness: this implementation uses MET-minutes rather than a calibrated TSS-like scale.
- Never apply absolute TSB thresholds. When
training.summary.trainingLoad is non-null, cite relative CTL direction (ctlDelta30dPct / ctlDelta90dPct) and combine it with explicit sleep, HRV, resting-heart-rate, or recoverySupport.adequate evidence.
- If
trainingLoad is null, fall back to loadTrend and say so explicitly (e.g. "数据覆盖不足 28 天,暂以 30 天对比为准")
- Sport sections must focus on the actual top sports in
training.sports[]
- Only discuss heart rate or distance when the structured data includes those metrics
- Recommendations are for training management and health monitoring, not race plans or diagnosis
- For a sport with no workouts in the last 30 days, keep recommendations empty;
do not infer that the user wants to restart it
- Do not prescribe fixed session counts for a named sport unless the user
explicitly requested a program; otherwise change one training variable at a time
Required Reading Before Writing Narrative
summary.json
insights.json
- references/report-llm-json.md for health mode
- references/training-report-llm-json.md for training mode
- references/safety-boundaries.md
- references/analysis-framework.md
Constraints
- Only reference facts from
summary.json and insights.json
- Do not fabricate sport metrics, chart IDs, or medical risks
- Provide health management and training adjustment advice, not diagnoses or treatment plans
- If a module is
insufficient_data, say so plainly
- Do not generate final HTML directly; write the narrative JSON first, then run
render
Error Handling
- ZIP format error: if
prepare cannot find the HealthData XML, verify the user provided the official Apple Health export ZIP. The main XML filename is not fixed and may be localized (for example 导出.xml) or appear as mojibake. export_cda.xml / ClinicalDocument is auxiliary only and should not be used as the main analysis input.
- Out of memory: parsing is streaming but retained supported records can still be large.
--from and --to constrain analysis output after parsing and do not currently reduce peak parse memory; use a machine with more memory or pre-filter a copy of the export with a trusted local tool
- Health narrative validation failure: verify
report.llm.json matches schema v3
- Training narrative validation failure: verify
training.report.llm.json matches schema v2 and only references existing sport/chart IDs
- npm cache EPERM: use
npm_config_cache=./.npm-cache
- Sandbox/policy rejection: do not chain destructive commands with
prepare / render; create directories separately if needed
Output Files
Always produced by prepare:
summary.json
insights.json
Health render (file names are fixed; do not rename):
report.llm.json
report.md
report.html
Training render (file names are fixed; do not rename):
training.report.llm.json
training.report.md
training.report.html
The two HTML reports cross-link via the topbar and footer using relative paths (./report.html ↔ ./training.report.html). Keep both in the same output/ directory for the links to work.
1---2name: apple-health-analyst3description: Analyze Apple Health export ZIP. Run local prepare to generate structured insights, then produce complementary health and training reports with long-term context.4---56# Apple Health Advisor78Use this skill when a user wants to analyze an Apple Health export ZIP. The ZIP is too large to fit directly into context, so the skill uses a local CLI pipeline to parse and structure the data first.910This is one skill that ships two complementary reports:1112- **Default (recommended): generate BOTH reports** — health report + training report, rendered into the same `output/` folder and cross-linked via an in-page link in the topbar. `prepare` runs once, then `render` runs twice.13- **Explicit health-only**: user says "只要健康报告" / "health report only" / similar → skip training render.14- **Explicit training-only**: user says "只要运动报告" / "training report only" / similar → skip health render. Naming a sport without saying "only" still produces both reports and prioritizes that sport in the training narrative.1516## Language Detection1718Detect the user's language from their message:1920- If the user writes in Chinese, use `--lang zh`21- For all other languages, use `--lang en`2223The narrative language must match the language declared in `insights.json`:2425- Health report: `narrativeContext.language`26- Training report: `training.narrativeContext.language`2728## Intent Routing2930**Default: generate both health + training reports.** Only drop one when the user is explicit.3132- Default (both) examples:33 - `Analyze my Apple Health export`34 - `帮我分析 Apple Health 导出`35 - `Generate a report from my Apple Health export`36- Health-only examples (skip training render):37 - `Only generate the health report`38 - `只要健康报告`39 - `不用生成运动报告`40- Training-only examples (skip health render):41 - `Only generate the training report`42 - `只要运动报告`43 - `只生成运动报告,重点分析拳击`44 - `Only generate the training report for running and cycling`45- Named-sport examples that still default to both:46 - `重点分析拳击训练状态`47 - `分析跑步和骑行训练趋势`4849Ambiguous-but-lean-training keywords still default to **both** reports (the training report alone is rarely enough context). The keywords below only matter as hints — they do NOT suppress the health report unless the user also says "只" / "only":5051- `training`, `workout`, `运动`, `训练`, `专项`52- named sports such as `boxing`, `running`, `cycling`, `walking`, `hiking`, `strength training`, `拳击`, `跑步`, `骑行`, `力量训练`5354## Your Role5556Two roles share the same pipeline:57581. Health management advisor:59 - Integrate sleep, recovery, activity, and body metrics into an overall health view60 - Prioritize cross-metric reasoning over metric-by-metric reporting612. Training status advisor:62 - Judge load, recovery support, consistency, and sport-specific trends63 - Give actionable training-management advice without pretending to be Garmin or a coach writing a periodized plan6465## Workflow66671. Confirm the input is an official Apple Health export ZIP and that the main XML has `HealthData` as its root node.682. Run local `prepare` once with the correct `--lang`, producing `summary.json` and `insights.json`.69 Raw ZIP/XML parsing stays local. If the active agent uses a hosted model for70 the narrative, the structured JSON it reads may be processed by that model71 provider; follow the provider's data controls and the repository privacy notice.723. Read `summary.json`, then `insights.json`.734. Decide which reports to produce (default = both unless the user is explicit; see Intent Routing).745. For each selected report, write the narrative JSON:75 - health: `report.llm.json`76 - training: `training.report.llm.json`776. Run `render` for each selected report:78 - health: default `render`79 - training: `render --type training`807. Both HTML reports share the same `output/` folder. The topbar carries a cross-link between them, so the user can jump back and forth. File names are fixed (`report.html` ↔ `training.report.html`) — do not rename.8182## `insights.json` Keys You Must Use8384### Shared8586| Key | What it contains |87|-----|-----------------|88| `metadata` | `tool`, `version`, `language`, `schemaVersion`, `generatedAt` |89| `historicalContext` | Recent 30d, baseline 90d, trailing 180d, all-time context |90| `charts[]` | Health chart groups |91| `crossMetric` | Cross-metric health reasoning |92| `riskFlags[]` | Health risks with evidence |93| `notableChanges[]` | Significant changes |94| `dataGaps[]` | Missing or sparse data warnings |95| `sourceConfidence[]` | Device/source reliability signals |9697### Health report9899| Key | What it contains |100|-----|-----------------|101| `analysis.sleep` | Sleep duration, stages, timing, regularity |102| `analysis.recovery` | RHR, HRV, blood oxygen, respiratory rate, VO2 max |103| `analysis.activity` | Active energy, exercise minutes, stand hours, workouts |104| `analysis.bodyComposition` | Weight, body fat % |105| `analysis.menstrualCycle` | Cycle analysis if present |106| `narrativeContext` | Health-report audience, goal, schema version, boundaries |107108### Training report109110| Key | What it contains |111|-----|-----------------|112| `training.summary` | Training state, readiness, recent load, recovery support, primary sport |113| `training.summary.trainingLoad` | MET-minute EWMA load snapshot (42-day CTL baseline, 7-day ATL recent load, TSB load balance) + relative 30-day & 90-day changes; null when < 28 days of data or < 6 load-bearing workouts |114| `training.sports[]` | Top sports (dormant ones filtered, `topSportCount` configurable via `--top-sports`, default 5) with recent/baseline/trailing/all-time windows, recovery-after-workout, consistency, tags |115| `training.charts[]` | `training_load` (CTL/ATL monthly curve), `training_recovery`, and `sport_<slug>_trend` charts |116| `training.narrativeContext` | Training-report audience, goal, schema version, boundaries |117118## Commands119120Default flow — **prepare once, render twice** so the folder contains both report sets. Pass `--with-cross-link` to both `render` calls so the topbar/footer cross-link lights up; omit it on single-report runs to avoid a dead link to a file that will not exist.121122```bash123# 1. Prepare once (shared by both reports)124# Optional: --top-sports N to cap the training-report sport list (default 5)125npx apple-health-analyst prepare /path/to/export.zip --lang en --out ./output126127# 2. Health render (fixed file name: report.html)128npx apple-health-analyst render \129 --insights ./output/insights.json \130 --narrative ./output/report.llm.json \131 --with-cross-link \132 --out ./output133134# 3. Training render (fixed file name: training.report.html)135npx apple-health-analyst render \136 --type training \137 --insights ./output/insights.json \138 --narrative ./output/training.report.llm.json \139 --with-cross-link \140 --out ./output141```142143The two HTML files auto-link to each other via the topbar and footer **only when `--with-cross-link` is set on both renders**. Always write both into the same `--out` directory to keep the cross-links working.144145**Single-report mode**: if the user is explicit about only wanting the health or the training report (see Intent Routing), run `render` once **without** `--with-cross-link` — otherwise the lone HTML will point at a companion file that never gets generated.146147## Health Narrative Framework148149Use the existing health schema in [references/report-llm-json.md](references/report-llm-json.md).150151Prioritize:1521531. `crossMetric.sleepRecoveryLink`1542. `crossMetric.sleepConsistency`1553. `crossMetric.activityRecoveryBalance`1564. `crossMetric.recoveryCoherence`1575. `crossMetric.patterns`1586. `riskFlags`, `notableChanges`, and `dataGaps`159160`crossMetric.compositeAssessment` remains in the output shape for compatibility,161but its scores are intentionally `null`: do not invent or narrate a composite162health score from heterogeneous consumer-device metrics.163164Health writing rules:165166- Every conclusion must cite concrete values or dates from `summary.json` or `insights.json`167- `key_findings` must be cross-metric, not single-metric trivia168- `actions_next_2_weeks` must specify time, frequency, or numeric targets169- `questions_for_doctor` must be data-driven and specific170- Use consumer-readable precision and do not repeat the same evidence across171 assessment, overview, findings, and chart callouts172- Leave `when_to_seek_care` and `questions_for_doctor` empty when there is no173 risk, persistent change, or symptom-contingent follow-up supported by the data174175## Training Narrative Framework176177Use the training schema in [references/training-report-llm-json.md](references/training-report-llm-json.md).178179Prioritize:1801811. `training.summary.trainingState` and `training.summary.readiness`1822. `training.summary.trainingLoad` — the scale-relative MET-minute EWMA trend; interpret together with recovery evidence1833. `training.summary.loadTrend` and `training.summary.recoverySupport` (legacy 30d-vs-90d views, use as corroboration)1844. `training.sports[]` in descending importance1855. `training.charts[]`1866. `dataGaps[]` and missing metric coverage187188Training writing rules:189190- Treat CTL as the 42-day personal load baseline, ATL as 7-day recent load, and TSB as their difference. Do not relabel them as fitness, fatigue, form, or readiness: this implementation uses MET-minutes rather than a calibrated TSS-like scale.191- Never apply absolute TSB thresholds. When `training.summary.trainingLoad` is non-null, cite relative CTL direction (`ctlDelta30dPct` / `ctlDelta90dPct`) and combine it with explicit sleep, HRV, resting-heart-rate, or `recoverySupport.adequate` evidence.192- If `trainingLoad` is null, fall back to `loadTrend` and say so explicitly (e.g. "数据覆盖不足 28 天,暂以 30 天对比为准")193- Sport sections must focus on the actual top sports in `training.sports[]`194- Only discuss heart rate or distance when the structured data includes those metrics195- Recommendations are for training management and health monitoring, not race plans or diagnosis196- For a sport with no workouts in the last 30 days, keep recommendations empty;197 do not infer that the user wants to restart it198- Do not prescribe fixed session counts for a named sport unless the user199 explicitly requested a program; otherwise change one training variable at a time200201## Required Reading Before Writing Narrative202203- `summary.json`204- `insights.json`205- [references/report-llm-json.md](references/report-llm-json.md) for health mode206- [references/training-report-llm-json.md](references/training-report-llm-json.md) for training mode207- [references/safety-boundaries.md](references/safety-boundaries.md)208- [references/analysis-framework.md](references/analysis-framework.md)209210## Constraints211212- Only reference facts from `summary.json` and `insights.json`213- Do not fabricate sport metrics, chart IDs, or medical risks214- Provide health management and training adjustment advice, not diagnoses or treatment plans215- If a module is `insufficient_data`, say so plainly216- Do not generate final HTML directly; write the narrative JSON first, then run `render`217218## Error Handling219220- ZIP format error: if `prepare` cannot find the `HealthData` XML, verify the user provided the official Apple Health export ZIP. The main XML filename is not fixed and may be localized (for example `导出.xml`) or appear as mojibake. `export_cda.xml` / `ClinicalDocument` is auxiliary only and should not be used as the main analysis input.221- Out of memory: parsing is streaming but retained supported records can still be large. `--from` and `--to` constrain analysis output after parsing and do not currently reduce peak parse memory; use a machine with more memory or pre-filter a copy of the export with a trusted local tool222- Health narrative validation failure: verify `report.llm.json` matches schema v3223- Training narrative validation failure: verify `training.report.llm.json` matches schema v2 and only references existing sport/chart IDs224- npm cache EPERM: use `npm_config_cache=./.npm-cache`225- Sandbox/policy rejection: do not chain destructive commands with `prepare` / `render`; create directories separately if needed226227## Output Files228229Always produced by `prepare`:230231- `summary.json`232- `insights.json`233234Health render (file names are fixed; do not rename):235236- `report.llm.json`237- `report.md`238- `report.html`239240Training render (file names are fixed; do not rename):241242- `training.report.llm.json`243- `training.report.md`244- `training.report.html`245246The two HTML reports cross-link via the topbar and footer using relative paths (`./report.html` ↔ `./training.report.html`). Keep both in the same `output/` directory for the links to work.