feat(admin): resource schedules for bubbles, pool releases and wildlife (schema 65)
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / postgres-tools (push) Successful in 23s
Foundation / server-image (push) Successful in 4m38s
Foundation / image (push) Successful in 5m35s

ADR-0182 section 12: the game source as recurring admin commands. A schedule
repeats add_bubbles, release_pool or spawn_wildlife every 1 s to 24 h while
enabled; the region's pending-command read queues each due run as an ordinary
command (recorded in the trace, bound once), never two waiting per schedule,
so an idle region builds no backlog. Append-only schedule versions; admin API
GET/POST /api/regions/<n>/schedules and a portal card to add, stop and start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-27 18:30:37 -04:00
co-authored by Claude Opus 5.5
parent 2485a028bb
commit 018b4b1817
13 changed files with 425 additions and 14 deletions
+56
View File
@@ -483,6 +483,59 @@ function commandsCard(region) {
return { card, load, send };
}
// Resource schedules (schema 65): a command repeated every N seconds while enabled. The game
// source for bubbles, a steady release of the spent pool, or a wildlife population top-up.
function schedulesCard(region) {
const list = h('div');
const note = h('div', { class: 'muted small' });
const kind = h('select', {}, [['add_bubbles', 'Add bubbles'], ['release_pool', 'Release spent pool'], ['spawn_wildlife', 'Spawn wildlife']]
.map(([v, label]) => h('option', { value: v }, label)));
const count = h('input', { type: 'number', min: 1, max: 256, value: 10, class: 'count', title: 'bubbles or cells each time' });
const every = h('input', { type: 'number', min: 1, max: 86400, value: 30, class: 'count', title: 'seconds between runs' });
const amount = amountInputs();
const reason = h('input', { type: 'text', maxlength: 200, placeholder: 'Reason (optional)' });
const fromSchedule = (x) => ({
id: x.id, kind: x.kind, count: String(x.count), interval: String(x.interval),
energy: x.amount[0], carbon: x.amount[1], nitrogen: x.amount[2], phosphorus: x.amount[3], other: x.amount[4],
});
const save = async (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}/schedules?${q}`, true, 'POST');
note.textContent = `Saved schedule #${r.id} (${label}).`;
reason.value = '';
load();
return true;
} catch (e) { note.textContent = `Could not save: ${e.code || e.message}`; return false; }
};
const add = () => {
let values;
try { values = kind.value === 'spawn_wildlife' ? {} : amount.read(); } catch (e) { note.textContent = e.message; return; }
save({ kind: kind.value, count: count.value, interval: every.value, enabled: '1', ...values }, 'new')
.then((ok) => { if (ok) amount.clear(); });
};
async function load() {
try {
const data = await api(`/api/regions/${region}/schedules`);
list.replaceChildren(data.schedules.length ? h('table', { class: 'compact' }, h('tbody', {}, data.schedules.map((x) =>
h('tr', {},
h('td', { class: 'mono' }, `#${x.id}`),
h('td', {}, `${kindLabels[x.kind] || x.kind} ×${x.count} every ${fmtDuration(x.interval)}`,
x.kind !== 'spawn_wildlife' ? h('div', { class: 'muted' }, `per run: ${fmtEnergy(x.amount[0])}, ${x.amount.slice(1).map(fmtMass).join(' / ')}`) : null),
h('td', {}, x.enabled ? h('span', { class: 'badge alive' }, `on · ${x.runs} runs`) : h('span', { class: 'badge' }, 'off')),
h('td', {}, h('button', { onclick: () => save({ ...fromSchedule(x), enabled: x.enabled ? '0' : '1' }, x.enabled ? 'disabled' : 'enabled') }, x.enabled ? 'Stop' : 'Start')))))) : h('p', { class: 'muted' }, 'No schedules.'));
} catch (e) { list.textContent = `Unavailable: ${e.message}`; }
}
const card = h('div', { class: 'card' }, h('h2', {}, 'Resource schedules'), list,
h('div', { class: 'action' }, h('strong', {}, 'New schedule'),
h('div', { class: 'row' }, kind, count, h('span', { class: 'muted' }, 'every'), every, h('span', { class: 'muted' }, 's')),
amount.node, h('div', { class: 'row' }, h('button', { onclick: add }, 'Add schedule'))),
reason, note);
load();
return { card, load };
}
// ---------- Region view ----------
const channelNames = ['energy', 'carbon', 'nitrogen', 'phosphorus', 'other'];
const css = (name) => getComputedStyle(document.documentElement).getPropertyValue(`--${name}`).trim();
@@ -500,6 +553,7 @@ async function regionPage(region, params) {
const live = h('input', { type: 'checkbox', checked: true });
const sessions = sessionWindowCard(region);
const commands = commandsCard(region);
const schedules = schedulesCard(region);
let view = null, selected = null, timer = null, beats = 0;
let zoom = 1, panX = 0, panY = 0, drag = null;
@@ -513,6 +567,7 @@ async function regionPage(region, params) {
sessions.card,
detail,
commands.card,
schedules.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' },
@@ -712,6 +767,7 @@ async function regionPage(region, params) {
await load();
if (++beats % 10 === 0) sessions.load();
if (beats % 5 === 0) commands.load();
if (beats % 15 === 0) schedules.load();
}
tick();
}, 1000);