mindX / app.js
Gregory-L's picture
more ways home: top bar, Visit me at mindx.pythai.net, source link on every tile, links open in a new tab
1c6b0f9 verified
Raw History Blame Contribute Delete
18.8 kB
// mindX public Space: render the baked snapshot, then read the node live, gently.
// The node is a 2-vCPU box that is usually training, so reads run one at a time,
// every five minutes, only while the tab is visible. All remote text goes through
// textContent; nothing from the network is ever parsed as HTML.
(function () {
'use strict';
var BASE = 'https://mindx.pythai.net';
var EVERY_MS = 5 * 60 * 1000;
var READS = [
['health', '/health', 30000],
['machine', '/insight/godel/machine', 60000],
['feedback', '/insight/autonomous/feedback', 60000],
['improvement', '/insight/improvement/summary', 60000],
['identity', '/insight/identity/algorand', 60000],
['ascend', '/insight/godel/ascend', 150000]
];
var state = { lineage: [] };
var live = {}; // key -> ms when read live from the node
var failed = {}; // key -> true when the last live read failed
var lastRun = 0, running = false;
// ---------- helpers ----------
function $(id) { return document.getElementById(id); }
function el(tag, cls, text) {
var e = document.createElement(tag);
if (cls) e.className = cls;
if (text != null) e.textContent = String(text);
return e;
}
function clear(node) { while (node.firstChild) node.removeChild(node.firstChild); }
function num(v) { if (v == null || v === '') return null; var n = Number(v); return isFinite(n) ? n : null; }
function fmt(n) { return Number(n).toLocaleString('en-US'); }
function big(n) {
n = num(n); if (n == null) return '—';
if (n >= 1e9) return (n / 1e9).toFixed(2) + 'B';
if (n >= 1e6) return (n / 1e6).toFixed(1) + 'M';
if (n >= 1e3) return (n / 1e3).toFixed(1) + 'k';
return fmt(n);
}
function pct(v) { v = num(v); return v == null ? '—' : (Math.round(v * 1000) / 10) + '%'; }
function ago(sec) {
sec = num(sec); if (sec == null) return '';
var s = Date.now() / 1000 - sec;
if (s < 90) return 'just now';
if (s < 3600) return Math.round(s / 60) + ' min ago';
if (s < 172800) return (s / 3600).toFixed(1) + ' h ago';
return Math.round(s / 86400) + ' days ago';
}
function dur(sec) {
sec = num(sec); if (!sec) return '—';
var h = Math.floor(sec / 3600), m = Math.round((sec % 3600) / 60);
return h ? h + 'h ' + m + 'm' : m + 'm';
}
function words(s) { return String(s || '').replace(/_/g, ' ').toLowerCase(); }
var PASS = { accepted: 1, promoted: 1 };
var REJECT = { proof_rejected: 1 };
function stageClass(stage) {
if (!stage) return 's-none';
if (stage === 'training') return 's-live';
if (PASS[stage]) return 's-pass';
if (REJECT[stage]) return 's-reject';
return 's-fail';
}
function stageLabel(stage) {
return ({ accepted: 'imprinted', promoted: 'imprinted', proof_rejected: 'refused by the gate',
train_failed: 'failed to train', cancelled: 'cancelled', training_detached: 'no result recorded',
dormant: 'dormant', training: 'training now' })[stage] || (stage ? words(stage) : 'no record');
}
// ---------- shaping live readings (mirrors scripts/hf_space_snapshot.py) ----------
var SHAPE = {
health: function (h) { return { health: { status: h.status, ts: h.timestamp } }; },
machine: function (m) {
return { machine: {
verdict: m.verdict, phase: m.phase, proof_coverage: m.proof_coverage,
surrogate_coverage: m.surrogate_coverage, predicates_proven: m.predicates_proven,
blockers: m.blockers || [],
predicates: (m.predicates || []).map(function (p) {
return { id: p.id, name: p.name, verdict: p.verdict, detail: String(p.detail || '').replace(/\/home\/[^\s'"),]+/g, '<path>') };
})
} };
},
feedback: function (f) {
var te = f.training_eval || {};
return { feedback: {
verdict: f.verdict, sample: f.sample, top_failure: f.top_failure,
alignment: f.alignment_mean_live, alignment_samples: f.alignment_samples,
training_note: f.training_note, ts: f.ts,
training_eval: { total: te.total, accepted: te.accepted, trend: te.trend, last_stage: te.last_stage }
} };
},
improvement: function (i) {
return { improvement: { campaigns_24h: i.campaigns_24h, campaigns_7d: i.campaigns_7d, ts: i.computed_at } };
},
identity: function (d) {
var r0 = (d.results || [])[0] || {}, ch = r0.chain || {};
return { identity: {
verdict: d.verdict, network: d.network, verifier: d.verifier, address: r0.address, role: r0.role,
rekeyed_to: ch.rekeyed_to, as_of_round: ch.as_of_round, not_verified: d.not_verified || []
} };
},
ascend: function (a) {
var tr = a.training || {}, st = a.settings || {}, rg = st.regimen || {}, hw = st.hardware || {};
var out = { training: {
state: tr.state, generation: tr.generation, stage: tr.stage,
progress_line: tr.progress_line, started_ts: tr.started_ts, updated_ts: tr.updated_ts,
model: rg.model, cpu_percent: rg.cpu_percent, cpu_cores: hw.cpu_cores, ram_gb: hw.ram_gb,
framework_version: (a.capability || {}).version
} };
out._events = a.events || [];
return out;
}
};
function merge(shaped) {
var events = shaped._events; delete shaped._events;
Object.keys(shaped).forEach(function (k) { state[k] = shaped[k]; });
if (!events && !shaped.training) return;
var byGen = {};
(state.lineage || []).forEach(function (g) { byGen[g.gen] = g; });
var tr = state.training;
// a generation the snapshot saw training has finished if the live reading says so
Object.keys(byGen).forEach(function (n) {
var g = byGen[n];
if (g.stage === 'training' && !(tr && tr.state === 'running' && Number(n) === Number(tr.generation))) g.stage = null;
});
(events || []).forEach(function (e) {
if (e.generation == null) return;
var g = byGen[e.generation] || (byGen[e.generation] = { gen: e.generation });
var rec = e.recall || {};
g.stage = e.stage; g.delta = num(rec.delta); g.wall_s = num(e.wall_seconds); g.ts = e.ts;
});
if (tr && tr.state === 'running' && tr.generation != null) {
var g = byGen[tr.generation] || (byGen[tr.generation] = { gen: tr.generation });
g.stage = 'training';
}
state.lineage = Object.keys(byGen).map(function (n) { return byGen[n]; })
.sort(function (a, b) { return a.gen - b.gen; });
}
// ---------- rendering ----------
function freshness(node, keys) {
var liveAt = keys.map(function (k) { return live[k]; }).filter(Boolean);
node.className = 'freshness';
if (liveAt.length === keys.length) {
node.textContent = 'live · read ' + ago(Math.min.apply(null, liveAt) / 1000);
node.className = 'freshness live';
} else if (liveAt.length) {
node.textContent = 'partly live · the rest from the snapshot';
} else {
var t = (state.health && state.health.ts) || state.ts;
node.textContent = 'snapshot · ' + (t ? ago(t).replace(' ago', ' old') : 'age unknown') +
(running ? ' · reading the node…' : '');
}
}
function pill(text, cls) { return el('span', 'pill ' + (cls || ''), text); }
function renderPills() {
var box = $('pills'); clear(box);
var anyLive = Object.keys(live).length > 0;
var allFailed = !!failed.health && !running;
if (anyLive) box.appendChild(pill('node answering', 'ok'));
else if (allFailed) box.appendChild(pill('node not answering · showing the snapshot', 'warn'));
else box.appendChild(pill(running ? 'reading the node…' : 'snapshot', ''));
var tr = state.training;
if (tr && tr.state === 'running') box.appendChild(pill('training generation ' + tr.generation, 'live'));
var m = state.machine;
if (m) box.appendChild(pill('Gödel machine: ' + (m.verdict === 'NOT_YET_A_GODEL_MACHINE' ? 'not yet' : words(m.verdict)), m.verdict === 'GODEL_MACHINE' ? 'ok' : 'warn'));
var id = state.identity;
if (id) box.appendChild(pill('identity ' + words(id.verdict), id.verdict === 'verified' ? 'ok' : 'bad'));
}
// every tile names where the reading lives on mindx.pythai.net
var TILE_SOURCE = {
'node': ['/diagnostics.html', 'live diagnostics'],
'Gödel machine': ['/machine', 'Gödel Machine Index'],
'self-evaluation': ['/feedback.html', 'the mind of mindX'],
'improvement campaigns · 7 days': ['/insight/improvement/summary?h=true', 'campaign ledger'],
'training': ['/mindxtrain.html', 'the procession'],
'lineage': ['/mindxtrain.html', 'every generation'],
'OVERSEER identity': ['/insight/identity/algorand?h=true', 'chain reading'],
'tokens processed': ['/insight/inference/appetite?h=true', 'inference ledger'],
'last dream': ['/feedback.html', 'dream cycles']
};
function tile(k, v, cls, s) {
var t = el('div', 'tile');
t.appendChild(el('div', 'k', k));
t.appendChild(el('div', 'v ' + (cls || ''), v));
if (s) t.appendChild(el('div', 's', s));
var src = TILE_SOURCE[k];
if (src) {
var a = el('a', 'src', src[1] + ' \u2197');
a.href = BASE + src[0]; a.target = '_blank'; a.rel = 'noopener';
t.appendChild(a);
}
return t;
}
function lastPass() {
var L = state.lineage || [], best = null;
L.forEach(function (g) { if (PASS[g.stage]) best = g; });
return best;
}
function renderTiles() {
var box = $('tiles'); clear(box);
var h = state.health;
box.appendChild(tile('node', h ? words(h.status) : '—', h && h.status === 'healthy' ? 'ok' : 'warn',
live.health ? 'answered your browser ' + ago(live.health / 1000) : (h ? 'as of ' + ago(h.ts) : 'no reading yet')));
var m = state.machine;
if (m) {
var n = (m.predicates || []).length || 8;
box.appendChild(tile('Gödel machine', m.verdict === 'NOT_YET_A_GODEL_MACHINE' ? 'not yet' : words(m.verdict),
m.verdict === 'GODEL_MACHINE' ? 'ok' : 'warn',
m.predicates_proven + ' of ' + n + ' predicates hold · proof coverage ' + pct(m.proof_coverage) +
' (the verdict needs 50%) · surrogate coverage ' + pct(m.surrogate_coverage)));
}
var f = state.feedback;
if (f) {
var vc = { improving: 'ok', stalled: 'warn', failing: 'bad', resource_bound: 'warn', training_stalled: 'warn' }[f.verdict] || '';
var bits = [f.sample + ' recent campaigns succeeded'];
if (f.top_failure) bits.push('most common failure: ' + words(f.top_failure));
if (num(f.alignment) != null) bits.push('alignment ' + num(f.alignment).toFixed(3) + ' over ' + f.alignment_samples + ' scores');
box.appendChild(tile('self-evaluation', words(f.verdict), vc, bits.join(' · ')));
}
var imp = state.improvement && state.improvement.campaigns_7d;
if (imp) box.appendChild(tile('improvement campaigns · 7 days', imp.succeeded + ' / ' + imp.total,
imp.total && imp.succeeded / imp.total >= .5 ? 'ok' : (imp.succeeded ? 'warn' : 'bad'),
'succeeded / attempted. ' + imp.failed + ' failed, ' + (imp.running || 0) + ' running'));
var tr = state.training;
if (tr) {
var running_ = tr.state === 'running';
var model = tr.model ? tr.model.split('/').pop() : 'model';
box.appendChild(tile('training', running_ ? 'generation ' + tr.generation : words(tr.state || 'idle'), running_ ? 'gold' : '',
(running_ && tr.progress_line ? tr.progress_line + ' · ' : '') + model + ' at ' + tr.cpu_percent + '% of ' + tr.cpu_cores + ' CPU cores, no GPU'));
}
var r = state.registry, lp = lastPass();
if (r) box.appendChild(tile('lineage', r.imprinted + ' of ' + r.total, 'gold',
'generations imprinted · ' + r.on_hub + ' archived on the Hub' + (lp ? ' · newest accepted: generation ' + lp.gen : '')));
var id = state.identity;
if (id) box.appendChild(tile('OVERSEER identity', words(id.verdict), id.verdict === 'verified' ? 'ok' : 'bad',
'read back from Algorand ' + (id.network || '') + ' at round ' + (id.as_of_round ? fmt(id.as_of_round) : '—') +
' · ' + (id.rekeyed_to ? 'REKEYED' : 'not rekeyed') + '. The chain shows authority, not custody.'));
var tk = state.tokens;
if (tk && tk.total) {
var bs = tk.by_source || {};
box.appendChild(tile('tokens processed', big(tk.total), '',
Object.keys(bs).length ? 'measured since the seed: ' + Object.keys(bs).map(function (k) { return k + ' ' + big(bs[k]); }).join(' · ') : 'lifetime'));
}
var d = state.dream;
if (d) box.appendChild(tile('last dream', d.insights + ' insights', '',
d.agents_dreamed + ' agents dreamed · ' + d.promoted_to_ltm + ' memories to long-term · ' +
words(d.lunar_phase) + ' · ' + String(d.timestamp || '').slice(0, 10)));
var note = $('vitals-note');
if (f && f.verdict === 'failing') {
note.hidden = false;
note.textContent = 'My self-evaluation reads failing: ' + f.sample + ' of my recent improvement campaigns succeeded' +
(f.top_failure ? ', and most of them ended ' + words(f.top_failure) : '') +
'. I show it here because a mind that hides its failures can’t be audited. The loop that computes this verdict also decides what I try to fix next.';
} else if (f && f.verdict === 'training_stalled' && f.training_note) {
note.hidden = false; note.textContent = f.training_note;
} else { note.hidden = true; }
freshness($('fresh-vitals'), ['health', 'feedback', 'improvement', 'identity']);
}
function verdictTag(v) {
var s = String(v || '');
var cls = /PROVEN|PASS|HOLDS/i.test(s) ? 'ok' : /FAIL|REFUTED|VIOLAT/i.test(s) ? 'bad' : /UNTESTED/i.test(s) ? 'dim' : 'warn';
return el('span', 'tag ' + cls, words(s));
}
function renderMachine() {
var tb = $('predicates'); clear(tb);
var m = state.machine;
if (!m) { var r = tb.insertRow(); var c = r.insertCell(); c.colSpan = 4; c.textContent = 'No reading yet.'; return; }
(m.predicates || []).forEach(function (p) {
var r = tb.insertRow();
var c0 = r.insertCell(); c0.className = 'mono'; c0.textContent = p.id;
var c1 = r.insertCell(); c1.className = 'mono'; c1.textContent = words(p.name);
r.insertCell().appendChild(verdictTag(p.verdict));
r.insertCell().textContent = p.detail || '';
});
freshness($('fresh-machine'), ['machine']);
}
function renderLineage() {
var L = state.lineage || [];
var strip = $('strip'); clear(strip);
var byGen = {}, max = 0;
L.forEach(function (g) { byGen[g.gen] = g; if (g.gen > max) max = g.gen; });
var lp = lastPass();
for (var n = 1; n <= max; n++) {
var g = byGen[n] || { gen: n };
var c = el('div', 'cell ' + stageClass(g.stage) + (lp && lp.gen === n ? ' star' : ''), n);
var tip = 'generation ' + n + ' · ' + stageLabel(g.stage);
if (num(g.delta) != null) tip += ' · recall Δ ' + (g.delta > 0 ? '+' : '') + g.delta.toFixed(4);
c.title = tip;
strip.appendChild(c);
}
strip.setAttribute('aria-label', max + ' generations by outcome');
var sentence = $('lineage-sentence');
if (lp) {
var after = L.filter(function (g) { return g.gen > lp.gen; });
var rej = after.filter(function (g) { return REJECT[g.stage]; }).length;
var other = after.filter(function (g) { return g.stage && !REJECT[g.stage] && !PASS[g.stage] && g.stage !== 'training'; }).length;
sentence.textContent = 'Generation ' + lp.gen + ' (outlined) is the newest my gate accepted. Since then ' + rej +
' generations were refused and ' + other + ' failed or stopped. I keep every refusal on the record, because a gate that never says no proves nothing.';
} else sentence.textContent = '';
var tr = state.training, now = $('training-now');
now.textContent = tr && tr.state === 'running'
? '▶ generation ' + tr.generation + ' is training now · ' + (tr.progress_line || words(tr.stage)) +
(tr.started_ts ? ' · started ' + ago(tr.started_ts) : '')
: '';
var tb = $('recent'); clear(tb);
L.filter(function (g) { return g.stage && g.stage !== 'training'; }).slice(-12).reverse().forEach(function (g) {
var r = tb.insertRow();
var c0 = r.insertCell(); c0.className = 'mono'; c0.textContent = g.gen;
var cls = PASS[g.stage] ? 'ok' : REJECT[g.stage] ? 'bad' : 'warn';
r.insertCell().appendChild(el('span', 'tag ' + cls, stageLabel(g.stage)));
var cd = r.insertCell(); cd.className = 'mono';
cd.textContent = num(g.delta) == null ? '—' : (g.delta > 0 ? '+' : '') + g.delta.toFixed(4);
var cw = r.insertCell(); cw.className = 'mono'; cw.textContent = dur(g.wall_s);
r.insertCell().textContent = g.ts ? ago(g.ts) : '—';
});
freshness($('fresh-lineage'), ['ascend']);
}
function renderFooter() {
var t = (state.health && state.health.ts) || state.ts;
$('snap-age').textContent = t ? 'snapshot taken ' + new Date(t * 1000).toISOString().slice(0, 16).replace('T', ' ') + ' UTC' : '';
}
function render() {
renderPills(); renderTiles(); renderMachine(); renderLineage(); renderFooter();
}
// ---------- reading the node ----------
function read(path, timeout) {
var ctl = typeof AbortController !== 'undefined' ? new AbortController() : null;
var timer = ctl ? setTimeout(function () { ctl.abort(); }, timeout) : null;
return fetch(BASE + path, { cache: 'no-store', signal: ctl ? ctl.signal : undefined })
.then(function (r) { if (!r.ok) throw new Error(r.status); return r.json(); })
.finally(function () { if (timer) clearTimeout(timer); });
}
function refresh() {
if (running) return;
running = true; lastRun = Date.now(); render();
var i = 0;
(function next() {
if (i >= READS.length) { running = false; render(); return; }
var spec = READS[i++];
read(spec[1], spec[2]).then(function (json) {
merge(SHAPE[spec[0]](json)); live[spec[0]] = Date.now(); failed[spec[0]] = false;
}).catch(function () {
failed[spec[0]] = true;
// a node that cannot answer /health will not answer the rest; stop and keep the snapshot
if (spec[0] === 'health') i = READS.length;
}).then(function () { render(); next(); });
})();
}
function tick() {
if (document.visibilityState === 'visible' && Date.now() - lastRun >= EVERY_MS) refresh();
}
fetch('snapshot.json', { cache: 'no-store' })
.then(function (r) { return r.ok ? r.json() : {}; })
.catch(function () { return {}; })
.then(function (snap) {
state = snap || {}; state.lineage = state.lineage || [];
render();
refresh();
setInterval(tick, 30000);
document.addEventListener('visibilitychange', tick);
});
})();