# guidriver `guidriver` is a Windows-first PUDA edge service for software-controlled laboratory instruments that expose only a graphical user interface. It can observe a tightly allowlisted application window, record researcher clicks and keystrokes, compile the trace into a reviewable routine, and replay only routines that have been explicitly approved and cryptographically bound to their reviewed content. PyAutoGUI performs replay and screenshots; it does not provide the demonstration recorder. `guidriver` uses non-blocking `pynput` mouse/keyboard listeners to capture the researcher's operation, then uses PyAutoGUI only after PUDA state and approval checks pass. This repository is an executable MVP and engineering plan. It does **not** claim that raw screen coordinates can safely automate every GUI. Accessibility identifiers or vendor APIs remain preferable; coordinate/image automation is a bounded fallback. ## Safety boundary The lifecycle deliberately separates learning from actuation: ```text researcher operation -> local recording -> draft routine -> human review/test -> approval hash -> generated @command -> edge restart -> PUDA execution ``` - Real replay is rejected unless the exact routine content has a valid human approval hash. - Approval and execution are rejected without an intact researcher-demonstration event hash. - `run_function(..., dry_run=true)` is the default. - The configured title regex and process name form an application allowlist. - The target must remain active before each non-wait step. - Clicks outside the target window are rejected, and PyAutoGUI's corner fail-safe remains enabled. - The MVP rejects target windows outside the primary monitor because PyAutoGUI multi-monitor behavior is not reliable enough for equipment control. - Printable keyboard text is redacted by default and becomes a required routine parameter. - Screenshots, recordings, and site-specific functions stay under ignored `runtime/` storage. - Approval is a local CLI action, never a remotely callable PUDA command. See [PLAN.md](PLAN.md), [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md), and [docs/SAFETY.md](docs/SAFETY.md) before operating real equipment. ## Repository structure ```text guidriver/ ├── main.py # Config -> Driver -> EdgeNatsClient -> EdgeRunner ├── driver.py # Reviewed PUDA command surface ├── guidriver/ │ ├── backend.py # Windows UIA identity + bounded PyAutoGUI input │ ├── recorder.py # Target-scoped researcher operation recording │ ├── compiler.py # Recording -> non-executable draft │ ├── executor.py # State/approval-gated replay │ ├── codegen.py # Approved routine -> first-class @command method │ ├── generated_commands.py # Generated mixin, loaded only after edge restart │ ├── models.py # Versioned JSON contracts │ └── store.py # Local JSON, NDJSON, screenshots, SHA-256 evidence ├── examples/functions/ # Non-executable examples └── tests/ # Desktop-free fake-backend tests ``` ## Setup GUI automation must run in the logged-in interactive Windows session that owns the vendor application. A normal Linux Docker container cannot see or control that desktop, so this edge deliberately runs bare metal. ```powershell Copy-Item .env.example .env uv sync --all-groups ``` Edit `.env` to use a narrow target: ```dotenv NATS_SERVERS=nats://127.0.0.1:4222 MACHINE_ID=gui-driver TARGET_WINDOW_TITLE_REGEX=^Instrument Control$ TARGET_PROCESS_NAME=instrument.exe GUIDRIVER_DATA_DIR=./runtime RECORD_TEXT_INPUT=false CAPTURE_SCREENSHOTS=true ``` Start the target application, focus it, then run: ```powershell uv run python main.py ``` PUDA can discover the reviewed command surface with: ```powershell puda machine commands gui-driver ``` ## Record and turn operations into functions 1. Start recording through PUDA: `start_recording(name="enter-sample")`. 2. Perform the small, atomic operation in the target application. 3. Call `stop_recording()`. 4. Call `draft_function(recording_id=..., function_name="enter_sample_id")`. 5. Open `runtime/functions/enter_sample_id.json`; replace fragile coordinates, rename redacted parameters, add state checks, and test with `dry_run=true`. 6. Approve locally only after review: ```powershell uv run guidriver --data-dir runtime validate enter_sample_id uv run guidriver --data-dir runtime approve enter_sample_id ` --reviewer "Researcher Name" --acknowledge-reviewed ``` Approval regenerates `guidriver/generated_commands.py`. Review its diff and restart the edge service. The routine then appears as a typed, first-class PUDA command. Any later JSON edit invalidates the approval hash and blocks real replay until re-review. ## Verification ```powershell uv run ruff check . uv run ruff format --check . uv run pytest -q ``` The tests use a fake backend and never click or type on the real desktop. ## Current scope The MVP supports Windows UIA window identity, screenshots/hashes, clicks, drags, scrolling, text entry, single keys, hotkeys, waits, pause/resume/cancel, and target-window state checks. The next milestones add semantic UIA selectors, OCR/template anchors, event-to-function editing UI, isolated vendor-specific profiles, richer state predicates, signed approvals, and controlled pilot validation on non-hazardous instrument workflows.