From 8bb85d7c474c677b5766d48c259883a83943134e Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 27 Jun 2026 15:35:12 +0100 Subject: [PATCH] Add document surface diagnostics --- packages/cultmesh-ts/src/index.ts | 40 +++++++++++++++++++ packages/cultmesh-ts/test/cultmesh.test.ts | 38 +++++++++++++++++- src/GameCult.Mesh/CultMesh.cs | 29 ++++++++++++++ src/GameCult.Mesh/CultMeshPrimitives.cs | 14 +++++++ src/GameCult.Mesh/docs/public-api.md | 17 ++++---- .../CultMeshStreamingTests.cs | 21 +++++++++- 6 files changed, 149 insertions(+), 10 deletions(-) diff --git a/packages/cultmesh-ts/src/index.ts b/packages/cultmesh-ts/src/index.ts index f2505358..545a0e14 100644 --- a/packages/cultmesh-ts/src/index.ts +++ b/packages/cultmesh-ts/src/index.ts @@ -280,6 +280,8 @@ export type CultMeshSurfaceKind = | "projection-recipe" | "live-feed" | "operation" + | "document" + | "collection" | "state-pointer" | "native-slice-view"; @@ -301,6 +303,8 @@ export interface CultMeshSurfaceCatalogIndexDiagnostic { readonly projectionRecipes: readonly CultMeshSurfaceDiagnostic[]; readonly liveFeeds: readonly CultMeshSurfaceDiagnostic[]; readonly operations: readonly CultMeshSurfaceDiagnostic[]; + readonly documents: readonly CultMeshSurfaceDiagnostic[]; + readonly collections: readonly CultMeshSurfaceDiagnostic[]; readonly statePointers: readonly CultMeshSurfaceDiagnostic[]; readonly nativeSliceViews: readonly CultMeshSurfaceDiagnostic[]; } @@ -2504,6 +2508,16 @@ export function cultMeshDescribeSurface( readonly routeHint: CultMeshRouteHint; readonly sources: readonly CultMeshProjectionSource[]; } + | { + readonly documentId: string; + readonly routeHint: CultMeshRouteHint; + readonly sources: readonly CultMeshProjectionSource[]; + } + | { + readonly collectionId: string; + readonly routeHint: CultMeshRouteHint; + readonly sources: readonly CultMeshProjectionSource[]; + } | { readonly pointerId: string; readonly routeHint?: CultMeshRouteHint; @@ -2529,6 +2543,20 @@ export function cultMeshDescribeSurface( }); } + if ("documentId" in surface) { + return cultMeshSurfaceDiagnostic("document", surface.documentId, { + routeHint: surface.routeHint, + sources: surface.sources, + }); + } + + if ("collectionId" in surface) { + return cultMeshSurfaceDiagnostic("collection", surface.collectionId, { + routeHint: surface.routeHint, + sources: surface.sources, + }); + } + if ("viewId" in surface) { return cultMeshSurfaceDiagnostic("native-slice-view", surface.viewId, { routeHint: surface.route, @@ -2608,6 +2636,8 @@ export function cultMeshSurfaceCatalogIndex( projectionRecipes: cultMeshSurfacesByKind(catalog, "projection-recipe"), liveFeeds: cultMeshSurfacesByKind(catalog, "live-feed"), operations: cultMeshSurfacesByKind(catalog, "operation"), + documents: cultMeshSurfacesByKind(catalog, "document"), + collections: cultMeshSurfacesByKind(catalog, "collection"), statePointers: cultMeshSurfacesByKind(catalog, "state-pointer"), nativeSliceViews: cultMeshSurfacesByKind(catalog, "native-slice-view"), }; @@ -3849,6 +3879,16 @@ export class CultMesh { | { readonly pointerId: string; } + | { + readonly documentId: string; + readonly routeHint: CultMeshRouteHint; + readonly sources: readonly CultMeshProjectionSource[]; + } + | { + readonly collectionId: string; + readonly routeHint: CultMeshRouteHint; + readonly sources: readonly CultMeshProjectionSource[]; + } | CultMeshNativeSliceViewDescriptor, ): CultMeshSurfaceDiagnostic { return cultMeshDescribeSurface(surface); diff --git a/packages/cultmesh-ts/test/cultmesh.test.ts b/packages/cultmesh-ts/test/cultmesh.test.ts index 2660595d..7c79bae7 100644 --- a/packages/cultmesh-ts/test/cultmesh.test.ts +++ b/packages/cultmesh-ts/test/cultmesh.test.ts @@ -646,6 +646,24 @@ test("CultMesh TS describes typed surface catalogs for tools and generated bindi routeHint, }, ); + const document = CultMesh.document( + "daemon:aetheria.frame.latest.v1", + { schemaId: "gamecult.aetheria.daemon_frame.v1" }, + async () => ({ frameId: 1 }), + { + sources: [source], + routeHint, + }, + ); + const collection = CultMesh.collection( + "daemon:aetheria.contacts.v1", + { schemaId: "gamecult.aetheria.contact.v1" }, + async () => [], + { + sources: [source], + routeHint, + }, + ); const nativeView = CultMesh.nativeSliceView( "aetheria.zone.render", "gamecult.aetheria.render_body.v1", @@ -658,17 +676,23 @@ test("CultMesh TS describes typed surface catalogs for tools and generated bindi const feedSurface = CultMesh.describeSurface(feed); const operationSurface = CultMesh.describeSurface(operation); const pointerSurface = CultMesh.describeSurface(pointer); + const documentSurface = CultMesh.describeSurface(document); + const collectionSurface = CultMesh.describeSurface(collection); const nativeViewSurface = CultMesh.describeSurface(nativeView); const catalog = CultMesh.describeSurfaceCatalog("gamecult.aetheria.rts.surfaces.v1", [ querySurface, feedSurface, operationSurface, + documentSurface, + collectionSurface, pointerSurface, nativeViewSurface, ]); assert.equal(querySurface.kind, "query"); assert.equal(feedSurface.kind, "live-feed"); + assert.equal(documentSurface.kind, "document"); + assert.equal(collectionSurface.kind, "collection"); assert.equal(pointerSurface.kind, "state-pointer"); assert.equal(pointerSurface.routeHint.kind, "shared-memory"); assert.deepEqual(pointerSurface.sources.map(next => next.schemaId), [ @@ -680,6 +704,8 @@ test("CultMesh TS describes typed surface catalogs for tools and generated bindi "aetheria.zone.objects.visible", "aetheria.rts.viewport.feed", "aetheria.pilot.set_move_vector", + "daemon:aetheria.frame.latest.v1", + "daemon:aetheria.contacts.v1", "aetheria.selection.current", "aetheria.zone.render", ]); @@ -689,12 +715,16 @@ test("CultMesh TS describes typed surface catalogs for tools and generated bindi ]); assert.notEqual(catalog.surfaces[0], querySurface); assert.notEqual(catalog.surfaces[0].sources, querySurface.sources); - assert.equal(catalog.surfaces[4].routeHint.kind, "shared-memory"); + assert.equal(catalog.surfaces[6].routeHint.kind, "shared-memory"); assert.equal( CultMesh.findSurface(catalog, "aetheria.selection.current")?.kind, "state-pointer", ); + assert.equal( + CultMesh.findSurface(catalog, "daemon:aetheria.frame.latest.v1")?.kind, + "document", + ); assert.equal(CultMesh.findSurface(catalog, "missing"), undefined); const operations = CultMesh.surfacesByKind(catalog, "operation"); @@ -715,6 +745,12 @@ test("CultMesh TS describes typed surface catalogs for tools and generated bindi assert.deepEqual(index.operations.map(surface => surface.surfaceId), [ "aetheria.pilot.set_move_vector", ]); + assert.deepEqual(index.documents.map(surface => surface.surfaceId), [ + "daemon:aetheria.frame.latest.v1", + ]); + assert.deepEqual(index.collections.map(surface => surface.surfaceId), [ + "daemon:aetheria.contacts.v1", + ]); assert.deepEqual(index.statePointers.map(surface => surface.surfaceId), [ "aetheria.selection.current", ]); diff --git a/src/GameCult.Mesh/CultMesh.cs b/src/GameCult.Mesh/CultMesh.cs index 37b8b1bd..74afbe51 100644 --- a/src/GameCult.Mesh/CultMesh.cs +++ b/src/GameCult.Mesh/CultMesh.cs @@ -1454,6 +1454,35 @@ namespace GameCult.Mesh return new CultMeshSurfaceDiagnostic(CultMeshSurfaceKind.LiveFeed, feed.FeedId, feed.RouteHint, feed.Sources); } + /// + /// Describes a typed document handle as one entry in a surface catalog. + /// + public static CultMeshSurfaceDiagnostic DescribeSurface( + ICultMeshDocumentHandle document) + { + if (document == null) throw new ArgumentNullException(nameof(document)); + return new CultMeshSurfaceDiagnostic( + CultMeshSurfaceKind.Document, + document.DocumentId, + document.RouteHint, + document.Sources); + } + + /// + /// Describes a typed collection handle as one entry in a surface catalog. + /// + public static CultMeshSurfaceDiagnostic DescribeSurface( + CultMeshCollectionHandle collection) + where TDocument : class + { + if (collection == null) throw new ArgumentNullException(nameof(collection)); + return new CultMeshSurfaceDiagnostic( + CultMeshSurfaceKind.Collection, + collection.CollectionId, + collection.RouteHint, + collection.Sources); + } + /// /// Describes a typed state pointer as one entry in a surface catalog. /// diff --git a/src/GameCult.Mesh/CultMeshPrimitives.cs b/src/GameCult.Mesh/CultMeshPrimitives.cs index 5152e738..52f212cc 100644 --- a/src/GameCult.Mesh/CultMeshPrimitives.cs +++ b/src/GameCult.Mesh/CultMeshPrimitives.cs @@ -1502,6 +1502,12 @@ namespace GameCult.Mesh /// A typed operation handle. Operation, + /// A typed reactive document handle. + Document, + + /// A typed reactive collection handle. + Collection, + /// A typed pointer to Verse state. StatePointer, @@ -1608,6 +1614,8 @@ namespace GameCult.Mesh ProjectionRecipes = catalog.FindByKind(CultMeshSurfaceKind.ProjectionRecipe); LiveFeeds = catalog.FindByKind(CultMeshSurfaceKind.LiveFeed); Operations = catalog.FindByKind(CultMeshSurfaceKind.Operation); + Documents = catalog.FindByKind(CultMeshSurfaceKind.Document); + Collections = catalog.FindByKind(CultMeshSurfaceKind.Collection); StatePointers = catalog.FindByKind(CultMeshSurfaceKind.StatePointer); NativeSliceViews = catalog.FindByKind(CultMeshSurfaceKind.NativeSliceView); } @@ -1627,6 +1635,12 @@ namespace GameCult.Mesh /// Gets typed operation handles. public IReadOnlyList Operations { get; } + /// Gets typed reactive document handles. + public IReadOnlyList Documents { get; } + + /// Gets typed reactive collection handles. + public IReadOnlyList Collections { get; } + /// Gets typed pointers to Verse state. public IReadOnlyList StatePointers { get; } diff --git a/src/GameCult.Mesh/docs/public-api.md b/src/GameCult.Mesh/docs/public-api.md index e34d8263..b18f1dd5 100644 --- a/src/GameCult.Mesh/docs/public-api.md +++ b/src/GameCult.Mesh/docs/public-api.md @@ -388,19 +388,20 @@ diagnostic shape for generated clients, Eve/CultUI inspectors, MCP tools, and surface catalogs. Tooling should ask CultMesh for these descriptors instead of copying source lists and route hints by convention. `CultMesh.DescribeSurface(...)` and `CultMesh.DescribeSurfaceCatalog(...)` -collect query surfaces, projection recipes, live feeds, operations, state -pointers, and native views into one inspectable catalog for a runtime or -generated binding package. State pointers are advertised by pointer id; native -slice views are advertised by view id and route while the full column layout -stays in `CultMeshNativeSliceViewDescriptor`. +collect query surfaces, projection recipes, live feeds, operations, document +handles, collection handles, state pointers, and native views into one +inspectable catalog for a runtime or generated binding package. Documents are +advertised by document id, collections by collection id, state pointers by +pointer id, and native slice views by view id and route while the full column +layout stays in `CultMeshNativeSliceViewDescriptor`. Catalog diagnostics support exact id lookup and kind filtering so tools can discover, for example, every operation or native view without local scan conventions. `CultMesh.DescribeSurfaceCatalogIndex(...)` / TS `CultMesh.surfaceCatalogIndex(...)` promotes that grouping into a shared diagnostic shape with `queries`, `projectionRecipes`, `liveFeeds`, -`operations`, `statePointers`, and `nativeSliceViews`, so generated bindings -and tools can ask for the semantic bucket they need without copying catalog -scan logic. +`operations`, `documents`, `collections`, `statePointers`, and +`nativeSliceViews`, so generated bindings and tools can ask for the semantic +bucket they need without copying catalog scan logic. Live feeds compose several query surfaces into one client-facing snapshot without making the UI own refresh loops: diff --git a/tests/GameCult.Mesh.Tests/CultMeshStreamingTests.cs b/tests/GameCult.Mesh.Tests/CultMeshStreamingTests.cs index d3229bdb..a3e080ea 100644 --- a/tests/GameCult.Mesh.Tests/CultMeshStreamingTests.cs +++ b/tests/GameCult.Mesh.Tests/CultMeshStreamingTests.cs @@ -911,6 +911,19 @@ public sealed class CultMeshStreamingTests () => new Subject(), route, sources); + var document = CultMesh.Document( + "daemon:aetheria.frame.latest.v1", + CultMesh.Verse("aetheria.local", "unity-raven").Context, + _context => Task.FromResult(new MeshNoteDocument { Schema = "frame", Text = "current", Revision = 1 }), + _context => new Subject(), + sources, + route); + var collection = new CultMeshCollectionHandle( + "daemon:aetheria.contacts.v1", + () => Task.FromResult>(Array.Empty()), + () => new Subject>(), + sources, + route); var nativeView = new CultMeshNativeSliceViewDescriptor( "aetheria.zone.render", "gamecult.aetheria.render_body.v1", @@ -925,18 +938,22 @@ public sealed class CultMeshStreamingTests CultMesh.DescribeSurface(query), CultMesh.DescribeSurface(feed), CultMesh.DescribeSurface(operation), + CultMesh.DescribeSurface(document), + CultMesh.DescribeSurface(collection), CultMesh.DescribeSurface(pointer), CultMesh.DescribeSurface(nativeView) }); catalog.CatalogId.Should().Be("gamecult.aetheria.rts.surfaces.v1"); - catalog.Surfaces.Should().HaveCount(5); + catalog.Surfaces.Should().HaveCount(7); catalog.Surfaces[0].Kind.Should().Be(CultMeshSurfaceKind.Query); catalog.Surfaces[0].SurfaceId.Should().Be("aetheria.zone.objects.visible"); catalog.Surfaces[0].RouteHint.Kind.Should().Be(CultMeshLocalityKind.SharedMemory); catalog.Surfaces[0].Sources.Should().HaveCount(1); catalog.Find("aetheria.rts.viewport.feed")!.Kind.Should().Be(CultMeshSurfaceKind.LiveFeed); catalog.Find("aetheria.entity.pilot.move")!.Kind.Should().Be(CultMeshSurfaceKind.Operation); + catalog.Find("daemon:aetheria.frame.latest.v1")!.Kind.Should().Be(CultMeshSurfaceKind.Document); + catalog.Find("daemon:aetheria.contacts.v1")!.Kind.Should().Be(CultMeshSurfaceKind.Collection); catalog.Find("aetheria.selection.current")!.Kind.Should().Be(CultMeshSurfaceKind.StatePointer); catalog.Find("aetheria.selection.current")!.RouteHint.Kind.Should().Be(CultMeshLocalityKind.SharedMemory); catalog.Find("aetheria.selection.current")!.Sources.Should().ContainSingle(); @@ -957,6 +974,8 @@ public sealed class CultMeshStreamingTests index.Queries.Should().ContainSingle().Which.SurfaceId.Should().Be("aetheria.zone.objects.visible"); index.LiveFeeds.Should().ContainSingle().Which.SurfaceId.Should().Be("aetheria.rts.viewport.feed"); index.Operations.Should().ContainSingle().Which.SurfaceId.Should().Be("aetheria.entity.pilot.move"); + index.Documents.Should().ContainSingle().Which.SurfaceId.Should().Be("daemon:aetheria.frame.latest.v1"); + index.Collections.Should().ContainSingle().Which.SurfaceId.Should().Be("daemon:aetheria.contacts.v1"); index.StatePointers.Should().ContainSingle().Which.SurfaceId.Should().Be("aetheria.selection.current"); index.NativeSliceViews.Should().ContainSingle().Which.SurfaceId.Should().Be("aetheria.zone.render"); index.ProjectionRecipes.Should().BeEmpty();