Skip to content

feat(docs-site): the model explorer is one browser app - #667

Closed
dmealing wants to merge 3 commits into
mainfrom
fm/mo-130-explorer-app
Closed

dmealing wants to merge 3 commits into
mainfrom
fm/mo-130-explorer-app

Conversation

@dmealing

@dmealing dmealing commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • docsSiteFile() now writes the model explorer as one browser app by default (output: "app"): a shell, the app, the theme, vendored Cytoscape 3.30.2 and three data files (explorer.json, explorer-model.js, explorer-stamp.js). The app draws each page on visit with the same page code and templates, runs from file:// with no server, and addresses pages as index.html#/<page>. It polls the stamp file about once a second and redraws the open page when the model changes on disk. output: "static" keeps the earlier page-per-screen site, also exposed as generateExplorerSite({ output: "static" }).
  • The app's source lives once in explorer-app/ (built by server/typescript/packages/docs-site/scripts/build-app.ts). scripts/sync-explorer-app.sh copies it into each port's package, and the explorer app copies step of scripts/ci-local.sh --only gates fails when a copy is stale. Non-TypeScript ports ship the files, but their docs-site generators do not yet write them.
  • assetBase now applies only to the static export. The app loads Cytoscape from the shipped copy, so graphs draw offline and the CDN notice is removed from the explorer. Generated-output change: the next meta gen replaces the explorer's pages with the app files. A project that ejected the theme on a 1.3.0 candidate must copy docs-site/assets/explorer.js again (meta eject docs-site --force), because the app calls window.MO_THEME.

Proof

Page-for-page equality against the old static site

The old site was built with main's code at 86a0b03 (an archive of the base commit). The new pages were
drawn by the committed bundle (assets/explorer-app.js) running in a Node VM, from the
explorer-model.js the new generator writes. Script tags that load Cytoscape are normalised,
because the app's shell loads it once for every page.

Model Old pages Identical explorer.json identical Map data identical Files written, old → app
shop (explorer-conformance) 28 28/28 yes yes 32 → 8
crm (explorer-conformance) 22 22/22 yes yes 26 → 8
fitness (persistence canonical) 71 71/71 yes yes 75 → 8
a downstream adopter estate (143 metadata files) 838 838/838 yes yes 842 → 8

test/explorer-app.test.ts repeats this check for the three fixtures on every run, against the static export from the same sources.

Headless Chrome from file:// (CDP)

Check shop adopter estate
First draw 63 ms 136 ms
Nav-bar link → map, Cytoscape canvases drawn 3 canvases, 8 nodes 3 canvases, 190 nodes
Map control writes query into route #/map.html?colour=claims same
Model index → package → object (real link clicks) yes, object mini-map drawn yes
Back, back, forward correct page each time correct page each time
Search box → result click 17 results → #/model/acme/shop/Order.html 25 results, hit opens
Cross-page member link #/model/acme/shop/Order.html#m-reference, scrolled to member n/a
Unknown route "No such page" same
Console errors / exceptions none none

Live update

With the page open, the test rewrote explorer-model.js and explorer-stamp.js with a changed title and never touched the page.

shop adopter estate
Edit visible after 204 ms 769 ms
Route kept yes yes
Scroll kept yes (400 → 400) yes (400 → 400)
Revert visible after ~1.0 s ~1.1 s

The poll interval is 1 s, so any delay up to about 1 s is expected.

The pipeline took 1 run, with two review fix rounds.

Validation

Risk Assessment

✅ Low: The fix-round changes are small and correct: the not-found Overview link now resolves to #/index.html, the rebuilt bundle carries the fix, and all four port copies are identical. The docs now say the app keeps only each drawn page's title and body. The rest of the change was reviewed in earlier rounds, and the tests hold the app's page output byte-for-byte to the static export.

Testing

Baseline scripts/ci-local.sh --affected --strict-toolchains passed at the target commit and was not re-run. I generated the app with the real generateExplorerSite from the fixtures/explorer-conformance/shop fixture into a scratch dir. Headless google-chrome then loaded it over file:// with no server. The overview rendered, the deep link #/model/acme/shop/Order.html rendered the real Order page, and a missing page showed "No such page" with an Overview link. That link resolves to #/index.html from a nested path, which is the root-relative fix. Model-change-on-disk following was not driven. Scratch output removed.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Generate explorer app from shop fixture (local generator, synthetic fixture) ✅ pass live bun driver over generateExplorerSite; output 28 pages, 8 files (index.html, explorer-model.js, explorer.json, assets)
Overview opens from file:// with no server ✅ pass live explorer-index.png shows 'What Shop does' overview, nav, requirements and packages
Deep link to a model page renders the real page ✅ pass live explorer-order-page.png shows the Order entity page: fields, keys, API routes, neighbourhood map
Missing page shows not-found with a working Overview link (adversarial, nested path) ✅ pass live explorer-missing-page.png; --dump-dom gives href="#/index.html" for the Overview link from a nested missing path
Model change on disk followed by the live view ⏸️ untested no Not driven in this run. Needs a meta gen rerun while the page is open, which requires a browser automation loop. Time budget went to the listed scenarios.

Overview page, file:// no server

Order model page via deep link

Not-found page for missing model page

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 3 issues (2 warnings, 1 info)
  • ⚠️ scripts/ci-local.sh:1514 - The explorer app copies gate is registered in run_gates_offline. That group runs before the dependencies installed step (bun_install, line 1775), and in lane_gates it runs before run_gates_bun. gate_explorer_app_drift runs build-app.ts --check, and that script calls Bun.build over app-src/main.ts. The build resolves workspace @metaobjectsdev/* packages (the bun condition) and the third-party mustache dependency through node_modules. On a fresh CI checkout there is no node_modules yet. The bundle then fails to resolve, so the check is red there and green on warm dev machines. Or bun auto-installs and binds the published packages, which is worse: the check compares against a stale loader. The comment above run_gates_bun (ci-local.sh:1516-1523) records this exact failure class. Fix: move the step into run_gates_bun, or into run_drift_gates beside the other build-and-diff gates. Another option is to prefix it with bun_install &amp;&amp;.
  • ⚠️ server/typescript/packages/docs-site/scripts/build-app.ts:28 - The bundle inlines mustache.js (MIT, via @metaobjectsdev/render's render.ts) and minifies it. The committed explorer-app/assets/explorer-app.js has no copyright or licence notice: a grep for Copyright|license finds 0 matches. This file ships in the npm package (app/), the Python wheel and the Java jar, and it is written into every adopter's generated site. MIT requires the copyright and permission notice in all copies or substantial portions. Cytoscape is handled correctly (the vendored file keeps its header, and the README cites it), but mustache.js is not. Fix: add a banner to the Bun.build call with the mustache.js MIT notice. Add a matching row to explorer-app/README.md's file table. Then rebuild and re-sync the four copies.
  • ⚠️ server/typescript/packages/docs-site/assets/explorer.js:330 - The app now needs a hook from the theme script: it calls window.MO_THEME once per page it draws. A project that ran meta eject docs-site on a 1.3.0 RC has an owned codegen/docs-site/assets/explorer.js without that hook, because the explorer shipped in those candidates. generateExplorerSite writes the owned copy in place of the packaged one (theme() in site.ts). Trace: the old IIFE runs once at shell load against the Loading the model… body and finds nothing. Then show() calls w.MO_THEME?.(), which is undefined. Search, the theme toggle, the map, the mini-maps and the trace all stop working on every page. Nothing errors, and the existing meta gen warning only covers missing explorer files. meta eject docs-site without --force does not refresh a file that already exists. Smallest fix: in changelog.d/explorer-app.md (the 'Generated-output change' sentence, line 14), tell owners of an ejected explorer.js to re-copy it (meta eject docs-site --force) or add the window.MO_THEME = run hook. Make the same note in docs/features/explorer-site.md, 'Own the theme'.
  • ⚠️ scripts/sync-explorer-app.sh:12 - Simplification: the change commits three non-TypeScript copies of the app (about 490 KB each: server/python/.../explorer_app, server/java/codegen-base/.../explorer-app, server/csharp/MetaObjects.Codegen/ExplorerApp). It also adds a sync script and drift-gate loops to keep them current. No port's generator reads these copies yet; the changelog and docs say 'the other ports' docs-site generators are still to write them'. The intent says 'This task is the app itself', so these copies serve a future task. Meanwhile they add about 490 KB of unused JS to the Python wheel and the Java jar for 1.3.0. Recommend removing the three port copies, their entries in sync-explorer-app.sh and gate_explorer_app_drift, and the port table rows. Add them with the port generators that consume them.
  • ⚠️ server/typescript/packages/docs-site/src/explorer/site.ts:159 - Simplification: the intent says the app 'replaces the static per-port page loop that writes a page per screen'. The change instead keeps that loop as a second public mode: output: &#34;static&#34; on generateExplorerSite and docsSiteFile, the EXPLORER_OUTPUT_* constants, and assetBase now scoped to that mode. The mode also adds new behavior: the vendored Cytoscape copy, and a mirror that ships no copy. The byte-identical test and Pagefind publishing justify keeping it, but no stated requirement needs a user-facing option. Confirm that the static export should stay a supported option. Otherwise, reduce it to an internal test path, or remove it with the assetBase branch.
  • ℹ️ server/typescript/packages/docs-site/app-src/main.ts:104 - Most of the new app logic runs only in a browser, and no test executes it. That covers the hash-route parse and build, the per-page link rewrite, the anchor-only hashchange path, replaceQuery, and the stamp-then-model poll handshake. The test file runs only the MoExplorer.explorerFor page table. The docs make claims about back, forward, new-tab links, keeping the scroll position and skipping a half-written model, and nothing checks them. A DOM-backed test (for example happy-dom) could drive #/model/acme/shop/Order.html#m-total and a stamp change. That test would reject a link rewritten against the wrong base, or a model taken without its stamp. I traced the cases by hand and found no defect.

🔧 Fix applied.
5 issues (3 warnings, 2 infos) still open:

  • ⚠️ scripts/sync-explorer-app.sh:12 - Simplification: the change commits three non-TypeScript copies of the app (about 490 KB each: server/python/.../explorer_app, server/java/codegen-base/.../explorer-app, server/csharp/MetaObjects.Codegen/ExplorerApp). It also adds a sync script and drift-gate loops to keep them current. No port's generator reads these copies yet; the changelog and docs say 'the other ports' docs-site generators are still to write them'. The intent says 'This task is the app itself', so these copies serve a future task. Meanwhile they add about 490 KB of unused JS to the Python wheel and the Java jar for 1.3.0. Recommend removing the three port copies, their entries in sync-explorer-app.sh and gate_explorer_app_drift, and the port table rows. Add them with the port generators that consume them.
  • ⚠️ server/typescript/packages/docs-site/src/explorer/site.ts:159 - Simplification: the intent says the app 'replaces the static per-port page loop that writes a page per screen'. The change instead keeps that loop as a second public mode: output: &#34;static&#34; on generateExplorerSite and docsSiteFile, the EXPLORER_OUTPUT_* constants, and assetBase now scoped to that mode. The mode also adds new behavior: the vendored Cytoscape copy, and a mirror that ships no copy. The byte-identical test and Pagefind publishing justify keeping it, but no stated requirement needs a user-facing option. Confirm that the static export should stay a supported option. Otherwise, reduce it to an internal test path, or remove it with the assetBase branch.
  • ℹ️ server/typescript/packages/docs-site/app-src/main.ts:104 - Most of the new app logic runs only in a browser, and no test executes it. That covers the hash-route parse and build, the per-page link rewrite, the anchor-only hashchange path, replaceQuery, and the stamp-then-model poll handshake. The test file runs only the MoExplorer.explorerFor page table. The docs make claims about back, forward, new-tab links, keeping the scroll position and skipping a half-written model, and nothing checks them. A DOM-backed test (for example happy-dom) could drive #/model/acme/shop/Order.html#m-total and a stamp change. That test would reject a link rewritten against the wrong base, or a model taken without its stamp. I traced the cases by hand and found no defect.
  • ⚠️ server/typescript/packages/docs-site/app-src/main.ts:127 - The not-found page's 'Overview' link is written as href=&#34;index.html&#34;. rewrite(doc, r.path, …) then resolves it against the missing page's own path, not the site root. The live view makes this easy to reach: the reader has #/model/acme/shop/Order.html open, then renames or deletes Order and runs meta gen. show(true) redraws, and the page is not found. The 'Overview' link becomes #/model/acme/shop/index.html, which is the package index (Pages.packagePage), not the overview. If that package was also removed, the link leads to another 'No such page'. A stale bookmark or a link from a new tab hits the same problem. Fix: build the link relative to the root, for example &#34;../&#34;.repeat(r.path.split(&#34;/&#34;).length - 1) + HOME, or use the same relHref the pages use. Then rebuild explorer-app/ and run scripts/sync-explorer-app.sh so all four port copies match. This code came from the original commit; the fix round did not touch it.
  • ℹ️ docs/features/explorer-site.md:174 - The docs say 'The app carries your templates in explorer-model.js and draws every page with them'. However, show() (app-src/main.ts:132-135) keeps only the drawn document's &lt;title&gt;, its &lt;body&gt; attributes and its body children. Everything else that an owned explorer-head.mustache puts in &lt;head&gt; is discarded with no warning: an extra stylesheet &lt;link&gt;, a &lt;style&gt; block, a favicon, &lt;meta&gt; tags, and attributes on &lt;html&gt;. The static export keeps all of these. Fix the 'Own the theme' paragraph and the docs-site README sentence: say that the app uses only the title and body of each drawn page, so head additions belong in an owned explorer.css or explorer.js.

🔧 Fix applied.
3 issues (2 warnings, 1 info) still open:

  • ⚠️ scripts/sync-explorer-app.sh:12 - Simplification: the change commits three non-TypeScript copies of the app (about 490 KB each: server/python/.../explorer_app, server/java/codegen-base/.../explorer-app, server/csharp/MetaObjects.Codegen/ExplorerApp). It also adds a sync script and drift-gate loops to keep them current. No port's generator reads these copies yet; the changelog and docs say 'the other ports' docs-site generators are still to write them'. The intent says 'This task is the app itself', so these copies serve a future task. Meanwhile they add about 490 KB of unused JS to the Python wheel and the Java jar for 1.3.0. Recommend removing the three port copies, their entries in sync-explorer-app.sh and gate_explorer_app_drift, and the port table rows. Add them with the port generators that consume them.
  • ⚠️ server/typescript/packages/docs-site/src/explorer/site.ts:159 - Simplification: the intent says the app 'replaces the static per-port page loop that writes a page per screen'. The change instead keeps that loop as a second public mode: output: &#34;static&#34; on generateExplorerSite and docsSiteFile, the EXPLORER_OUTPUT_* constants, and assetBase now scoped to that mode. The mode also adds new behavior: the vendored Cytoscape copy, and a mirror that ships no copy. The byte-identical test and Pagefind publishing justify keeping it, but no stated requirement needs a user-facing option. Confirm that the static export should stay a supported option. Otherwise, reduce it to an internal test path, or remove it with the assetBase branch.
  • ℹ️ server/typescript/packages/docs-site/app-src/main.ts:104 - Most of the new app logic runs only in a browser, and no test executes it. That covers the hash-route parse and build, the per-page link rewrite, the anchor-only hashchange path, replaceQuery, and the stamp-then-model poll handshake. The test file runs only the MoExplorer.explorerFor page table. The docs make claims about back, forward, new-tab links, keeping the scroll position and skipping a half-written model, and nothing checks them. A DOM-backed test (for example happy-dom) could drive #/model/acme/shop/Order.html#m-total and a stamp change. That test would reject a link rewritten against the wrong base, or a model taken without its stamp. I traced the cases by hand and found no defect.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Generate explorer app from shop fixture (local generator, synthetic fixture) ✅ pass live bun driver over generateExplorerSite; output 28 pages, 8 files (index.html, explorer-model.js, explorer.json, assets)
Overview opens from file:// with no server ✅ pass live explorer-index.png shows 'What Shop does' overview, nav, requirements and packages
Deep link to a model page renders the real page ✅ pass live explorer-order-page.png shows the Order entity page: fields, keys, API routes, neighbourhood map
Missing page shows not-found with a working Overview link (adversarial, nested path) ✅ pass live explorer-missing-page.png; --dump-dom gives href="#/index.html" for the Overview link from a nested missing path
Model change on disk followed by the live view ⏸️ untested no Not driven in this run. Needs a meta gen rerun while the page is open, which requires a browser automation loop. Time budget went to the listed scenarios.
  • scripts/ci-local.sh --affected --strict-toolchains
  • bun driver over generateExplorerSite (app output) from fixtures/explorer-conformance/shop into a scratch dir (28 pages, 8 files)
  • google-chrome --headless screenshot file:///.../index.html (overview)
  • google-chrome --headless screenshot file:///.../index.html#/model/acme/shop/Order.html (real model page)
  • google-chrome --headless --dump-dom file:///.../index.html#/model/acme/shop/Nope.html (not-found Overview href)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…view

docsSiteFile() now writes the explorer as a single-page app instead of a
page per screen: a shell, the bundled page code and templates, the theme,
a vendored Cytoscape 3.30.2 (MIT), and three data files (explorer.json,
explorer-model.js, explorer-stamp.js). Pages are drawn on visit by the
same code the static export runs (src/explorer/core.ts), so they are byte
for byte the old pages. It runs from file:// with hash routes and follows
the model on disk by polling the stamp file.

output: "static" keeps the page-per-screen export from the same code;
assetBase now applies to it only. The app's files live once at
explorer-app/ with a committed copy in every port's package, refreshed by
scripts/sync-explorer-app.sh and held by the `explorer app copies` gate.
@dmealing

Copy link
Copy Markdown
Member Author

Superseded: this branch conflicts with main after #666 landed. Its commits ship inside the follow-up PR for the explorer's 3D map and running-application view, which resolves the conflict and carries this PR's proof.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant