trainbud 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/.env.example +11 -11
  2. package/CHANGELOG.md +757 -675
  3. package/QUICKSTART.md +185 -182
  4. package/README.md +329 -322
  5. package/dist/appDb.d.ts +40 -1
  6. package/dist/appDb.js +120 -51
  7. package/dist/cli.js +47 -0
  8. package/dist/dashboard.js +820 -820
  9. package/dist/dashboardCharts.js +42 -42
  10. package/dist/deviceTokens.d.ts +29 -0
  11. package/dist/deviceTokens.js +49 -0
  12. package/dist/history/context.js +35 -35
  13. package/dist/history/schema.js +66 -66
  14. package/dist/httpServer.js +64 -1
  15. package/dist/pairApi.js +11 -2
  16. package/dist/promptApi.js +5 -5
  17. package/dist/usage.js +17 -17
  18. package/package.json +82 -77
  19. package/dist/appDb.d.ts.map +0 -1
  20. package/dist/appDb.js.map +0 -1
  21. package/dist/check.d.ts.map +0 -1
  22. package/dist/check.js.map +0 -1
  23. package/dist/cli.d.ts.map +0 -1
  24. package/dist/cli.js.map +0 -1
  25. package/dist/config.d.ts.map +0 -1
  26. package/dist/config.js.map +0 -1
  27. package/dist/dashboard.d.ts.map +0 -1
  28. package/dist/dashboard.js.map +0 -1
  29. package/dist/dashboardCharts.d.ts.map +0 -1
  30. package/dist/dashboardCharts.js.map +0 -1
  31. package/dist/dashboardData.d.ts.map +0 -1
  32. package/dist/dashboardData.js.map +0 -1
  33. package/dist/detect/baseline.d.ts.map +0 -1
  34. package/dist/detect/baseline.js.map +0 -1
  35. package/dist/detect/countdown.d.ts.map +0 -1
  36. package/dist/detect/countdown.js.map +0 -1
  37. package/dist/detect/detectors.d.ts.map +0 -1
  38. package/dist/detect/detectors.js.map +0 -1
  39. package/dist/detect/findings.d.ts.map +0 -1
  40. package/dist/detect/findings.js.map +0 -1
  41. package/dist/detect/forecast.d.ts.map +0 -1
  42. package/dist/detect/forecast.js.map +0 -1
  43. package/dist/detect/index.d.ts.map +0 -1
  44. package/dist/detect/index.js.map +0 -1
  45. package/dist/detect/sleepQuality.d.ts.map +0 -1
  46. package/dist/detect/sleepQuality.js.map +0 -1
  47. package/dist/detect/trimp.d.ts.map +0 -1
  48. package/dist/detect/trimp.js.map +0 -1
  49. package/dist/detect/week.d.ts.map +0 -1
  50. package/dist/detect/week.js.map +0 -1
  51. package/dist/garmin/auth.d.ts.map +0 -1
  52. package/dist/garmin/auth.js.map +0 -1
  53. package/dist/garmin/cache.d.ts.map +0 -1
  54. package/dist/garmin/cache.js.map +0 -1
  55. package/dist/garmin/client.d.ts.map +0 -1
  56. package/dist/garmin/client.js.map +0 -1
  57. package/dist/garmin/daily.d.ts.map +0 -1
  58. package/dist/garmin/daily.js.map +0 -1
  59. package/dist/garmin/garminApiTypes.d.ts.map +0 -1
  60. package/dist/garmin/garminApiTypes.js.map +0 -1
  61. package/dist/garmin/garminConnect.d.ts.map +0 -1
  62. package/dist/garmin/garminConnect.js.map +0 -1
  63. package/dist/garmin/partial.d.ts.map +0 -1
  64. package/dist/garmin/partial.js.map +0 -1
  65. package/dist/garmin/rawApi.d.ts.map +0 -1
  66. package/dist/garmin/rawApi.js.map +0 -1
  67. package/dist/garmin/types.d.ts.map +0 -1
  68. package/dist/garmin/types.js.map +0 -1
  69. package/dist/history/capture.d.ts.map +0 -1
  70. package/dist/history/capture.js.map +0 -1
  71. package/dist/history/context.d.ts.map +0 -1
  72. package/dist/history/context.js.map +0 -1
  73. package/dist/history/fallback.d.ts.map +0 -1
  74. package/dist/history/fallback.js.map +0 -1
  75. package/dist/history/ingest.d.ts.map +0 -1
  76. package/dist/history/ingest.js.map +0 -1
  77. package/dist/history/scheduler.d.ts.map +0 -1
  78. package/dist/history/scheduler.js.map +0 -1
  79. package/dist/history/schema.d.ts.map +0 -1
  80. package/dist/history/schema.js.map +0 -1
  81. package/dist/history/store.d.ts.map +0 -1
  82. package/dist/history/store.js.map +0 -1
  83. package/dist/httpServer.d.ts.map +0 -1
  84. package/dist/httpServer.js.map +0 -1
  85. package/dist/index.d.ts.map +0 -1
  86. package/dist/index.js.map +0 -1
  87. package/dist/mcpConfig.d.ts.map +0 -1
  88. package/dist/mcpConfig.js.map +0 -1
  89. package/dist/pairApi.d.ts.map +0 -1
  90. package/dist/pairApi.js.map +0 -1
  91. package/dist/paths.d.ts.map +0 -1
  92. package/dist/paths.js.map +0 -1
  93. package/dist/profile.d.ts.map +0 -1
  94. package/dist/profile.js.map +0 -1
  95. package/dist/promptApi.d.ts.map +0 -1
  96. package/dist/promptApi.js.map +0 -1
  97. package/dist/promptSuggestions.d.ts.map +0 -1
  98. package/dist/promptSuggestions.js.map +0 -1
  99. package/dist/selfTest.d.ts.map +0 -1
  100. package/dist/selfTest.js.map +0 -1
  101. package/dist/server.d.ts.map +0 -1
  102. package/dist/server.js.map +0 -1
  103. package/dist/setup.d.ts.map +0 -1
  104. package/dist/setup.js.map +0 -1
  105. package/dist/toolErrors.d.ts.map +0 -1
  106. package/dist/toolErrors.js.map +0 -1
  107. package/dist/tools/activities.d.ts.map +0 -1
  108. package/dist/tools/activities.js.map +0 -1
  109. package/dist/tools/bodyComposition.d.ts.map +0 -1
  110. package/dist/tools/bodyComposition.js.map +0 -1
  111. package/dist/tools/context.d.ts.map +0 -1
  112. package/dist/tools/context.js.map +0 -1
  113. package/dist/tools/findings.d.ts.map +0 -1
  114. package/dist/tools/findings.js.map +0 -1
  115. package/dist/tools/heartRate.d.ts.map +0 -1
  116. package/dist/tools/heartRate.js.map +0 -1
  117. package/dist/tools/index.d.ts.map +0 -1
  118. package/dist/tools/index.js.map +0 -1
  119. package/dist/tools/payloads.d.ts.map +0 -1
  120. package/dist/tools/payloads.js.map +0 -1
  121. package/dist/tools/recovery.d.ts.map +0 -1
  122. package/dist/tools/recovery.js.map +0 -1
  123. package/dist/tools/sleep.d.ts.map +0 -1
  124. package/dist/tools/sleep.js.map +0 -1
  125. package/dist/tools/stress.d.ts.map +0 -1
  126. package/dist/tools/stress.js.map +0 -1
  127. package/dist/tools/trainingInsights.d.ts.map +0 -1
  128. package/dist/tools/trainingInsights.js.map +0 -1
  129. package/dist/tools/types.d.ts.map +0 -1
  130. package/dist/tools/types.js.map +0 -1
  131. package/dist/tools/vo2Max.d.ts.map +0 -1
  132. package/dist/tools/vo2Max.js.map +0 -1
  133. package/dist/tools/week.d.ts.map +0 -1
  134. package/dist/tools/week.js.map +0 -1
  135. package/dist/usage.d.ts.map +0 -1
  136. package/dist/usage.js.map +0 -1
  137. package/dist/utils/batch.d.ts.map +0 -1
  138. package/dist/utils/batch.js.map +0 -1
  139. package/dist/utils/helpers.d.ts.map +0 -1
  140. package/dist/utils/helpers.js.map +0 -1
  141. package/dist/utils/jsonFile.d.ts.map +0 -1
  142. package/dist/utils/jsonFile.js.map +0 -1
  143. package/dist/utils/logger.d.ts.map +0 -1
  144. package/dist/utils/logger.js.map +0 -1
  145. package/dist/utils/secretFile.d.ts.map +0 -1
  146. package/dist/utils/secretFile.js.map +0 -1
  147. package/dist/utils/stdio.d.ts.map +0 -1
  148. package/dist/utils/stdio.js.map +0 -1
  149. package/dist/version.d.ts.map +0 -1
  150. package/dist/version.js.map +0 -1
  151. package/dist/watchApi.d.ts.map +0 -1
  152. package/dist/watchApi.js.map +0 -1
package/README.md CHANGED
@@ -1,322 +1,329 @@
1
- # TrainBud
2
-
3
- **Talk to your training data.**
4
-
5
- TrainBud is an open-source MCP server that connects your Garmin Connect fitness data to Claude, Cursor, and other AI assistants. Ask about workouts, sleep, heart rate, recovery, and body composition in plain English — privately, on your machine.
6
-
7
- > **Disclaimer:** TrainBud is an unofficial community project. It is not affiliated with, endorsed by, or sponsored by Garmin Ltd. Garmin Connect is a trademark of Garmin Ltd.
8
-
9
- [![CI](https://github.com/Zsadigzade/trainbud/actions/workflows/ci.yml/badge.svg)](https://github.com/Zsadigzade/trainbud/actions/workflows/ci.yml)
10
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
11
- [![Node 20+](https://img.shields.io/badge/node-%3E%3D20-brightgreen)](.nvmrc)
12
-
13
- ## Try it
14
-
15
- Once connected to your MCP client, ask things like:
16
-
17
- - *"What did I do today?"*
18
- - *"How's my sleep been this week?"*
19
- - *"Am I recovered enough to train hard tomorrow?"*
20
- - *"Is my resting heart rate trending down?"*
21
-
22
- See [examples/prompts.md](./examples/prompts.md) for more ideas.
23
-
24
- ## Why TrainBud
25
-
26
- - **Private** — credentials stay in your local `.env`; data is cached on your machine
27
- - **Local-first** — SQLite cache, session tokens in `.trainbud/`
28
- - **Works everywhere** — Windows, macOS, Linux (Node.js 20+)
29
- - **Any MCP client** — Claude Desktop, Cursor, and other stdio-compatible clients
30
- - **Smart fetching** — batched API calls and automatic re-auth when sessions expire
31
-
32
- ## Quick start
33
-
34
- ```bash
35
- npx trainbud setup
36
- ```
37
-
38
- The setup wizard walks you through credentials, authentication, and connecting Cursor or
39
- Claude Desktop no MCP config editing required. Then restart your MCP client and ask it
40
- what you did today.
41
-
42
- To keep `trainbud` on your PATH instead of typing `npx` every time:
43
-
44
- ```bash
45
- npm install -g trainbud
46
- trainbud setup
47
- ```
48
-
49
- Needs Node 20+. Full walkthrough: [QUICKSTART.md](./QUICKSTART.md)
50
-
51
- <details>
52
- <summary><b>From source</b> (for contributors, or to run an unreleased commit)</summary>
53
-
54
- ```bash
55
- git clone https://github.com/Zsadigzade/trainbud.git
56
- cd trainbud
57
- npm install
58
- npm run build
59
- npm link # puts `trainbud` on your PATH; undo with `npm unlink -g trainbud`
60
- trainbud setup
61
- ```
62
-
63
- Without `npm link`, every `trainbud <command>` in this README is
64
- `node dist/index.js <command>` run from the repo root. If `dist/` does not exist yet,
65
- run `npm run build` first.
66
- </details>
67
-
68
- ## Claude Code plugin (recommended)
69
-
70
- Install as a [Claude Code plugin](https://code.claude.com/docs/en/plugins) — skills **and** MCP server in one step:
71
-
72
- ```bash
73
- /plugin marketplace add Zsadigzade/trainbud
74
- /plugin install trainbud@trainbud
75
- ```
76
-
77
- Set credentials, then restart Claude Code:
78
-
79
- ```bash
80
- export GARMIN_EMAIL="your@email.com"
81
- export GARMIN_PASSWORD="yourpassword"
82
- ```
83
-
84
- | Command | What it does |
85
- |---------|----------------|
86
- | `/trainbud:trainbud-setup` | First-time setup and diagnostics |
87
- | `/trainbud:trainbud` | Ask about workouts, sleep, recovery, HR, stress, VO2 max |
88
-
89
- Plugin files live in [`plugin/`](./plugin/). See [`plugin/README.md`](./plugin/README.md).
90
-
91
- ## Claude Code skills (in-repo)
92
-
93
- This repo also ships project skills in [`.claude/skills/`](./.claude/skills/) for development without installing the plugin:
94
-
95
- | Command | What it does |
96
- |---------|----------------|
97
- | `/trainbud-setup` | Install, authenticate, configure MCP, run live check |
98
- | `/trainbud` | Ask about workouts, sleep, recovery, HR, stress, VO2 max |
99
-
100
- Open the repo in **Claude Code** (`claude` in this directory) — skills load automatically.
101
-
102
- To use skills in **every** project without the plugin, copy them to `~/.claude/skills/`.
103
-
104
- After setup, restart your MCP client and try `/trainbud` with *"What did I do today?"*
105
-
106
- ## Dashboard
107
-
108
- `trainbud serve` hosts a dashboard at `/dashboard`. It is phone-first, because the
109
- pairing flow is: you are standing next to the watch holding a phone when you approve a
110
- code.
111
-
112
- It shows what stands out today against your own baselines, this week against last week,
113
- and resting heart rate and sleep plotted against your own 30-day median all read from
114
- the local history store, so it paints instantly and works even when your Connect session
115
- has expired. **A break in a line is a day with no measurement, not a zero.**
116
-
117
- It is also where you tell TrainBud who it is talking to:
118
-
119
- | Setting | What it changes |
120
- |---|---|
121
- | Name, units, primary sport, weekly goal | Every renderer, and what the AI is told about you |
122
- | Thresholds | Where green becomes amber and amber becomes red on the watch too |
123
- | Watch cards | Which cards appear on the wrist and in what order, live on the next sync |
124
- | AI model, tone, answer length | How the Ask card and the daily insight sound |
125
- | Your own Ask questions | Up to five, 32 characters each. They lead the watch's Ask menu; the rest of the slots stay generated from what fired |
126
- | Monthly spending cap | Optional. Refuses an Ask past the cap instead of spending past it |
127
- | Privacy | Local feature counters, on by default, with a delete button |
128
-
129
- **Usage.** TrainBud runs on your own AI provider key, so every question and every daily
130
- insight is charged to you. The dashboard shows the tokens and cost per call, the month to
131
- date, and a 30-day chart. A model this build has no published price for is recorded with
132
- its cost left *unknown* rather than as zero a call priced at zero would make a cap that
133
- can never trip.
134
-
135
- Nothing on this page leaves your machine. There is no endpoint to send it to.
136
-
137
- ## Garmin watch widget (Connect IQ)
138
-
139
- View recovery, sleep, activity, stress, and VO2 max on your Garmin watch via a Connect IQ widget in [`ciq/`](./ciq/).
140
-
141
- **Requires:** `trainbud serve` running + HTTPS tunnel (same setup as web AI).
142
-
143
- 1. Start the server and tunnel:
144
- ```bash
145
- trainbud serve
146
- cloudflared tunnel --url http://127.0.0.1:3847
147
- ```
148
- 2. Build and sideload the widget — see [ciq/README.md](./ciq/README.md)
149
- 3. In **Garmin Connect Mobile** Connect IQ → TrainBud settings, set:
150
- - **Server URL** your tunnel URL (e.g. `https://abc.trycloudflare.com`)
151
- 4. Open the widget on your watch it shows a pairing code. Approve it in the dashboard (`/dashboard?token=YOUR_API_KEY`) to complete setup. The dashboard swaps that token for a session cookie and drops it from the URL, so the address bar is safe to screenshot afterwards.
152
-
153
- The glance shows recovery and sleep from the last cached summary, so it renders without
154
- waiting on the network. Open it and tap or swipe to cycle through the cards you left switched on in the dashboard. The watch
155
- calls `GET /api/watch` a compact JSON summary, not the full MCP protocol.
156
-
157
- ## Connect to Claude Desktop
158
-
159
- Edit `claude_desktop_config.json`:
160
-
161
- **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
162
- **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
163
-
164
- ```json
165
- {
166
- "mcpServers": {
167
- "trainbud": {
168
- "command": "node",
169
- "args": ["C:/path/to/trainbud/dist/index.js", "start"],
170
- "env": {
171
- "GARMIN_EMAIL": "your@email.com",
172
- "GARMIN_PASSWORD": "yourpassword"
173
- }
174
- }
175
- }
176
- }
177
- ```
178
-
179
- With `trainbud` on your PATH (`npm install -g trainbud`, or `npm link` from a clone),
180
- point the client at the command instead of a path:
181
-
182
- ```json
183
- {
184
- "mcpServers": {
185
- "trainbud": {
186
- "command": "trainbud",
187
- "args": ["start"]
188
- }
189
- }
190
- }
191
- ```
192
-
193
- Restart your MCP client, then start asking questions.
194
-
195
- ## Tools
196
-
197
- | Tool | What it answers |
198
- |------|-----------------|
199
- | `get_latest_activity` | Your most recent workout — distance, pace, HR, elevation |
200
- | `get_activities_range` | Activities between two dates |
201
- | `get_sleep_data` | Sleep duration, stages, score, awakenings |
202
- | `get_heart_rate_trends` | Resting, max, and average HR over time |
203
- | `get_recovery_status` | Recovery score from HRV, sleep, stress, resting HR |
204
- | `get_body_composition` | Weight, body fat, and muscle mass trends |
205
- | `get_stress_levels` | Daily stress averages and trends |
206
- | `get_vo2_max_trends` | VO2 max fitness trends over time |
207
- | `get_training_insights` | Combined weekly summary (activities, sleep, recovery, stress) |
208
- | `get_findings` | What stands out against **your own** 28-day baselines, not a population average |
209
- | `get_week_review` | This week against last, the load forecast, sleep debt, and your next race |
210
- | `remember_context` | Record a goal, a race and its date, an injury, or a note |
211
- | `get_user_context` | What is on record about you, on any date |
212
- | `log_subjective` | How a session actually felt — RPE, soreness, mood |
213
-
214
- ## CLI
215
-
216
- ```bash
217
- trainbud setup # Interactive first-time setup (recommended)
218
- trainbud serve # Remote HTTP MCP for web AI (claude.ai, ChatGPT)
219
- trainbud check # Live diagnostics against all tools
220
- trainbud doctor # What the watch would see: public URL, AI key, history depth
221
- trainbud backfill # Pull Garmin history into the local store (resumable)
222
- trainbud findings # What stands out against your own baselines
223
- trainbud start # Start the MCP server (stdio)
224
- trainbud auth # Force re-authentication
225
- trainbud cache clear # Clear cached data
226
- trainbud status # Show session and cache status
227
- trainbud --version # Print version
228
- ```
229
-
230
- Every one of these also works as `npx trainbud <command>` without installing anything.
231
-
232
- ### Troubleshooting: `trainbud: command not found`
233
-
234
- Either use `npx trainbud <command>`, or install it globally with
235
- `npm install -g trainbud`. Running from a clone instead? Run `npm link` once from the
236
- repo root, or call the built entry point directly with `node dist/index.js doctor`
237
- (after `npm run build`).
238
-
239
- ## Configuration
240
-
241
- | Variable | Default | Description |
242
- |----------|---------|-------------|
243
- | `GARMIN_EMAIL` | — | Garmin Connect email |
244
- | `GARMIN_PASSWORD` | | Garmin Connect password |
245
- | `TRAINBUD_SESSION_PATH` | `.trainbud/session.json` | Session token storage |
246
- | `TRAINBUD_LOG_PATH` | `.trainbud/mcp.log` | Log file path |
247
- | `TRAINBUD_CACHE_PATH` | `.trainbud/cache.db` | SQLite cache database |
248
- | `CACHE_TTL_ACTIVITIES` | `1800` | Activity cache TTL (seconds) |
249
- | `CACHE_TTL_SLEEP` | `7200` | Sleep cache TTL (seconds) |
250
- | `CACHE_TTL_STATS` | `3600` | Stats cache TTL (seconds) |
251
- | `TRAINBUD_API_KEY` | auto-generated | Bearer token for HTTP MCP (`trainbud serve`) |
252
- | `TRAINBUD_HOST` | `127.0.0.1` | Bind host for HTTP server |
253
- | `TRAINBUD_PORT` | `3847` | Bind port for HTTP server |
254
-
255
- ## Security & privacy
256
-
257
- - Credentials live only in your local `.env` file — never sent to a third party
258
- - Session tokens in `.trainbud/session.json` are as sensitive as a password
259
- - Tool errors are sanitized before reaching the AI client
260
- - Uses the unofficial [`garmin-connect`](https://www.npmjs.com/package/garmin-connect) npm package (not Garmin's enterprise OAuth API)
261
- - **MFA is not supported** by the underlying library disable MFA or use an app-specific password
262
- - The server binds `127.0.0.1` by default. It is only reachable from the internet if
263
- you point a tunnel at it, and every route except `/health` needs the API key
264
- - The dashboard takes the key once, on `/dashboard?token=…`, then trades it for an
265
- `HttpOnly` session cookie and redirects to a clean URL so the key does not sit in
266
- your address bar, your history, or a screenshot
267
- - **A paired watch holds the API key itself**, not a scoped per-device token. Pairing
268
- approval hands over the same key that opens the dashboard and `/mcp`. Revoke a watch
269
- by changing `TRAINBUD_API_KEY` and pairing again. A narrower per-device token is
270
- planned; until then, treat pairing as handing out a password
271
-
272
- ### What TrainBud is not
273
-
274
- - **Not a hosted service.** There is no TrainBud account and no TrainBud server. You run
275
- it, on your machine, against your own Garmin credentials
276
- - **Not an official Garmin integration.** It drives an unofficial library against the
277
- Connect web API. Garmin can change that API without notice, and does
278
- - **Not MFA-compatible.** If your Connect account has MFA on, this will not log in
279
- - **Not free to ask.** The AI features run on your own Anthropic key and are billed to
280
- you. The dashboard meters every call and can refuse past a cap you set
281
-
282
- ## Troubleshooting
283
-
284
- | Issue | Fix |
285
- |-------|-----|
286
- | Authentication failed | Verify `.env` credentials, run `trainbud auth` |
287
- | MFA enabled on account | Disable MFA or use an app-specific password |
288
- | Stale data | Run `trainbud cache clear` |
289
- | Rate limited | Wait 60 seconds; cached responses are used when available |
290
- | Watch shows "Not a TrainBud server" or error -400 | Your public URL is answering with something that is not TrainBud's JSON — usually a tunnel that is down. Run `trainbud doctor`; it says exactly what came back |
291
- | Watch shows "Watch not authorised" | The API key changed since the watch paired. Pair it again from the dashboard |
292
- | Watch shows "AI not set up" | AI is bring-your-own-key. Paste an Anthropic key into the dashboard |
293
- | No sleep/HR data | Ensure your Garmin device has synced to Garmin Connect |
294
- | Server won't start | Check that `GARMIN_EMAIL` and `GARMIN_PASSWORD` are set in `.env` |
295
-
296
- ## Development
297
-
298
- ```bash
299
- npm install
300
- npm run build
301
- npm test # 551 tests via the Node test runner
302
- npm run lint
303
- npm run dev # Start with auto-reload
304
- ```
305
-
306
- Use `.nvmrc` with nvm/fnm for Node 20. If your project path contains `#`, use `npm test` instead of `npm run test:vitest`.
307
-
308
- See [CONTRIBUTING.md](./CONTRIBUTING.md) and [docs/VAULT.md](./docs/VAULT.md) for architecture and design notes (Obsidian vault, outside this repo).
309
-
310
- ## Roadmap
311
-
312
- - [x] VO2 max trends
313
- - [x] Stress levels
314
- - [x] Training insights
315
- - [ ] Workout comparison
316
- - [ ] Docker image
317
-
318
- ## License
319
-
320
- MIT see [LICENSE](./LICENSE).
321
-
322
- Garmin Connect is a trademark of Garmin Ltd. This project is not affiliated with Garmin Ltd.
1
+ # TrainBud
2
+
3
+ **Talk to your training data.**
4
+
5
+ TrainBud is an open-source MCP server that connects your Garmin Connect fitness data to Claude, Cursor, and other AI assistants. Ask about workouts, sleep, heart rate, recovery, and body composition in plain English — privately, on your machine.
6
+
7
+ > **Disclaimer:** TrainBud is an unofficial community project. It is not affiliated with, endorsed by, or sponsored by Garmin Ltd. Garmin Connect is a trademark of Garmin Ltd.
8
+
9
+ [![npm](https://img.shields.io/npm/v/trainbud)](https://www.npmjs.com/package/trainbud)
10
+ [![CI](https://github.com/Zsadigzade/trainbud/actions/workflows/ci.yml/badge.svg)](https://github.com/Zsadigzade/trainbud/actions/workflows/ci.yml)
11
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
12
+ [![Node 20+](https://img.shields.io/badge/node-%3E%3D20-brightgreen)](.nvmrc)
13
+
14
+ ## Try it
15
+
16
+ Once connected to your MCP client, ask things like:
17
+
18
+ - *"What did I do today?"*
19
+ - *"How's my sleep been this week?"*
20
+ - *"Am I recovered enough to train hard tomorrow?"*
21
+ - *"Is my resting heart rate trending down?"*
22
+
23
+ See [examples/prompts.md](./examples/prompts.md) for more ideas.
24
+
25
+ ## Why TrainBud
26
+
27
+ - **Private** — credentials stay in your local `.env`; data is cached on your machine
28
+ - **Local-first** — SQLite cache, session tokens in `.trainbud/`
29
+ - **Works everywhere** — Windows, macOS, Linux (Node.js 20+)
30
+ - **Any MCP client** — Claude Desktop, Cursor, and other stdio-compatible clients
31
+ - **Smart fetching** — batched API calls and automatic re-auth when sessions expire
32
+
33
+ ## Quick start
34
+
35
+ ```bash
36
+ npx trainbud setup
37
+ ```
38
+
39
+ The setup wizard walks you through credentials, authentication, and connecting Cursor or
40
+ Claude Desktop no MCP config editing required. Then restart your MCP client and ask it
41
+ what you did today.
42
+
43
+ To keep `trainbud` on your PATH instead of typing `npx` every time:
44
+
45
+ ```bash
46
+ npm install -g trainbud
47
+ trainbud setup
48
+ ```
49
+
50
+ Needs Node 20+. Full walkthrough: [QUICKSTART.md](./QUICKSTART.md)
51
+
52
+ <details>
53
+ <summary><b>From source</b> (for contributors, or to run an unreleased commit)</summary>
54
+
55
+ ```bash
56
+ git clone https://github.com/Zsadigzade/trainbud.git
57
+ cd trainbud
58
+ npm install
59
+ npm run build
60
+ npm link # puts `trainbud` on your PATH; undo with `npm unlink -g trainbud`
61
+ trainbud setup
62
+ ```
63
+
64
+ Without `npm link`, every `trainbud <command>` in this README is
65
+ `node dist/index.js <command>` run from the repo root. If `dist/` does not exist yet,
66
+ run `npm run build` first.
67
+ </details>
68
+
69
+ ## Claude Code plugin (recommended)
70
+
71
+ Install as a [Claude Code plugin](https://code.claude.com/docs/en/plugins) — skills **and** MCP server in one step:
72
+
73
+ ```bash
74
+ /plugin marketplace add Zsadigzade/trainbud
75
+ /plugin install trainbud@trainbud
76
+ ```
77
+
78
+ Set credentials, then restart Claude Code:
79
+
80
+ ```bash
81
+ export GARMIN_EMAIL="your@email.com"
82
+ export GARMIN_PASSWORD="yourpassword"
83
+ ```
84
+
85
+ | Command | What it does |
86
+ |---------|----------------|
87
+ | `/trainbud:trainbud-setup` | First-time setup and diagnostics |
88
+ | `/trainbud:trainbud` | Ask about workouts, sleep, recovery, HR, stress, VO2 max |
89
+
90
+ Plugin files live in [`plugin/`](./plugin/). See [`plugin/README.md`](./plugin/README.md).
91
+
92
+ ## Claude Code skills (in-repo)
93
+
94
+ This repo also ships project skills in [`.claude/skills/`](./.claude/skills/) for development without installing the plugin:
95
+
96
+ | Command | What it does |
97
+ |---------|----------------|
98
+ | `/trainbud-setup` | Install, authenticate, configure MCP, run live check |
99
+ | `/trainbud` | Ask about workouts, sleep, recovery, HR, stress, VO2 max |
100
+
101
+ Open the repo in **Claude Code** (`claude` in this directory) — skills load automatically.
102
+
103
+ To use skills in **every** project without the plugin, copy them to `~/.claude/skills/`.
104
+
105
+ After setup, restart your MCP client and try `/trainbud` with *"What did I do today?"*
106
+
107
+ ## Dashboard
108
+
109
+ `trainbud serve` hosts a dashboard at `/dashboard`. It is phone-first, because the
110
+ pairing flow is: you are standing next to the watch holding a phone when you approve a
111
+ code.
112
+
113
+ It shows what stands out today against your own baselines, this week against last week,
114
+ and resting heart rate and sleep plotted against your own 30-day median all read from
115
+ the local history store, so it paints instantly and works even when your Connect session
116
+ has expired. **A break in a line is a day with no measurement, not a zero.**
117
+
118
+ It is also where you tell TrainBud who it is talking to:
119
+
120
+ | Setting | What it changes |
121
+ |---|---|
122
+ | Name, units, primary sport, weekly goal | Every renderer, and what the AI is told about you |
123
+ | Thresholds | Where green becomes amber and amber becomes red on the watch too |
124
+ | Watch cards | Which cards appear on the wrist and in what order, live on the next sync |
125
+ | AI model, tone, answer length | How the Ask card and the daily insight sound |
126
+ | Your own Ask questions | Up to five, 32 characters each. They lead the watch's Ask menu; the rest of the slots stay generated from what fired |
127
+ | Monthly spending cap | Optional. Refuses an Ask past the cap instead of spending past it |
128
+ | Privacy | Local feature counters, on by default, with a delete button |
129
+
130
+ **Usage.** TrainBud runs on your own AI provider key, so every question and every daily
131
+ insight is charged to you. The dashboard shows the tokens and cost per call, the month to
132
+ date, and a 30-day chart. A model this build has no published price for is recorded with
133
+ its cost left *unknown* rather than as zero — a call priced at zero would make a cap that
134
+ can never trip.
135
+
136
+ Nothing on this page leaves your machine. There is no endpoint to send it to.
137
+
138
+ ## Garmin watch widget (Connect IQ)
139
+
140
+ View recovery, sleep, activity, stress, and VO2 max on your Garmin watch via a Connect IQ widget in [`ciq/`](./ciq/).
141
+
142
+ **Requires:** `trainbud serve` running + HTTPS tunnel (same setup as web AI).
143
+
144
+ 1. Start the server and tunnel:
145
+ ```bash
146
+ trainbud serve
147
+ cloudflared tunnel --url http://127.0.0.1:3847
148
+ ```
149
+ 2. Build and sideload the widget see [ciq/README.md](./ciq/README.md)
150
+ 3. In **Garmin Connect Mobile** Connect IQ TrainBud settings, set:
151
+ - **Server URL** your tunnel URL (e.g. `https://abc.trycloudflare.com`)
152
+ 4. Open the widget on your watch — it shows a pairing code. Approve it in the dashboard (`/dashboard?token=YOUR_API_KEY`) to complete setup. The dashboard swaps that token for a session cookie and drops it from the URL, so the address bar is safe to screenshot afterwards.
153
+
154
+ The glance shows recovery and sleep from the last cached summary, so it renders without
155
+ waiting on the network. Open it and tap or swipe to cycle through the cards you left switched on in the dashboard. The watch
156
+ calls `GET /api/watch` — a compact JSON summary, not the full MCP protocol.
157
+
158
+ ## Connect to Claude Desktop
159
+
160
+ Edit `claude_desktop_config.json`:
161
+
162
+ **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
163
+ **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
164
+
165
+ ```json
166
+ {
167
+ "mcpServers": {
168
+ "trainbud": {
169
+ "command": "node",
170
+ "args": ["C:/path/to/trainbud/dist/index.js", "start"],
171
+ "env": {
172
+ "GARMIN_EMAIL": "your@email.com",
173
+ "GARMIN_PASSWORD": "yourpassword"
174
+ }
175
+ }
176
+ }
177
+ }
178
+ ```
179
+
180
+ With `trainbud` on your PATH (`npm install -g trainbud`, or `npm link` from a clone),
181
+ point the client at the command instead of a path:
182
+
183
+ ```json
184
+ {
185
+ "mcpServers": {
186
+ "trainbud": {
187
+ "command": "trainbud",
188
+ "args": ["start"]
189
+ }
190
+ }
191
+ }
192
+ ```
193
+
194
+ Restart your MCP client, then start asking questions.
195
+
196
+ ## Tools
197
+
198
+ | Tool | What it answers |
199
+ |------|-----------------|
200
+ | `get_latest_activity` | Your most recent workout — distance, pace, HR, elevation |
201
+ | `get_activities_range` | Activities between two dates |
202
+ | `get_sleep_data` | Sleep duration, stages, score, awakenings |
203
+ | `get_heart_rate_trends` | Resting, max, and average HR over time |
204
+ | `get_recovery_status` | Recovery score from HRV, sleep, stress, resting HR |
205
+ | `get_body_composition` | Weight, body fat, and muscle mass trends |
206
+ | `get_stress_levels` | Daily stress averages and trends |
207
+ | `get_vo2_max_trends` | VO2 max fitness trends over time |
208
+ | `get_training_insights` | Combined weekly summary (activities, sleep, recovery, stress) |
209
+ | `get_findings` | What stands out against **your own** 28-day baselines, not a population average |
210
+ | `get_week_review` | This week against last, the load forecast, sleep debt, and your next race |
211
+ | `remember_context` | Record a goal, a race and its date, an injury, or a note |
212
+ | `get_user_context` | What is on record about you, on any date |
213
+ | `log_subjective` | How a session actually felt — RPE, soreness, mood |
214
+
215
+ ## CLI
216
+
217
+ ```bash
218
+ trainbud setup # Interactive first-time setup (recommended)
219
+ trainbud serve # Remote HTTP MCP for web AI (claude.ai, ChatGPT)
220
+ trainbud check # Live diagnostics against all tools
221
+ trainbud doctor # What the watch would see: public URL, AI key, history depth
222
+ trainbud backfill # Pull Garmin history into the local store (resumable)
223
+ trainbud findings # What stands out against your own baselines
224
+ trainbud start # Start the MCP server (stdio)
225
+ trainbud auth # Force re-authentication
226
+ trainbud cache clear # Clear cached data
227
+ trainbud devices # List paired watches
228
+ trainbud devices revoke <id> # Take one watch's access away
229
+ trainbud status # Show session and cache status
230
+ trainbud --version # Print version
231
+ ```
232
+
233
+ Every one of these also works as `npx trainbud <command>` without installing anything.
234
+
235
+ ### Troubleshooting: `trainbud: command not found`
236
+
237
+ Either use `npx trainbud <command>`, or install it globally with
238
+ `npm install -g trainbud`. Running from a clone instead? Run `npm link` once from the
239
+ repo root, or call the built entry point directly with `node dist/index.js doctor`
240
+ (after `npm run build`).
241
+
242
+ ## Configuration
243
+
244
+ | Variable | Default | Description |
245
+ |----------|---------|-------------|
246
+ | `GARMIN_EMAIL` | | Garmin Connect email |
247
+ | `GARMIN_PASSWORD` | | Garmin Connect password |
248
+ | `TRAINBUD_SESSION_PATH` | `.trainbud/session.json` | Session token storage |
249
+ | `TRAINBUD_LOG_PATH` | `.trainbud/mcp.log` | Log file path |
250
+ | `TRAINBUD_CACHE_PATH` | `.trainbud/cache.db` | SQLite cache database |
251
+ | `CACHE_TTL_ACTIVITIES` | `1800` | Activity cache TTL (seconds) |
252
+ | `CACHE_TTL_SLEEP` | `7200` | Sleep cache TTL (seconds) |
253
+ | `CACHE_TTL_STATS` | `3600` | Stats cache TTL (seconds) |
254
+ | `TRAINBUD_API_KEY` | auto-generated | Bearer token for HTTP MCP (`trainbud serve`) |
255
+ | `TRAINBUD_HOST` | `127.0.0.1` | Bind host for HTTP server |
256
+ | `TRAINBUD_PORT` | `3847` | Bind port for HTTP server |
257
+
258
+ ## Security & privacy
259
+
260
+ - Credentials live only in your local `.env` file never sent to a third party
261
+ - Session tokens in `.trainbud/session.json` are as sensitive as a password
262
+ - Tool errors are sanitized before reaching the AI client
263
+ - Uses the unofficial [`garmin-connect`](https://www.npmjs.com/package/garmin-connect) npm package (not Garmin's enterprise OAuth API)
264
+ - **MFA is not supported** by the underlying library disable MFA or use an app-specific password
265
+ - The server binds `127.0.0.1` by default. It is only reachable from the internet if
266
+ you point a tunnel at it, and every route except `/health` needs the API key
267
+ - The dashboard takes the key once, on `/dashboard?token=…`, then trades it for an
268
+ `HttpOnly` session cookie and redirects to a clean URL — so the key does not sit in
269
+ your address bar, your history, or a screenshot
270
+ - **A paired watch holds a token scoped to that watch**, minted at pairing and stored
271
+ on the server as a SHA-256 hash. `trainbud devices` lists them, `trainbud devices
272
+ revoke <id>` takes one away — without logging out the dashboard, `/mcp`, or your
273
+ other watches. A watch paired before 0.5.2 holds the API key itself; re-pair it to
274
+ swap that for a scoped token
275
+ - Every response carries `Content-Security-Policy`, `X-Content-Type-Options`,
276
+ `X-Frame-Options` and `Referrer-Policy`, including the 401s. HSTS is sent only on a
277
+ request that actually arrived over TLS, so the loopback dashboard stays reachable
278
+
279
+ ### What TrainBud is not
280
+
281
+ - **Not a hosted service.** There is no TrainBud account and no TrainBud server. You run
282
+ it, on your machine, against your own Garmin credentials
283
+ - **Not an official Garmin integration.** It drives an unofficial library against the
284
+ Connect web API. Garmin can change that API without notice, and does
285
+ - **Not MFA-compatible.** If your Connect account has MFA on, this will not log in
286
+ - **Not free to ask.** The AI features run on your own Anthropic key and are billed to
287
+ you. The dashboard meters every call and can refuse past a cap you set
288
+
289
+ ## Troubleshooting
290
+
291
+ | Issue | Fix |
292
+ |-------|-----|
293
+ | Authentication failed | Verify `.env` credentials, run `trainbud auth` |
294
+ | MFA enabled on account | Disable MFA or use an app-specific password |
295
+ | Stale data | Run `trainbud cache clear` |
296
+ | Rate limited | Wait 60 seconds; cached responses are used when available |
297
+ | Watch shows "Not a TrainBud server" or error -400 | Your public URL is answering with something that is not TrainBud's JSON — usually a tunnel that is down. Run `trainbud doctor`; it says exactly what came back |
298
+ | Watch shows "Watch not authorised" | The API key changed since the watch paired. Pair it again from the dashboard |
299
+ | Watch shows "AI not set up" | AI is bring-your-own-key. Paste an Anthropic key into the dashboard |
300
+ | No sleep/HR data | Ensure your Garmin device has synced to Garmin Connect |
301
+ | Server won't start | Check that `GARMIN_EMAIL` and `GARMIN_PASSWORD` are set in `.env` |
302
+
303
+ ## Development
304
+
305
+ ```bash
306
+ npm install
307
+ npm run build
308
+ npm test # 551 tests via the Node test runner
309
+ npm run lint
310
+ npm run dev # Start with auto-reload
311
+ ```
312
+
313
+ Use `.nvmrc` with nvm/fnm for Node 20. If your project path contains `#`, use `npm test` instead of `npm run test:vitest`.
314
+
315
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) and [docs/VAULT.md](./docs/VAULT.md) for architecture and design notes (Obsidian vault, outside this repo).
316
+
317
+ ## Roadmap
318
+
319
+ - [x] VO2 max trends
320
+ - [x] Stress levels
321
+ - [x] Training insights
322
+ - [ ] Workout comparison
323
+ - [ ] Docker image
324
+
325
+ ## License
326
+
327
+ MIT — see [LICENSE](./LICENSE).
328
+
329
+ Garmin Connect is a trademark of Garmin Ltd. This project is not affiliated with Garmin Ltd.