Files
alkane-toolkit/HANDOFF.md
T
noahandClaude Opus 4.8 bd17a33ea1 GUI round 2: selection, scan loop, column management, dark-mode fix
- Fixed "Scan ranges" button label (no longer grows with the range list).
- Dark-mode KPI cards: derive colours from the live system theme luminance
  instead of is_dark(), which mis-detected some GTK dark themes.
- Removed the checkbox column; the table is multi-select (wxDV_MULTIPLE,
  ctrl/shift-click), with the selection tracked by IP so it survives refreshes.
- Replaced Rescan with Play / Pause / Stop; added an editable auto-rescan
  interval (scan-ranges dialog; ~/.config/alkane-toolkit/auto-rescan-secs.txt)
  with a timer-driven countdown scheduler.
- Status bar shows the last-probed IP during a scan and a countdown to the next
  scan when idle (dropped the "scan complete" text).
- Default sort is IP-ascending with a header chevron; IP is column 0, sortable.
- Choose-columns dialog is a wxRearrangeCtrl (check to show; up/down or drag to
  reorder) exposing every metric, including Pool 1/2/3 URL + worker.
- Column drag-reorder moves the whole column with its data on drop.
- Row separator lines (wxDV_ROW_LINES). GTK3 native has no zebra striping; a
  GTK4-forward zebra-CSS hook and pkg-config gtk cflags are in place.

Scan engine: parse each configured pool's (url, worker); Progress carries the
last-probed IP. Model: Column::Sel removed; Pool1/2/3 columns; default IP sort.

wx-rs bridge: multi-select + selection/context-menu events + get_selections,
alternating-row + zebra-CSS hooks, in-place column title, rearrangeable list,
and popup-menu primitives (for the upcoming right-click config menu). Patches
0001-0003 regenerated and round-trip validated.

Review fixes: scan loop no longer sticks "scanning" if a thread ends without
Done (channel-disconnect handling + Stop force-reset); Play no longer starts a
second scan; stale selections pruned on rescan; column apply order/visibility
applied atomically.

Verified: 22 unit tests, a 14-check headless UI self-test, and interaction
checks (multi-select, column rearrange/drag, play/pause/stop, dark mode).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-16 17:27:20 -06:00

145 lines
16 KiB
Markdown

# HANDOFF — alkane-toolkit
**For:** resuming this work in Claude Code (or any fresh agent session).
**Read order:** this file → `docs/IMPLEMENTATION-PLAN.md` → `docs/UI-SPEC.md` → `docs/adr/000{1,2,3}*.md` → `README.md`.
Parent project: `~/Ultron/projects/miner-firmware/` (its `HANDOFF.md`, `AGENTS.md` and `MEMORY-SNAPSHOT/` hold the bench context and standing orders — read them before touching real hardware).
## 1. What this repo is
`alkane-toolkit` = cross-platform desktop toolkit (pure-Rust GUI on wxWidgets)
to install **stock or alkaneOS** on ASIC miner control boards, whatever they
currently run. Sibling repo `~/Ultron/projects/miner-firmware/alkane-sdk/`
owns the board doctrine (`docs/install-methods.md` = the invariants) and the
board metadata (`boards/*/board.yml`); this toolkit mechanizes those recipes.
- Remote: `https://gitea.bluefla.re/blueflare/alkane-toolkit` (private, branch `main`, tip `b264cdd6`)
- GitHub is DEAD (account suspended): never touch github remotes; old ones are kept as `github-suspended` in sibling clones
- Gitea auth: token in `~/.config/gitea/token`, askpass helper `~/.config/gitea/askpass` (user `noah`, admin). For git: `export GIT_ASKPASS=~/.config/gitea/askpass GIT_TERMINAL_PROMPT=0`
## 2. Current state (2026-09-15)
**Ships today (M1 primary view):**
- Discovery via vendored **asic-rs 0.8.1** (MinerFactory::scan_stream over the configured CIDR list)
- UI-SPEC primary view: 6 KPIs (Total/Hashing/Slow/Not hashing/total hashrate/est. power), scan-ranges editor, Excel-style filter panel, columns panel, sortable + drag-reorderable table with row checkboxes, IP pinned first, default order hashrate → power → chip temp → cooling → firmware → pool worker → model/status
- Pure-Rust GUI on wxWidgets: vendored wx-rs 0.2.0 **extended by patches** (upstream stubs Linux and had no widgets) + vendored wxWidgets 3.3.3 (static monolithic GTK3)
- **Visually verified working** (off-screen Xvfb screenshots): table renders below the header full-width; all dialogs (Scan ranges / Filter / Columns) open, apply, and close without crashing; header-click sort, column hide, and row-checkbox all work.
**Fixed 2026-09-15 (this session), with regression tests:**
- **Table rendered in the top-left corner** instead of below the header: the dvlc was created but never added to the sizer. `rebuild_table` now adds it to the root sizer (proportion 1, EXPAND) and re-runs the panel layout; `add_stretch(1)` (which ate all vertical space) removed.
- **App crashed (abort) on most buttons**: the dialog `root` sizers passed `ALIGN_CENTRE_VERTICAL` to a *vertical* sizer, tripping a wxWidgets consistency assert whose default handler pumps a nested event loop; the 1 s scan timer then re-entered the single `dispatch` while it still held the `App` `RefCell` borrow → `RefCell already borrowed` → non-unwinding panic → abort. Fixed the invalid flags, and hardened `dispatch` into two phases (build under the borrow, `show_modal` outside it) with `try_borrow_mut` so any future nested re-entry drops the event instead of aborting.
- Header-click sort mapped the clicked column through `view.order` (wrong when a column was hidden) → now maps through `display_columns()`. Drag-reorder likewise (`ViewState::apply_visible_reorder`, splices visible order back into the full order so hidden columns are never dropped). Row-selection checkbox now survives a table refresh.
**Feature round 2026-09-15 (operator requests, verified by live bench scan + selftest):**
- Redesigned KPI header: colour-coded cards (green Hashing / amber Slow / red Not hashing / blue Hashrate), big value over small label, theme-aware.
- Light/dark mode follows the system (wxSystemSettings + `set_appearance_system`); custom KPI colours adapt.
- SI-formatted hashrate/power everywhere (KPIs + columns): prefix chosen so the mantissa is 1-999, 1 decimal below 100 (e.g. `685 TH/s`, `21.3 kW`, `95.0 TH/s`). Note: strict "<=2 digits" would render 685 TH/s as `0.7 PH/s`; the 3-sig-fig form reads better - flag if you want the strict form.
- Scan ranges accept CIDR, single IP, `A.B.C.D-E.F.G.H` full ranges, and `A.B.C.D-N` short ranges (`scan::parse_line`).
- Scan progress bar across the top of the table + status-bar text (`scan_stream_with_ip` gives per-address progress); the inline "scan done" text is gone.
- Out-of-range miners are dropped when a scan starts (rows retained by the new target set).
- Columns panel exposes **every** scannable `MinerData` metric (~30, model.rs `Column`), with All / None / Defaults.
- Excel-style filter panel built out: per-category value checklists (numeric columns excluded), per-column All/None, Apply/Reset/Cancel, "(blank)" handling.
- Sort direction shown as an ASCII marker in the header (`^`/`v`); native `SetSortOrder` was rejected because it re-sorts the store lexically and fought the numeric sort.
- Double-click a row opens `http://<ip>` in the default browser (`wxLaunchDefaultBrowser`).
- Filter panel horizontal layout can get wide with many category columns (no scrolled-window in the bridge yet); it is resizable. Live text-search within a filter column is not implemented.
**Feature round 2 (2026-09-16, operator requests):**
- Scan-ranges button is a fixed "Scan ranges" label (no longer grows with the ranges).
- Dark-mode KPI cards fixed: colours derive from the live system theme luminance (`palette()` reads `system_color`), not `is_dark()` which mis-detected some GTK dark themes.
- Checkbox column removed; the table is multi-select (`wxDV_MULTIPLE`, ctrl/shift-click), selection tracked by IP so it survives scan refreshes.
- Rescan replaced by Play / Pause / Stop; auto-rescan interval editable in the scan-ranges dialog (`scan::load/save_auto_secs`, `~/.config/alkane-toolkit/auto-rescan-secs.txt`). Timer-driven scheduler with a countdown.
- Status bar shows the last-probed IP during a scan and a countdown to the next scan when idle (no more "scan complete" text).
- Default sort is IP-ascending with a header chevron; IP is column 0 and sortable.
- Choose-columns dialog is a `wxRearrangeCtrl` (check to show, up/down or drag to reorder); exposes every metric incl. Pool 1/2/3 URL + worker (`MinerRow.pools`).
- Column drag-reorder in the table moves the whole column with its data on drop (native GTK shows only the header ghost during the drag - not changeable without a custom-drawn table).
- Row separation: `wxDV_ROW_LINES` (thin separators). GTK3's native dataview has no zebra striping (SetAlternateRowColour is generic-only; `:nth-child` CSS is GTK4-only). A `wxbr_apply_zebra_css` hook is in place for GTK4; true zebra on GTK3 needs a custom `wxDataViewVirtualListModel` with `GetAttrByRow` - deferred.
- `build.rs` now adds `pkg-config --cflags gtk+-3.0` so the bridge can call GTK directly.
**Deferred - item 11 (right-click multi-config menu):** intersection-of-config context menu that writes to live miners via asic-rs `HasMinerControl`/`SupportsConfigs` (fault light, power limit, tuning, restart, pause/resume, pool config). The wx bridge for it (popup menu + context-menu event) is already in place; the apply-to-live-hardware layer + confirm-before-apply is the next round.
**Dev / review / visual-feedback loop (see AGENTS.md):**
- `scripts/ui-selftest.sh` — headless workflow self-test: `ALKANE_SELFTEST` mode renders the bench-fleet fixtures through the real widgets and compares the table cells + KPIs to the expected hardware output (13 checks; exit non-zero on any mismatch). `cargo test -p alkane-gui` runs the transform-layer unit tests (10).
- `scripts/ui-screenshot.sh [out.png] [--live]` — off-screen (private Xvfb) screenshot for visual review; defaults to the offline `ALKANE_FAKE_SCAN` fixtures.
- Offline modes: `ALKANE_FAKE_SCAN=1` feeds `crates/alkane-gui/src/fixtures.rs` (the 9 bench boards) instead of scanning; `ALKANE_SELFTEST=1` runs the self-test and exits.
- Headless X gotcha: the GTK window only maps under Xvfb with `GDK_BACKEND=x11` set (the scripts do this).
**Not done yet (open threads, in rough priority):**
1. Windows + macOS builds — `scripts/build-gui-{windows,macos}.sh` exist; Windows needs msys2/MSVC (wx-rs build.rs handles msys2 paths natively), macOS needs a Mac to link. Consider a gitea Actions CI runner. No CI config exists at all yet.
2. ARP/ICMP pre-pass for link-up-but-silent boards (M1 scope, spec'd in plan §5, not implemented)
3. Column order/visibility *persistence* to `ui.conf` (spec'd in UI-SPEC "Implementation notes"). Visibility (Columns dialog) and drag-reorder both work in-session; only the save/restore across runs is missing.
4. Sort-direction indicator in headers; per-model "Slow" bands (currently flat 80% of expected); model-derived power estimates for units that don't report wattage
5. M2: verify-image port (magic/min-size/integrity) + artifact registry expansion (`crates/alkane-artifacts/data/manifest-seed.csv` = 14 sha256'd bench artifacts; bulk archives 3.7GB/624MB not hashed)
6. M3+: first install pathway (zynq-7010 stock↔stock, proven on the bench S17), then per plan §7. Note **no alkaneOS build exists** (SDK boards all "bake"), so installs are stock↔stock only until the SDK produces artifacts.
## 3. How to build / run (this machine)
```sh
cd ~/Ultron/projects/miner-firmware/alkane-toolkit
scripts/build-wx-linux.sh # once: wx 3.3.3 → ~/.cache/wx-3.3.3-linux (out-of-tree)
scripts/build-gui-linux.sh # release build (needs WX_RS_WXCONFIG, script sets it)
/usr/local/bin/alkane-toolkit # installed binary; or ~/.cache/alkane-tk-target/release/alkane-toolkit
```
Needs a display (user's desktop session has DISPLAY=:0). Headless smoke test:
`timeout 15 xvfb-run -a /usr/local/bin/alkane-toolkit` — rc 124 = ran until killed (good), rc 139 = crash.
## 4. Machine quirks (these cost hours — don't re-learn them)
- **The synced project mount is noexec** for newly-written files: never build or execute anything inside the repo tree. wx builds go to `~/.cache/wxbuild`, cargo target to `~/.cache/alkane-tk-target` (set machine-locally via `~/.cargo/config.toml`, NOT committed).
- **`cargo vendor vendor` DELETES unmanaged directories under vendor/**. Hand-made trees live in `thirdparty/` (wxwidgets, wx-rs). Only cargo-managed crate sources are in `vendor/` (341 crates; offline builds via committed `.cargo/config.toml`).
- **/tmp tmpfs is 100% full** (bench artifacts live there — do not clean). Build outputs must not go to /tmp.
- The FS is very slow for many-file operations: `git add` of thirdparty/wxwidgets (~10k files) takes ~20 min; extraction of the wx tarball will blow a 120 s timeout. Run big FS operations as background jobs and poll.
- sudo: `sudo -S -p '' <cmd> < ~/.sudopass` (non-interactive).
- Rust 1.97.1, cargo, gdb, xvfb-run, mingw-w64, gtk3 dev, pcre2 dev all installed.
## 5. Architecture map
```
crates/
alkane-core/ domain types (stub — next milestone fills it)
alkane-discovery/ asic-rs dependency wired (engine lives in alkane-gui/scan.rs today)
alkane-access/ stub (SSH/foothold layer, M3+)
alkane-flash/ stub (write/verify engines, M3+)
alkane-artifacts/ manifest-seed.csv (14 artifacts w/ sha256)
alkane-cli/ stub bin
alkane-gui/ THE APP (bin "alkane-toolkit"): main.rs, model.rs, scan.rs, ui.rs
thirdparty/
wxwidgets/wxWidgets-3.3.3/ pristine dist tarball tree (+ VERSION sha256, patches/ empty)
wx-rs/wx-rs-0.2.0-patched/ the used crate (path dep) + VERSION + patches/:
0001 linux/GTK3 wx-config build path (build.rs; handles full-path .a in --libs!)
0002 Rust widget bindings (src/widgets.rs: Widget API + single event dispatcher)
0003 C++ widget bridge (cpp_src/widgets_bridge.cpp: panel/sizers/static text/
button/textctrl/checkbox/checklistbox/dialog/dvlc/timer/destroy)
0004 upstream fixes (Linux get_client_size branch; init render/handle_events —
upstream left them UNINITIALIZED: 5ms render timer calls garbage in release)
vendor/ cargo-managed ONLY (341 crates, offline)
scripts/ build-wx-linux.sh, build-gui-{linux,windows,macos}.sh
docs/ IMPLEMENTATION-PLAN.md, UI-SPEC.md, adr/0001-0003
```
Key implementation facts (don't re-derive):
- **Event model**: ONE C callback (`wxbr_set_widget_event_fn`) → Rust `set_event_handler(Handler)`; all events funnel through `ui::dispatch` (thread_local APP). Event kinds: ButtonClicked(id), DvlcValueChanged(row,col), DvlcHeaderClick(col), DvlcReordered, TimerTick(id).
- **Table semantics**: `view.order` = creation order = display order; toggle col is creation idx 0 (bool variants only); `dvlc_col_at_pos()` maps display→creation after a drag; store rows are appended in filtered+sorted view order, so store row == `view_idx[row]`. Header click sort cycles asc→desc→off and refills.
- **Scan thread**: std thread + own tokio runtime + std mpsc; a 1 s wx Timer drains it (`App::drain_scan`). Ranges: `~/.config/alkane-toolkit/scan-ranges.txt` (default 10.255.1.0/24), parse via `scan::parse_cidr`.
- **asic-rs API**: `MinerFactory::from_subnet("a.b.c.d/p")`, `.scan_stream()` → `Stream<Item=Box<dyn Miner>>`; `Miner::get_data().await -> MinerData` (trait at `asic_rs::core::traits::miner::Miner`); `HashRate.clone().as_unit(HashRateUnit::TeraHash).value`; `Power::as_watts()`, `Temperature::as_celsius()`, `AngularVelocity::as_rpm()`; pools: `MinerData.pools[].pools[]` with `.user/.active`.
- **wx 3.3 API gotchas hit**: `store->GetValueByRow(v,row,col)` (not GetValue), `GetColumnPosition()` (no GetColumnAt), `--enable-dataview` doesn't exist, `--disable-stc --without-catch2 --disable-tests` needed only if using the GitHub source export (the dist tarball in thirdparty/ is complete — just chmod +x configure).
## 6. Verification evidence
- `cargo build --workspace --offline` clean (network-independent; all sources vendored)
- `cargo test -p alkane-gui --offline`: 10 transform-layer unit tests pass (KPIs, sort, filter, cell formatting, slow band, hidden-column mapping, drag-reorder splice, selection-survives-upsert).
- `scripts/ui-selftest.sh`: 13/13 checks pass end-to-end through the real widgets (KPI labels, row count, every cell matches the model, slow/not-hashing spot checks, IP is first text column).
- Visual review via `scripts/ui-screenshot.sh` (off-screen Xvfb): confirmed the table renders below the header, and drove every button with xdotool (open/apply/cancel each dialog, header sort, column hide, row check) with zero crashes/panics.
- Git: previous tip `b264cdd6` pushed to gitea (gitea repo `size` field updates lazily — that commit has 16k files/4.9M insertions incl. the wx tree).
- Still open: eyeball on the **real bench fleet** (`--live`). The visual + interaction checks above used the offline fixtures; a live run against the 9 boards on 10.255.1.0/24 is the remaining confidence step.
## 7. Bench fleet context (for the scan you'll see)
9 boards live on 10.255.1.0/24: S17 stock (.112, root+EMPTY password, legacy SSH algos), S19 xil OurOS (.166), S19j Pro bb OurOS (.152), S19k Pro cv OurOS (.167), S21 Pro aml stock (.149), WhatsMiner H3 (.126), H616 (.131), M50 CB4 (.148 — random MAC, address moves), WardenOS dev (.115). Scanning is read-only and routine; the `live-fleet-ops` rules (no auth bursts, gentle on prod 10.2.1.0/24) are standing orders in AGENTS.md. Never install/flash anything without the operator explicitly asking.
## 8. Conventions for this repo
- Confidence tags (CONFIRMED/DERIVED/EXTERNAL) on claims in docs; cite file paths.
- Commit style so far: single-line imperative summaries, no sign-off noise.
- Repo-level rules now live in `AGENTS.md` (dev/review/visual loop, offline modes, build discipline). Keep it short.
- When you change the vendored wx-rs: edit `thirdparty/wx-rs/wx-rs-0.2.0-patched/`, regenerate the matching `patches/NNNN-*.patch` via `diff -u` against the pristine crate (tarball URL+sha in `thirdparty/wx-rs/VERSION`), and confirm the patch set reconstructs the patched tree before committing both.