feat(admin): bans, admin logout and time played (schema 64)
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / postgres-tools (push) Successful in 2m9s
Foundation / server-image (push) Successful in 5m23s
Foundation / image (push) Successful in 6m10s

ADR-0182 section 11.
- Append-only account bans; a ban also revokes the account's grants (its live
  session closes at the next control renewal) and issue_account_grant refuses a
  banned account (EVL20 -> broker 403 account_banned). Lifting is another row.
- admin_logout_account_v1 revokes by account id.
- Session intervals recorded by claim/renew/release (signatures unchanged):
  time played, sessions and last seen per account.
- The region view carries each cell's lineage root; the portal counts living
  wildlife descended from an account's lives.
- Portal: Ban/Unban and Log out with reason and history; time played column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-27 17:50:34 -04:00
co-authored by Claude Opus 5.5
parent b3eca78549
commit 070c458dc5
18 changed files with 490 additions and 36 deletions
+58 -4
View File
@@ -57,6 +57,14 @@ function fmtAgo(seconds) {
return `${Math.round(hr / 24)}d ago`;
}
const short = (id) => (id ? `${id.slice(0, 8)}…` : '—');
function fmtDuration(seconds) {
const s = Math.max(0, Math.round(seconds || 0));
if (s < 60) return `${s}s`;
const m = Math.floor(s / 60);
if (m < 60) return `${m}m ${s % 60}s`;
const hr = Math.floor(m / 60);
return hr < 48 ? `${hr}h ${m % 60}m` : `${Math.floor(hr / 24)}d ${hr % 24}h`;
}
// ---------- Sign-in ----------
function b64url(bytes) {
@@ -184,8 +192,9 @@ function table(columns, rows, { onRow, sortKey, sortUp = false } = {}) {
}
function statusBadge(a) {
return h('span', { class: `badge ${a.status === 'alive' ? 'alive' : a.status === 'dead' ? 'dead' : ''}` },
const life = h('span', { class: `badge ${a.status === 'alive' ? 'alive' : a.status === 'dead' ? 'dead' : ''}` },
a.status === 'no_life' ? 'no life' : a.status);
return a.banned ? h('span', {}, life, ' ', h('span', { class: 'badge dead' }, 'banned')) : life;
}
function sessionBadge(a) {
return a.logged_in ? h('span', { class: 'badge online' }, `online · region ${a.control_region}`)
@@ -209,6 +218,7 @@ async function accountsPage() {
{ key: 'deaths', label: 'Deaths', num: true },
{ key: 'resets', label: 'Resets', num: true },
{ key: 'mutation_choices', label: 'Mutation choices', num: true },
{ key: 'played_seconds', label: 'Time played', num: true, render: (a) => fmtDuration(a.played_seconds) },
{ key: 'created_at', label: 'Created', render: (a) => (a.created_at ? fmtAgo(a.created_at) : '—'), sort: (a) => a.created_at ?? 0 },
];
const draw = () => {
@@ -238,9 +248,49 @@ function stat(label, value, sub) {
// persistence::LifeRefusal.
const rejections = ['accepted', 'refused: not enough funding', 'refused: no placement', 'cancelled', 'refused: already alive'];
async function livingOffspring(identities) {
// Living wildlife whose lineage root is one of the account's lives, in every viewable region.
const roots = new Set(identities);
let count = 0;
try {
const regions = await api('/api/regions');
for (const r of regions.regions.filter((x) => x.viewable)) {
try {
const view = await api(`/api/regions/${r.region}/view`);
count += view.cells.filter((c) => (c[6] & 1) && roots.has(c[14])).length;
} catch { /* region not ready */ }
}
} catch { return null; }
return count;
}
async function accountPage(id) {
const data = await api(`/api/accounts/${id}`);
const a = data.account;
const offspring = h('span', { class: 'muted' }, '…');
livingOffspring(data.lives.filter((l) => l.born !== null).map((l) => l.identity))
.then((n) => { offspring.textContent = n === null ? '—' : fmtInt(n); });
const note = h('span', { class: 'muted small' });
const reason = h('input', { type: 'text', maxlength: 200, placeholder: 'Reason (optional)' });
const act = async (path, label, ask) => {
if (ask && !confirm(ask)) return;
try {
const q = new URLSearchParams(path.includes('?') ? path.split('?')[1] : '');
if (reason.value.trim()) q.set('reason', reason.value.trim());
await api(`/api/accounts/${a.account}/${path.split('?')[0]}?${q}`, true, 'POST');
route();
} catch (e) { note.textContent = `Could not ${label}: ${e.code || e.message}`; }
};
const actions = h('div', { class: 'card' }, h('h2', {}, 'Account actions'),
h('div', { class: 'window-controls' },
h('button', { onclick: () => act('logout', 'log out', `Log out ${short(a.account)} now? Its session closes within seconds.`) }, 'Log out'),
a.banned
? h('button', { onclick: () => act('ban?banned=0', 'lift the ban') }, 'Lift ban')
: h('button', { class: 'danger', onclick: () => act('ban?banned=1', 'ban', `Ban ${short(a.account)}? It is logged out and cannot sign in to play.`) }, 'Ban')),
reason, note,
data.bans.length ? h('table', { class: 'compact' }, h('tbody', {}, data.bans.slice(0, 8).map((b) =>
h('tr', {}, h('td', {}, fmtTime(b.at)), h('td', {}, b.banned ? h('span', { class: 'badge dead' }, 'banned') : 'lifted'),
h('td', { class: 'muted' }, (b.author || '').split(' (')[0]), h('td', { class: 'muted' }, b.reason || ''))))) : null);
const facts = h('dl', { class: 'facts' },
h('dt', {}, 'Account'), h('dd', { class: 'mono' }, a.account),
h('dt', {}, 'Keycloak subject'), h('dd', { class: 'mono' }, a.subject || '—'),
@@ -250,7 +300,9 @@ async function accountPage(id) {
a.control_expires ? h('span', { class: 'muted' }, ` control ${a.logged_in ? 'until' : 'ended'} ${fmtTime(a.control_expires)}`) : null),
h('dt', {}, 'Active life'), h('dd', { class: 'mono' }, a.active_life ?? '—',
a.active_region ? h('span', {}, ' ', h('a', { href: `#/regions/${a.active_region}?account=${a.account}` }, `show in region ${a.active_region}`)) : null),
h('dt', {}, 'Created'), h('dd', {}, fmtTime(a.created_at)));
h('dt', {}, 'Created'), h('dd', {}, fmtTime(a.created_at)),
h('dt', {}, 'Last seen'), h('dd', {}, a.last_seen ? `${fmtTime(a.last_seen)} (${fmtAgo(a.last_seen)})` : '—'),
h('dt', {}, 'Living offspring'), h('dd', {}, offspring, h('span', { class: 'muted' }, ' wildlife descended from its lives')));
const lives = table([
{ key: 'request', label: 'Request', sort: (l) => Number(l.request) },
{ key: 'identity', label: 'Life', render: (l) => h('span', { class: 'mono' }, l.identity) },
@@ -265,10 +317,12 @@ async function accountPage(id) {
h('div', { class: 'head' }, h('div', {}, h('a', { href: '#/accounts' }, '← Accounts'), h('h1', {}, `Account ${short(a.account)}`))),
h('div', { class: 'stats' },
stat('Lives', fmtInt(a.lives)), stat('Deaths', fmtInt(a.deaths)), stat('Resets', fmtInt(a.resets)),
stat('Mutation choices', fmtInt(a.mutation_choices))),
stat('Mutation choices', fmtInt(a.mutation_choices)),
stat('Time played', fmtDuration(a.played_seconds), `${fmtInt(a.sessions)} sessions`)),
h('div', { class: 'card' }, facts),
actions,
h('h2', {}, 'Lives'), lives,
h('p', { class: 'muted' }, 'Time played, bans, current mutations and living offspring arrive with the next admin phase (ADR-0182).'));
h('p', { class: 'muted' }, 'Time played counts sessions from schema 64 on; earlier play is not recorded.'));
}
async function regionsPage() {