Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

Guestbook: auto-reseed the live daemon onto each published shell

nyblnet0e4cd8356c8e
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index 73e191ee..d222c2d6 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -57,7 +57,9 @@ verify the manifest signature against the public key embedded in every shell.
node scripts/publish-site.mjs "landing: copy tweak" # add --gallery to regen decks
```
- Preview any publish first with `--dry`.
+ Preview any publish first with `--dry`. `publish-site.mjs` also re-seeds the
+ live **guestbook daemon** onto the freshly-published shell as a best-effort
+ final step (see below) — no separate command needed.
5. Also attach `site/releases/slides/Bento_Slides.bento.html` to a GitHub
Release for the tag — download counts, release-watch notifications, and a
@@ -103,3 +105,30 @@ before starting a share session.
The relay stores ONLY ciphertext (room-key-encrypted frames) and a hash of
the room key; there are no secrets to manage server-side. Rooms self-delete
after ~30 idle days — the file is the durable artifact.
+
+## The guestbook daemon and the shell (why the guestbook can lag)
+
+`bento.page/guestbook.bento.html` is **NOT served from the static site** — a
+separate Cloudflare daemon (`server/guestbook-daemon/`) serves it from KV so it
+can archive/roll epochs. `release.mjs` re-shells the *static*
+`site/guestbook.bento.html` (only the KV-empty fallback), so a shell release does
+**not** by itself update what visitors see — the daemon keeps serving the deck in
+its KV until it's re-seeded. (Tell: the plain URL shows an old app-hash while
+`?cb=1` — GitHub Pages — shows the new one.)
+
+`scripts/reseed-guestbook.mjs` closes the gap and `publish-site.mjs` runs it
+automatically after every push:
+
+- It fetches the daemon's **own** current deck, so the live room + walls are
+ preserved (the walls live in the relay room; the KV deck only carries the
+ shell + creds), re-shells that doc onto the fresh shell, and `PUT`s it back to
+ `/guestbook-admin/seed`.
+- Idempotent — a no-op when the daemon already serves the current shell.
+- Best-effort — needs the admin bearer key at `working/guestbook-admin-key.txt`
+ (gitignored); a missing key or unreachable daemon is a warning, never a failed
+ publish. Run it by hand any time with `node scripts/reseed-guestbook.mjs`
+ (`--dry` to preview).
+
+An epoch **roll** (fresh room + blank walls) is a separate, deliberate act
+(`build-guestbook.mjs` locally, or `POST /guestbook-admin/roll`) — re-seeding
+never rolls.
diff --git a/scripts/publish-site.mjs b/scripts/publish-site.mjs
index bf152c5e..a0e1c040 100755
--- a/scripts/publish-site.mjs
+++ b/scripts/publish-site.mjs
@@ -106,3 +106,16 @@ const ver = (() => {
} catch { return '?' }
})()
console.log(`\n✓ published to bento-site @ ${head} (app v${ver})`)
+
+// ---- keep the LIVE guestbook daemon on the freshly-published shell ---------
+// bento.page/guestbook.bento.html is served by the Cloudflare daemon from KV,
+// not from this static tree — so a new shell doesn't reach it until the daemon
+// is re-seeded. This round-trips the daemon's own current deck onto the fresh
+// shell (walls preserved) and is a no-op when it's already current. Best-effort:
+// the script exits 0 on any problem (no key / daemon down), so publish never
+// fails on it.
+try {
+ run('node', [join(root, 'scripts/reseed-guestbook.mjs')])
+} catch (e) {
+ console.warn(`⚠ guestbook daemon re-seed step errored (non-fatal): ${e.message ?? e}`)
+}
diff --git a/scripts/reseed-guestbook.mjs b/scripts/reseed-guestbook.mjs
new file mode 100644
index 00000000..1b2a6157
--- /dev/null
+++ b/scripts/reseed-guestbook.mjs
@@ -0,0 +1,97 @@
+#!/usr/bin/env node
+// Keep the LIVE guestbook daemon on the current shell.
+//
+// bento.page/guestbook.bento.html is served by the Cloudflare daemon from its
+// KV store (server/guestbook-daemon), NOT from GitHub Pages. release.mjs
+// re-shells the *static* site/guestbook.bento.html (the KV-empty fallback), but
+// the daemon keeps serving whatever deck sits in KV — so after a shell release
+// the served guestbook stays on the OLD runtime until the daemon is re-seeded.
+//
+// This script closes that gap: it fetches the daemon's OWN current deck (so the
+// live room + walls are preserved — the walls live in the relay room, the KV
+// deck only carries the shell + creds), re-shells that doc onto the freshly
+// built shell, and PUTs it back to /guestbook-admin/seed. Idempotent: if the
+// daemon already serves the fresh shell it does nothing.
+//
+// node scripts/reseed-guestbook.mjs [--shell <file>] [--base <url>] [--dry]
+//
+// --shell the fresh shell to re-shell onto
+// (default: site/releases/slides/Bento_Slides.bento.html,
+// then slides/dist-single/Bento_Slides.bento.html)
+// --base daemon origin (default https://bento.page)
+// --dry report what would change; don't seed.
+//
+// Auth: the Bearer key in working/guestbook-admin-key.txt (gitignored). Absent
+// key or unreachable daemon is a WARNING, not an error — callers (publish-site)
+// treat guestbook re-seeding as best-effort.
+
+import { existsSync, readFileSync } from 'node:fs'
+import { createHash } from 'node:crypto'
+import { dirname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+import { spliceDoc, extractDoc } from './guestbook-deck.mjs'
+
+const root = dirname(dirname(fileURLToPath(import.meta.url)))
+const args = process.argv.slice(2)
+const opt = (name, fallback) => {
+ const i = args.indexOf(`--${name}`)
+ return i >= 0 && args[i + 1] ? args[i + 1] : fallback
+}
+const dry = args.includes('--dry')
+
+const warn = (m) => { console.warn(`⚠ guestbook re-seed skipped: ${m}`) }
+
+// App payload fingerprint — the deflate-b64 runtime blocks. Two decks with the
+// same hash embed the same shell (identical runtime), whatever their doc holds.
+const appHash = (html) => {
+ const blocks = [...html.matchAll(/type="bento\/deflate-b64"[^>]*>([A-Za-z0-9+/=]+)</g)].map((m) => m[1])
+ return blocks.length ? createHash('sha256').update(blocks.join('')).digest('hex') : null
+}
+
+const shellFile = opt('shell', null) ?? [
+ join(root, 'site/releases/slides/Bento_Slides.bento.html'),
+ join(root, 'slides/dist-single/Bento_Slides.bento.html'),
+].find(existsSync)
+if (!shellFile || !existsSync(shellFile)) { warn('no fresh shell found (run a build/release first)'); process.exit(0) }
+
+const keyFile = join(root, 'working/guestbook-admin-key.txt')
+if (!existsSync(keyFile)) { warn(`no admin key at ${keyFile.slice(root.length + 1)}`); process.exit(0) }
+const adminKey = readFileSync(keyFile, 'utf8').trim()
+if (!adminKey) { warn('admin key file is empty'); process.exit(0) }
+
+const base = (opt('base', 'https://bento.page')).replace(/\/$/, '')
+const freshShell = readFileSync(shellFile, 'utf8')
+const freshHash = appHash(freshShell)
+
+try {
+ // 1 · the daemon's OWN current deck (carries the live room creds + walls seed)
+ const curResp = await fetch(`${base}/guestbook.bento.html`, { headers: { 'cache-control': 'no-cache' } })
+ if (!curResp.ok) { warn(`daemon GET returned ${curResp.status}`); process.exit(0) }
+ const curHtml = await curResp.text()
+ const curHash = appHash(curHtml)
+
+ if (curHash && curHash === freshHash) {
+ console.log(`✓ guestbook daemon already on the current shell (${freshHash.slice(0, 12)}…) — nothing to do`)
+ process.exit(0)
+ }
+
+ // 2 · re-shell the daemon's doc onto the fresh shell (SAME room, SAME walls)
+ const doc = extractDoc(curHtml)
+ const reshelled = spliceDoc(freshShell, doc)
+ const room = doc.collab?.room?.split('/').pop() ?? '?'
+ console.log(`• guestbook daemon on ${curHash?.slice(0, 12) ?? '?'}… → re-shelling to ${freshHash.slice(0, 12)}… (room ${room}, epoch ${doc.guestbookEpoch ?? '?'})`)
+ if (dry) { console.log('(dry run — not seeding)'); process.exit(0) }
+
+ // 3 · seed it back (walls untouched: they live in the relay, not this deck)
+ const put = await fetch(`${base}/guestbook-admin/seed`, {
+ method: 'PUT',
+ headers: { 'Authorization': `Bearer ${adminKey}`, 'content-type': 'text/html' },
+ body: reshelled,
+ })
+ const bodyText = await put.text()
+ if (!put.ok) { warn(`seed PUT returned ${put.status}: ${bodyText.slice(0, 200)}`); process.exit(0) }
+ console.log(`✓ guestbook daemon re-seeded onto the current shell — ${bodyText.replace(/\s+/g, ' ').trim()}`)
+} catch (e) {
+ warn(String(e))
+ process.exit(0)
+}