Commit 01cc5d9
committed
feat: auto-backup edited entities before write/destructive tool calls
Closes #1288. Captures a per-entity snapshot of every wrapped write or
destructive MCP tool call (automation, script, scene, helper, dashboard,
dashboard resource, label, category, group, zone, area/floor, todo item,
calendar event, entity, integration enable/disable + matching remove /
delete tools — 28 wrapped points). Captures land as YAML files in a
local directory (default /data/ha_mcp_backups on the addon,
${XDG_DATA_HOME:-~/.local/share}/ha_mcp/backups elsewhere; override via
HAMCP_BACKUP_DIR) and are listable, viewable, diffable, restorable, and
deletable via:
- Polymorphic MCP tool ha_manage_backup(scope, action, ...). Replaces
the previous ha_backup_create + ha_backup_restore pair under
scope="snapshot" (existing full-HA-tarball behavior, no semantic
change) and adds the new scope="edits" actions list/view/restore/
delete. Strong gating against accidental wrong-mode usage: invalid
(scope, action) combos return VALIDATION_INVALID_PARAMETER with the
legal set in suggestions; required params validated per cell so
"restore my automation" can never route through the heavy
HA-restart restore path.
- New "Backups" tab in the existing /settings web UI with filter, view,
diff, restore, per-row delete, and bulk-delete-by-filter actions —
list / view / diff / restore / delete REST endpoints at
/api/settings/backups[/<name>[/diff|/restore]].
Capture is gated by the new enable_auto_backup setting (default off).
Throttle window is configurable via auto_backup_throttle_minutes
(default 0 = capture every write); retention is configurable via
auto_backup_retain_per_entity (default 20). All three plumb through the
addon config + dev mirror + dev translation + start.py env mapping.
Implementation lives in src/ha_mcp/backup_manager.py (BackupManager +
DomainHandler registry) and src/ha_mcp/tools/auto_backup.py
(@with_auto_backup decorator). Captures are best-effort: any failure in
the pre-write hook logs a WARNING and the wrapped tool proceeds. The
existing ha_config_set_yaml backup precedent in
custom_components/ha_mcp_tools is untouched — this PR adds a
parallel system that works without the custom component installed.1 parent d128bf1 commit 01cc5d9
31 files changed
Lines changed: 3011 additions & 174 deletions
File tree
- docs/superpowers/specs
- homeassistant-addon-dev
- translations
- homeassistant-addon
- src/ha_mcp
- tools
- transforms
- tests/src
- e2e/workflows
- auto_backup
- convenience
- unit
Lines changed: 70 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
127 | 130 | | |
128 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
129 | 190 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
135 | 196 | | |
136 | 197 | | |
137 | 198 | | |
| |||
208 | 269 | | |
209 | 270 | | |
210 | 271 | | |
211 | | - | |
212 | 272 | | |
213 | 273 | | |
214 | 274 | | |
215 | 275 | | |
216 | 276 | | |
| 277 | + | |
217 | 278 | | |
218 | 279 | | |
219 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
| |||
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
43 | 49 | | |
44 | 50 | | |
45 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
48 | 72 | | |
49 | 73 | | |
50 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
221 | 224 | | |
222 | 225 | | |
223 | 226 | | |
| |||
242 | 245 | | |
243 | 246 | | |
244 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
245 | 254 | | |
246 | 255 | | |
247 | 256 | | |
| |||
282 | 291 | | |
283 | 292 | | |
284 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
285 | 297 | | |
286 | 298 | | |
287 | 299 | | |
| |||
0 commit comments