Commit 1cd6805
feat(dashboard): add jq_transform and find_card for efficient editing (#333)
* feat(dashboard): add jq_transform and find_card for efficient editing
Implements features from issues #319 and #320 to improve dashboard
editing UX for AI agents.
## New features:
### jq_transform parameter (#319)
- Added `jq_transform` parameter to `ha_config_set_dashboard`
- Apply jq expressions to existing dashboard config instead of full replacement
- Examples: update card icon, add cards, delete cards by path
- Reduces token usage for small changes (99% reduction for single edits)
### ha_dashboard_find_card tool (#320)
- Find cards by entity_id (with wildcard support), card_type, or heading
- Returns jq_path for each match, ready for use with jq_transform
- Eliminates manual index counting from large dashboard configs
## Dependencies:
- Added jq>=1.8.0 for jq expression support
## Usage example:
```python
# Find card location
find = ha_dashboard_find_card(url_path="my-dash", entity_id="light.bedroom")
# Update using jq_path
ha_config_set_dashboard(
url_path="my-dash",
jq_transform=f'{find["matches"][0]["jq_path"]}.icon = "mdi:lamp"'
)
```
Closes #319
Closes #320
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat(dashboard): require config_hash, remove card tools, add hints
BREAKING CHANGE: Remove ha_dashboard_add_card, ha_dashboard_update_card,
ha_dashboard_remove_card tools. Use jq_transform in ha_config_set_dashboard
instead for all card operations.
Changes:
- config_hash now REQUIRED for jq_transform (optimistic locking)
- config_hash optional for full config replacement (validates if provided)
- Add card_count and hint to get_dashboard for large dashboards (30+ cards)
- Add soft warning when full-replacing large dashboards
- Document multi-op jq syntax with pipe chaining
- Add IMPORTANT warning about index shifting after delete/add ops
- Add ENABLE_DASHBOARD_PARTIAL_TOOLS feature flag for find_card
- Remove 726 lines of redundant card tool code
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* chore: remove obsolete tests for non-existent dashboard tools
Remove test file and conftest that tested dashboard resource tools
(ha_config_add_dashboard_resource, etc.) which were never implemented.
Also fix feature flag check to handle missing settings gracefully.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* test: remove E2E tests for removed card tools
Remove TestCardOperations class from E2E tests since ha_dashboard_add_card,
ha_dashboard_update_card, and ha_dashboard_remove_card have been replaced
by jq_transform in ha_config_set_dashboard.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* refactor(dashboard): improve tool guidance and use token-based threshold
Address feedback from PR review:
- Update tool description to clearly prefer jq_transform for edits
- Change threshold from card count to config size (10KB ≈ 2-3k tokens)
- Return config_size_bytes instead of card_count in get_dashboard
- Remove unused _count_cards_in_config helper
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* test: add E2E tests for jq_transform and find_card
Add comprehensive E2E tests for new features:
- jq_transform: update field, add/delete cards
- config_hash validation: conflict detection, required for jq_transform
- ha_dashboard_find_card: by entity, by type, workflow with jq_transform
Tests cover:
- Basic jq operations (update, add, delete)
- Optimistic locking (hash validation)
- find_card -> jq_transform workflow
- Error cases (missing hash, stale hash)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 248b181 commit 1cd6805
7 files changed
Lines changed: 773 additions & 2602 deletions
File tree
- src/ha_mcp
- tools
- tests/src
- e2e/workflows/dashboards
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
72 | 77 | | |
73 | 78 | | |
74 | 79 | | |
| |||
0 commit comments