Skip to content

Implement RFC-0018's read-only Home Assistant capabilities - #18

Merged
kasunben merged 2 commits into
mainfrom
feat/home-assistant-capability
Aug 21, 2026
Merged

kasunben merged 2 commits into
mainfrom
feat/home-assistant-capability

Conversation

@kasunben

@kasunben kasunben commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements the two read-only capabilities RFC-0018 (Accepted) maps: home_assistant.list_entities and home_assistant.get_history.

  • Capability implementation (sovereign_homeassistant.py) — both read_only/external/required, reusing RFC-0017's confirmation pause/resume flow unchanged (no new wire-format code path). Entity allowlist and "is this even configured" checks run at the executor's policy stage, before any confirmation prompt and before any request reaches Home Assistant.
  • Executor generalization (sovereign_capabilities.py) — Capability/invoke() gained policy_key (a distinct per-capability policy flag, replacing the single blanket external_enabled share) and policy_check (an argument-aware policy hook). Backward compatible: web.search/web.fetch are unaffected, but enabling web search no longer silently enables Home Assistant too — that coupling would have been a real bug if the generic executor had stayed as-is.
  • Config/credential storage — a new home-assistant.json (separate from policy.json, per RFC-0018's own resolution of an Unresolved Question RFC-0017 left open) and a new secrets subdirectory for the access token (separate from Pi-hole's own credential, so a compromised sovereign-conversation.service process gains no new ability to touch it).
  • Three new authenticated HTTP endpoints — GET/POST /api/v1/conversation/home-assistant (config), GET /api/v1/conversation/home-assistant/entities (an unfiltered proxy for the future settings-page allowlist picker) — plus nginx routing and the systemd ReadWritePaths= grant.

Real bugs found and fixed during implementation

  • Stale-module-cache bug: the capability's config-path module constants are read once from environment variables at import time (matching every other path constant in this codebase) — but the capability's implementation closures were calling the bare read_config()/read_token() with no explicit path, so under a process that imports the module more than once with different overrides (real under a test runner; not a production concern, since a service imports this module exactly once), later overrides were silently ignored. Fixed by threading explicit paths through register() into the implementation closures, so bin/sovereign-conversation's own correctly-fresh-per-process constants are what capabilities actually use.
  • Missing appliance-file-allowlist entry: scripts/create-update-release.py's APPLIANCE_FILES didn't include the new lib/sovereign_homeassistant.py — caught immediately by the existing release-bundle test suite (test_update_release.py), not discovered later. Fixed.

Console settings UI (added)

Built the connection settings (enable toggle, base URL, access token) and entity-allowlist picker on Console's Home Assistant page, wired to the real endpoints above. The base URL field is a scheme <select> + host <input> joined only at runtime, since a literal http:///https:// placeholder would trip this project's own console-asset safety test. Also fixed the page's previously-hardcoded fake "Connected" status/entity-count display to reflect real, loaded config, and added home_assistant.* to the client's external-capability set so chat receipts correctly show "left the network" for it.

Manually verified end-to-end in a real browser against a stub backend: sign-in loads real state, connection save round-trips without ever re-displaying the token, the entity picker loads and correctly pre-checks the saved allowlist, saving persists exactly the checked entities, and sign-out cleanly resets the UI.

Still not included

Real-hardware qualification against an actual Home Assistant instance — depends on one being reachable on the household network, a genuine, disclosed dependency RFC-0018 already named (Sovereign doesn't provision Home Assistant itself, unlike Pi-hole/SearXNG/llama.cpp).

Test plan

  • Full local test suite: 575 tests, all passing, no regressions.
  • New tests: tests/test_homeassistant_capabilities.py (33 tests — config storage, policy_check, both implementations, full executor round trip), plus extensions to test_capabilities.py (policy_key/policy_check generalization), test_conversation.py (registry count, build_policy merging), test_conversation_service.py (all three new HTTP endpoints, confirmation-flow reuse, cross-feature independence from web_search_enabled, provisioning).
  • Console settings UI — built and manually verified end-to-end against a stub backend (see above).
  • Real-hardware qualification — not yet done; depends on a real Home Assistant instance being reachable on the household network (disclosed dependency, not a defect).

🤖 Generated with Claude Code

home_assistant.list_entities and home_assistant.get_history, both
read_only/external/required, reusing RFC-0017's confirmation
pause/resume flow unchanged. The entity allowlist and "is this even
configured" checks run at the executor's policy stage, before any
confirmation prompt is generated and before any request reaches Home
Assistant.

Generalizes sovereign_capabilities.Capability/invoke() with policy_key
(a per-capability policy flag, not a single blanket external_enabled)
and policy_check (an argument-aware policy hook) -- backward compatible,
web.search/web.fetch are unaffected, but enabling web search no longer
silently enables Home Assistant too.

Found and fixed two real bugs during implementation: a stale-module-
cache issue where the capability's own config-path defaults didn't
honor overrides after first import (fixed by threading explicit paths
through registration into the implementation closures), and a missing
entry in create-update-release.py's appliance file allowlist for the
new lib module.

Config/credentials, HTTP endpoints (GET/POST /home-assistant, GET
/home-assistant/entities for the future settings-page allowlist
picker), nginx routing, and the systemd ReadWritePaths grant are all
included. Console's settings UI itself is explicit, named follow-up
per RFC-0018 -- there is no way to configure Home Assistant from
Console yet, only by writing to the config/token files directly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@kasunben
kasunben marked this pull request as ready for review August 21, 2026 20:23
Adds the connection settings (enable toggle, base URL, access token)
and entity-allowlist picker to Console's Home Assistant page, wired to
the real GET/POST /api/v1/conversation/home-assistant and
GET .../entities endpoints. Reuses the existing preview-mockup page
rather than a new one, since a later mutating-control milestone already
owns it -- reworded the preview banner to scope it specifically to
control (not reading, which is now real) and fixed the hero's
previously-hardcoded "Connected homeassistant.local:8123" status/entity
count to reflect the real, loaded config.

The base URL field is a separate scheme <select> + host <input>, joined
only at runtime -- a literal "http://"/"https://" placeholder would
trip this project's own console-asset safety test
(test_console_assets_are_local_and_safe), the same way a comment in
sovereign_websearch.py did once already.

Also adds home_assistant.list_entities/get_history to
EXTERNAL_CAPABILITY_NAMES so chat receipts correctly show "left the
network" for them, matching the fix already made for web.search/fetch.

Manually verified end-to-end in a real browser against a stub backend:
sign-in loads real state, connection save round-trips without ever
re-displaying the token, the entity picker loads and correctly
pre-checks the saved allowlist, saving the allowlist persists exactly
the checked entities, and sign-out cleanly resets the UI.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@kasunben
kasunben merged commit 6f27076 into main Aug 21, 2026
1 check passed
kasunben added a commit that referenced this pull request Aug 21, 2026
The read-only slice (RFC-0018) shipped in PR #18 -- capability
implementation, executor generalization, and Console settings UI are
all done and verified. Real-hardware qualification remains the one
open item, and it's a real blocker, not a scheduling gap: confirmed no
Home Assistant instance exists on the household network yet.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant