Brickheart

Brick Heart: handover, offline pack bench

: Written by a human with AI assistance.

1. State

Verified (your bench run, subject 1, ?step=9):

  • Install: 4021 of 4021 files, 1.5 s.
  • Origin storage: 13.7 MiB (whole origin, includes the sql.js DB).
  • Run: 196 of 1759 stems, closure 899 files, 0 missing, closure 114 ms, geometry 2522 ms, 18,092 triangles, 0 failures.
  • JS heap: 110.9 MiB.
  • The r:1 flag works: listStems returned 1759.
  • dist/data/ldraw is served, so the build.mjs copy block works.

Inferred, not tested:

  • The hook serves every request. bench-build.mjs v2 wipes dist/bench and writes no /bench/ldraw tree, and there were 1 failures. Applying inline style violates the following Content Security Policy directive 'style-src 'self''. Either the 'unsafe-inline' keyword, a hash ('sha256-BT3cCquDgSz1RSD7tm34sX+FhZxo0u2myqBEoq1Ginw='), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present. The action has been blocked.
  1. Run ?all=1, and report time and heap. installing: 2157/2157 files installed in 0.9 s storage usage (whole origin): 18.1 MiB stems 923 of 923, closure 2157 files, missing 0 closure 245 ms, geometry 10230 ms, 80,040 triangles failures 0: JS heap 301.9 MiB (Chromium only)

  2. npm run typecheck

app@0.0.0 typecheck tsc --noEmit

src/bench/ldraw-store.ts:154:20 - error TS2345: Argument of type 'DecompressionStream' is not assignable to parameter of type 'ReadableWritablePair<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBufferLike>>'. Types of property 'writable' are incompatible. Type 'WritableStream<BufferSource>' is not assignable to type 'WritableStream<Uint8Array<ArrayBufferLike>>'. Type 'BufferSource' is not assignable to type 'Uint8Array<ArrayBufferLike>'. Type 'ArrayBuffer' is missing the following properties from type 'Uint8Array<ArrayBufferLike>': BYTES_PER_ELEMENT, buffer, byteOffset, copyWithin, and 29 more.

154 .pipeThrough(new DecompressionStream('gzip')) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Found 1 error in src/bench/ldraw-store.ts:154

npm error Lifecycle script typecheck failed with error: npm error code 2 npm error path /home/chinapal/brickheart-web/app npm error workspace app@0.0.0 npm error location /home/chinapal/brickheart-web/app npm error command failed npm error command sh -c tsc --noEmit

Not done:

  • The blocked-network test (*/data/ldraw/*).
  • Install of subjects 2 and 3, and shared-file dedup on removal.
  • removeSubject, interrupted installs and persist() results (the persist() result printed but was not pasted).
  • A true offline reload, which needs the service worker.
  • Cloudflare Content-Encoding on .gz is untested, because it has not been deployed.
  • engineRotFromLdraw and the stock LDrawLoader versus class m are still unresolved (2fmu4y60objlb.js lines 160 to 190).

2. Decisions made

  • No stripping. Packs hold the text as read.
  • Option B. files is keyed by normalised name and shared across subjects. A members store keyed [subject, name] has an index on name and an r root flag. Removal deletes a file only when no member row remains.
  • Pack format. subject-N.jsonl.gz, one line per file: {n, d, t, r?}. ldconfig.ldr is in every pack.
  • Packer checks. It verifies that shared files are identical across subjects. The last run passed: 4,674 distinct names against 8,765 summed, 10.25 MiB gzip in total.
  • Persistence. The tap handler calls requestPersistence() explicitly, before the install.
  • Bench source. The bench takes its parts from the installed pack, with no excavator and no MPD.

3. Files (all in app/)

  • ldraw_pack.py, at /home/chinapal/brickheart/rebrickable/. It is the full rewrite.
  • src/bench/ldraw-store.ts, the full rewrite.
  • src/bench/ldraw-hook.ts, which patches FileLoader.prototype.load for /bench/ldraw/ URLs.
  • src/bench/offline.ts, which imports from ./geometry.
  • src/bench/geometry.ts, your loader module, with BASE = '/bench/ldraw'. The hook has its own copy of that string, so the two must match.
  • build.mjs, with the pack copy block.
  • bench-build.mjs v2, which builds dist/bench/offline/.

Build order: npm run build, then node bench-build.mjs, then npm run preview. Open /bench/offline/?subject=1&step=9.

4. Next session

  1. Run the blocked-network test: block */data/ldraw/*, reload, click Run, and confirm that no ldraw requests appear and the results match.
  2. Install subjects 2 and 3, then remove subject 1. Confirm that files shared with 2 and 3 survive, using ?parts= on a shared part.
  3. Test an interrupted install (abort mid-download, reload, and confirm cleanupInterrupted ran) and a quota failure.
  4. Read 2fmu4y60objlb.js lines 160 to 190 for the real engineRotFromLdraw. Do this with sed -n '160,190p' and cut -c1-3000, or run prettier on a copy.
  5. Move on to the service worker, so that a real offline reload is possible.

After that, in order:

  • The ?set= build page and the palette (needs your approval of the ui.json keys).
  • Connector-based PLACE (needs 2fmu4y60objlb.js lines 205 to 337 and the connections.json format).
  • The colour modes.

5. Cautions

  • Don't guess. Ask for the command output instead.
  • Mark anything unverified. British spelling.
  • All visible text in the real app goes through site/ui.json with your approval. The bench is English only and not shipped.
  • The sql.js CSP uses 'wasm-unsafe-eval', not 'unsafe-eval'.
  • Cloudflare limits are 25 MiB per file and 20,000 files, and generated artefacts must be committed.
  • Don't assume the tooling. The app is built with build.mjs (esbuild) and previewed with wrangler dev.
  • Give whole files, not patches when many edits are required that arent simple additions or function replacements.