Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions addon-edge/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.0.0-edge.40

- Clear open manual run history when Domus observes a change to the member's current access.

## 0.0.0-edge.39

- Review your previous manual automation runs from the saved rule, including the original task outcome and retained results from before restoration.

## 0.0.0-edge.38

- Enable a saved manual automation revision, run it with an original receipt, and disable future runs.
Expand Down
7 changes: 4 additions & 3 deletions addon-edge/DOCS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Installation and operation

Edge 0.0.0-edge.38 packages the immutable runtime declared in
Edge 0.0.0-edge.40 packages the immutable runtime declared in
[artifact.json](artifact.json). Overview shows the signed-in member's completed tasks and
posted earned points for the current Family week. Open Family for the full report.
In Household settings, authorized members can preview a manual task proposal and
Expand All @@ -20,8 +20,9 @@ the optional `ha_deadline_digest` setting. The calendar uses its own
`ha_calendar_digest` setting. Both share the private app port `8100` when enabled.
Enable a saved revision in Manual automation and confirm it before running.
The run receipt links to its task when the stock condition matches. Check
the original request after an interrupted response.
Edge.38 introduces SQLite schema 33 and is listed in `breaking_versions`.
the original request after an interrupted response. Show run history lists
your own previous runs of the selected rule, with older pages on demand.
Edge.40 uses SQLite schema 33. Edge.38 introduced SQLite schema 33 and is listed in `breaking_versions`.
Keep a compatible image and stopped-app backup before
upgrading from an earlier schema. A binary that expects the earlier schema
requires its compatible data backup.
Expand Down
8 changes: 4 additions & 4 deletions addon-edge/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# The Supervisor builds this folder. Fetch only the reviewed immutable runtime and UI.
FROM ghcr.io/astral-sh/uv:0.11.29@sha256:eb2843a1e56fd9e30c7276ce1a52cba86e64c7b385f5e3279a0e08e02dd058fc AS uv
FROM python:3.14.6-slim-trixie@sha256:7bec7ddcddeff7975d6ba9b4be7dd6f6b2f55e7491539145e2978f7f97ce9144 AS source
ARG DOMUS_SOURCE_COMMIT=fee2e9695b5f7b648c38dbb550038614f30095d4
ARG DOMUS_SOURCE_SHA256=32920033aef3f2efb021b82dbbc5abb04475952628eb5d0ff794f791945f5a71
ARG DOMUS_SOURCE_COMMIT=50aa7190e4d910c8bea5e35658314279db284e3b
ARG DOMUS_SOURCE_SHA256=3959dde1479d90d3d6ddcb1489742ed998d6b47fcccc7daeba1fe1a3f324b987
ADD https://codeload.github.com/vypdev/domus/tar.gz/${DOMUS_SOURCE_COMMIT} /tmp/source.tar.gz
RUN printf '%s /tmp/source.tar.gz\n' "$DOMUS_SOURCE_SHA256" | sha256sum --check - \
&& mkdir /app \
Expand All @@ -24,9 +24,9 @@ RUN uv sync --frozen --no-dev --package domus-server --no-editable
RUN .venv/bin/python -c "from pathlib import Path; import domus; from domus.entrypoints.ui_bundle import load_bundle; assert load_bundle(Path(domus.__file__).parent / 'ui') is not None"

FROM python:3.14.6-slim-trixie@sha256:7bec7ddcddeff7975d6ba9b4be7dd6f6b2f55e7491539145e2978f7f97ce9144
ARG BUILD_VERSION=0.0.0-edge.38
ARG BUILD_VERSION=0.0.0-edge.40
ARG BUILD_ARCH
ARG DOMUS_SOURCE_COMMIT=fee2e9695b5f7b648c38dbb550038614f30095d4
ARG DOMUS_SOURCE_COMMIT=50aa7190e4d910c8bea5e35658314279db284e3b
LABEL io.hass.type="app" \
io.hass.version="${BUILD_VERSION}" \
io.hass.arch="${BUILD_ARCH}" \
Expand Down
27 changes: 14 additions & 13 deletions addon-edge/artifact.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"schemaVersion": 1,
"version": "0.0.0-edge.38",
"sourceCommit": "fee2e9695b5f7b648c38dbb550038614f30095d4",
"sourceArchiveSHA256": "32920033aef3f2efb021b82dbbc5abb04475952628eb5d0ff794f791945f5a71",
"version": "0.0.0-edge.40",
"sourceCommit": "50aa7190e4d910c8bea5e35658314279db284e3b",
"sourceArchiveSHA256": "3959dde1479d90d3d6ddcb1489742ed998d6b47fcccc7daeba1fe1a3f324b987",
"storageSchema": 33,
"wheelSHA256": "0c900758ed64a861cdd7a398d526a1012612233699f1921782ee77d503662a9f",
"wheelSHA256": "a75cb57fd5e309a11bc26aeb33446b4ee5e78b63bdcc569423176cb6ebd1f716",
"pythonFiles": {
"domus/__init__.py": "7182c88b92234b4328f94497f4e70222d4390d8093e4b62893dfa78ac5530ac6",
"domus/application/__init__.py": "1e8c0c87bf2a8ca947112543070583c0cc55d9d40b56eab0d86ed59a4ec1e82c",
Expand All @@ -16,6 +16,7 @@
"domus/application/automation_drafts.py": "4dd7a3f4225c91580fc2ac8deb8831238b5bb2e9a32af5de71bbdaa5376b117b",
"domus/application/automation_execution.py": "7e14ea9afa73a8ce3f3fb1ac373e9c13140eb1a08f6d7f3b1999d5fb036cb471",
"domus/application/automation_preview.py": "94289b9a6a5deb42ca4e82b430724e27d1bf53239b1d60b48c332a6ed854707f",
"domus/application/automation_run_history.py": "8b1b5de75b97920874a23e3df8b08483ea3a19cc6971163b61eb829b13280ac8",
"domus/application/calendar_commands.py": "bec257c2b7ba07166e69b1dd7ed0016541cd30ab6cb26f18f4fc4dce11017001",
"domus/application/calendar_queries.py": "37b9b8f1d43d9a21cc73c2533a908570783116ff7e5b6db47d6591dfbe2393d9",
"domus/application/commands.py": "b41069d5db23e594f135bc742f2479e25fce537dc0966052546d95409dc7bc05",
Expand Down Expand Up @@ -49,7 +50,7 @@
"domus/application/points.py": "a2a660198151d5b65a62b57cb90b35a82a28f38a9a3b7b214b49d6cf6cf0294e",
"domus/application/points_ports.py": "8392b778007d4c55bc55498d38c959d6dc1d4eeaa1dc501cf4d4928ce09f4ac0",
"domus/application/policy_commands.py": "bc588b5b5feb72fd5cb57d7b4a10ef5a05ae48da5ec042fd569142ce50fedeb6",
"domus/application/ports.py": "e73f85562b7c86b4692797415c1bfa5d00c19510d0fed9f9b41f8c227ceae287",
"domus/application/ports.py": "f8ab345f3acd5cd8d95c9787d237221c63d45a011a632f4f6246f368c37c80e6",
"domus/application/recovery_commands.py": "2b8c198cde97f0213ec1612ea32bce5e00637aab99862fe08b59418d3c64af49",
"domus/application/recurrence_commands.py": "4d91c498ced40c335b8a081719a33dde97ab081a050ab352c3f1fac83e6f1447",
"domus/application/recurrence_ports.py": "651d86417a20810c198aba0cd48129de6396db185278c01836366575027d6c24",
Expand Down Expand Up @@ -100,7 +101,7 @@
"domus/composition/recurrence.py": "62adda116cec8667e9142b03f422a138818575cf5814a79e219a65999dbed1e6",
"domus/composition/restore.py": "fe4f5040a99db1404938e402eefa54fc93139055a5bc92abdfb7bf35d0c87297",
"domus/composition/server.py": "f857338e254477cd7b1d452fc85434e75fd7a25781ed237bb0d5658ac13ad719",
"domus/composition/tasks.py": "5869ad675ef3c49a4c9d63780e6d667d09b76c69b4fbd6047b61e545713fb0e9",
"domus/composition/tasks.py": "1aeddf554d8b25182df653fcf7b4e6ffe5cf5bda5512cc9ad9578abdf7c8b4d8",
"domus/domain/__init__.py": "0aac8a2ba41471d7a174ef7baca6073c95009a9db96df3e032392aa4f80bd079",
"domus/domain/activation.py": "fcb2e47e939127d5e254e2136fb7f1459b40fa8c8561100579fced49666ad0fe",
"domus/domain/automation.py": "6ba1e359240ed89115fbb0499160c3e1931d5e451ea18624bf15dad08b5036aa",
Expand Down Expand Up @@ -144,7 +145,7 @@
"domus/entrypoints/__init__.py": "d46875cbfef7220c7244bf1b89112ece8122ecb0d66cd908f08f098f0f3c419f",
"domus/entrypoints/administration_dto.py": "aefac6648dd8fefae9d2366abed1c9d595c24a356f7caf945b742043b2c39777",
"domus/entrypoints/administration_http.py": "9ab62ee9759a4b31c5e994354562b48b947bd3428a5866dd9faeb0545ae37afe",
"domus/entrypoints/automation_http.py": "0b32b23adcb174723d736178d447243807b9ca574e9577f938f4e3d6e2188af4",
"domus/entrypoints/automation_http.py": "95a9e6cc02c30c8f658fea1fb6ff8c6ecb71869003156e412c7f9a51604b93cc",
"domus/entrypoints/bounded_http.py": "d8047746eddb7193f1aa9f16007958c79cc6ae7ac1c30ab93909883e3aa97b54",
"domus/entrypoints/calendar_http.py": "5a7359ac2a876296a13bfe4bc63ac69bd36aec48e55c536a20470a789a6fef13",
"domus/entrypoints/console_recovery.py": "854a3f8d7a2e74f301ac5bd4b54682e409e2669a3bb7e05546e479c113c09026",
Expand All @@ -160,7 +161,7 @@
"domus/entrypoints/ingress_boundary.py": "1aa1d684b8625464b5d36d272f71d94b4cd32b84819ff8765a821c9a722f8f28",
"domus/entrypoints/ingress_http.py": "f6557eb5481d132131f66ad7691e30c223c63a66a6f0ae5754c9fba3bc7f3626",
"domus/entrypoints/inventory_http.py": "a58e114de6ff684f6d7d1a93f7f4cb316b8ffa60b0c662733df2c1fd70c2ab6e",
"domus/entrypoints/native_http.py": "68aa8a19bc303345dec44cb67dfc3855cc4d4be9cbe8143b6c63859b8f9f2def",
"domus/entrypoints/native_http.py": "d6d8c06095b9128ea316a2dcb2f7cb0ac1559c29ef28dad8d9d70150a69aac15",
"domus/entrypoints/openapi.py": "01a3fab9e5890ebcc1fb9c70bce9ced43d45b9190afd134db7dd45e0c5eb28f1",
"domus/entrypoints/point_allocation_http.py": "7339c88c083206c0778885b55793c80af219b15af7004c5a51d34dbc28f4da5c",
"domus/entrypoints/recurrence_dto.py": "094e6f64e1f963bfb053e830b214eed1189258e4f0eb8ff15ddba1f059649a1a",
Expand All @@ -169,7 +170,7 @@
"domus/entrypoints/schedule_creation_http.py": "2a3c3ea682f978eb2767dc8808a218c312861f31079cc2c76dbc3847ddec3197",
"domus/entrypoints/task_category_http.py": "e5443015f5e5cb2684eb6807e0a3bac5116703b5611508281afd7d1addee9672",
"domus/entrypoints/task_dto.py": "10657d1df0180bf05e71d1f38ac3214d2cea34c8822f50ea25ab331b9c014049",
"domus/entrypoints/task_http.py": "4ae65072cbeb4b4e060ac9b8c6a6c04a018b501b2ddef2c6f9aabb1d65390b96",
"domus/entrypoints/task_http.py": "a1182b29378346fb9822113f1296e497c5a90985045d0f7c577506235f827bf8",
"domus/entrypoints/task_response.py": "d2f4c0795aee429fc318b32495601031c559fa38af1d7da63b4735f7e6eb5d13",
"domus/entrypoints/ui_bundle.py": "beae3d4a7a57375ee195cca81efccdbc899d9db4286029d53eabaf30de6e14f7",
"domus/entrypoints/ui_http.py": "b6c47baa742f3862173a93e4121dc9914fd972eb6287ffffb9ffccecbf2ebe4a",
Expand Down Expand Up @@ -204,7 +205,7 @@
"domus/infrastructure/sqlite_member_profiles.py": "db7be5e4209d408f2fd780f684ba3a0a76267347fd2cbc0521a33c06e5453ec5",
"domus/infrastructure/sqlite_point_allocations.py": "e1aa5075544bf5faf16dac92fc0655c82fc65a3b5495fc916dc33769168c8bd5",
"domus/infrastructure/sqlite_points.py": "5ca24ac9c135e676968e15ab8d7a17e5f2cd12bf9cd0b4fee53a3542d2da0236",
"domus/infrastructure/sqlite_receipts.py": "0c7abbc6bcce8b1550e97da54c42701bc2dc5c6280cf61e3370a53ce6839745c",
"domus/infrastructure/sqlite_receipts.py": "0e972eda2076e71226bd3387b77c1bd63626f85800ec4ea6e2f2abfea849916d",
"domus/infrastructure/sqlite_recovery.py": "01fa6b8896674ce8203073c468eccb7033a9824052d7db3a853c80a2df6e2650",
"domus/infrastructure/sqlite_recurrence.py": "5f74818f6f711b9bd4c02ff1661b536e7e87af202bf711e32a50a200c7d297a4",
"domus/infrastructure/sqlite_recurrence_integrity.py": "b69d15222964e9d6e44d6cfb22501de47f1efd12383ff4a7a141c206ffcd3752",
Expand Down Expand Up @@ -233,9 +234,9 @@
"domus/infrastructure/task_materials.py": "d5d2934e36f290c7bf44b473392f014eab8749f1f3b3d26a3402079e65d2818f"
},
"uiFiles": {
".vite/manifest.json": "0668970d07960016c3d9d24807f6ffdbd3e9aad8fedf67b0e46745316e0d2982",
"assets/index-Bq58zfmH.js": "e662150cb70518dd642a80be62c0ad15bc8ef3fd54c9b12ba138ffbc9fb44356",
".vite/manifest.json": "6b7306c5c8bf00ef6645af1c42382d115bd1f2fb8f2543fef4d4d8e24a42b447",
"assets/index-CjJnHZzV.css": "0f2c8c2e31576c0b64fe60373150f09390dafb896df6c07777b2a220ad430e48",
"index.html": "be33a29f23894572c40532edb4128495f808ac8fb5b79b99f3a68a231a2949dc"
"assets/index-yveh722F.js": "adb93e081a9db030ffdb6d4f827284a8a4932a9eca3ae66fa650d2a8f554781c",
"index.html": "421ae444b7598e39be8b6f552c76a258d3d643c4685fd4b94470c538898c8583"
}
}
2 changes: 1 addition & 1 deletion addon-edge/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Domus Edge
version: "0.0.0-edge.38"
version: "0.0.0-edge.40"
slug: domus_edge
description: Development preview of the local Domus household application
url: https://github.com/vypdev/domus
Expand Down
151 changes: 151 additions & 0 deletions backend/src/domus/application/automation_run_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
"""Read one member's previously committed manual automation outcomes."""

import re
from collections.abc import Callable
from dataclasses import dataclass

from domus.application.automation_execution import RUN_AUTOMATION
from domus.application.automation_preview import AutomationCommandAuthority
from domus.application.fixed_materialization import MaintenanceScope
from domus.application.ports import Transactions, UnitOfWork
from domus.application.task_authorization import TaskAccess
from domus.application.task_ports import TaskCursors
from domus.domain.errors import Forbidden, InvalidInput, NotFound, StorageFailure
from domus.domain.identity import MAX_REVISION, HumanIdentity, Permission, validate_revision
from domus.domain.storage import CommandKey, JsonDocument, Receipt, validate_identifier


@dataclass(frozen=True, slots=True)
class AutomationRunSummary:
operation_id: str
created_at: int
rule_revision: str
condition_matched: bool
task_created: bool
historical: bool
task_occurrence_id: str | None


@dataclass(frozen=True, slots=True)
class AutomationRunPage:
rule_id: str
items: tuple[AutomationRunSummary, ...]
next_cursor: str | None


def _position(marker: str) -> int:
if not re.fullmatch(r"[1-9][0-9]{0,18}", marker) or int(marker) > MAX_REVISION:
raise InvalidInput("invalid_task_cursor")
return int(marker)


def _task_access(unit: UnitOfWork, home: str, actor: HumanIdentity) -> bool:
try:
TaskAccess(actor).require(unit, home, Permission.TASKS_READ)
except Forbidden:
return False
return True


def _summary(
unit: UnitOfWork,
receipt: Receipt,
*,
task_access: bool,
) -> AutomationRunSummary:
result = receipt.result.decode()
revision = result.get("rule_revision")
matched = result.get("condition_matched")
occurrence_id = result.get("task_occurrence_id")
task_operation_id = result.get("task_operation_id")
try:
if (
not isinstance(revision, str)
or str(int(revision)) != revision
or type(matched) is not bool
or (
matched
and not (isinstance(occurrence_id, str) and isinstance(task_operation_id, str))
)
or (not matched and (occurrence_id is not None or task_operation_id is not None))
or type(receipt.created_at) is not int
or not 0 <= receipt.created_at <= MAX_REVISION
):
raise InvalidInput("invalid_automation_run_receipt")
validate_revision(int(revision))
if isinstance(occurrence_id, str) and isinstance(task_operation_id, str):
validate_identifier(occurrence_id)
validate_identifier(task_operation_id)
except InvalidInput, ValueError:
raise StorageFailure("invalid_automation_run_receipt") from None

linked = (
occurrence_id
if isinstance(occurrence_id, str)
and not receipt.historical
and task_access
and unit.tasks.occurrence(receipt.command.household_id, occurrence_id) is not None
else None
)
return AutomationRunSummary(
receipt.operation_id,
receipt.created_at,
revision,
matched,
matched,
receipt.historical,
linked,
)


@dataclass(frozen=True, slots=True)
class AutomationRunHistory:
transactions: Transactions
scope: MaintenanceScope
read_actor: Callable[[], HumanIdentity]
cursors: TaskCursors

def page(self, rule_id: str, *, limit: int, cursor: str | None) -> AutomationRunPage:
validate_identifier(rule_id)
if type(limit) is not int or not 1 <= limit <= 100:
raise InvalidInput("invalid_page_size")
human = self.read_actor()
home = self.scope.household_id
authority = AutomationCommandAuthority(
human, self.scope, CommandKey(home, human.ha_user_id, RUN_AUTOMATION, "history")
)
with self.transactions.read() as unit:
member = authority.owner(unit)
if unit.automation_drafts.latest(home, rule_id) is None:
raise NotFound("automation_draft_missing")
binding = JsonDocument.from_value(
{
"query": "manual-automation-runs-v1",
"installation": self.scope.installation.instance_id,
"channel": self.scope.installation.channel,
"household": home,
"actor": human.ha_user_id,
"member": member.member_id,
"rule": rule_id,
"limit": limit,
}
)
through = (
MAX_REVISION
if cursor is None
else _position(self.cursors.decode(binding, cursor)) - 1
)
rows = unit.receipts.automation_run_page(
home, human.ha_user_id, member.member_id, rule_id, limit=limit + 1, through=through
)
can_read_task = _task_access(unit, home, human)
return AutomationRunPage(
rule_id,
tuple(
_summary(unit, receipt, task_access=can_read_task)
for _, receipt in rows[:limit]
),
self.cursors.encode(binding, str(rows[limit - 1][0]))
if len(rows) > limit
else None,
)
10 changes: 10 additions & 0 deletions backend/src/domus/application/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ def get(self, command: CommandKey) -> Receipt | None: ...
def get_operation(
self, household_id: str, actor_id: str, operation_id: str
) -> Receipt | None: ...
def automation_run_page(
self,
household_id: str,
actor_id: str,
member_id: str,
rule_id: str,
*,
limit: int,
through: int,
) -> tuple[tuple[int, Receipt], ...]: ...
def add(self, receipt: Receipt) -> None: ...


Expand Down
2 changes: 2 additions & 0 deletions backend/src/domus/composition/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from domus.application.automation_drafts import AutomationDrafts
from domus.application.automation_execution import AutomationExecution
from domus.application.automation_preview import AutomationPreview
from domus.application.automation_run_history import AutomationRunHistory
from domus.application.calendar_commands import CalendarCommands
from domus.application.calendar_queries import CalendarQueries
from domus.application.family_queries import FamilyQueries
Expand Down Expand Up @@ -112,6 +113,7 @@ def family() -> FamilyQueries:
lambda: AutomationPreview(store, scope, actor.read()),
AutomationDrafts(store, scope, actor, actor.read, clock, identifiers, cursors),
AutomationExecution(store, scope, actor, actor.read, clock, identifiers, tasks),
AutomationRunHistory(store, scope, actor.read, cursors),
)

return context
9 changes: 9 additions & 0 deletions backend/src/domus/entrypoints/automation_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
RunAutomation,
)
from domus.application.automation_preview import AutomationPreviewAccess
from domus.application.automation_run_history import AutomationRunPage
from domus.domain.automation import (
AUTOMATION_RULE_VERSION,
MAX_RULE_NODES,
Expand Down Expand Up @@ -264,6 +265,14 @@ def configure(
)
return _receipt(receipt)

@router.get("/drafts/{rule_id}/runs", response_model=AutomationRunPage)
def run_history(
request: Request, rule_id: Identifier, query: Annotated[PageQuery, Query()]
) -> AutomationRunPage:
return context(request).automation_run_history.page(
rule_id, limit=query.limit, cursor=query.cursor
)

@router.post(
"/drafts/{rule_id}/runs",
response_model=ReceiptResponse,
Expand Down
5 changes: 5 additions & 0 deletions backend/src/domus/entrypoints/native_http.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Native HTTP binds HA Ingress to local sessions and the common household API."""

import re
from collections.abc import Callable
from dataclasses import dataclass
from typing import Annotated, Literal, cast
Expand Down Expand Up @@ -112,6 +113,10 @@ def _allowed(self, scope: Scope) -> None:
"/api/v1/inventory/shopping-list/",
)
)
or re.fullmatch(
r"/api/v1/automation/drafts/[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}/runs",
scope["path"],
)
or scope["path"]
in (
"/api/v1/automation/drafts",
Expand Down
Loading