Discover a browser workflow once with an LLM. Review it as a typed, versioned capability. Replay it deterministically—with no LLM in the execution loop.
Design & implementation · Interview brief · Assignment report · Schema diagrams · Run evidence
Computer-use agents are useful at exploration, but a free-form agent loop is a poor production contract. This project turns a discovered browser workflow into an explicit artifact that a reviewer can inspect, approve, test, and replay safely.
flowchart LR
A[Goal] --> B[LLM discovery]
B --> C[Typed capability artifact]
C --> D[Human review]
D --> E[Approved versioned store]
E --> F[Deterministic replay]
F --> G[Typed result + evidence]
F --> H[Same-session human handoff]
H --> F
A replayed run reaches this page in the included legacy target app; the browser navigates, searches, opens the result, and reads the balance itself:
- Quick start
- Discover a new capability
- What it guarantees
- Capability lifecycle
- Beyond the happy path
- Architecture and contracts
- Verification
- Repository map
- License
Requires Python 3.12+ and Chromium.
python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/python -m playwright install chromiumStart the target application in one terminal:
.venv/bin/cua serve-targetIn a second terminal, replay the already-reviewed sample artifact:
# Valid member: returns a typed Money output
.venv/bin/cua replay \
--artifact artifacts/acme_core.lookup_savings_balance/2.json \
-p member_id=12345
# Valid business answer: returns MEMBER_NOT_FOUND, not an exception
.venv/bin/cua replay \
--artifact artifacts/acme_core.lookup_savings_balance/2.json \
-p member_id=99999Expected result for the first command (member 12345):
status: success
outputs:
{
"savings_balance": {
"amount_minor": 816000,
"currency": "USD"
}
}
Replay and hardening require no API key and never call an LLM. Only discovery does.
This is the assignment's end-to-end demo path: a live LLM run against the target app produces a draft artifact, which is reviewed and replayed.
cp .env.example .env
# GEMINI_API_KEY -- required for discovery. Free tier: https://aistudio.google.com/apikey--name below is demo_lookup_savings_balance, not lookup_savings_balance -- artifact versions save to artifacts/<capability_id>/<version>.json and a fresh discovery run always starts at version 1, so reusing the sample's name would silently overwrite the already-approved artifacts/acme_core.lookup_savings_balance/1.json shipped in this repo.
# 1. A live LLM/browser discovery run emits a draft artifact.
.venv/bin/cua discover \
--goal "look up member 12345 and read their current savings balance" \
--target http://127.0.0.1:8800/members/search \
--name demo_lookup_savings_balance
# 2. Review and promote it. Unattended replay refuses drafts.
.venv/bin/cua approve \
--artifact artifacts/acme_core.demo_lookup_savings_balance/1.json
# 3. Replay the artifact discovery itself just produced.
.venv/bin/cua replay \
--artifact artifacts/acme_core.demo_lookup_savings_balance/1.json \
-p member_id=12345A happy-path discovery run never sees "no such member," so step 1's artifact declares no business outcomes yet. cua harden closes that deterministically -- no LLM, a deliberately bad input, and only the condition actually observed gets recorded -- which is how the sample's own 2.json (used in Quick start) was produced from its 1.json:
.venv/bin/cua harden \
--artifact artifacts/acme_core.demo_lookup_savings_balance/1.json \
-p member_id=99999 \
--detect-text "No member records match" \
--outcome-code MEMBER_NOT_FOUND
.venv/bin/cua approve \
--artifact artifacts/acme_core.demo_lookup_savings_balance/2.json| Property | How it is enforced |
|---|---|
| No LLM in replay | cua replay takes only an approved artifact, typed inputs, policy, and browser adapter. Tests block discovery and outbound TCP during replay. |
| Reviewable behavior | A Pydantic capability declares typed inputs and outputs, ordered steps, locators, success conditions, and recovery rules. |
| Safe execution | The executor enforces scope, derives risk from the live target, bounds recovery, and distinguishes business outcomes from failures. |
| Auditable intervention | A leased SQLite handoff keeps the same browser session alive, then rechecks the page and policy before resuming. |
stateDiagram-v2
[*] --> Discovery: LLM observes and acts
Discovery --> Draft: compile transcript
Draft --> Approved: reviewer approves
Approved --> Replay: typed parameters
Replay --> Success: success condition
Replay --> BusinessOutcome: declared terminal condition
Replay --> Failed: unrecoverable error
Replay --> HumanHandoff: policy-gated intervention
HumanHandoff --> Replay: release + re-check
Approved --> Draft: harden / set-scope / tag-output / overlay apply
The discover → approve → replay flow above is the core loop; a few other operations build on it. Each has a real, captured run -- exact commands and result -- in evidence/README.md, and its design rationale in docs/DESIGN_AND_IMPLEMENTATION.md:
- Scope narrowing (
cua set-scope) restricts an artifact to specific origins/routes and re-requires approval. - Tenant overlays (
cua overlay apply) resolve a base capability plus a version-pinned per-tenant patch into a new, independently reviewed artifact -- reusing one capability across heterogeneous markup. - Drift detection (
cua drift-report) aggregates which locator layer resolved each step across every completed run, surfacing brittle steps before they break. - Human handoff pauses replay or discovery in the live browser session (
cua ops claim <run_id>/cua ops release <run_id>). Replay re-checks and resumes after release; discovery requires a structured--resolution:cleared_obstacleresumes LLM discovery, whileworkflow_advancedaborts without emitting an artifact. A handoff-touched discovery artifact must passcua validatebefore approval.
The detailed technical narrative is in docs/DESIGN_AND_IMPLEMENTATION.md. The contract diagrams are generated from the Pydantic JSON Schema and committed for review:
| Diagram | What it shows |
|---|---|
| Artifact contract | Typed containment between capability models. |
| Semantic references | Step IDs, ordering, input templates, and output dependencies. |
| Replay result contract | The typed terminal result variants. |
| Tenant overlay contract | The constrained overlay model. |
.venv/bin/python -m pytest -q
.venv/bin/python -m ruff check src testsTests cover artifact validation, replay safety and outcome ordering, scope/risk policy, bounded recovery, handoff ownership (both replay- and discovery-side), pre-approval validation, overlays, drift reporting, and a real Chromium end-to-end path from target-app fixture data to typed Money output.
| Path | Responsibility |
|---|---|
src/cua/target_app/ |
The included proxy target: a mock legacy credit-union servicing console. |
src/cua/agent/ |
Discovery (the only LLM call in the whole project), plus deterministic compilation and hardening. |
src/cua/schema/ |
Pydantic capability, overlay, and replay-result contracts. |
src/cua/surface/ |
SurfaceAdapter protocol, the locator-ladder resolver, and the Playwright WebAdapter. |
src/cua/replay/ |
Deterministic engine and terminal-match evaluation. |
src/cua/safety/ |
Allowlist, scope, risk, bounds, and redaction enforcement. |
src/cua/escalation/ |
SQLite control-transfer state and human evidence. |
artifacts/ and overlays/ |
Versioned reviewed behavior and tenant-specific deltas. |
evidence/ |
Captured discovery, replay, and handoff records. |
For the concise evaluator narrative, start with docs/INTERVIEW_BRIEF.md. For the complete design, start with docs/DESIGN_AND_IMPLEMENTATION.md.
