Add Kotlin built-in schema catalog

This commit is contained in:
Meta Vens 2026-06-16 16:03:18 +01:00
commit 2355617eca
4 changed files with 231 additions and 1 deletions

View file

@ -339,6 +339,15 @@ Current progress:
without making the transport own catalog truth. Both adapters implement the
shared `CultNetSchemaMessageTransport` shape so the helper logic has one
owner across Kotlin stream and RUDP paths.
- Kotlin now also has a built-in schema catalog factory on the branded
`CultMesh` surface. It advertises the Kotlin-supported CultNet/CultMesh
request and response message descriptors, including schema catalog, shard
catalog, shard log, Verse catalog, peer exchange, and the shared transport
profile contract. Descriptors for contracts already present in the canonical
schema set use those schema ids and content hashes; Kotlin-local descriptor
bodies use schema-version ids until shared schema files exist. The descriptors
are still normal `CultNetSchemaCatalog` state; transports do not own catalog
truth.
- Kotlin authority lease catalogs now also expose watch callbacks, so JVM and
Android clients can react to lease changes without treating peer-card contact
hints as trust.

View file

@ -34,7 +34,7 @@ CultMesh.
| Python | Package runtime, local daemon endpoint, raw interop peer, typed state participant | CultCache/CultNet/CultMesh package surface, schema catalogs, shard catalogs/logs, local TCP CultMesh server, session/prediction/simulation fact helpers, authority leases, streams, RUDP codec/session/socket transport, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence, benchmark evidence against C# cache paths | Universal C# throughput, full C# daemon/server stack, and RUDP as the only public service pipe |
| TypeScript | Node/browser-adjacent projection and interop runtime | CultCache parity tests, CultNet schema-v0 peer, advertised schema/shard catalog wire contracts plus request/sync helpers, transport profiles, TCP-framed transport port and peer helper, shared RUDP socket transport, RUDP reconnect policy/controller, RUDP reconnect-loop helper, local CultMesh node/catalog/authority/stream ergonomics | Full C# game session/server stack |
| Rust | Low-level cache/transport/runtime substrate | CultCache/CultNet interop lane, schema and shard catalog helpers, transport profiles, TCP-framed port, shared RUDP codec/session/socket transport, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence, small CultMesh facade for peer cards, authority leases, RUDP endpoint parsing, and peer-card RUDP client construction | Full CultMesh game-session/server facade, stream catalog, or production game-session server |
| Kotlin | JVM/Android client substrate | Typed MessagePack cache, schema/shard catalogs with shared schema-message transport fetch/sync helpers, authority leases, stream catalog, branded `CultMesh` facade, WebSocket transport profile/connection helper, RUDP client/server sugar, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence | C# SoA store, full C# server daemon, or Unity hot-loop memory layout |
| Kotlin | JVM/Android client substrate | Typed MessagePack cache, built-in schema catalog advertisement, schema/shard catalogs with shared schema-message transport fetch/sync helpers, authority leases, stream catalog, branded `CultMesh` facade, WebSocket transport profile/connection helper, RUDP client/server sugar, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence | C# SoA store, full C# server daemon, or Unity hot-loop memory layout |
## Evidence Gates

View file

@ -136,6 +136,13 @@ val response = catalog.createResponse(
`CultNetSchemaCatalog.applyResponse(...)` imports
`cultnet.schema_catalog_response.v0` descriptors from other runtimes and keeps
their content hashes, wire contracts, schema ids, and optional schema JSON.
`CultMesh.createBuiltInSchemaCatalog(...)` returns the Kotlin-supported
CultNet/CultMesh wire-message descriptors on the same catalog surface, including
schema catalog, shard catalog, shard log, Verse catalog, peer exchange, and the
shared transport profile contract. Descriptors for shared schema files keep the
canonical schema ids and content hashes; Kotlin-local descriptor bodies use
schema-version ids until shared schema files exist. Inline schema JSON is opt-in
and only emitted for descriptor bodies Kotlin owns.
Shard catalogs and shard-log responses use the same schema-v0 lane:

View file

@ -287,6 +287,9 @@ object CultMesh {
fun createSchemaCatalog(): CultNetSchemaCatalog = CultNetSchemaCatalog()
fun createBuiltInSchemaCatalog(includeSchemaJson: Boolean = false): CultNetSchemaCatalog =
cultNetBuiltInSchemaCatalog(includeSchemaJson)
fun createShardCatalog(): CultNetShardCatalog = CultNetShardCatalog()
fun createRudpServer(
@ -970,6 +973,168 @@ fun defineCultNetSchemaDescriptor(
schemaJson = schemaJson,
)
private const val cultNetSchemaBase = "https://github.com/GameCult/cultnet-ts/contracts"
private data class CultNetBuiltInSchemaSpec(
val schemaVersion: String,
val title: String,
val schemaId: String,
val kind: String = "wire_message",
val wireContracts: List<String> = listOf("cultnet.schema.v0"),
val requiredFields: List<String> = listOf("schemaVersion", "messageId"),
val contentHash: String? = null,
)
private val cultNetBuiltInSchemaSpecs = listOf(
CultNetBuiltInSchemaSpec(
schemaVersion = "cultnet.hello.v0",
title = "CultNet Hello Message",
schemaId = "$cultNetSchemaBase/cultnet.hello.schema.json",
requiredFields = listOf("schemaVersion", "runtimeId", "runtimeKind"),
contentHash = "1d2114bf0c92a2dd5e07dd735778ceeb939402c6424550d6d281d9db423f56b3",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultnet.document_delete.v0",
title = "CultNet Document Delete Message",
schemaId = "$cultNetSchemaBase/cultnet.document-delete.schema.json",
requiredFields = listOf("schemaVersion", "messageId", "schemaId", "recordKey"),
contentHash = "037f7cf1b30756904e0bfada6bcff486269378997afbe3c4b6fc5c573fc8a4df",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultnet.document_put_raw.v0",
title = "CultNet Raw Document Put Message",
schemaId = "$cultNetSchemaBase/cultnet.document-put-raw.schema.json",
contentHash = "b61e7e6cce8508653fbeccc4d956ef211c853a174d67c7e1903ce294e15985a2",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultnet.snapshot_request.v0",
title = "CultNet Snapshot Request Message",
schemaId = "$cultNetSchemaBase/cultnet.snapshot-request.schema.json",
contentHash = "9f6546f51a1aab85978554e6908d7a59e96b3329feff7b35022be210495dd721",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultnet.snapshot_response_raw.v0",
title = "CultNet Raw Snapshot Response Message",
schemaId = "$cultNetSchemaBase/cultnet.snapshot-response-raw.schema.json",
contentHash = "0dbca3338a3ae5d4011aed2c973c75b9b47b6b9dfc0874459ac56da01fef4582",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultnet.schema_catalog_request.v0",
title = "CultNet Schema Catalog Request Message",
schemaId = "$cultNetSchemaBase/cultnet.schema-catalog-request.schema.json",
wireContracts = listOf("cultnet.schema.v0", "gamecult.networking.v0"),
contentHash = "bdd49b44428daf24b514c521e53027ec944aecfebb39ca0d10967661c303e096",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultnet.schema_catalog_response.v0",
title = "CultNet Schema Catalog Response Message",
schemaId = "$cultNetSchemaBase/cultnet.schema-catalog-response.schema.json",
wireContracts = listOf("cultnet.schema.v0", "gamecult.networking.v0"),
contentHash = "b158de53d1ca614eacf2e05767122fb4b9e06504c037ad76c649cffdf71dd648",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultnet.shard_catalog_request.v0",
title = "CultNet Shard Catalog Request Message",
schemaId = "cultnet.shard_catalog_request.v0",
contentHash = "0abd131a1db12f6731010333b86e104d550160bd58f539b18413a2b61198fa38",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultnet.shard_catalog_response.v0",
title = "CultNet Shard Catalog Response Message",
schemaId = "cultnet.shard_catalog_response.v0",
contentHash = "93a0e90ac81bc6ab21b68925ad25e381edfac8773232333679d3275141cff37b",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultnet.shard_log_request.v0",
title = "CultNet Shard Log Request Message",
schemaId = "cultnet.shard_log_request.v0",
requiredFields = listOf("schemaVersion", "messageId", "shardId"),
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultnet.shard_log_response.v0",
title = "CultNet Shard Log Response Message",
schemaId = "cultnet.shard_log_response.v0",
requiredFields = listOf("schemaVersion", "messageId", "shardId", "shardEpoch", "entries"),
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultmesh.verse_catalog_request.v0",
title = "CultMesh Verse Catalog Request Message",
schemaId = "cultmesh.verse_catalog_request.v0",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultmesh.verse_catalog_response.v0",
title = "CultMesh Verse Catalog Response Message",
schemaId = "cultmesh.verse_catalog_response.v0",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultmesh.peer_exchange_request.v0",
title = "CultMesh Peer Exchange Request Message",
schemaId = "cultmesh.peer_exchange_request.v0",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultmesh.peer_exchange_response.v0",
title = "CultMesh Peer Exchange Response Message",
schemaId = "cultmesh.peer_exchange_response.v0",
),
CultNetBuiltInSchemaSpec(
schemaVersion = "cultnet.transport_profile.v0",
title = "CultNet Transport Profile",
schemaId = "$cultNetSchemaBase/cultnet.transport-profile.schema.json",
kind = "shared_contract",
requiredFields = listOf("schemaVersion", "runtimeId", "transports"),
contentHash = "84473264f543ca3443267999e43d72b7993b61b7b2ac53c642c9cbe8b6de0217",
),
)
fun cultNetBuiltInSchemaCatalog(includeSchemaJson: Boolean = false): CultNetSchemaCatalog {
val catalog = CultNetSchemaCatalog()
cultNetBuiltInSchemaSpecs.forEach { spec ->
val schemaJson = cultNetBuiltInSchemaJson(spec, spec.schemaId)
val inlineSchemaJson = if (spec.contentHash == null && includeSchemaJson) schemaJson else null
catalog.upsert(
defineCultNetSchemaDescriptor(
schemaId = spec.schemaId,
kind = spec.kind,
schemaVersion = spec.schemaVersion,
title = spec.title,
wireContracts = spec.wireContracts,
contentHash = spec.contentHash ?: sha256Hex(schemaJson),
schemaJson = inlineSchemaJson,
),
)
}
return catalog
}
private fun cultNetBuiltInSchemaJson(spec: CultNetBuiltInSchemaSpec, schemaId: String): String =
"{" +
"\"\$schema\":\"https://json-schema.org/draft/2020-12/schema\"," +
"\"\$id\":\"${jsonEscape(schemaId)}\"," +
"\"title\":\"${jsonEscape(spec.title)}\"," +
"\"type\":\"object\"," +
"\"required\":${jsonStringArray(spec.requiredFields)}," +
"\"additionalProperties\":true," +
"\"properties\":{\"schemaVersion\":{\"const\":\"${jsonEscape(spec.schemaVersion)}\"}}" +
"}"
private fun jsonStringArray(values: List<String>): String =
values.joinToString(prefix = "[", postfix = "]") { "\"${jsonEscape(it)}\"" }
private fun jsonEscape(value: String): String = buildString {
value.forEach { char ->
when (char) {
'\\' -> append("\\\\")
'"' -> append("\\\"")
'\b' -> append("\\b")
'\u000C' -> append("\\f")
'\n' -> append("\\n")
'\r' -> append("\\r")
'\t' -> append("\\t")
else -> append(char)
}
}
}
data class CultMeshVerseCompatibility(
val transportVersion: String,
val rulesHash: String,
@ -2613,6 +2778,7 @@ fun main(args: Array<String>) {
cultNetReconnectControllerSchedulesAttemptsAndReset()
cultNetRudpReconnectLoopConsumesSharedController()
cultNetWebSocketTransportCarriesSchemaFramesWithStats()
cultNetBuiltInSchemaCatalogAdvertisesWireContracts()
cultNetSchemaCatalogsRoundTripDescriptors()
cultMeshCatalogsRoundTripDiscoveryMessages()
cultMeshAuthorityLeasesGatePeerTrust()
@ -2991,6 +3157,54 @@ private fun cultNetWebSocketTransportCarriesSchemaFramesWithStats() {
}
}
private fun cultNetBuiltInSchemaCatalogAdvertisesWireContracts() {
val catalog = CultMesh.createBuiltInSchemaCatalog()
val request = cultNetSchemaCatalogRequest(
messageId = "kotlin-builtins",
includeSchemaJson = false,
kinds = listOf("wire_message"),
)
val response = catalog.createResponse(request)
val parsed = parseCultNetMessage(response.toBytes())
val schemas = mapList(parsed.body["schemas"])
val schemaCatalogRequest = schemas.single { it["schemaVersion"] == "cultnet.schema_catalog_request.v0" }
check(schemaCatalogRequest["schemaId"] == "$cultNetSchemaBase/cultnet.schema-catalog-request.schema.json")
check(schemaCatalogRequest["wireContracts"] == listOf("cultnet.schema.v0", "gamecult.networking.v0"))
check(!schemaCatalogRequest.containsKey("schemaJson"))
val shardCatalogRequest = schemas.single { it["schemaVersion"] == "cultnet.shard_catalog_request.v0" }
check(shardCatalogRequest["schemaId"] == "cultnet.shard_catalog_request.v0")
check(shardCatalogRequest["wireContracts"] == listOf("cultnet.schema.v0"))
check(shardCatalogRequest["contentHash"] == "0abd131a1db12f6731010333b86e104d550160bd58f539b18413a2b61198fa38")
val shardCatalogResponse = schemas.single { it["schemaVersion"] == "cultnet.shard_catalog_response.v0" }
check(shardCatalogResponse["schemaId"] == "cultnet.shard_catalog_response.v0")
check(shardCatalogResponse["wireContracts"] == listOf("cultnet.schema.v0"))
val inlineCatalog = cultNetBuiltInSchemaCatalog(includeSchemaJson = true)
val transportResponse = inlineCatalog.createResponse(
cultNetSchemaCatalogRequest(
messageId = "kotlin-builtins-transport",
includeSchemaJson = true,
schemaIds = listOf("$cultNetSchemaBase/cultnet.transport-profile.schema.json"),
),
)
val transportProfile = mapList(transportResponse.body["schemas"]).single()
check(transportProfile["kind"] == "shared_contract")
check(transportProfile["contentHash"] == "84473264f543ca3443267999e43d72b7993b61b7b2ac53c642c9cbe8b6de0217")
check(!transportProfile.containsKey("schemaJson"))
val inlineResponse = inlineCatalog.createResponse(
cultNetSchemaCatalogRequest(
messageId = "kotlin-builtins-inline",
includeSchemaJson = true,
schemaIds = listOf("cultmesh.peer_exchange_request.v0"),
),
)
val inlineSchemas = mapList(inlineResponse.body["schemas"])
val peerExchangeRequest = inlineSchemas.single()
check(peerExchangeRequest["kind"] == "wire_message")
check((peerExchangeRequest["schemaJson"] as String).contains("cultmesh.peer_exchange_request.v0"))
}
private fun cultNetSchemaCatalogsRoundTripDescriptors() {
val catalog = CultNetSchemaCatalog()
var watched: CultNetSchemaDescriptor? = null