Repository navigation
feat(docs-site): ship the model explorer as one browser app with a 3D map - #668
Merged
Merged
Conversation
…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.
…mo-130-explorer-3d-live # Conflicts: # server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts # server/typescript/packages/docs-site/src/link-check.ts
…plication
The explorer map gains a 2D/3D View control. The 3D mode draws the same nodes, edges,
slice and colouring with 3d-force-graph 1.77.0 (MIT, bundling three.js, licences in the
file header), vendored into explorer-app/ and every port's copy and loaded only when a
reader first chooses 3D. Click a node for the side panel, click again to open its page.
runtime-ts serves the loaded model's docs view at GET {apiPrefix}/_meta/docs
(mountMetaDocsRoute, mountMetaDocsRouteHono, metaDocsJson), opt-in beside /_meta, with
an ETag, 304 on If-None-Match, and an allowOrigin opt-in for cross-origin reads. The
explorer app opened as index.html?source=<url> reads that route instead of the model
file and follows it once a second. The route's shape is documented as a cross-port
contract in docs/features/metadata-api.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #667: that PR conflicted with
mainafter #666 landed, so the explorer app ships here together with the 3D map and the running-application view.What Changed
docsSiteFile()writes a shell, the app bundle (explorer-app/, copied into every port), Cytoscape 3.30.2, and three data files (explorer.json,explorer-model.js,explorer-stamp.js) in place of a page per screen. The app draws each page on visit, works fromfile://, and reloads whenmeta genchanges the model (stamp polled about once a second).output: "static"keeps the page-per-screen export.3d-force-graph1.77.0 loads only when the reader picks 3D.GET {apiPrefix}/_meta/docsserves the loaded model's docs view. Opt-in on Fastify and Hono, with ETag and304support and optionalallowOrigin. Open the app withindex.html?source=<url>to follow a running application's model.Generated-output change: regenerate with
meta gento replace the explorer pages. Ejected themes on 1.3.0 candidates need re-ejecting (meta eject docs-site --force). Building the explorer bundle requires Bun 1.3.14, which is now the declared package manager.Proof (carried from #667: the explorer app)
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 weredrawn by the committed bundle (
assets/explorer-app.js) running in a Node VM, from theexplorer-model.jsthe new generator writes. Script tags that load Cytoscape are normalised,because the app's shell loads it once for every page.
test/explorer-app.test.tsrepeats this check for the three fixtures on every run, against the static export from the same sources.Headless Chrome from
file://(CDP)#/map.html?colour=claims#/model/acme/shop/Order.html#/model/acme/shop/Order.html#m-reference, scrolled to memberLive update
With the page open, the test rewrote
explorer-model.jsandexplorer-stamp.jswith a changed title and never touched the page.The poll interval is 1 s, so any delay up to about 1 s is expected.
Proof (this PR: the 3D map and the running-application view)
A TypeScript fixture application (Fastify,
mountMetaRoute+mountMetaDocsRouteunder/api, the shop model fromfixtures/explorer-conformance/,allowOrigin: "*") ran on localhost. The explorer app was opened fromfile://asindex.html?source=http://127.0.0.1:<port>/api/_meta/docsin headless Chrome, driven over CDP with real mouse events. This covers the browser scenario the Test step's table marks untested.3D toggle
#cyhidden,#g3dshown with a WebGL canvas, 4 nodes and 1 link in the default slice; route#/map.html?colour=cap&view=3d; the 3D library loaded on demand (no script tag in the page)Ordernodeacme::shop · entityand its claims; route unchanged#/model/acme/shop/Order.htmlin 51 ms#/map.html?colour=cap&view=3d, 3D drawn again#/map.html?colour=cap; Cytoscape canvas shown, 3D view hidden and emptiedThe toggle was also driven with chrome-devtools-axi (open, set View to 3D, inspect): canvas present, 4 nodes, 1 link, route
view=3d.Following a running application
model/index.html) keptCouponto the model, restart the applicationCoupon768 ms after the restart, with no reload (navigation entries 1); nodes 8 → 9; route keptCouponpageCoupon, its description showncurlthe routeETag,Cache-Control: no-cacheand the CORS headers; repeated withIf-None-Match→304, 0 bytesThe route serves the model the application loaded and never re-reads metadata files; following edits on disk is the file app's job (above), and a reload of the running application is the host's (a watcher or restart), which the app follows.
The pipeline took 1 run: three review rounds (two fix rounds) and one Test fix round (docs only).
Validation
Risk Assessment
✅ Low: The only change since the last review is a one-line edit: root packageManager now declares bun@1.3.14, matching every workflow pin and EXPLORER_APP_BUN, plus a changelog fragment in the correct format. Nothing else reads packageManager, and the earlier fixes (F4 fixture oracle, F7 optional ETag in the contract, F8 ?title= removal) are confirmed in the current code.
Testing
Baseline affected-lanes run passed. Live, against the real runtime-ts route on a disposable Fastify server bound to localhost: the docs body matches the independent model-alone oracle byte for byte, a poll with the current ETag returns 304, and a restarted server serves an edited model copy. Edit-without-restart was not tested because the operator decided it is out of scope. The browser explorer app (file:// and ?source=) was not driven, so it is untested. Servers were stopped, the worktree is clean, and no processes remain.
Evidence: Docs route body, model-alone (live, served by runtime-ts route)
Evidence: Docs route response headers (ETag, Cache-Control)
acme::library::Writerand noacme::library::Author(kept with the run, not attached)Evidence: Driver script used to serve the route
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts:69- Inline fix. TheassetBasedoc comment said a static explorer loads only Cytoscape from the mirror.site.tsalso loads3d-force-graph.min.jsfrom that base and ships neither copy. The comment now names both libraries.server/typescript/packages/runtime-ts/src/meta-endpoint.ts:52- Inline fix. ThemetaDocsJsonJSDoc said the body is "the same bytes as theexplorer.jsona docs-site build writes". Ameta gendocs-site build passes the verify ledger and the run's generation manifest intobuildDocsView, so itsexplorer.jsondiffers whenever the project has requirements or other generators. The comment now says the two match only when the build had neither.scripts/ci-local.sh:1128- Two checks compare the committed bundle byte for byte against a freshBun.build({ minify: true }):gate_explorer_app_drift(build-app.ts --check) and the ts-unit test "explorer-app/ is what the sources build" (server/typescript/packages/docs-site/test/explorer-app.test.ts:89). Minified output follows the Bun version. The workflows pin 1.3.14, but root package.json declarespackageManager: bun@1.3.8andengines.bun >=1.3.0. A contributor on the declared 1.3.8 who touches nothing in the explorer can therefore get a red gate and a red unit test whenever the two minifiers disagree. I did not reproduce a difference; the coupling is the risk. Remedy: make the bundle independent of the Bun version, for example build it unminified for the check, or pin one Bun version for the check and fail with a clear message on any other.server/typescript/packages/runtime-ts/test/meta-docs-route.test.ts:16- Weak oracle under the test-quality rule. The body tests comparemetaDocsJson(root)toserializeDocsView(buildDocsView({ root })), which is the implementation's own expression copied. The mount tests compare the response tometaDocsJson(root), so they inherit the same oracle. If the docs view builder or serializer went wrong, every one of these would still pass. metadata-api.md names an independent oracle for this cross-port body:fixtures/explorer-conformance/<case>/expected.json. Load that case's model, mount the route, and compare the served body to the fixture (with no routes passed, as the fixture's model-alone view).scripts/sync-explorer-app.sh:12- Simplification. The change commits three copies of the app (about 2 MB each: the bundle, Cytoscape, 3d-force-graph) into the Python, Java and C# packages, plus theexplorer app copiesgate that keeps them in step. No code in those ports reads them; the changelog says "the other ports' docs-site generators are still to write them". Hatch includesserver/python/src/metaobjects/documentation/explorer_app/in the PyPI wheel, and the Java copy ships in thecodegen-basejar, so each published artifact grows by about 2 MB of unused files. The intent requires the app and its TypeScript writer, not port copies with no consumer. Recommendation: drop the three port copies and their gate entries until a port's generator writes the app. Keep onlyexplorer-app/and the TypeScript package copy.server/typescript/packages/docs-site/src/explorer/site.ts:146- Simplification. The intent takes Option 4, "the explorer becomes one browser app over the docs view ..., replacing the static per-port page loop". The change keeps that loop as a second mode,output: "static"(ongenerateExplorerSiteanddocsSiteFile). It also keeps theexplorer-data.jswriter and theassetBasemirror branch that applies only to this mode. The intent does not require it. The stated reasons are Pagefind and publishing without scripts, and several tests use it as their oracle. Recommendation: confirm with the user that the static export should survive in 1.3.0. If not, remove it and its static-only options.server/typescript/packages/runtime-ts/src/meta-endpoint.ts:61- Simplification. The docs view route adds ETag generation (metaDocsEtag),If-None-Matchmatching with 304 (etagMatches), andAccess-Control-Expose-Headers: ETag. metadata-api.md then makes the ETag and the 304 part of the cross-port contract every other port must serve. The intent asks only that the explorer follow a running application, and the app already detects change by comparing bodies (text !== lastin app-src/main.ts). The 304 saves bandwidth on a once-a-second poll of what can be a large view, so it is a reasonable optimisation, but it is not required. Narrower form: serve the body withCache-Control: no-cacheonly, and keep ETag out of the cross-port contract (or make it optional).server/typescript/packages/docs-site/app-src/main.ts:239- Simplification. The?title=query parameter (params.get("title") ?? base?.title ?? url.host) is an extra input that no intent requirement asks for. The model file already supplies the title, and the host is the fallback. Recommendation: remove the parameter, and the sentence in docs/features/explorer-site.md that describes it.🔧 Fix applied.
6 issues (3 warnings, 3 infos) still open:
server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts:69- Inline fix. TheassetBasedoc comment said a static explorer loads only Cytoscape from the mirror.site.tsalso loads3d-force-graph.min.jsfrom that base and ships neither copy. The comment now names both libraries.server/typescript/packages/runtime-ts/src/meta-endpoint.ts:52- Inline fix. ThemetaDocsJsonJSDoc said the body is "the same bytes as theexplorer.jsona docs-site build writes". Ameta gendocs-site build passes the verify ledger and the run's generation manifest intobuildDocsView, so itsexplorer.jsondiffers whenever the project has requirements or other generators. The comment now says the two match only when the build had neither.scripts/sync-explorer-app.sh:12- Simplification. The change commits three copies of the app (about 2 MB each: the bundle, Cytoscape, 3d-force-graph) into the Python, Java and C# packages, plus theexplorer app copiesgate that keeps them in step. No code in those ports reads them; the changelog says "the other ports' docs-site generators are still to write them". Hatch includesserver/python/src/metaobjects/documentation/explorer_app/in the PyPI wheel, and the Java copy ships in thecodegen-basejar, so each published artifact grows by about 2 MB of unused files. The intent requires the app and its TypeScript writer, not port copies with no consumer. Recommendation: drop the three port copies and their gate entries until a port's generator writes the app. Keep onlyexplorer-app/and the TypeScript package copy.server/typescript/packages/docs-site/src/explorer/site.ts:146- Simplification. The intent takes Option 4, "the explorer becomes one browser app over the docs view ..., replacing the static per-port page loop". The change keeps that loop as a second mode,output: "static"(ongenerateExplorerSiteanddocsSiteFile). It also keeps theexplorer-data.jswriter and theassetBasemirror branch that applies only to this mode. The intent does not require it. The stated reasons are Pagefind and publishing without scripts, and several tests use it as their oracle. Recommendation: confirm with the user that the static export should survive in 1.3.0. If not, remove it and its static-only options.server/typescript/packages/docs-site/scripts/build-app.ts:44- This fix-round code came from round 1's F3 fix. The pinEXPLORER_APP_BUN = "1.3.14"makesbuildExplorerApp()throw on any other Bun. Rootpackage.json:36still declares"packageManager": "bun@1.3.8", andengines.bunis>=1.3.0. A contributor on the declared Bun 1.3.8 who touches nothing in the explorer now always fails two checks. The first is the ts-unit testexplorer-app/ is what the sources build(server/typescript/packages/docs-site/test/explorer-app.test.ts:89), which callsbuildExplorerApp(). The second is theexplorer app copiesgate (scripts/ci-local.sh:1128). Before the fix, failure was possible; now it is certain on any Bun other than 1.3.14. CI and this machine use 1.3.14, so hosted runs stay green. The cause is that the repository declares two Bun versions. Remedy: set rootpackageManagertobun@1.3.14, the version every workflow pins. integration-tests.yml:96 already records that 1.3.8 segfaults on exit. Because this is a repo-wide toolchain declaration, confirm it with the user. The alternative is to make the unit test skip with the version message while the gate stays strict.explorer-app/README.md:19- Inline fix. The rebuild instructions did not say that build-app.ts now runs only on the pinned Bun. I added a paragraph that namesEXPLORER_APP_BUN(1.3.14) and says any other Bun stops with an error. The copies gate excludes README.md, so the port copies are unaffected.🔧 Fix applied.
5 issues (2 warnings, 3 infos) still open:
server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts:69- Inline fix. TheassetBasedoc comment said a static explorer loads only Cytoscape from the mirror.site.tsalso loads3d-force-graph.min.jsfrom that base and ships neither copy. The comment now names both libraries.server/typescript/packages/runtime-ts/src/meta-endpoint.ts:52- Inline fix. ThemetaDocsJsonJSDoc said the body is "the same bytes as theexplorer.jsona docs-site build writes". Ameta gendocs-site build passes the verify ledger and the run's generation manifest intobuildDocsView, so itsexplorer.jsondiffers whenever the project has requirements or other generators. The comment now says the two match only when the build had neither.scripts/sync-explorer-app.sh:12- Simplification. The change commits three copies of the app (about 2 MB each: the bundle, Cytoscape, 3d-force-graph) into the Python, Java and C# packages, plus theexplorer app copiesgate that keeps them in step. No code in those ports reads them; the changelog says "the other ports' docs-site generators are still to write them". Hatch includesserver/python/src/metaobjects/documentation/explorer_app/in the PyPI wheel, and the Java copy ships in thecodegen-basejar, so each published artifact grows by about 2 MB of unused files. The intent requires the app and its TypeScript writer, not port copies with no consumer. Recommendation: drop the three port copies and their gate entries until a port's generator writes the app. Keep onlyexplorer-app/and the TypeScript package copy.server/typescript/packages/docs-site/src/explorer/site.ts:146- Simplification. The intent takes Option 4, "the explorer becomes one browser app over the docs view ..., replacing the static per-port page loop". The change keeps that loop as a second mode,output: "static"(ongenerateExplorerSiteanddocsSiteFile). It also keeps theexplorer-data.jswriter and theassetBasemirror branch that applies only to this mode. The intent does not require it. The stated reasons are Pagefind and publishing without scripts, and several tests use it as their oracle. Recommendation: confirm with the user that the static export should survive in 1.3.0. If not, remove it and its static-only options.explorer-app/README.md:19- Inline fix. The rebuild instructions did not say that build-app.ts now runs only on the pinned Bun. I added a paragraph that namesEXPLORER_APP_BUN(1.3.14) and says any other Bun stops with an error. The copies gate excludes README.md, so the port copies are unaffected.🔧 **Test** - 2 issues found → auto-fixed ✅
server/typescript/packages/runtime-ts/src/fastify/index.ts- Live check:/_meta/docsserves the model loaded at mount. A model edit on disk is not visible until the backend restarts (no reload hook in mountMetaDocsRoute). The intent says the explorer follows model changes on disk, so this scenario fails. Decide whether the in-app endpoint must reload, or whether reload is the host's job. The static file:// path was not driven live here.scripts/ci-local.sh --affected --strict-toolchainsbun scripts/build-app.ts --checkin server/typescript/packages/docs-site (exit 0)bun test test/meta-docs-route.test.tsin server/typescript/packages/runtime-ts (8 pass)Live: Fastify server on 127.0.0.1 with mountMetaDocsRoute over fixtures/explorer-conformance/model-alone copy; GET /api/_meta/docs; cmp against expected.json (byte identical)Live: If-None-Match with matching ETag -> 304; non-matching -> 200Live: edited model file on disk while server running, refetched -> no Publisher entity served; restarted server -> Publisher present🔧 Fix applied.
✅ Re-checked - no issues remain.
scripts/ci-local.sh --affected --strict-toolchainsFastify app withmountMetaDocsRoute(runtime-ts src) onfixtures/explorer-conformance/model-alone/project, loaded withMetaDataLoader.fromDirectorystrict;curl GET /_meta/docsheaders and bodycmp served body againstfixtures/explorer-conformance/model-alone/expected.json(independent oracle, byte-identical)curl -H 'If-None-Match: <current ETag>' /_meta/docsreturns 304Copy of model-alone project in $DEV_SCRATCH: rename Author to Writer in metaobjects/meta.library.json, restart server, body contains acme::library::Writer and no acme::library::AuthorBaselinescripts/ci-local.sh --affected --strict-toolchainsalready passed at this commit; not re-run (no source changes in this turn)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.