Brickheart

Dev (Page 2)

  • Changelog 26OCT2026 dev

    Licensing and process decisions from 26 Oct. These are the owner's decisions, not legal advice.

    • BrickNet is MIT and Brickheart is MIT. BrickNet's copyright notice is kept in any ported code and converted data.
    • Connector labels derive from the LDraw library, whose licence is already carried.
    • Brickheart is free and sits in the same grey zone as the OMR, Rebrickable and similar projects. This is recorded as the owner's decision.
    • Any statistic derived from the OMR pack is an aggregate count with a source line, never model content.
    • Generated draft instructions are released CC0 and carry a label that they are a machine-generated draft, derived from the manual, possibly with errors. A per-set status of draft or reviewed is proposed.
    • BrickNet is the connector source for the MVP. The LDCad shadow library is a possible second source behind the same schema.
    • Alias mapping lives in the database.
    • Snap code lives in src/snap/ as pure modules with no DOM or three.js access, tested with node --test.
  • Changelog 25OCT2026 dev

    Working rules recorded on 25 Oct.

    • All visible text in the app goes through the translation files, with the owner's approval. Since 7 and 8 Nov the app English file is app/i18n/ui/en.json.
    • No inline styles. The CSP is style-src 'self', so colours are set through the CSSOM.
    • Cloudflare limits are 25 MiB per file and 20,000 files. Generated artefacts must be committed.
    • British spelling.
    • Whole files, not patches, when an edit is not simple.
    • Build order: npm run typecheck && npm run build && npm run preview.
    • renderBuild must be called after fs.rmSync(dist) in build.mjs.
  • Changelog 24OCT2026 dev

    • Tooling rules: the app is built with build.mjs (esbuild) and previewed with wrangler dev.
    • The sql.js CSP uses 'wasm-unsafe-eval', not 'unsafe-eval'.
    • An inline style in the bench experiment was blocked by style-src 'self'. This was the one failure in the run.
    • The bench experiment (src/bench/, bench-build.mjs) was removed on 6 Nov with the other finished experiments.
  • Changelog 19OCT2026 dev

    Data pipeline and repo state, 19 Oct. The first packs were replaced on 24 Oct and 5 Nov.

    • load_data.py rebuilds rebrickable.db from scratch on every run: schema.sql, Rebrickable CSVs and enrichment CSVs. At the time: 2,210 sets, 2,022 parts, 74 colours, 70,496 inventory_parts rows, 11.07 MB. Sets had 15 to 399 parts. Changed on 9 Nov: 78 modern colours, and sets are 15 to 999 parts.
    • Pipeline rules: keep version 1 inventories, drop minifigs and stickers, drop side-project themes, roll colours up to the modern colours, keep the top 100 printed parts and swap the rest for plain parts, and map mold variants to the newest mold.
    • New fetch_ldraw_map.py (one-off) writes ldraw_map.json from the Rebrickable parts catalogue and colours list.
    • load_ldraw_map(conn) adds parts.ldraw_stem and colors.ldraw_code. A part resolves if one of its LDraw ids is a BrickNet stem or alias, has a collider file, and is not in missing_ldraw_parts.csv. A colour resolves if a code is in BrickNet's colour table.
    • remove_unbuildable_sets is strict: a set with any non-spare part or colour that has no mapping is removed. It removed 5,112 sets.
    • ldraw_weight.py and remove_heavy_part_sets remove sets with a part over MAX_PART_TRIANGLES. It removed 13 parts and 28 sets, including Plate 16 x 16 (91405).
    • app was not yet in the root workspaces. It has been since the app got its build.mjs.
    • Key tables: sets, themes (with subject_id), inventories, inventory_parts, parts, colors and model_subject (1 Real World, 2 Original Fiction, 3 Licensed Fiction, 0 Unknown).
    • LDraw library at ~/bricknet/ldraw. Units: 20 LDU per stud, 8 per plate, 24 per brick height. BrickNet has 14,583 catalogue parts, with 14,462 colliders found locally.
    • Aliases: 2,522 old stems map to a canonical stem plus a 4x4 transform. The loader keeps only the canonical stem and drops the transform.
    • First packs: subject-N.mpd.gz for subjects 1 to 3, 9.52 MiB gzipped in total, written by ldraw_pack.py with manifest.json. Replaced by subject-N.jsonl.gz on 24 Oct and the indexed packs on 5 Nov.
    • Working rules: all DB work stays in Python. Node and TypeScript only read the finished artefacts. The 6 Nov audit plans a TypeScript port of the pipeline.
    • Cloudflare only runs templating, so generated data must be committed and copied into dist/ by build.mjs.
  • Changelog 17OCT2026 dev

    The alternative-history data pipeline, 17 Oct. Items changed by later sessions are noted.

    Concept

    • Brickheart is a digitally buildable alternative history of LEGO. It is not meant to be complete. LDraw later shows what can be built, and the rules are revisited against its catalogue.

    Tools

    • load_data.py rebuilds rebrickable.db from scratch on every run, from schema.sql and the Rebrickable .csv.gz files.
    • Enrichment CSVs: rebrickable_themes_by_subject_format_scale.csv and simplified_lego_colors.csv.
    • site/data/colour-mapping.json holds the full old-to-modern colour map.
    • A Streamlit app with a query() helper, reference tables and a set-selection tab.

    Rules, in order

    1. Keep version 1 inventories only.
    2. Remove all minifigs and stickers before set sizes are recounted.
    3. Recount sets.num_parts from the surviving inventory, excluding spares.
    4. Remove side-project themes (THEME_IDS and descendants), database or 1:87 sets, and Modulex, Duplo and Likit colours.
    5. Keep sets of 15 to 399 parts (MIN_PARTS, MAX_PARTS). Changed on 9 Nov: the upper limit is 999.
    6. Remove sets containing parts that appear in only one theme. This runs once, after the size filter.
    7. Build the modern colour map: colours with y2 > 2020, excluding opal and glitter, give 74 colours. Retired colours map to the nearest modern colour in Lab space, matching transparency. colors gains modern_color_id, is_modern, base_color and basic_rgb. Changed on 9 Nov: 78 modern colours.
    8. Keep the top 100 printed parts (TOP_PRINTED_PARTS), ranked by number of sets. Printed parts are found through P relationships or a regex on the part number suffix. Parts with no plain version compete on equal terms. Everything is logged in print_replacements.
    9. REWRITE_INVENTORY_PARTS is a destructive single pass on inventory_parts. It swaps printed parts for plain ones and mold variants for the newest mold (M relationships), rolls colours up to the modern palette, sums duplicate rows, then recounts set sizes and re-applies the size filter.
    10. DELETE_RETIRED_COLORS cuts colors to the modern colours.
    11. Remove orphans: trim elements to used part and colour pairs, delete themes without sets, and clear parent_id where the parent was removed.
    12. Statistics run last: year_stats, part_stats, part_rank, era_stats and part_era_rank. part_rank.part_palette and inventories.set_palette come from base colours.

    Streamlit selection tool

    • Greedy weighted set cover over leaf theme, parent theme, year, subject, format, scale, complexity and parent theme by year.
    • It minimises the number of sets, total pieces or distinct parts, with a "sets per item" depth slider. It sweeps min and max part counts and lists extra sets buildable from the chosen parts.
    • distinct parts already uses a marginal cost, counting only parts not yet in the selection.

    Answered by 19 Oct

    • The LDraw library is at ~/bricknet/ldraw.
    • The Rebrickable to LDraw mapping was built with fetch_ldraw_map.py.
    • The size target is the Cloudflare 25 MiB file limit, plus a part triangle limit.
    • The plan for the LDraw session was done on 19 Oct: marginal file size, id mapping through BrickNet stems and aliases, colour mapping to LDraw codes, and the LDraw filter before the printed-part ranking.
  • Brickheart website overview

    This supplements site-build.md and brand_guide.md. It covers only what was added, changed or corrected during the build, plus the reasoning behind it.

    State

    Both builds are live on Cloudflare Workers, deployed from GitHub. dev.brickheart.org (dev/): complete. brickheart.org (site/): English pages, picker, per-language 404s, hreflang sitemap and the translation pipeline are all working. zh is launched as translations are filled in. app/: not started.

    Repo layout (as built)

    package.json root: workspaces ["dev","site"], markdown-it dependency, wrangler, scripts shared/ assets/ copied wholesale into each dist (css, js, brand, fonts, favicons, manifest, _headers) engine/ build code, never copied: paths, markdown, layout, lists, sitemap (+ .test.mjs) dev/ content/, css/dev.css, config.mjs, scan.mjs, render.mjs, build.mjs, wrangler.jsonc site/ content/, css/site.css, config.mjs, languages.json, ui.json, links.mjs, scan.mjs, blocks.mjs, translate.mjs, localize.mjs, render.mjs, root.mjs, build.mjs, translations/, wrangler.jsonc Single dependency location: markdown-it lives only in the root package.json, because shared/engine/ resolves packages from the root node_modules. dev/package.json and site/package.json hold only a build script (gray-matter was removed). Scripts: npm test runs node --test shared/engine/.test.mjs dev/.test.mjs site/.test.mjs. build:dev and build:site run each build. Run all npm commands from the repo root. Cloudflare: the root directory is the repo root. Build is npm ci && npm run build:site (or build:dev), with CI set (Cloudflare sets it automatically). Each project has its own wrangler.jsonc with assets.directory: ./dist and not_found_handling: "404-page". .gitignore: node_modules/, dev/dist/, site/dist/, site/translations/todo.json. site/translations/translations.json must be committed. Corrections and additions to site-build.md

    Paths

    Assets land at the dist root (css/, js/, brand/, fonts/), not under assets/. Favicon is brand/favicon.svg. 404 pages are the one exception to relative links: they use root-absolute asset paths, because Cloudflare serves one file at any URL depth. Cloudflare serves .html files extensionless, so canonical URLs and sitemap entries have no .html, and index pages end in /. brand_guide.md, and on dev picker.js and page.js, are excluded from the dist copy.

    Brand and naming

    Roboto Slab is self-hosted as two variable .woff2 subsets with @font-face in base.css (the strict CSP forbids external fonts). Quote styling (figure.quote) lives in base.css because 404 pages don’t load the project CSS.

    Theme

    shared/assets/js/theme.js runs in the head, not deferred, on every page including 404s and the picker. It reads a bh-theme cookie, then localStorage, then the system setting. picker.js writes both localStorage and a cookie on .brickheart.org, so the choice carries between the site and dev. page.js now only clears the saved language on “Change settings”. There is no theme toggle on dev yet.

    Content rules

    Link rewriting (site): authors write About. The build rewrites it to the correct relative .html link, and fails on a missing target or a link starting with /. Dev doesn’t use it. Markdown renderer: raw HTML disabled; the h1 is removed from the body and placed by the template; each h2 becomes <section aria-labelledby>; code blocks get tabindex="0". h1 counting uses the parser, not a regex. All errors are collected and reported in one pass. Site page names are limited to a-z 0-9 _ -; 404.md is reserved.

    Dev changes

    Changelog: entries get no pages of their own. The index and per-category pages (app, dev, site, paginated) show full entry bodies, each with an anchor id. There is no changelog archive. Pages collection: dev/content/pages/ holds standalone pages, for example pages/ai.md → ai-transparency.html. AI transparency: every blog post should sit under one of the tag folders ai-none, ai-assisted or ai-generated. The entry page shows the matching note linked to the AI page. A missing tag is a warning, and two tags is an error. tagLabels in dev/config.mjs overrides tag display names. Excerpts come from the first paragraph. The old summary front matter and RSS feed are gone. Reserved slugs: index, archive, tags for blog entries, plus more for pages. Tag folders must be [a-z0-9_-], and a tag named like another tag’s page 2 (x-2 beside x) fails. Blog tag pages are at blog/tags/<name>.html.

    Site additions

    Footer on every page: “Change settings” link, LEGO trademark disclaimer, and the LDraw CC BY credit. These are UI strings, so they are translated. Root picker is generated from languages.json (English plus each language’s own name). There is one 404 per language plus a neutral root one. Header and footer logos: the small wordmark in the header at all widths

    Translation pipeline (site only)

    This replaces steps 1 to 6 of the scope with a simpler design. Blocks: each page is split into heading, paragraph and list-item blocks, keyed page/position. UI strings from ui.json are blocks keyed ui/<name>. Code blocks are skipped. One working file: translations/todo.json is both todo and inbox. Run a build, fill in the blank language fields, and build again. Filled fields merge in, blanks are skipped, and the file is rewritten with only what remains. If a translation is rejected for a fixable reason (changed link target or {placeholder}), your draft stays in the field. If it was rejected because the English changed, it’s dropped. Store is keyed by the hash of the English text, not by position. This was a redesign after an edit shifted positions and wiped every translation. Inserting, moving or reverting English costs nothing, identical English is translated once, and nothing is auto-deleted. The old position-keyed format migrates on read. Checks on merge: link targets and {placeholders} must match the English (this includes {licence} and {language}). Building languages: a page is translated only if all its blocks and all UI strings have translations. Translated pages are rebuilt from the English Markdown with blocks swapped, and carry a “machine translated” notice. Incomplete pages are built in English inside the language folder, with lang="en-GB" and an English canonical, and stay out of the hreflang sitemap. A language with no complete pages isn’t built, and doesn’t appear in the picker, 404s or sitemap. CI is read-only: with CI set, the build only reads translations.json. It never merges, writes or fails on stale translations. Don’t set CI locally, but CI=1 npm run build:site simulates Cloudflare. Workflow: run npm run build:site, fill in todo.json, run it again, then commit translations.json with the content change that needed it.

    Known limits: translatable blocks are top-level paragraphs, headings (# style) and list items. Blockquote text isn’t collected, setext headings aren’t handled, and a multi-paragraph list item only keeps its first paragraph. Site content should avoid these.

    Open items

    Move shared code-block and blockquote styles from dev.css into a shared stylesheet so site articles get them. Add additional languages to languages.json, and translate. A dev theme toggle, an optional prune-translations command, and a build warning for unsupported Markdown in translatable content. The app/ WebGL editor (offline, with its own bundled logos and PWA icons per the brand guide).

  • Changelog 08OCT2026 dev

    How the project was set up, 8 Oct.

    • The domain was bought at Cloudflare, with email forwarding and subdomains set up there.
    • The site is deployed from GitHub to Cloudflare Workers as static assets. Each workspace has its own wrangler.jsonc pointing at ./dist, and the deploy command is npx wrangler deploy --config site/wrangler.jsonc. After the first deploy a custom domain is attached, with workers_dev and preview_urls set to false.
    • The project is written in TypeScript. The first test was the docs example from the PolymerLabs brick-viewer repo.
    • The first plan was five GitHub repos: four public (ldraw-lite, lplace, lframe and brickheart) and one private (brickheart-web). By 7 Oct the work was in brickheart-web with site, app, dev and shared.
    • The development machine runs Ubuntu with nvm, Node LTS, VS Code and gh. The app started as a Vite vanilla-ts project. Vite was dropped on 6 Nov.
  • Changelog 07OCT2026 dev

    Dev blog rules, 7 Oct. The 11 Nov working agreement is the current reference where it differs.

    • dev/content has three collections: blog, changelog (folders app, dev, site) and roadmap (folders now, next, later).
    • Blog and changelog file names are yyyyMMdd[a-z].md. The date comes from the name, and the letter only breaks ties on the same day. The build fails on a wrong file name or an invalid date.
    • The HTML name is the slug of the h1, and the h1 is the display title. A duplicate slug in a collection fails the build.
    • Roadmap items are short .md files. Their folder sets their status, and roadmap.html shows them grouped. There is no Done group: a shipped item is deleted from the roadmap and gets a changelog entry.
    • The changelog describes what changed for visitors in plain sentences, and is not generated from git.
    • Every folder in an entry's path is a tag, and the same folder name anywhere is the same tag. Tag pages are tags/<name>.html, with later pages as tags/<name>-2.html. Every tag gets a page.
    • An intro file <name>.md inside a folder <name> is shown first on that tag's page. Two intro files for one tag fail the build.
    • The tag navigation lists only tags with an intro file or at least N entries. The default is 3, as one config value.
    • Orphan posts are accepted and reachable through the archive.
    • Index pages show the latest 10 entries with date, title, tags and the first paragraph. archive.html lists every entry. Tag pages use the index format with accessible pagination.
    • There are no feeds anywhere.
    • Assistance entries: the assistant writes each entry at the end of a session and a human edits and approves it. They record outcomes only, with the h1 as the purpose, followed by Asked for, Produced, Human changes and Checked by. There are no AI labels.
    • Changed on 11 Nov: the folder is blog/ai-assisted/claude, not blog/assistance/claude, and the blog has since carried handovers and design pages.