๐ŸŽฏ What this solves
The browser brain only runs while a tab is open. Close Chrome โ†’ brain stops. Re-open โ†’ brain starts from scratch (only learns from new captures going forward).

The worker fixes this:
  • Runs 24/7 on Cloudflare's edge โ€” every minute, polls Finnhub, runs capture/resolve/train, persists state in KV.
  • Historical bootstrap works โ€” no CORS limits server-side. Finnhub's /stock/candle works from the worker even though it's blocked from your browser.
  • Free tier โ€” Cloudflare Workers free plan covers everything (100k req/day, 1GB KV).
  • Browser becomes a viewer โ€” pages read state from the worker via /brain/state. Local capture continues as a fallback.
๐Ÿ“‹ One-time setup (10 minutes)

1. Get the worker code

The worker source lives in worker/ in the repo. Clone the repo locally if you haven't yet.
git clone https://github.com/Keyvaniath/bpleone-options-desk cd bpleone-options-desk/worker

2. Install Wrangler (Cloudflare's CLI)

npm install -g wrangler wrangler login # opens browser to authorize

3. Create the KV namespace

wrangler kv:namespace create BRAIN_KV # Output gives you an `id = "..."` โ€” copy that # Paste it into wrangler.toml (replace REPLACE_WITH_KV_ID_FROM_WRANGLER_OUTPUT)

4. Set secrets

wrangler secret put FINNHUB_API_KEY # (paste your Finnhub key when prompted โ€” same one you use in settings.html) wrangler secret put ADMIN_TOKEN # (make up a random long string โ€” used to trigger bootstrap)

5. Deploy

wrangler deploy # Returns a URL like: # https://bpleone-brain-worker.YOUR-SUBDOMAIN.workers.dev # Copy that URL.

6. Trigger the initial bootstrap

Pulls 250 days of Yahoo Finance daily bars across 71 symbols, computes rich features (RSI, ATR, momentum, range position, SMA distance), and trains the model for 5 epochs. Takes 30-90 seconds depending on Cloudflare plan (Pro = 30s CPU/req).
curl -X POST -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \ https://bpleone-brain-worker.YOUR-SUBDOMAIN.workers.dev/brain/bootstrap

7. Connect this browser to the worker

Paste the worker URL below and click connect. From this moment, every page reads brain state from the worker.
๐Ÿ“ก Live worker status
Connected
โ€”
Last tick
โ€”
Journal (server)
โ€”
Model n_trained
โ€”
Auto-refreshes every 15 seconds. Expected worker version: pass-201.
๐Ÿ”Œ Disconnect
Falls back to browser-only brain. Worker keeps running in Cloudflare โ€” you just stop reading from it.