Skip to content

feat(metadata): build port-neutral docs view from loaded model - #665

Merged
dmealing merged 7 commits into
mainfrom
fm/mo-130-ts-docs-view
Nov 27, 2026
Merged

dmealing merged 7 commits into
mainfrom
fm/mo-130-ts-docs-view

Conversation

@dmealing

@dmealing dmealing commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Adds buildDocsView and serializeDocsView in @metaobjectsdev/metadata (src/docs-view/). They build one facts-only docs view from the loaded, resolved model: nodes with effective attrs, grouped members, resolved references and reverse references, requirements flat with depth and status roll-ups, claims, generated files, packages, counts and verify advisories. No HTML or Markdown.
  • The docs-site explorer now renders from that view instead of its own model re-derivation. docs-site/src/explorer/build.ts and index-model.ts are removed, replaced by view-index.ts. docsSiteFile() builds the view from ctx.loadedRoot and generateExplorerSite writes it as explorer.json.
  • Adds the fixtures/explorer-conformance/crm corpus (custom vocabulary, with provider, verify and expected outputs), reworks shop expected output, and gates the view with metadata/test/docs-view-conformance.test.ts. The contract is in docs/features/docs-view.md.

Evidence

Corpus diff (fixtures/explorer-conformance/, main...HEAD):

 README.md                              |   95 +-
 crm/expected.json                      | 2233 +++++++++++
 crm/project/metaobjects/meta.crm.json  |  112 +
 crm/project/metaobjects/meta.tax.json  |    8 +
 crm/provider.json                      |   42 +
 crm/verify.json                        |   80 +
 shop/effective.json                    |  348 --
 shop/expected.json                     | 3891 ++++++++++++++++----
 shop/routes.json                       |    7 +
 9 files changed, 5646 insertions(+), 1170 deletions(-)
  • shop/expected.json is re-pinned as the docs view (10 nodes, 9 requirements). effective.json is gone, because the view is built from the loaded model, not from meta export --effective. routes.json is new.
  • crm/ is new. Its vocabulary (page.list, block.table, capability.module) is declared only in provider.json. Its members and @objectRef references appear in the view with no docs code that names them. It also pins three id rules: a same-name page declared before its entity (the entity keeps its claims), @of on an inherited member (it lands on the owner's row), and a nameless source.rdb with @parameterRef (its label keeps #0).

Site build: main versus this branch. Each side builds the explorer with generateExplorerSite, from the same loaded model. generateExplorerSite throws on a dangling link, so every build below also passed the link check.

Model Files (main / branch) Pages identical Only an empty anchor <span id="m-…"> added Other
shop (same inputs, no routes) 32 / 32 26 3 0
fitness (persistence-conformance/canonical) 75 / 75 19 36 17
crm (new) — / 26
  • Anchors. Some members get no table row on a page, for example a source or an index. Each now gets an empty, invisible anchor in the crumbs, so every link the view states lands. The Mustache templates are unchanged, so a theme someone ejected keeps working.
  • The 17 other fitness pages. 15 gain "Referenced by" links that the old seven-kind edge list never read: a report's @from/@spine, a projection's @of/@via, a junction's @through. For example, Program gains LiveIntroPrograms, ProgramsByMonth and RecentPrograms. The other two (AllTypesBreakdown, LiveIntroPrograms) print @filter with its keys in code-unit order. No link was lost.
  • Map. The map's nodes are identical on both sides. Edges are labelled with the reference attribute, so payload becomes payloadRef, reply becomes responseRef, and association becomes objectRef. Fitness goes from 51 edges to 71. main shipped one dangling edge, IntEnumArray → PublishState, to a node the map does not draw. The branch emits only edges whose two ends are drawn.

Drift gate. gen-docs-generators.test.ts covers it: a second meta gen run is identical, and meta verify --codegen reports clean.

Local checks before the gate. Root bun run build and bun run typecheck pass. The metadata, docs-site, codegen-ts and cli suites pass with 0 failures, and so does scripts/ci-local.sh --only gates.

The no-mistakes gate took 1 run: three review fix rounds and one document fix.

Validation

Risk Assessment

✅ Low: The latest fix round is small. It changes refLink to one byPlain lookup and pins the three id rules in the crm corpus. I traced the crm view and found the expected results: Lead keeps its claims while the page is declared first, and @Of Lead.score lands on Lead.html#m-score with declaredOn Scored. The nameless source keeps its #0 label. The spec, README and CONFORMANCE notes match the code.

Testing

Baseline ci-local --affected passed at target commit. Live probe of the builder on a disposable project with the requirement declared before its entity: the shadowing fix holds (entity keeps claim; requirement gets its own node). Docs-view conformance and ref tests pass (17), but that is not live evidence. Inherited-member links, nameless member labels, and CLI explorer.json output were not driven live. Worktree clean. No evidence files written; no background processes.

  • Live validation: ✅ go - 1 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Requirement declared before same-name entity: entity keeps plain id, claim and implementedBy (live: local buildDocsView over loader output, synthetic package acme::shop) ✅ pass live bun probe calling MetaDataLoader.fromDirectory + buildDocsView on a temp project; node acme::shop::Order claims=1; acme::shop::Order[requirement.functional] claims=0 at requirements/ path; implemented…
Docs view corpus reproduces expected.json for shop and crm, plus id, inheritance, reference and requirement rules ⏸️ untested no Unit and conformance tests run the builder in-process; they are not a live product run, so they do not count as a live pass.
Inherited-member reflink and nameless member label (#3) against a live probe ⏸️ untested no Not driven live. Ran out of time budget. Covered by the fix-round unit tests only, which the review noted are not in the shared corpus. Needs a probe with abstract Base.total and Order extends Base, a…
explorer.json written by the CLI and read by the browser map/search ⏸️ untested no Not driven. This step builds the TS view only; part B (pages into Mustache, CLI wiring) is not in this change. Needs a meta gen docs run on a fixture.
  • Outcome: ⚠️ 1 warning across 1 run (6m58s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ⚠️ server/typescript/packages/metadata/src/docs-view/build.ts:195 - byPlain keeps whichever node with a given plain path the walk reaches first (if (!this.byPlain.has(plain))). That contradicts the id rule a few lines up, under which an object keeps the plain id even when it is declared later. Concrete sequence: a page Lead (or a requirement Order) is declared before the entity of the same name, for example pages in meta.app.json loading before entities in meta.crm.json. Then byPlain.get(&#34;acme::crm::Lead&#34;) returns the page. Members also collide, because a qualified top's members build plain from the unqualified parent.plain: a page block email shadows the entity field email. Every resolution-key lookup then lands on the wrong node with no error: (1) claims at build.ts:391, where resolveClaimTarget returns the entity but the claim, the requirement's targets and the link go to the page; (2) manifest sourceNode at :416, so generated files are listed on the page; (3) routes at :428; (4) advisories at :443, so subject and the entity's unclaimed flag (:447/:520) move to the page and the entity page loses its unclaimed outline. The old builder keyed these by id, where the object held the plain id. The crm fixture declares the entity first, so the corpus misses this. Fix: when a plain path is already held, let the walked node whose top holds the unqualified id (w.top.id === w.top.plain) take over. Add a corpus or unit case with the non-object declared first.

  • ℹ️ docs/features/docs-view.md:73 - The spec says "A link to an inherited member lands on the node that declares it, because a reference to that member resolves there". The builder does not do this for the two main link sources. A claim such as @implementedBy: Customer.id, with id inherited from BaseEntity, resolves through byPlain to the walk under Customer, so it lands on Customer.html#m-id (build.ts:391; the corpus test asserts exactly that path for the inherited member). A reference value acme::shop::Customer.id fails the topLevelNodeOf(exact) === owner check (build.ts:239), so it falls back to the owner and lands on Customer.html, not on BaseEntity. Only declaredOn and a member's extends land on the declaring node. Since other ports will be held to this spec, either correct the sentence or make the builder match it.

  • ⚠️ server/typescript/packages/docs-site/src/index.ts:7 - Simplification: the change adds new public exports that no intent requirement needs. @metaobjectsdev/docs-site now exports ViewIndex, STATUSES and STATUS_GLYPH, plus the PageNode, ReqEntry, Claim and ModelEdge types, at index.ts:7-8. Nothing outside the docs-site package imports them. @metaobjectsdev/metadata also exports docsPackageDir and docsPageStem through docs-view/index.ts:1, and only build.ts uses them. The intent asks only for buildDocsView/serializeDocsView and the view types to be public. ViewIndex is page-side scaffolding that part B (moving HTML into templates and deleting pages.ts/html.ts) will likely reshape, so exporting it now in unreleased 1.3.0 creates API surface that later has to be broken. Suggested fix: remove these exports, unless they are meant for owned themes.

  • ℹ️ CHANGELOG.md:1469 - Inline fix. The CHANGELOG ("never a list of attribute names"), docs/features/docs-view.md:34 and docs/features/explorer-data.md:29 said a provider's vocabulary gets its links with no change. But the loader resolves only attributes in the fixed core set REF_BEARING_ATTR_NAMES (resolve-references.ts:137 via isRefBearingAttr). A provider attribute with another name (for example @entityRef) stays text, and the crm fixture links only because it reuses @objectRef. I reworded all three places: a provider attribute links when the loader resolves it as a reference (such as @objectRef). The test header comment in metadata/test/docs-view-conformance.test.ts:6-8 makes the same overstatement and is left for the fixer, because I do not edit test files inline.

  • ⚠️ server/typescript/packages/metadata/src/docs-view/build.ts:195 - This round-1 finding is still open. The only commit after the original change (633ac38, reviewer inline fixes) edits docs only. byPlain keeps the first walked holder of a plain path (if (!this.byPlain.has(plain))). That contradicts the id rule at :143-160, under which the object holds the plain id even when it is declared later. I reproduced it with a probe on the current code. Package acme::shop declares requirement.functional Order (@implementedBy: [&#34;Order&#34;]) before object.entity Order, with routes and manifest keyed acme::shop::Order. The result has the entity acme::shop::Order with 0 claims, 0 routes and 0 files. acme::shop::Order[requirement.functional] gets 1 claim, 1 route and 1 file. The implementedBy link also points at the requirement's own page. Nothing errors. Members collide the same way: a qualified top builds its members' plain from the unqualified parent.plain (:162), so a page block email would shadow an entity field email. Every consumer of byPlain lands on the wrong node: claims at :391 (resolveClaimTarget returned the entity, but the lookup by its resolution key gets the other node); the manifest sourceNode at :416; routes at :428; advisory subject at :443, and therefore unclaimedIds at :447 and the entity's unclaimed flag at :520. The crm corpus declares the entity first, so the corpus does not catch this. Fix: when a plain path is already held, let the node whose top holds the unqualified id (w.top.id === w.top.plain) replace the holder, or key byPlain only from walks under plain-id tops. Add a corpus or unit case in which the non-object is declared first.

  • ⚠️ server/typescript/packages/metadata/src/docs-view/build.ts:239 - Round 1 reported this as a doc mismatch (info). It is still unfixed, and it is a wrong value, not only wording. When a reference value names a member the owner inherits, refLink drops the member and links to the owner. The guard topLevelNodeOf(exact) === owner fails because the member physically sits on the base. Probe: Base (abstract) declares total, and Order extends Base. An origin.aggregate with @of: &#34;Order.total&#34; produces a link to acme::shop::Order / model/acme/shop/Order.html, with no member anchor. Two specs disagree with this. docs-view.md:157-159 says the link points at the member the dotted tail names. docs-view.md:73-74 says a link to an inherited member lands on the node that declares it. The builder applies three different rules to the same member: extends lands on the declaring node (Base.html#m-total); a claim @implementedBy: Order.total lands on the subtype's row (Order.html#m-total, via byPlain at :391); an attribute reference lands on the owner page with no member. Other ports will be pinned to this corpus, and no corpus case has a dotted reference to an inherited member. Pick one rule. Suggested fix: when exact is not physically under owner, resolve the walk of owner plus the dotted tail through byPlain (consistent with claims). Then correct the sentence at docs-view.md:73-74 to state that rule (extends/declaredOn still name the declaring node), and add a corpus case.

  • ⚠️ server/typescript/packages/docs-site/src/index.ts:7 - Simplification, still open from round 1 with no recorded decision. @metaobjectsdev/docs-site now exports ViewIndex, STATUSES, STATUS_GLYPH and the types PageNode, ReqEntry, Claim and ModelEdge. Nothing outside the package imports them. @metaobjectsdev/metadata also exports docsPackageDir and docsPageStem (docs-view/index.ts:1), and only build.ts uses them. The intent asks for buildDocsView/serializeDocsView and the view types. ViewIndex is page-side scaffolding that part B (pages into Mustache templates, deleting pages.ts/html.ts) will probably reshape. Exporting it in unreleased 1.3.0 creates API surface that a later step would have to break. A related point: docs-site/src/explorer/pages.ts:134 keeps its own pkgDir, a second copy of the docsPackageDir rule, for the package index path. If docsPackageDir stays exported, pages.ts should use it. Otherwise drop the export. Recommendation: remove the docs-site exports and the two helper exports, unless they are meant for owned themes.

  • ℹ️ server/typescript/packages/metadata/src/docs-view/build.ts:225 - A direct member with no name has the id &lt;top&gt;#&lt;index&gt; (:163). The member label is built as w.id.slice(w.top.id.length + 1), so the # is cut off. A probe gives {label: &#34;Order.3&#34;, id: &#34;acme::shop::Order#3&#34;}, which contradicts the spec rule &lt;owner name&gt;.&lt;member path&gt; and the id. The same slice produces DocsViewClaim.member at :400. Nameless members with a reference attribute are legal, for example a nameless source.rdb with @parameterRef. No corpus case has one, so the bytes other ports will match are still open. Fix: slice from top.id.length and drop a leading . only, so nameless members keep #&lt;index&gt;.

  • ℹ️ server/typescript/packages/metadata/test/docs-view-conformance.test.ts:6 - Left open from round 1 (the reviewer does not edit tests inline). The header says a provider's references "must come out linked with no change to the builder: the view reads the loader's resolution, never a list of attribute names". The loader resolves only attributes in the fixed core set REF_BEARING_ATTR_NAMES (naming-refs.ts:57, via isRefBearingAttr). The crm fixture links only because it reuses @objectRef. Reword to match CHANGELOG/docs-view.md: a provider attribute links when the loader resolves it as a reference (such as @objectRef).

🔧 Fix applied.
4 infos still open:

  • ℹ️ server/typescript/packages/metadata/test/docs-view-conformance.test.ts:6 - Left open from round 1 (the reviewer does not edit tests inline). The header says a provider's references "must come out linked with no change to the builder: the view reads the loader's resolution, never a list of attribute names". The loader resolves only attributes in the fixed core set REF_BEARING_ATTR_NAMES (naming-refs.ts:57, via isRefBearingAttr). The crm fixture links only because it reuses @objectRef. Reword to match CHANGELOG/docs-view.md: a provider attribute links when the loader resolves it as a reference (such as @objectRef).
  • ℹ️ server/typescript/packages/metadata/test/docs-view-conformance.test.ts:195 - The round-2 fix round added three view rules, and only TypeScript unit tests pin them: (1) the plain-id holder owns byPlain whatever the declaration order (build.ts:196); (2) a reference value naming an inherited member lands on the owner's own row (build.ts:243); (3) a nameless member keeps #&lt;index&gt; in its label and claim member (build.ts:226, :249). Neither shared fixture exercises them. shop and crm have no dotted reference attribute, no same-name node declared before an object, and no nameless member with a reference. The intent says the view is pinned by the corpus so that every port's view is byte-identical. A later port could therefore diverge on all three rules and still pass the corpus. Suggested fix: add these cases to a corpus fixture (for example crm: a projection with @of on an inherited member, a nameless source.rdb with @parameterRef, and a page declared before the same-name entity), then re-pin expected.json with UPDATE_DOCS_VIEW=1. Once the corpus covers them, the unit tests can stay or be dropped.
  • ℹ️ server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts:158 - Inline fix. The change left two JSDoc blocks stacked above interface RunRoute, and the stale one, which describes runRoutes, sat first. I moved the runRoutes doc comment down onto the function.
  • ℹ️ server/typescript/packages/metadata/src/docs-view/types.ts:14 - Inline fix. The fix round changed the member label and the claim member so that a nameless member keeps #&lt;index&gt;, and it updated docs-view.md to match. It did not update the type doc comments. DocsViewLink.label still said &lt;owner name&gt;.&lt;member path&gt;, and DocsViewClaim.member (line 66) still said "dotted member path". I reworded both to match the spec: the member's id after the owner's id, with Order#3 / #3 for a nameless member.

🔧 Fix applied.
📝 2 wording or comment-placement notes left for the author (no fix round spent):

  • ℹ️ server/typescript/packages/codegen-ts/src/generators/docs-site-file.ts:158 - Inline fix. The change left two JSDoc blocks stacked above interface RunRoute, and the stale one, which describes runRoutes, sat first. I moved the runRoutes doc comment down onto the function.
  • ℹ️ server/typescript/packages/metadata/src/docs-view/types.ts:14 - Inline fix. The fix round changed the member label and the claim member so that a nameless member keeps #&lt;index&gt;, and it updated docs-view.md to match. It did not update the type doc comments. DocsViewLink.label still said &lt;owner name&gt;.&lt;member path&gt;, and DocsViewClaim.member (line 66) still said "dotted member path". I reworded both to match the spec: the member's id after the owner's id, with Order#3 / #3 for a nameless member.
⚠️ **Test** - 1 warning
  • ⚠️ server/typescript/packages/metadata/src/docs-view/build.ts:243 - Live check of the inherited-member link (fix round 4 rule) and nameless member label was not driven; only unit tests cover them and the shared corpus does not yet pin them. Recommend a corpus case, as the review asked.
  • Live validation: ✅ go - 1 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Requirement declared before same-name entity: entity keeps plain id, claim and implementedBy (live: local buildDocsView over loader output, synthetic package acme::shop) ✅ pass live bun probe calling MetaDataLoader.fromDirectory + buildDocsView on a temp project; node acme::shop::Order claims=1; acme::shop::Order[requirement.functional] claims=0 at requirements/ path; implemented…
Docs view corpus reproduces expected.json for shop and crm, plus id, inheritance, reference and requirement rules ⏸️ untested no Unit and conformance tests run the builder in-process; they are not a live product run, so they do not count as a live pass.
Inherited-member reflink and nameless member label (#3) against a live probe ⏸️ untested no Not driven live. Ran out of time budget. Covered by the fix-round unit tests only, which the review noted are not in the shared corpus. Needs a probe with abstract Base.total and Order extends Base, a…
explorer.json written by the CLI and read by the browser map/search ⏸️ untested no Not driven. This step builds the TS view only; part B (pages into Mustache, CLI wiring) is not in this change. Needs a meta gen docs run on a fixture.
  • scripts/ci-local.sh --affected --strict-toolchains
  • Probe: MetaDataLoader.fromDirectory + buildDocsView on a temp project with requirement declared before same-name object (byPlain shadowing regression), run under DEV_SCRATCH and removed afterwards
  • bun test test/docs-view-conformance.test.ts test/docs-ref.test.ts (server/typescript/packages/metadata): 17 pass, 0 fail, 73 expect calls
🔧 **Document** - 1 issue found → auto-fixed ✅
  • ℹ️ docs/features/codegen-data-shapes.md:87 - States the requirement rows are what the explorer graph holds. The docs view now builds requirements from the verify ledger and loaded model, so this may be stale. Not verified in code; confirm whether requirementRows still feeds explorer.json.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Every documentation page reads one port-neutral document of facts, the docs view, and a
port builds it from the model it has already loaded rather than from re-derived JSON. This
is the first step of making docs ordinary configured Mustache codegen in every port.

- metadata: buildDocsView / serializeDocsView. Nodes of any type with effective attrs,
  members grouped by type (declaredOn for an inherited member), refs from the loader's own
  resolution and their reverse, claims through the gate's resolver, files and routes; the
  requirements flat with depth, status, links and roll-up; packages, counts, advisories and
  slices. Facts only, every key always present, object values in code-unit key order.
- docs-site: the explorer pages read the view through a ViewIndex. build.ts, index-model.ts
  and types.ts are deleted, with markInherited and the seven-kind edge list. The pages look
  the same: a member with no row gets an empty anchor in the crumbs, and "Referenced by" and
  the map now carry every resolved reference. The map draws only edges whose two ends it
  draws. Templates are unchanged, so an ejected theme keeps working.
- fixtures/explorer-conformance: shop re-pinned as the view (effective.json dropped,
  routes.json added); new crm case with provider.json vocabulary whose members and refs
  appear with no docs code that names them.
- docs: docs/features/docs-view.md (the contract); explorer-data.md rewritten around the
  inputs; explorer-site, CONFORMANCE, READMEs and CHANGELOG updated.
@dmealing
dmealing merged commit 86a0b03 into main Nov 27, 2026
11 checks passed
@dmealing
dmealing deleted the fm/mo-130-ts-docs-view branch November 27, 2026 11:29
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