---
name: sprouts-grocery-sync
description: Sync Sprouts grocery orders from the last 30 days into the canonical purchase tracker ledger and yearly merchant CSV files using the authenticated automation browser profile.
---

# Sprouts Grocery Sync

## Standing Rules for All Merchant Skills

These rules are the inherited baseline for all new merchant skills derived from the Ralphs template.

### Native Input Only
- All credential and form-field entry must use native typing semantics (`CDP Input.insertText` or equivalent keystroke dispatch).
- Never use direct JS value assignment for credential entry.
- JS fill on modern React/controlled inputs is a confirmed failure mode and must be treated as prohibited for login flows.
- Shared utility for future implementations: `../shared/common_input.js`

### Credential Emission Normalization
- Before submitting any credential value retrieved from LastPass CLI or local credential helpers, normalize whitespace.
- Always strip leading/trailing whitespace and carriage returns.
- Emit only clean values to the browser interaction layer.

### Login Entry Point
- Always enter through the merchant’s order-history URL (for example `/orders`, `/mypurchases`, or the merchant equivalent), not the bare `/login` URL.
- Bare login URLs frequently render non-interactive shells with missing form controls and should be treated as a known failure mode.

### Humanization Checklist
- Every merchant skill must include a site-specific humanization section.
- Minimum baseline requirements:
  - introduce randomized delays between interactions (100–400ms baseline)
  - use native input events only
  - avoid instant sequential navigation
  - check for bot-detection signals before proceeding (CAPTCHA, challenge pages, blank/non-interactive form renders)
- Document any site-specific humanization adaptations in the merchant’s notes section.

## Sprouts Humanization
- Use native typing only for login, zip prompts, and any credential or recovery prompt.
- Introduce randomized delays between major interactions (100–400ms baseline; longer if Sprouts hydration is slow).
- Avoid back-to-back navigation and extraction actions before the page visibly hydrates.
- Check for CAPTCHA, challenge pages, zip prompt loops, and blank/non-interactive renders before proceeding.
- If Sprouts-specific anti-bot or hydration anomalies are observed, record them in `references/extraction-notes.md`.

1. Step 0: Confirm automation browser profile (`/Users/openclaw/.openclaw/browser/merchant-automation/user-data`) session is active before navigation.
2. Detect logged-out state before extraction. If logged out, retrieve credentials with `scripts/get_credential.sh sprouts.com`, normalize emitted credential values, perform login using native typing semantics only, and enable any remember-me/stay-signed-in option present.
3. Open Sprouts account/order-history via the live-discovered account surface. Current entry path starts from `https://www.sprouts.com/` → `Sign In / Register`, which routes through Sprouts SSO to `https://account.sprouts.com/account`. From there, continue into `Your Orders` / `Order History` and handle first-load zip prompt if shown.
4. Capture page snapshots at each major step (history loaded, date filter set, details expanded, final extraction).
5. Collect orders from the last 30 days; capture `order_date`, `order_id`, `fulfillment_type`, `order_total`, detail URL.
6. For each order detail page, run expand + repeated bottom scroll + load-more/pagination until no new rows appear.
7. Explicitly detect and click `Show all`/`View all items` controls before extraction.
8. Extract all visible line items and visible adjustment lines as separate rows.
9. Run strict sanity/reconciliation gate (5%): if extracted item subtotal (+ adjustments) does not reconcile with order total within 5%, mark order `partial-sync` and do **not** write that order/items/adjustments to canonical tables.
10. Record strict-gate skips in `purchase_order_exceptions` (exception lane) with retry metadata and extraction context (`route_family`, totals, delta, detail URL, artifacts).
11. Write normalized payload via `scripts/sync_to_grocery_db.py` using:
   - DB: `/Users/openclaw/outputs/purchase-tracker/purchases.db`
   - classification: `/Users/openclaw/outputs/purchase-tracker/classification.json`
   - log: `/Users/openclaw/outputs/purchase-tracker/logs/dorian_log.txt`
12. Merge yearly CSV exports with `scripts/merge_grocery_csv.py`.
13. Stop and report blocker on login failure, CAPTCHA, zip prompt loops, or unrecoverable page-design breakage.

## References
- Shared schema: `../grocery-shared/references/schema.md`
- Shared input utility: `../shared/common_input.js`
- Merchant notes: `references/extraction-notes.md`

## Completion Contract

```text
Completion Contract
Done: Sprouts sync attempted for the last 30 days and all successful outputs were written.
Findings: orders found, orders inserted, items written, adjustments written, CSV paths, and any reconciliation anomalies or exception-lane skips.
Decision needed: only if login failed, CAPTCHA appeared, zip prompt loops persisted, or extraction remained incomplete / partial-sync heavy.
Next step: recommended retry window, parser hardening target, or manual follow-up if blocked.
```
