---
name: amazon-grocery-sync
description: Sync Amazon grocery orders (Amazon Fresh, Whole Foods Market, Amazon Grocery) into the canonical purchase tracker ledger and yearly merchant CSV files using the authenticated user browser profile.
---

# Amazon Grocery Sync

1. Step 0: Confirm `user` browser profile/session is active before navigation.
2. Open Amazon order history and default first-run window to last 90 days; support date-range parameter overrides for catch-up runs.
3. Capture page snapshots at each major step.
4. Collect grocery orders only; capture `order_date`, `order_id`, `merchant`, `fulfillment_type`, `order_total`, detail URL.
5. For each detail page, run expand + repeated bottom scroll + load-more/pagination until no new items appear.
6. Explicitly detect and click `Show all`/`View all items` controls before extraction.
7. Extract all visible line items and adjustment lines separately.
8. Apply `classification.json` expense rules to flag Triune/business items at line-item level.
9. Run sanity-check: compare extracted item + adjustment totals against order total and flag when delta exceeds 5%.
10. Write normalized payload via `scripts/sync_to_grocery_db.py` using canonical DB/classification/log paths.
11. Merge yearly CSV exports with `scripts/merge_grocery_csv.py`.
12. Stop and report blocker on login failure, CAPTCHA, or unrecoverable page-design breakage.

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