feat(admin): live admin commands in trace 5 (schema 63)
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / postgres-tools (push) Successful in 30s
Foundation / server-image (push) Successful in 4m44s
Foundation / image (push) Successful in 5m33s

The admin portal can now spawn wildlife, add bubbles, add to or release the
spent pool, remove a cell and grant a cell's reserve on a running rules-13
region (ADR-0182 section 10). No new owner format or region opening.

- Trace 5: trace 4 plus 64-byte command records counted in the tick header's
  last word; a batch without commands stays trace 4 (older builds replay it).
  Bundle 15 admits trace 5.
- CellularLives::admin_candidate applies a tick's commands after its births,
  each on a copy kept only when it applies and closes: imports through the
  boundary ledger, removals into the spent pool with a new `removed` corpse
  cause, spawned roots via the ADR-0180 seed (now a shared helper) funded by
  an exact import. Refused commands change nothing.
- Schema 63: the immutable admin_commands queue (spawn identities from the
  life allocator), pending/history reads, and binding of every recorded
  command exactly once inside both cellular publishers; the SQL trace parsers
  read trace 5 through its trace-4 normal form.
- The region polls pending commands every 2 s and appends up to 16 per tick;
  the admin API and portal gain region actions, per-cell Remove/Grant and the
  command history.
- Fixes an existing test that did not advance its head after a tick commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-27 17:14:04 -04:00
co-authored by Claude Opus 5.5
parent b075198040
commit b1cc3b121b
32 changed files with 1487 additions and 138 deletions
+97 -1
View File
@@ -349,6 +349,86 @@ function sessionWindowCard(region) {
return { card, load };
}
// Amounts typed in friendly units: energy in µJ (10^6 pJ), matter in ng (10^6 fg).
function amountInputs() {
const make = (label) => h('input', { type: 'number', min: 0, step: 'any', placeholder: label, class: 'amount' });
const fields = { energy: make('energy µJ'), carbon: make('C ng'), nitrogen: make('N ng'), phosphorus: make('P ng'), other: make('other ng') };
const read = () => {
const out = {};
for (const [name, input] of Object.entries(fields)) {
const v = Number(input.value || 0);
if (!Number.isFinite(v) || v < 0) throw new Error(`${name} must be a positive number`);
out[name] = String(Math.round(v * 1e6));
}
return out;
};
const clear = () => Object.values(fields).forEach((input) => { input.value = ''; });
return { node: h('div', { class: 'amounts' }, Object.values(fields)), read, clear };
}
const kindLabels = {
remove_cell: 'remove cell', grant_reserve: 'grant reserve', add_bubbles: 'add bubbles',
add_pool: 'add to pool', release_pool: 'release pool', spawn_wildlife: 'spawn wildlife',
};
// Admin commands (ADR-0182): queued now, applied by the region at its next ticks.
function commandsCard(region) {
const note = h('div', { class: 'muted small' });
const history = h('div');
const reason = h('input', { type: 'text', maxlength: 200, placeholder: 'Reason (optional)' });
async function send(params, label) {
try {
const q = new URLSearchParams(params);
if (reason.value.trim()) q.set('reason', reason.value.trim());
const r = await api(`/api/regions/${region}/commands?${q}`, true, 'POST');
note.textContent = `Queued #${r.id} (${label}). The region applies it within a few seconds.`;
reason.value = '';
load();
return true;
} catch (e) {
note.textContent = `Could not queue ${label}: ${e.code || e.message}`;
return false;
}
}
const spawnCount = h('input', { type: 'number', min: 1, max: 64, value: 10, class: 'count' });
const bubbleCount = h('input', { type: 'number', min: 1, max: 256, value: 20, class: 'count' });
const bubbleAmount = amountInputs();
const poolAmount = amountInputs();
const releaseCount = h('input', { type: 'number', min: 1, max: 256, value: 20, class: 'count' });
const releaseAmount = amountInputs();
const withAmount = (amount, extra, label) => {
let values;
try { values = amount.read(); } catch (e) { note.textContent = e.message; return; }
send({ ...extra, ...values }, label).then((ok) => { if (ok) amount.clear(); });
};
async function load() {
try {
const data = await api(`/api/regions/${region}/commands`);
history.replaceChildren(data.commands.length ? h('table', { class: 'compact' }, h('tbody', {}, data.commands.slice(0, 10).map((c) =>
h('tr', {}, h('td', { class: 'mono' }, `#${c.id}`), h('td', {}, kindLabels[c.kind] || c.kind,
c.count ? ` ×${c.count}` : '', c.kind === 'remove_cell' || c.kind === 'grant_reserve' ? ` ${c.target}` : ''),
h('td', {}, c.applied_tick ? h('span', { class: 'badge alive' }, `tick ${c.applied_tick}`) : h('span', { class: 'badge warn' }, 'pending')),
h('td', { class: 'muted', title: c.author || '' }, (c.author || '').split(' (')[0]))))) : h('p', { class: 'muted' }, 'No commands yet.'));
} catch (e) {
history.textContent = `Unavailable: ${e.message}`;
}
}
const card = h('div', { class: 'card' },
h('h2', {}, 'Region actions'),
h('div', { class: 'action' }, h('strong', {}, 'Spawn wildlife'), h('div', { class: 'row' }, spawnCount,
h('button', { onclick: () => send({ kind: 'spawn_wildlife', count: spawnCount.value }, 'spawn wildlife') }, 'Spawn'))),
h('div', { class: 'action' }, h('strong', {}, 'Add bubbles'), bubbleAmount.node, h('div', { class: 'row' }, bubbleCount, h('span', { class: 'muted' }, 'bubbles'),
h('button', { onclick: () => withAmount(bubbleAmount, { kind: 'add_bubbles', count: bubbleCount.value }, 'add bubbles') }, 'Add'))),
h('div', { class: 'action' }, h('strong', {}, 'Add to spent pool'), poolAmount.node,
h('div', { class: 'row' }, h('button', { onclick: () => withAmount(poolAmount, { kind: 'add_pool' }, 'add to pool') }, 'Add to pool'))),
h('div', { class: 'action' }, h('strong', {}, 'Release spent pool as bubbles'), releaseAmount.node,
h('div', { class: 'row' }, releaseCount, h('span', { class: 'muted' }, 'bubbles'),
h('button', { onclick: () => withAmount(releaseAmount, { kind: 'release_pool', count: releaseCount.value }, 'release pool') }, 'Release'))),
reason, note, h('h2', {}, 'Recent commands'), history);
load();
return { card, load, send };
}
// ---------- Region view ----------
const channelNames = ['energy', 'carbon', 'nitrogen', 'phosphorus', 'other'];
const css = (name) => getComputedStyle(document.documentElement).getPropertyValue(`--${name}`).trim();
@@ -365,6 +445,7 @@ async function regionPage(region, params) {
const toggle = (k, label) => h('label', {}, h('input', { type: 'checkbox', checked: true, onchange: (e) => { show_[k] = e.target.checked; paint(); } }), label);
const live = h('input', { type: 'checkbox', checked: true });
const sessions = sessionWindowCard(region);
const commands = commandsCard(region);
let view = null, selected = null, timer = null, beats = 0;
let zoom = 1, panX = 0, panY = 0, drag = null;
@@ -377,6 +458,7 @@ async function regionPage(region, params) {
h('div', { class: 'side' },
sessions.card,
detail,
commands.card,
h('div', { class: 'card' }, h('h2', {}, 'Show'), h('div', { class: 'toggles' },
toggle('players', 'Player cells'), toggle('wildlife', 'Wildlife'), toggle('pools', 'Pools'), toggle('bubbles', 'Bubbles'))),
h('div', { class: 'card' }, h('h2', {}, 'Legend'), h('div', { class: 'legend' },
@@ -480,9 +562,22 @@ async function regionPage(region, params) {
}
function showDetail(c) {
selected = c;
const grant = amountInputs();
const remove = () => {
if (!confirm(`Remove ${c.flags & 1 ? 'wildlife' : 'player'} cell ${c.life}? Its body and reserve go to the spent pool.`)) return;
commands.send({ kind: 'remove_cell', target: c.life }, `remove cell ${c.life}`);
};
const give = () => {
let values;
try { values = grant.read(); } catch (e) { return alert(e.message); }
commands.send({ kind: 'grant_reserve', target: c.life, ...values }, `grant reserve to ${c.life}`)
.then((ok) => { if (ok) grant.clear(); });
};
detail.replaceChildren(h('h2', {}, c.flags & 1 ? 'Wildlife cell' : 'Player cell'),
h('dl', { class: 'facts' }, cellLines(c).flatMap(([k, v]) => [h('dt', {}, k), h('dd', { class: k === 'Life' || k === 'Account' ? 'mono' : null }, v)])),
c.account ? h('p', {}, h('a', { href: `#/accounts/${c.account}` }, 'Open account →')) : null);
c.account ? h('p', {}, h('a', { href: `#/accounts/${c.account}` }, 'Open account →')) : null,
h('div', { class: 'action' }, h('strong', {}, 'Grant reserve'), grant.node,
h('div', { class: 'row' }, h('button', { onclick: give }, 'Grant'), h('button', { class: 'danger', onclick: remove }, 'Remove cell'))));
paint();
}
@@ -562,6 +657,7 @@ async function regionPage(region, params) {
if (live.checked && !document.hidden) {
await load();
if (++beats % 10 === 0) sessions.load();
if (beats % 5 === 0) commands.load();
}
tick();
}, 1000);
+7 -1
View File
@@ -58,7 +58,7 @@ button {
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
input[type="search"], input[type="text"], select {
input[type="search"], input[type="text"], input[type="number"], select {
font: inherit;
color: var(--text);
background: var(--panel);
@@ -188,3 +188,9 @@ dl.facts dd { margin: 0; }
table.compact { margin-top: 10px; font-size: 12.5px; background: transparent; }
table.compact td { padding: 4px 6px; white-space: normal; }
button:disabled { opacity: 0.5; cursor: default; }
.action { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.action .row { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.amounts { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; margin-top: 6px; }
input.amount, input.count { min-width: 0; width: 100%; }
input.count { width: 80px; }
button.danger { color: var(--bad); border-color: var(--bad); }