variant round: roll retired, chance is variant literature (strict parse, crypto pick on reception, picked-only rendering, /story variance metric); entity round: /story the whole deliverable, /table the play projection, the slidwin carry (smart contwin cutoff, whole exchanges, housekeeper reads session-minus-tail); dormant-session rework: universal session lifecycle (dormant->live->finished, sessions/<n> storage), move-at-stop, start lint + auto-send rule, rebaseable housekeeping, turn-0 -> carryover.jsonl, seed -> memory.json, draft-only save-package; format house rules enforced by the nine-rule check-repo (ascii bytes, no text-mutating css); smoke 105/105 + restart + reminder + browser pass green, irene hand-migrated to the new layout

This commit is contained in:
2026-11-15 14:35:00 +00:00
parent c51d31078e
commit fa3f23b474
51 changed files with 3477 additions and 1719 deletions
+9 -9
View File
@@ -1,13 +1,13 @@
// server/users.mjs — the deployment's people: users, invites, tokens.
// server/users.mjs -- the deployment's people: users, invites, tokens.
//
// Identity is a token, nothing else: no usernames, no passwords, no
// external IDPs. A single-use invite code is exchanged at claim time
// for a persistent token; the server stores hashes only, the client
// keeps the token. Spent invites stay recorded forever — claiming
// keeps the token. Spent invites stay recorded forever -- claiming
// with a spent code is rejected loudly, never silently dropped. The
// first claim on a fresh deployment creates the superuser; recovery
// for a lost superuser token is filesystem access (it is their
// deployment). Revocation deletes the row — the token dies with it,
// deployment). Revocation deletes the row -- the token dies with it,
// and the person returns (if invited again) as a new identity.
//
// All times are UTC (house rule). Never model-facing: nothing here
@@ -56,7 +56,7 @@ export function userCount() {
return db.prepare('SELECT COUNT(*) AS n FROM users').get().n;
}
// does this identity exist? A revoked user's id resolves to absent —
// does this identity exist? A revoked user's id resolves to absent --
// dead ids are ownerless by resolution, never by rewriting history
export function exists(uid) {
if (uid == null) return false;
@@ -82,7 +82,7 @@ export function listUsers() {
}
// revocation destroys the identity: no suspend, no restore. Their runs
// and packages stay — ownerless, readable, forkable.
// and packages stay -- ownerless, readable, forkable.
export function revokeUser(id) {
return db.prepare('DELETE FROM users WHERE id = ?').run(id).changes > 0;
}
@@ -90,7 +90,7 @@ export function revokeUser(id) {
// --- invites ---------------------------------------------------------------------
export function mintInvite(byUid, kind = 'invite') {
const code = hex(12); // 24 hex chars — shown once, stored hashed
const code = hex(12); // 24 hex chars -- shown once, stored hashed
const res = db.prepare(
'INSERT INTO invites (code_hash, kind, created_by, created_at) VALUES (?, ?, ?, ?)'
).run(sha(code), kind, byUid, now());
@@ -118,12 +118,12 @@ export function claimInvite(code, name) {
if (!n) fail('a display name is required');
const row = db.prepare('SELECT * FROM invites WHERE code_hash = ?').get(sha(c));
if (!row) fail('unknown invite code');
if (row.claimed_by != null) fail('this invite was already used — ask for a fresh one');
if (row.claimed_by != null) fail('this invite was already used -- ask for a fresh one');
if (row.kind === 'bootstrap' && userCount() > 0) {
fail('the bootstrap invite expired when this deployment got its superuser — ask the operator for an invite');
fail('the bootstrap invite expired when this deployment got its superuser -- ask the operator for an invite');
}
const uid = hex(4);
const token = hex(16); // 32 hex chars — returned once, never again
const token = hex(16); // 32 hex chars -- returned once, never again
const su = userCount() === 0 ? 1 : 0;
db.exec('BEGIN');
try {