hae-vault 0.1.0

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 (160) hide show
  1. package/.env.example +7 -0
  2. package/CLAUDE.md +220 -0
  3. package/README.md +206 -0
  4. package/SKILL.md +60 -0
  5. package/dist/cli/dashboard.d.ts +3 -0
  6. package/dist/cli/dashboard.d.ts.map +1 -0
  7. package/dist/cli/dashboard.js +206 -0
  8. package/dist/cli/dashboard.js.map +1 -0
  9. package/dist/cli/import.d.ts +3 -0
  10. package/dist/cli/import.d.ts.map +1 -0
  11. package/dist/cli/import.js +78 -0
  12. package/dist/cli/import.js.map +1 -0
  13. package/dist/cli/index.d.ts +3 -0
  14. package/dist/cli/index.d.ts.map +1 -0
  15. package/dist/cli/index.js +31 -0
  16. package/dist/cli/index.js.map +1 -0
  17. package/dist/cli/info.d.ts +5 -0
  18. package/dist/cli/info.d.ts.map +1 -0
  19. package/dist/cli/info.js +34 -0
  20. package/dist/cli/info.js.map +1 -0
  21. package/dist/cli/metrics.d.ts +3 -0
  22. package/dist/cli/metrics.d.ts.map +1 -0
  23. package/dist/cli/metrics.js +20 -0
  24. package/dist/cli/metrics.js.map +1 -0
  25. package/dist/cli/query.d.ts +3 -0
  26. package/dist/cli/query.d.ts.map +1 -0
  27. package/dist/cli/query.js +18 -0
  28. package/dist/cli/query.js.map +1 -0
  29. package/dist/cli/serve.d.ts +3 -0
  30. package/dist/cli/serve.d.ts.map +1 -0
  31. package/dist/cli/serve.js +19 -0
  32. package/dist/cli/serve.js.map +1 -0
  33. package/dist/cli/sleep.d.ts +3 -0
  34. package/dist/cli/sleep.d.ts.map +1 -0
  35. package/dist/cli/sleep.js +19 -0
  36. package/dist/cli/sleep.js.map +1 -0
  37. package/dist/cli/summary.d.ts +3 -0
  38. package/dist/cli/summary.d.ts.map +1 -0
  39. package/dist/cli/summary.js +53 -0
  40. package/dist/cli/summary.js.map +1 -0
  41. package/dist/cli/trends.d.ts +3 -0
  42. package/dist/cli/trends.d.ts.map +1 -0
  43. package/dist/cli/trends.js +77 -0
  44. package/dist/cli/trends.js.map +1 -0
  45. package/dist/cli/watch.d.ts +12 -0
  46. package/dist/cli/watch.d.ts.map +1 -0
  47. package/dist/cli/watch.js +89 -0
  48. package/dist/cli/watch.js.map +1 -0
  49. package/dist/cli/workouts.d.ts +3 -0
  50. package/dist/cli/workouts.d.ts.map +1 -0
  51. package/dist/cli/workouts.js +19 -0
  52. package/dist/cli/workouts.js.map +1 -0
  53. package/dist/config.d.ts +9 -0
  54. package/dist/config.d.ts.map +1 -0
  55. package/dist/config.js +25 -0
  56. package/dist/config.js.map +1 -0
  57. package/dist/db/importLog.d.ts +5 -0
  58. package/dist/db/importLog.d.ts.map +1 -0
  59. package/dist/db/importLog.js +10 -0
  60. package/dist/db/importLog.js.map +1 -0
  61. package/dist/db/metrics.d.ts +4 -0
  62. package/dist/db/metrics.d.ts.map +1 -0
  63. package/dist/db/metrics.js +14 -0
  64. package/dist/db/metrics.js.map +1 -0
  65. package/dist/db/schema.d.ts +5 -0
  66. package/dist/db/schema.d.ts.map +1 -0
  67. package/dist/db/schema.js +100 -0
  68. package/dist/db/schema.js.map +1 -0
  69. package/dist/db/sleep.d.ts +4 -0
  70. package/dist/db/sleep.d.ts.map +1 -0
  71. package/dist/db/sleep.js +13 -0
  72. package/dist/db/sleep.js.map +1 -0
  73. package/dist/db/workouts.d.ts +4 -0
  74. package/dist/db/workouts.d.ts.map +1 -0
  75. package/dist/db/workouts.js +11 -0
  76. package/dist/db/workouts.js.map +1 -0
  77. package/dist/index.d.ts +3 -0
  78. package/dist/index.d.ts.map +1 -0
  79. package/dist/index.js +5 -0
  80. package/dist/index.js.map +1 -0
  81. package/dist/parse/metrics.d.ts +17 -0
  82. package/dist/parse/metrics.d.ts.map +1 -0
  83. package/dist/parse/metrics.js +33 -0
  84. package/dist/parse/metrics.js.map +1 -0
  85. package/dist/parse/sleep.d.ts +23 -0
  86. package/dist/parse/sleep.d.ts.map +1 -0
  87. package/dist/parse/sleep.js +58 -0
  88. package/dist/parse/sleep.js.map +1 -0
  89. package/dist/parse/time.d.ts +4 -0
  90. package/dist/parse/time.d.ts.map +1 -0
  91. package/dist/parse/time.js +41 -0
  92. package/dist/parse/time.js.map +1 -0
  93. package/dist/parse/workouts.d.ts +17 -0
  94. package/dist/parse/workouts.d.ts.map +1 -0
  95. package/dist/parse/workouts.js +24 -0
  96. package/dist/parse/workouts.js.map +1 -0
  97. package/dist/server/app.d.ts +5 -0
  98. package/dist/server/app.d.ts.map +1 -0
  99. package/dist/server/app.js +39 -0
  100. package/dist/server/app.js.map +1 -0
  101. package/dist/server/ingest.d.ts +15 -0
  102. package/dist/server/ingest.d.ts.map +1 -0
  103. package/dist/server/ingest.js +41 -0
  104. package/dist/server/ingest.js.map +1 -0
  105. package/dist/types/hae.d.ts +103 -0
  106. package/dist/types/hae.d.ts.map +1 -0
  107. package/dist/types/hae.js +2 -0
  108. package/dist/types/hae.js.map +1 -0
  109. package/dist/util/zip.d.ts +3 -0
  110. package/dist/util/zip.d.ts.map +1 -0
  111. package/dist/util/zip.js +24 -0
  112. package/dist/util/zip.js.map +1 -0
  113. package/docs/COMMANDS.md +315 -0
  114. package/docs/plans/2026-02-18-hae-vault-initial-implementation.md +2015 -0
  115. package/docs/plans/2026-02-18-readme-dashboard-design.md +213 -0
  116. package/docs/plans/2026-02-18-readme-dashboard-plan.md +1306 -0
  117. package/docs/plans/2026-02-18-zip-env-watch-design.md +213 -0
  118. package/docs/plans/2026-02-18-zip-env-watch.md +966 -0
  119. package/package.json +57 -0
  120. package/src/cli/dashboard.ts +242 -0
  121. package/src/cli/import.ts +85 -0
  122. package/src/cli/index.ts +32 -0
  123. package/src/cli/info.ts +36 -0
  124. package/src/cli/metrics.ts +20 -0
  125. package/src/cli/query.ts +17 -0
  126. package/src/cli/serve.ts +18 -0
  127. package/src/cli/sleep.ts +19 -0
  128. package/src/cli/summary.ts +58 -0
  129. package/src/cli/trends.ts +103 -0
  130. package/src/cli/watch.ts +111 -0
  131. package/src/cli/workouts.ts +19 -0
  132. package/src/config.ts +28 -0
  133. package/src/db/importLog.ts +18 -0
  134. package/src/db/metrics.ts +15 -0
  135. package/src/db/schema.ts +105 -0
  136. package/src/db/sleep.ts +15 -0
  137. package/src/db/workouts.ts +13 -0
  138. package/src/index.ts +4 -0
  139. package/src/parse/metrics.ts +50 -0
  140. package/src/parse/sleep.ts +82 -0
  141. package/src/parse/time.ts +43 -0
  142. package/src/parse/workouts.ts +42 -0
  143. package/src/server/app.ts +46 -0
  144. package/src/server/ingest.ts +68 -0
  145. package/src/types/hae.ts +94 -0
  146. package/src/util/zip.ts +24 -0
  147. package/tests/cli-watch.test.ts +64 -0
  148. package/tests/db-import-log.test.ts +40 -0
  149. package/tests/db-metrics.test.ts +44 -0
  150. package/tests/db-schema.test.ts +55 -0
  151. package/tests/db-sleep.test.ts +36 -0
  152. package/tests/db-workouts.test.ts +34 -0
  153. package/tests/ingest.test.ts +99 -0
  154. package/tests/parse-metrics.test.ts +55 -0
  155. package/tests/parse-sleep.test.ts +65 -0
  156. package/tests/parse-time.test.ts +48 -0
  157. package/tests/parse-workouts.test.ts +43 -0
  158. package/tests/types.test.ts +27 -0
  159. package/tests/util-zip.test.ts +46 -0
  160. package/tsconfig.json +19 -0
@@ -0,0 +1,213 @@
1
+ # hae-vault β€” README, Dashboard & CLI Polish Design
2
+
3
+ **Date:** 2026-02-18
4
+ **Status:** Approved
5
+
6
+ ---
7
+
8
+ ## Scope
9
+
10
+ Five deliverables:
11
+
12
+ 1. **package.json** β€” add `repository`, `homepage`, `bugs`, `keywords`; match whoop-up metadata style
13
+ 2. **Git setup** β€” init, first commit, set remote `git@github.com:mrkhachaturov/hae-vault.git`, push to main
14
+ 3. **README.md + docs/COMMANDS.md** β€” full documentation following whoop-up style with example terminal outputs
15
+ 4. **CLI additions** β€” `hvault dashboard` (new) + `hvault summary --color` (enhancement) + `hvault trends` (new)
16
+
17
+ ---
18
+
19
+ ## package.json Changes
20
+
21
+ Add these fields to match whoop-up:
22
+
23
+ ```json
24
+ "keywords": ["apple-health", "health-auto-export", "sqlite", "cli", "hvault", "sleep", "hrv", "steps", "fitness"],
25
+ "repository": { "type": "git", "url": "https://github.com/mrkhachaturov/hae-vault.git" },
26
+ "homepage": "https://github.com/mrkhachaturov/hae-vault#readme",
27
+ "bugs": { "url": "https://github.com/mrkhachaturov/hae-vault/issues" }
28
+ ```
29
+
30
+ Author already correct: `"Ruben Khachaturov <mr.kha4a2rov@protonmail.com>"`
31
+
32
+ ---
33
+
34
+ ## README.md Structure
35
+
36
+ Mirrors whoop-sync/README.md style:
37
+
38
+ 1. Title + npm badge
39
+ 2. One-liner description
40
+ 3. Quick start (install + 4 key commands)
41
+ 4. Setup (HAE app config, env vars, serve/import/watch)
42
+ 5. Commands table β€” grouped: Ingest, Query, Analysis
43
+ 6. Example outputs β€” `hvault dashboard`, `hvault summary --color`, `hvault stats`
44
+ 7. Environment variables table
45
+ 8. Token/auth note (none β€” no OAuth, just local SQLite)
46
+ 9. Exit codes
47
+ 10. Development section
48
+ 11. Link to `docs/COMMANDS.md`
49
+
50
+ ---
51
+
52
+ ## docs/COMMANDS.md Structure
53
+
54
+ Full reference following whoop-sync/docs/COMMANDS.md:
55
+ - Each command with flags, description, example output
56
+ - Groups: Ingest (serve/import/watch), Query (metrics/sleep/workouts/query), Analysis (summary/dashboard), Info (sources/last-sync/stats)
57
+
58
+ ---
59
+
60
+ ## New CLI: `hvault dashboard`
61
+
62
+ **File:** `src/cli/dashboard.ts`
63
+
64
+ Sections:
65
+
66
+ ### Sleep (last night)
67
+ Query: `SELECT * FROM sleep ORDER BY date DESC LIMIT 1`
68
+ Fields: `asleep_h`, `deep_h`, `rem_h`, `awake_h`, `in_bed_h`, `source`
69
+ Derived: efficiency = asleep_h / in_bed_h * 100, stage percentages
70
+
71
+ ### Activity (today)
72
+ Query: `SELECT qty FROM metrics WHERE metric IN ('step_count','active_energy_burned','apple_stand_hour') AND date = today ORDER BY ts DESC LIMIT 1 each`
73
+ Graceful: show `β€”` if metric not in DB
74
+
75
+ ### Heart Health
76
+ Query: `SELECT qty FROM metrics WHERE metric IN ('resting_heart_rate','heart_rate_variability_sdnn') AND date = today ORDER BY ts DESC LIMIT 1 each`
77
+ Fallback: search last 7 days if today has no data
78
+
79
+ ### Recent Workouts
80
+ Query: `SELECT date, name, duration_min, calories FROM workouts ORDER BY ts DESC LIMIT 5`
81
+ Show sport emoji based on name (walkβ†’πŸšΆ, runβ†’πŸƒ, cyclingβ†’πŸš΄, etc.)
82
+
83
+ ### 7-Day Trends
84
+ Per metric: fetch 7 daily aggregates (avg per day), compute firstβ†’last delta, direction arrow ↑↓→
85
+ Metrics: step_count, resting_heart_rate, heart_rate_variability_sdnn + sleep.asleep_h
86
+
87
+ ### Vault Stats
88
+ Row counts: metrics, sleep, workouts tables
89
+ Last sync: `SELECT received_at FROM sync_log ORDER BY received_at DESC LIMIT 1`
90
+
91
+ **Output format:**
92
+ ```
93
+ πŸ“… 2026-02-18 | Apple Health Vault
94
+
95
+ ── Sleep (last night) ────────────────
96
+ 😴 7.2h | Efficiency: 94%
97
+ Deep: 1.5h (21%) | REM: 2.1h (29%) | Light: 3.6h (50%)
98
+ Awake: 0.3h | Source: Apple Watch
99
+
100
+ ── Activity (today) ──────────────────
101
+ πŸ‘Ÿ 8,432 steps | πŸ”₯ 420 kcal active
102
+ Stand hours: 10
103
+
104
+ ── Heart Health ──────────────────────
105
+ πŸ’“ Resting HR: 58bpm | HRV: 44ms
106
+
107
+ ── Recent Workouts ───────────────────
108
+ πŸƒ 2026-02-17 Walking 45min 280 kcal
109
+ 🚴 2026-02-15 Cycling 62min 420 kcal
110
+
111
+ ── 7-Day Trends ──────────────────────
112
+ Steps: 7,200 β†’ 8,432 ↑ (avg 7,840)
113
+ Sleep: 6.8h β†’ 7.2h ↑ (avg 7.1h)
114
+ Resting HR: 60 β†’ 58bpm ↓
115
+ HRV: 42 β†’ 44ms ↑
116
+
117
+ ── Vault Stats ───────────────────────
118
+ Metrics: 570,432 | Sleep: 365 | Workouts: 248
119
+ Last sync: 2026-02-18 09:23 UTC
120
+ ```
121
+
122
+ **Flags:**
123
+ - `--json` β€” output raw JSON (for AI agent use)
124
+ - `--days <n>` β€” trend window (default: 7)
125
+
126
+ ---
127
+
128
+ ## Enhanced `hvault summary --color`
129
+
130
+ **File:** `src/cli/summary.ts` (modify existing)
131
+
132
+ Current behavior: JSON output of all metric averages.
133
+ New behavior with `--color`: pretty terminal output of key metric averages.
134
+
135
+ Key metrics to highlight (skip if not in DB):
136
+ - `step_count` β†’ πŸ‘Ÿ
137
+ - `resting_heart_rate` β†’ πŸ’“
138
+ - `heart_rate_variability_sdnn` β†’ 🧠
139
+ - `active_energy_burned` β†’ πŸ”₯
140
+ - Sleep hours (from `sleep` table) β†’ 😴
141
+
142
+ **Output:**
143
+ ```
144
+ πŸ“Š 30-Day Summary
145
+
146
+ πŸ‘Ÿ Avg Steps: 8,432
147
+ πŸ’“ Avg Resting HR: 58bpm
148
+ 🧠 Avg HRV: 44ms
149
+ 😴 Avg Sleep: 7.2h
150
+ πŸ”₯ Avg Active Cal: 420 kcal
151
+ ```
152
+
153
+ New flags added to `summary`:
154
+ - `-c, --color` β€” pretty terminal output with emoji headers
155
+ - `--json` β€” explicit JSON mode (existing `--pretty` remains for compat)
156
+
157
+ ---
158
+
159
+ ## CLI Registration
160
+
161
+ `src/cli/index.ts`: add `import { dashboardCommand }` + `program.addCommand(dashboardCommand)`
162
+
163
+ ---
164
+
165
+ ## Constraints & Notes
166
+
167
+ - All metric names are case-sensitive strings from HAE β€” use lowercase snake_case as stored
168
+ - Dashboard gracefully handles missing metrics (shows `β€”`)
169
+ - No new dependencies required β€” pure Node.js string formatting
170
+ - `--json` on dashboard returns structured object for AI agent consumption
171
+ - Workout `duration_min` may need to be computed from `ts` range if not stored directly β€” check `workouts` table schema
172
+
173
+ ---
174
+
175
+ ## New CLI: `hvault trends`
176
+
177
+ **File:** `src/cli/trends.ts`
178
+
179
+ Multi-metric trend analysis over N days with direction arrows. Similar to `whoop trends`.
180
+
181
+ **Flags:**
182
+ - `--days <n>` β€” window (default: 7, accepts any value)
183
+ - `--json` β€” raw JSON output
184
+
185
+ **Logic:**
186
+ - Fetch per-metric daily averages over N days (same queries as dashboard trends section)
187
+ - For each metric: compute avg, min, max, direction (compare first half vs second half average)
188
+ - Include sleep from `sleep` table
189
+
190
+ **Output:**
191
+ ```
192
+ πŸ“Š 7-Day Trends
193
+
194
+ πŸ‘Ÿ Steps: 8,432 avg (6,100–11,200) ↑
195
+ πŸ’“ Resting HR: 58bpm avg (55–62) ↓
196
+ 🧠 HRV: 44ms avg (38–52) ↑
197
+ 😴 Sleep: 7.2h avg (5.5–8.9h) ↑
198
+ πŸ”₯ Active Cal: 420 kcal avg (280–620) β†’
199
+ ```
200
+
201
+ ---
202
+
203
+ ## Files to Create/Modify
204
+
205
+ | File | Action |
206
+ |---|---|
207
+ | `package.json` | Edit β€” add repo/homepage/bugs/keywords |
208
+ | `README.md` | Create |
209
+ | `docs/COMMANDS.md` | Create |
210
+ | `src/cli/dashboard.ts` | Create |
211
+ | `src/cli/trends.ts` | Create |
212
+ | `src/cli/summary.ts` | Edit β€” add `--color` flag |
213
+ | `src/cli/index.ts` | Edit β€” register dashboard + trends |