os: editable main dashboard + full settings tabs (drivers/services/monitor)

Make the main dashboard an editable deck, like wardenOS's dashboard, and split
the remaining settings into their own tabs.

- console.rs: dashboard/overview is now an editable deck - a .wdash-style
  document stored on the box (bus dashboard/* verbs behind /api/dashboard) whose
  blocks draw live values from the open miner-state API. A self-contained island
  (CSS + JS in the flare-ui shell) renders the grid and, in edit mode, adds,
  removes, reorders and saves blocks; Reset restores the template. Drivers,
  Services and Monitor are now distinct settings tabs rather than bundled into
  System/Security.
- schema/alkane-bb.json: add the settings/drivers, settings/services and
  settings/monitor menus so the nav shows them (settings now has 11 tabs).
- service.rs: the deck directory falls back to a writable path off the miner so
  the editable dashboard saves in a dev run too.

Verified on --serve-sim: the dashboard renders with an Edit toolbar, a deck
saves and reloads from /api/dashboard and Reset restores the 5-block template,
and every settings tab (system/tuning/pools/network/drivers/security/services/
monitor/logs/files/terminal) answers. 203 tests pass, clippy -D warnings clean,
no emojis.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BdKQBPjAXpCwmigUov5eQk
This commit is contained in:
2026-11-10 21:18:18 -06:00
co-authored by Claude Opus 4.8
parent e036d99f02
commit 34bccbd437
5 changed files with 137 additions and 40 deletions
+21
View File
@@ -111,6 +111,27 @@
"order": 60,
"page": "settings.logs"
},
{
"id": "settings/drivers",
"slug": "drivers",
"title": "Drivers",
"order": 50,
"page": "settings.drivers"
},
{
"id": "settings/services",
"slug": "services",
"title": "Services",
"order": 70,
"page": "settings.services"
},
{
"id": "settings/monitor",
"slug": "monitor",
"title": "Monitor",
"order": 80,
"page": "settings.monitor"
},
{
"id": "settings/files",
"slug": "files",
+96 -37
View File
@@ -42,17 +42,20 @@ pub fn page(
let hw = bus.read_state_or(topics::HARDWARE, serde_json::json!({"available": false}));
let ctl = bus.read_state_or(topics::CONTROL, serde_json::json!({"running": false}));
let body = match (section, tab) {
("dashboard", "overview") | ("", "") => overview_card(&hw, &ctl),
("dashboard", "overview") | ("", "") => editable_dashboard(),
("dashboard", "alerts") => alerts_card(&hw),
("mining", "overview") => control_card(&hw, &ctl, csrf),
("mining", "hashboards") => hashboards_card(&hw),
("mining", "power") => power_card(&hw),
("mining", "fans") => fans_card(&hw),
("settings", "system") => system_card(&hw),
("settings", "system") => system_card(),
("settings", "tuning") => tuning_card(&dash, &ctl, csrf, errors),
("settings", "pools") => pools_card(),
("settings", "network") => network_card(),
("settings", "security") => security_card(&hw),
("settings", "drivers") => drivers_card(&hw),
("settings", "security") => security_card(),
("settings", "services") => services_card(),
("settings", "monitor") => monitor_card(&hw),
("settings", "logs") => logs_card(),
("settings", "files") => files_card(),
("settings", "terminal") => terminal_card(),
@@ -137,10 +140,6 @@ fn text(doc: &Value, pointer: &str, fallback: &str) -> String {
doc.pointer(pointer).and_then(Value::as_str).unwrap_or(fallback).to_string()
}
fn available(hw: &Value) -> bool {
hw.get("available").and_then(Value::as_bool).unwrap_or(false)
}
fn active_chain_count(hw: &Value) -> usize {
hw.get("active_chains").and_then(Value::as_array).map(|a| a.len()).unwrap_or(0)
}
@@ -159,31 +158,85 @@ fn run_state(hw: &Value, ctl: &Value) -> (Level, String) {
// --- cards -------------------------------------------------------------------
fn overview_card(hw: &Value, ctl: &Value) -> Markup {
let freq = reading("frequency_mhz", "Chain frequency", num(hw, "/frequency_mhz"), "MHz", 0);
let (level, state) = run_state(hw, ctl);
let run = reading("run", "State", None, "", 0);
components::card(
"Overview",
/// The main dashboard: an editable deck, like wardenOS's dashboard. The layout
/// is a `.wdash`-style document stored on the box (bus `dashboard/*` verbs behind
/// `/api/dashboard`); blocks draw live values from the open miner-state API. In
/// edit mode the operator can add, remove, reorder and save blocks.
fn editable_dashboard() -> Markup {
html! {
@if available(hw) {
(readings::hero(&freq))
(readings::status(&run, level, &state))
(readings::plate(&[
("Profile".into(), text(hw, "/profile", "unknown")),
("Chip".into(), text(hw, "/chip", "unknown")),
("Power supply".into(), text(hw, "/psu", "not identified")),
("Mode".into(), text(ctl, "/mode_label", "-")),
("Target".into(), text(hw, "/target", "-")),
("Active chains".into(), active_chain_count(hw).to_string()),
]))
} @else {
(readings::note("No backend is attached. Run the miner (or alkane-os --serve-sim on a workstation) to populate this page."))
(PreEscaped(DECK_CSS))
div class="bf-card" {
div class="akd-bar" {
button id="akd-edit" class="bf-btn bf-text-button" type="button" { "Edit" }
button id="akd-add" class="bf-btn bf-text-button" type="button" hidden { "Add block" }
button id="akd-save" class="bf-btn bf-btn-primary bf-text-button" type="button" hidden { "Save" }
button id="akd-reset" class="bf-btn bf-btn-danger bf-text-button" type="button" hidden { "Reset to template" }
span id="akd-msg" class="bf-text-body-sm" {}
}
div id="akd-grid" class="akd-grid" {}
}
(PreEscaped(DECK_JS))
}
},
)
}
const DECK_CSS: &str = "<style>\
.akd-bar{display:flex;gap:8px;align-items:center;margin-bottom:12px;flex-wrap:wrap}\
.akd-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px}\
.akd-card{border:1px solid var(--border,#192858);border-radius:8px;padding:12px;background:rgba(255,255,255,.03);min-width:0}\
.akd-card h3{margin:0 0 6px;font-size:13px;font-weight:600;opacity:.8}\
.akd-big{font-size:28px;font-weight:700;line-height:1.1;word-break:break-word}\
.akd-unit{opacity:.7;font-size:13px;margin-left:4px}\
.akd-s1{grid-column:span 1}.akd-s2{grid-column:span 2}.akd-s3{grid-column:span 3}.akd-s4{grid-column:span 4}\
.akd-card table{width:100%;border-collapse:collapse;font-size:12px}.akd-card td,.akd-card th{text-align:left;padding:2px 4px}\
.akd-card.drag{opacity:.5}.akd-rm{float:right;cursor:pointer;opacity:.6}\
.akd-dim{opacity:.5}\
@media(max-width:720px){.akd-grid{grid-template-columns:1fr}.akd-s2,.akd-s3,.akd-s4{grid-column:span 1}}\
</style>";
const DECK_JS: &str = "<script>(function(){\
var DECK='dashboard',doc=null,edit=false,drag=null;\
function $(i){return document.getElementById(i)}\
function esc(s){return String(s).replace(/[&<>\"']/g,function(c){return{'&':'&amp;','<':'&lt;','>':'&gt;','\"':'&quot;',\"'\":'&#39;'}[c]})}\
function msg(t){var e=$('akd-msg');if(e)e.textContent=t}\
var grid=$('akd-grid');\
function render(){grid.innerHTML='';(doc.blocks||[]).forEach(function(b){\
var c=document.createElement('div');c.className='akd-card akd-s'+(b.span||1);c.draggable=edit;\
c.addEventListener('dragstart',function(){drag=b.id;c.classList.add('drag')});\
c.addEventListener('dragend',function(){c.classList.remove('drag')});\
c.addEventListener('dragover',function(e){if(edit)e.preventDefault()});\
c.addEventListener('drop',function(e){e.preventDefault();if(!drag||drag===b.id)return;\
var f=doc.blocks.findIndex(function(x){return x.id===drag}),t=doc.blocks.findIndex(function(x){return x.id===b.id});\
if(f<0||t<0)return;var m=doc.blocks.splice(f,1)[0];doc.blocks.splice(t,0,m);render();msg('unsaved changes')});\
var h=document.createElement('h3');h.textContent=b.title||b.id;\
if(edit){var x=document.createElement('span');x.className='akd-rm';x.textContent='x';x.title='remove';\
x.onclick=function(){doc.blocks=doc.blocks.filter(function(y){return y.id!==b.id});render();msg('unsaved changes')};h.appendChild(x)}\
c.appendChild(h);\
if(b.kind==='metric'||b.kind==='status'){var big=document.createElement('div');big.className='akd-big';big.dataset.source=b.source||'';big.textContent='--';\
if(b.unit){var u=document.createElement('span');u.className='akd-unit';u.textContent=b.unit;big.appendChild(u)}c.appendChild(big)}\
else if(b.kind==='table'){var tb=document.createElement('table');tb.dataset[b.source==='fans'?'fans':'table']=b.source||'';tb.innerHTML='<tbody><tr><td class=akd-dim>loading</td></tr></tbody>';c.appendChild(tb)}\
else{var p=document.createElement('div');p.className='akd-dim';p.dataset.kv=b.source||'';p.textContent='loading';c.appendChild(p)}\
grid.appendChild(c)})}\
function fill(){var hw=null,sm=null;function paint(){if(!hw||!sm)return;var s=(sm.SUMMARY||[{}])[0];\
var src={status:s.Status||'unknown',accepted:s.Accepted||0,rejected:s.Rejected||0,elapsed:s.Elapsed||0,\
active_chains:(hw.active_chains||[]).length,frequency:hw.frequency_mhz||0,voltage:(hw.operating_point||{}).voltage_mv||0,target:hw.target||'-'};\
document.querySelectorAll('[data-source]').forEach(function(el){var v=src[el.dataset.source];var u=el.querySelector('.akd-unit');\
el.childNodes[0]&&(el.childNodes[0].nodeValue=(v===undefined||v===null)?'n/a':String(v));if(u)el.appendChild(u)});\
document.querySelectorAll('[data-table]').forEach(function(t){var rows=(hw.chains||[]).map(function(c){return[c.index,c.chip,c.chips_found,c.response_per_mille]});\
t.innerHTML=rows.length?'<thead><tr><th>#</th><th>chip</th><th>chips</th><th>resp</th></tr></thead><tbody>'+rows.map(function(r){return '<tr>'+r.map(function(c){return '<td>'+esc(c)+'</td>'}).join('')+'</tr>'}).join('')+'</tbody>':'<tbody><tr><td class=akd-dim>no chains</td></tr></tbody>'});\
document.querySelectorAll('[data-kv]').forEach(function(el){var rows=[['profile',hw.profile||'-'],['chip',hw.chip||'-'],['psu',hw.psu||'-'],['target',hw.target||'-'],['stopped',hw.stopped?hw.stopped:'no']];\
el.innerHTML=rows.map(function(r){return '<div><span class=akd-dim>'+esc(r[0])+'</span> '+esc(r[1])+'</div>'}).join('')});\
document.querySelectorAll('[data-fans]').forEach(function(t){var rows=(hw.fan_zones||[]).map(function(z){return[z.fan,(z.zones||[]).join(', ')]});\
t.innerHTML=rows.length?'<thead><tr><th>fan</th><th>zones</th></tr></thead><tbody>'+rows.map(function(r){return '<tr><td>'+esc(r[0])+'</td><td>'+esc(r[1])+'</td></tr>'}).join('')+'</tbody>':'<tbody><tr><td class=akd-dim>not mapped</td></tr></tbody>'})}\
fetch('/api/hardware').then(function(r){return r.json()}).then(function(h){hw=h;paint()}).catch(function(){});\
fetch('/api/summary').then(function(r){return r.json()}).then(function(x){sm=x;paint()}).catch(function(){})}\
function setEdit(on){edit=on;['akd-add','akd-save','akd-reset'].forEach(function(i){$(i).hidden=!on});$('akd-edit').textContent=on?'Done':'Edit';render()}\
$('akd-edit').onclick=function(){setEdit(!edit)};\
$('akd-add').onclick=function(){if(doc.blocks.length>=32){msg('32 block limit');return}doc.blocks.push({id:'block'+(doc.blocks.length+1),kind:'metric',span:1,title:'New block',source:'power_w',unit:'W'});render();msg('unsaved changes')};\
$('akd-save').onclick=function(){fetch('/api/dashboard?deck='+DECK,{method:'PUT',headers:{'Content-Type':'application/json'},body:JSON.stringify(doc)}).then(function(r){return r.ok?r.json().then(function(d){doc=d;msg('saved')}):r.text().then(msg)})};\
$('akd-reset').onclick=function(){fetch('/api/dashboard?deck='+DECK+'&reset=1',{method:'PUT',headers:{'Content-Type':'application/json'},body:'{}'}).then(function(r){return r.json()}).then(function(d){doc=d;render();fill();msg('template restored')})};\
fetch('/api/dashboard?deck='+DECK).then(function(r){return r.json()}).then(function(d){doc=d;render();fill();setInterval(fill,5000)});\
})();</script>";
fn alerts_card(hw: &Value) -> Markup {
let stopped = hw.get("stopped").and_then(Value::as_str);
let run = reading("alert", "Supervisor", None, "", 0);
@@ -316,12 +369,10 @@ fn plate_from(rows: Vec<(&str, String)>) -> Markup {
readings::plate(&items)
}
fn system_card(hw: &Value) -> Markup {
fn system_card() -> Markup {
html! {
(components::card("Identity", plate_from(web::system_rows())))
(components::card("Network", plate_from(web::network_rows())))
(components::card("Updates", plate_from(web::update_rows())))
(components::card("Drivers", plate_from(web::driver_rows(hw))))
}
}
@@ -329,12 +380,20 @@ fn network_card() -> Markup {
components::card("Network", plate_from(web::network_rows()))
}
fn security_card(hw: &Value) -> Markup {
html! {
(components::card("Security", plate_from(web::security_rows())))
(components::card("Services", readings::table(&["service", "running"], &web::service_rows())))
(components::card("Monitor", plate_from(web::monitor_rows(hw))))
}
fn drivers_card(hw: &Value) -> Markup {
components::card("Drivers", plate_from(web::driver_rows(hw)))
}
fn security_card() -> Markup {
components::card("Security", plate_from(web::security_rows()))
}
fn services_card() -> Markup {
components::card("Services", readings::table(&["service", "running"], &web::service_rows()))
}
fn monitor_card(hw: &Value) -> Markup {
components::card("Monitor", plate_from(web::monitor_rows(hw)))
}
fn logs_card() -> Markup {
+4 -1
View File
@@ -284,11 +284,14 @@ mod tests {
fn the_schema_loads_and_yields_the_three_sections() {
let dash = Dashboard::load(temp_path("load"));
let effective = dash.schema().expect("schema loads");
assert_eq!(effective.doc.menus.len(), 17);
assert_eq!(effective.doc.menus.len(), 20);
let nav = dash.nav().expect("nav builds");
assert_eq!(nav.sections.len(), 3);
assert_eq!(nav.sections[1].slug, "mining");
assert_eq!(nav.sections[1].tabs.len(), 4);
// Settings now carries the full tab set including drivers/services/monitor.
assert_eq!(nav.sections[2].slug, "settings");
assert_eq!(nav.sections[2].tabs.len(), 11);
}
#[test]
+11 -1
View File
@@ -30,12 +30,22 @@ pub(crate) fn settings_path() -> PathBuf {
std::env::temp_dir().join("alkane-settings.json")
}
/// The deck directory: the on-box `/var/lib/alkane/decks` when it exists or can
/// be created (root on the miner), else a writable fallback for a dev run.
fn deck_dir() -> PathBuf {
let dir = Path::new(DECK_DIR);
if dir.is_dir() || fs::create_dir_all(dir).is_ok() {
return dir.to_path_buf();
}
std::env::temp_dir().join("alkane-decks")
}
fn deck_path(deck: &str) -> PathBuf {
let safe: String = deck
.chars()
.filter(|c| c.is_ascii_alphanumeric() || *c == '-' || *c == '_')
.collect();
Path::new(DECK_DIR).join(format!("{safe}.json"))
deck_dir().join(format!("{safe}.json"))
}
pub(crate) fn load_deck(deck: &str) -> Value {
+4
View File
@@ -931,7 +931,11 @@ mod tests {
"/mining/fans",
"/settings/system",
"/settings/tuning",
"/settings/network",
"/settings/drivers",
"/settings/security",
"/settings/services",
"/settings/monitor",
"/settings/logs",
"/settings/files",
"/settings/terminal",