Generated from ARCHITECTURE.md · do not edit by hand

Architecture

ChopWatch is a local, mostly read-only Salad Chopping dashboard: an Express helper, a Vite/React UI, and an optional Electron tray shell. It watches what Salad is doing on this PC — lifecycle, GPU/host load, Bowl wallet lines, chopping hours (paid vs unpaid), optional electricity ROI, phase alerts — without opening customer workloads or container filesystems.

Version: product version lives in root package.json (currently 0.5.x). Repo: https://github.com/ejw427/ChopWatch · day-to-day dev · stable main

---

System overview

flowchart LR
  subgraph ui [UI layer]
    Vite["Vite React UI<br/>127.0.0.1:5177<br/>dev"]
    Electron["Electron shell<br/>window + tray"]
  end

  Helper["Helper Express API<br/>127.0.0.1:3781"]

  subgraph local [Local machine]
    SaladFiles["Salad ProgramData / AppData<br/>Bowl logs · prefs · config"]
    Nvidia["nvidia-smi + OS<br/>GPU · CPU · RAM · disk"]
  end

  SaladAPI["app-api.salad.com<br/>opt-in balance / history"]

  Vite -->|"GET /api/snapshot every 3s"| Helper
  Electron -->|"dev → :5177<br/>packaged → :3781/"| Helper
  Electron -->|"spawn helper process"| Helper
  Helper --> SaladFiles
  Helper --> Nvidia
  Helper -.->|"auth cookie when enabled"| SaladAPI
Piece Role
helper/ Express on 127.0.0.1:3781. Builds snapshots from Bowl logs, GPU/host, wallet lines, chopping-hour estimates (paid/unpaid), earning ROI, phase alerts. Optional Salad API.
web/ Vite + React on 127.0.0.1:5177 in dev. Tabs: Overview (ROI + paid/unpaid hours), Results (paid % scoreboard + dual-axis graph + readiness playbook), Details (rich sessions/timeline + local day hours), Settings ($/kWh + recommended bail), About.
desktop/ Electron shell + tray. Dev loads Vite; packaged builds spawn the helper with ELECTRON_RUN_AS_NODE and load the UI from the helper (CHOPWATCH_UI_DIR). Packaged builds can register Start with Windows (app.setLoginItemSettings, --hidden → tray).
Root concurrently runs helper + web; product version in root package.json. npm run dist builds Windows installers into release/.

---

Dev vs packaged topology

flowchart TB
  subgraph devBrowser ["npm start — browser"]
    B1[Vite :5177] -->|poll 3s| H1[Helper :3781]
  end

  subgraph devApp ["npm run app — desktop"]
    E1[Electron] -->|spawn| H2[Helper :3781]
    E1 -->|load| B2[Vite :5177]
    B2 -->|poll 3s| H2
  end

  subgraph pack ["Packaged ChopWatch.exe"]
    E2[Electron + tray] -->|ELECTRON_RUN_AS_NODE| H3[Helper in resources/helper]
    H3 -->|serves static| UI[resources/ui]
    E2 -->|load http://127.0.0.1:3781/| H3
    Data["%APPDATA%\\ChopWatch\\data<br/>settings · secrets · state"]
    H3 --> Data
  end

Packaged layout

ChopWatch.exe
resources/
  app.asar          (desktop main + preload)
  helper/           (Express API + production node_modules)
  ui/               (vite build output)
  package.json      (product version)

User data (settings, secrets, Connect browser profile) lives under Electron userData via CHOPWATCH_DATA_DIR, not next to the install.

Ports & polling

Loop Interval Where
UI snapshot poll 3s web/src/App.jsx → GET /api/snapshot
Helper phase watcher (toasts with tray-hidden UI) 5s helper/src/index.js
Thermosync ChopWatch bridge (optional) ~5s with watcher thermosyncBridge.js → 127.0.0.1:19553
Connect Salad status poll 1.5–2s while waiting Settings tab
Connect cookie sweep 1.5s, timeout 5 min saladConnect.js
Salad API cache 60s saladApi.js

---

Snapshot pipeline

helper/src/snapshot.js → buildSnapshot() aggregates machine state into one JSON payload for the UI.

flowchart TD
  A[buildSnapshot] --> B[processes.js<br/>Salad / Bowl / Bootstrapper]
  A --> C[preferences.js<br/>pause flags + prefs]
  A --> D[bowlLog.js<br/>WLInstanceState* lifecycle]
  A --> E[wallet.js<br/>Current / Predicted + heartbeat]
  A --> F[gpu.js · host.js · disk.js]
  A --> G[chopHours.js<br/>paid/unpaid · 15m gap cap]
  A --> Roi[earningRoi.js<br/>gross · power · net]
  A --> H[alerts.js<br/>phase change · 20s debounce]
  A --> Bail[downloadBail.js<br/>status only in snapshot]
  A --> I[saladApi.js<br/>opt-in account]
  A --> J[JSON → UI /api/snapshot]
Order Module Reads / does
1 processes.js tasklist for Salad*: Salad, Bowl.Service, Bootstrapper
2 preferences.js %APPDATA%\Salad\config.json flags + ProgramData prefs (allowlisted)
3 bowlLog.js %PROGRAMDATA%\Salad\logs → WLInstanceState*, SpinnerPullProgressEvent (size/speed/ETA), sessions (stop reason, event count), timeline (phase / stop reason), finding-job inference
4 wallet.js Bowl Wallet: Current(...), Predicted(...) + heartbeat age
5 gpu.js / host.js / disk.js / network.js nvidia-smi, CPU/RAM, ProgramData sizes + ext4.vhdx metadata + C: free, WSL Hyper-V NIC RX/TX (skips blockedFiles)
6 degraded.js Bowl InstallFailure / pull errors / known WRN·ERR patterns (digests stripped)
7 imageHistory.js Local opaque /sce (or salad-public) uuid sightings + paid-run counts in runtime state
8 chopHours.js Integrate active samples; paid = Running, unpaid = Pulling/setup; gaps capped 15m
9 earningRoi.js Paid % + optional net $/day from gpu.powerW × Settings electricityUsdPerKwh
10 alerts.js Snapshot reads last alert only; watcher owns phase-change / startup toasts (20s debounce)
11 downloadBail.js Snapshot status for unpaid download/init bail (auto action runs in 5s watcher)
12 saladApi.js Opt-in balance / machines / 30-day history
— thermosyncBridge.js Optional soft-fail POST of Overview gauges + phase to Thermosync ChopWatch Extra effect (19553). See THERMOSYNC_BRIDGE.md.

Key Salad paths

Path Use
C:\ProgramData\Salad\logs Bowl lifecycle + wallet lines + InstallFailure / pull signals
C:\ProgramData\Salad\wsl\ext4.vhdx File size metadata only (never mounted)
C:\ProgramData\Salad\workloads\ Folder names + path-based miner process detection
C:\ProgramData\Salad\…\preferences.txt Workload preference levels (allowlisted writes)
%APPDATA%\Salad\config.json Pause / auto-launch / overlay flags (allowlisted writes)
C:\Program Files\Salad Install presence only

---

Core workflows

Start (packaged)

sequenceDiagram
  participant User
  participant Electron
  participant Helper
  participant UI
  User->>Electron: launch ChopWatch.exe
  Electron->>Helper: spawn via ELECTRON_RUN_AS_NODE
  Electron->>Helper: poll GET /health
  Electron->>UI: load http://127.0.0.1:3781/
  loop every 3s
    UI->>Helper: GET /api/snapshot
  end
  Note over Electron: Close window → hide to tray<br/>Quit → stop helper

Connect Salad account (opt-in API)

sequenceDiagram
  participant User
  participant Settings as Settings tab
  participant API as Helper :3781
  participant Browser as Private Edge/Chrome profile
  User->>Settings: Connect Salad account
  Settings->>API: POST /api/settings/auth/connect
  API->>Browser: open salad.com/login
  loop every 1.5s up to 5 min
    API->>Browser: look for auth cookie
  end
  API->>API: write secrets.json · enable saladApi
  Settings->>API: poll connect status
  API-->>Settings: connected

Chrome/Salad lock their cookie DBs while running, so scraping them usually fails. Connect opens a private profile under …/data/salad-browser-profile/. Manual paste stays under Advanced as fallback.

Pause / resume chopping

sequenceDiagram
  participant UI as Overview
  participant API as Helper :3781
  participant Salad as AppData Salad config.json
  UI->>API: POST /api/salad/flags<br/>SALAD_CHOPPING_INDEFINITELY_PAUSED
  API->>Salad: write allowlisted flag only
  UI->>API: GET /api/snapshot
  API-->>UI: salad.choppingPaused + phase may be paused

ChopWatch does not invent Bowl Running/Pulling — those still come from Salad logs. Allowlisted writes also cover preference levels and a short list of app flags (SALAD_AUTO_LAUNCH, overlay, etc.).

Phase alerts

flowchart LR
  Watcher["Helper 5s watcher"] --> Eval["alerts.js<br/>compare lastPhase"]
  Eval --> Debounce{"changed / startup + 20s debounce?"}
  Debounce -->|yes| Store["runtime lastAlertEvent"]
  Store -->|browser / npm start| Toast[Windows NotifyIcon balloon]
  Store -->|desktop CHOPWATCH_DESKTOP=1| Tray[Electron tray.displayBalloon]
  UI["UI 3s poll"] --> Hint{"new alert.at + browser hint?"}
  Hint -->|yes| Notif[Browser Notification API]

Watcher-only evaluation (snapshot is read-only via readLastAlertEvent) so toasts do not double-fire. Desktop sets CHOPWATCH_DESKTOP=1 so the helper skips PowerShell balloons and Electron owns AFK tray tips. Startup announces Running / Downloading / Initializing / Paused / Offline once. Alertable phases also include finding and stopped.

Current task identity (what chefs can see)

Salad’s own activity indicator only exposes Finding / Downloading / Initializing / Running Job — support article. There is no chef-facing API for customer/org/job names: app-api.salad.com chef cookie auth serves profile, balance, machines, and earning history; probed /workloads, /jobs, /containers, /chopping paths return 404. SaladCloud APIs that name container groups are customer-org APIs (Salad-Api-Key), not ChopWatch’s chef cookie.

ChopWatch therefore surfaces everything that is safely available:

Signal Source Customer name?
Phase / instance short id / timers Bowl lifecycle logs (filtered scan of recent rotated files so a quiet Running isn’t buried under HTTP spam) No
Registry host + /sce/<uuid> image id SpinnerPullProgressEvent (digests never stored) No — opaque Salad tokens
Kind hint (container vs miner) Host process list (vmmemWSL, known miners + ProgramData\Salad\workloads paths) + wsl -l -v distro names/states only No
WSL NIC RX/TX Hyper-V vEthernet (WSL…) byte counters No
Disk pressure C: free space + ext4.vhdx file size No
Bowl failure signals InstallFailure / PullFailure / known WRN·ERR (digests stripped) No
Opaque image history Local sighting counts for /sce uuids No
Machine id Opt-in /api/v2/machines No

Overview’s Current task panel shows these fields and states explicitly that what problem and for whom are not available. ChopWatch still never opens WSL shells, docker inspect, or customer filesystems.

Paid vs unpaid hours & ROI

chopHours.js integrates Bowl state samples into total active time and buckets: paid = Running, unpaid = Pulling / InstallStarting / Starting (15m gap cap). Snapshot includes 24h/7d/30d paid hours + paid %, plus a 14-day series with per-day paid/unpaid/paidPct. earningRoi.js exposes paid % and optional net $/day = Bowl Predicted − (gpu.powerW × Settings electricityUsdPerKwh); while Running, power cost projects a full day at current draw. Overview shows the ROI panel and stacked hours chart; Results is the scoreboard (24h/7d paid-% rings, dual-axis 14-day chart, readiness checklist from earnPlaybook.js); Details lists sessions/timeline with paid tags and a local chopping-hours-by-day table (and overlays local hours onto official API history days when dates match).

Earn playbook (Results)

earnPlaybook.js grades live readiness: Salad up, not paused, disk free (≥ ~70 GB guideline), no GPU-busy pause, auto-bail on / matching recommended thresholds. It also emits phase tips (protect Running, Skip stuck unpaid pulls), best/worst paid-% days, session pull→Running averages, and a short daily habit list. Snapshot field: earnPlaybook. Watcher evaluateEarnAlerts can toast on low 24h paid % (default under 55% with ≥1.5h active, 2h cooldown) and on GPU-busy (20m cooldown). Settings electricity rate is user-supplied ($/kWh from the utility bill, or optional US-average preset ≈ $0.18).

Slow-download bail (re-roll unpaid pulls)

Container downloads and Initializing are unpaid until Running. When auto-bail is enabled (default), the 5s watcher calls downloadBail.js with: a grace warm-up (no auto-skip — speed often ramps), then skip only if age ≥ max, ETA stays over max ETA for a persist window (improving ETA resets the clock; download only), or progress stalled. ChopWatch writes SALAD_CHOPPING_INDEFINITELY_PAUSED=true, waits ~8s, then clears the flag. The same instance is re-rolled at most once, then left alone (~75m blackout) so we don’t dump jobs Salad keeps assigning. Settings exposes three presets — Patient, Balanced (defaults: grace 10m · max 25m · ETA 35m/persist 6m · stall 8m · cooldown 20m), and Aggressive unpaid kill (6 / 15 / 22×4 / 5 / 12) — plus manual number edits. Overview Skip download / Skip setup forces a manual re-roll even while paused.

flowchart LR
  Watcher["Helper 5s watcher"] --> Bail["downloadBail.js"]
  Bail -->|too slow| Pause["pause flag true"]
  Pause --> Hold["~8s hold"]
  Hold --> Resume["pause flag false"]
  Resume --> Finding["Salad Finding Job"]

---

Safety boundaries

ChopWatch never:

Optional Salad auth cookie lives only in helper/data/secrets.json (dev) or %APPDATA%\ChopWatch\data\secrets.json (packaged) — gitignored. Treat it like a password.

flowchart TB
  subgraph never [Never]
    N1[token.txt / ProgramData secrets]
    N2[WSL / customer containers]
    N3[Encrypted workload images]
    N4[Invented Bowl phases]
  end

  subgraph allowed [Allowlisted only]
    A1[Read Bowl logs + wallet lines]
    A2[Read nvidia-smi / OS metrics]
    A3[Write Salad pause + prefs flags]
    A4[Opt-in Salad API with local cookie]
    A5[Auto pause/resume for slow-download bail]
    A6[Host process / WSL list names only for kind hint]
    A7[WSL NIC counters · VHDX size · C: free]
    A8[Bowl failure codes · opaque /sce history]
  end

---

API surface

Route Purpose
GET /health Ready check for Electron / scripts
GET /api/snapshot Full dashboard payload
GET /api/chop-hours Chopping-hour series
GET/POST /api/settings Alerts / API toggles / download-bail thresholds / electricityUsdPerKwh / thermosyncBridgeEnabled
POST/DELETE /api/settings/auth/connect Connect Salad browser flow
GET /api/salad-account Opt-in official account summary
POST /api/salad/flags · preferences · controls Allowlisted Salad writes
POST /api/download-bail Manual skip slow download (pause→resume re-roll)

---

Data on disk

Path Contents
helper/data/settings.json (dev) or %APPDATA%\ChopWatch\data\ (packaged) Alerts / API toggles / electricity $/kWh
…/secrets.json Auth cookie (never commit)
…/runtime-state.json Last phase / alert debounce
…/salad-browser-profile/ Private browser profile for Connect

---

Release & quality

flowchart LR
  Commit[Commit on dev] --> Hook[pre-commit PATCH bump]
  Hook --> CI[CI: test · web build · docs HTML drift]
  CI --> Tag[tag v*]
  Tag --> Rel[Release workflow<br/>Windows npm run dist]
  Rel --> GH[GitHub Release<br/>NSIS + portable]
Concern Mechanism
Version SoT Root package.json; hook syncs helper/web
Tests Vitest — bowlLog, chopHours, earningRoi, wallet, alerts, logTail, version
CI main / dev: test → web build → docs:html (fail on HTML drift)
Packaging scripts/pack-desktop.ps1 → release/
Signing No paid cert. Releases publish SHA256SUMS.txt; optional free SignPath OSS when secrets exist. See SIGNING.md. CSC_IDENTITY_AUTO_DISCOVERY=false for local dist.

Edit .md only; regenerate HTML with npm run docs:html / npm run docs:view.