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
1 change: 1 addition & 0 deletions .github/agent-safety-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"packages/flow/openadapt_flow/ir.py",
"packages/flow/openadapt_flow/runtime/replayer.py",
"packages/flow/openadapt_flow/runtime/effects/**",
"packages/flow/openadapt_flow/local_state_sources.py",
"packages/flow/tests/test_verify_run.py",
"packages/flow/tests/test_verify_tools.py"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| Check a change that no app database holds: a saved file (contents and SHA-256), a Windows registry value (`winreg`, read-only) or a macOS preference key (`defaults export`), declared as typed sources in `verify.yaml` (`kind: local-state`); a missing value is a state, a failed read halts | On main | Real app in the lab: Windows 11 Notepad, recorded, compiled, replayed with a new note and checked by `verify-run` in the guest, 3 of 4 final trials `verified` (the fourth hit a lab timeout before replay), each with a skipped-replay control refuted; Windows registry reads checked on the same machine. The macOS source is unit-tested only | [LOCAL_STATE_CHECKS.md](packages/flow/docs/LOCAL_STATE_CHECKS.md), `runtime/effects/local_state.py`, `examples/local_state/` |
4 changes: 3 additions & 1 deletion packages/flow/docs/EFFECT_KIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ environment-assigned surrogate key is the right choice for it.
| `email` | `MaildirDeliveryVerifier` | maildir / SMTP-capture directory → one record per message (`to`, `subject`, `message_id`, body probe, freshness); verifies delivery TO THE CAPTURE POINT, not end-to-end receipt | **contract-proven in CI against maildir/tmp-dir fixtures** (wrong recipient, duplicate send, leak-to-other-recipient collateral hook) -- not live-proven against a production MTA |
| `document` | `DocumentArrivalVerifier` | report arrival + **parseable-content assertion**: each candidate parses (JSON dotted paths or named-regex groups) into judgeable fields; a corrupt report REFUTEs a `parseable: True` contract | **contract-proven in CI against temp-dir fixtures** (corrupt report, wrong entity, duplicates, stale mtime) |
| `document-hash` | `DocumentHashVerifier` | SHA-256 of each document in a store | live in CI (no external service) |
| `local-state` | `LocalStateVerifier` | typed, read-only sources on this computer: a file (contents, SHA-256), a macOS preference key, a Windows registry value; one record per source ([LOCAL_STATE_CHECKS.md](LOCAL_STATE_CHECKS.md)) | unit tests with stand-ins in CI; lab-proven on Windows 11 (Notepad file save, registry reads); macOS source unit-tested only |

All substrates share one judge (`runtime/effects/_common.py`), so
at-most-once counting, idempotency-key de-duplication, field read-back,
Expand Down Expand Up @@ -1233,6 +1234,7 @@ Per-kind required fields:
| `email` | `root` | `mail_pattern`, `file_mtime_window_s` (freshness), `file_content_probe` (body regex) |
| `document` | `root` | `file_pattern`, `document_format` (`json` \| `text`), `document_field_paths`, `document_text_pattern`, `file_mtime_window_s` |
| `document-hash` | `root` | `glob` |
| `local-state` | `local_state`: a list of `file`, `macos_defaults` or `windows_registry` sources | `poll_interval_s` |
| `surfaces` | `surfaces`: name -> one plain verifier config (any kind above) | each effect's `probe` names its surface (`surface=<name>`); an effect naming none, or an unknown one, halts |

A paged list is read whole or not at all. `fhir` follows the Bundle's `next`
Expand Down Expand Up @@ -1474,7 +1476,7 @@ profiles gate on the tier, never on prose:

| Tier | Label | What it proves | Adapters |
|---|---|---|---|
| 1 | `independent-system` | a read through the SoR's own API/DB/store -- independent proof | `rest`, `graphql`, `fhir`, `sql`; `file`, `email`, `document`, `document-hash` with `artifact_producer: system_of_record` |
| 1 | `independent-system` | a read through the SoR's own API/DB/store -- independent proof | `rest`, `graphql`, `fhir`, `sql`, `local-state`; `file`, `email`, `document`, `document-hash` with `artifact_producer: system_of_record` |
| 2 | `independent-session` | same app, read through its record page in a separate, separately signed-in, read-only session. **Not a system-of-record read** | `ui_readback`; `desktop_readback` with its own sign-in; file kinds with `artifact_producer: separate_session`; a plugin may also declare it |
| 3 | `reacquired-state` | the app's own UI re-navigated to re-fetch persisted state | `onscreen` with a different-path read-back; `desktop_readback` without its own sign-in |
| 4 | `screen-consistency` | the same surface the write drove still shows the value | `onscreen` same-surface; file kinds with `artifact_producer` `acting_session` or unset |
Expand Down
118 changes: 118 additions & 0 deletions packages/flow/docs/LOCAL_STATE_CHECKS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Check a change on this computer: files and OS settings

Most OpenAdapt checks read a saved record back from an application's
database or API. Some tasks change state that no application database holds:
a document saved to disk, or a setting such as Dark Mode. For those, the
`local-state` record check reads the state back through the operating
system's own read-only interfaces, so a run can still end "done and checked".

It is one check for every such task. An example declares which state it
changes and what that state must be after the run; the check reads it and
rules. It never runs a command you supply, and it never writes.

## What it can read

| Source `type` | What it reads | How | Record fields |
| --- | --- | --- | --- |
| `file` | A file's contents | Ordinary read-only file I/O | `present`, `size`, `sha256`, `text` (UTF-8, files up to 1 MiB) |
| `macos_defaults` | One key in a preferences domain | `/usr/bin/defaults export <domain> -` (goes through `cfprefsd`, so it sees the current value). Unit-tested only so far; not yet run on a real Mac | `present`, `value`, `value_type` |
| `windows_registry` | One registry value under `HKCU` or `HKLM` | `winreg` with `KEY_READ` access only | `present`, `value`, `value_type` |

Each source becomes one record with the source's `id`, judged by the same
effect kinds every other record check uses (`field_equals`, `record_written`).
A value is compared as text: numbers in decimal, booleans as `true`/`false`.

A missing file, preference key or registry value is a real state
(`present: False`). Light Mode on macOS, for example, is the absence of
`AppleInterfaceStyle`. Absence counts only inside a container that exists:
the file's folder, a preferences domain with at least one key, a registry
key. A missing folder, an empty domain (`defaults export` prints an empty
dictionary for a domain that doesn't exist, so a typo would look like
"absent") or a missing registry key is unreadable, like any other failed
read (the wrong operating system, permission denied, `defaults` failing).
Then the verdict is `INDETERMINATE` and the run stops. The check never
guesses a value.

The receipt records the verdict, the source's identity and digests. It
doesn't copy a file's text, but the baseline file `verify-run` writes before
the run holds the raw read (mode 0600), as it does for every record check.

The check is tier 1 (`independent-system`): it reads the store the state
lives in, through a separate process or API, not the screen that showed the
change.

## Use it

```yaml
# verify.yaml
schema_version: openadapt.verify/v1
minimum_effect_strength: independent_system_of_record
verifier:
kind: local-state
local_state:
- type: file
id: note
path: ~/openadapt-examples/note.txt
# Saving rewrites the file, so its hash and size change with its text.
frame:
target_fields: [present, text, sha256, size]
effects:
- kind: field_equals
match: {id: note}
field: text
value: {param: note}
```

`verify-run` also checks that nothing else in the read changed (the
frame). Without `frame.target_fields`, only the fields the effects name may
change, so a save would show `sha256` and `size` as unexpected changes and
the receipt would say `reconciliation_required`. List every field the change
is allowed to move; a change to any other source still fails the check.

Check a run with `verify-run`: read the state before the run, run the
program, then read it again and rule.

```bash
openadapt-flow verify-run --verify verify.yaml --params task.json --capture-baseline before.json
# ... run the program with the task's values ...
openadapt-flow verify-run --verify verify.yaml --params task.json \
--run-record run.json --authorization-ref local --baseline before.json --out receipt/
```

The lab runs drove the program with Flow's replayer through the Windows
agent and ran both `verify-run` steps on the Windows machine.

Run the check on the computer whose state changed. It reads only that
computer.

## Examples

The examples live in [`examples/local_state/`](../examples/local_state/).

| Example | State | Status |
| --- | --- | --- |
| `notepad-save` | `~/openadapt-examples/note.txt`, text equals the note | End to end on Windows 11 in the lab: record, compile, replay, check `verified`. Turn Notepad's status bar off (View > Status bar) so replay can confirm the typing |
| `windows-dark-mode` | `HKCU\...\Themes\Personalize` `AppsUseLightTheme` and `SystemUsesLightTheme` are `0` | Check only, on the real registry; see below |

TextEdit and macOS Dark Mode follow the same pattern (a `file` source; a
`macos_defaults` source on `NSGlobalDomain` `AppleInterfaceStyle`). They have
no example yet because they haven't been run on a Mac.

## What it can't check, and why

- **Night Shift (macOS).** Its state lives in CoreBrightness, a private
framework. There is no public API and no preference key that reliably
shows whether Night Shift is on now (the stored schedule is in a root-only
file and is not the current state). OpenAdapt can't check it, so there is
no Night Shift example.
- **Notes (macOS).** The supported ways to read a note are AppleScript and
Shortcuts. Both are scripts, not a typed read, and both need an Automation
consent prompt per app. The Notes database is private and protected by
Full Disk Access. There is no Notes source.
- **Calendar (macOS).** EventKit is a supported, public read API. It needs a
Calendar permission prompt and a PyObjC dependency that OpenAdapt doesn't
ship today. It is a candidate source, not built.
- **Windows dark mode on an unactivated Windows.** Windows locks the
Personalization pages until it is activated, so the setting can't be
demonstrated through Settings there. The check itself reads the registry
on any Windows.
20 changes: 20 additions & 0 deletions packages/flow/examples/local_state/notepad-save/verify.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Notepad (Windows): type a note into a text file and save it.
# The check reads the saved file back from disk: its text must be exactly
# the note this run was asked to type. Synthetic text only.
schema_version: openadapt.verify/v1
minimum_effect_strength: independent_system_of_record
verifier:
kind: local-state
local_state:
- type: file
id: note
path: ~/openadapt-examples/note.txt
# Saving rewrites the file, so its hash and size change with its text.
frame:
target_fields: [present, text, sha256, size]
effects:
- kind: field_equals
match: {id: note}
field: text
value: {param: note}
timeout_s: 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Dark mode (Windows): Settings > Personalization > Colors > Dark.
# The check reads the two per-user theme values from the registry with
# read-only access: 0 is dark, 1 is light.
schema_version: openadapt.verify/v1
minimum_effect_strength: independent_system_of_record
verifier:
kind: local-state
local_state:
- type: windows_registry
id: apps_theme
hive: HKCU
path: Software\Microsoft\Windows\CurrentVersion\Themes\Personalize
name: AppsUseLightTheme
- type: windows_registry
id: system_theme
hive: HKCU
path: Software\Microsoft\Windows\CurrentVersion\Themes\Personalize
name: SystemUsesLightTheme
frame:
target_fields: [present, value, value_type]
effects:
- kind: field_equals
match: {id: apps_theme}
field: value
value: "0"
timeout_s: 5
- kind: field_equals
match: {id: system_theme}
field: value
value: "0"
timeout_s: 5
1 change: 1 addition & 0 deletions packages/flow/import_layers.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"openadapt_flow.deployment",
"openadapt_flow.form_tx.receipt",
"openadapt_flow.key_rotation",
"openadapt_flow.local_state_sources",
"openadapt_flow.offline_seal",
"openadapt_flow.policy",
"openadapt_flow.production_qualification",
Expand Down
35 changes: 33 additions & 2 deletions packages/flow/openadapt_flow/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import os
import re
from pathlib import Path
from typing import Any, Callable, Final, Literal, Mapping, Optional
from typing import Annotated, Any, Callable, Final, Literal, Mapping, Optional

from pydantic import (
BaseModel,
Expand All @@ -39,6 +39,7 @@
model_validator,
)

from openadapt_flow.local_state_sources import LocalStateSource
from openadapt_flow.lookup_capabilities import (
DeclaredSurface,
declared_surface_problem,
Expand Down Expand Up @@ -225,6 +226,8 @@ def _surface_matches_kind(self) -> "BackendConfig":
"email",
"document",
"document-hash",
"local-state",
"local_state",
"desktop_readback",
"desktop-readback",
"deferred_report",
Expand Down Expand Up @@ -306,7 +309,7 @@ class EffectsConfig(BaseModel):

#: ``none`` | ``onscreen`` | ``ui_readback`` | ``rest`` | ``graphql`` |
#: ``fhir`` | ``sql`` | ``file`` | ``email`` | ``document`` |
#: ``document-hash``, or a PLUGIN
#: ``document-hash`` | ``local-state``, or a PLUGIN
#: kind registered under the
#: ``openadapt_flow.effect_verifiers`` entry-point group (the customer
#: adapter SDK seam -- see docs/EFFECT_KIT.md). ``onscreen`` is the no-API
Expand Down Expand Up @@ -538,6 +541,15 @@ class EffectsConfig(BaseModel):
root: Optional[str] = None
glob: str = "*"

# -- local-state (files and OS settings on this computer) ----------------
#: The typed, read-only sources ``kind: local-state`` reads: ``file``
#: (contents and SHA-256), ``macos_defaults`` (a preference key) and
#: ``windows_registry`` (a registry value). There is no free-form command;
#: see :mod:`openadapt_flow.runtime.effects.local_state`.
local_state: list[Annotated[LocalStateSource, Field(discriminator="type")]] = Field(
default_factory=list
)

# -- plugin record-check packs (registered kinds only) --------------------
#: Non-secret settings for a PLUGIN verifier kind: the per-system record
#: check a private pack implements (which read endpoint, which record
Expand Down Expand Up @@ -690,6 +702,8 @@ def _serialize_compatible(self, handler: Any) -> dict[str, Any]:
):
if data.get(added, "") is None:
data.pop(added, None)
if not data.get("local_state"):
data.pop("local_state", None)
return data

@model_validator(mode="after")
Expand Down Expand Up @@ -2361,6 +2375,11 @@ def sanitized(value: Any, *, key: str = "") -> Any:
):
if isinstance(candidate, dict) and candidate.get(added) is None:
candidate.pop(added, None)
# ``local_state`` defaults to an empty list; omit it unless configured so
# existing verifier identities stay unchanged.
for holder in [config, *(config.get("candidates") or [])]:
if isinstance(holder, dict) and not holder.get("local_state"):
holder.pop("local_state", None)
# The same rule one level down: ``ui_readback.reference`` came later.
for holder in [config, *(config.get("candidates") or [])]:
section = holder.get("ui_readback") if isinstance(holder, dict) else None
Expand Down Expand Up @@ -2665,6 +2684,18 @@ def _build_effect_verifier_unredacted(
acting_roots=cfg.acting_roots,
)

if kind in ("local-state", "local_state"):
if not cfg.local_state:
raise ValueError(
"effects.kind 'local-state' requires effects.local_state "
"(the files or settings to read)"
)
from openadapt_flow.runtime import LocalStateVerifier

return LocalStateVerifier(
list(cfg.local_state), poll_interval_s=cfg.poll_interval_s
)

if kind == "graphql":
if not cfg.base_url:
raise ValueError("effects.kind 'graphql' requires effects.base_url")
Expand Down
1 change: 1 addition & 0 deletions packages/flow/openadapt_flow/execution_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,7 @@ def _external_network_call_state(
"onscreen",
"file",
"document_hash",
"local_state",
"snapshot",
"test",
"fake",
Expand Down
Loading
Loading