Skip to main content

Zu pattern library: the policy-prior / move-ordering layer over the Action Surface (§5)

Project description

zu-patterns — the policy-prior / move-ordering layer (§5)

Import these (cross-run memory + guided search already ship here — don't rebuild them):

import does
from zu_patterns import recognize recognize a surface archetype (cookie wall, login, cart, …) + emit rail invariants
from zu_patterns import fsm_from_events cross-run "learned site map" — induce an FSM from prior run/shadow events
from zu_patterns import mpc_run the live model-predictive-control loop (live_mpc_step, plan, classify_action)

Also: fsm_from_shadow / merge_transition_models (fold a Shadow recording into the map, merge maps across runs), Plan / PlanStep, the built-in recognizers (cookie_banner, login_form, search_box, cart_checkout, …). Run zu capabilities.

A UI is a state space; the Action Surface is the move generator (affordances = legal moves). This package is the policy prior + guided search layer over that surface — the AlphaZero shape, not Deep Blue. It does not brute-force a live space (visiting a node might charge a card). It proposes the promising interaction without exploring, and the rail (§1) verifies the prediction.

The new port — Pattern (group zu.patterns)

The Pattern Protocol lives in zu-core (zu_core.ports.Pattern), like the other ports. A pattern is read-only: it recognizes a situation over a core SurfaceView (zu_core.surface) and emits success_invariants / failure_invariants (declarative zu_core.invariants.Invariants the rail verifies). It never calls a tool and never decides the task action — that is the policy's job. A recognized pattern is a prior to be confirmed by observation, never ground truth (ZU-RAIL-9): its success criteria compile (via compile_spec) to Monitors, and a behaviour mismatch fires a detector.

The boundary that makes this clean: recognize takes the core SurfaceView, never zu-tools' Surface. zu-tools projects its Surface onto SurfaceView through a one-way adapter (zu_tools.surface_adapter.to_surface_view), so zu-patterns depends only on zu-core.

The pieces

  • recognizer.py — a pure pass over a SurfaceView: classify → archetype + confidence. Low confidence ⇒ no hint (fall through to the model).
  • reversibility.py — a principled, default-to-committing classifier of an action as reversible (read-only/idempotent, safe to explore live) vs committing (side-effecting — the live-search/rail commit boundary). No site-specific keyword blocklist: HTTP-method/idempotency, affordance semantics, an extensible prior set, default-to-committing on uncertainty.
  • rail.py — the success/failure → Invariant helpers shared by the patterns.
  • search.py — an offline best-first planner over the Phase-1 zu_core.reachability.Fsm with the recognizer as the move-ordering prior, plus an event-log → Fsm transition-model builder. Pure, offline, $0. The live guided-MPC loop and the Shadow-sourced transition model are deferred seams (stubbed/documented).

The 8 starter archetypes

cookie_banner, login_form, search_box, modal_dialog, paginated_list, sortable_table, autocomplete, cart_checkout — the last is the canonical irreversible-boundary pattern (its place-order/pay step is classified COMMITTING; the script stops before it).

All recognition is deterministic structural matching over roles/labels/states (no model), so every pattern is tested at $0 with hand-built SurfaceViews. A small-model recognizer is a future plugin behind the same Protocol.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zu_patterns-0.4.0.tar.gz (41.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zu_patterns-0.4.0-py3-none-any.whl (40.6 kB view details)

Uploaded Python 3

File details

Details for the file zu_patterns-0.4.0.tar.gz.

File metadata

  • Download URL: zu_patterns-0.4.0.tar.gz
  • Upload date:
  • Size: 41.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for zu_patterns-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8d8406de214b2b3686355fc2847bb4f27d420e3dd14ee4d8202b8c28508055ec
MD5 d110386a23f5b7dad0981de6abb62eca
BLAKE2b-256 d0a832fa3790bd6df79f4fcd0478eb43b7d5a64dbd979b980109b37cadb44caf

See more details on using hashes here.

File details

Details for the file zu_patterns-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: zu_patterns-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 40.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for zu_patterns-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5394f43641de2b539e98af5241eff7e3b278e3c9dab6fbbbefd7045f1fac88ce
MD5 51c78a9c2a3667a85c4f6f11c55898dc
BLAKE2b-256 6eb47b78f3cb9c61402c6155017de0c93573ffedd4c522519ef4035b64e97d71

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page