Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

kernel: one "body is sealed" predicate, and the sealed TEST document (K3) (#780)

nyblnetb1609c9dc2bc
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 69e55ad3..64560fe0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -182,6 +182,13 @@ jobs:
# every derivation, every blob re-sealed byte for byte, every refusal.
run: node scripts/test-recovery.ts
+ - name: identity seal — one "body is sealed" predicate
+ # bento/id §E: every plaintext-to-disk guard asks isBodySealed(), not
+ # "is there a password". The identity-sealed body is a genuine bento/enc
+ # v1 envelope (kdf hkdf-kdoc) that frozen shells read as sealed; fresh
+ # salt per save; the password path unchanged; the two refuse each other.
+ run: node scripts/test-body-seal.ts
+
- name: Typecheck convert (standalone)
# convert/ is a library beside the apps (the CLI and bento.page/import
# use it; no shell does), so no app's tsc -b reaches it. Its own flags,
@@ -196,6 +203,16 @@ jobs:
- name: Splice conformance gate
run: node scripts/shell-gate.mjs slides/dist-single/Bento_Slides.bento.html
+ - name: The gate refuses a sealed TEST shell
+ # Positive control for the gate's no-test-seal check (security §31): the
+ # build:sealtest shell carries the sealed test document's key handoff,
+ # inside its deflated runtime, and must be refused for it; the release
+ # shell from the same source must pass.
+ working-directory: slides
+ run: |
+ npm run build:sealtest
+ node ../scripts/test-seal-gate.mjs
+
# spaces: a second app proving the kernel seam — same pipeline, same gate.
- name: Install (spaces)
working-directory: spaces
@@ -2523,6 +2540,14 @@ jobs:
run: |
npm ci --prefix slides
npm run build:single --prefix slides
+ npm run build:sealtest --prefix slides
+ - name: The sealed TEST document in Chromium
+ # bento/id §E (security §31): the shared helper boots the build:sealtest
+ # shell with the identity seal set before the app's own boot, proves it
+ # took, and the saved file carries an identity-sealed envelope, a
+ # neutral <title> and filename, no preview, and no plaintext; the
+ # unsealed control shows the same checks can see a leak.
+ run: node scripts/test-sealed-boot.mjs
- name: Exercise the packaged documents in Chromium
# Real UI and serialization, offline; delayed mock writes expose save races.
run: |
diff --git a/.gitignore b/.gitignore
index c34f5864..d709a6f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,8 @@
node_modules
dist/
dist-single/
+# sealed TEST shells (npm run build:sealtest): never shipped
+dist-sealtest/
# local test decks — never committed (may contain confidential content)
testing/
diff --git a/dash/package.json b/dash/package.json
index 9fbb5f48..c098f270 100644
--- a/dash/package.json
+++ b/dash/package.json
@@ -8,6 +8,7 @@
"dev": "vite",
"build": "tsc -b && vite build",
"build:single": "tsc -b && SINGLEFILE=1 vite build --outDir dist-single && mv dist-single/index.html dist-single/Bento_Dash.bento.html && node ../scripts/postbuild-compress.mjs dist-single/Bento_Dash.bento.html --generator bento-dash --title \"bento/dash\"",
+ "build:sealtest": "rm -rf dist-sealtest && tsc -b && SINGLEFILE=1 BENTO_TEST_SEAL=1 vite build --outDir dist-sealtest && mv dist-sealtest/index.html dist-sealtest/Bento_Dash.bento.html && node ../scripts/postbuild-compress.mjs dist-sealtest/Bento_Dash.bento.html --generator bento-dash --title \"bento/dash\"",
"preview": "vite preview"
},
"devDependencies": {
diff --git a/dash/vite.config.ts b/dash/vite.config.ts
index eb02eb39..63f028df 100644
--- a/dash/vite.config.ts
+++ b/dash/vite.config.ts
@@ -11,7 +11,14 @@ export default defineConfig({
base: './',
// The app version baked into every shipped shell — what update checks
// compare against the release manifest. Single source: package.json.
- define: { __APP_VERSION__: JSON.stringify(pkg.version) },
+ // __BENTO_TEST_SEAL__: the sealed TEST document's key handoff (kernel save.ts
+ // capturePristine). false, and so dead-code-eliminated, unless BENTO_TEST_SEAL=1
+ // (npm run build:sealtest, which writes dist-sealtest/, never dist-single/).
+ // shell-gate.mjs refuses any release shell that still carries it.
+ define: {
+ __APP_VERSION__: JSON.stringify(pkg.version),
+ __BENTO_TEST_SEAL__: JSON.stringify(process.env.BENTO_TEST_SEAL === '1'),
+ },
plugins: [...(process.env.SINGLEFILE ? [viteSingleFile()] : [])],
// Dev-only: allow serving ../kernel (shared TS-source kernel) — without a
// workspace root, vite's fs allow-list stops at the app dir. Build output
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md
index b0ddb07e..ffc19ab0 100644
--- a/docs/DECISIONS.md
+++ b/docs/DECISIONS.md
@@ -11137,6 +11137,36 @@ design's §2f (raw 32-byte scalars checked to lie in 1..n−1 and to match the
binding; the code is 16 Crockford base-32 characters plus a mod-37 check
symbol, and the 10 decoded bytes, never the string, feed the derivation).
+## 2026-10-18 — bento/id: one "body is sealed" predicate, and the sealed TEST document
+
+The kernel half of identity-kernel §E.2 (security §31):
+- **`isBodySealed()` is THE question for every plaintext-to-disk guard**
+ (recovery snapshots, version history, previews, filenames, native
+ indexes). It is true when the body is sealed by a password OR by the
+ identity seal. `isEncryptionActive()` stays, and means only "there is a
+ password": the password UI asks that, and a guard must not. A document sealed
+ to people has no password, so a guard asking the old question writes it to
+ disk in plaintext. Measured on slides before its guards switch: a sealed
+ deck's edit lands in both IndexedDB stores.
+- **`setIdentitySeal(kdoc)`** is synchronous, so the predicate is true from the
+ call on. It imports the 32-byte document key non-extractable as an HKDF base.
+ Each save draws a fresh 16-byte salt and IV, and bodyKey = HKDF(K_doc, salt,
+ "bento/body.v1"). The body is a GENUINE bento/enc v1 envelope with
+ `kdf:'hkdf-kdoc'`. Never v:2: an old shell's parseEnvelope would reject it,
+ boot the starter deck, and overwrite the sealed block on its next save. The
+ password path is unchanged and wins when both are set. Each path refuses the
+ other's envelope.
+- **The sealed TEST document is compiled only into test builds.** Phase 1 has no
+ real way to seal a document at boot (the per-recipient wraps are phase 2), so
+ `npm run build:sealtest` (→ `dist-sealtest/`) builds a shell whose
+ `capturePristine()` consumes a one-shot key handoff before any editor exists.
+ `scripts/lib/sealed-boot.mjs` is the one helper every app and security use. It
+ never runs in a release: in phase 1 nobody holds a wrap for such a body, so
+ one stray global would make a person's file unrecoverable. The flag
+ `__BENTO_TEST_SEAL__` is false in every release build and the minifier drops
+ the branch. shell-gate.mjs refuses any shell carrying the handoff's name,
+ scanning the deflated payloads too. `scripts/test-seal-gate.mjs` proves the
+ gate refuses a real test shell.
## 2026-10-18 — bento/id: the desktop agent's recovery code, key blobs and no-TPM store (home/desktop/agent)
Follows the desktop agent core entry above.
diff --git a/kernel/fixtures/README.md b/kernel/fixtures/README.md
index a9476ce1..19e8c91e 100644
--- a/kernel/fixtures/README.md
+++ b/kernel/fixtures/README.md
@@ -85,6 +85,16 @@ bytes end to end. Reference: `kernel/src/recovery.ts`. Rig:
invisible. On top of the table: NFC is required, at most 64 code points, and
ZWNJ/ZWJ (U+200C/U+200D) are allowed only mid-text. (home-desktop found the
drift; security added the unassigned code points.)
+- **Compare normalised text by code points, not by string equality, in Swift.**
+ Swift's `String ==` is canonical equivalence, so a decomposed `é` compares
+ equal to its NFC form and an NFC check written as `s == nfc(s)` passes text
+ that isn't NFC. Compare `unicodeScalars` instead. (home-ios, measured)
+- **Check a recovered private scalar with the platform's key constructor, never
+ bignum arithmetic.** It's a secret, and a hand-rolled d·G is variable-time on
+ it. CryptoKit's `P256.Signing.PrivateKey(rawRepresentation:)` refuses 0, n,
+ n+1 and 2^256−1 and accepts 1 and n−1 (home-ios, measured). The Rust `p256`
+ crate's `SecretKey::from_slice` is likewise constant-time (home-desktop).
+ Derive the public key from it and compare that to the bound key.
- **Compute NFC with Unicode 17.0 (or later) data.** Normalisation is stable
across versions only for assigned characters, and the table refuses
everything unassigned at 17.0. So any normaliser at 17.0 or later agrees on
diff --git a/kernel/src/save.ts b/kernel/src/save.ts
index f035f6b3..13fbbeb3 100644
--- a/kernel/src/save.ts
+++ b/kernel/src/save.ts
@@ -38,6 +38,41 @@ let pristine: Document | null = null
/** Call first thing at boot, before any DOM mutation. */
export function capturePristine() {
pristine = document.cloneNode(true) as Document
+ if (typeof __BENTO_TEST_SEAL__ !== 'undefined' && __BENTO_TEST_SEAL__) consumeTestSeal()
+}
+
+/**
+ * TEST BUILDS ONLY (security §31): the sealed TEST document's key handoff.
+ * Phase 1 has no real path that seals a document at boot (the per-recipient
+ * wraps are phase 2), yet all four apps' plaintext-to-disk guards must be
+ * exercised end to end against an identity-sealed document. A rig installs a
+ * one-shot global with the raw document key before the page loads (Playwright
+ * addInitScript, scripts/lib/sealed-boot.mjs). Every app calls capturePristine()
+ * at boot before its editor exists, so the seal is in place before any autosave
+ * can start: the §E.2 ordering invariant, by construction.
+ *
+ * NEVER in a release shell. In phase 1 nobody holds a wrap for such a body, so a
+ * stray global (an extension, a host user script, a future bug) would seal a
+ * person's file to a key no one can recover. Each app's vite config defines
+ * __BENTO_TEST_SEAL__ false unless BENTO_TEST_SEAL=1, the minifier drops this
+ * branch, and the release conformance gate (shell-gate.mjs) refuses any shell
+ * containing the global's name.
+ */
+declare const __BENTO_TEST_SEAL__: boolean | undefined
+function consumeTestSeal() {
+ const g = globalThis as { __bentoTestSeal?: unknown; __bentoTestSealProbe?: unknown }
+ const key = g.__bentoTestSeal
+ delete g.__bentoTestSeal
+ if (!(key instanceof Uint8Array)) return
+ setIdentitySeal(key)
+ // What the rigs read back: did the seal take, and what would a save write?
+ // (Its name carries the same mark, so the gate refuses it in a release too.)
+ g.__bentoTestSealProbe = Object.freeze({
+ sealed: () => isBodySealed(),
+ body: (doc: KernelDoc) => encodeDocBody(doc),
+ file: (doc: KernelDoc) => serializeAuto(doc),
+ fileName: (doc: KernelDoc) => suggestedFileName(doc),
+ })
}
export function readEmbeddedDoc(): string | null {
@@ -236,7 +271,7 @@ export function registerPreview(fn: PreviewProvider): void {
* Pure and exported so `scripts/test-preview.ts` can exercise it directly —
* the surrounding DOM work is not unit-testable in node, this decision is.
*/
-export function previewAllowed(body: string, encrypted = isEncryptionActive()): boolean {
+export function previewAllowed(body: string, encrypted = isBodySealed()): boolean {
return !encrypted && parseEnvelope(body) === null
}
@@ -415,7 +450,10 @@ export function serializeFile(doc: KernelDoc): string {
export interface EncEnvelope {
format: 'bento/enc'
v: 1
- it: number
+ /** PBKDF2 rounds (password envelopes) */
+ it?: number
+ /** 'hkdf-kdoc' = identity-sealed (§E.1): opened by the document key, never a password */
+ kdf?: 'hkdf-kdoc'
salt: string
iv: string
data: string
@@ -462,6 +500,36 @@ export function setEncryptionPassword(p: string | null) {
export const isEncryptionActive = () => encPassword !== null
+/**
+ * The identity seal (identity-kernel §E.2): K_doc as an HKDF base key, set when
+ * a person's agent unwraps the document key, cleared on lock. With no password
+ * set, every save seals the body under it (encodeDocBody).
+ */
+let sealBodyKey: Promise<CryptoKey> | null = null
+
+/**
+ * Set (or clear with null) the identity seal. `kdoc` is the raw 32-byte
+ * document key, imported NON-EXTRACTABLE as an HKDF base. Synchronous on
+ * purpose: isBodySealed() is true from this call on, before the import settles,
+ * so no guard can slip a plaintext write into that gap. A failed import fails
+ * every later save closed rather than letting it write plaintext.
+ */
+export function setIdentitySeal(kdoc: Uint8Array | null): void {
+ if (kdoc === null) { sealBodyKey = null; return }
+ if (!(kdoc instanceof Uint8Array) || kdoc.length !== 32) throw new Error('the document key is 32 bytes')
+ sealBodyKey = crypto.subtle.importKey('raw', kdoc.slice() as BufferSource, 'HKDF', false, ['deriveKey'])
+}
+
+/**
+ * Is the body sealed on disk, by a password OR the identity seal? THE question
+ * for every plaintext-to-disk guard (recovery snapshots, version history,
+ * previews, the filename). `isEncryptionActive()` answers only "is there a
+ * password", which is what the password UI wants and what a guard must not ask:
+ * an identity-sealed document has no password, so a guard reading that flag
+ * writes it to disk in plaintext.
+ */
+export const isBodySealed = () => encPassword !== null || sealBodyKey !== null
+
/** Parse a data-block body as an encryption envelope; null if it is not one. */
export function parseEnvelope(text: string): EncEnvelope | null {
try {
@@ -498,6 +566,48 @@ async function encryptBody(json: string, password: string): Promise<string> {
return JSON.stringify(env)
}
+const BODY_INFO = new TextEncoder().encode('bento/body.v1')
+
+/** bodyKey = HKDF-SHA-256(K_doc, salt, "bento/body.v1") as an AES-256-GCM key. */
+const bodyKeyFor = (kdoc: CryptoKey, salt: Uint8Array) => crypto.subtle.deriveKey(
+ { name: 'HKDF', hash: 'SHA-256', salt: salt as BufferSource, info: BODY_INFO as BufferSource },
+ kdoc, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])
+
+/**
+ * The identity-sealed body: a GENUINE bento/enc v1 envelope (§E.1), so frozen
+ * shells, previewAllowed and convert all read it as sealed. Never v:2, never
+ * without salt: an old parseEnvelope would reject it, boot the starter deck, and a
+ * later save would overwrite the sealed block. `salt` is the real HKDF salt,
+ * fresh on every save as the password path's is, and `kdf` (ignored by old
+ * shells) says which key opens it.
+ */
+async function sealBody(json: string, kdoc: CryptoKey): Promise<string> {
+ const salt = new Uint8Array(16)
+ const iv = new Uint8Array(12)
+ crypto.getRandomValues(salt)
+ crypto.getRandomValues(iv)
+ const ct = await crypto.subtle.encrypt(
+ { name: 'AES-GCM', iv: iv as BufferSource }, await bodyKeyFor(kdoc, salt), new TextEncoder().encode(json))
+ const env: EncEnvelope = {
+ format: 'bento/enc', v: 1, kdf: 'hkdf-kdoc',
+ salt: eb64.enc(salt), iv: eb64.enc(iv), data: eb64.enc(new Uint8Array(ct)),
+ }
+ return JSON.stringify(env)
+}
+
+/** Open an identity-sealed envelope with the raw document key; null if it isn't one or the key is wrong. */
+export async function openIdentitySealed(env: EncEnvelope, kdoc: Uint8Array): Promise<string | null> {
+ if (env.kdf !== 'hkdf-kdoc') return null
+ try {
+ const base = await crypto.subtle.importKey('raw', kdoc as BufferSource, 'HKDF', false, ['deriveKey'])
+ const pt = await crypto.subtle.decrypt(
+ { name: 'AES-GCM', iv: eb64.dec(env.iv) as BufferSource }, await bodyKeyFor(base, eb64.dec(env.salt)), eb64.dec(env.data) as BufferSource)
+ return new TextDecoder().decode(pt)
+ } catch {
+ return null
+ }
+}
+
/** Decrypt an envelope with a candidate password; null on wrong password. */
export async function decryptEnvelope(env: EncEnvelope, password: string): Promise<string | null> {
try {
@@ -521,7 +631,9 @@ export async function decryptEnvelope(env: EncEnvelope, password: string): Promi
* it is DOM-free, so it is the seam a rig can drive the real write path with.
*/
export async function encodeDocBody(doc: KernelDoc): Promise<string> {
- return encPassword ? encryptBody(JSON.stringify(doc), encPassword) : JSON.stringify(doc)
+ if (encPassword) return encryptBody(JSON.stringify(doc), encPassword)
+ if (sealBodyKey) return sealBody(JSON.stringify(doc), await sealBodyKey)
+ return JSON.stringify(doc)
}
export async function serializeDocInto(shell: Document, doc: KernelDoc): Promise<string> {
@@ -538,7 +650,7 @@ export function suggestedFileName(doc: KernelDoc, suffix = ''): string {
// An encrypted deck should not carry its title in the download filename
// either — use a neutral default (the app name). The real title is kept in the
// live tab and returns to the filename once the password is cleared.
- const source = isEncryptionActive() ? appConfig().appName : doc.title
+ const source = isBodySealed() ? appConfig().appName : doc.title
const base = source.replace(/[^\w\d-]+/g, '_').replace(/^_+|_+$/g, '') || 'Untitled'
return `${base}${suffix ? `-${suffix}` : ''}.bento.html`
}
diff --git a/scripts/lib/sealed-boot.mjs b/scripts/lib/sealed-boot.mjs
new file mode 100644
index 00000000..0f61f89c
--- /dev/null
+++ b/scripts/lib/sealed-boot.mjs
@@ -0,0 +1,156 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+//
+// THE sealed TEST document, one helper for every app (security §31): slides,
+// spaces, dash, type and security's run-it check all exercise the same thing.
+//
+// It boots an app's TEST shell (npm run build:sealtest → dist-sealtest/, the
+// only build that carries the key handoff) with the identity seal set BEFORE the
+// app's own boot runs: the key is installed with addInitScript, and the kernel
+// consumes it in capturePristine(), before any editor or autosave exists. Then it
+// PROVES the seal took effect before a rig checks a single guard, because a
+// guard check against a document that was never sealed passes vacuously.
+//
+// import { openSealed, scanIndexedDB } from './lib/sealed-boot.mjs'
+// const { page, reload } = await openSealed(browser, 'slides', { doc }) // doc optional
+// ...edit the document, wait out the autosave debounce...
+// assert.deepEqual(await scanIndexedDB(page, MARKER), [])
+//
+// Every rig that uses it should also run its edit on an UNSEALED page
+// (openSealed(browser, app, { sealed: false })) and see the marker land in
+// IndexedDB: the positive control that the scan can see a leak at all.
+
+import { existsSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { pathToFileURL } from 'node:url'
+
+const SHELLS = {
+ slides: 'slides/dist-sealtest/Bento_Slides.bento.html',
+ spaces: 'spaces/dist-sealtest/Bento_Spaces.bento.html',
+ dash: 'dash/dist-sealtest/Bento_Dash.bento.html',
+ type: 'type/dist-sealtest/Bento_Type.bento.html',
+}
+
+/** A fixed TEST document key. Never a real one: the bodies it seals are throwaway. */
+export const TEST_KDOC = Array.from({ length: 32 }, (_, i) => (i * 7 + 3) & 0xff)
+
+/**
+ * The test shell for an app, by explicit path. Never a release (dist-single)
+ * shell. build:sealtest deletes dist-sealtest/ before it compiles, so a build
+ * that fails leaves NO shell rather than the previous one: a mutation that does
+ * not compile can't be scored against stale code (type and dash both hit this).
+ */
+export function sealtestShell(app) {
+ const rel = SHELLS[app]
+ if (!rel) throw new Error(`sealed-boot: no such app ${app}`)
+ const url = new URL(`../../${rel}`, import.meta.url)
+ if (!existsSync(url)) throw new Error(`sealed-boot: no ${rel}. Run npm run build:sealtest --prefix ${app}, and check its exit code: a failed build leaves no shell`)
+ return url
+}
+
+/**
+ * The test shell with a FIXED document in its #bento-doc block, written to a
+ * temp file. For rigs that need the same docId across reloads (recovery is keyed
+ * by docId; a fresh shell mints a new one each load). Plaintext JSON, `<`-escaped
+ * as every save writes it. The seal is still applied at boot by the handoff.
+ */
+export function sealtestShellWith(app, doc) {
+ const html = readFileSync(sealtestShell(app), 'utf8')
+ const open = '<scr' + 'ipt type="application/bento+json" id="bento-doc">'
+ const close = '</scr' + 'ipt>'
+ const at = html.indexOf(open)
+ const end = at < 0 ? -1 : html.indexOf(close, at + open.length)
+ if (at < 0 || end < 0) throw new Error(`sealed-boot: no #bento-doc block in ${app}'s test shell`)
+ const json = (typeof doc === 'string' ? doc : JSON.stringify(doc)).replace(/</g, '\\u003c')
+ const out = join(mkdtempSync(join(tmpdir(), 'bento-sealed-')), `${app}.bento.html`)
+ writeFileSync(out, html.slice(0, at + open.length) + json + html.slice(end))
+ return pathToFileURL(out)
+}
+
+/**
+ * Open `app`'s test shell, sealed (the default) or not. Resolves once the app has
+ * booted and, when sealed, once the seal is proven: the probe says sealed, and a
+ * save of the live document would write an identity-sealed envelope.
+ *
+ * `doc` boots a fixed document instead of the app's starter (sealtestShellWith).
+ * `reload()` on the result reloads the same page, keeping its seal state, with
+ * the handoff installed again and the state proven again.
+ * `context` opens the page in an existing context, so it shares that context's
+ * IndexedDB, and `url` reopens a file an earlier call returned. Together: an
+ * unsealed session leaves a plaintext snapshot, then
+ * openSealed(browser, app, { context: first.context, url: first.url })
+ * boots the SAME document SEALED on the same storage, which must refuse it.
+ */
+export async function openSealed(browser, app, { sealed = true, kdoc = TEST_KDOC, doc, url, context, viewport = { width: 1280, height: 900 } } = {}) {
+ if (!context) {
+ context = await browser.newContext({ viewport })
+ await context.route(/^https?:/, (route) => route.abort())
+ }
+ const page = await context.newPage()
+ // per PAGE, not per context: a second openSealed on the same context (same
+ // IndexedDB) can then boot the other seal state, and no page inherits a key
+ if (sealed) await page.addInitScript((k) => { globalThis.__bentoTestSeal = new Uint8Array(k) }, kdoc)
+ const errors = []
+ page.on('pageerror', (e) => errors.push(e.message))
+ url ??= (doc === undefined ? sealtestShell(app) : sealtestShellWith(app, doc)).href
+ await page.goto(url)
+ await provenState(page, app, sealed)
+ const reload = async () => { await page.reload(); await provenState(page, app, sealed) }
+ return { context, page, errors, url, reload }
+}
+
+/** Wait for boot, then prove the seal state matches `sealed`; throw otherwise. */
+async function provenState(page, app, sealed) {
+ await page.waitForFunction(() => window.bento?.doc, null, { timeout: 30000 })
+ const state = await page.evaluate(async () => {
+ const p = globalThis.__bentoTestSealProbe
+ if (!p) return { probe: false, handoffLeft: '__bentoTestSeal' in globalThis }
+ let env = null
+ try { env = JSON.parse(await p.body(window.bento.doc)) } catch { /* not JSON: not an envelope */ }
+ return { probe: true, sealed: p.sealed(), kdf: env?.kdf ?? null, v: env?.v ?? null, handoffLeft: '__bentoTestSeal' in globalThis }
+ })
+ if (state.handoffLeft) throw new Error(`sealed-boot: ${app} never consumed the key handoff (is this a build:sealtest shell?)`)
+ if (sealed) {
+ if (!state.probe) throw new Error(`sealed-boot: ${app} has no seal probe: not a build:sealtest shell, or the seal was never consumed`)
+ if (!state.sealed) throw new Error(`sealed-boot: ${app} booted but isBodySealed() is false`)
+ if (state.kdf !== 'hkdf-kdoc' || state.v !== 1) throw new Error(`sealed-boot: ${app}'s save would not write an identity-sealed v1 envelope (kdf=${state.kdf}, v=${state.v})`)
+ } else if (state.probe) {
+ throw new Error(`sealed-boot: ${app} is sealed although no key was handed over`)
+ }
+}
+
+/** What a save would write: the whole file, its suggested name, and the #bento-doc body. Sealed pages only. */
+export async function savedFile(page) {
+ return page.evaluate(async () => {
+ const p = globalThis.__bentoTestSealProbe
+ return { file: await p.file(window.bento.doc), fileName: p.fileName(window.bento.doc), body: await p.body(window.bento.doc) }
+ })
+}
+
+/**
+ * Every IndexedDB record in the page's origin whose JSON contains `marker`, as
+ * `db/store` strings. [] means no plaintext copy of the marker is on disk.
+ */
+export async function scanIndexedDB(page, marker) {
+ return page.evaluate(async (m) => {
+ const hits = []
+ const dbs = (await indexedDB.databases()).map((d) => d.name).filter(Boolean)
+ for (const name of dbs) {
+ const db = await new Promise((res, rej) => { const r = indexedDB.open(name); r.onsuccess = () => res(r.result); r.onerror = () => rej(r.error) })
+ for (const store of db.objectStoreNames) {
+ const all = await new Promise((res, rej) => {
+ const r = db.transaction(store, 'readonly').objectStore(store).getAll()
+ r.onsuccess = () => res(r.result); r.onerror = () => rej(r.error)
+ })
+ for (const rec of all) {
+ let text
+ try { text = JSON.stringify(rec) } catch { text = String(rec) }
+ if (text.includes(m)) { hits.push(`${name}/${store}`); break }
+ }
+ }
+ db.close()
+ }
+ return hits
+ }, marker)
+}
diff --git a/scripts/shell-gate.mjs b/scripts/shell-gate.mjs
index 7aa0b4cf..e3903bf6 100644
--- a/scripts/shell-gate.mjs
+++ b/scripts/shell-gate.mjs
@@ -450,9 +450,26 @@ function checkPreviewRulesAreImplemented() {
fail('kernel/src/save.ts no longer places the remover immediately after the preview — a frame could paint between the two')
}
+// A FOURTH invariant (security §31): no release shell carries the sealed TEST
+// document's key handoff. That hook seals a body to a key nobody holds a wrap
+// for in phase 1, so in a person's shell one stray global would make their file
+// unrecoverable. It is compiled only into `npm run build:sealtest` shells; this
+// scans the file AND every inflated payload, because the runtime ships deflated
+// and a plain scan of the HTML would never see it.
+const TEST_SEAL_MARK = '__bento' + 'TestSeal'
+
+/** Throws if the shell (or any payload inside it) carries the test-seal hook. */
+export function checkNoTestSeal(html, label = 'shell') {
+ if (html.includes(TEST_SEAL_MARK)) fail(`the ${label} carries the sealed-test key handoff (${TEST_SEAL_MARK}): a build:sealtest shell, never a release`)
+ for (const [id, text] of inflatePayloads(html)) {
+ if (text.includes(TEST_SEAL_MARK)) fail(`payload #${id} carries the sealed-test key handoff (${TEST_SEAL_MARK}): a build:sealtest shell, never a release (${label})`)
+ }
+}
+
/** Throws with a GATE: message on the first violated invariant. */
export function gateShell(shellPath) {
const shell = readFileSync(shellPath, 'utf8')
+ checkNoTestSeal(shell)
checkSpliceContract(shell, 'shell')
checkDataBlocks(shell, 'shell')
checkPackCarryingShell(shell)
@@ -462,7 +479,7 @@ export function gateShell(shellPath) {
checkEscapeIsImplemented()
checkPreviewRulesAreImplemented()
console.log(
- 'conformance gate: old-updater splice contract OK (incl. pack- and preview-carrying shells)' +
+ 'conformance gate: old-updater splice contract OK (incl. pack- and preview-carrying shells); no test-seal hook' +
(compressed ? '; runtime ships deflated only' : ''),
)
}
diff --git a/scripts/test-body-seal.ts b/scripts/test-body-seal.ts
new file mode 100644
index 00000000..efd6c98e
--- /dev/null
+++ b/scripts/test-body-seal.ts
@@ -0,0 +1,114 @@
+#!/usr/bin/env node
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+// The identity seal (identity-kernel §E): one "body is sealed" predicate, and a
+// sealed body that every shell, frozen or new, reads as sealed.
+//
+// node scripts/test-body-seal.ts
+//
+// WHY. Every plaintext-to-disk guard in the apps (recovery snapshots, version
+// history, previews, the filename) asked isEncryptionActive(): "is there a
+// PASSWORD". A document sealed to people rather than a password has none, so
+// each of those guards would write it to IndexedDB, or into the file beside the
+// ciphertext, in plaintext. isBodySealed() is the question they must ask.
+//
+// And the sealed body must be a GENUINE bento/enc v1 envelope. Frozen shells'
+// parseEnvelope accepts only v1 with salt, iv and data. Anything else and an old
+// shell boots the starter deck in its place, and its next save overwrites the
+// sealed block: data loss.
+
+import { configureApp } from '../kernel/src/app.ts'
+import {
+ setIdentitySeal, isBodySealed, isEncryptionActive, setEncryptionPassword, encodeDocBody,
+ parseEnvelope, previewAllowed, openIdentitySealed, decryptEnvelope, suggestedFileName,
+} from '../kernel/src/save.ts'
+
+let failures = 0
+let checks = 0
+function ok(cond: boolean, msg: string) {
+ checks++
+ if (!cond) { failures++; console.log(` FAIL ${msg}`) }
+ else console.log(` ok ${msg}`)
+}
+
+configureApp({ appId: 'bento-test', appName: 'Bento Test', manifestUrl: 'https://invalid.example/m.json' })
+const TITLE = 'ZZ Secret Title ZZ'
+const doc = { format: 'bento/test', docId: '00000000-0000-4000-8000-000000000000', title: TITLE, body: 'ZZSECRETBODYZZ' } as never
+const kdoc = Uint8Array.from({ length: 32 }, (_, i) => i + 1)
+const other = Uint8Array.from({ length: 32 }, (_, i) => 0xff - i)
+
+console.log('\nbefore any seal: plaintext, as today')
+ok(!isBodySealed() && !isEncryptionActive(), 'nothing is sealed')
+{
+ const body = await encodeDocBody(doc)
+ ok(parseEnvelope(body) === null && body.includes('ZZSECRETBODYZZ'), 'the body is the plain document JSON')
+ ok(suggestedFileName(doc).startsWith('ZZ_Secret_Title_ZZ'), 'the filename carries the title')
+ ok(previewAllowed(body), 'a preview is allowed')
+}
+
+console.log('\nthe identity seal, with no password')
+setIdentitySeal(kdoc)
+ok(isBodySealed(), 'isBodySealed() is true')
+ok(!isEncryptionActive(), 'isEncryptionActive() stays false: there is no password (the password UI is unchanged)')
+{
+ const body = await encodeDocBody(doc)
+ const env = parseEnvelope(body)
+ ok(env !== null, "the frozen shells' parseEnvelope accepts it (a genuine v1 envelope)")
+ ok(env?.v === 1 && env?.format === 'bento/enc' && !!env.salt && !!env.iv && !!env.data, 'v1, with real salt, iv and data')
+ ok(env?.kdf === 'hkdf-kdoc' && env?.it === undefined, "kdf: 'hkdf-kdoc', and no PBKDF2 rounds")
+ ok(!body.includes('ZZSECRETBODYZZ') && !body.includes(TITLE), 'neither the body nor the title is in it')
+ ok(!previewAllowed(body), 'no preview: the envelope vetoes it')
+ ok(!previewAllowed('{"plain":true}'), "no preview even for a plain body while sealed (previewAllowed's default is isBodySealed)")
+ ok(suggestedFileName(doc) === 'Bento_Test.bento.html', 'the filename is neutral (the app name)')
+ ok(suggestedFileName(doc, 'copy') === 'Bento_Test-copy.bento.html', 'and with a suffix')
+
+ // guarded, so a broken seal reports every row rather than crashing the rig
+ const back = env ? await openIdentitySealed(env, kdoc) : null
+ ok(back !== null && JSON.parse(back).body === 'ZZSECRETBODYZZ', 'the document key opens it to the document')
+ ok(!!env && (await openIdentitySealed(env, other)) === null, 'another key does not')
+ ok(!!env && (await decryptEnvelope(env, 'any password')) === null, 'no password opens it')
+ ok(!!env && (await openIdentitySealed({ ...env, kdf: undefined }, kdoc)) === null, 'without its kdf marker it is not opened as identity-sealed')
+
+ const again = parseEnvelope(await encodeDocBody(doc))
+ ok(!!env && !!again && again.data !== env.data, 'two saves of the same document share no ciphertext')
+ ok(!!env && !!again && again.salt !== env.salt && again.iv !== env.iv, 'every save draws a fresh salt and iv (a fresh body key)')
+}
+
+console.log('\nthe two paths refuse each other')
+{
+ setEncryptionPassword('correct horse')
+ const pw = parseEnvelope(await encodeDocBody(doc))
+ setEncryptionPassword(null)
+ ok(!!pw && (await openIdentitySealed(pw, kdoc)) === null, 'a password envelope offered to the document key is refused')
+ ok(!!pw && (await decryptEnvelope(pw, 'correct horse')) !== null, 'control: the password does open it')
+}
+
+console.log('\nsynchronous: sealed from the call, before the key import settles')
+setIdentitySeal(null)
+setIdentitySeal(kdoc)
+ok(isBodySealed(), 'isBodySealed() is true in the same tick as setIdentitySeal()')
+{
+ const pending = encodeDocBody(doc)
+ ok(parseEnvelope(await pending)?.kdf === 'hkdf-kdoc', 'a save started in that tick is sealed')
+}
+
+console.log('\na password set as well: the password path, unchanged')
+setEncryptionPassword('correct horse')
+{
+ const env = parseEnvelope(await encodeDocBody(doc))!
+ ok(isBodySealed() && isEncryptionActive(), 'both predicates are true')
+ ok(env.kdf === undefined && typeof env.it === 'number', 'the body is a PBKDF2 envelope (the password wins, as today)')
+ ok((await decryptEnvelope(env, 'correct horse')) !== null, 'and the password opens it')
+}
+setEncryptionPassword(null)
+
+console.log('\nclearing the seal')
+setIdentitySeal(null)
+ok(!isBodySealed(), 'isBodySealed() is false again')
+ok(parseEnvelope(await encodeDocBody(doc)) === null, 'saves are plaintext again')
+let threw = false
+try { setIdentitySeal(new Uint8Array(16)) } catch { threw = true }
+ok(threw && !isBodySealed(), 'a document key that is not 32 bytes is refused, and seals nothing')
+
+console.log(`\n${checks - failures}/${checks} checks passed`)
+process.exit(failures ? 1 : 0)
diff --git a/scripts/test-enc-title.ts b/scripts/test-enc-title.ts
index a0ec2720..e4f0eb9a 100644
--- a/scripts/test-enc-title.ts
+++ b/scripts/test-enc-title.ts
@@ -14,7 +14,7 @@
// TWO LAYERS, because a DOM is not always present:
// 1. SOURCE GATE (always runs, including CI): serializeBody neutralises the
// <title> under the same veto as the preview (previewAllowed(body)), and
-// suggestedFileName neutralises the filename under isEncryptionActive().
+// suggestedFileName neutralises the filename under isBodySealed().
// This is the regression guard CI enforces and the mutation target.
// 2. FILE SCAN (only where jsdom is installed — locally and in a browser, not
// CI, matching scripts/test-type-preview.ts): actually serialize an
@@ -46,9 +46,11 @@ console.log('\n— source gate: the encrypted-output neutralisation is in place
ok(/titleEl\.textContent\s*=\s*previewAllowed\(body\)\s*\?[\s\S]{0,120}:\s*appConfig\(\)\.appName/.test(src),
'serializeBody neutralises <title> when the output is encrypted (previewAllowed veto)')
- // The suggested filename is gated on isEncryptionActive(): neutral when encrypted.
- ok(/isEncryptionActive\(\)\s*\?\s*appConfig\(\)\.appName\s*:\s*doc\.title/.test(src),
- 'suggestedFileName neutralises the download name when the password is active')
+ // The suggested filename is gated on isBodySealed(): neutral when the body is
+ // sealed by a password OR the identity seal. isEncryptionActive() is only the
+ // password, so gating on it named an identity-sealed file after its title.
+ ok(/isBodySealed\(\)\s*\?\s*appConfig\(\)\.appName\s*:\s*doc\.title/.test(src),
+ 'suggestedFileName neutralises the download name when the body is sealed')
}
// ───────────────────────────────────────────── 2. FILE SCAN (needs a DOM)
diff --git a/scripts/test-seal-gate.mjs b/scripts/test-seal-gate.mjs
new file mode 100644
index 00000000..2797c2a6
--- /dev/null
+++ b/scripts/test-seal-gate.mjs
@@ -0,0 +1,36 @@
+#!/usr/bin/env node
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+//
+// The release gate refuses a sealed TEST shell, and passes the release shell
+// built from the same source (security §31). This is the positive control for
+// shell-gate.mjs's checkNoTestSeal: a gate that never sees the hook would pass
+// every release shell vacuously. The test shell must be refused FOR THE HOOK,
+// not for anything else, and the release shell must pass because the build
+// removed the hook, not because the scan missed it.
+//
+// npm run build:single --prefix slides && npm run build:sealtest --prefix slides
+// node scripts/test-seal-gate.mjs
+
+import { readFileSync } from 'node:fs'
+import { gateShell, checkNoTestSeal } from './shell-gate.mjs'
+
+const release = new URL('../slides/dist-single/Bento_Slides.bento.html', import.meta.url)
+const sealtest = new URL('../slides/dist-sealtest/Bento_Slides.bento.html', import.meta.url)
+
+let failures = 0, checks = 0
+const ok = (cond, what) => { checks++; if (cond) console.log(' ok ' + what); else { failures++; console.log(' FAIL ' + what) } }
+const refusal = (fn) => { try { fn(); return null } catch (e) { return String(e.message) } }
+
+const testHtml = readFileSync(sealtest, 'utf8')
+const releaseHtml = readFileSync(release, 'utf8')
+
+const r1 = refusal(() => gateShell(sealtest.pathname))
+ok(r1 !== null && r1.includes('sealed-test key handoff'), `the full gate refuses the build:sealtest shell, for the hook (${r1 ?? 'passed'})`)
+ok(r1 !== null && r1.includes('payload #'), 'it found the hook INSIDE a deflated payload: a plain scan of the HTML would not')
+ok(!testHtml.includes('__bento' + 'TestSeal'), 'control: the hook is not visible in the raw HTML of the test shell')
+ok(refusal(() => checkNoTestSeal(releaseHtml)) === null, 'the release shell carries no hook')
+ok(refusal(() => gateShell(release.pathname)) === null, 'the full gate passes the release shell')
+
+console.log(`\n${checks - failures}/${checks} checks passed`)
+process.exit(failures ? 1 : 0)
diff --git a/scripts/test-sealed-boot.mjs b/scripts/test-sealed-boot.mjs
new file mode 100644
index 00000000..54ae0055
--- /dev/null
+++ b/scripts/test-sealed-boot.mjs
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+//
+// THE SEALED TEST DOCUMENT, end to end on a real built shell (security §31).
+// Proves the shared helper (scripts/lib/sealed-boot.mjs) and the KERNEL's sinks
+// against slides' build:sealtest shell:
+// - the seal is in place before the app's boot, and the handoff is consumed;
+// - a save writes an identity-sealed v1 envelope, a neutral <title>, a neutral
+// filename, no preview, and neither the title nor the content anywhere;
+// - the unsealed control writes the title, so these checks can see a leak.
+// It also MEASURES what reaches IndexedDB after an edit, sealed and unsealed.
+// That's each app's guard, switched in its own PR, so it is reported here and
+// asserted there.
+//
+// npm run build:sealtest --prefix slides && node scripts/test-sealed-boot.mjs
+
+import { openSealed, savedFile, scanIndexedDB } from './lib/sealed-boot.mjs'
+
+const { chromium } = await import(process.env.PLAYWRIGHT_MODULE || 'playwright')
+const MARK = 'ZZSEALEDMARK' + Date.now()
+let failures = 0, checks = 0
+const ok = (cond, what) => { checks++; if (cond) console.log(' ok ' + what); else { failures++; console.log(' FAIL ' + what) } }
+
+const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH, headless: true })
+
+/** Give the live document a marked title and slide text, as an edit would. */
+async function markDocument(page) {
+ await page.evaluate((m) => {
+ const d = structuredClone(window.bento.doc)
+ d.title = m
+ const el = d.slides?.[0]?.elements?.find((e) => e.type === 'text')
+ if (el) el.html = `<p>${m}</p>`
+ window.bento.loadDoc(JSON.stringify(d))
+ }, MARK)
+ await page.waitForTimeout(4000) // past the 2.5s autosave debounce
+}
+
+try {
+ console.log('\nsealed')
+ {
+ const { page, context, errors } = await openSealed(browser, 'slides')
+ ok(true, 'the seal took before boot: probe sealed, a save would write kdf hkdf-kdoc v1 (openSealed asserts these)')
+ await markDocument(page)
+ const { file, fileName, body } = await savedFile(page)
+ const env = JSON.parse(body)
+ ok(env.format === 'bento/enc' && env.v === 1 && env.kdf === 'hkdf-kdoc' && !!env.salt && !!env.iv && !!env.data, 'the saved body is an identity-sealed v1 envelope')
+ ok(!file.includes(MARK), 'the saved FILE carries neither the title nor the content, anywhere')
+ ok(/<title>[^<]*<\/title>/.test(file) && !/<title>[^<]*ZZSEALED/.test(file), 'the <title> is neutral')
+ ok(!file.includes('data-bento-preview'), 'no first-page preview')
+ ok(!fileName.includes(MARK), `the filename is neutral, not the title (${fileName})`)
+ const idb = await scanIndexedDB(page, MARK)
+ console.log(` info IndexedDB records carrying the content after an edit, sealed: ${idb.length ? idb.join(', ') : 'none'}`)
+ ok(errors.length === 0, `no page errors${errors.length ? ': ' + errors[0] : ''}`)
+ await context.close()
+ }
+
+ console.log('\na fixed document, across a reload (for recovery rows keyed by docId)')
+ {
+ const base = await openSealed(browser, 'slides', { sealed: false })
+ const doc = await base.page.evaluate((m) => ({ ...structuredClone(window.bento.doc), title: m }), MARK)
+ await base.context.close()
+ const { page, context, reload } = await openSealed(browser, 'slides', { doc })
+ const first = await page.evaluate(() => ({ id: window.bento.doc.docId, title: window.bento.doc.title }))
+ ok(first.id === doc.docId && first.title === MARK, 'the fixed document booted, sealed, with its own docId')
+ await reload() // re-installs the handoff and re-proves the seal, or throws
+ const again = await page.evaluate(() => window.bento.doc.docId)
+ ok(again === doc.docId, 'after reload(): the same docId, and the seal proven again')
+ await context.close()
+ }
+
+ console.log('\nboth seal states on ONE storage (a sealed boot after an unsealed session)')
+ {
+ const plain = await openSealed(browser, 'slides', { sealed: false })
+ await markDocument(plain.page)
+ ok((await scanIndexedDB(plain.page, MARK)).length > 0, 'the unsealed session leaves the marker in IndexedDB')
+ const docId = await plain.page.evaluate(() => window.bento.doc.docId)
+ const sealedPage = await openSealed(browser, 'slides', { context: plain.context, url: plain.url })
+ ok((await scanIndexedDB(sealedPage.page, MARK)).length > 0, 'a sealed page on the same context sees the same storage')
+ ok(await sealedPage.page.evaluate(() => !!globalThis.__bentoTestSealProbe), 'and it is sealed (the handoff is per page)')
+ await plain.reload()
+ ok(await plain.page.evaluate(() => !('__bentoTestSealProbe' in globalThis)), 'the unsealed page reloads unsealed: no page inherits a key')
+ ok(typeof docId === 'string', 'control: the session had a docId')
+ await plain.context.close()
+ }
+
+ console.log('\nunsealed control (same test shell, no key handed over)')
+ {
+ const { page, context } = await openSealed(browser, 'slides', { sealed: false })
+ ok(await page.evaluate(() => !('__bentoTestSealProbe' in globalThis)), 'no seal without the handoff')
+ await markDocument(page)
+ const file = await page.evaluate(() => window.bento.serialize())
+ ok(file.includes(MARK), 'control: the unsealed file DOES carry the marker, so the file checks can see a leak')
+ const idb = await scanIndexedDB(page, MARK)
+ ok(idb.length > 0, `control: the unsealed edit DOES reach IndexedDB (${idb.join(', ') || 'none'}), so the scan can see a leak`)
+ await context.close()
+ }
+} finally {
+ await browser.close()
+}
+
+console.log(`\n${checks - failures}/${checks} checks passed`)
+process.exit(failures ? 1 : 0)
diff --git a/slides/package.json b/slides/package.json
index 6ee9259b..6251e42e 100644
--- a/slides/package.json
+++ b/slides/package.json
@@ -8,6 +8,7 @@
"dev": "vite",
"build": "tsc -b && vite build",
"build:single": "tsc -b && SINGLEFILE=1 vite build --outDir dist-single && mv dist-single/index.html dist-single/Bento_Slides.bento.html && node ../scripts/postbuild-compress.mjs dist-single/Bento_Slides.bento.html",
+ "build:sealtest": "rm -rf dist-sealtest && tsc -b && SINGLEFILE=1 BENTO_TEST_SEAL=1 vite build --outDir dist-sealtest && mv dist-sealtest/index.html dist-sealtest/Bento_Slides.bento.html && node ../scripts/postbuild-compress.mjs dist-sealtest/Bento_Slides.bento.html",
"preview": "vite preview"
},
"dependencies": {
diff --git a/slides/vite.config.ts b/slides/vite.config.ts
index eb02eb39..63f028df 100644
--- a/slides/vite.config.ts
+++ b/slides/vite.config.ts
@@ -11,7 +11,14 @@ export default defineConfig({
base: './',
// The app version baked into every shipped shell — what update checks
// compare against the release manifest. Single source: package.json.
- define: { __APP_VERSION__: JSON.stringify(pkg.version) },
+ // __BENTO_TEST_SEAL__: the sealed TEST document's key handoff (kernel save.ts
+ // capturePristine). false, and so dead-code-eliminated, unless BENTO_TEST_SEAL=1
+ // (npm run build:sealtest, which writes dist-sealtest/, never dist-single/).
+ // shell-gate.mjs refuses any release shell that still carries it.
+ define: {
+ __APP_VERSION__: JSON.stringify(pkg.version),
+ __BENTO_TEST_SEAL__: JSON.stringify(process.env.BENTO_TEST_SEAL === '1'),
+ },
plugins: [...(process.env.SINGLEFILE ? [viteSingleFile()] : [])],
// Dev-only: allow serving ../kernel (shared TS-source kernel) — without a
// workspace root, vite's fs allow-list stops at the app dir. Build output
diff --git a/spaces/package.json b/spaces/package.json
index 4a914462..fc1cd178 100644
--- a/spaces/package.json
+++ b/spaces/package.json
@@ -8,6 +8,7 @@
"dev": "vite",
"build": "tsc -b && vite build",
"build:single": "tsc -b && SINGLEFILE=1 vite build --outDir dist-single && mv dist-single/index.html dist-single/Bento_Spaces.bento.html && node ../scripts/postbuild-compress.mjs dist-single/Bento_Spaces.bento.html --generator bento-spaces --title \"bento/spaces\"",
+ "build:sealtest": "rm -rf dist-sealtest && tsc -b && SINGLEFILE=1 BENTO_TEST_SEAL=1 vite build --outDir dist-sealtest && mv dist-sealtest/index.html dist-sealtest/Bento_Spaces.bento.html && node ../scripts/postbuild-compress.mjs dist-sealtest/Bento_Spaces.bento.html --generator bento-spaces --title \"bento/spaces\"",
"preview": "vite preview"
},
"devDependencies": {
diff --git a/spaces/vite.config.ts b/spaces/vite.config.ts
index eb02eb39..63f028df 100644
--- a/spaces/vite.config.ts
+++ b/spaces/vite.config.ts
@@ -11,7 +11,14 @@ export default defineConfig({
base: './',
// The app version baked into every shipped shell — what update checks
// compare against the release manifest. Single source: package.json.
- define: { __APP_VERSION__: JSON.stringify(pkg.version) },
+ // __BENTO_TEST_SEAL__: the sealed TEST document's key handoff (kernel save.ts
+ // capturePristine). false, and so dead-code-eliminated, unless BENTO_TEST_SEAL=1
+ // (npm run build:sealtest, which writes dist-sealtest/, never dist-single/).
+ // shell-gate.mjs refuses any release shell that still carries it.
+ define: {
+ __APP_VERSION__: JSON.stringify(pkg.version),
+ __BENTO_TEST_SEAL__: JSON.stringify(process.env.BENTO_TEST_SEAL === '1'),
+ },
plugins: [...(process.env.SINGLEFILE ? [viteSingleFile()] : [])],
// Dev-only: allow serving ../kernel (shared TS-source kernel) — without a
// workspace root, vite's fs allow-list stops at the app dir. Build output
diff --git a/type/package.json b/type/package.json
index 61c156ea..b874a518 100644
--- a/type/package.json
+++ b/type/package.json
@@ -8,6 +8,7 @@
"dev": "vite",
"build": "tsc -b && vite build",
"build:single": "tsc -b && SINGLEFILE=1 vite build --outDir dist-single && mv dist-single/index.html dist-single/Bento_Type.bento.html && node ../scripts/postbuild-compress.mjs dist-single/Bento_Type.bento.html --generator bento-type --title \"bento/type\"",
+ "build:sealtest": "rm -rf dist-sealtest && tsc -b && SINGLEFILE=1 BENTO_TEST_SEAL=1 vite build --outDir dist-sealtest && mv dist-sealtest/index.html dist-sealtest/Bento_Type.bento.html && node ../scripts/postbuild-compress.mjs dist-sealtest/Bento_Type.bento.html --generator bento-type --title \"bento/type\"",
"preview": "vite preview"
},
"devDependencies": {
diff --git a/type/vite.config.ts b/type/vite.config.ts
index eb02eb39..63f028df 100644
--- a/type/vite.config.ts
+++ b/type/vite.config.ts
@@ -11,7 +11,14 @@ export default defineConfig({
base: './',
// The app version baked into every shipped shell — what update checks
// compare against the release manifest. Single source: package.json.
- define: { __APP_VERSION__: JSON.stringify(pkg.version) },
+ // __BENTO_TEST_SEAL__: the sealed TEST document's key handoff (kernel save.ts
+ // capturePristine). false, and so dead-code-eliminated, unless BENTO_TEST_SEAL=1
+ // (npm run build:sealtest, which writes dist-sealtest/, never dist-single/).
+ // shell-gate.mjs refuses any release shell that still carries it.
+ define: {
+ __APP_VERSION__: JSON.stringify(pkg.version),
+ __BENTO_TEST_SEAL__: JSON.stringify(process.env.BENTO_TEST_SEAL === '1'),
+ },
plugins: [...(process.env.SINGLEFILE ? [viteSingleFile()] : [])],
// Dev-only: allow serving ../kernel (shared TS-source kernel) — without a
// workspace root, vite's fs allow-list stops at the app dir. Build output