{"data":{"kind":"file","path":"README.md","version_id":"ddjcaktgrjod287kflsrvm2l","entry":{"name":"README.md","path":"README.md","is_directory":false,"size":18915,"modified_at":"2026-09-09T09:57:34.920000","content_hash":"a490a49f2d51f7d9428e8ebf76d3d3983c0088fc539eb0ed96ed3837839af09e"},"entries":[],"content":"# DemoCart / Amazon Cart 001\n\n## Secured Prime live viewer — version 0.4.0 (2026-09-09)\n\nThe default environment uses the peach-header Java/XML/SQLite app, package `com.primeintellect.amazonuidemo`. A hosted model loop creates one Prime VM, boots Android, sends the model's actions to that device, and exports screenshots, recording and policy receipts before deleting the VM. The new browser viewer relays actual Android PNGs through an authenticated Prime HTTPS tunnel. During a separate UI inspection, it supports tapping, dragging, Back and typing into a focused field; during a model evaluation, every human control is disabled.\n\nThe viewer is implemented and tested offline, but no new Prime image, Android VM, tunnel URL, smoke test or evaluation has been created. The last image-build attempt received an actual `Payment required. Check billing status.` response; the account balance was read back as USD 0.00. Creating the new viewer-access secret is also awaiting explicit approval. A Hub page is code hosting, not a live Android screen. The browser-test preview uses a labeled historical PNG fixture and is not proof of live Prime rendering.\n\n| Component / file | Exact implementation | Verified or remaining boundary |\n|---|---|---|\n| `integrations/prime_env.py` | Defaults to the hosted peach adapter. Older local ADB profile requires explicit `execution=\"legacy_local_adb\"`. | Loading alone creates no VM and calls no model. |\n| `integrations/hosted_env.py` | Requires `allow_eval=true`; live-view runs also require `DEMOCART_VIEWER_TOKEN` before any billed session. Starts a read-only viewer and logs its public URL. Stops the viewer before final export and cleanup. | A true hosted model run requires `--hosted`; no local-run/upload fallback is used. |\n| `integrations/hosted_session.py` | Creates one Prime VM: 4 CPU, 8 GB RAM, 32 GB disk, 20-minute lifetime. Frames must match the episode, immutable control mode, path, size and SHA-256. Evidence export precedes VM deletion. | Actual image readiness and usable nested KVM are unverified. Timeouts are not spending caps. |\n| `harness/hosted_worker.py` | Ordered reset/step/finalize mailbox; KVM gate; fresh API-33 emulator; installed APK hash; Android screenrecord and per-action evidence. Inspection finalization is explicitly NOT_SCORED. | Manual inspection and model evaluation use separate workers and fresh app state. |\n| `harness/live_device.py` | Captures original PNGs, retains eight recent frame pairs, and checks frame identity, age and coordinate bounds before inspection input. Writes manual-input receipts without calling them model actions. | The Android worker independently rejects controls in evaluation mode. No public ADB endpoint. |\n| `integrations/live_viewer.py` | Localhost HTTP server protects image/status/control APIs with a bearer token; no-cache responses, restricted routes and content-security headers. Accounts for capture/download latency and repeated stale frames. | This is periodically refreshed imagery, not a high-frame-rate remote-desktop stream. |\n| `integrations/viewer_tunnel.py` | Uses pinned `prime-tunnel==0.1.11` and run-local private transport configuration. Returns a URL only after checking public HTTPS, unauthenticated 401 and authenticated PNG delivery. Removes its tunnel/config/access link on shutdown. | Real Prime tunnel/authentication checks have not run. HTTP/TCP sandbox exposure is not assumed available for VM sandboxes. |\n| `viewer/index.html`, `viewer.css`, `viewer.js` | Browser login, frame age, displayed-image coordinate mapping, inspection controls, evaluation read-only display and disconnected/stale warnings. URL-fragment tokens are removed from browser history and never logged. | Headless browser checks passed with an explicit OFFLINE TEST fixture. Prime evaluation-dashboard inline video rendering remains unverified. |\n| `ui_smoke.py` | Explicit `--allow-compute` guard; boots a Prime VM, opens a temporary interactive viewer for 15–300 seconds, then exports evidence and deletes the VM. | No model calls or benchmark result upload. If launched locally, the local process is only the viewer/controller; Android runs on Prime. |\n| `Dockerfile`, `.dockerignore`, `pyproject.toml` | Current app source and SDK/recording tools are included in the private image recipe. Viewer assets ship in the wheel. Source context excludes generated runs, credentials and caches. | Publishing the wheel does not build the Android runtime image. Publish with `--runtime v0` for the classic MultiTurnEnv API. |\n| `tests/test_live_viewer.py`, `tests/test_hosted_runtime.py` | Authentication, schema, read-only enforcement, freshness, episode identity, secret preflight, private-file permissions, lifecycle and packaging regressions. | Offline tests must not be counted as a Prime smoke test or model evaluation. |\n\nThe task and reward contract are unchanged: 14 policies with five registered slots each; 34 implemented and 36 explicitly unavailable slots. Policy support is `0.5 + 0.1 × PASS count`, with inclusive `>= 0.7` and an all-INVALID override. Six workflow stages are progress diagnostics, not extra rewards. Generic interaction checks and task-verifier outcomes remain separate from viewer-health checks.\n\n### First: publish code and build the runtime image\n\nFrom this environment directory, using the authenticated terrano09 personal account:\n\n```bash\nprime --plain env push --owner terrano09 --name amazon-cart-001 --runtime v0\nprime --plain env info terrano09/amazon-cart-001\nprime --plain images push democart-peach:0.4.0 --dockerfile Dockerfile --context .\nprime --plain images list\n```\n\nKeep the image private. The intended image is `prime/terrano09/democart-peach:0.4.0`; it is not yet built. Stop if billing or image construction fails. Confirm actual Ready status before creating a sandbox. Docker cannot itself supply host KVM; the worker refuses to silently use a slow CPU fallback.\n\nFor a hosted viewer, an authorized operator must configure an encrypted environment secret named `DEMOCART_VIEWER_TOKEN` containing a newly generated random URL-safe 32-byte token. A 43–128-character URL-safe shape is enforced, but arbitrary repeated characters are not a secure password. Do not put the value in source, CLI arguments, logs, environment arguments, screenshots, receipts or the model prompt. Creation of that new credential is pending user approval. The model provider key is separate and must also be available as the intended hosted secret before a model evaluation.\n\n### Next: a compute-only interactive UI smoke test\n\nAfter image readiness, funding and permission, the manual inspection command is:\n\n```bash\npython -m amazon_cart_001.ui_smoke \\\n  --allow-compute \\\n  --image prime/terrano09/democart-peach:0.4.0 \\\n  --output-dir artifacts/prime_ui_smoke \\\n  --hold-seconds 180\n```\n\nThis prints a public tunnel URL only after real Android captures and authenticated HTTPS checks succeed. The matching private access link is stored temporarily at `artifacts/prime_ui_smoke/<run_id>/.viewer-private/access.json` with mode 0600, inside a 0700 directory. Hand that link privately to the authorized viewer, or open the public URL and enter the approved access token. If no configured token is supplied to this inspection command, it generates a session-only token; it does not create a durable Hub secret. The URL is temporary and stops working after teardown. No placeholder or historical screenshot is presented as a live session.\n\nA local invocation of this inspection utility is not itself a Prime-hosted evaluation. Its Android VM and app run on Prime; its controller and browser relay run where the command was launched. The evaluation below runs the model/controller on Prime as well and always opens a new VM, so manual inspection cannot complete the task for the evaluated model.\n\n### Only after the UI smoke passes: one real hosted evaluation\n\n```bash\nprime --plain eval run terrano09/amazon-cart-001 \\\n  --hosted --follow --allow-sandbox-access --allow-tunnel-access \\\n  --model dots-studio/dots-3-note-preview:free \\\n  --api-base-url https://openrouter.ai/api/v1 \\\n  --api-key-var OPENROUTER_API_KEY \\\n  --api-client-type openai_chat_completions \\\n  --num-examples 1 --rollouts-per-example 1 --max-concurrent 1 --max-retries 0 \\\n  --timeout-minutes 120 \\\n  --env-args '{\"allow_eval\":true,\"live_viewer\":true,\"sandbox_image\":\"prime/terrano09/democart-peach:0.4.0\"}' \\\n  --eval-name democart-peach-hosted-live\n```\n\nThis is a future launch command, not a recorded run. Recheck model availability, image input support and zero-priced routing before launch; do not silently switch to a paid model. Both `OPENROUTER_API_KEY` and `DEMOCART_VIEWER_TOKEN` must be explicitly available in the hosted environment; local shell variables alone do not prove secret delivery. The sandbox/tunnel flags grant the hosted run access to those Prime APIs. The hosted timeout is separate from the adapter's 900-second rollout and 20-minute Android VM lifetime; none is a dollar cap.\n\nWatch hosted logs for `DEMOCART_LIVE_VIEWER`. Its receipt contains the public HTTPS URL and health checks, never the password. Open it and enter the separately supplied viewer token. During evaluation the page is read-only, including direct API calls: taps cannot affect the model's task. The live viewer is a separate Prime tunnel page, not a claim that Prime's evaluation metrics page embeds an interactive Android desktop.\n\n### Saved evidence and validation boundaries\n\nInitial and after-action screenshots remain original PNGs in the model conversation. Final sample info retains policy checkpoints, the recording and a hash-checked ZIP of logs/evidence. The archive limit is 100 MiB; the embedded dashboard payload limit is 25 MiB. Export/cleanup errors remain explicit INVALID pipeline outcomes and preserve any available task verdict separately. The private viewer/tunnel credentials are not part of the worker evidence archive or uploaded sample.\n\nDirectly verified: offline security/interaction tests, real browser rendering of an explicitly historical fixture, JavaScript syntax and package builds. Inferred from code: live capture and tunnel lifecycle are wired into the hosted rollout. Unverified: Prime image build, KVM boot, actual live HTTPS viewing and Prime dashboard inline screenshot/video rendering. Do not label those pending checks as passed.\n\nReferences: [Prime tunnels and hosted permissions](https://docs.primeintellect.ai/sandboxes/tunnel), [Sandbox SDK and VM exposure limits](https://docs.primeintellect.ai/sandboxes/sdk), [Hosted environment secrets](https://docs.primeintellect.ai/tutorials-environments/secrets), [Hosted evaluations](https://docs.primeintellect.ai/tutorials-environments/hosted-evaluations), [Prime Images](https://docs.primeintellect.ai/sandboxes/images).\n\n## Legacy local profile and historical implementation\n\nSearch separately for Nimbus Wireless Headphones, Trail Steel Water Bottle and Metro Laptop Backpack. Add one of each, no extras, and open the cart. The expected subtotal is INR 4,997. The app is a controlled offline Android demo, with Material Views components. Its Java app, Python action harness, evidence collection, policy verifiers and Prime adapter are packaged together.\n\nVersion 0.2.0 uses the common task layout below. The earlier ten-action, eleven-screenshot run was `scripted-ui-validation (no model)`. It remains a scripted run. This version adds a genuine OpenRouter runner, but no new model evaluation was launched during this cleanup. Generated files and historical evaluation artifacts are excluded from Git and distribution packages.\n\n## File tree\n\n```text\namazon_cart_001/\n├── pyproject.toml\n├── README.md\n├── IMPLEMENTATION_LOG.md\n├── app/shopping_android_app/\n│   ├── AndroidManifest.xml\n│   ├── build.gradle\n│   ├── settings.gradle\n│   ├── gradle.properties\n│   ├── gradlew + gradle/wrapper/\n│   ├── app/build.gradle\n│   ├── app/src/test/java/.../AppStateTest.java\n│   ├── res/\n│   └── src/.../\n│       ├── MainActivity.java\n│       ├── AppState.java\n│       ├── StateStore.java\n│       └── VerifierStateProvider.java\n├── amazon_cart_001/\n│   ├── __init__.py\n│   ├── cli.py\n│   ├── specs/\n│   │   ├── task.json\n│   │   ├── app_contract.json\n│   │   ├── policies.json\n│   │   └── scoring.json\n│   ├── harness/\n│   │   ├── actions.py\n│   │   ├── device.py\n│   │   ├── acceptance.py\n│   │   ├── episode.py\n│   │   ├── evidence.py\n│   │   └── prompts.py\n│   ├── agents/\n│   │   ├── scripted.py\n│   │   └── openrouter.py\n│   ├── verification/\n│   │   ├── contracts.py\n│   │   ├── registry.py\n│   │   ├── evidence_readers.py\n│   │   ├── generic/validity.py\n│   │   ├── generic/interaction.py\n│   │   ├── semantic.py\n│   │   ├── task_checks.py\n│   │   ├── records.py\n│   │   ├── progress.py\n│   │   └── scoring.py\n│   └── integrations/\n│       ├── prime_env.py\n│       └── prime_upload.py\n├── scripts/\n│   ├── build_apk.sh\n│   ├── start_emulator.sh\n│   ├── install_apk.sh\n│   └── run_eval.sh\n└── tests/\n    ├── test_layout_contract.py\n    ├── test_task_checks.py\n    └── test_policies.py\n```\n\nTask-specific extras are retained where real functionality exists: payment has Android instrumentation/capture tests; DemoCart has `Catalog.java`, vector product illustrations, its scripted demonstration CLI and `integrations/legacy_scripted.py` for the immutable historical scripted export. No empty matching files are manufactured.\n\n## What the files do\n\n| Files | Code responsibility | Validation or boundary |\n|---|---|---|\n| `specs/task.json` | The only task definition; its values and step budget drive the actor instruction and expected outcome. | The duplicate root task file is removed. Registry checks reject missing or incompatible configuration. |\n| `MainActivity.java`, `AppState.java`, `StateStore.java` | Render controls, validate business actions, persist state and record action acceptance. | `AppState.java` (formerly `ShoppingState.java`) handles searches, cart quantities and operation history. `Catalog.java` defines six fictional offline products. The read-only journal verifier independently replays accepted operations and compares reconstructed business state. There is no Amazon login, live listing, order, checkout or purchase. |\n| `harness/actions.py`, `acceptance.py`, `episode.py` | Validate JSON and permitted targets, execute fresh UI actions, separate tool execution from app acceptance, reject an early finish. | Malformed actions are controlled errors; the actor is not repaired or silently replaced by a script. |\n| `device.py`, `evidence.py` | Capture reset plus each action screenshot, UI tree, persisted state, read-only runtime snapshot, journal and ADB receipts. | Hashes and episode identities bind evidence; OCR is optional and cannot fabricate a missing vote. |\n| `verification/` | Evaluate 14 policies using five registered strategies each; expose reasons, evidence references and conflicting votes. | Read-only inspection; no verifier completes the task for the actor. |\n| `integrations/prime_env.py`, `prime_upload.py` | Expose the same episode through `verifiers.MultiTurnEnv`; upload an explicitly selected genuine model result with original logs/screenshots. | Loading alone starts nothing. Local KVM execution and uploaded results are not Prime-hosted compute. |\n| `pyproject.toml`, build scripts | Package the Python implementation and Android source; build the APK using pinned Gradle/Android dependencies. | SDK/JDK paths select installed tools. Cache/temp outputs default to task-local artifacts. No generated APKs, signing keys, caches or saved runs are committed. |\n\n## Exact policy and reward contract\n\nV1–V2 check specification/capability readiness and evidence integrity. G1–G4 check action format, permission, target availability and execution. S1 checks task-bound semantic selections. T1 exact three product identities; T2 quantity one each; T3 unit prices/currency; T4 three distinct search-to-add links; T5 subtotal/counter arithmetic; T6 cart review screen; T7 accepted action history.\n\nEvery verifier returns PASS = 1, INVALID = 0, FAIL = -1. A policy's support is `0.5 + 0.1 * passed_verifiers`; `>= 0.7` passes. All five INVALID returns 0; otherwise insufficient support returns -1. Two PASS votes therefore outweigh three FAIL votes. This is not 70% agreement, not a probability and not a weighted sum of stages.\n\nAny failed policy makes the episode -1; otherwise any invalid policy makes it 0; otherwise all fourteen passing gives 1. Pipeline-invalid episodes must be excluded explicitly before training normalization. Six workflow-stage indicators show progress separately from terminal reward. Evidence channels are correlated; five registrations do not imply five independent proofs. If a channel cannot establish a policy's full claim, it returns INVALID, not a guessed PASS.\n\n## Commands\n\nRun from this task directory. Keep credentials outside source files. Installing and offline tests do not start an evaluation:\n\n```bash\npython3 -m pip install -e .\npython3 -m unittest discover -s tests -p 'test_*.py'\n```\n\nFor an app build, point `ANDROID_SDK_ROOT` and `JAVA_HOME` at installed tools; `GRADLE_BIN` may point at an existing Gradle 8.9 executable. Build outputs stay in this task. Set `GRADLE_USER_HOME` and `TMPDIR` under `/data/Tirtha` when using the restricted server workspace.\n\n```bash\nbash scripts/build_apk.sh\n```\n\nAfter explicitly preparing/installing on a chosen emulator, a separately approved model evaluation can be launched with:\n\n```bash\npython3 -m amazon_cart_001.cli \\\n  --confirm-eval --serial emulator-5556 \\\n  --apk app/shopping_android_app/app/build/outputs/apk/debug/app-debug.apk \\\n  --output-dir artifacts/model --model '<approved-model-id>:free'\n```\n\nThe runner requires `OPENROUTER_API_KEY` and checks current zero-price/image-input model capability at run time. It does not authorize paid-model fallback.\n\nSaved runs contain per-action frames, trajectory and ADB logs, model request receipts, policy results, progress history, final verdict, metadata and a hash manifest. Prime uploading is a separate explicit action:\n\n```bash\npython3 -m amazon_cart_001.integrations.prime_upload --help\n```\n\nOffline test fixtures are not model evaluations. Previous live UI validation does not prove the renamed/model-enabled package has completed a new live rollout. No such rollout or new Prime upload was performed as part of this cleanup.\n","encoding":"utf-8","truncated":false,"total_bytes":18915},"status":null}