Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions changelog.d/explorer-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- **docs-site: the model explorer is one browser app.** `docsSiteFile()` now writes the
explorer as a few files (a shell, the app, the theme, Cytoscape and three data files:
`explorer.json`, `explorer-model.js`, `explorer-stamp.js`) in place of a page per screen.
The app draws every page when it is visited, with the same page code and templates, so each
page is byte-for-byte the one the static site wrote. It runs from `file://` with no server,
addresses each page as `index.html#/<page>`, and follows the model while it is open: it polls
the stamp file about once a second and draws the current page again when `meta gen` rewrites
the model. Cytoscape 3.30.2 (MIT) ships with the site, so the graphs draw offline and the
CDN notice is gone. `docsSiteFile({ output: "static" })` (and `generateExplorerSite({ output:
"static" })`) writes the earlier page-per-screen site from the same code, for publishing
without scripts or for Pagefind; `assetBase` now applies to that export only, which given one
loads Cytoscape from it and ships no copy. The app's files live once at `explorer-app/` and
in every port's package (`scripts/sync-explorer-app.sh`, gated by `explorer app copies`);
the other ports' docs-site generators are still to write them. Generated-output change: the
next `meta gen` replaces the explorer's pages with the app's files, and `meta verify
--codegen` holds the new files to the model as before.
If you ejected the theme on a 1.3.0 candidate, your `codegen/docs-site/assets/explorer.js`
predates the app, which calls `window.MO_THEME` each time it draws a page: without that hook
search, the theme toggle and the graphs do nothing. Copy it again with `meta eject docs-site
--force` and carry your edits into the new copy (the app also needs its `window.MO_APP` link,
query and listener hooks, so adding the one line is not enough).
100 changes: 80 additions & 20 deletions docs/features/explorer-site.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# The model explorer site

`docsSiteFile()` builds a static site that shows one project: what the software does, how the
`docsSiteFile()` builds a site that shows one project: what the software does, how the
model is put together, and whether each requirement claim holds. Every page is drawn from one
data file, [`explorer.json`](docs-view.md) (the docs view), which the generator builds during the same
`meta gen` run. A page never works a model fact out for itself.

By default the site is one browser app: a handful of files that draw every page when it is
visited, from `file://` with no server, and follow the model while it is open. `output:
"static"` writes every page as its own HTML file instead, from the same page code.

The explorer is the default site. The earlier site (package navigation, a page per object, the
Mermaid ER diagrams) is still there as `docsSiteFile({ site: "classic" })`.

Expand Down Expand Up @@ -35,26 +39,61 @@ generator in the run, wherever it appears in the list, because it reads what the
| Generated files per node | The files this run wrote, with the node each came from. Files under a target whose `outDir` lies outside the project are left out, under `meta gen` and `verify --codegen` alike |
| Routes per node | The REST routes this run's routes generator mounts; none if the run has no routes generator |

Open `site/index.html` in a browser, or serve the directory. The pages use relative links, so
the site works from any path and from `file://`.
Open `site/index.html` in a browser, or serve the directory. The site uses relative links, so
it works from any path and from `file://`.

### What it writes

| File | What it is |
|---|---|
| `index.html` | The app's shell |
| `assets/explorer-app.js` | The app: the explorer's page code and templates, and a router |
| `assets/explorer.css`, `assets/explorer.js` | The theme (yours, when you own it) |
| `assets/cytoscape.min.js` | [Cytoscape.js](https://js.cytoscape.org/) 3.30.2 (MIT), so the graphs draw offline |
| `explorer.json` | The docs view |
| `explorer-model.js` | The view, the prompt texts, the title and any owned templates, as a script |
| `explorer-stamp.js` | A hash of the model file |

Every page is an address inside the app: `index.html#/model/acme/shop/Order.html`, with the
map's and the trace's query and a member's anchor after it
(`#/map.html?slice=…`, `#/model/acme/shop/Order.html#m-total`). Back, forward, bookmarks and
opening a link in a new tab work as they do on a static site. The app files are the same in
every port; `explorer-app/README.md` at the repository root describes them and the two data
files a port writes beside them.

### The live view

Leave the explorer open while you work. About once a second it reloads `explorer-stamp.js`,
and when the stamp has moved (a `meta gen` rewrote the model) it reloads `explorer-model.js`
and draws the page you are on again, keeping the address and the scroll position. A model
file caught half-written is not taken: the app waits for one that carries the new stamp.

### The static export

`docsSiteFile({ output: "static" })` writes the earlier layout: a page per screen, the theme,
`assets/cytoscape.min.js`, `assets/explorer-data.js` (the map's data) and `explorer.json`. It
draws its pages with the same code as the app, and the two are held to each other page for
page. Use it to publish the site where scripts are not wanted, or to index it for full-text
search.

### Options

| Option | Default | What it does |
|---|---|---|
| `site` | `"explorer"` | `"classic"` builds the earlier site instead |
| `output` | `"app"` | The explorer only: `"static"` writes a page per screen (see "The static export") |
| `subDir` | `"site"` | The directory under the `docs` target |
| `title` | the project directory's name | The name in the header and the page titles |
| `prompts` | none | An extra directory of prompt `.mustache` sources, so the prompt pages can show the text |
| `stamp` | none | Footer text. With none, the pages depend on the model alone |
| `assetBase` | `https://cdn.jsdelivr.net/npm` | Where the graph library loads from (see "Offline use") |
| `assetBase` | none | A static explorer only: load the graph library from this base and ship no copy (see "Offline use"). The classic site's CDN base |
| `target` | `"docs"` | The output target |

### Search

Every page has a search box over a built-in index of objects, fields, prompts and
requirements; press `/` to jump to it. For full-text search, run
[Pagefind](https://pagefind.app/) over the output after `meta gen`:
requirements; press `/` to jump to it. For full-text search, build the static export and run
[Pagefind](https://pagefind.app/) over it after `meta gen`:

```bash
npx pagefind --site docs/generated/site
Expand All @@ -70,15 +109,17 @@ Pagefind's output is not generated by `meta gen`, so leave `pagefind/` out of th
### Offline use

The map, the mini-maps and the trace draw with [Cytoscape.js](https://js.cytoscape.org/),
loaded from `${assetBase}/cytoscape@3.30.2/dist/cytoscape.min.js`. Only those three kinds of
page load it. Opened without network access, every page still renders and the graphs show a
notice in their place. To serve the file yourself, put
`cytoscape@3.30.2/dist/cytoscape.min.js` under a path of your own and pass that path:
which the site ships as `assets/cytoscape.min.js`, so the explorer needs no network access.
A static export loads it only on those three kinds of page. To load it from a mirror of your
own instead, give a static export an `assetBase`: its pages then load
`${assetBase}/cytoscape@3.30.2/dist/cytoscape.min.js` and the site ships no copy.

```ts
docsSiteFile({ assetBase: "/vendor/npm" })
docsSiteFile({ output: "static", assetBase: "/vendor/npm" })
```

If the library does not load, every page still renders and the graphs show a notice.

## The screens

| Screen | Page | What it shows |
Expand Down Expand Up @@ -130,16 +171,27 @@ copies the templates of both sites to `codegen/docs-site/templates/` (the explor
`explorer-*.mustache` files) and their CSS and JS to `codegen/docs-site/assets/`
(`explorer.css`, `explorer.js`). Only files that are not there yet are written (`--force`
overwrites). `docsSiteFile()` renders with your copies, and a file you did not copy falls back
to the packaged one. A project that ejected the theme before the explorer existed has only the
to the packaged one. The app carries your templates in `explorer-model.js` and draws every
page with them, and writes your CSS and JS in place of its own. The app keeps only each drawn
page's title and body, so what an owned `explorer-head.mustache` adds to `<head>` (a stylesheet,
a `<style>` block, a favicon, `<meta>` tags) reaches the static export only; put those
additions in your `explorer.css` or `explorer.js` instead. A project that ejected the theme before the explorer existed has only the
classic files; `meta gen` warns about it, and running `meta eject docs-site` again adds the
explorer's files without touching the ones you own.

The app calls `window.MO_THEME` each time it draws a page, and the packaged `explorer.js` sets it
to the function that wires search, the theme toggle and the graphs. An `explorer.js` ejected
from a 1.3.0 candidate predates that hook, so those controls do nothing in the app. Copy it again
with `meta eject docs-site --force` and carry your edits into the new copy: the app also needs
the copy's `window.MO_APP` hooks for links, the query string and listeners, so adding the one
line is not enough.

## Drift and determinism

The site prints no date and no build time, its graph layouts start from fixed positions, and
the same model writes the same bytes. `meta verify --codegen` therefore holds it to the model
like any other generated output. Every build also checks its own links and fails on a dangling
one.
the same model writes the same bytes, in both outputs. `meta verify --codegen` therefore holds
it to the model like any other generated output. Every build draws every page and checks its
links, the app's in memory, and fails on a dangling one.

## As a library

Expand All @@ -157,22 +209,30 @@ generateExplorerSite({
});
```

It takes `templatesDir`, `assetsDir`, `assetBase` and `stamp` as well, and throws on a
dangling link. `buildDocsView` also takes the verify payload, the manifest and the routes
It takes `output`, `templatesDir`, `assetsDir`, `assetBase` and `stamp` as well, and throws on
a dangling link. `createExplorer` (the page table both outputs draw from) and
`explorerModelScript` (the model file's writer) are exported too. `buildDocsView` also takes the verify payload, the manifest and the routes
([explorer-data.md](explorer-data.md)); the view's shape is [docs-view.md](docs-view.md).

## Not built yet

- A 3D view of the map, an LLM-written summary, a test-result overlay, a live view served by
the running application, and publishing the site.
- A 3D view of the map, an LLM-written summary, a test-result overlay, a view served by the
running application, and publishing the site.
- The app in the other ports: its files are in each port's package already (see
`explorer-app/README.md`), and each port's docs-site generator is still to write them.
- "Hand-written code that imports it": the site reads no import graph, so the object pages say
it was not scanned.
- Generated-file provenance from the JVM, Python and C# generators (see
[explorer-data.md](explorer-data.md)), so for those ports the generated-file lists are empty.

## Verified by

- `server/typescript/packages/docs-site/test/explorer-site.test.ts`: the shop and crm cases
- `server/typescript/packages/docs-site/test/explorer-app.test.ts`: the files the app output
writes, the model and stamp files, owned templates and theme, and the committed bundle, run
outside a browser, drawing every page the static export writes byte for byte on the shop, crm
and fitness models. `explorer-app/` is what the sources build, and the TypeScript package's
copy equals it (the `explorer app copies` gate checks every port's).
- `server/typescript/packages/docs-site/test/explorer-site.test.ts` (the static export): the shop and crm cases
(`fixtures/explorer-conformance/`) and the fitness model
(`fixtures/persistence-conformance/canonical/meta.fitness.json`). Every screen is written,
links resolve, two builds match byte for byte, status chips and verdict outlines are
Expand Down
60 changes: 60 additions & 0 deletions explorer-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# The model explorer app

The model explorer as one browser app, which every port's docs-site generator writes beside the
docs view. This directory is the canonical copy; each port's package carries the same bytes.

Everything here but this README and `assets/cytoscape.min.js` is built. Do not edit it by hand:
change the sources and rebuild.

```bash
bun server/typescript/packages/docs-site/scripts/build-app.ts # rebuild
bun server/typescript/packages/docs-site/scripts/build-app.ts --check # exit 1 when stale
bash scripts/sync-explorer-app.sh # refresh every port's copy
```

The `explorer app copies` step of `scripts/ci-local.sh --only gates` fails when this directory is
stale or a port's copy differs from it.

## Files

| File | What it is | Built from |
|---|---|---|
| `index.html` | The shell: loads the data, Cytoscape, the app and the theme | `server/typescript/packages/docs-site/app-src/index.html` |
| `assets/explorer-app.js` | The app: the explorer's page code and templates, and the router around them, as one classic script | `app-src/main.ts`, `src/explorer/{core,pages,html,view-index}.ts`, `templates/explorer-*.mustache`, the Mustache renderer |
| `assets/explorer.css`, `assets/explorer.js` | The theme (`meta eject docs-site` copies them; an owned copy replaces these in the written site) | `server/typescript/packages/docs-site/assets/` |
| `assets/explorer-app.js` (inlined) | [mustache.js](https://github.com/janl/mustache.js) 4.2.0, MIT (its licence is the file's header) | the npm package `mustache@4.2.0`, through `@metaobjectsdev/render` |
| `assets/cytoscape.min.js` | [Cytoscape.js](https://js.cytoscape.org/) 3.30.2, MIT (its licence is the file's header), so the graphs draw offline | vendored from the npm package `cytoscape@3.30.2`, `dist/cytoscape.min.js` |

## Where each port keeps its copy

| Port | Copy |
|---|---|
| TypeScript | `server/typescript/packages/docs-site/app/` |
| Python | `server/python/src/metaobjects/documentation/explorer_app/` |
| Java and Kotlin | `server/java/codegen-base/src/main/resources/metaobjects/explorer-app/` |
| C# | `server/csharp/MetaObjects.Codegen/ExplorerApp/` |

## What a port writes beside the app

A port's generator copies the files above into the site directory and writes three data files of
its own:

| File | Contents |
|---|---|
| `explorer.json` | The docs view (`docs/features/docs-view.md`) |
| `explorer-model.js` | `window.MO_MODEL = {"stamp":…,"title":…,"footer":…,"texts":{…},"templates":{…},"view":{…}};` — the project's title, the footer text, each prompt's text by node id, any owned explorer templates by basename (sorted keys), and the view, as compact JSON |
| `explorer-stamp.js` | `window.MO_STAMP = "<stamp>";` |

The stamp is the first 16 hex digits of the SHA-256 of the model's JSON without the stamp
(`{"title":…,…,"view":…}`). The app polls `explorer-stamp.js` about once a second and reloads
`explorer-model.js` when the stamp moves, so the open page follows a regenerated model. The
TypeScript writer is `explorerModelScript()` in `@metaobjectsdev/docs-site`.

## Drawing the pages outside a browser

The bundle sets `globalThis.MoExplorer.explorerFor(model)`, which takes the parsed `MO_MODEL`
object and returns the explorer's page table (`pages`, a map from site path to a function that
draws the page, and `graphData()`). The TypeScript static export (`docsSiteFile({ output:
"static" })`) draws the same pages from the same sources, and
`server/typescript/packages/docs-site/test/explorer-app.test.ts` holds this bundle to them page
for page.
32 changes: 32 additions & 0 deletions explorer-app/assets/cytoscape.min.js

Large diffs are not rendered by default.

Loading