Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 159ad486e5 | |||
|
|
b6e06cf89a | ||
|
|
366774dc4c | ||
|
|
9eb099be4d | ||
|
|
3136ee8b80 | ||
| fd7a48484d | |||
| 4a6c04a073 | |||
|
|
ee8eec41f3 | ||
|
|
ebafda432f | ||
|
|
e95f1ab5ba | ||
|
|
0ba536eec1 | ||
|
|
e119e76301 | ||
|
|
afe05b0c7e |
27 changed files with 1107 additions and 2472 deletions
35
.github/workflows/portable-contracts.yml
vendored
35
.github/workflows/portable-contracts.yml
vendored
|
|
@ -8,6 +8,11 @@ on:
|
||||||
pull_request:
|
pull_request:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
# A newer push or PR update replaces the older run on the same ref; workflow_dispatch runs are never cancelled.
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: ${{ github.event_name != 'workflow_dispatch' }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
contracts-and-browser:
|
contracts-and-browser:
|
||||||
name: ${{ matrix.os }} ${{ matrix.package }}
|
name: ${{ matrix.os }} ${{ matrix.package }}
|
||||||
|
|
@ -16,7 +21,10 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [windows-latest, ubuntu-latest]
|
# No Windows runner exists: the windows-latest leg runs on workflow_dispatch only (GitHub or a
|
||||||
|
# Windows runner), the ubuntu-latest leg gates push and PR. Windows push/PR triggers return in the PR
|
||||||
|
# that registers a Windows runner.
|
||||||
|
os: ${{ fromJSON(github.event_name == 'workflow_dispatch' && '["windows-latest", "ubuntu-latest"]' || '["ubuntu-latest"]') }}
|
||||||
package: [eve-contracts, eve-browser-lowering]
|
package: [eve-contracts, eve-browser-lowering]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
@ -30,6 +38,14 @@ jobs:
|
||||||
cache: npm
|
cache: npm
|
||||||
cache-dependency-path: packages/${{ matrix.package }}/package-lock.json
|
cache-dependency-path: packages/${{ matrix.package }}/package-lock.json
|
||||||
|
|
||||||
|
# eve-browser-lowering links eve-contracts as file:../eve-contracts; npm installs none of the
|
||||||
|
# linked package's dependencies, and tsc resolves its declarations from the real path, so
|
||||||
|
# ajv must be installed in eve-contracts itself.
|
||||||
|
- name: Install eve-contracts dependencies
|
||||||
|
if: matrix.package != 'eve-contracts'
|
||||||
|
working-directory: packages/eve-contracts
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
- name: Install package dependencies
|
- name: Install package dependencies
|
||||||
working-directory: packages/${{ matrix.package }}
|
working-directory: packages/${{ matrix.package }}
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
@ -38,6 +54,23 @@ jobs:
|
||||||
working-directory: packages/${{ matrix.package }}
|
working-directory: packages/${{ matrix.package }}
|
||||||
run: npm test
|
run: npm test
|
||||||
|
|
||||||
|
# The forge runner images carry no pwsh; GitHub's Windows and hosted images do.
|
||||||
|
- name: Install PowerShell
|
||||||
|
if: runner.os == 'Linux'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if command -v pwsh >/dev/null; then pwsh -Version; exit 0; fi
|
||||||
|
SUDO=""; [ "$(id -u)" -eq 0 ] || SUDO="sudo"
|
||||||
|
PWSH_VERSION=7.4.6
|
||||||
|
curl -fsSL "https://github.com/PowerShell/PowerShell/releases/download/v${PWSH_VERSION}/powershell-${PWSH_VERSION}-linux-x64.tar.gz" -o "${RUNNER_TEMP:-/tmp}/powershell.tar.gz"
|
||||||
|
$SUDO mkdir -p /opt/microsoft/powershell/7
|
||||||
|
$SUDO tar -xzf "${RUNNER_TEMP:-/tmp}/powershell.tar.gz" -C /opt/microsoft/powershell/7
|
||||||
|
$SUDO chmod +x /opt/microsoft/powershell/7/pwsh
|
||||||
|
$SUDO ln -sf /opt/microsoft/powershell/7/pwsh /usr/local/bin/pwsh
|
||||||
|
echo "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1" >> "$GITHUB_ENV"
|
||||||
|
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 pwsh -Version
|
||||||
|
|
||||||
- name: Reject stale generated output
|
- name: Reject stale generated output
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -8,11 +8,6 @@ packages/eve-browser-lowering/node_modules/
|
||||||
!packages/eve-contracts/**
|
!packages/eve-contracts/**
|
||||||
packages/eve-contracts/node_modules/
|
packages/eve-contracts/node_modules/
|
||||||
packages/eve-contracts/*.tgz
|
packages/eve-contracts/*.tgz
|
||||||
!packages/thing-contract/
|
|
||||||
!packages/thing-contract/**
|
|
||||||
packages/thing-contract/node_modules/
|
|
||||||
packages/thing-contract/dist/
|
|
||||||
packages/thing-contract/dist-test/
|
|
||||||
!packages/org.gamecult.eve.surface/
|
!packages/org.gamecult.eve.surface/
|
||||||
!packages/org.gamecult.eve.surface/**
|
!packages/org.gamecult.eve.surface/**
|
||||||
packages/org.gamecult.eve.surface/bin~/
|
packages/org.gamecult.eve.surface/bin~/
|
||||||
|
|
|
||||||
56
README.md
56
README.md
|
|
@ -1,9 +1,41 @@
|
||||||
# Thing
|
# Thing
|
||||||
|
|
||||||
This repository is Thing. Its present tree is Thing 1, kept running for live
|
This repository is Thing (the Eve display, control and sensor edge for GameCult
|
||||||
consumers until each ports; Thing 2.0 is built here (`docs/thing2-target.md`).
|
apps). Its present tree is Thing 1, kept running for live consumers until each
|
||||||
The Thing 1 renderer repos are archived under their Eve names: EveUnity,
|
ports; Thing 2.0 is built here (`docs/thing2-target.md`). The Thing 1 renderer
|
||||||
EveFlutter, EveElectron, EveTui, EvePlugins and EveConformance.
|
repos are archived under their Eve names: EveUnity, EveFlutter, EveElectron,
|
||||||
|
EveTui, EvePlugins and EveConformance.
|
||||||
|
|
||||||
|
## Start Here
|
||||||
|
|
||||||
|
Value: services publish a surface once, as a typed retained document
|
||||||
|
(`gamecult.eve.surface.v1`), and every runtime lowers it locally. Providers keep
|
||||||
|
authority over state and commands; Eve owns projection, input capture and
|
||||||
|
timestamped sensor publication.
|
||||||
|
|
||||||
|
Problem: without a shared surface contract, each service hand-builds its own
|
||||||
|
dashboard and each renderer re-implements layout, binding and commands.
|
||||||
|
|
||||||
|
Live (Thing 1):
|
||||||
|
|
||||||
|
- `packages/org.gamecult.eve.surface`: renderer-neutral C# surface contract and
|
||||||
|
composition builders; tests in `tests/GameCult.Eve.Surface.Serialization.Tests`.
|
||||||
|
- `packages/eve-contracts`: TypeScript types and validators generated from
|
||||||
|
`schemas/` (`npm run generate`, `npm test`).
|
||||||
|
- `packages/eve-browser-lowering`: browser DOM/CSS lowering of surface documents
|
||||||
|
(`npm test`).
|
||||||
|
- `web/`: browser reference oracle (`web/index.html`, `web/eve-dsl.js`; tests
|
||||||
|
with `node --test web/eve-dsl.test.mjs`).
|
||||||
|
- `docs/surface-contract-v1.md`: the contract. `docs/repo-strategy.md`: repo
|
||||||
|
ownership. `docs/parity-testing-harness.md` with
|
||||||
|
`scripts/run-parity-harness.ps1`: parity runs.
|
||||||
|
- `android/` and `Sources/` (iOS Theos app, `make package`): native proof
|
||||||
|
clients; build steps under Build Shape below.
|
||||||
|
|
||||||
|
Planned (Thing 2.0, in progress): `crates/thing-contract` is the first Rust
|
||||||
|
piece. The layout solver, text, accessibility tree, closed render-command list
|
||||||
|
and thin backends described in `docs/thing2-target.md` and `docs/thing2-map.md`
|
||||||
|
are not built yet; `docs/thing-campaign.md` holds the rename plan.
|
||||||
|
|
||||||
CultMesh-based surface web, portable control layer, and timestamped sensor
|
CultMesh-based surface web, portable control layer, and timestamped sensor
|
||||||
edge.
|
edge.
|
||||||
|
|
@ -214,11 +246,8 @@ render:
|
||||||
|
|
||||||
## VoidBot CEF Stream
|
## VoidBot CEF Stream
|
||||||
|
|
||||||
Start the Starfire relay from `E:\Projects\VoidBot`:
|
The CEF relay that produced these frames is not in VoidBot's default branch, so
|
||||||
|
no relay command is documented here until one exists.
|
||||||
```powershell
|
|
||||||
npm run swarm:eve-cef-relay -- --width 1620 --height 2160 --scale 2 --port 8792
|
|
||||||
```
|
|
||||||
|
|
||||||
EveCanvas displays binary JPEG frames and returns touch events only when a
|
EveCanvas displays binary JPEG frames and returns touch events only when a
|
||||||
stream lowering is configured through `EVE_STREAM_URLS`. The native app no
|
stream lowering is configured through `EVE_STREAM_URLS`. The native app no
|
||||||
|
|
@ -226,12 +255,11 @@ longer guesses a Starfire relay address.
|
||||||
|
|
||||||
## Mimir Sensor Uplink
|
## Mimir Sensor Uplink
|
||||||
|
|
||||||
Start Mimir with `config/mimir-runtime.raven-eve.example.json` or run the
|
Run the receiver processes from a Mimir checkout (a sibling `..\Mimir` here):
|
||||||
receiver processes directly:
|
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
dotnet run --project E:\Projects\Mimir\src\Mimir.EveSensorReceiver\Mimir.EveSensorReceiver.csproj -- --port 8793 --path /eve/camera --source-id eve-camera --type video-frame
|
dotnet run --project ..\Mimir\src\Mimir.EveSensorReceiver\Mimir.EveSensorReceiver.csproj -- --port 8793 --path /eve/camera --source-id eve-camera --type video-frame
|
||||||
dotnet run --project E:\Projects\Mimir\src\Mimir.EveSensorReceiver\Mimir.EveSensorReceiver.csproj -- --port 8794 --path /eve/mic --source-id eve-mic --type audio-block
|
dotnet run --project ..\Mimir\src\Mimir.EveSensorReceiver\Mimir.EveSensorReceiver.csproj -- --port 8794 --path /eve/mic --source-id eve-mic --type audio-block
|
||||||
```
|
```
|
||||||
|
|
||||||
EveCanvas sends binary `mimir.eve_media_observation.v1` camera and microphone
|
EveCanvas sends binary `mimir.eve_media_observation.v1` camera and microphone
|
||||||
|
|
@ -245,7 +273,7 @@ guess receiver URLs.
|
||||||
Start the dashboard authority on Starfire:
|
Start the dashboard authority on Starfire:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
dotnet run --project E:\Projects\Mimir\src\Mimir.EveDashboard\Mimir.EveDashboard.csproj -- --port 8795
|
dotnet run --project ..\Mimir\src\Mimir.EveDashboard\Mimir.EveDashboard.csproj -- --port 8795
|
||||||
```
|
```
|
||||||
|
|
||||||
EveCanvas connects to the Mimir dashboard WebSocket lowering for native retained
|
EveCanvas connects to the Mimir dashboard WebSocket lowering for native retained
|
||||||
|
|
|
||||||
201
docs/research/swarm-dashboard.md
Normal file
201
docs/research/swarm-dashboard.md
Normal file
|
|
@ -0,0 +1,201 @@
|
||||||
|
# Swarm dashboard: contract state, sources, first cut
|
||||||
|
|
||||||
|
Serves Eureka's ruling `swarm-dashboard-first-thing2-surface` (not readable from
|
||||||
|
the libby mind; cited by the id in the claiming follow-up
|
||||||
|
`libby-body:follow_up:chat-s354-359`). Read-only pass by the `libby` Self run
|
||||||
|
`libby:run:mind-20261031T061423908Z`, 2026-10-31. Nothing was built or deployed.
|
||||||
|
Claims below were probed on 2026-10-31 unless marked **unverified**.
|
||||||
|
|
||||||
|
The question the dashboard answers for a stranger: **is anyone working, and on what.**
|
||||||
|
|
||||||
|
## 1. Where Thing 2's surface contract stands
|
||||||
|
|
||||||
|
Probed against the forge `GameCult/Thing` (main `e119e76`, 2026-10-22) and its
|
||||||
|
`hands/thing2-*` branches. The source of truth for cut status is the `thing2`
|
||||||
|
campaign in the Eureka mind, which this pass cannot read; the prose map
|
||||||
|
(`docs/thing2-map.md`, last edited 2026-10-12) is the evidence used.
|
||||||
|
|
||||||
|
| Piece | State |
|
||||||
|
| --- | --- |
|
||||||
|
| Contract, Rust (`crates/thing-contract`) | On main. 13-arm closed `Node` union, `SurfaceDocument`, `CompositionDocument`, `CommandDecl/Invocation/Result`, `AssetCatalog`; byte goldens under `tests/goldens/`. |
|
||||||
|
| Contract, C# and TypeScript | Not on main. Branches `hands/thing2-contract-cs` (`3dadfc6`, 2026-10-14) and `hands/thing2-contract-ts` (`aeede04`, 2026-10-12). The map lists the cross-runtime store check and publication as waiting. |
|
||||||
|
| Core (resolution, `thing.std` compositions, binding via the CultMesh port, Taffy layout, command dispatch) | Not built. No crate exists. Decoding Verse surfaces waits on `cultlib-gaps:follow_up:decode-stack-safety`. |
|
||||||
|
| TUI backend | Not built. Planned first backend. |
|
||||||
|
| Web backend and shell | Not built. |
|
||||||
|
| Discovery/advertisement | Not a Thing kind (`thing2:ruling:advertisement-owner`); read through a core port; today's `gamecult.eve.provider_advertisement.v1` is unchanged. |
|
||||||
|
|
||||||
|
`README.md` says the same: the layout solver, text, accessibility tree, render
|
||||||
|
commands and backends "are not built yet". **Nothing can render a Thing 2
|
||||||
|
surface today.** The only live renderers are Thing 1's (browser oracle, Ghostlight's vendored lowering,
|
||||||
|
the Nightwing browser reference), and Eve dashboards are quarantined (`gamecult.md`: no new Eve surfaces).
|
||||||
|
|
||||||
|
### What a provider must publish to render
|
||||||
|
|
||||||
|
From `docs/thing2-map.md` "The consumer contract" and `crates/thing-contract/src`:
|
||||||
|
|
||||||
|
1. A `SurfaceDocument` (`gamecult.thing.surface.v1`, key `thing:surface:<providerId>.<label>`,
|
||||||
|
`version` bumped only on structure change). Closed nodes: `Box, Text, Image, Button, Toggle,
|
||||||
|
Slider, TextInput, Select, Repeat, Overlay, Plot, Embed, Use`. A swarm board is `Box` + `Text` +
|
||||||
|
`Repeat` (one row per instance) + `Use` of `thing.std` compositions (`card`, `metric`, `key-value`).
|
||||||
|
2. The **bound state records** the document points at, under the provider's own schema and key. A
|
||||||
|
`Bind` is `{provider?, schema, key, member path, format?}` plus `Item` inside a `Repeat`. A
|
||||||
|
collection binds to `{provider, schema, key_prefix}` or a list member of one record. No
|
||||||
|
expressions, no derived values: **the state's owner publishes derived values** (map rationale,
|
||||||
|
P5). So the dashboard's "working / idle" must be a published field, not computed in the surface.
|
||||||
|
3. Discovery: the provider is found through the existing advertisement, not a Thing record.
|
||||||
|
4. Commands only if the surface acts. A read-only board declares none.
|
||||||
|
|
||||||
|
A provider needs no layout or renderer code. It needs the contract package in its language
|
||||||
|
(Rust is the only one on main) and typed CultMesh state.
|
||||||
|
|
||||||
|
## 2. Sources (all typed state)
|
||||||
|
|
||||||
|
### 2a. Run documents, eight minds
|
||||||
|
|
||||||
|
Each mind is its own Huginn daemon (`HEARTBEAT_PERSONAS` in `/etc/gamecult/heartbeat/heartbeat.env`):
|
||||||
|
eureka 17872, libby 17873, heimdall 17874, kiko 17875, aqua 17876, weksa 17877, nibu 17878,
|
||||||
|
void 17879, all `rudp://10.77.0.1:<port>`. Probed: from this Self run,
|
||||||
|
`EUREKA_INSTANCE=<name> HUGINN_ENDPOINT=<endpoint> huginn query '{"schemas":["epiphany.pipeline.run.v2"],"limit":200}'`
|
||||||
|
answers on all eight, read-only, with caller `client unknown` (no per-client read identity yet).
|
||||||
|
Counts that day: eureka 68, libby 78, heimdall 94, kiko 70, aqua 81, weksa 74, nibu 71, void 87.
|
||||||
|
|
||||||
|
`epiphany.pipeline.run.v2` (`huginn schema run`): `instance, label, operated_by (Operator|Mind),
|
||||||
|
turn (PersonaTurn|SelfRun), host, started_on (a date), budget_usd, claims [PipelineRef], campaigns`.
|
||||||
|
|
||||||
|
What the dashboard can and cannot take from it:
|
||||||
|
|
||||||
|
- **Open/closed is not on the Run.** It is derived: a Run is closed when a `Resolution` with
|
||||||
|
`subject` = the run is in force (`huginn query` prints `InForce` or `Resolved:<outcome>`).
|
||||||
|
Resolution key `<instance>:resolution:run.<label>.n<seq>`. `huginn history <runId>` reads it.
|
||||||
|
- **Start time is a date.** The label `mind-YYYYMMDDTHHMMSSmmmZ` encodes the start to the
|
||||||
|
millisecond, but that is a convention in a string. The admission header (`huginn view`) carries
|
||||||
|
`admitted <timestamp>`, and the Resolution's header gives the end. Both are header facts, not
|
||||||
|
document fields. A dashboard needing start and end times wants them as typed fields.
|
||||||
|
- **"Outcome" is nearly empty.** Of 78 libby runs, 77 resolved `Recorded` and one is in force.
|
||||||
|
The meaning lives in free text: `reason "answered 1"` (55), `"answered 2"` (5), `"the connector
|
||||||
|
refused the credential lease: UnknownCaller"` (3), `"unit not active"`, `"failed after 0
|
||||||
|
answered..."`, plus rationales `The Persona unit's start ended.` (61) and `The Self run's carrier
|
||||||
|
closed the run its claude left open.` (11). Two Self-run resolutions carry the run's whole result
|
||||||
|
message inside `reason` (long prose, operator-facing detail). A public board
|
||||||
|
must **never project `reason` or `rationale`**.
|
||||||
|
- **"On what" is only on Self runs.** `claims` holds the follow-up or other document the run took;
|
||||||
|
a `PersonaTurn` has no claims (its work is the chat room). The claimed `follow_up.item` is the
|
||||||
|
operator's chat-relayed brief, free text, sometimes private. The typed handle (claim id, campaign
|
||||||
|
slug, the claimed document's `repo`) is safe; the `item` is not.
|
||||||
|
- **An open Run can be a dead Run.** Eleven libby Self runs were closed with "carrier closed the
|
||||||
|
run its claude left open", so for some interval an in-force Run belonged to nobody. "Open" is
|
||||||
|
"admitted and not yet resolved", not "a process is working".
|
||||||
|
- **Dollar fields:** `budget_usd` is on every Run. Do not bind it.
|
||||||
|
|
||||||
|
Snapshot at 06:16 UTC: two Self runs in force, `libby:run:mind-20261031T061423908Z` (this one) and
|
||||||
|
`void:run:mind-20261031T061543899Z` (claims `void-body:follow_up:chat-s335-340`); no Persona run
|
||||||
|
in force in any of the eight.
|
||||||
|
|
||||||
|
### 2b. Heartbeat state and poll trace
|
||||||
|
|
||||||
|
Source: `Huginn/crates/mind-body/src/heartbeat.rs`. `mind-heartbeat` is one Idunn-managed unit, sole
|
||||||
|
writer of `heartbeat.cc` (a single-file CultCache store under the unit's state directory). Two kinds:
|
||||||
|
|
||||||
|
- `eureka.heartbeat.initiative.v1`, key = instance slug: `initiative_usd, as_of, urgency, urgency_at,
|
||||||
|
last_burned_run, filled_events, classified_seq, launched_run, launch_spend_usd,
|
||||||
|
launch_spend_known, completions_through, launch_window`.
|
||||||
|
- `eureka.heartbeat.poll_trace.v1`, key = zero-padded unix ms, written only for polls that changed
|
||||||
|
something: `at, instances [InstanceTrace], launches [run label], burns [BurnTrace], classifier`.
|
||||||
|
`InstanceTrace`: `instance, initiative_usd, rate_usd_per_h, urgency, urgency_age_s, busy,
|
||||||
|
released, crossing_at, waited_s, idle_s, filled_by, fill_reason, note`.
|
||||||
|
|
||||||
|
Usable without dollars: `busy` (an in-force Persona run, from the mind), `released`, `crossing_at`,
|
||||||
|
`waited_s`, `idle_s`, `filled_by`/`fill_reason` (`tag` or `name`), `note`, `launches`, `urgency`,
|
||||||
|
`classifier`. These say **why nobody is working** (waiting for initiative, held by the envelope).
|
||||||
|
Dollar fields to leave alone: `initiative_usd`, `rate_usd_per_h`, `launch_spend_usd`,
|
||||||
|
`spend_usd`, and in the Initiative record the same names. The metering teardown removes them, and
|
||||||
|
`initiative_usd` is the unit initiative itself is denominated in, so the heartbeat's own model will
|
||||||
|
change under whatever binds this.
|
||||||
|
|
||||||
|
Gaps:
|
||||||
|
|
||||||
|
- **Not verified live.** `heartbeat.cc` is not readable from this Self run's account, and no
|
||||||
|
`/var/lib/gamecult` path for it was visible. The shape above is from source and
|
||||||
|
`eureka-body-map.md:534-540`, not from a read of the file.
|
||||||
|
- **No wire.** The heartbeat writes a file; it does not serve one. A reader opening a single-file
|
||||||
|
store while the heartbeat rewrites it has no stated safety (`FileStore::open` pulls the whole file
|
||||||
|
per call). A dashboard source must be published state, not a second process reading the file.
|
||||||
|
`mind-heartbeat timeline` prints the latest poll for a human.
|
||||||
|
- The trace is written only when a poll "changed something", so its newest line can be old while
|
||||||
|
the system is healthy. Staleness must come from the heartbeat's own published liveness, which
|
||||||
|
does not exist as a field.
|
||||||
|
|
||||||
|
### 2c. Connector usage readout
|
||||||
|
|
||||||
|
Source: `ModelConnector/schemas/usage_readout.json`, `crates/model-connector/src/readout.rs`.
|
||||||
|
`gamecult.model.usage_readout.v1`: `{schema_id, at_unix_ms, plan_quota: [{window, status,
|
||||||
|
utilization_permille (nullable), resets_at_unix_ms, observed_at_unix_ms}]}`. Whole-plan windows, no
|
||||||
|
per-caller field, **no dollars**: the safe source for "how much capacity is left".
|
||||||
|
|
||||||
|
Gaps: it is a connector operation (`usage_readout` on `gamecult.model.connector`), reached at the
|
||||||
|
heartbeat's `MIND_CONNECTOR_ENDPOINT` (`tcp://127.0.0.1:4110`), a loopback port with a per-caller
|
||||||
|
credential. Three libby Self runs were already refused with `UnknownCaller` on a lease, so a new
|
||||||
|
caller needs registration before it can ask. It is a request/answer, not a document in a store. A
|
||||||
|
dashboard needs a publisher that polls it and republishes it as a CultMesh record. `plan_quota`
|
||||||
|
also rides on every lease grant. **Unverified:** the live values, since asking requires a caller
|
||||||
|
credential this pass was not given.
|
||||||
|
|
||||||
|
### 2d. Not a source: the presence provider
|
||||||
|
|
||||||
|
CultLib's 10-29 presence provider attests Idunn-managed **service** liveness, not attention or work
|
||||||
|
(`libby-body:follow_up:presence-attention-not-carried`). It can answer "is the heartbeat unit up".
|
||||||
|
It cannot answer "is anyone working".
|
||||||
|
|
||||||
|
## 3. Smallest first cut
|
||||||
|
|
||||||
|
**Cut 1: one published read model, `swarm.work.v1`, from the Runs of the eight minds. No heartbeat,
|
||||||
|
no usage, no renderer.**
|
||||||
|
|
||||||
|
One record per instance (eight, key `<instance>`), derived and published by a single projector
|
||||||
|
(owner: the swarm-dashboard provider), holding only closed-set or id fields:
|
||||||
|
|
||||||
|
- `state`: `Working` (a Self run in force), `Turn` (a Persona run in force), or `Idle`.
|
||||||
|
- `run`: label of the newest in-force run, its `turn`, its start (from the admission header), else the
|
||||||
|
newest closed run's end.
|
||||||
|
- `on`: the claim id(s) and campaign slug(s), no free text.
|
||||||
|
- `observed_at` and the per-mind `as_of`, so a dead projector reads as stale.
|
||||||
|
|
||||||
|
This answers the stranger's question with typed state only. It deliberately omits `reason`,
|
||||||
|
`rationale`, `item`, `budget_usd`, and every `*_usd` field.
|
||||||
|
|
||||||
|
The Thing 2 surface for it is a `SurfaceDocument` that is a `Repeat` over those eight records, one
|
||||||
|
`thing.std.card` each, bound to `state` / `on` / the time fields. It can be authored and golden-tested
|
||||||
|
with the Rust contract on main. It cannot be seen until core (2a) and a backend exist. That is the
|
||||||
|
actual gating item, and it is not this cut's to work around with a Thing 1 or Eve surface.
|
||||||
|
|
||||||
|
Cut 2: add heartbeat liveness and the why-idle fields (`busy`, `released`, `waited_s`, `idle_s`,
|
||||||
|
`note`, `launches`), once the heartbeat publishes them as typed CultMesh state (it currently writes a
|
||||||
|
file only, and the dollar-denominated initiative model is under teardown).
|
||||||
|
Cut 3: add the `plan_quota` windows once a publisher polls the connector under a registered caller.
|
||||||
|
|
||||||
|
### Forks for the operator (recommendations given)
|
||||||
|
|
||||||
|
1. **Who is the stranger?** If public, the board shows ids and campaign slugs only (cut 1 as
|
||||||
|
written); "on what" in words needs a typed `public_label` that the claiming agent sets, not
|
||||||
|
`follow_up.item`. Recommend ids only until that field exists.
|
||||||
|
2. **Where does the projector live?** Recommend a small reader that queries the eight Huginns (all
|
||||||
|
answer today) and publishes `swarm.work.v1`, rather than adding publication to `mind-heartbeat`,
|
||||||
|
which is Idunn-managed with a single-file store and a dollar model in flux. Confidence moderate:
|
||||||
|
the cost is a new daemon, which needs the independent-lifecycle account `gamecult.md` requires.
|
||||||
|
3. **Is "open" enough?** Recommend marking `Working` only when a Run is in force **and** its
|
||||||
|
carrier is attested (the Run was admitted by a launch that is still live); the data for that
|
||||||
|
attestation is not in the Run. Until it is, say in the surface that `Working` means "admitted,
|
||||||
|
unresolved".
|
||||||
|
4. **Typed times.** Recommend asking Huginn for `started_at` and `ended_at` as Run/Resolution
|
||||||
|
document fields, so no consumer parses labels or header facts.
|
||||||
|
5. **Sequencing.** A stranger sees nothing until core and a backend land. If the swarm board should
|
||||||
|
come earlier than the TUI backend, say so; the TUI is the planned first backend and gives agents
|
||||||
|
a reader, but a stranger needs the web backend (map cut 4).
|
||||||
|
|
||||||
|
### Substrate gaps this pass felt
|
||||||
|
|
||||||
|
- The `swarm-dashboard-first-thing2-surface` ruling and the `thing2` campaign are in Eureka's mind,
|
||||||
|
not readable from libby's: cut status here comes from a 2026-10-12 prose map.
|
||||||
|
- `heartbeat.cc` unreadable from a Self run, and a file, not a served document.
|
||||||
|
- No typed `ended_at` / `started_at` on Run; outcome is free text in `reason`.
|
||||||
|
- No per-client read identity on the eight Huginns (`client unknown`).
|
||||||
825
docs/thing2-build-spec.md
Normal file
825
docs/thing2-build-spec.md
Normal file
|
|
@ -0,0 +1,825 @@
|
||||||
|
# Thing 2.0 build spec
|
||||||
|
|
||||||
|
Status: build spec, refreshed 2026-11-10 against the thing2 rulings in force, on
|
||||||
|
top of `docs/thing2-target.md` (why, invariants) and
|
||||||
|
`docs/thing2-map.md` (body facts P1-P22, model page, consumer contract, authority
|
||||||
|
map, cut order). It does not restate them; it adds what the map leaves at
|
||||||
|
deliverable level: **the pieces, each piece's contract, the build order, and the
|
||||||
|
test that defends each piece**, with prior art for every design choice.
|
||||||
|
|
||||||
|
Nothing here overrides a ruling. Where this spec makes a choice the rulings do not
|
||||||
|
force, it is labelled **D<n>** (decision, with confidence) and the ones it could
|
||||||
|
not settle are in "Open" at the end, each with a recommendation.
|
||||||
|
|
||||||
|
## How to read the prior-art tags
|
||||||
|
|
||||||
|
Each piece ends with **Prior art**. Tags: **[read]** = a source read in an earlier
|
||||||
|
Eyes or Imagination pass, with its evidence pointer in `docs/research/*` (cited as
|
||||||
|
R-F = `thing2-foundation-prior-art.md`, R-T = `thing2-text-input-a11y-prior-art.md`,
|
||||||
|
R-K = `thing2-contract-forks-prior-art.md`, R-C = `thing2-consumer-census.md`);
|
||||||
|
**[background]** = prior knowledge, not re-fetched for this spec, and the first
|
||||||
|
thing to verify when its piece is mapped into a `cut_spec`. Confidence is stated
|
||||||
|
per decision. The standard is "prior-art sources cited"; O12 asks whether it
|
||||||
|
also fixes a format.
|
||||||
|
|
||||||
|
## 0. The machine in one page
|
||||||
|
|
||||||
|
```
|
||||||
|
provider ──publishes──▶ CultMesh state (typed .cc records)
|
||||||
|
│ StatePort (subscribe / read)
|
||||||
|
▼
|
||||||
|
┌───────────────────────── thing-core (one crate, internal modules) ─────────────────────────┐
|
||||||
|
│ resolve ─▶ bind ─▶ layout ─▶ text ─▶ render ─┐ │
|
||||||
|
│ (docs, (Bind, (Taffy) (Parley or ├─▶ FrameOutput { commands, a11y, outbound, │
|
||||||
|
│ compos.) Repeat) cells) │ ime, diagnostics } │
|
||||||
|
│ input (focus, edit, hit-test, scroll) ─▶ command dispatcher ─▶ outbound CommandInvocation │
|
||||||
|
│ a11y (AccessKit tree) │
|
||||||
|
└───────────────────────────────────────────────────────────────────────────────────────────┘
|
||||||
|
▲ FrameInput { now, viewport, scale, events } │ commands + a11y
|
||||||
|
│ ▼
|
||||||
|
host event loop ◀────── thin backend: TUI (crossterm) | web (wasm + JS) | later hosts
|
||||||
|
```
|
||||||
|
|
||||||
|
Core is a **function of (documents, state, input, time)**. The host owns the loop
|
||||||
|
and calls `Core::frame`; core never spawns, sleeps, reads a clock or touches a
|
||||||
|
socket except through a port. This is what makes every test below runnable without
|
||||||
|
a daemon (`doctrine/gamecult.md`, "dependency injection is boring") and what makes
|
||||||
|
goldens byte-stable (map rule 10).
|
||||||
|
|
||||||
|
**D1. One crate for core, internal modules, not eight crates.** (Confidence
|
||||||
|
medium-high.) Authority separation (resolve, bind, layout, text, render, command)
|
||||||
|
is real, but the modules share one frame pipeline and one set of types; a crate per
|
||||||
|
stage buys build fan-out and a public surface no consumer may use, which
|
||||||
|
`narrow-consumer-contract` forbids. Splits that *do* earn a crate, each naming the
|
||||||
|
invariant it protects:
|
||||||
|
|
||||||
|
| Crate | Earns its boundary because |
|
||||||
|
| --- | --- |
|
||||||
|
| `thing-contract` (landed) | consumers depend on it alone (`narrow-consumer-contract`); three runtimes are held to its goldens |
|
||||||
|
| `thing-core` | owns geometry, text, focus, binding, results; depends on no transport, no clock, no platform |
|
||||||
|
| `thing-mesh` | the only crate that depends on CultMesh/CultNet: `StatePort`/discovery implementations. Keeps rule 7 and the mockable-port invariant checkable by a dependency-tree grep on `thing-core` |
|
||||||
|
| `thing-tui` | backend; depends on `thing-core` output types and `crossterm`, never `taffy`/`parley` (rule 8) |
|
||||||
|
| `thing-web` | wasm entry (`wasm-bindgen`) plus the JS host package; same dependency rule |
|
||||||
|
| `thing-testkit` | fake ports, fixture loader, golden harness, shared by every crate's tests; never a dependency of a shipped artifact |
|
||||||
|
|
||||||
|
Prior art: Xilem and egui split by renderer/backends and keep one core
|
||||||
|
(R-K §1: `masonry_core`, `egui`+`epaint`, backends as crates) **[read]**; AccessKit
|
||||||
|
and Parley are separate repos only where independently consumed or needing another
|
||||||
|
toolchain (R-K §1) **[read]**; Flutter merged repos to end rolls (R-K §1)
|
||||||
|
**[read]**. Same repo, many crates, is the dominant pattern.
|
||||||
|
|
||||||
|
## 1. Build order and dependency graph
|
||||||
|
|
||||||
|
```
|
||||||
|
0 decisions ─▶ 1 contract-ts ┐
|
||||||
|
├▶ 1 contract-cs ┴▶ 1x cross-store check
|
||||||
|
└▶ 2 testkit+ports ─▶ 3 resolve ─▶ 4 bind ─▶ 5 layout ─▶ 6 render+goldens ─▶ 7 commands
|
||||||
|
│ │
|
||||||
|
8 TUI ◀────────┘ │
|
||||||
|
9 text(Parley)/focus/edit ─▶ 10 a11y ─▶ 11 web ◀───┘
|
||||||
|
12 thing-mesh (parallel from 4 on)
|
||||||
|
13 consumer ports (one per consumer) ─▶ 14 retirement
|
||||||
|
```
|
||||||
|
|
||||||
|
Rules for the order: (a) contract before core (map, rationale); (b) the pipeline is
|
||||||
|
built **end to end thin first** (cut 8 draws a real surface in a terminal before
|
||||||
|
text, IME or a11y exist), then deepened, because the first full run is where unknown
|
||||||
|
unknowns show; (c) `thing-mesh` runs beside core from cut 4 because it is the
|
||||||
|
other half of the `StatePort` contract and needs the same fixtures; (d) no consumer
|
||||||
|
port starts before cut 7 and one backend (cut 8) work, so a port can be viewed.
|
||||||
|
|
||||||
|
Cuts are sized to Hands' budget (about 150 calls, 0.5M tokens is the danger line):
|
||||||
|
each row below is one `cut_spec`, or two where marked. Sizes are Self's estimates
|
||||||
|
in thousand lines of owned code (excluding goldens), pressure not metric.
|
||||||
|
|
||||||
|
| # | Cut | Waits on | Est. | Parallel with |
|
||||||
|
| --- | --- | --- | --- | --- |
|
||||||
|
| 1a/1b | contract-ts, contract-cs (specs `thing2:cut_spec:cut-contract-ts.r3`, `-cs.r3`) | contract-rs (landed `6ae2da0`) | mapped | each other |
|
||||||
|
| 1x | cross-store check | 1a, 1b | 0.3 | 2 |
|
||||||
|
| 2 | testkit + ports | contract-rs | 1.2 | 1a, 1b |
|
||||||
|
| 3 | resolve | 2 | 1.8 | - |
|
||||||
|
| 4 | bind | 3 | 1.5 | 12 |
|
||||||
|
| 5 | layout | 4 | 1.8 | - |
|
||||||
|
| 6 | render + goldens | 5 | 1.5 | - |
|
||||||
|
| 7 | commands | 4 (needs 6 only for hit-test) | 1.6 | 8 |
|
||||||
|
| 8 | TUI backend | 6, 7 | 1.5 | 7 tail |
|
||||||
|
| 9a/9b | text: measure+shape, then focus+editing+IME state | 6 | 2 + 2 | 8 |
|
||||||
|
| 10 | a11y tree | 9b | 1.0 | 11 start |
|
||||||
|
| 11a/11b/11c | web: wasm+drawing, IME mirror + a11y mirror, shell+discovery | 6, 9b, 10 | 1.5+1.5+1.0 | - |
|
||||||
|
| 12 | thing-mesh | 2, 4 | 1.5 | 5-8 |
|
||||||
|
| 13.n | consumer ports | 7, 8 (web for browser consumers: 11c) | per consumer | one repo each |
|
||||||
|
| 14 | retirement | last port | -1x | - |
|
||||||
|
|
||||||
|
## 2. Cross-cutting contracts
|
||||||
|
|
||||||
|
### 2.1 Core API (the one public surface core has)
|
||||||
|
|
||||||
|
```
|
||||||
|
Core::new(ports: Ports, config: Config) -> Core
|
||||||
|
Core::frame(&mut self, input: FrameInput) -> FrameOutput
|
||||||
|
FrameInput { now: Instant, viewport: Size, scale: f32, events: Vec<InputEvent>, metrics: MetricsMode }
|
||||||
|
FrameOutput { commands: Vec<RenderCommand>, a11y: Option<TreeUpdate>, outbound: Vec<CommandInvocation>,
|
||||||
|
ime: Option<ImeRequest>, diagnostics: Vec<Diagnostic>, next_wake: Option<Instant> }
|
||||||
|
Ports { state: dyn StatePort, fonts: dyn FontPort, clock: dyn Clock, ids: dyn IdSource, host: dyn HostEffects }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **One owner for time and ids.** `now` arrives in the frame input; `IdSource`
|
||||||
|
mints invocation ids. Tests substitute both, so a run is a pure function and
|
||||||
|
invocation ids in goldens are reproducible.
|
||||||
|
- **Outbound is invocations only** (rule 7). `Ports.state` has `read`, `subscribe`,
|
||||||
|
`list(schema, key_prefix)`; it has no `write`. The one write path is
|
||||||
|
`FrameOutput.outbound`, which the host or `thing-mesh` forwards.
|
||||||
|
- **`HostEffects`** has exactly the closed `effect` set of the contract:
|
||||||
|
`open_surface(key)`, `open_external(url)`; plus `clipboard` read/write when the
|
||||||
|
text piece needs it (see Open O7).
|
||||||
|
- Metrics mode (`Pixels` | `Cells`) is a core input, because the TUI measures in
|
||||||
|
cells inside the Taffy measure function (R-T §5: iocraft does exactly this
|
||||||
|
**[read]**) and rule 8 forbids the backend from owning any layout input. The
|
||||||
|
cell-metrics provider is part of core (small: `unicode-width` and
|
||||||
|
`unicode-segmentation`), not of `thing-tui`.
|
||||||
|
|
||||||
|
Prior art: Clay's per-frame contract (set dimensions → pointer state → begin layout
|
||||||
|
→ end layout returns the command array) is the model for `frame` **[read, R-F
|
||||||
|
§2.1]**; egui and Bevy UI emit shapes or commands to thin backends **[read, R-F
|
||||||
|
§2.4, R-T §1]**. Elm/Redux style "update is a pure function of state and event"
|
||||||
|
**[background]**. Confidence high: no contrary evidence found.
|
||||||
|
|
||||||
|
### 2.2 The closed render-command list (D2)
|
||||||
|
|
||||||
|
`FillRect{rect, radius, color}`, `StrokeRect{rect, radius, width, color}`,
|
||||||
|
`Text{origin, run, color}` where `run` is `Glyphs{font, size, glyphs}` (Pixels mode)
|
||||||
|
or `Cells{col, row, text, style}` (Cells mode), `Image{rect, catalog, asset, fit}`,
|
||||||
|
`ClipPush{rect, radius}`, `ClipPop`, `Polyline{points, width, color}`,
|
||||||
|
`Polygon{points, color}` (plot marks), `Embed{rect, slot_kind, slot_id}`.
|
||||||
|
Nine variants. Selection highlights, carets, focus rings and scrollbars are
|
||||||
|
`FillRect`/`StrokeRect` that core emits. Z order is emission order; there is no
|
||||||
|
z-index, no layers, no custom escape. A new command is a reviewed change to core
|
||||||
|
plus every backend and the goldens at once (that is the point of closing it).
|
||||||
|
|
||||||
|
Colours in commands are resolved literals; theme tokens never cross to a backend.
|
||||||
|
Coordinates are `f32` logical pixels in Pixels mode, integer cells in Cells mode.
|
||||||
|
|
||||||
|
Prior art: Clay's complete enum is `NONE, RECTANGLE, BORDER, TEXT, IMAGE,
|
||||||
|
SCISSOR_START, SCISSOR_END, OVERLAY_COLOR_START/END, CUSTOM`, with renderers for
|
||||||
|
SDL, raylib, canvas2d, termbox2 and a terminal, all thin **[read, R-F §2.1]**.
|
||||||
|
Thing's list differs on purpose: no `CUSTOM` (Embed is the closed host slot), no
|
||||||
|
overlay-colour pair (an overlay scrim is a `FillRect`), plus polylines for `Plot`.
|
||||||
|
Confidence medium: the count is a proposal; whether `Plot` should lower to
|
||||||
|
`Polyline`/`Polygon` or be left to an `Embed` is O3.
|
||||||
|
|
||||||
|
### 2.3 Diagnostics (D3)
|
||||||
|
|
||||||
|
A closed `Diagnostic { code, node, document, detail }`: `UnresolvedUse`,
|
||||||
|
`BindSchemaMismatch`, `BindMemberMissing`, `UnknownNode`, `UndeclaredCommand`,
|
||||||
|
`DuplicateNodeId`, `StaleVersionIgnored`, `MalformedResult`, `UnknownInvocation`,
|
||||||
|
`InvocationTimedOut`, `DecodeRefused`. The same value drives (a) the placeholder or
|
||||||
|
error node drawn in the frame, (b) a log line, (c) the a11y tree (an error node is
|
||||||
|
announced), and (d) the tests. Rules 2, 4, 5 and 6 are asserted on these codes, so
|
||||||
|
a rule that is deleted fails by name, not by a screenshot.
|
||||||
|
Confidence high; the alternative (free-text logs) is what Thing 1's gap ledgers were.
|
||||||
|
|
||||||
|
### 2.4 Test layers and golden format (D4)
|
||||||
|
|
||||||
|
Doctrine splits tests into local-authority unit tests, adjacent-organ pipeline
|
||||||
|
smokes, and end-to-end Verse contract runs; every piece below names which layer.
|
||||||
|
|
||||||
|
- **Fixtures** (`tests/fixtures/*.surface.cc`, committed): typed documents encoded
|
||||||
|
through `thing-contract`, one per row of the fixture table (§2.5). Built by a
|
||||||
|
`thing-testkit` builder in Rust, then frozen; the bytes are what is loaded.
|
||||||
|
- **Geometry golden**: for a fixture + viewport + state script, the resolved node
|
||||||
|
tree with `(node id, x, y, w, h)` in a stable text form.
|
||||||
|
- **Render golden**: the `Vec<RenderCommand>` encoded with CultCache MessagePack
|
||||||
|
through the same derive the contract uses, plus a line-oriented text rendering
|
||||||
|
beside it for diffs. The binary form is the oracle (byte-identical, rule 10); the
|
||||||
|
text form is only for review.
|
||||||
|
- **Regeneration** is `cargo xtask bless`, runs only on a reviewed core change,
|
||||||
|
and a backend crate cannot call it (model page: goldens are the core's).
|
||||||
|
- **Layout correctness is inherited, tree building is tested.** Taffy is itself
|
||||||
|
validated against Chrome with generated fixtures (`just gentest`, R-F §2.2
|
||||||
|
**[read]**), as is Yoga (`gentest/`, R-F §2.3 **[read]**); Thing does not re-prove
|
||||||
|
flexbox. Thing's tests prove that *our* style mapping puts the right inputs into
|
||||||
|
Taffy and that the output flows into commands unchanged. One extra check
|
||||||
|
re-derives a small fixture's geometry from the raw Taffy API directly and compares
|
||||||
|
(guards against our mapping drifting while goldens are re-blessed).
|
||||||
|
- **Mutation**: `tools/cargo-mutants.sh` once per Hands pass, scoped to the cut's
|
||||||
|
diff, per the Eureka rule. Each piece's "Test" below names the rules whose
|
||||||
|
mutants must die; a survivor is triaged, not hidden.
|
||||||
|
- **Property tests** (`proptest` [background]) only where a total function has a
|
||||||
|
clear law: contract round-trip (exists), `resolve` never panics and either
|
||||||
|
returns a tree whose ids are unique or a refusal, `bind` is idempotent for the
|
||||||
|
same state, `frame` with no events and unchanged state returns an equal command
|
||||||
|
list (stability). Fuzzing the decoder (`cargo-fuzz` [background]) waits only on Eve taking the
|
||||||
|
CultLib pin that carries `decode-stack-safety` (Fixed, CultLib `bbb98eaf`,
|
||||||
|
`cultlib-gaps:resolution:follow_up.decode-stack-safety.n1`; map P20).
|
||||||
|
|
||||||
|
Prior art: golden command lists are not published by any project read (R-F §2.5:
|
||||||
|
"not found, not searched exhaustively"), so this is the least-supported decision
|
||||||
|
in the spec; the nearest supported techniques are Taffy/Yoga generated geometry
|
||||||
|
tests and egui's `egui_kittest` snapshot crate (R-K §1 lists the crate;
|
||||||
|
its snapshot method is **[background]**). Confidence medium: the idea is sound
|
||||||
|
because commands are renderer-independent by construction; cost of churn on
|
||||||
|
intentional change is the risk, mitigated by `bless` being one command.
|
||||||
|
|
||||||
|
### 2.5 Fixture set (the census sizes the floor)
|
||||||
|
|
||||||
|
Twelve fixtures cover the node set and every rule; each is named for the consumer
|
||||||
|
shape it models (R-C §7 cross-table is the source, and Thing is a general library,
|
||||||
|
so a fixture exists for a capability a reasonable consumer would expect even with
|
||||||
|
no caller today):
|
||||||
|
|
||||||
|
| Fixture | Exercises | Rules |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `f01-swarm-dashboard` | VoidBot-shaped: Box grid, bound Text/Format, `Repeat` over a collection prefix, one Button | 6, 9 |
|
||||||
|
| `f02-login-effect` | Ghostlight/Heimdall: TextInput, Button, `OpenExternal{resume}` result | 1, 2 |
|
||||||
|
| `f03-input-target` | Muninn: `position: absolute` target over an `Image`, bound label (P6) | - |
|
||||||
|
| `f04-form` | Toggle, Slider, Select, TextInput number, `captures` and `clear_drafts` | 1 |
|
||||||
|
| `f05-modal-overlay` | `Overlay` modal with dismiss command, focus trap | - |
|
||||||
|
| `f06-scroll-list` | `overflow: scroll`, `Repeat` 1k items, keyed insert/remove | - |
|
||||||
|
| `f07-plot` | Stonks/StreamPixels-shaped `Plot` series | - |
|
||||||
|
| `f08-embed-viewport` | `Embed` slot as a leaf of given size | - |
|
||||||
|
| `f09-composition-stack` | nested `Use` with typed args and child slots, `thing.std` plus a publisher composition | 5 |
|
||||||
|
| `f10-hostile` | unknown arm, undeclared `CommandRef`, duplicate id after expansion, unresolved `Use`, schema-mismatched `Bind` | 4, 5, 6 |
|
||||||
|
| `f11-deep` | nesting at the 256 bound (decoded on a large-stack thread until Eve's pin of CultLib `bbb98eaf` merges) | - |
|
||||||
|
| `f12-text-edge` | bidi, CJK wide characters, combining marks, emoji ZWJ, long wrap | - |
|
||||||
|
|
||||||
|
## 3. The pieces
|
||||||
|
|
||||||
|
Each piece lists **Owner** (one writer), **In**, **Out**, **Ports**,
|
||||||
|
**Invariants** (what must die under mutation), **Failure**, **Test** (layer and the
|
||||||
|
rule each pins), **Deletes/forbidden** (what the piece must not contain), and
|
||||||
|
**Prior art**. Map rules are cited as M1-M10 (the ten in the map's "Rules that must
|
||||||
|
die under their own mutation").
|
||||||
|
|
||||||
|
### Piece 1: contract (packages for TS and C#, and the store check)
|
||||||
|
|
||||||
|
Rust (`crates/thing-contract`) landed after two Soul passes; `contract-ts` and
|
||||||
|
`contract-cs` are mapped (`thing2:cut_spec:cut-contract-ts.r3`, `-cs.r3`; r2
|
||||||
|
is superseded) and have
|
||||||
|
branches (`hands/thing2-contract-ts`, `hands/thing2-contract-cs`) not yet merged.
|
||||||
|
This spec adds no contract change. Rulings that bind the packages:
|
||||||
|
|
||||||
|
- **Unknown union arms** are refused by CultCache in every runtime, the C#
|
||||||
|
reference included, and Thing packages carry no check of their own
|
||||||
|
(`thing2:ruling:contract-decode-tolerance`; the fix is CultLib's, follow-up
|
||||||
|
`thing2:follow_up:cultcache-union-parity`, resolved in the mind). The "unknown union arm is refused"
|
||||||
|
test below therefore exercises CultCache, not package code.
|
||||||
|
- **Nil in required slots** is refused by each package: constructors and factories
|
||||||
|
reject null, decoding nil into a slot the Rust contract does not make optional
|
||||||
|
is a typed refusal (`thing2:ruling:contract-refuses-nil-in-required-slots`,
|
||||||
|
Defaulted). In TS this is a `present(codec)` on every non-Option slot, and
|
||||||
|
results are validated and frozen at one factory (`cut-contract-ts.r3`).
|
||||||
|
- **Byte payloads** (`RecordPayload.Bytes`) are a copied read-only view in C#
|
||||||
|
(`ReadOnlyMemory<byte>`); Rust's `Vec<u8>` and the wire are unchanged
|
||||||
|
(`thing2:ruling:payload-bytes-read-only`, Defaulted). The catalog type name for
|
||||||
|
that slot changes with it, which the 1x store check must read from the C# set.
|
||||||
|
|
||||||
|
- **Owner:** the contract crate; packages own nothing (map authority).
|
||||||
|
- **Test (per package):** the shared golden fixtures decode and re-encode
|
||||||
|
byte-identical (M1, M3); the refusal goldens (`seq` 0, extra slot, unknown union
|
||||||
|
arm) are refused; a hand-built object with seq 0 is refused at encode.
|
||||||
|
- **1x cross-store check:** the C# package opens a `.cc` store the TS package wrote
|
||||||
|
and the reverse, and both open Rust's. The check lives in `thing-testkit` as a
|
||||||
|
scripted cross-runtime job run on Yggdrasil's verify stopgap
|
||||||
|
(`tools/stopgap/ygg-verify.sh`), because only that image has all three runtimes.
|
||||||
|
It proves the catalog type names agree (map cut 1 waiting line).
|
||||||
|
- **Prior art:** CultCache wire parity against the C# reference is the standing
|
||||||
|
CultLib rule; probe P12-P13 are the evidence **[read, map]**; golden-file
|
||||||
|
interoperability is how Protobuf and Cap'n Proto test language bindings
|
||||||
|
(`conformance` suites) **[background]**. Confidence high.
|
||||||
|
|
||||||
|
### Piece 2: testkit and ports
|
||||||
|
|
||||||
|
- **Owner:** `thing-testkit` owns fakes; `thing-core` owns the port *traits*
|
||||||
|
(a trait is the narrow port; the fake is a test crate's business).
|
||||||
|
- **In/Out:** `StatePort { read(schema,key)->Option<Entry>, list(schema,prefix),
|
||||||
|
subscribe(schema,key|prefix) -> Stream<Change> }` where `Change` is
|
||||||
|
`Upsert(entry)|Delete(key)`; `FontPort { resolve(family, weight, style) ->
|
||||||
|
FontHandle, bytes(handle) }`; `Clock`; `IdSource`; `HostEffects`. All object-safe.
|
||||||
|
- **Fakes:** `MemState` (a `CultCache`-backed map with a scripted change feed and
|
||||||
|
a record of every call), `FixedFonts` (one bundled test font, so Parley output is
|
||||||
|
deterministic across machines), `ManualClock`, `SeqIds`.
|
||||||
|
- **Invariants:** `StatePort` has no write method (M7, checked by the trait's
|
||||||
|
method list in a test that enumerates it and by a grep over `thing-core`);
|
||||||
|
`MemState` returns entries only as decoded contract records, never `Value`.
|
||||||
|
- **Failure:** a decode refusal from the port surfaces as a `Change::Refused`
|
||||||
|
carrying the code, never as a missing record (a refusal must not look like
|
||||||
|
absence).
|
||||||
|
- **Test:** unit. `MemState` change ordering; fixture loader round-trips all twelve
|
||||||
|
fixtures through the contract (a fixture that fails the contract is a bug in the
|
||||||
|
fixture before it is a bug in core).
|
||||||
|
- **Deletes/forbidden:** no global state, no `Instant::now()` in core (negative
|
||||||
|
grep).
|
||||||
|
- **Prior art:** the port style is the project's own doctrine; Xilem's
|
||||||
|
`masonry_testing` and egui's `egui_kittest` are test-harness crates beside a core
|
||||||
|
(R-K §1) **[read]**. Confidence high.
|
||||||
|
|
||||||
|
### Piece 3: resolve
|
||||||
|
|
||||||
|
- **Owner:** `thing-core::resolve`. It is the only code that interprets Thing
|
||||||
|
Script structure.
|
||||||
|
- **In:** `SurfaceDocument`, a `CompositionStore` (std compiled in, plus publisher
|
||||||
|
compositions read through `StatePort`). **Out:** `ResolvedTree` (arena of
|
||||||
|
nodes, unique ids, every `Use` expanded or replaced by a placeholder node, every
|
||||||
|
`CommandRef` checked against the document's `CommandDecl`s, bindings still
|
||||||
|
unresolved), plus diagnostics.
|
||||||
|
- **Invariants:** M4 (unknown kind, undeclared `CommandRef`, duplicate id after
|
||||||
|
expansion refuse the document *whole*, and the old document stays displayed);
|
||||||
|
M5 (unresolved `Use` is a visible placeholder with a diagnostic); expansion is
|
||||||
|
substitution only (no conditionals, no arithmetic: a test that every
|
||||||
|
`thing.std` composition expands under a parameter-less evaluator); expansion
|
||||||
|
terminates (recursion in compositions is refused with a cycle diagnostic and a
|
||||||
|
depth bound); expansion is deterministic and order-preserving; ids of expanded
|
||||||
|
nodes are derived from the `Use` node id and the template id by one scheme, so
|
||||||
|
they are stable across republishes (focus and scroll state key on them).
|
||||||
|
- **Failure:** a referenced composition arrives later → the placeholder is
|
||||||
|
replaced next frame without a republish.
|
||||||
|
- **Test:** unit per rule on `f09`, `f10`; property (`resolve` total, ids unique or
|
||||||
|
refusal); pipeline smoke: `resolve` output fed to `layout` (cut 5) in `f01`.
|
||||||
|
Mutants that must die: skip the duplicate-id check; treat an undeclared
|
||||||
|
`CommandRef` as a warning; drop the placeholder; expand `Use` without pinning the
|
||||||
|
composition version.
|
||||||
|
- **Deletes/forbidden:** no `kind` string dispatch anywhere (closed enum only); no
|
||||||
|
fallback along a kind path (M4); no expression evaluator. No text-syntax parser
|
||||||
|
outside `thing-core` (`thing-script-form`): `resolve` consumes only the typed
|
||||||
|
document; a later `.thingscript` parser is core's and feeds it.
|
||||||
|
- **Prior art:** Adaptive Cards separates template expansion from render
|
||||||
|
(`adaptivecards-templating` expands a template against data before render)
|
||||||
|
**[read, R-K §2]**; Thing's `Use` is the same split without an expression
|
||||||
|
language, which R-K §2/P5 shows the failure of (the DSL's renderer-local `derive`)
|
||||||
|
**[read]**. Slint compiles a text language to a typed tree at build/run time
|
||||||
|
**[read, R-K §2]**. Confidence high on substitution-only; medium on id-derivation
|
||||||
|
(no source read; it is the same problem React solves with keys **[background]**).
|
||||||
|
|
||||||
|
### Piece 4: bind
|
||||||
|
|
||||||
|
- **Owner:** `thing-core::bind`. Only code that reads typed state.
|
||||||
|
- **In:** `ResolvedTree`, `StatePort`. **Out:** `BoundTree` with every `Bind`
|
||||||
|
replaced by a typed value or a binding-error value; `Repeat` expanded to one
|
||||||
|
subtree per item, keyed by the item key; subscriptions established and released
|
||||||
|
as bindings appear and disappear.
|
||||||
|
- **Invariants:** M6 (different schema or missing member renders a typed error,
|
||||||
|
never a coerced value); M9 (a version at or below the held one is ignored, and
|
||||||
|
the ignore is a `StaleVersionIgnored` diagnostic at most once per document
|
||||||
|
version, not per frame); a value change never triggers layout of anything but the
|
||||||
|
nodes whose bound values changed (dirty tracking is observable through a counter
|
||||||
|
the test reads); `Format` is total and locale-free in core (formats are the
|
||||||
|
closed set; any locale is a host input, see O8); `Repeat` item keys must be
|
||||||
|
unique, a duplicate key refuses the document at bind time as M4 does; keyed
|
||||||
|
reorder preserves node identity, so focus and scroll survive a reorder.
|
||||||
|
- **Subscription rule:** core subscribes to exactly the `(schema,key)` pairs and
|
||||||
|
prefixes the live tree references; a document replacement diffs its subscription
|
||||||
|
set. An unsubscribed record's arrival changes nothing.
|
||||||
|
- **Failure:** record absent → a typed `Absent` value rendered as the node's
|
||||||
|
declared empty text (the contract field), not an error; schema mismatch → error.
|
||||||
|
- **Test:** unit per rule on `f01`, `f06`, `f10` with scripted `MemState` feeds;
|
||||||
|
pipeline smoke `bind → layout` checks dirty-node count; mutants: coerce a
|
||||||
|
mismatched schema; drop the version gate; resubscribe every frame; reorder by
|
||||||
|
index instead of key.
|
||||||
|
- **Deletes/forbidden:** no local `var`/`derive`/`collection` store (P5); no draft
|
||||||
|
binding (BD2: editing state is `input`'s).
|
||||||
|
- **Prior art:** BD1-BD9 collapse in the map **[read, map]**; keyed list
|
||||||
|
reconciliation is React's `key` and Elm's `Html.Keyed` **[background]**;
|
||||||
|
Clay retains element state by ID and requires `CLAY_IDI` for loops (R-F §2.1)
|
||||||
|
**[read]**, the same constraint. Flutter's retained tree keeps state by key
|
||||||
|
**[background]**. Confidence high.
|
||||||
|
|
||||||
|
### Piece 5: layout
|
||||||
|
|
||||||
|
- **Owner:** `thing-core::layout`. The only crate-user of `taffy`.
|
||||||
|
- **In:** `BoundTree`, viewport, metrics mode, `FontPort`. **Out:** `LaidTree`:
|
||||||
|
per node a content box, scroll extents, clip, and absolute-positioned overlay
|
||||||
|
boxes.
|
||||||
|
- **Contract:** the mapping from contract `BoxStyle` to Taffy style is one
|
||||||
|
function with an exhaustive match (a new contract field fails to compile until it
|
||||||
|
is mapped). Leaf measure for `Text`, `TextInput`, `Image`, `Embed`, `Plot`
|
||||||
|
goes through one `Measure` trait: Pixels → Parley (piece 9), Cells → cell metrics,
|
||||||
|
`Image`/`Embed`/`Plot` → declared sizes. Overlay nodes are laid out as a
|
||||||
|
separate root attached to an anchor node's final rectangle or the viewport.
|
||||||
|
Scroll containers expose `content size` and clamp offsets that `input` owns.
|
||||||
|
- **Invariants:** layout is a pure function of (tree, viewport, scale, metrics,
|
||||||
|
fonts): same inputs, byte-identical geometry (M10); a style field with a literal
|
||||||
|
and a token resolves via the one theme resolver before reaching Taffy; `fr`,
|
||||||
|
`%`, `auto` and `content` sizes reach Taffy as the matching Taffy dimensions
|
||||||
|
with no rewriting; an `Embed` is a leaf of exactly its declared size.
|
||||||
|
- **Failure:** NaN or negative sizes from a document are refused at resolve (the
|
||||||
|
contract already refuses at decode for `Count`); layout never panics on a
|
||||||
|
constraint it cannot satisfy and instead overflows per CSS rules.
|
||||||
|
- **Test:** unit geometry goldens on `f01`, `f03`, `f05`, `f06`, `f08`; the
|
||||||
|
raw-Taffy rederivation on one small tree (§2.4); property: layout is
|
||||||
|
deterministic across repeats and scale 1 vs 2 scales positions linearly when
|
||||||
|
fonts are scale-independent (fixed font); Cells mode: `f12` widths equal
|
||||||
|
`unicode-width` expectations. Mutants: swap row/column mapping; drop `gap`;
|
||||||
|
round positions; ignore `position: absolute` insets.
|
||||||
|
- **Deletes/forbidden:** `taffy` appears in no other crate's tree (M8, `cargo tree
|
||||||
|
-i taffy` negative check on `thing-tui`, `thing-web`, `thing-mesh`, contract).
|
||||||
|
- **Prior art:** Taffy implements Block, Flexbox and Grid, is used by Servo, Blitz,
|
||||||
|
Bevy, Slint, iocraft, Zed/GPUI and is validated against Chrome (R-F §2.2) **[read]**;
|
||||||
|
measure-function leaf text is the documented integration point (R-F §2.2, R-T §1)
|
||||||
|
**[read]**; iocraft's measure for Cells (R-T §5) **[read]**. Ruling
|
||||||
|
`thing:ruling:thing2-one-solver-taffy`. Pin: Taffy 0.14.0 (2026-08-24 [read]);
|
||||||
|
Slint pins 0.10 flexbox-only and iocraft 0.5.2 (R-T §1, §5), so the Grid feature
|
||||||
|
surface at 0.14 is the one to prove first (confidence medium).
|
||||||
|
|
||||||
|
### Piece 6: render and goldens
|
||||||
|
|
||||||
|
- **Owner:** `thing-core::render`. Turns `LaidTree` + paint + input state into the
|
||||||
|
command list; draws selection, caret, focus ring, scrollbars.
|
||||||
|
- **Invariants:** M10 (byte-identical command list for equal inputs); painter
|
||||||
|
order is document order, then overlays last; `ClipPush`/`ClipPop` balance (a
|
||||||
|
validator over every golden); every `Embed` and `Image` node produces exactly
|
||||||
|
one command or a visible missing-asset placeholder (diagnostic `AssetMissing`
|
||||||
|
added to D3's list when this cut lands, O9); nothing outside the clip stack is
|
||||||
|
drawn for `overflow: clip|scroll` nodes.
|
||||||
|
- **Backends must prove consumption (M10 second half):** each backend's parity
|
||||||
|
test replays a golden list and asserts one draw call per command; a backend that
|
||||||
|
skips a command variant fails by name.
|
||||||
|
- **Test:** golden suite described in §2.4 over all fixtures; pipeline smoke
|
||||||
|
`resolve→bind→layout→render` on `f01`; mutants: drop `ClipPop`, reorder overlay,
|
||||||
|
emit caret when unfocused, emit a command with a theme token not a literal.
|
||||||
|
- **Prior art:** Clay's sorted command array and scissor start/end (R-F §2.1)
|
||||||
|
**[read]**; egui/epaint clipped shapes to thin backends (R-F §2.4) **[read,
|
||||||
|
background]**. Confidence high on structure, medium on exact variants (O3).
|
||||||
|
|
||||||
|
### Piece 7: commands (dispatcher and result validation)
|
||||||
|
|
||||||
|
- **Owner:** `thing-core::command`. Mints invocations, tracks them, validates
|
||||||
|
results. The only producer of `FrameOutput.outbound`.
|
||||||
|
- **Lifecycle (D5):** `Issued → Pending* → Completed | Denied | Failed`, with two
|
||||||
|
core-only terminal states, `Malformed` (result failed to decode, or named an
|
||||||
|
unknown invocation) and `TimedOut`. Terminal states are final: a later result
|
||||||
|
for a terminal invocation is a diagnostic, not a state change.
|
||||||
|
- **In:** input events that activate a `CommandRef` node; results arriving as
|
||||||
|
`StatePort` changes of schema `gamecult.thing.command_result.v1`.
|
||||||
|
**Out:** `CommandInvocation` (id from `IdSource`, `captured` from `input`'s editing
|
||||||
|
state for the nodes `CommandDecl.captures` lists, `surface` = key + held version,
|
||||||
|
`issued_at` from the clock; **no caller identity field written**, the transport
|
||||||
|
sets it), UI state for the issuing node (busy, denied-at-node), effects through
|
||||||
|
`HostEffects`.
|
||||||
|
- **Invariants:** M2 (a result that fails to decode, or an unknown `invocation_id`,
|
||||||
|
becomes a visible `Malformed` state for that invocation and a log line; no
|
||||||
|
invocation stays pending past its timeout without one); M7 (core writes nothing
|
||||||
|
but invocations); idempotency: one user action mints exactly one id, and a
|
||||||
|
re-delivered invocation carries the same id; `Completed{clear_drafts:true}`
|
||||||
|
clears exactly the captured nodes' drafts and no others; `OpenExternal{resume}`
|
||||||
|
is executed once per result `seq`; a `Denied{node}` marks that node and no
|
||||||
|
other; a double-click on a busy Button mints no second invocation while the first
|
||||||
|
is non-terminal (the Button node's enabled state is derived from lifecycle, not a
|
||||||
|
flag a document sets).
|
||||||
|
- **Timeout:** a core config value, default 15 s in `Config` (O5: it is a guess).
|
||||||
|
- **Failure:** `StatePort` refusal on a result (piece 2's `Change::Refused`) maps to
|
||||||
|
`Malformed`, which is the case P2 shows Thing 1 lacked (result rejected whole
|
||||||
|
by `ajv` with nothing visible).
|
||||||
|
- **Test:** unit lifecycle table (every transition, every illegal one), driven
|
||||||
|
with `ManualClock` for timeouts; pipeline smoke with `MemState`: press a Button in
|
||||||
|
`f02`, assert exactly one outbound invocation with the right captures, feed
|
||||||
|
`Pending` then `Completed{OpenExternal}`, assert one host effect; negative:
|
||||||
|
result with extra field (M1) never reaches the lifecycle. Mutants: no timeout;
|
||||||
|
mint id per frame; `clear_drafts` clears all; accept results after terminal;
|
||||||
|
write caller identity.
|
||||||
|
- **Prior art:** idempotency keys for commands and retries (Stripe API
|
||||||
|
idempotency, RFC draft "Idempotency-Key" header) **[background]**; command/result
|
||||||
|
split with a pending phase (job/operation resources in Google AIP-151 long-running
|
||||||
|
operations) **[background]**; Flutter's `TextInputConnection` shows what drafts the
|
||||||
|
host must hold (R-T §4) **[read]**. Evidence of the failure it prevents: P2, P7
|
||||||
|
**[read, map]**. Confidence medium-high; the `Malformed` rule follows directly
|
||||||
|
from P2.
|
||||||
|
|
||||||
|
### Piece 8: TUI backend (`thing-tui`)
|
||||||
|
|
||||||
|
- **Owner:** `thing-tui`: terminal drawing, keyboard and mouse into `InputEvent`.
|
||||||
|
First end-to-end consumer of core; also the agents' reader.
|
||||||
|
- **In:** `FrameOutput.commands` in Cells mode. **Out:** terminal bytes via
|
||||||
|
`crossterm`; `InputEvent`s.
|
||||||
|
- **Invariants:** M8 (no `taffy`/`parley` in the tree); every `RenderCommand`
|
||||||
|
variant is handled and each is either drawn or explicitly declared
|
||||||
|
not-representable in cells (`Image` → block placeholder with alt text,
|
||||||
|
`Polyline` → braille or block approximation): "not representable" is a table in
|
||||||
|
the crate, tested; wide and zero-width characters advance the cursor as the
|
||||||
|
`Cells` run says (the backend never re-measures); the screen diff writes only
|
||||||
|
changed cells (testable on a `Vec<Cell>` buffer without a terminal).
|
||||||
|
- **Test:** unit on a virtual screen (`ratatui`-style test buffer is
|
||||||
|
**[background]**; ours is a `Vec<Cell>`): every golden command list renders to a
|
||||||
|
stored screen dump; pipeline smoke: `f01` through the whole of cuts 3-7 to a
|
||||||
|
screen dump; parity (M10): every command variant produces a cell effect.
|
||||||
|
Mutants: skip `ClipPop`; mis-advance on a wide char; draw a command outside the
|
||||||
|
clip; ignore `Text` colour.
|
||||||
|
- **Forbidden:** layout of any kind.
|
||||||
|
- **Prior art:** Clay has `termbox2` and terminal renderers as thin command
|
||||||
|
consumers (R-F §2.1) **[read]**; iocraft is a Taffy-based TUI (R-T §5) **[read]**;
|
||||||
|
ratatui uses Cassowary not Taffy and pins `unicode-width >= 0.2.0` (R-T §5)
|
||||||
|
**[read]**, a version issue to carry into our own pin (confidence medium: width
|
||||||
|
tables differ between 0.1.x and 0.2.x, so the cell widths in goldens must be
|
||||||
|
pinned to a crate version, D6).
|
||||||
|
|
||||||
|
### Piece 9: text (9a measure+shape, 9b focus+editing+IME state)
|
||||||
|
|
||||||
|
- **Owner:** `thing-core::text` (`thing:ruling:thing2-thing-owns-text`, operator:
|
||||||
|
core owns shaping (Parley), editing and IME state, focus and the AccessKit tree;
|
||||||
|
backends only draw and bridge to platform protocols; glyph rasterization stays
|
||||||
|
backend-private and the render-command contract carries shaped glyph runs).
|
||||||
|
- **9a In/Out:** string + `TextStyle` + width constraint → `TextLayout` with
|
||||||
|
line boxes and glyph runs (Pixels, via Parley) or cell lines (Cells). One
|
||||||
|
`Measure` implementation per metrics mode behind the layout `Measure` trait.
|
||||||
|
- **9b In/Out:** `InputEvent`s targeted by hit-test/focus → editing state per
|
||||||
|
`TextInput` node (value, selection, composition range), caret rectangle,
|
||||||
|
`ImeRequest { rect, text_window, selection }` (the data a hidden host element
|
||||||
|
needs), and edits fed to `command` as captured values.
|
||||||
|
- **Focus (D7):** one focus owner in core. Tab order is document order of
|
||||||
|
focusable nodes, overlays trap focus while modal, focus is keyed by node id and
|
||||||
|
survives republish when the id survives, and a focused node removed moves focus
|
||||||
|
to its previous sibling then parent. A backend never owns focus; it forwards host
|
||||||
|
focus loss/gain only.
|
||||||
|
- **Invariants (9a):** shaping and bidi never run in a backend (M8); a run's glyph
|
||||||
|
positions are a pure function of (text, style, width, font bytes); wrap and
|
||||||
|
`max_lines` are applied by core and appear in the command list.
|
||||||
|
- **Invariants (9b):** the draft is core's state and dies with the session (model
|
||||||
|
page row 5); composition text is displayed but not committed or captured until
|
||||||
|
the host commits; an IME update never rewrites committed text; every selection
|
||||||
|
edit is on grapheme-cluster boundaries (`unicode-segmentation`); `ImeRequest`
|
||||||
|
windows the text rather than mirroring a whole large value, and coalesces to one
|
||||||
|
per frame (R-T §2: GPUI's mirror coalesces writes because each write restarts the
|
||||||
|
IME connection **[read]**).
|
||||||
|
- **Test:** 9a: unit on `f12` (bidi order, CJK width, combining marks, ZWJ
|
||||||
|
emoji clusters, wrap at several widths) with the bundled font; golden glyph
|
||||||
|
runs. 9b: scripted event sequences (type, move, select, delete across a
|
||||||
|
cluster, compose-update-commit, compose-cancel, undo if D8 includes it) assert
|
||||||
|
value/selection/`ImeRequest` at each step; focus: traversal order on `f04`,
|
||||||
|
trap on `f05`, removal on a republish. Mutants: byte-index deletion in a
|
||||||
|
cluster; commit composition on update; focus not keyed by id; mirror whole value.
|
||||||
|
- **Prior art:** Parley: rich-text layout with HarfRust shaping, ICU4X bidi and
|
||||||
|
segmentation, `PlainEditor`, IME primitives, an AccessKit editor example
|
||||||
|
(R-T §1) **[read]**; Bevy (taffy 0.14 + parley 0.11), Slint (`shared-parley`),
|
||||||
|
Blitz (Stylo + Taffy + Parley, text input state in the DOM node), Masonry (R-T §1-2)
|
||||||
|
**[read]**: four independent Taffy+Parley integrations. Cosmic-text is the
|
||||||
|
alternative; Parley wins on the integrations above and AccessKit ties, not on
|
||||||
|
measured quality (R-T §1; no benchmark read). IME-restart and mirror behaviour
|
||||||
|
from GPUI web, egui `text_agent`, Flutter web `text_editing.dart` (R-T §2)
|
||||||
|
**[read]**. Confidence medium: all of this is an assembly of read-but-not-built
|
||||||
|
parts; the biggest risk is Parley under `wasm32` and `no_std`-adjacent builds
|
||||||
|
(not established; O1). Slug/Vello GPU glyphs (R-T §6) is the operator's scope
|
||||||
|
addition and is **out of this build order**: glyphs reach the backend as
|
||||||
|
positioned runs, and how the web backend rasterizes them (canvas 2D first,
|
||||||
|
GPU later) is O2.
|
||||||
|
|
||||||
|
### Piece 10: a11y tree
|
||||||
|
|
||||||
|
- **Owner:** `thing-core::a11y`. Derives an AccessKit `TreeUpdate` per frame from
|
||||||
|
the resolved tree, roles, labels, focus, text editing state and layout.
|
||||||
|
- **Invariants:** every focusable node has a role and an accessible name (a
|
||||||
|
document that offers none gets the diagnostic `NoAccessibleName`, O9); roles come
|
||||||
|
from the contract's closed `Role` set mapped by one exhaustive match; bounds equal
|
||||||
|
layout bounds; updates are incremental (unchanged nodes omitted), keyed by node
|
||||||
|
id; an `Embed` is exposed as a generic node with its label; text input exposes
|
||||||
|
value, selection and composition as AccessKit text-run data.
|
||||||
|
- **Test:** unit: tree for `f01`, `f04`, `f05` compared to stored AccessKit
|
||||||
|
dumps; incremental update test (change one bound value → exactly the changed
|
||||||
|
node plus ancestors needed); mutants: drop `focus`; stale bounds after scroll;
|
||||||
|
role map swap. An actual screen reader cannot be run in CI; it is an operator
|
||||||
|
check at web cutover (O6).
|
||||||
|
- **Prior art:** AccessKit as the schema, with Bevy, Blitz, Masonry, Slint, GPUI
|
||||||
|
and egui integrating it (R-T §3) **[read]**; Blitz's `build_accessibility_tree`
|
||||||
|
tests (`accessibility_roles.rs`) are the closest test style **[read]**. Web
|
||||||
|
adapter: **planned only** in AccessKit (R-F §2.6, R-T §3), so the web backend
|
||||||
|
mirrors the tree to DOM itself (piece 11b); Flutter web is the shipped precedent,
|
||||||
|
and its open issues (semantics DOM stealing taps, R-T §3) are the failure
|
||||||
|
catalogue for 11b. Confidence high on native, medium on web.
|
||||||
|
|
||||||
|
### Piece 11: web backend and shell (`thing-web`)
|
||||||
|
|
||||||
|
- **Owner:** `thing-web` (wasm entry + a small JS host package). Replaces the
|
||||||
|
Nightwing browser reference (`nightwing-eve-browser-reference`, P8).
|
||||||
|
- **11a draw:** core compiled to wasm, `frame` called from `requestAnimationFrame`
|
||||||
|
with batched events; commands drawn to one canvas 2D context (D9: canvas 2D
|
||||||
|
first, because GPUI web already rasterizes through OffscreenCanvas 2D, R-T §2,
|
||||||
|
and the contract is already glyph-run based so a GPU path swaps in under the same
|
||||||
|
commands). The JS host holds **no layout, no text shaping, no focus state**.
|
||||||
|
- **11b IME + a11y:** a hidden `<textarea>` placed from `ImeRequest` (the pattern
|
||||||
|
all three of egui, GPUI and Flutter web converge on, R-T §2), mirrored text
|
||||||
|
windowed and coalesced; a DOM accessibility mirror of the AccessKit update,
|
||||||
|
clipped so it cannot intercept pointer events (the exact Flutter failures in R-T
|
||||||
|
§3: #194011, #192466), off by default until an assistive-technology signal or an
|
||||||
|
explicit toggle, as Flutter does.
|
||||||
|
- **11c shell + discovery:** a web app that discovers surfaces through the Verse's
|
||||||
|
discovery owner (map: discovery is not Thing's, `advertisement-owner`; until the
|
||||||
|
owner's typed advertisement lands, `thing2:follow_up:discovery-owner-campaign`,
|
||||||
|
through one adapter over today's `gamecult.eve.provider_advertisement.v1`,
|
||||||
|
deleted when it does) and mounts core; reachable by `thing-mesh`'s transport or a gateway (O4).
|
||||||
|
- **Invariants:** M8 (no `taffy`/`parley` in the JS package or the wasm host
|
||||||
|
glue); the JS host calls only `Core::frame`, passes only the closed
|
||||||
|
`InputEvent`s, and draws only the closed commands; the hidden textarea never
|
||||||
|
scrolls the page into view (R-T §2: egui's park-over-canvas) and never receives
|
||||||
|
pointer events; one frame's work for `f06` (1k items) stays under a stated budget
|
||||||
|
(O10: a number is owed, none was measured).
|
||||||
|
- **Test:** unit in `wasm-bindgen-test` (headless Chrome and Firefox in the verify
|
||||||
|
image): replay goldens through the canvas and compare against a canvas-drawn
|
||||||
|
reference of the same list (command consumption, M10); IME: scripted composition
|
||||||
|
events at the textarea produce core edits equal to the 9b scripts; a11y: DOM
|
||||||
|
mirror equals the AccessKit tree for `f04`; click-through: a pointer test over a
|
||||||
|
mirror region reaches the canvas target (guards the Flutter failure). Real IME
|
||||||
|
and real screen readers are operator checks (O6).
|
||||||
|
- **Prior art:** R-T §2-3 as above; EditContext is Chrome-only (MDN, R-T §3) so it
|
||||||
|
is not the base path; `egui` web and Flutter web **[read]**; Slint web has no
|
||||||
|
accessibility and is not recommended for general web apps (R-T §2) **[read]** (the
|
||||||
|
failure this piece exists to avoid). Confidence medium: no Taffy+AccessKit
|
||||||
|
web combination exists in the sources read (R-T Gaps), so 11b is first of its
|
||||||
|
kind for this stack.
|
||||||
|
|
||||||
|
### Piece 12: thing-mesh (the CultMesh adapters)
|
||||||
|
|
||||||
|
- **Owner:** `thing-mesh`: `StatePort` and a discovery client over CultMesh/CultNet
|
||||||
|
and CultCache (the client is a port: Thing's contract has no advertisement of its own, `advertisement-owner`); the outbound invocation sender; the only crate with a transport
|
||||||
|
dependency.
|
||||||
|
- **Invariants:** a `StatePort` never returns `serde_json::Value` or an untyped
|
||||||
|
blob (P3); decode runs through the contract types and refuses on error
|
||||||
|
(`Change::Refused`), never a silently-dropped update; subscription uses the mesh's
|
||||||
|
own mechanism, never a poll loop (BD9 dies); the sender sets the caller identity
|
||||||
|
from the transport session and has no API to override it; decode needs no special thread once Eve pins CultLib `bbb98eaf`, which
|
||||||
|
carries `cultlib-gaps:follow_up:decode-stack-safety` (Fixed); until that pin
|
||||||
|
merges, decode runs on a thread with the stack it needs (P20).
|
||||||
|
- **Test:** pipeline smoke: a real CultMesh in-process loopback publishes
|
||||||
|
`f01`'s state and a document; core with `thing-mesh` shows it; then a hostile
|
||||||
|
record (unknown arm) yields `Change::Refused`; an invocation sent through the
|
||||||
|
sender arrives at a fake provider with the transport's identity and not any value
|
||||||
|
the core supplied. End-to-end (per Verse contract): later, with Odin's discovery.
|
||||||
|
- **Prior art:** the doctrine itself (CultMesh is the state substrate;
|
||||||
|
`doctrine/gamecult.md`); service registries are not owned by the UI toolkit
|
||||||
|
(R-K §3: Consul, Kubernetes Services **[background]**; Teams manifests vs cards
|
||||||
|
**[background]**). Confidence high on shape, unknown on the CultMesh API surface
|
||||||
|
it must wrap: that API is read when the cut is specced (O4).
|
||||||
|
|
||||||
|
### Piece 13: consumer ports (template)
|
||||||
|
|
||||||
|
One `cut_spec` per consumer, each carrying its rename (T, E1-E7 in
|
||||||
|
`thing-campaign.md`) and deleting its Thing 1 path in the same cut. Order per map
|
||||||
|
cut 5 (Odin, VoidBot, Ghostlight+Heimdall, Muninn/sleipnir, weksa, Stonks, Vili,
|
||||||
|
Gjallar, StreamPixels, gamecult-ops, CultLib), with cutover shape per
|
||||||
|
`thing2:ruling:port-cutover`: live consumers cut over one at a time, never all at
|
||||||
|
once.
|
||||||
|
|
||||||
|
Rulings that shape every port:
|
||||||
|
|
||||||
|
- **Naming and wire.** The eve-to-thing wire rename is frozen and folded into Thing
|
||||||
|
2.0; no wire, window or prose rename lands apart from a port. Thing 2.0 adopts
|
||||||
|
rename table T and edge table E1-E7 as its naming rule, so surviving kinds are
|
||||||
|
born `gamecult.thing.*` (`thing:ruling:wire-rename-freeze-fold`).
|
||||||
|
- **No compatibility ids.** No `CompatibleSchemaIds` on any renamed type. An
|
||||||
|
Eve-typed store is deleted and rebuilt by its daemon, conformance packs are
|
||||||
|
re-exported under thing ids, and a store found to be truth stops its cut as a
|
||||||
|
fork (`thing:ruling:operator-compat-rebuild`). A port therefore carries a
|
||||||
|
rebuild step, not a reader of old ids.
|
||||||
|
- **No new Eve surfaces.** Thing, formerly Eve, is deprecated; every new surface
|
||||||
|
waits for Thing 2.0 (`thing2:ruling:surfaces-wait-for-thing2`). Operator
|
||||||
|
dashboards are quarantined (parked tag, removed from main and the build) and
|
||||||
|
rebuilt on Thing 2 by follow-ups, e.g. `thing2:follow_up:ymir-operator-view-on-thing2`,
|
||||||
|
`weksa-`, `mimir-`, `muninn-operator-view-on-thing2`
|
||||||
|
(`thing2:ruling:eve-dashboards-quarantined-2`). Product UIs are decided case by
|
||||||
|
case: `Mimir.EveSensorReceiver` and the Pitch page's visual-novel component are
|
||||||
|
frozen until Thing 2, neither extended nor removed
|
||||||
|
(`thing2:ruling:mimir-sensor-receiver-frozen`, `thing2:ruling:pitch-component-frozen`).
|
||||||
|
- **Discovery is not Thing's.** A port reads the provider advertisement through the
|
||||||
|
`thing-mesh` port, not through a Thing-owned kind (`thing2:ruling:advertisement-owner`).
|
||||||
|
Until the owner lands (`thing2:follow_up:discovery-owner-campaign`), one adapter
|
||||||
|
over today's `gamecult.eve.provider_advertisement.v1` serves the port and is
|
||||||
|
deleted when the owner's typed advertisement arrives.
|
||||||
|
- **Repo set.** The code home is the Eve repo renamed Thing; Unity and Flutter
|
||||||
|
backends get their own repos only when a live consumer needs one
|
||||||
|
(`thing2:ruling:code-home`). The campaign waits for `cut-campaign-repos`, then
|
||||||
|
target r2 names the 13 repos before the first port
|
||||||
|
(`thing2:ruling:campaign-repo-limit`). The six retired family repos are archived
|
||||||
|
under their Eve names (`thing2:ruling:retired-repo-names`).
|
||||||
|
|
||||||
|
**Port-list gap.** gamecult-site's Thing 1 surface is tracked in
|
||||||
|
`void-body:follow_up:site-eve-present-tense` (Void's mind; folded there by
|
||||||
|
`thing2:resolution:follow_up.site-thing1-surface.n1`), and its Pitch component is
|
||||||
|
frozen until Thing 2 (`thing2:ruling:pitch-component-frozen`). The repo count
|
||||||
|
stays 13.
|
||||||
|
|
||||||
|
The template (every port cut has the same spec skeleton, so Soul can run the same
|
||||||
|
falsifications):
|
||||||
|
|
||||||
|
1. Fixture first: the consumer's current surface rebuilt as a Thing Script document
|
||||||
|
through its language package, loaded into `thing-testkit`, geometry-golden'd.
|
||||||
|
2. Deletes: its Thing 1 publisher path and every `gamecult.eve.*` reader/writer
|
||||||
|
(exact paths from the census, to `file:line`).
|
||||||
|
3. Commands: each existing command becomes a `CommandDecl` and a handler
|
||||||
|
returning an `Outcome` through the package (no state-as-string, M3).
|
||||||
|
4. Test: the consumer's own suite plus one pipeline smoke that renders the
|
||||||
|
consumer's real surface headlessly through core and asserts the geometry golden
|
||||||
|
and the command round-trip. Operator check: view it in the TUI/web.
|
||||||
|
5. Negative grep: no `gamecult.eve` and no `eve-browser-lowering` imports remain.
|
||||||
|
- **Prior art:** expand/contract (parallel change) and strangler-fig, with the
|
||||||
|
caveat in R-K §4 that Thing 2 kinds are new kinds not renames, so an aggregator
|
||||||
|
reads two kinds, not one under two ids **[read]**. Confidence high on the
|
||||||
|
template, per-consumer specs owe their own census read.
|
||||||
|
|
||||||
|
### Piece 14: retirement
|
||||||
|
|
||||||
|
Delete Thing 1's tree from the kernel repo after the last port. Test: negative
|
||||||
|
greps for `gamecult.eve`, `eve-browser-lowering`, `packages/eve-contracts`,
|
||||||
|
`web/eve-dsl.js`; workspace builds with the directories gone; README front door
|
||||||
|
(`doctrine`: first screen true) rewritten; Idunn targets (P15) re-pointed. Soul
|
||||||
|
pass before the tag.
|
||||||
|
|
||||||
|
## 4. What every cut's Soul pass attacks (derived, not new)
|
||||||
|
|
||||||
|
Rules M1-M10 are the checklist; in addition the shared failure shapes from this
|
||||||
|
spec: (i) a backend that grows layout, text or focus (compare dependency trees and
|
||||||
|
public fns); (ii) a decode refusal that reads as absence; (iii) a rule held by a
|
||||||
|
constructor but skipped by decode (the contract's P18 lesson, now applied to
|
||||||
|
`CommandInvocation` and results received by core); (iv) a golden re-blessed to
|
||||||
|
match a bug (Soul reruns generation on a clean checkout and diffs); (v) an `Embed`
|
||||||
|
or placeholder that silently drops.
|
||||||
|
|
||||||
|
## 5. Decisions made here (summary)
|
||||||
|
|
||||||
|
| ID | Decision | Confidence |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| D1 | One `thing-core` crate with modules; six crates in total | medium-high |
|
||||||
|
| D2 | Nine-variant closed render-command list | medium |
|
||||||
|
| D3 | Closed diagnostics enum drives placeholders, logs, a11y and tests | high |
|
||||||
|
| D4 | Byte-compared binary render and geometry goldens, `bless` task | medium |
|
||||||
|
| D5 | Invocation lifecycle with core-only `Malformed` and `TimedOut` | medium-high |
|
||||||
|
| D6 | Cell widths pinned to a `unicode-width` version in goldens | medium |
|
||||||
|
| D7 | One focus owner in core, id-keyed, modal trap | medium-high |
|
||||||
|
| D8 | (see O7) edit history scope | open |
|
||||||
|
| D9 | Web draws through canvas 2D first | medium |
|
||||||
|
|
||||||
|
## 6. Open: what this spec could not decide
|
||||||
|
|
||||||
|
Each with a recommendation; none blocks cuts 1-8.
|
||||||
|
|
||||||
|
- **O1. Parley (and AccessKit types) on `wasm32`.** No source read establishes
|
||||||
|
that Parley + fontique build and perform for wasm; GPUI web has its own text
|
||||||
|
system and Slint web uses femtovg, not Parley. Recommendation: one half-day
|
||||||
|
probe (build `thing-core` text module to wasm, shape `f12`) before cut 9a is
|
||||||
|
specced; the fallback is browser `Canvas.measureText` behind the `Measure` trait,
|
||||||
|
which weakens "core owns text" for the web only. `thing:ruling:thing2-thing-owns-text`
|
||||||
|
already puts shaping in core, so taking the fallback contradicts it and needs a
|
||||||
|
new operator ruling. Needs: the probe.
|
||||||
|
- **O2. Glyph rasterization path** (canvas 2D, Slug, Vello family). Partly ruled:
|
||||||
|
rasterization is backend-private and the first GPU backend picks Vello or a Slug
|
||||||
|
port by measurement (`thing:ruling:thing2-thing-owns-text`). Still open:
|
||||||
|
Recommendation: canvas 2D now; revisit after a measured frame budget (O10).
|
||||||
|
Needs: operator word on whether GPU glyphs gate web cutover.
|
||||||
|
- **O3. The exact command list**, in particular whether `Plot` lowers to
|
||||||
|
`Polyline`/`Polygon` in core or becomes an `Embed`. Recommendation: lower in core
|
||||||
|
(consumers expect charts; an `Embed` makes every host write one). Needs: a
|
||||||
|
decision on D2 from the spec's reviewer.
|
||||||
|
- **O4. CultMesh/CultNet surface for `thing-mesh` and how a browser reaches it**
|
||||||
|
(direct WebTransport/QUIC, or a gateway). Not read in this pass. Who owns the
|
||||||
|
provider advertisement is ruled (`thing2:ruling:advertisement-owner`: discovery
|
||||||
|
leaves Thing, its owner is CultMesh or Odin, follow-up
|
||||||
|
`thing2:follow_up:discovery-owner-campaign`); the transport question stays open.
|
||||||
|
Needs: a short
|
||||||
|
Eyes pass over `cultmesh-ts`/`cultnet-ts` in CultLib before cut 12 and 11c are
|
||||||
|
specced.
|
||||||
|
- **O5. Defaults that are guesses:** invocation timeout 15 s, frame budget, scrollbar
|
||||||
|
style, overlay z policy. Recommendation: land as `Config` with these defaults and
|
||||||
|
record a follow-up to measure.
|
||||||
|
- **O6. What only the operator can check:** real IME on Windows/macOS/iOS/Android
|
||||||
|
browsers, a real screen reader on the web mirror. No CI substitute exists; the
|
||||||
|
spec names them as operator checks at cut 11 and at each consumer cutover.
|
||||||
|
- **O7. Editing scope (D8):** undo/redo, clipboard, drag-select auto-scroll in 9b.
|
||||||
|
Recommendation: undo and clipboard are in (a general library's reasonable
|
||||||
|
expectation; clipboard goes through `HostEffects`), word/line navigation in,
|
||||||
|
rich text out. Needs: nothing but a go.
|
||||||
|
- **O8. Locale in `Format`.** Recommendation: a host-supplied `Locale` input,
|
||||||
|
default `en`, formats stay a closed set.
|
||||||
|
- **O9. Diagnostics added by later cuts** (`AssetMissing`, `NoAccessibleName`)
|
||||||
|
extend D3's list; confirm the list stays closed and versioned with core.
|
||||||
|
- **O10. Performance budgets** (frame time at 1k and 10k nodes, wasm size). No
|
||||||
|
number was measured anywhere in the sources read; Clay's "microsecond layout"
|
||||||
|
claim has no table (R-F §2.1) and the Taffy README numbers are layout-only
|
||||||
|
(R-F §2.2). Recommendation: cut 6 records the first measured numbers in a
|
||||||
|
bench fixture, and budgets are set from them rather than guessed.
|
||||||
|
- **O11. Thing Script text syntax: closed by ruling, no open question.**
|
||||||
|
`thing2:ruling:thing-script-form` (InForce, ruled 2026-10-10, choice
|
||||||
|
`document-authority-text-later`; operator: "all recommended") says the typed
|
||||||
|
document is Thing Script's one authority, and a `.thingscript` text syntax comes
|
||||||
|
later, parsed only by core. Consequences held in this spec: nothing but the typed
|
||||||
|
document is authoritative; no language package or host parses a text form (packages
|
||||||
|
build the typed document and nothing else; tooling reaches the one parser through core, which
|
||||||
|
the question's recommendation expects to expose via wasm); when the text form is cut
|
||||||
|
it lands in `thing-core` next to `resolve` and produces a `SurfaceDocument`, so
|
||||||
|
`resolve` still sees only the typed document, and its tests are round-trip
|
||||||
|
(text to document to text) plus the existing `resolve` suite on the parsed
|
||||||
|
output. It has no cut yet and sits after cut 3; the map's cut order is not
|
||||||
|
changed here.
|
||||||
|
- **O12. Prior-art standard.** This spec reads "prior-art sources cited" as: every
|
||||||
|
decision names the sources and a confidence, with [read]/[background] honesty.
|
||||||
|
Open: whether the standard also fixes a format, a minimum source count or a
|
||||||
|
required venue; the tags above are where to retrofit it.
|
||||||
|
- **O13. Where the repo's unmerged contract-ts / contract-cs branches stand.**
|
||||||
|
Ruled as far as the mind records: the live specs are `cut-contract-ts.r3` and
|
||||||
|
`-cs.r3`, which wait on contract-cs h2 being admitted, held by Soul and merged
|
||||||
|
by Self. This spec did not re-verify branch heads; that check belongs to the
|
||||||
|
merging Self.
|
||||||
|
|
||||||
|
## 7. Substrate gaps felt writing this spec
|
||||||
|
|
||||||
|
- Resolved: the `thing2` and `thing` campaigns are now readable
|
||||||
|
(`huginn rulings thing2 thing`, `huginn view <id>`), and this spec was checked
|
||||||
|
against them on 2026-11-10. Rulings are now cited by id. Remaining gap: the
|
||||||
|
`huginn rulings` header line truncates the choice, so each ruling needs a `view`.
|
||||||
|
- No published golden-command suite exists to copy (D4); the harness is ours to
|
||||||
|
build and is itself a cut-1 testkit deliverable.
|
||||||
|
|
@ -473,6 +473,10 @@ code fails it.
|
||||||
|
|
||||||
## Cut order (deliverables)
|
## Cut order (deliverables)
|
||||||
|
|
||||||
|
Per-piece contracts, the build graph with sizes, a test per piece and the prior-art
|
||||||
|
citations for each choice are in `docs/thing2-build-spec.md`; this list is the
|
||||||
|
summary.
|
||||||
|
|
||||||
0. **`stale-voidbot-cleanup`** (Eve main, any time): spec
|
0. **`stale-voidbot-cleanup`** (Eve main, any time): spec
|
||||||
`thing2:cut_spec:cut-stale-voidbot-cleanup.r1`. Owned here by
|
`thing2:cut_spec:cut-stale-voidbot-cleanup.r1`. Owned here by
|
||||||
`thing:follow_up:stale-voidbot-cleanup-on-main`.
|
`thing:follow_up:stale-voidbot-cleanup-on-main`.
|
||||||
|
|
@ -494,7 +498,7 @@ code fails it.
|
||||||
(`thing2:verdict:cut-contract-rs.s1`, `.s2`). The siblings are mapped
|
(`thing2:verdict:cut-contract-rs.s1`, `.s2`). The siblings are mapped
|
||||||
against `6ae2da0` and run side by side, touching only their own package and
|
against `6ae2da0` and run side by side, touching only their own package and
|
||||||
one `.gitignore` insertion each, at separate anchors:
|
one `.gitignore` insertion each, at separate anchors:
|
||||||
`thing2:cut_spec:cut-contract-cs.r2` and `thing2:cut_spec:cut-contract-ts.r2`.
|
`thing2:cut_spec:cut-contract-cs.r3` and `thing2:cut_spec:cut-contract-ts.r3`.
|
||||||
Waiting, one line each:
|
Waiting, one line each:
|
||||||
- Cross-runtime store check, after both siblings land: the C# package opens
|
- Cross-runtime store check, after both siblings land: the C# package opens
|
||||||
a store the TS package wrote and the reverse, which proves the catalog
|
a store the TS package wrote and the reverse, which proves the catalog
|
||||||
|
|
|
||||||
71
packages/thing-contract/package-lock.json
generated
71
packages/thing-contract/package-lock.json
generated
|
|
@ -1,71 +0,0 @@
|
||||||
{
|
|
||||||
"name": "@gamecult/thing-contract",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"lockfileVersion": 3,
|
|
||||||
"requires": true,
|
|
||||||
"packages": {
|
|
||||||
"": {
|
|
||||||
"name": "@gamecult/thing-contract",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@gamecult/cultcache-ts": "file:../../../CultLib/packages/cultcache-ts"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/node": "^24.0.0",
|
|
||||||
"typescript": "^5.9.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"../../../CultLib/packages/cultcache-ts": {
|
|
||||||
"name": "@gamecult/cultcache-ts",
|
|
||||||
"version": "0.14.0",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@msgpack/msgpack": "^3.1.3",
|
|
||||||
"zod": "^3.25.76"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/node": "^24.0.0",
|
|
||||||
"typescript": "^5.9.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=20"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@gamecult/cultcache-ts": {
|
|
||||||
"resolved": "../../../CultLib/packages/cultcache-ts",
|
|
||||||
"link": true
|
|
||||||
},
|
|
||||||
"node_modules/@types/node": {
|
|
||||||
"version": "24.19.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.19.2.tgz",
|
|
||||||
"integrity": "sha512-93d49wCWJkCyN87MxLpNN6KXPCwFw7bVUg79mGUV1OS40JGWwVCr8n61DXCSqz7CV6/VfPkb7xec7uP2M+QHWQ==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"undici-types": ">=7.24.0 <7.24.7"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/typescript": {
|
|
||||||
"version": "5.9.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
|
||||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "Apache-2.0",
|
|
||||||
"bin": {
|
|
||||||
"tsc": "bin/tsc",
|
|
||||||
"tsserver": "bin/tsserver"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=14.17"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/undici-types": {
|
|
||||||
"version": "7.24.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.24.6.tgz",
|
|
||||||
"integrity": "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
{
|
|
||||||
"name": "@gamecult/thing-contract",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"description": "The gamecult.thing.* wire types and codecs for TypeScript, held byte for byte to the Rust crate's goldens.",
|
|
||||||
"type": "module",
|
|
||||||
"main": "dist/index.js",
|
|
||||||
"types": "dist/index.d.ts",
|
|
||||||
"exports": {
|
|
||||||
".": {
|
|
||||||
"types": "./dist/index.d.ts",
|
|
||||||
"import": "./dist/index.js"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"dist"
|
|
||||||
],
|
|
||||||
"scripts": {
|
|
||||||
"build": "tsc -p tsconfig.json",
|
|
||||||
"test": "tsc -p tsconfig.json && tsc -p tsconfig.test.json && node --test dist-test/test/*.test.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@gamecult/cultcache-ts": "file:../../../CultLib/packages/cultcache-ts"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/node": "^24.0.0",
|
|
||||||
"typescript": "^5.9.0"
|
|
||||||
},
|
|
||||||
"license": "MIT"
|
|
||||||
}
|
|
||||||
|
|
@ -1,511 +0,0 @@
|
||||||
// One codec per type of crates/thing-contract, built from cultcache-ts's slots, union, list, nullable and lazy at the
|
|
||||||
// crate's slot and arm keys. Nothing here encodes or decodes by hand, declares a slot default, or checks an arm: the
|
|
||||||
// library's codecs refuse an unknown arm or a missing slot, and domain.ts holds the five domains.
|
|
||||||
//
|
|
||||||
// Every slots and union codec is named GameCult.Thing.Contract.<RustName>, the reference's full type name, because a
|
|
||||||
// store's schema catalog carries the type name of each document slot and the reference compares them.
|
|
||||||
//
|
|
||||||
// Definition order is dependency order. The one cycle is Node (through Box, Button, Overlay, Repeat and Slot), and it
|
|
||||||
// closes at slot level with `lazy`, never inside a union's arm table.
|
|
||||||
import { codecs } from "@gamecult/cultcache-ts";
|
|
||||||
import type { Codec } from "@gamecult/cultcache-ts";
|
|
||||||
|
|
||||||
import { channel, count, segment, version } from "./domain.js";
|
|
||||||
import type * as T from "./types.js";
|
|
||||||
|
|
||||||
const { string, boolean, float64, bytes, list, nullable, lazy, unit } = codecs;
|
|
||||||
|
|
||||||
const named = (rustName: string): string => `GameCult.Thing.Contract.${rustName}`;
|
|
||||||
|
|
||||||
// A union codec reads nil as null. A required union slot is typed without the null; a nil there is CultLib's
|
|
||||||
// nullable-reference rule (the reference reads nil too), not this package's.
|
|
||||||
const required = <TValue>(codec: Codec<TValue | null>): Codec<TValue> => codec as Codec<TValue>;
|
|
||||||
|
|
||||||
// source.rs
|
|
||||||
export const paramName = codecs.slots<T.ParamName>({ 0: ["name", string] }, named("ParamName"));
|
|
||||||
export const textLiteral = codecs.slots<T.TextLiteral>({ 0: ["value", string] }, named("TextLiteral"));
|
|
||||||
export const numberLiteral = codecs.slots<T.NumberLiteral>({ 0: ["value", float64] }, named("NumberLiteral"));
|
|
||||||
export const boolLiteral = codecs.slots<T.BoolLiteral>({ 0: ["value", boolean] }, named("BoolLiteral"));
|
|
||||||
|
|
||||||
export const memberName = codecs.slots<T.MemberName>({ 0: ["name", string] }, named("MemberName"));
|
|
||||||
export const memberIndex = codecs.slots<T.MemberIndex>({ 0: ["index", count] }, named("MemberIndex"));
|
|
||||||
export const memberStep = required(
|
|
||||||
codecs.union<T.MemberStep>("MemberStep", { 0: ["Name", memberName], 1: ["Index", memberIndex] }, named("MemberStep")),
|
|
||||||
);
|
|
||||||
export const memberPath = codecs.slots<T.MemberPath>({ 0: ["steps", list(memberStep)] }, named("MemberPath"));
|
|
||||||
|
|
||||||
export const numberFormat = codecs.slots<T.NumberFormat>(
|
|
||||||
{ 0: ["precision", count], 1: ["percent", boolean], 2: ["unit", nullable(string)] },
|
|
||||||
named("NumberFormat"),
|
|
||||||
);
|
|
||||||
export const affixFormat = codecs.slots<T.AffixFormat>({ 0: ["prefix", string], 1: ["suffix", string] }, named("AffixFormat"));
|
|
||||||
export const format = required(
|
|
||||||
codecs.union<T.Format>(
|
|
||||||
"Format",
|
|
||||||
{ 0: ["Number", numberFormat], 1: ["Duration", unit], 2: ["Timestamp", unit], 3: ["Affix", affixFormat] },
|
|
||||||
named("Format"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
export const stateRef = codecs.slots<T.StateRef>(
|
|
||||||
{ 0: ["provider", nullable(string)], 1: ["schema", string], 2: ["key", string] },
|
|
||||||
named("StateRef"),
|
|
||||||
);
|
|
||||||
export const stateSource = required(
|
|
||||||
codecs.union<T.StateSource>("StateSource", { 0: ["Record", stateRef], 1: ["Item", unit] }, named("StateSource")),
|
|
||||||
);
|
|
||||||
export const bind = codecs.slots<T.Bind>(
|
|
||||||
{ 0: ["source", stateSource], 1: ["member", memberPath], 2: ["format", nullable(format)] },
|
|
||||||
named("Bind"),
|
|
||||||
);
|
|
||||||
|
|
||||||
export const textSource = required(
|
|
||||||
codecs.union<T.TextSource>(
|
|
||||||
"TextSource",
|
|
||||||
{ 0: ["Literal", textLiteral], 1: ["Bound", bind], 2: ["Param", paramName] },
|
|
||||||
named("TextSource"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
export const numberSource = required(
|
|
||||||
codecs.union<T.NumberSource>(
|
|
||||||
"NumberSource",
|
|
||||||
{ 0: ["Literal", numberLiteral], 1: ["Bound", bind], 2: ["Param", paramName] },
|
|
||||||
named("NumberSource"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
export const boolSource = required(
|
|
||||||
codecs.union<T.BoolSource>(
|
|
||||||
"BoolSource",
|
|
||||||
{ 0: ["Literal", boolLiteral], 1: ["Bound", bind], 2: ["Param", paramName] },
|
|
||||||
named("BoolSource"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
export const recordsSource = codecs.slots<T.RecordsSource>(
|
|
||||||
{ 0: ["provider", nullable(string)], 1: ["schema", string], 2: ["keyPrefix", string] },
|
|
||||||
named("RecordsSource"),
|
|
||||||
);
|
|
||||||
export const collectionSource = required(
|
|
||||||
codecs.union<T.CollectionSource>(
|
|
||||||
"CollectionSource",
|
|
||||||
{ 0: ["Records", recordsSource], 1: ["Member", bind], 2: ["Param", paramName] },
|
|
||||||
named("CollectionSource"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// style.rs
|
|
||||||
export const scalar = codecs.slots<T.Scalar>({ 0: ["value", float64] }, named("Scalar"));
|
|
||||||
export const dimension = required(
|
|
||||||
codecs.union<T.Dimension>(
|
|
||||||
"Dimension",
|
|
||||||
{ 0: ["Px", scalar], 1: ["Percent", scalar], 2: ["Fr", scalar], 3: ["Auto", unit], 4: ["Content", unit] },
|
|
||||||
named("Dimension"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
export const size2 = codecs.slots<T.Size2>({ 0: ["width", dimension], 1: ["height", dimension] }, named("Size2"));
|
|
||||||
export const edges = codecs.slots<T.Edges>(
|
|
||||||
{ 0: ["top", dimension], 1: ["right", dimension], 2: ["bottom", dimension], 3: ["left", dimension] },
|
|
||||||
named("Edges"),
|
|
||||||
);
|
|
||||||
export const display = required(
|
|
||||||
codecs.union<T.Display>("Display", { 0: ["Flex", unit], 1: ["Grid", unit], 2: ["Block", unit] }, named("Display")),
|
|
||||||
);
|
|
||||||
export const direction = required(
|
|
||||||
codecs.union<T.Direction>(
|
|
||||||
"Direction",
|
|
||||||
{ 0: ["Row", unit], 1: ["Column", unit], 2: ["RowReverse", unit], 3: ["ColumnReverse", unit] },
|
|
||||||
named("Direction"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
export const wrap = required(
|
|
||||||
codecs.union<T.Wrap>("Wrap", { 0: ["NoWrap", unit], 1: ["Wrap", unit], 2: ["WrapReverse", unit] }, named("Wrap")),
|
|
||||||
);
|
|
||||||
export const position = required(
|
|
||||||
codecs.union<T.Position>("Position", { 0: ["Relative", unit], 1: ["Absolute", unit] }, named("Position")),
|
|
||||||
);
|
|
||||||
export const overflow = required(
|
|
||||||
codecs.union<T.Overflow>("Overflow", { 0: ["Visible", unit], 1: ["Clip", unit], 2: ["Scroll", unit] }, named("Overflow")),
|
|
||||||
);
|
|
||||||
export const itemAlign = required(
|
|
||||||
codecs.union<T.ItemAlign>(
|
|
||||||
"ItemAlign",
|
|
||||||
{
|
|
||||||
0: ["Auto", unit],
|
|
||||||
1: ["Start", unit],
|
|
||||||
2: ["End", unit],
|
|
||||||
3: ["Center", unit],
|
|
||||||
4: ["Stretch", unit],
|
|
||||||
5: ["Baseline", unit],
|
|
||||||
},
|
|
||||||
named("ItemAlign"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
export const contentAlign = required(
|
|
||||||
codecs.union<T.ContentAlign>(
|
|
||||||
"ContentAlign",
|
|
||||||
{
|
|
||||||
0: ["Auto", unit],
|
|
||||||
1: ["Start", unit],
|
|
||||||
2: ["End", unit],
|
|
||||||
3: ["Center", unit],
|
|
||||||
4: ["Stretch", unit],
|
|
||||||
5: ["SpaceBetween", unit],
|
|
||||||
6: ["SpaceAround", unit],
|
|
||||||
7: ["SpaceEvenly", unit],
|
|
||||||
},
|
|
||||||
named("ContentAlign"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
export const boxStyle = codecs.slots<T.BoxStyle>(
|
|
||||||
{
|
|
||||||
0: ["display", display],
|
|
||||||
1: ["direction", direction],
|
|
||||||
2: ["wrap", wrap],
|
|
||||||
3: ["gap", size2],
|
|
||||||
4: ["padding", edges],
|
|
||||||
5: ["margin", edges],
|
|
||||||
6: ["size", size2],
|
|
||||||
7: ["minSize", size2],
|
|
||||||
8: ["maxSize", size2],
|
|
||||||
9: ["position", position],
|
|
||||||
10: ["inset", edges],
|
|
||||||
11: ["overflow", overflow],
|
|
||||||
12: ["alignItems", itemAlign],
|
|
||||||
13: ["alignSelf", itemAlign],
|
|
||||||
14: ["alignContent", contentAlign],
|
|
||||||
15: ["justifyContent", contentAlign],
|
|
||||||
16: ["grow", float64],
|
|
||||||
17: ["shrink", float64],
|
|
||||||
18: ["basis", dimension],
|
|
||||||
19: ["gridColumns", list(dimension)],
|
|
||||||
20: ["gridRows", list(dimension)],
|
|
||||||
},
|
|
||||||
named("BoxStyle"),
|
|
||||||
);
|
|
||||||
export const themeToken = codecs.slots<T.ThemeToken>({ 0: ["name", string] }, named("ThemeToken"));
|
|
||||||
export const rgba = codecs.slots<T.Rgba>(
|
|
||||||
{ 0: ["r", channel], 1: ["g", channel], 2: ["b", channel], 3: ["a", channel] },
|
|
||||||
named("Rgba"),
|
|
||||||
);
|
|
||||||
export const colorRef = required(
|
|
||||||
codecs.union<T.ColorRef>("ColorRef", { 0: ["Token", themeToken], 1: ["Rgba", rgba] }, named("ColorRef")),
|
|
||||||
);
|
|
||||||
export const border = codecs.slots<T.Border>({ 0: ["color", colorRef], 1: ["width", float64] }, named("Border"));
|
|
||||||
export const paint = codecs.slots<T.Paint>(
|
|
||||||
{ 0: ["background", nullable(colorRef)], 1: ["border", nullable(border)], 2: ["radius", float64] },
|
|
||||||
named("Paint"),
|
|
||||||
);
|
|
||||||
export const role = required(
|
|
||||||
codecs.union<T.Role>(
|
|
||||||
"Role",
|
|
||||||
{
|
|
||||||
0: ["Group", unit],
|
|
||||||
1: ["Region", unit],
|
|
||||||
2: ["List", unit],
|
|
||||||
3: ["ListItem", unit],
|
|
||||||
4: ["Heading", unit],
|
|
||||||
5: ["Dialog", unit],
|
|
||||||
6: ["Toolbar", unit],
|
|
||||||
},
|
|
||||||
named("Role"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// command.rs
|
|
||||||
export const commandDecl = codecs.slots<T.CommandDecl>(
|
|
||||||
{ 0: ["id", string], 1: ["payloadSchema", string], 2: ["captures", list(string)], 3: ["confirm", nullable(string)] },
|
|
||||||
named("CommandDecl"),
|
|
||||||
);
|
|
||||||
export const commandIdRef = codecs.slots<T.CommandIdRef>({ 0: ["id", string] }, named("CommandIdRef"));
|
|
||||||
export const commandRef = required(
|
|
||||||
codecs.union<T.CommandRef>("CommandRef", { 0: ["Id", commandIdRef], 1: ["Param", paramName] }, named("CommandRef")),
|
|
||||||
);
|
|
||||||
export const recordPayload = codecs.slots<T.RecordPayload>(
|
|
||||||
{ 0: ["schema", string], 1: ["bytes", bytes] },
|
|
||||||
named("RecordPayload"),
|
|
||||||
);
|
|
||||||
export const textValue = codecs.slots<T.TextValue>({ 0: ["value", string] }, named("TextValue"));
|
|
||||||
export const numberValue = codecs.slots<T.NumberValue>({ 0: ["value", float64] }, named("NumberValue"));
|
|
||||||
export const boolValue = codecs.slots<T.BoolValue>({ 0: ["value", boolean] }, named("BoolValue"));
|
|
||||||
export const choiceValue = codecs.slots<T.ChoiceValue>({ 0: ["value", string] }, named("ChoiceValue"));
|
|
||||||
export const inputValue = required(
|
|
||||||
codecs.union<T.InputValue>(
|
|
||||||
"InputValue",
|
|
||||||
{ 0: ["Text", textValue], 1: ["Number", numberValue], 2: ["Bool", boolValue], 3: ["Choice", choiceValue] },
|
|
||||||
named("InputValue"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
export const capturedInput = codecs.slots<T.CapturedInput>(
|
|
||||||
{ 0: ["node", string], 1: ["value", inputValue] },
|
|
||||||
named("CapturedInput"),
|
|
||||||
);
|
|
||||||
export const commandInvocation = codecs.slots<T.CommandInvocation>(
|
|
||||||
{
|
|
||||||
0: ["invocationId", string],
|
|
||||||
1: ["surfaceKey", string],
|
|
||||||
2: ["surfaceVersion", version],
|
|
||||||
3: ["command", string],
|
|
||||||
4: ["payload", recordPayload],
|
|
||||||
5: ["captured", list(capturedInput)],
|
|
||||||
6: ["client", string],
|
|
||||||
7: ["issuedAt", string],
|
|
||||||
8: ["delegation", nullable(string)],
|
|
||||||
},
|
|
||||||
named("CommandInvocation"),
|
|
||||||
);
|
|
||||||
|
|
||||||
// result.rs
|
|
||||||
export const pendingOutcome = codecs.slots<T.PendingOutcome>({ 0: ["message", string] }, named("PendingOutcome"));
|
|
||||||
export const openSurfaceEffect = codecs.slots<T.OpenSurfaceEffect>({ 0: ["key", string] }, named("OpenSurfaceEffect"));
|
|
||||||
export const openExternalEffect = codecs.slots<T.OpenExternalEffect>(
|
|
||||||
{ 0: ["url", string], 1: ["resume", commandRef] },
|
|
||||||
named("OpenExternalEffect"),
|
|
||||||
);
|
|
||||||
export const effect = required(
|
|
||||||
codecs.union<T.Effect>(
|
|
||||||
"Effect",
|
|
||||||
{ 0: ["OpenSurface", openSurfaceEffect], 1: ["OpenExternal", openExternalEffect] },
|
|
||||||
named("Effect"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
export const completedOutcome = codecs.slots<T.CompletedOutcome>(
|
|
||||||
{ 0: ["sourceVersion", nullable(version)], 1: ["clearDrafts", boolean], 2: ["effect", nullable(effect)] },
|
|
||||||
named("CompletedOutcome"),
|
|
||||||
);
|
|
||||||
export const deniedOutcome = codecs.slots<T.DeniedOutcome>(
|
|
||||||
{ 0: ["reason", string], 1: ["node", nullable(string)] },
|
|
||||||
named("DeniedOutcome"),
|
|
||||||
);
|
|
||||||
export const failedOutcome = codecs.slots<T.FailedOutcome>({ 0: ["reason", string] }, named("FailedOutcome"));
|
|
||||||
export const outcome = required(
|
|
||||||
codecs.union<T.Outcome>(
|
|
||||||
"Outcome",
|
|
||||||
{ 0: ["Pending", pendingOutcome], 1: ["Completed", completedOutcome], 2: ["Denied", deniedOutcome], 3: ["Failed", failedOutcome] },
|
|
||||||
named("Outcome"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// node.rs
|
|
||||||
export const nodeCommon = codecs.slots<T.NodeCommon>(
|
|
||||||
{ 0: ["id", string], 1: ["visible", boolSource], 2: ["a11yLabel", nullable(textSource)] },
|
|
||||||
named("NodeCommon"),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Node closes its own cycle here and nowhere else.
|
|
||||||
export const node: Codec<T.Node> = lazy(() => nodeUnion);
|
|
||||||
|
|
||||||
export const boxNode = codecs.slots<T.BoxNode>(
|
|
||||||
{ 0: ["common", nodeCommon], 1: ["style", boxStyle], 2: ["paint", paint], 3: ["role", role], 4: ["children", list(node)] },
|
|
||||||
named("BoxNode"),
|
|
||||||
);
|
|
||||||
export const textNode = codecs.slots<T.TextNode>(
|
|
||||||
{
|
|
||||||
0: ["common", nodeCommon],
|
|
||||||
1: ["content", textSource],
|
|
||||||
2: ["styleToken", string],
|
|
||||||
3: ["wrap", boolean],
|
|
||||||
4: ["maxLines", nullable(count)],
|
|
||||||
5: ["selectable", boolean],
|
|
||||||
},
|
|
||||||
named("TextNode"),
|
|
||||||
);
|
|
||||||
export const imageFit = required(
|
|
||||||
codecs.union<T.ImageFit>(
|
|
||||||
"ImageFit",
|
|
||||||
{ 0: ["Contain", unit], 1: ["Cover", unit], 2: ["Fill", unit], 3: ["Unscaled", unit] },
|
|
||||||
named("ImageFit"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
export const imageNode = codecs.slots<T.ImageNode>(
|
|
||||||
{ 0: ["common", nodeCommon], 1: ["catalog", string], 2: ["asset", string], 3: ["fit", imageFit], 4: ["alt", textSource] },
|
|
||||||
named("ImageNode"),
|
|
||||||
);
|
|
||||||
export const buttonNode = codecs.slots<T.ButtonNode>(
|
|
||||||
{ 0: ["common", nodeCommon], 1: ["content", list(node)], 2: ["onActivate", commandRef], 3: ["enabled", boolSource] },
|
|
||||||
named("ButtonNode"),
|
|
||||||
);
|
|
||||||
export const toggleNode = codecs.slots<T.ToggleNode>(
|
|
||||||
{ 0: ["common", nodeCommon], 1: ["checked", boolSource], 2: ["onChange", commandRef] },
|
|
||||||
named("ToggleNode"),
|
|
||||||
);
|
|
||||||
export const sliderNode = codecs.slots<T.SliderNode>(
|
|
||||||
{
|
|
||||||
0: ["common", nodeCommon],
|
|
||||||
1: ["min", float64],
|
|
||||||
2: ["max", float64],
|
|
||||||
3: ["step", float64],
|
|
||||||
4: ["value", numberSource],
|
|
||||||
5: ["commit", commandRef],
|
|
||||||
},
|
|
||||||
named("SliderNode"),
|
|
||||||
);
|
|
||||||
export const inputKind = required(
|
|
||||||
codecs.union<T.InputKind>("InputKind", { 0: ["Text", unit], 1: ["Number", unit] }, named("InputKind")),
|
|
||||||
);
|
|
||||||
export const textInputNode = codecs.slots<T.TextInputNode>(
|
|
||||||
{
|
|
||||||
0: ["common", nodeCommon],
|
|
||||||
1: ["multiline", boolean],
|
|
||||||
2: ["inputKind", inputKind],
|
|
||||||
3: ["placeholder", textSource],
|
|
||||||
4: ["initial", textSource],
|
|
||||||
5: ["submit", commandRef],
|
|
||||||
},
|
|
||||||
named("TextInputNode"),
|
|
||||||
);
|
|
||||||
export const selectOption = codecs.slots<T.SelectOption>({ 0: ["value", string], 1: ["label", string] }, named("SelectOption"));
|
|
||||||
export const literalOptions = codecs.slots<T.LiteralOptions>({ 0: ["options", list(selectOption)] }, named("LiteralOptions"));
|
|
||||||
export const boundOptions = codecs.slots<T.BoundOptions>(
|
|
||||||
{ 0: ["collection", collectionSource], 1: ["valueMember", memberPath], 2: ["labelMember", memberPath] },
|
|
||||||
named("BoundOptions"),
|
|
||||||
);
|
|
||||||
export const optionList = required(
|
|
||||||
codecs.union<T.OptionList>("OptionList", { 0: ["Literal", literalOptions], 1: ["Bound", boundOptions] }, named("OptionList")),
|
|
||||||
);
|
|
||||||
export const selectNode = codecs.slots<T.SelectNode>(
|
|
||||||
{ 0: ["common", nodeCommon], 1: ["options", optionList], 2: ["value", bind], 3: ["onChange", commandRef] },
|
|
||||||
named("SelectNode"),
|
|
||||||
);
|
|
||||||
export const repeatNode = codecs.slots<T.RepeatNode>(
|
|
||||||
{ 0: ["common", nodeCommon], 1: ["collection", collectionSource], 2: ["keyMember", memberPath], 3: ["template", node] },
|
|
||||||
named("RepeatNode"),
|
|
||||||
);
|
|
||||||
export const anchorNode = codecs.slots<T.AnchorNode>({ 0: ["node", string] }, named("AnchorNode"));
|
|
||||||
export const anchor = required(
|
|
||||||
codecs.union<T.Anchor>("Anchor", { 0: ["Viewport", unit], 1: ["Node", anchorNode] }, named("Anchor")),
|
|
||||||
);
|
|
||||||
export const overlayNode = codecs.slots<T.OverlayNode>(
|
|
||||||
{
|
|
||||||
0: ["common", nodeCommon],
|
|
||||||
1: ["anchor", anchor],
|
|
||||||
2: ["modal", boolean],
|
|
||||||
3: ["dismiss", commandRef],
|
|
||||||
4: ["children", list(node)],
|
|
||||||
},
|
|
||||||
named("OverlayNode"),
|
|
||||||
);
|
|
||||||
export const plotMark = required(
|
|
||||||
codecs.union<T.PlotMark>("PlotMark", { 0: ["Line", unit], 1: ["Bar", unit], 2: ["Area", unit] }, named("PlotMark")),
|
|
||||||
);
|
|
||||||
export const plotNode = codecs.slots<T.PlotNode>(
|
|
||||||
{
|
|
||||||
0: ["common", nodeCommon],
|
|
||||||
1: ["series", bind],
|
|
||||||
2: ["mark", plotMark],
|
|
||||||
3: ["xMin", nullable(float64)],
|
|
||||||
4: ["xMax", nullable(float64)],
|
|
||||||
5: ["yMin", nullable(float64)],
|
|
||||||
6: ["yMax", nullable(float64)],
|
|
||||||
},
|
|
||||||
named("PlotNode"),
|
|
||||||
);
|
|
||||||
export const embedNode = codecs.slots<T.EmbedNode>(
|
|
||||||
{
|
|
||||||
0: ["common", nodeCommon],
|
|
||||||
1: ["slotKind", string],
|
|
||||||
2: ["slotId", string],
|
|
||||||
3: ["width", float64],
|
|
||||||
4: ["height", float64],
|
|
||||||
},
|
|
||||||
named("EmbedNode"),
|
|
||||||
);
|
|
||||||
export const compositionRef = codecs.slots<T.CompositionRef>(
|
|
||||||
{ 0: ["publisher", string], 1: ["name", segment], 2: ["version", version] },
|
|
||||||
named("CompositionRef"),
|
|
||||||
);
|
|
||||||
export const textArg = codecs.slots<T.TextArg>({ 0: ["value", string] }, named("TextArg"));
|
|
||||||
export const numberArg = codecs.slots<T.NumberArg>({ 0: ["value", float64] }, named("NumberArg"));
|
|
||||||
export const boolArg = codecs.slots<T.BoolArg>({ 0: ["value", boolean] }, named("BoolArg"));
|
|
||||||
export const collectionArg = codecs.slots<T.CollectionArg>({ 0: ["source", collectionSource] }, named("CollectionArg"));
|
|
||||||
export const commandArg = codecs.slots<T.CommandArg>({ 0: ["command", commandRef] }, named("CommandArg"));
|
|
||||||
export const slotArg = codecs.slots<T.SlotArg>({ 0: ["nodes", list(node)] }, named("SlotArg"));
|
|
||||||
export const argValue = required(
|
|
||||||
codecs.union<T.ArgValue>(
|
|
||||||
"ArgValue",
|
|
||||||
{
|
|
||||||
0: ["Text", textArg],
|
|
||||||
1: ["Number", numberArg],
|
|
||||||
2: ["Bool", boolArg],
|
|
||||||
3: ["Bind", bind],
|
|
||||||
4: ["Collection", collectionArg],
|
|
||||||
5: ["Command", commandArg],
|
|
||||||
6: ["Slot", slotArg],
|
|
||||||
},
|
|
||||||
named("ArgValue"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
export const arg = codecs.slots<T.Arg>({ 0: ["name", string], 1: ["value", argValue] }, named("Arg"));
|
|
||||||
export const useNode = codecs.slots<T.UseNode>(
|
|
||||||
{ 0: ["common", nodeCommon], 1: ["composition", compositionRef], 2: ["args", list(arg)] },
|
|
||||||
named("UseNode"),
|
|
||||||
);
|
|
||||||
|
|
||||||
const nodeUnion = required(
|
|
||||||
codecs.union<T.Node>(
|
|
||||||
"Node",
|
|
||||||
{
|
|
||||||
0: ["Box", boxNode],
|
|
||||||
1: ["Text", textNode],
|
|
||||||
2: ["Image", imageNode],
|
|
||||||
3: ["Button", buttonNode],
|
|
||||||
4: ["Toggle", toggleNode],
|
|
||||||
5: ["Slider", sliderNode],
|
|
||||||
6: ["TextInput", textInputNode],
|
|
||||||
7: ["Select", selectNode],
|
|
||||||
8: ["Repeat", repeatNode],
|
|
||||||
9: ["Overlay", overlayNode],
|
|
||||||
10: ["Plot", plotNode],
|
|
||||||
11: ["Embed", embedNode],
|
|
||||||
12: ["Use", useNode],
|
|
||||||
},
|
|
||||||
named("Node"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
export const paramKind = required(
|
|
||||||
codecs.union<T.ParamKind>(
|
|
||||||
"ParamKind",
|
|
||||||
{
|
|
||||||
0: ["Text", unit],
|
|
||||||
1: ["Number", unit],
|
|
||||||
2: ["Bool", unit],
|
|
||||||
3: ["Bind", unit],
|
|
||||||
4: ["Collection", unit],
|
|
||||||
5: ["Command", unit],
|
|
||||||
6: ["Slot", unit],
|
|
||||||
},
|
|
||||||
named("ParamKind"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
export const paramDecl = codecs.slots<T.ParamDecl>({ 0: ["name", string], 1: ["kind", paramKind] }, named("ParamDecl"));
|
|
||||||
|
|
||||||
// The documents' slot records. CommandResult's is in result.ts: it is the one that mints an instance.
|
|
||||||
export const surfaceDocument = codecs.slots<T.SurfaceDocument>(
|
|
||||||
{
|
|
||||||
0: ["providerId", string],
|
|
||||||
1: ["label", segment],
|
|
||||||
2: ["version", version],
|
|
||||||
3: ["title", string],
|
|
||||||
4: ["root", node],
|
|
||||||
5: ["commands", list(commandDecl)],
|
|
||||||
},
|
|
||||||
named("SurfaceDocument"),
|
|
||||||
);
|
|
||||||
export const compositionDocument = codecs.slots<T.CompositionDocument>(
|
|
||||||
{
|
|
||||||
0: ["publisher", string],
|
|
||||||
1: ["name", segment],
|
|
||||||
2: ["version", version],
|
|
||||||
3: ["params", list(paramDecl)],
|
|
||||||
4: ["body", node],
|
|
||||||
},
|
|
||||||
named("CompositionDocument"),
|
|
||||||
);
|
|
||||||
export const assetEntry = codecs.slots<T.AssetEntry>(
|
|
||||||
{ 0: ["id", string], 1: ["mediaType", string], 2: ["uri", string], 3: ["width", count], 4: ["height", count] },
|
|
||||||
named("AssetEntry"),
|
|
||||||
);
|
|
||||||
export const assetCatalog = codecs.slots<T.AssetCatalog>(
|
|
||||||
{ 0: ["providerId", string], 1: ["catalogId", segment], 2: ["version", version], 3: ["assets", list(assetEntry)] },
|
|
||||||
named("AssetCatalog"),
|
|
||||||
);
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
// The five document definitions (crates/thing-contract/src/lib.rs). `type` and `schemaVersion` are the crate's
|
|
||||||
// cultcache(type, schema). The codec runs on both doors (encodeDocumentPayload and decodeDocumentPayload run it and then
|
|
||||||
// the definition's schema.parse), so the domains hold whichever way a value enters. The four plain kinds parse as the
|
|
||||||
// identity; a command_result parses only an instance of CommandResult.
|
|
||||||
import { defineDocumentRegistry, defineDocumentType } from "@gamecult/cultcache-ts";
|
|
||||||
|
|
||||||
import { assetCatalog, commandInvocation, compositionDocument as compositionCodec, surfaceDocument as surfaceCodec } from "./codecs.js";
|
|
||||||
import { CommandResult, commandResult as commandResultCodec } from "./result.js";
|
|
||||||
import type { AssetCatalog, CommandInvocation, CompositionDocument, SurfaceDocument } from "./types.js";
|
|
||||||
|
|
||||||
const identity = <TValue>(input: unknown): TValue => input as TValue;
|
|
||||||
|
|
||||||
export const surfaceDocument = defineDocumentType({
|
|
||||||
type: "gamecult.thing.surface",
|
|
||||||
schemaName: "gamecult.thing.surface",
|
|
||||||
schemaVersion: "gamecult.thing.surface.v1",
|
|
||||||
schema: { parse: identity<SurfaceDocument> },
|
|
||||||
codec: surfaceCodec,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const compositionDocument = defineDocumentType({
|
|
||||||
type: "gamecult.thing.composition",
|
|
||||||
schemaName: "gamecult.thing.composition",
|
|
||||||
schemaVersion: "gamecult.thing.composition.v1",
|
|
||||||
schema: { parse: identity<CompositionDocument> },
|
|
||||||
codec: compositionCodec,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const commandInvocationDocument = defineDocumentType({
|
|
||||||
type: "gamecult.thing.command_invocation",
|
|
||||||
schemaName: "gamecult.thing.command_invocation",
|
|
||||||
schemaVersion: "gamecult.thing.command_invocation.v1",
|
|
||||||
schema: { parse: identity<CommandInvocation> },
|
|
||||||
codec: commandInvocation,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const commandResultDocument = defineDocumentType({
|
|
||||||
type: "gamecult.thing.command_result",
|
|
||||||
schemaName: "gamecult.thing.command_result",
|
|
||||||
schemaVersion: "gamecult.thing.command_result.v1",
|
|
||||||
schema: {
|
|
||||||
parse(input: unknown): CommandResult {
|
|
||||||
if (!CommandResult.isResult(input)) throw new Error("a CommandResult is built by its factories");
|
|
||||||
return input;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
codec: commandResultCodec,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const assetCatalogDocument = defineDocumentType({
|
|
||||||
type: "gamecult.thing.asset_catalog",
|
|
||||||
schemaName: "gamecult.thing.asset_catalog",
|
|
||||||
schemaVersion: "gamecult.thing.asset_catalog.v1",
|
|
||||||
schema: { parse: identity<AssetCatalog> },
|
|
||||||
codec: assetCatalog,
|
|
||||||
});
|
|
||||||
|
|
||||||
/** The five kinds, as the crate's ThingContract registers them. */
|
|
||||||
export const thingContract = defineDocumentRegistry(
|
|
||||||
surfaceDocument,
|
|
||||||
compositionDocument,
|
|
||||||
commandInvocationDocument,
|
|
||||||
commandResultDocument,
|
|
||||||
assetCatalogDocument,
|
|
||||||
);
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
// The value domains of the contract's numbers and local names (crates/thing-contract/src/domain.rs). Each is a leaf
|
|
||||||
// codec of cultcache-ts with the contract's bound added, so the bound holds on both doors of a document: encode and
|
|
||||||
// decode. A refusal names the domain and its bound, never the value (the leaf's own refusals do not echo one either).
|
|
||||||
import { codecs } from "@gamecult/cultcache-ts";
|
|
||||||
import type { Codec } from "@gamecult/cultcache-ts";
|
|
||||||
|
|
||||||
// A domain's wire form is its value, so its encode hands the checked value back: a caller that holds a number from
|
|
||||||
// outside (a factory argument, a key part) passes it through `encode` and keeps what comes out.
|
|
||||||
export interface Domain<TValue> extends Codec<TValue> {
|
|
||||||
encode(value: TValue): TValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bounded<TValue extends number | bigint | string>(
|
|
||||||
leaf: Codec<TValue>,
|
|
||||||
refusal: (value: TValue) => string | null,
|
|
||||||
): Domain<TValue> {
|
|
||||||
const hold = (value: TValue): TValue => {
|
|
||||||
const refused = refusal(value);
|
|
||||||
if (refused !== null) throw new Error(refused);
|
|
||||||
return value;
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
typeName: leaf.typeName,
|
|
||||||
valueType: leaf.valueType,
|
|
||||||
encode: (value) => hold(leaf.encode(value) as TValue),
|
|
||||||
decode: (raw) => hold(leaf.decode(raw)),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A result's position in its invocation's answers, counting from 1. */
|
|
||||||
export const seq = bounded(codecs.int32, (value) => (value >= 1 ? null : "Seq must be at least 1"));
|
|
||||||
|
|
||||||
/** A document or source version, never negative. */
|
|
||||||
export const version = bounded(codecs.int64, (value) => (value >= 0 ? null : "Version must be at least 0"));
|
|
||||||
|
|
||||||
/** A count, an extent or an index, never negative. */
|
|
||||||
export const count = bounded(codecs.int32, (value) => (value >= 0 ? null : "Count must be at least 0"));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A name the contract joins into a record key: non-empty, no '.'. A domain admits no nil, and the library refuses a nil
|
|
||||||
* in a value slot, so it is declared one.
|
|
||||||
*/
|
|
||||||
export const segment: Domain<string> = {
|
|
||||||
...bounded(codecs.string, (value) =>
|
|
||||||
value === "" ? "Segment must be non-empty" : value.includes(".") ? "Segment must be free of '.'" : null,
|
|
||||||
),
|
|
||||||
valueType: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
/** One colour channel: a byte. */
|
|
||||||
export const channel = bounded(codecs.int32, (value) => (value >= 0 && value <= 255 ? null : "Rgba channel must be 0 to 255"));
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
export * as codecs from "./codecs.js";
|
|
||||||
export * as domain from "./domain.js";
|
|
||||||
export * from "./documents.js";
|
|
||||||
export * from "./keys.js";
|
|
||||||
export { CommandResult } from "./result.js";
|
|
||||||
export type * from "./types.js";
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
// The record key of each kind (crates/thing-contract/src/keys.rs). Provider, publisher and invocation ids are free
|
|
||||||
// strings (dotted, as the Verse names them); the trailing parts are typed, so a key splits at its last dot (surface,
|
|
||||||
// asset catalog, result) or last two (composition) and two different field sets never build one key. Each local
|
|
||||||
// segment goes through the segment codec, and a seq or version through its own.
|
|
||||||
import { segment, seq, version } from "./domain.js";
|
|
||||||
|
|
||||||
export function surfaceKey(providerId: string, label: string): string {
|
|
||||||
return `thing:surface:${providerId}.${segment.encode(label)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function compositionKey(publisher: string, name: string, versionNumber: number | bigint): string {
|
|
||||||
return `thing:composition:${publisher}.${segment.encode(name)}.v${version.encode(versionNumber)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function invocationKey(invocationId: string): string {
|
|
||||||
return `thing:invocation:${invocationId}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resultKey(invocationId: string, position: number): string {
|
|
||||||
return `thing:result:${invocationId}.${seq.encode(position)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function assetCatalogKey(providerId: string, catalogId: string): string {
|
|
||||||
return `thing:asset_catalog:${providerId}.${segment.encode(catalogId)}`;
|
|
||||||
}
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
// The answer to a command invocation. A CommandResult is built by its four factories, each of which copies the
|
|
||||||
// invocation's id, and by the command_result document codec when it decodes. Decoding is the other door and holds the
|
|
||||||
// same domain: `seq` is refused below 1 whichever door it enters by. No export takes a state as a string or converts a
|
|
||||||
// plain object: an object literal, a spread, structuredClone copy or parsed JSON is not a result, and encoding one is
|
|
||||||
// refused (schema.parse in documents.ts).
|
|
||||||
//
|
|
||||||
// The copied invocation id is a convenience and not provenance: core binds a result to an invocation it issued.
|
|
||||||
import { codecs } from "@gamecult/cultcache-ts";
|
|
||||||
import type { SlotsCodec } from "@gamecult/cultcache-ts";
|
|
||||||
|
|
||||||
import { outcome } from "./codecs.js";
|
|
||||||
import { seq } from "./domain.js";
|
|
||||||
import type { CommandInvocation, Effect, NodeId, Outcome } from "./types.js";
|
|
||||||
|
|
||||||
// The one constructor call. The class's static block sets `mint`; the factories and the codec below use it; it is not
|
|
||||||
// exported. The constructor refuses a call that does not carry `door`, so a script that reaches the constructor at run
|
|
||||||
// time (the TypeScript `private` is compile-time only) builds nothing, and it holds the seq domain for every door.
|
|
||||||
const door: unique symbol = Symbol("CommandResult.door");
|
|
||||||
let mint: (invocationId: string, position: number, outcome: Outcome) => CommandResult;
|
|
||||||
|
|
||||||
export class CommandResult {
|
|
||||||
readonly #brand = true;
|
|
||||||
readonly invocationId: string;
|
|
||||||
readonly seq: number;
|
|
||||||
readonly outcome: Outcome;
|
|
||||||
|
|
||||||
private constructor(key: typeof door, invocationId: string, position: number, outcome: Outcome) {
|
|
||||||
if (key !== door) throw new Error("a CommandResult is built by its factories");
|
|
||||||
this.invocationId = invocationId;
|
|
||||||
this.seq = seq.encode(position);
|
|
||||||
this.outcome = outcome;
|
|
||||||
Object.freeze(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
mint = (invocationId, position, outcome) => new CommandResult(door, invocationId, position, outcome);
|
|
||||||
}
|
|
||||||
|
|
||||||
static pending(invocation: CommandInvocation, position: number, message: string): CommandResult {
|
|
||||||
return mint(invocation.invocationId, position, { kind: "Pending", message });
|
|
||||||
}
|
|
||||||
|
|
||||||
static completed(
|
|
||||||
invocation: CommandInvocation,
|
|
||||||
position: number,
|
|
||||||
sourceVersion: number | bigint | null,
|
|
||||||
clearDrafts: boolean,
|
|
||||||
effect: Effect | null,
|
|
||||||
): CommandResult {
|
|
||||||
return mint(invocation.invocationId, position, { kind: "Completed", sourceVersion, clearDrafts, effect });
|
|
||||||
}
|
|
||||||
|
|
||||||
static denied(invocation: CommandInvocation, position: number, reason: string, node: NodeId | null): CommandResult {
|
|
||||||
return mint(invocation.invocationId, position, { kind: "Denied", reason, node });
|
|
||||||
}
|
|
||||||
|
|
||||||
static failed(invocation: CommandInvocation, position: number, reason: string): CommandResult {
|
|
||||||
return mint(invocation.invocationId, position, { kind: "Failed", reason });
|
|
||||||
}
|
|
||||||
|
|
||||||
/** True for an instance a factory or the codec made; false for every other value, whatever its shape or prototype. */
|
|
||||||
static isResult(value: unknown): value is CommandResult {
|
|
||||||
return typeof value === "object" && value !== null && #brand in value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The command_result document codec: the slot record, with decode minting an instance. Encode reads the instance's
|
|
||||||
// fields through the same slot record, so the seq domain is held on both doors.
|
|
||||||
const slotRecord = codecs.slots<{ invocationId: string; seq: number; outcome: Outcome }>(
|
|
||||||
{ 0: ["invocationId", codecs.string], 1: ["seq", seq], 2: ["outcome", outcome] },
|
|
||||||
"GameCult.Thing.Contract.CommandResult",
|
|
||||||
);
|
|
||||||
|
|
||||||
export const commandResult: SlotsCodec<CommandResult> = {
|
|
||||||
names: slotRecord.names,
|
|
||||||
typeName: slotRecord.typeName,
|
|
||||||
get members() {
|
|
||||||
return slotRecord.members;
|
|
||||||
},
|
|
||||||
encode: (value) => slotRecord.encode(value),
|
|
||||||
decode: (raw) => {
|
|
||||||
const { invocationId, seq: position, outcome: answer } = slotRecord.decode(raw);
|
|
||||||
return mint(invocationId, position, answer);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
@ -1,369 +0,0 @@
|
||||||
// One TypeScript type per type of crates/thing-contract. A record is an interface of readonly camelCase fields; a closed
|
|
||||||
// set is a union discriminated on `kind`, the Rust arm name, and an arm carries its payload's fields beside the tag (a
|
|
||||||
// unit arm is just the tag). Option<T> is `T | null`, Vec<T> is `readonly T[]`, bytes are a Uint8Array.
|
|
||||||
//
|
|
||||||
// The value domains (Seq, Version, Count, Segment, an Rgba channel) are held by the codecs in domain.ts, not by these
|
|
||||||
// types: a type cannot say "at least 1". Every document is minted and checked by its codec.
|
|
||||||
|
|
||||||
type Arm<Kind extends string, Payload = unknown> = { readonly kind: Kind } & Payload;
|
|
||||||
|
|
||||||
export type ProviderId = string;
|
|
||||||
export type SchemaId = string;
|
|
||||||
export type RecordKey = string;
|
|
||||||
export type NodeId = string;
|
|
||||||
export type CommandId = string;
|
|
||||||
|
|
||||||
// source.rs
|
|
||||||
export interface ParamName { readonly name: string }
|
|
||||||
export interface TextLiteral { readonly value: string }
|
|
||||||
export interface NumberLiteral { readonly value: number }
|
|
||||||
export interface BoolLiteral { readonly value: boolean }
|
|
||||||
export type TextSource = Arm<"Literal", TextLiteral> | Arm<"Bound", Bind> | Arm<"Param", ParamName>;
|
|
||||||
export type NumberSource = Arm<"Literal", NumberLiteral> | Arm<"Bound", Bind> | Arm<"Param", ParamName>;
|
|
||||||
export type BoolSource = Arm<"Literal", BoolLiteral> | Arm<"Bound", Bind> | Arm<"Param", ParamName>;
|
|
||||||
export interface Bind {
|
|
||||||
readonly source: StateSource;
|
|
||||||
readonly member: MemberPath;
|
|
||||||
readonly format: Format | null;
|
|
||||||
}
|
|
||||||
export type StateSource = Arm<"Record", StateRef> | Arm<"Item">;
|
|
||||||
export interface StateRef {
|
|
||||||
readonly provider: ProviderId | null;
|
|
||||||
readonly schema: SchemaId;
|
|
||||||
readonly key: RecordKey;
|
|
||||||
}
|
|
||||||
export interface MemberPath { readonly steps: readonly MemberStep[] }
|
|
||||||
export type MemberStep = Arm<"Name", MemberName> | Arm<"Index", MemberIndex>;
|
|
||||||
export interface MemberName { readonly name: string }
|
|
||||||
/** `index` is a Count: at least 0. */
|
|
||||||
export interface MemberIndex { readonly index: number }
|
|
||||||
export type Format = Arm<"Number", NumberFormat> | Arm<"Duration"> | Arm<"Timestamp"> | Arm<"Affix", AffixFormat>;
|
|
||||||
/** `precision` is a Count: at least 0. */
|
|
||||||
export interface NumberFormat {
|
|
||||||
readonly precision: number;
|
|
||||||
readonly percent: boolean;
|
|
||||||
readonly unit: string | null;
|
|
||||||
}
|
|
||||||
export interface AffixFormat { readonly prefix: string; readonly suffix: string }
|
|
||||||
export type CollectionSource = Arm<"Records", RecordsSource> | Arm<"Member", Bind> | Arm<"Param", ParamName>;
|
|
||||||
export interface RecordsSource {
|
|
||||||
readonly provider: ProviderId | null;
|
|
||||||
readonly schema: SchemaId;
|
|
||||||
readonly keyPrefix: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// style.rs
|
|
||||||
export interface Scalar { readonly value: number }
|
|
||||||
export type Dimension =
|
|
||||||
| Arm<"Px", Scalar>
|
|
||||||
| Arm<"Percent", Scalar>
|
|
||||||
| Arm<"Fr", Scalar>
|
|
||||||
| Arm<"Auto">
|
|
||||||
| Arm<"Content">;
|
|
||||||
export interface Size2 { readonly width: Dimension; readonly height: Dimension }
|
|
||||||
export interface Edges {
|
|
||||||
readonly top: Dimension;
|
|
||||||
readonly right: Dimension;
|
|
||||||
readonly bottom: Dimension;
|
|
||||||
readonly left: Dimension;
|
|
||||||
}
|
|
||||||
export type Display = Arm<"Flex"> | Arm<"Grid"> | Arm<"Block">;
|
|
||||||
export type Direction = Arm<"Row"> | Arm<"Column"> | Arm<"RowReverse"> | Arm<"ColumnReverse">;
|
|
||||||
export type Wrap = Arm<"NoWrap"> | Arm<"Wrap"> | Arm<"WrapReverse">;
|
|
||||||
export type Position = Arm<"Relative"> | Arm<"Absolute">;
|
|
||||||
export type Overflow = Arm<"Visible"> | Arm<"Clip"> | Arm<"Scroll">;
|
|
||||||
export type ItemAlign = Arm<"Auto"> | Arm<"Start"> | Arm<"End"> | Arm<"Center"> | Arm<"Stretch"> | Arm<"Baseline">;
|
|
||||||
export type ContentAlign =
|
|
||||||
| Arm<"Auto">
|
|
||||||
| Arm<"Start">
|
|
||||||
| Arm<"End">
|
|
||||||
| Arm<"Center">
|
|
||||||
| Arm<"Stretch">
|
|
||||||
| Arm<"SpaceBetween">
|
|
||||||
| Arm<"SpaceAround">
|
|
||||||
| Arm<"SpaceEvenly">;
|
|
||||||
export interface BoxStyle {
|
|
||||||
readonly display: Display;
|
|
||||||
readonly direction: Direction;
|
|
||||||
readonly wrap: Wrap;
|
|
||||||
readonly gap: Size2;
|
|
||||||
readonly padding: Edges;
|
|
||||||
readonly margin: Edges;
|
|
||||||
readonly size: Size2;
|
|
||||||
readonly minSize: Size2;
|
|
||||||
readonly maxSize: Size2;
|
|
||||||
readonly position: Position;
|
|
||||||
readonly inset: Edges;
|
|
||||||
readonly overflow: Overflow;
|
|
||||||
readonly alignItems: ItemAlign;
|
|
||||||
readonly alignSelf: ItemAlign;
|
|
||||||
readonly alignContent: ContentAlign;
|
|
||||||
readonly justifyContent: ContentAlign;
|
|
||||||
readonly grow: number;
|
|
||||||
readonly shrink: number;
|
|
||||||
readonly basis: Dimension;
|
|
||||||
readonly gridColumns: readonly Dimension[];
|
|
||||||
readonly gridRows: readonly Dimension[];
|
|
||||||
}
|
|
||||||
export interface ThemeToken { readonly name: string }
|
|
||||||
/** Each channel is a byte: 0 to 255. */
|
|
||||||
export interface Rgba { readonly r: number; readonly g: number; readonly b: number; readonly a: number }
|
|
||||||
export type ColorRef = Arm<"Token", ThemeToken> | Arm<"Rgba", Rgba>;
|
|
||||||
export interface Border { readonly color: ColorRef; readonly width: number }
|
|
||||||
export interface Paint {
|
|
||||||
readonly background: ColorRef | null;
|
|
||||||
readonly border: Border | null;
|
|
||||||
readonly radius: number;
|
|
||||||
}
|
|
||||||
export type Role =
|
|
||||||
| Arm<"Group">
|
|
||||||
| Arm<"Region">
|
|
||||||
| Arm<"List">
|
|
||||||
| Arm<"ListItem">
|
|
||||||
| Arm<"Heading">
|
|
||||||
| Arm<"Dialog">
|
|
||||||
| Arm<"Toolbar">;
|
|
||||||
|
|
||||||
// command.rs
|
|
||||||
export interface CommandDecl {
|
|
||||||
readonly id: CommandId;
|
|
||||||
readonly payloadSchema: SchemaId;
|
|
||||||
readonly captures: readonly NodeId[];
|
|
||||||
readonly confirm: string | null;
|
|
||||||
}
|
|
||||||
export interface CommandIdRef { readonly id: CommandId }
|
|
||||||
export type CommandRef = Arm<"Id", CommandIdRef> | Arm<"Param", ParamName>;
|
|
||||||
export interface RecordPayload { readonly schema: SchemaId; readonly bytes: Uint8Array }
|
|
||||||
export interface TextValue { readonly value: string }
|
|
||||||
export interface NumberValue { readonly value: number }
|
|
||||||
export interface BoolValue { readonly value: boolean }
|
|
||||||
export interface ChoiceValue { readonly value: string }
|
|
||||||
export type InputValue = Arm<"Text", TextValue> | Arm<"Number", NumberValue> | Arm<"Bool", BoolValue> | Arm<"Choice", ChoiceValue>;
|
|
||||||
export interface CapturedInput { readonly node: NodeId; readonly value: InputValue }
|
|
||||||
/**
|
|
||||||
* A consumer's request that a provider run a declared command. Its fields are plain, so a result's copy of
|
|
||||||
* `invocationId` is a convenience and not provenance: core binds results to the invocations it issued.
|
|
||||||
* `surfaceVersion` is a Version: at least 0.
|
|
||||||
*/
|
|
||||||
export interface CommandInvocation {
|
|
||||||
readonly invocationId: string;
|
|
||||||
readonly surfaceKey: string;
|
|
||||||
readonly surfaceVersion: number | bigint;
|
|
||||||
readonly command: CommandId;
|
|
||||||
readonly payload: RecordPayload;
|
|
||||||
readonly captured: readonly CapturedInput[];
|
|
||||||
readonly client: string;
|
|
||||||
readonly issuedAt: string;
|
|
||||||
readonly delegation: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// result.rs
|
|
||||||
export interface PendingOutcome { readonly message: string }
|
|
||||||
/** `sourceVersion` is a Version: at least 0. */
|
|
||||||
export interface CompletedOutcome {
|
|
||||||
readonly sourceVersion: number | bigint | null;
|
|
||||||
readonly clearDrafts: boolean;
|
|
||||||
readonly effect: Effect | null;
|
|
||||||
}
|
|
||||||
export interface DeniedOutcome { readonly reason: string; readonly node: NodeId | null }
|
|
||||||
export interface FailedOutcome { readonly reason: string }
|
|
||||||
export type Outcome =
|
|
||||||
| Arm<"Pending", PendingOutcome>
|
|
||||||
| Arm<"Completed", CompletedOutcome>
|
|
||||||
| Arm<"Denied", DeniedOutcome>
|
|
||||||
| Arm<"Failed", FailedOutcome>;
|
|
||||||
export interface OpenSurfaceEffect { readonly key: string }
|
|
||||||
export interface OpenExternalEffect { readonly url: string; readonly resume: CommandRef }
|
|
||||||
export type Effect = Arm<"OpenSurface", OpenSurfaceEffect> | Arm<"OpenExternal", OpenExternalEffect>;
|
|
||||||
|
|
||||||
/** A provider's handler for one invocation: the outcome it answers with. */
|
|
||||||
export type Handler = (invocation: CommandInvocation) => Outcome | Promise<Outcome>;
|
|
||||||
|
|
||||||
// node.rs
|
|
||||||
export interface NodeCommon {
|
|
||||||
readonly id: NodeId;
|
|
||||||
readonly visible: BoolSource;
|
|
||||||
readonly a11yLabel: TextSource | null;
|
|
||||||
}
|
|
||||||
export type Node =
|
|
||||||
| Arm<"Box", BoxNode>
|
|
||||||
| Arm<"Text", TextNode>
|
|
||||||
| Arm<"Image", ImageNode>
|
|
||||||
| Arm<"Button", ButtonNode>
|
|
||||||
| Arm<"Toggle", ToggleNode>
|
|
||||||
| Arm<"Slider", SliderNode>
|
|
||||||
| Arm<"TextInput", TextInputNode>
|
|
||||||
| Arm<"Select", SelectNode>
|
|
||||||
| Arm<"Repeat", RepeatNode>
|
|
||||||
| Arm<"Overlay", OverlayNode>
|
|
||||||
| Arm<"Plot", PlotNode>
|
|
||||||
| Arm<"Embed", EmbedNode>
|
|
||||||
| Arm<"Use", UseNode>;
|
|
||||||
export interface BoxNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly style: BoxStyle;
|
|
||||||
readonly paint: Paint;
|
|
||||||
readonly role: Role;
|
|
||||||
readonly children: readonly Node[];
|
|
||||||
}
|
|
||||||
/** `maxLines` is a Count: at least 0. */
|
|
||||||
export interface TextNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly content: TextSource;
|
|
||||||
readonly styleToken: string;
|
|
||||||
readonly wrap: boolean;
|
|
||||||
readonly maxLines: number | null;
|
|
||||||
readonly selectable: boolean;
|
|
||||||
}
|
|
||||||
export type ImageFit = Arm<"Contain"> | Arm<"Cover"> | Arm<"Fill"> | Arm<"Unscaled">;
|
|
||||||
export interface ImageNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly catalog: string;
|
|
||||||
readonly asset: string;
|
|
||||||
readonly fit: ImageFit;
|
|
||||||
readonly alt: TextSource;
|
|
||||||
}
|
|
||||||
export interface ButtonNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly content: readonly Node[];
|
|
||||||
readonly onActivate: CommandRef;
|
|
||||||
readonly enabled: BoolSource;
|
|
||||||
}
|
|
||||||
export interface ToggleNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly checked: BoolSource;
|
|
||||||
readonly onChange: CommandRef;
|
|
||||||
}
|
|
||||||
export interface SliderNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly min: number;
|
|
||||||
readonly max: number;
|
|
||||||
readonly step: number;
|
|
||||||
readonly value: NumberSource;
|
|
||||||
readonly commit: CommandRef;
|
|
||||||
}
|
|
||||||
export type InputKind = Arm<"Text"> | Arm<"Number">;
|
|
||||||
/**
|
|
||||||
* The Rust field is `kind`; here it is `inputKind`, because a TextInput arm carries its payload beside the union's own
|
|
||||||
* `kind` tag and the two cannot share a name.
|
|
||||||
*/
|
|
||||||
export interface TextInputNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly multiline: boolean;
|
|
||||||
readonly inputKind: InputKind;
|
|
||||||
readonly placeholder: TextSource;
|
|
||||||
readonly initial: TextSource;
|
|
||||||
readonly submit: CommandRef;
|
|
||||||
}
|
|
||||||
export interface SelectOption { readonly value: string; readonly label: string }
|
|
||||||
export interface LiteralOptions { readonly options: readonly SelectOption[] }
|
|
||||||
export interface BoundOptions {
|
|
||||||
readonly collection: CollectionSource;
|
|
||||||
readonly valueMember: MemberPath;
|
|
||||||
readonly labelMember: MemberPath;
|
|
||||||
}
|
|
||||||
export type OptionList = Arm<"Literal", LiteralOptions> | Arm<"Bound", BoundOptions>;
|
|
||||||
export interface SelectNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly options: OptionList;
|
|
||||||
readonly value: Bind;
|
|
||||||
readonly onChange: CommandRef;
|
|
||||||
}
|
|
||||||
export interface RepeatNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly collection: CollectionSource;
|
|
||||||
readonly keyMember: MemberPath;
|
|
||||||
readonly template: Node;
|
|
||||||
}
|
|
||||||
export interface AnchorNode { readonly node: NodeId }
|
|
||||||
export type Anchor = Arm<"Viewport"> | Arm<"Node", AnchorNode>;
|
|
||||||
export interface OverlayNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly anchor: Anchor;
|
|
||||||
readonly modal: boolean;
|
|
||||||
readonly dismiss: CommandRef;
|
|
||||||
readonly children: readonly Node[];
|
|
||||||
}
|
|
||||||
export type PlotMark = Arm<"Line"> | Arm<"Bar"> | Arm<"Area">;
|
|
||||||
export interface PlotNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly series: Bind;
|
|
||||||
readonly mark: PlotMark;
|
|
||||||
readonly xMin: number | null;
|
|
||||||
readonly xMax: number | null;
|
|
||||||
readonly yMin: number | null;
|
|
||||||
readonly yMax: number | null;
|
|
||||||
}
|
|
||||||
export interface EmbedNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly slotKind: string;
|
|
||||||
readonly slotId: string;
|
|
||||||
readonly width: number;
|
|
||||||
readonly height: number;
|
|
||||||
}
|
|
||||||
/** `name` is a Segment (non-empty, no '.'); `version` is a Version (at least 0). */
|
|
||||||
export interface CompositionRef {
|
|
||||||
readonly publisher: string;
|
|
||||||
readonly name: string;
|
|
||||||
readonly version: number | bigint;
|
|
||||||
}
|
|
||||||
export interface UseNode {
|
|
||||||
readonly common: NodeCommon;
|
|
||||||
readonly composition: CompositionRef;
|
|
||||||
readonly args: readonly Arg[];
|
|
||||||
}
|
|
||||||
export interface Arg { readonly name: string; readonly value: ArgValue }
|
|
||||||
export interface TextArg { readonly value: string }
|
|
||||||
export interface NumberArg { readonly value: number }
|
|
||||||
export interface BoolArg { readonly value: boolean }
|
|
||||||
export interface CollectionArg { readonly source: CollectionSource }
|
|
||||||
export interface CommandArg { readonly command: CommandRef }
|
|
||||||
export interface SlotArg { readonly nodes: readonly Node[] }
|
|
||||||
export type ArgValue =
|
|
||||||
| Arm<"Text", TextArg>
|
|
||||||
| Arm<"Number", NumberArg>
|
|
||||||
| Arm<"Bool", BoolArg>
|
|
||||||
| Arm<"Bind", Bind>
|
|
||||||
| Arm<"Collection", CollectionArg>
|
|
||||||
| Arm<"Command", CommandArg>
|
|
||||||
| Arm<"Slot", SlotArg>;
|
|
||||||
export type ParamKind =
|
|
||||||
| Arm<"Text">
|
|
||||||
| Arm<"Number">
|
|
||||||
| Arm<"Bool">
|
|
||||||
| Arm<"Bind">
|
|
||||||
| Arm<"Collection">
|
|
||||||
| Arm<"Command">
|
|
||||||
| Arm<"Slot">;
|
|
||||||
export interface ParamDecl { readonly name: string; readonly kind: ParamKind }
|
|
||||||
|
|
||||||
// The documents. `label`, `name` and `catalogId` are Segments, `version` a Version, an extent a Count. The fifth
|
|
||||||
// document, CommandResult, is a class (result.ts).
|
|
||||||
export interface SurfaceDocument {
|
|
||||||
readonly providerId: ProviderId;
|
|
||||||
readonly label: string;
|
|
||||||
readonly version: number | bigint;
|
|
||||||
readonly title: string;
|
|
||||||
readonly root: Node;
|
|
||||||
readonly commands: readonly CommandDecl[];
|
|
||||||
}
|
|
||||||
export interface CompositionDocument {
|
|
||||||
readonly publisher: string;
|
|
||||||
readonly name: string;
|
|
||||||
readonly version: number | bigint;
|
|
||||||
readonly params: readonly ParamDecl[];
|
|
||||||
readonly body: Node;
|
|
||||||
}
|
|
||||||
export interface AssetEntry {
|
|
||||||
readonly id: string;
|
|
||||||
readonly mediaType: string;
|
|
||||||
readonly uri: string;
|
|
||||||
readonly width: number;
|
|
||||||
readonly height: number;
|
|
||||||
}
|
|
||||||
export interface AssetCatalog {
|
|
||||||
readonly providerId: ProviderId;
|
|
||||||
readonly catalogId: string;
|
|
||||||
readonly version: number | bigint;
|
|
||||||
readonly assets: readonly AssetEntry[];
|
|
||||||
}
|
|
||||||
|
|
@ -1,478 +0,0 @@
|
||||||
// The values the goldens are built from, ported from crates/thing-contract/tests/common/mod.rs and goldens.rs. Every
|
|
||||||
// value is an object literal of the package's exported types; no bytes are spelled here. The golden files are read, never
|
|
||||||
// written: the Rust crate blesses them.
|
|
||||||
import { existsSync, readFileSync } from "node:fs";
|
|
||||||
import { dirname, join } from "node:path";
|
|
||||||
import { fileURLToPath } from "node:url";
|
|
||||||
|
|
||||||
import { CommandResult } from "@gamecult/thing-contract";
|
|
||||||
import type {
|
|
||||||
Arg,
|
|
||||||
AssetCatalog,
|
|
||||||
BoxNode,
|
|
||||||
Bind,
|
|
||||||
BoolSource,
|
|
||||||
CollectionSource,
|
|
||||||
CommandInvocation,
|
|
||||||
CommandRef,
|
|
||||||
CompositionDocument,
|
|
||||||
Dimension,
|
|
||||||
Edges,
|
|
||||||
Format,
|
|
||||||
MemberPath,
|
|
||||||
Node,
|
|
||||||
NodeCommon,
|
|
||||||
NumberSource,
|
|
||||||
Paint,
|
|
||||||
Size2,
|
|
||||||
SurfaceDocument,
|
|
||||||
TextSource,
|
|
||||||
BoxStyle,
|
|
||||||
} from "@gamecult/thing-contract";
|
|
||||||
|
|
||||||
export const CANARY = "CANARY-7f3a91c2";
|
|
||||||
export const PINNED_CLOCK = "2026-01-01T00:00:00Z";
|
|
||||||
|
|
||||||
/** The goldens directory, found by walking up from this file (a mutation sandbox sits deeper in the tree). */
|
|
||||||
export const goldensDir: string = (() => {
|
|
||||||
let here = dirname(fileURLToPath(import.meta.url));
|
|
||||||
for (;;) {
|
|
||||||
const candidate = join(here, "crates", "thing-contract", "tests", "goldens");
|
|
||||||
if (existsSync(candidate)) return candidate;
|
|
||||||
const parent = dirname(here);
|
|
||||||
if (parent === here) throw new Error("the Rust crate's goldens directory is not above this file");
|
|
||||||
here = parent;
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
export function golden(file: string): Uint8Array {
|
|
||||||
return new Uint8Array(readFileSync(join(goldensDir, file)));
|
|
||||||
}
|
|
||||||
|
|
||||||
export const lit = (value: string): TextSource => ({ kind: "Literal", value });
|
|
||||||
export const litBool = (value: boolean): BoolSource => ({ kind: "Literal", value });
|
|
||||||
export const litNumber = (value: number): NumberSource => ({ kind: "Literal", value });
|
|
||||||
export const param = (name: string) => ({ kind: "Param", name }) as const;
|
|
||||||
export const path = (...names: string[]): MemberPath => ({ steps: names.map((name) => ({ kind: "Name", name }) as const) });
|
|
||||||
export const command = (id: string): CommandRef => ({ kind: "Id", id });
|
|
||||||
|
|
||||||
export function recordBind(member: MemberPath, format: Format | null): Bind {
|
|
||||||
return {
|
|
||||||
source: { kind: "Record", provider: "provider.a", schema: "gamecult.thing.test.v1", key: "row-1" },
|
|
||||||
member,
|
|
||||||
format,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
export const itemBind = (member: MemberPath): Bind => ({ source: { kind: "Item" }, member, format: null });
|
|
||||||
|
|
||||||
export const common = (id: string): NodeCommon => ({ id, visible: litBool(true), a11yLabel: null });
|
|
||||||
export const px = (value: number): Dimension => ({ kind: "Px", value });
|
|
||||||
export const size2 = (width: Dimension, height: Dimension): Size2 => ({ width, height });
|
|
||||||
export const edges = (all: Dimension): Edges => ({ top: all, right: all, bottom: all, left: all });
|
|
||||||
|
|
||||||
export function style(): BoxStyle {
|
|
||||||
return {
|
|
||||||
display: { kind: "Flex" },
|
|
||||||
direction: { kind: "Column" },
|
|
||||||
wrap: { kind: "NoWrap" },
|
|
||||||
gap: size2(px(4), px(8)),
|
|
||||||
padding: edges(px(2)),
|
|
||||||
margin: edges({ kind: "Auto" }),
|
|
||||||
size: size2({ kind: "Percent", value: 100 }, { kind: "Content" }),
|
|
||||||
minSize: size2(px(0), px(0)),
|
|
||||||
maxSize: size2({ kind: "Auto" }, { kind: "Auto" }),
|
|
||||||
position: { kind: "Relative" },
|
|
||||||
inset: edges({ kind: "Auto" }),
|
|
||||||
overflow: { kind: "Visible" },
|
|
||||||
alignItems: { kind: "Stretch" },
|
|
||||||
alignSelf: { kind: "Auto" },
|
|
||||||
alignContent: { kind: "Start" },
|
|
||||||
justifyContent: { kind: "SpaceBetween" },
|
|
||||||
grow: 1,
|
|
||||||
shrink: 0,
|
|
||||||
basis: { kind: "Auto" },
|
|
||||||
gridColumns: [],
|
|
||||||
gridRows: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const plainPaint = (): Paint => ({ background: null, border: null, radius: 0 });
|
|
||||||
|
|
||||||
export function boxNode(id: string, children: readonly Node[]): BoxNode {
|
|
||||||
return { common: common(id), style: style(), paint: plainPaint(), role: { kind: "Group" }, children };
|
|
||||||
}
|
|
||||||
export const boxed = (id: string, children: readonly Node[]): Node => ({ kind: "Box", ...boxNode(id, children) });
|
|
||||||
export const text = (id: string, content: string): Node => ({
|
|
||||||
kind: "Text",
|
|
||||||
common: common(id),
|
|
||||||
content: lit(content),
|
|
||||||
styleToken: "body",
|
|
||||||
wrap: true,
|
|
||||||
maxLines: null,
|
|
||||||
selectable: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
export function invocation(): CommandInvocation {
|
|
||||||
return {
|
|
||||||
invocationId: "3f2b8c1e-5d44-4a6b-9a07-1c2d3e4f5a6b",
|
|
||||||
surfaceKey: "thing:surface:provider.a.main",
|
|
||||||
surfaceVersion: 7,
|
|
||||||
command: "go",
|
|
||||||
payload: { schema: "gamecult.thing.test.go.v1", bytes: new Uint8Array([0x91, 0x01, 0xff, 0x00]) },
|
|
||||||
captured: [
|
|
||||||
{ node: "name-input", value: { kind: "Text", value: "Ada" } },
|
|
||||||
{ node: "level", value: { kind: "Number", value: 0.75 } },
|
|
||||||
{ node: "flag", value: { kind: "Bool", value: true } },
|
|
||||||
{ node: "pick", value: { kind: "Choice", value: "a" } },
|
|
||||||
],
|
|
||||||
client: "renderer.web",
|
|
||||||
issuedAt: PINNED_CLOCK,
|
|
||||||
delegation: "delegate-1",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function bindAllFormats(): Bind[] {
|
|
||||||
const number: Format = { kind: "Number", precision: 2, percent: true, unit: "ms" };
|
|
||||||
const affix: Format = { kind: "Affix", prefix: "$", suffix: "/s" };
|
|
||||||
const indexed: MemberPath = { steps: [{ kind: "Name", name: "items" }, { kind: "Index", index: 3 }] };
|
|
||||||
return [
|
|
||||||
recordBind(indexed, number),
|
|
||||||
recordBind(path("elapsed"), { kind: "Duration" }),
|
|
||||||
recordBind(path("at"), { kind: "Timestamp" }),
|
|
||||||
recordBind(path("price"), affix),
|
|
||||||
recordBind(path("plain"), null),
|
|
||||||
itemBind(path("name")),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function fullSurface(): SurfaceDocument {
|
|
||||||
const binds = bindAllFormats();
|
|
||||||
const boundText: TextSource = { kind: "Bound", ...binds[3] };
|
|
||||||
const boundBool: BoolSource = { kind: "Bound", ...binds[4] };
|
|
||||||
const boundNumber: NumberSource = { kind: "Bound", ...binds[0] };
|
|
||||||
|
|
||||||
const painted: Node = {
|
|
||||||
kind: "Box",
|
|
||||||
common: { id: "painted", visible: param("show"), a11yLabel: param("label") },
|
|
||||||
style: {
|
|
||||||
...style(),
|
|
||||||
display: { kind: "Grid" },
|
|
||||||
gridColumns: [{ kind: "Fr", value: 1 }, px(120)],
|
|
||||||
gridRows: [{ kind: "Content" }],
|
|
||||||
position: { kind: "Absolute" },
|
|
||||||
overflow: { kind: "Scroll" },
|
|
||||||
direction: { kind: "RowReverse" },
|
|
||||||
wrap: { kind: "WrapReverse" },
|
|
||||||
alignItems: { kind: "Baseline" },
|
|
||||||
alignSelf: { kind: "Center" },
|
|
||||||
alignContent: { kind: "SpaceAround" },
|
|
||||||
justifyContent: { kind: "SpaceEvenly" },
|
|
||||||
},
|
|
||||||
paint: {
|
|
||||||
background: { kind: "Token", name: "surface.raised" },
|
|
||||||
border: { color: { kind: "Rgba", r: 1, g: 2, b: 3, a: 255 }, width: 1.5 },
|
|
||||||
radius: 4,
|
|
||||||
},
|
|
||||||
role: { kind: "Region" },
|
|
||||||
children: [text("deep-text", "deep")],
|
|
||||||
};
|
|
||||||
|
|
||||||
const repeat: Node = {
|
|
||||||
kind: "Repeat",
|
|
||||||
common: common("rows"),
|
|
||||||
collection: { kind: "Records", provider: null, schema: "gamecult.thing.test.v1", keyPrefix: "row-" },
|
|
||||||
keyMember: path("id"),
|
|
||||||
template: {
|
|
||||||
kind: "Text",
|
|
||||||
common: common("row-name"),
|
|
||||||
content: { kind: "Bound", ...itemBind(path("name")) },
|
|
||||||
styleToken: "body",
|
|
||||||
wrap: false,
|
|
||||||
maxLines: 2,
|
|
||||||
selectable: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const leaves: Node[] = [
|
|
||||||
{
|
|
||||||
kind: "Text",
|
|
||||||
common: common("t-bound"),
|
|
||||||
content: boundText,
|
|
||||||
styleToken: "label",
|
|
||||||
wrap: true,
|
|
||||||
maxLines: null,
|
|
||||||
selectable: false,
|
|
||||||
},
|
|
||||||
{ kind: "Image", common: common("img"), catalog: "icons", asset: "gear", fit: { kind: "Cover" }, alt: lit("a gear") },
|
|
||||||
{
|
|
||||||
kind: "Button",
|
|
||||||
common: common("go"),
|
|
||||||
content: [text("go-label", "Go")],
|
|
||||||
onActivate: command("go"),
|
|
||||||
enabled: boundBool,
|
|
||||||
},
|
|
||||||
{ kind: "Toggle", common: common("flag"), checked: boundBool, onChange: param("toggle") },
|
|
||||||
{
|
|
||||||
kind: "Slider",
|
|
||||||
common: common("level"),
|
|
||||||
min: 0,
|
|
||||||
max: 1,
|
|
||||||
step: 0.25,
|
|
||||||
value: boundNumber,
|
|
||||||
commit: command("set-level"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kind: "TextInput",
|
|
||||||
common: common("name-input"),
|
|
||||||
multiline: true,
|
|
||||||
inputKind: { kind: "Number" },
|
|
||||||
placeholder: lit("name"),
|
|
||||||
initial: param("initial"),
|
|
||||||
submit: command("rename"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kind: "TextInput",
|
|
||||||
common: common("title-input"),
|
|
||||||
multiline: false,
|
|
||||||
inputKind: { kind: "Text" },
|
|
||||||
placeholder: lit("title"),
|
|
||||||
initial: param("initial"),
|
|
||||||
submit: command("retitle"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kind: "Select",
|
|
||||||
common: common("pick"),
|
|
||||||
options: { kind: "Literal", options: [{ value: "a", label: "Alpha" }] },
|
|
||||||
value: binds[4],
|
|
||||||
onChange: command("pick"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kind: "Select",
|
|
||||||
common: common("pick-bound"),
|
|
||||||
options: {
|
|
||||||
kind: "Bound",
|
|
||||||
collection: { kind: "Member", ...binds[0] },
|
|
||||||
valueMember: path("id"),
|
|
||||||
labelMember: path("name"),
|
|
||||||
},
|
|
||||||
value: binds[5],
|
|
||||||
onChange: command("pick"),
|
|
||||||
},
|
|
||||||
repeat,
|
|
||||||
{
|
|
||||||
kind: "Overlay",
|
|
||||||
common: common("menu"),
|
|
||||||
anchor: { kind: "Node", node: "go" },
|
|
||||||
modal: false,
|
|
||||||
dismiss: command("close"),
|
|
||||||
children: [text("menu-item", "one")],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kind: "Overlay",
|
|
||||||
common: common("dialog"),
|
|
||||||
anchor: { kind: "Viewport" },
|
|
||||||
modal: true,
|
|
||||||
dismiss: command("close"),
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kind: "Plot",
|
|
||||||
common: common("trend"),
|
|
||||||
series: binds[1],
|
|
||||||
mark: { kind: "Area" },
|
|
||||||
xMin: 0,
|
|
||||||
xMax: null,
|
|
||||||
yMin: null,
|
|
||||||
yMax: 100,
|
|
||||||
},
|
|
||||||
{ kind: "Embed", common: common("viewport"), slotKind: "world.scene", slotId: "main", width: 640, height: 480 },
|
|
||||||
{
|
|
||||||
kind: "Use",
|
|
||||||
common: common("kv"),
|
|
||||||
composition: { publisher: "thing.std", name: "key-value", version: 1 },
|
|
||||||
args: [{ name: "key", value: { kind: "Text", value: "k" } }],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
let deep: Node = boxed("d4", [painted]);
|
|
||||||
for (const id of ["d3", "d2", "d1"]) deep = boxed(id, [deep]);
|
|
||||||
const children: Node[] = [deep, ...leaves];
|
|
||||||
for (const [id, mark] of [
|
|
||||||
["trend-line", { kind: "Line" }],
|
|
||||||
["trend-bar", { kind: "Bar" }],
|
|
||||||
] as const) {
|
|
||||||
children.push({
|
|
||||||
kind: "Plot",
|
|
||||||
common: common(id),
|
|
||||||
series: binds[2],
|
|
||||||
mark,
|
|
||||||
xMin: null,
|
|
||||||
xMax: null,
|
|
||||||
yMin: null,
|
|
||||||
yMax: null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
(["Contain", "Fill", "Unscaled"] as const).forEach((fit, index) => {
|
|
||||||
children.push({
|
|
||||||
kind: "Image",
|
|
||||||
common: common(`img-fit-${index}`),
|
|
||||||
catalog: "icons",
|
|
||||||
asset: "gear",
|
|
||||||
fit: { kind: fit },
|
|
||||||
alt: lit(""),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
(["List", "ListItem", "Heading", "Dialog", "Toolbar"] as const).forEach((role, index) => {
|
|
||||||
const roleStyle: BoxStyle =
|
|
||||||
index === 0
|
|
||||||
? { ...style(), direction: { kind: "Row" }, alignContent: { kind: "Auto" }, justifyContent: { kind: "Stretch" } }
|
|
||||||
: style();
|
|
||||||
children.push({
|
|
||||||
kind: "Box",
|
|
||||||
common: common(`role-${index}`),
|
|
||||||
style: roleStyle,
|
|
||||||
paint: plainPaint(),
|
|
||||||
role: { kind: role },
|
|
||||||
children: [],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
children.push({
|
|
||||||
kind: "Box",
|
|
||||||
common: common("block"),
|
|
||||||
style: {
|
|
||||||
...style(),
|
|
||||||
display: { kind: "Block" },
|
|
||||||
direction: { kind: "ColumnReverse" },
|
|
||||||
wrap: { kind: "Wrap" },
|
|
||||||
overflow: { kind: "Clip" },
|
|
||||||
alignContent: { kind: "Center" },
|
|
||||||
justifyContent: { kind: "End" },
|
|
||||||
alignItems: { kind: "End" },
|
|
||||||
alignSelf: { kind: "Start" },
|
|
||||||
basis: { kind: "Content" },
|
|
||||||
},
|
|
||||||
paint: plainPaint(),
|
|
||||||
role: { kind: "Group" },
|
|
||||||
children: [],
|
|
||||||
});
|
|
||||||
children.push({
|
|
||||||
kind: "Text",
|
|
||||||
common: common("t-param"),
|
|
||||||
content: param("title"),
|
|
||||||
styleToken: "title",
|
|
||||||
wrap: true,
|
|
||||||
maxLines: null,
|
|
||||||
selectable: false,
|
|
||||||
});
|
|
||||||
children.push({
|
|
||||||
kind: "Toggle",
|
|
||||||
common: { id: "literal-number", visible: param("v"), a11yLabel: null },
|
|
||||||
checked: litBool(false),
|
|
||||||
onChange: command("toggle"),
|
|
||||||
});
|
|
||||||
children.push({
|
|
||||||
kind: "Slider",
|
|
||||||
common: common("slider-literal"),
|
|
||||||
min: -1,
|
|
||||||
max: 1,
|
|
||||||
step: 0.5,
|
|
||||||
value: litNumber(0.5),
|
|
||||||
commit: command("set-level"),
|
|
||||||
});
|
|
||||||
children.push({
|
|
||||||
kind: "Slider",
|
|
||||||
common: common("slider-param"),
|
|
||||||
min: 0,
|
|
||||||
max: 10,
|
|
||||||
step: 1,
|
|
||||||
value: param("n"),
|
|
||||||
commit: command("set-level"),
|
|
||||||
});
|
|
||||||
const rows: CollectionSource = param("rows");
|
|
||||||
children.push({
|
|
||||||
kind: "Repeat",
|
|
||||||
common: common("rows-param"),
|
|
||||||
collection: rows,
|
|
||||||
keyMember: path("id"),
|
|
||||||
template: text("row-param", "r"),
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
providerId: "provider.a",
|
|
||||||
label: "main",
|
|
||||||
version: 7,
|
|
||||||
title: "All arms",
|
|
||||||
root: boxed("root", children),
|
|
||||||
commands: [
|
|
||||||
{ id: "go", payloadSchema: "gamecult.thing.test.go.v1", captures: ["name-input", "level"], confirm: "Go now?" },
|
|
||||||
{ id: "close", payloadSchema: "gamecult.thing.test.close.v1", captures: [], confirm: null },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function fullComposition(): CompositionDocument {
|
|
||||||
const args: Arg[] = [
|
|
||||||
{ name: "text", value: { kind: "Text", value: "t" } },
|
|
||||||
{ name: "number", value: { kind: "Number", value: 2.5 } },
|
|
||||||
{ name: "bool", value: { kind: "Bool", value: true } },
|
|
||||||
{ name: "bind", value: { kind: "Bind", ...recordBind(path("x"), null) } },
|
|
||||||
{ name: "collection", value: { kind: "Collection", source: param("rows") } },
|
|
||||||
{ name: "command", value: { kind: "Command", command: command("go") } },
|
|
||||||
{ name: "slot", value: { kind: "Slot", nodes: [text("slot-text", "inside"), boxed("slot-box", [])] } },
|
|
||||||
];
|
|
||||||
const innerUse: Node = {
|
|
||||||
kind: "Use",
|
|
||||||
common: common("inner"),
|
|
||||||
composition: { publisher: "thing.std", name: "card", version: 2 },
|
|
||||||
args,
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
publisher: "provider.a",
|
|
||||||
name: "panel",
|
|
||||||
version: 3,
|
|
||||||
params: [
|
|
||||||
{ name: "title", kind: { kind: "Text" } },
|
|
||||||
{ name: "count", kind: { kind: "Number" } },
|
|
||||||
{ name: "on", kind: { kind: "Bool" } },
|
|
||||||
{ name: "source", kind: { kind: "Bind" } },
|
|
||||||
{ name: "rows", kind: { kind: "Collection" } },
|
|
||||||
{ name: "act", kind: { kind: "Command" } },
|
|
||||||
{ name: "body", kind: { kind: "Slot" } },
|
|
||||||
],
|
|
||||||
body: boxed("panel-root", [text("panel-title", "t"), innerUse]),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function results(answered: CommandInvocation): [string, CommandResult][] {
|
|
||||||
return [
|
|
||||||
["result-pending", CommandResult.pending(answered, 1, "working")],
|
|
||||||
["result-completed", CommandResult.completed(answered, 2, 8, true, null)],
|
|
||||||
[
|
|
||||||
"result-completed-open-surface",
|
|
||||||
CommandResult.completed(answered, 3, null, false, { kind: "OpenSurface", key: "thing:surface:provider.a.next" }),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"result-completed-open-external",
|
|
||||||
CommandResult.completed(answered, 4, 9, true, {
|
|
||||||
kind: "OpenExternal",
|
|
||||||
url: "https://example.test/auth",
|
|
||||||
resume: command("resume"),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
["result-denied", CommandResult.denied(answered, 5, "not yours", "go")],
|
|
||||||
["result-denied-no-node", CommandResult.denied(answered, 6, "not allowed", null)],
|
|
||||||
["result-failed", CommandResult.failed(answered, 7, "broke")],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function assetCatalogValue(): AssetCatalog {
|
|
||||||
return {
|
|
||||||
providerId: "provider.a",
|
|
||||||
catalogId: "icons",
|
|
||||||
version: 2,
|
|
||||||
assets: [
|
|
||||||
{ id: "gear", mediaType: "image/png", uri: "assets/gear.png", width: 32, height: 32 },
|
|
||||||
{ id: "bolt", mediaType: "image/svg+xml", uri: "assets/bolt.svg", width: 0, height: 0 },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
// Every codec of the package is named GameCult.Thing.Contract.<RustName>, the reference's full type name, and every union
|
|
||||||
// names itself in its refusals. The exports are the lowerCamel of the Rust type names, so the test reads the expected name
|
|
||||||
// off the export.
|
|
||||||
import assert from "node:assert/strict";
|
|
||||||
import test from "node:test";
|
|
||||||
|
|
||||||
import { codecs } from "@gamecult/thing-contract";
|
|
||||||
|
|
||||||
const NS = "GameCult.Thing.Contract.";
|
|
||||||
const entries = Object.entries(codecs) as [string, { typeName?: string; decode(raw: unknown): unknown }][];
|
|
||||||
const rustName = (key: string) => key[0].toUpperCase() + key.slice(1);
|
|
||||||
|
|
||||||
test("the package exports ninety-five codecs", () => {
|
|
||||||
assert.equal(entries.length, 95);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("every codec carries the reference's full type name", () => {
|
|
||||||
for (const [key, codec] of entries) assert.equal(codec.typeName, `${NS}${rustName(key)}`, key);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("every union refuses an unknown arm by its own name, and the twenty-nine unions are all of them", () => {
|
|
||||||
const unions: string[] = [];
|
|
||||||
for (const [key, codec] of entries) {
|
|
||||||
let message: string;
|
|
||||||
try {
|
|
||||||
codec.decode([2 ** 30, []]);
|
|
||||||
continue;
|
|
||||||
} catch (error) {
|
|
||||||
message = (error as Error).message;
|
|
||||||
}
|
|
||||||
const named = /^Union (\w+): unknown arm key 1073741824 \(declared keys: [-\d, ]+\)\.$/.exec(message);
|
|
||||||
if (named === null) continue;
|
|
||||||
unions.push(key);
|
|
||||||
assert.equal(named[1], rustName(key), key);
|
|
||||||
}
|
|
||||||
assert.equal(unions.length, 29);
|
|
||||||
});
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
// The deepest tree the payload bound admits decodes and re-encodes on Node's default stack (no --stack-size), and one
|
|
||||||
// level deeper is refused with CultCachePayloadDepthError, never an abort. The Rust test of the same name needs a 16 MiB
|
|
||||||
// thread for this; here the stack holds, and the bound refuses first.
|
|
||||||
import assert from "node:assert/strict";
|
|
||||||
import test from "node:test";
|
|
||||||
|
|
||||||
import {
|
|
||||||
CultCachePayloadDepthError,
|
|
||||||
MAX_PAYLOAD_DEPTH,
|
|
||||||
decodeDocumentPayload,
|
|
||||||
documentPayloadBytes,
|
|
||||||
documentPayloadFromBytes,
|
|
||||||
encodeDocumentPayload,
|
|
||||||
} from "@gamecult/cultcache-ts";
|
|
||||||
import { surfaceDocument } from "@gamecult/thing-contract";
|
|
||||||
import type { Node, SurfaceDocument } from "@gamecult/thing-contract";
|
|
||||||
|
|
||||||
import { boxNode, boxed, text } from "./builders.js";
|
|
||||||
|
|
||||||
function chain(levels: number): SurfaceDocument {
|
|
||||||
let root: Node = text("leaf", "bottom");
|
|
||||||
for (let depth = levels - 1; depth >= 0; depth--) root = boxed(`deep-${depth}`, [root]);
|
|
||||||
return { providerId: "provider.a", label: "deep", version: 1, title: "deep", root, commands: [] };
|
|
||||||
}
|
|
||||||
|
|
||||||
const admits = (levels: number): boolean => {
|
|
||||||
try {
|
|
||||||
encodeDocumentPayload(surfaceDocument, chain(levels));
|
|
||||||
return true;
|
|
||||||
} catch (error) {
|
|
||||||
assert.ok(error instanceof CultCachePayloadDepthError, "the only refusal of a plain chain is the depth bound");
|
|
||||||
assert.equal(error.limit, MAX_PAYLOAD_DEPTH);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
test("the deepest Box chain the bound admits round-trips on the default stack, and one more is refused", () => {
|
|
||||||
let deepest = 1;
|
|
||||||
while (admits(deepest + 1)) deepest++;
|
|
||||||
assert.equal(deepest, 83, "the bound admits 83 Box levels above the text leaf, 84 nodes deep");
|
|
||||||
assert.ok(!admits(deepest + 1));
|
|
||||||
|
|
||||||
const value = chain(deepest);
|
|
||||||
const bytes = documentPayloadBytes(encodeDocumentPayload(surfaceDocument, value));
|
|
||||||
const decoded = decodeDocumentPayload(surfaceDocument, documentPayloadFromBytes(bytes));
|
|
||||||
assert.deepStrictEqual(decoded, value);
|
|
||||||
assert.deepEqual(documentPayloadBytes(encodeDocumentPayload(surfaceDocument, decoded)), bytes);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a payload one container past the bound is refused with the depth error, before any codec reads it", () => {
|
|
||||||
const nested = (levels: number) => new Uint8Array([...new Array<number>(levels).fill(0x91), 0xc0]);
|
|
||||||
assert.throws(
|
|
||||||
() => decodeDocumentPayload(surfaceDocument, documentPayloadFromBytes(nested(MAX_PAYLOAD_DEPTH + 1))),
|
|
||||||
(error: unknown) => error instanceof CultCachePayloadDepthError && error.depth === MAX_PAYLOAD_DEPTH + 1,
|
|
||||||
);
|
|
||||||
// At the bound the walk admits it and the codec refuses the shape instead.
|
|
||||||
assert.throws(
|
|
||||||
() => decodeDocumentPayload(surfaceDocument, documentPayloadFromBytes(nested(MAX_PAYLOAD_DEPTH))),
|
|
||||||
(error: unknown) => error instanceof Error && !(error instanceof CultCachePayloadDepthError),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a wide tree of a thousand nodes round-trips", () => {
|
|
||||||
const children: Node[] = Array.from({ length: 998 }, (_, index) => text(`t${index}`, "x"));
|
|
||||||
children.push(boxed("tail", []));
|
|
||||||
const wide: SurfaceDocument = {
|
|
||||||
providerId: "provider.a",
|
|
||||||
label: "wide",
|
|
||||||
version: 1,
|
|
||||||
title: "wide",
|
|
||||||
root: { kind: "Box", ...boxNode("root", children) },
|
|
||||||
commands: [],
|
|
||||||
};
|
|
||||||
const bytes = documentPayloadBytes(encodeDocumentPayload(surfaceDocument, wide));
|
|
||||||
assert.deepStrictEqual(decodeDocumentPayload(surfaceDocument, documentPayloadFromBytes(bytes)), wide);
|
|
||||||
});
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
// The five definitions carry the crate's cultcache(type, schema) and, per document slot, the reference's member name
|
|
||||||
// and C# type name that a store's schema catalog is compared on.
|
|
||||||
import assert from "node:assert/strict";
|
|
||||||
import test from "node:test";
|
|
||||||
|
|
||||||
import {
|
|
||||||
assetCatalogDocument,
|
|
||||||
commandInvocationDocument,
|
|
||||||
commandResultDocument,
|
|
||||||
compositionDocument,
|
|
||||||
surfaceDocument,
|
|
||||||
thingContract,
|
|
||||||
} from "@gamecult/thing-contract";
|
|
||||||
|
|
||||||
const NS = "GameCult.Thing.Contract.";
|
|
||||||
const STRING = "System.String";
|
|
||||||
const list = (item: string) => `System.Collections.Generic.List<${NS}${item}>`;
|
|
||||||
|
|
||||||
const rustName: Record<string, string> = {
|
|
||||||
"gamecult.thing.surface": "SurfaceDocument",
|
|
||||||
"gamecult.thing.composition": "CompositionDocument",
|
|
||||||
"gamecult.thing.command_invocation": "CommandInvocation",
|
|
||||||
"gamecult.thing.command_result": "CommandResult",
|
|
||||||
"gamecult.thing.asset_catalog": "AssetCatalog",
|
|
||||||
};
|
|
||||||
|
|
||||||
const expected = [
|
|
||||||
[surfaceDocument, "gamecult.thing.surface", [
|
|
||||||
"0:ProviderId:" + STRING,
|
|
||||||
"1:Label:" + STRING,
|
|
||||||
"2:Version:System.Int64",
|
|
||||||
"3:Title:" + STRING,
|
|
||||||
`4:Root:${NS}Node`,
|
|
||||||
`5:Commands:${list("CommandDecl")}`,
|
|
||||||
]],
|
|
||||||
[compositionDocument, "gamecult.thing.composition", [
|
|
||||||
"0:Publisher:" + STRING,
|
|
||||||
"1:Name:" + STRING,
|
|
||||||
"2:Version:System.Int64",
|
|
||||||
`3:Params:${list("ParamDecl")}`,
|
|
||||||
`4:Body:${NS}Node`,
|
|
||||||
]],
|
|
||||||
[commandInvocationDocument, "gamecult.thing.command_invocation", [
|
|
||||||
"0:InvocationId:" + STRING,
|
|
||||||
"1:SurfaceKey:" + STRING,
|
|
||||||
"2:SurfaceVersion:System.Int64",
|
|
||||||
"3:Command:" + STRING,
|
|
||||||
`4:Payload:${NS}RecordPayload`,
|
|
||||||
`5:Captured:${list("CapturedInput")}`,
|
|
||||||
"6:Client:" + STRING,
|
|
||||||
"7:IssuedAt:" + STRING,
|
|
||||||
"8:Delegation:" + STRING,
|
|
||||||
]],
|
|
||||||
[commandResultDocument, "gamecult.thing.command_result", [
|
|
||||||
"0:InvocationId:" + STRING,
|
|
||||||
"1:Seq:System.Int32",
|
|
||||||
`2:Outcome:${NS}Outcome`,
|
|
||||||
]],
|
|
||||||
[assetCatalogDocument, "gamecult.thing.asset_catalog", [
|
|
||||||
"0:ProviderId:" + STRING,
|
|
||||||
"1:CatalogId:" + STRING,
|
|
||||||
"2:Version:System.Int64",
|
|
||||||
`3:Assets:${list("AssetEntry")}`,
|
|
||||||
]],
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
for (const [definition, type, members] of expected) {
|
|
||||||
test(`${type}: type, schema and catalog members`, () => {
|
|
||||||
assert.equal(definition.type, type);
|
|
||||||
assert.equal(definition.schemaName, type);
|
|
||||||
assert.equal(definition.schemaVersion, `${type}.v1`);
|
|
||||||
assert.equal(definition.codec?.typeName, `${NS}${rustName[type]}`);
|
|
||||||
assert.deepEqual(
|
|
||||||
definition.members?.map((member) => `${member.slot}:${member.memberName}:${member.typeName}`),
|
|
||||||
members,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test("the registry lists the five definitions, in the crate's order", () => {
|
|
||||||
assert.deepEqual(
|
|
||||||
thingContract.definitions.map((definition) => definition.type),
|
|
||||||
expected.map(([, type]) => type),
|
|
||||||
);
|
|
||||||
assert.equal(new Set(thingContract.definitions).size, 5);
|
|
||||||
});
|
|
||||||
|
|
@ -1,141 +0,0 @@
|
||||||
// A CommandResult exists only by a factory or by the decode door. Construction is attacked the way an outside consumer
|
|
||||||
// would: an object literal, JSON.parse output, structuredClone, spread, prototype tricks, the constructor, a Proxy. Each is
|
|
||||||
// refused where a result is encoded, and none is a CommandResult. The type-level half is test/types.ts.
|
|
||||||
import assert from "node:assert/strict";
|
|
||||||
import test from "node:test";
|
|
||||||
|
|
||||||
import { decodeDocumentPayload, documentPayloadBytes, documentPayloadFromBytes, encodeDocumentPayload } from "@gamecult/cultcache-ts";
|
|
||||||
import { CommandResult, commandResultDocument } from "@gamecult/thing-contract";
|
|
||||||
|
|
||||||
import { CANARY, golden, invocation, results } from "./builders.js";
|
|
||||||
|
|
||||||
const answered = invocation();
|
|
||||||
const encodeResult = (value: unknown) => () => encodeDocumentPayload(commandResultDocument, value);
|
|
||||||
const BUILT = /a CommandResult is built by its factories/;
|
|
||||||
|
|
||||||
test("a factory copies the invocation id and holds the seq", () => {
|
|
||||||
const result = CommandResult.failed(answered, 5, "broke");
|
|
||||||
assert.equal(result.invocationId, answered.invocationId);
|
|
||||||
assert.equal(result.seq, 5);
|
|
||||||
assert.deepEqual(result.outcome, { kind: "Failed", reason: "broke" });
|
|
||||||
assert.ok(result instanceof CommandResult);
|
|
||||||
assert.ok(CommandResult.isResult(result));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("each factory builds its outcome", () => {
|
|
||||||
assert.deepEqual(CommandResult.pending(answered, 1, "working").outcome, { kind: "Pending", message: "working" });
|
|
||||||
assert.deepEqual(CommandResult.completed(answered, 2, 8, true, null).outcome, {
|
|
||||||
kind: "Completed",
|
|
||||||
sourceVersion: 8,
|
|
||||||
clearDrafts: true,
|
|
||||||
effect: null,
|
|
||||||
});
|
|
||||||
assert.deepEqual(CommandResult.denied(answered, 3, "no", "go").outcome, { kind: "Denied", reason: "no", node: "go" });
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a factory refuses seq below 1 naming Seq, and not the value", () => {
|
|
||||||
for (const bad of [0, -1, -(2 ** 31)]) {
|
|
||||||
for (const build of [
|
|
||||||
() => CommandResult.pending(answered, bad, "m"),
|
|
||||||
() => CommandResult.completed(answered, bad, null, false, null),
|
|
||||||
() => CommandResult.denied(answered, bad, "r", null),
|
|
||||||
() => CommandResult.failed(answered, bad, "r"),
|
|
||||||
]) {
|
|
||||||
assert.throws(build, (error: Error) => /Seq must be at least 1/.test(error.message) && !error.message.includes(String(bad)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert.throws(() => CommandResult.failed(answered, 1.5, "r"), /int32/);
|
|
||||||
assert.throws(() => CommandResult.failed(answered, 2 ** 31, "r"), /int32/);
|
|
||||||
assert.equal(CommandResult.failed(answered, 2 ** 31 - 1, "r").seq, 2 ** 31 - 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("the decode door yields a CommandResult instance, equal to the factory's", () => {
|
|
||||||
for (const [file, value] of results(answered)) {
|
|
||||||
const decoded = decodeDocumentPayload(commandResultDocument, documentPayloadFromBytes(golden(`${file}.bin`)));
|
|
||||||
assert.ok(decoded instanceof CommandResult, file);
|
|
||||||
assert.ok(CommandResult.isResult(decoded), file);
|
|
||||||
assert.deepStrictEqual(decoded, value, file);
|
|
||||||
assert.ok(Object.isFrozen(decoded), file);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("encoding a result a factory built succeeds, and re-decodes", () => {
|
|
||||||
const result = CommandResult.pending(answered, 1, "working");
|
|
||||||
const bytes = documentPayloadBytes(encodeDocumentPayload(commandResultDocument, result));
|
|
||||||
assert.deepEqual(bytes, golden("result-pending.bin"));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a copy of a result is not a result: structuredClone, spread and JSON.parse output are refused at encode", () => {
|
|
||||||
const result = CommandResult.failed(answered, 7, "broke");
|
|
||||||
for (const [name, copy] of [
|
|
||||||
["structuredClone", structuredClone(result)],
|
|
||||||
["spread", { ...result }],
|
|
||||||
["JSON.parse", JSON.parse(JSON.stringify(result)) as unknown],
|
|
||||||
["Object.assign", Object.assign({}, result)],
|
|
||||||
] as const) {
|
|
||||||
assert.ok(!CommandResult.isResult(copy), name);
|
|
||||||
assert.ok(!(copy instanceof CommandResult), name);
|
|
||||||
assert.throws(encodeResult(copy), BUILT, name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("an object literal is not a result", () => {
|
|
||||||
const literal = { invocationId: answered.invocationId, seq: 1, outcome: { kind: "Failed", reason: "broke" } };
|
|
||||||
assert.ok(!CommandResult.isResult(literal));
|
|
||||||
assert.throws(encodeResult(literal), BUILT);
|
|
||||||
for (const other of [null, undefined, 0, "", "completed", [], {}, () => 0]) {
|
|
||||||
assert.ok(!CommandResult.isResult(other));
|
|
||||||
assert.throws(encodeResult(other), BUILT);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("prototype tricks do not make a result", () => {
|
|
||||||
const result = CommandResult.failed(answered, 7, "broke");
|
|
||||||
const viaCreate = Object.assign(Object.create(CommandResult.prototype) as object, result);
|
|
||||||
const viaSetPrototype = Object.setPrototypeOf({ ...result }, CommandResult.prototype) as object;
|
|
||||||
const viaProxy = new Proxy(result, {});
|
|
||||||
class Impostor extends (CommandResult as unknown as new () => object) {}
|
|
||||||
for (const [name, fake] of [["Object.create", viaCreate], ["setPrototypeOf", viaSetPrototype], ["Proxy", viaProxy]] as const) {
|
|
||||||
assert.ok(!CommandResult.isResult(fake), name);
|
|
||||||
assert.throws(encodeResult(fake), BUILT, name);
|
|
||||||
}
|
|
||||||
assert.throws(() => new Impostor(), BUILT);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("the constructor is closed at run time as well as in types", () => {
|
|
||||||
const construct = CommandResult as unknown as new (...args: unknown[]) => CommandResult;
|
|
||||||
const outcome = { kind: "Failed", reason: "broke" };
|
|
||||||
assert.throws(() => new construct(answered.invocationId, 1, outcome), BUILT);
|
|
||||||
assert.throws(() => new construct(Symbol("door"), answered.invocationId, 1, outcome), BUILT);
|
|
||||||
assert.throws(() => new construct(undefined, answered.invocationId, 0, outcome), BUILT);
|
|
||||||
assert.throws(() => Reflect.construct(construct, [answered.invocationId, 0, outcome]), BUILT);
|
|
||||||
assert.throws(() => Reflect.construct(construct, [], CommandResult), BUILT);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a result is frozen: a script that ignores types cannot move its seq out of domain", () => {
|
|
||||||
const result = CommandResult.failed(answered, 7, "broke");
|
|
||||||
assert.ok(Object.isFrozen(result));
|
|
||||||
const writable = result as unknown as { seq: number; invocationId: string };
|
|
||||||
assert.throws(() => {
|
|
||||||
writable.seq = 0;
|
|
||||||
}, TypeError);
|
|
||||||
assert.throws(() => {
|
|
||||||
writable.invocationId = "other";
|
|
||||||
}, TypeError);
|
|
||||||
assert.equal(result.seq, 7);
|
|
||||||
assert.equal(result.invocationId, answered.invocationId);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("an out-of-domain seq cannot cross the decode door, and no message echoes the payload", () => {
|
|
||||||
const message = (run: () => unknown) => {
|
|
||||||
try {
|
|
||||||
run();
|
|
||||||
} catch (error) {
|
|
||||||
return (error as Error).message;
|
|
||||||
}
|
|
||||||
return assert.fail("expected a refusal");
|
|
||||||
};
|
|
||||||
const refused = message(() => decodeDocumentPayload(commandResultDocument, documentPayloadFromBytes(golden("result-seq-zero.bin"))));
|
|
||||||
assert.match(refused, /Seq must be at least 1/);
|
|
||||||
assert.ok(!refused.includes(CANARY));
|
|
||||||
});
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
// The value goldens: each file is what the Rust crate writes for the builder's value. Encoding the ported builder gives
|
|
||||||
// the file byte for byte, decoding the file gives the value back, and re-encoding what was decoded gives the file again.
|
|
||||||
import assert from "node:assert/strict";
|
|
||||||
import test from "node:test";
|
|
||||||
|
|
||||||
import {
|
|
||||||
decodeDocumentPayload,
|
|
||||||
documentPayloadBytes,
|
|
||||||
documentPayloadFromBytes,
|
|
||||||
encodeDocumentPayload,
|
|
||||||
} from "@gamecult/cultcache-ts";
|
|
||||||
import {
|
|
||||||
assetCatalogDocument,
|
|
||||||
commandInvocationDocument,
|
|
||||||
commandResultDocument,
|
|
||||||
compositionDocument,
|
|
||||||
surfaceDocument,
|
|
||||||
} from "@gamecult/thing-contract";
|
|
||||||
|
|
||||||
import { assetCatalogValue, fullComposition, fullSurface, golden, invocation, results } from "./builders.js";
|
|
||||||
|
|
||||||
type Case = [file: string, definition: Parameters<typeof encodeDocumentPayload>[0], value: unknown];
|
|
||||||
|
|
||||||
const answered = invocation();
|
|
||||||
const cases: Case[] = [
|
|
||||||
["surface-all-arms.bin", surfaceDocument, fullSurface()],
|
|
||||||
["composition-all-params.bin", compositionDocument, fullComposition()],
|
|
||||||
["invocation-all-inputs.bin", commandInvocationDocument, answered],
|
|
||||||
...results(answered).map(([name, value]): Case => [`${name}.bin`, commandResultDocument, value]),
|
|
||||||
["asset-catalog.bin", assetCatalogDocument, assetCatalogValue()],
|
|
||||||
];
|
|
||||||
|
|
||||||
test("the case table names the eleven value goldens", () => {
|
|
||||||
assert.equal(cases.length, 11);
|
|
||||||
assert.equal(new Set(cases.map(([file]) => file)).size, 11);
|
|
||||||
assert.equal(cases.filter(([, definition]) => definition === commandResultDocument).length, 7);
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const [file, definition, value] of cases) {
|
|
||||||
test(`${file}: the builder encodes to the golden, the golden decodes to the builder, and re-encodes identical`, () => {
|
|
||||||
const committed = golden(file);
|
|
||||||
assert.deepEqual(documentPayloadBytes(encodeDocumentPayload(definition, value)), committed);
|
|
||||||
|
|
||||||
const decoded = decodeDocumentPayload(definition, documentPayloadFromBytes(committed));
|
|
||||||
assert.deepStrictEqual(decoded, value);
|
|
||||||
assert.deepEqual(documentPayloadBytes(encodeDocumentPayload(definition, decoded)), committed);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
// The key grammar of crates/thing-contract/src/keys.rs and the cases of tests/result.rs: keys are built from the fields,
|
|
||||||
// every local segment is a Segment, and two different field sets never build one key.
|
|
||||||
import assert from "node:assert/strict";
|
|
||||||
import test from "node:test";
|
|
||||||
|
|
||||||
import { assetCatalogKey, compositionKey, invocationKey, resultKey, surfaceKey } from "@gamecult/thing-contract";
|
|
||||||
|
|
||||||
import { CANARY } from "./builders.js";
|
|
||||||
|
|
||||||
const builders: [string, (segment: string) => string][] = [
|
|
||||||
["surfaceKey", (segment) => surfaceKey("p", segment)],
|
|
||||||
["compositionKey name", (segment) => compositionKey("pub", segment, 1)],
|
|
||||||
["assetCatalogKey", (segment) => assetCatalogKey("p", segment)],
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const [name, build] of builders) {
|
|
||||||
test(`${name} refuses an empty, a dot and a dotted segment, naming Segment and not the value`, () => {
|
|
||||||
assert.throws(() => build(""), /Segment must be non-empty/);
|
|
||||||
assert.throws(() => build("."), /Segment must be free of '\.'/);
|
|
||||||
assert.throws(() => build("a.b"), /Segment must be free of '\.'/);
|
|
||||||
assert.throws(
|
|
||||||
() => build(`${CANARY}.x`),
|
|
||||||
(error: Error) => /Segment/.test(error.message) && !error.message.includes(CANARY),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test("the keys are spelled from the fields", () => {
|
|
||||||
assert.equal(invocationKey("an-invocation-no-constructor-can-guess"), "thing:invocation:an-invocation-no-constructor-can-guess");
|
|
||||||
assert.equal(resultKey("an-invocation-no-constructor-can-guess", 3), "thing:result:an-invocation-no-constructor-can-guess.3");
|
|
||||||
assert.equal(surfaceKey("p", "main"), "thing:surface:p.main");
|
|
||||||
assert.equal(compositionKey("pub", "card", 2), "thing:composition:pub.card.v2");
|
|
||||||
assert.equal(compositionKey("pub", "card", 2n ** 40n), "thing:composition:pub.card.v1099511627776");
|
|
||||||
assert.equal(assetCatalogKey("p", "icons"), "thing:asset_catalog:p.icons");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a result key refuses a seq below 1 and a composition key a version below 0", () => {
|
|
||||||
assert.throws(() => resultKey("x", 0), /Seq must be at least 1/);
|
|
||||||
assert.throws(() => compositionKey("pub", "card", -1), /Version must be at least 0/);
|
|
||||||
assert.equal(compositionKey("pub", "card", 0), "thing:composition:pub.card.v0");
|
|
||||||
assert.throws(() => compositionKey("pub", "card", 1.5), /int64/);
|
|
||||||
assert.throws(() => resultKey("x", 1.5), /int32/);
|
|
||||||
assert.throws(() => resultKey("x", 2 ** 31), /int32/);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("keys are injective over their field sets", () => {
|
|
||||||
// A dotted provider with a plain label, and a plain provider with a dotted label: the second cannot be built.
|
|
||||||
assert.equal(surfaceKey("a.b", "c"), "thing:surface:a.b.c");
|
|
||||||
assert.throws(() => surfaceKey("a", "b.c"), /Segment/);
|
|
||||||
assert.notEqual(surfaceKey("a", "c"), surfaceKey("a.b", "c"));
|
|
||||||
assert.notEqual(surfaceKey("a.b", "c"), surfaceKey("a", "bc"));
|
|
||||||
|
|
||||||
// A composition splits at its last two dots: publisher, name, then the version.
|
|
||||||
assert.equal(compositionKey("a.b", "c", 1), "thing:composition:a.b.c.v1");
|
|
||||||
assert.notEqual(compositionKey("a.b", "c", 1), compositionKey("a", "bc", 1));
|
|
||||||
assert.notEqual(compositionKey("a", "c", 1), compositionKey("a", "c", 11));
|
|
||||||
assert.notEqual(compositionKey("a", "c", 1), compositionKey("a", "c", 0));
|
|
||||||
|
|
||||||
// A catalog likewise, under the asset_catalog prefix.
|
|
||||||
assert.equal(assetCatalogKey("a.b", "c"), "thing:asset_catalog:a.b.c");
|
|
||||||
assert.notEqual(assetCatalogKey("a.b", "c"), assetCatalogKey("a", "bc"));
|
|
||||||
|
|
||||||
// A result splits at its last dot, and the seq is digits.
|
|
||||||
assert.equal(resultKey("x.1", 2), "thing:result:x.1.2");
|
|
||||||
assert.equal(resultKey("x", 12), "thing:result:x.12");
|
|
||||||
assert.notEqual(resultKey("x.1", 2), resultKey("x", 12));
|
|
||||||
});
|
|
||||||
|
|
@ -1,148 +0,0 @@
|
||||||
// The refusal goldens and the domain doors. A payload is refused by name (the union and the arm key, or the domain), and
|
|
||||||
// no message echoes a value: the goldens carry CANARY in the slots a refusal must not repeat.
|
|
||||||
import assert from "node:assert/strict";
|
|
||||||
import test from "node:test";
|
|
||||||
|
|
||||||
import {
|
|
||||||
decodeDocumentPayload,
|
|
||||||
defineDocumentType,
|
|
||||||
documentPayloadFromBytes,
|
|
||||||
encodeDocumentPayload,
|
|
||||||
} from "@gamecult/cultcache-ts";
|
|
||||||
import {
|
|
||||||
CommandResult,
|
|
||||||
assetCatalogDocument,
|
|
||||||
codecs,
|
|
||||||
commandResultDocument,
|
|
||||||
domain,
|
|
||||||
surfaceDocument,
|
|
||||||
} from "@gamecult/thing-contract";
|
|
||||||
|
|
||||||
import { CANARY, assetCatalogValue, fullSurface, golden, invocation } from "./builders.js";
|
|
||||||
|
|
||||||
const rgbaDocument = defineDocumentType({
|
|
||||||
type: "test.rgba",
|
|
||||||
schema: { parse: (input: unknown) => input },
|
|
||||||
codec: codecs.rgba,
|
|
||||||
});
|
|
||||||
|
|
||||||
function refusal(run: () => unknown): string {
|
|
||||||
try {
|
|
||||||
run();
|
|
||||||
} catch (error) {
|
|
||||||
assert.ok(error instanceof Error);
|
|
||||||
assert.ok(!error.message.includes(CANARY), `the refusal echoed a value: ${error.message}`);
|
|
||||||
return error.message;
|
|
||||||
}
|
|
||||||
return assert.fail("expected a refusal");
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (definition: Parameters<typeof decodeDocumentPayload>[0], file: string) => () =>
|
|
||||||
decodeDocumentPayload(definition, documentPayloadFromBytes(golden(file)));
|
|
||||||
|
|
||||||
test("a Thing 1 flat map is not a command result", () => {
|
|
||||||
refusal(read(commandResultDocument, "result-thing1-flat.bin"));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("an unknown Node arm is refused naming the union and the key", () => {
|
|
||||||
assert.match(refusal(read(surfaceDocument, "node-unknown-arm.bin")), /Union Node: unknown arm key 13/);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("an unknown Outcome arm is refused naming the union and the key", () => {
|
|
||||||
assert.match(refusal(read(commandResultDocument, "outcome-unknown-arm.bin")), /Union Outcome: unknown arm key 4/);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("an extra trailing slot is read and never written back", () => {
|
|
||||||
const decoded = decodeDocumentPayload(commandResultDocument, documentPayloadFromBytes(golden("result-extra-slot.bin")));
|
|
||||||
const expected = CommandResult.pending({ ...invocation(), invocationId: "inv-1" }, 1, "working");
|
|
||||||
assert.deepStrictEqual(decoded, expected);
|
|
||||||
assert.ok(!JSON.stringify(decoded).includes(CANARY));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("each domain golden is refused naming its domain", () => {
|
|
||||||
assert.match(refusal(read(commandResultDocument, "result-seq-zero.bin")), /Seq must be at least 1/);
|
|
||||||
assert.match(refusal(read(surfaceDocument, "surface-version-negative.bin")), /Version must be at least 0/);
|
|
||||||
assert.match(refusal(read(surfaceDocument, "surface-label-dotted.bin")), /Segment must be free of '\.'/);
|
|
||||||
assert.match(refusal(read(assetCatalogDocument, "asset-extent-negative.bin")), /Count must be at least 0/);
|
|
||||||
assert.match(refusal(read(rgbaDocument, "rgba-channel-out-of-range.bin")), /Rgba channel must be 0 to 255/);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("the encode door holds the same domains", () => {
|
|
||||||
const surface = fullSurface();
|
|
||||||
const catalog = assetCatalogValue();
|
|
||||||
const encodeSurface = (value: unknown) => () => encodeDocumentPayload(surfaceDocument, value);
|
|
||||||
assert.match(refusal(encodeSurface({ ...surface, label: `${CANARY}.x` })), /Segment must be free of '\.'/);
|
|
||||||
assert.match(refusal(encodeSurface({ ...surface, label: "" })), /Segment must be non-empty/);
|
|
||||||
assert.match(refusal(encodeSurface({ ...surface, label: null })), /label/);
|
|
||||||
assert.match(refusal(encodeSurface({ ...surface, version: -1 })), /Version must be at least 0/);
|
|
||||||
assert.match(refusal(encodeSurface({ ...surface, version: -(2n ** 40n) })), /Version must be at least 0/);
|
|
||||||
assert.match(
|
|
||||||
refusal(() => encodeDocumentPayload(assetCatalogDocument, { ...catalog, assets: [{ ...catalog.assets[0], width: -5 }] })),
|
|
||||||
/Count must be at least 0/,
|
|
||||||
);
|
|
||||||
assert.match(
|
|
||||||
refusal(() => encodeDocumentPayload(rgbaDocument, { r: 256, g: 0, b: 0, a: 255 })),
|
|
||||||
/Rgba channel must be 0 to 255/,
|
|
||||||
);
|
|
||||||
assert.match(
|
|
||||||
refusal(() => encodeDocumentPayload(rgbaDocument, { r: 0, g: -1, b: 0, a: 255 })),
|
|
||||||
/Rgba channel must be 0 to 255/,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("each domain accepts its boundary values and refuses the step beyond, on both doors", () => {
|
|
||||||
assert.equal(domain.seq.decode(1), 1);
|
|
||||||
assert.equal(domain.seq.decode(2 ** 31 - 1), 2 ** 31 - 1);
|
|
||||||
assert.throws(() => domain.seq.decode(0), /Seq must be at least 1/);
|
|
||||||
assert.throws(() => domain.seq.decode(2 ** 31), /int32/);
|
|
||||||
assert.throws(() => domain.seq.encode(0), /Seq must be at least 1/);
|
|
||||||
assert.equal(domain.seq.encode(1), 1);
|
|
||||||
assert.equal(domain.version.decode(0), 0);
|
|
||||||
assert.equal(domain.version.decode(2n ** 62n), 2n ** 62n);
|
|
||||||
assert.throws(() => domain.version.decode(-1), /Version must be at least 0/);
|
|
||||||
assert.throws(() => domain.version.encode(-1n), /Version must be at least 0/);
|
|
||||||
assert.equal(domain.version.encode(0), 0);
|
|
||||||
assert.equal(domain.count.decode(0), 0);
|
|
||||||
assert.throws(() => domain.count.decode(-1), /Count must be at least 0/);
|
|
||||||
assert.throws(() => domain.count.encode(-1), /Count must be at least 0/);
|
|
||||||
assert.equal(domain.count.encode(0), 0);
|
|
||||||
assert.equal(domain.segment.decode("a"), "a");
|
|
||||||
assert.throws(() => domain.segment.decode(""), /Segment must be non-empty/);
|
|
||||||
assert.throws(() => domain.segment.decode("."), /Segment must be free of '\.'/);
|
|
||||||
assert.throws(() => domain.segment.encode("a.b"), /Segment must be free of '\.'/);
|
|
||||||
assert.throws(() => domain.segment.encode(""), /Segment must be non-empty/);
|
|
||||||
assert.equal(domain.segment.encode("a"), "a");
|
|
||||||
assert.equal(domain.channel.decode(0), 0);
|
|
||||||
assert.equal(domain.channel.decode(255), 255);
|
|
||||||
assert.throws(() => domain.channel.decode(256), /Rgba channel must be 0 to 255/);
|
|
||||||
assert.throws(() => domain.channel.decode(-1), /Rgba channel must be 0 to 255/);
|
|
||||||
assert.throws(() => domain.channel.encode(256), /Rgba channel must be 0 to 255/);
|
|
||||||
assert.throws(() => domain.channel.encode(-1), /Rgba channel must be 0 to 255/);
|
|
||||||
assert.equal(domain.channel.encode(255), 255);
|
|
||||||
assert.equal(domain.channel.encode(0), 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a domain refusal never echoes the value", () => {
|
|
||||||
for (const run of [
|
|
||||||
() => domain.segment.decode(`${CANARY}.x`),
|
|
||||||
() => domain.seq.decode(-777),
|
|
||||||
() => domain.version.decode(-777),
|
|
||||||
() => domain.count.decode(-777),
|
|
||||||
() => domain.channel.decode(777),
|
|
||||||
() => domain.seq.encode(-777),
|
|
||||||
() => domain.channel.encode(777),
|
|
||||||
]) {
|
|
||||||
const message = refusal(run);
|
|
||||||
assert.ok(!message.includes("777"), message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a domain codec reports the reference's leaf type name", () => {
|
|
||||||
assert.equal(domain.seq.typeName, "System.Int32");
|
|
||||||
assert.equal(domain.count.typeName, "System.Int32");
|
|
||||||
assert.equal(domain.channel.typeName, "System.Int32");
|
|
||||||
assert.equal(domain.version.typeName, "System.Int64");
|
|
||||||
assert.equal(domain.segment.typeName, "System.String");
|
|
||||||
assert.equal(domain.version.valueType, true);
|
|
||||||
assert.equal(domain.segment.valueType, true);
|
|
||||||
});
|
|
||||||
|
|
@ -1,84 +0,0 @@
|
||||||
// surface.cc is a single-file store the Rust crate wrote with one record of each kind under a pinned clock. Opened through
|
|
||||||
// CultCache with the five definitions it yields five records, each re-encodes to its value golden's bytes, and each record
|
|
||||||
// key equals the key keys.ts builds from the value.
|
|
||||||
import assert from "node:assert/strict";
|
|
||||||
import { join } from "node:path";
|
|
||||||
import test from "node:test";
|
|
||||||
|
|
||||||
import { CultCache, SingleFileMessagePackBackingStore, documentPayloadBytes } from "@gamecult/cultcache-ts";
|
|
||||||
import {
|
|
||||||
CommandResult,
|
|
||||||
assetCatalogDocument,
|
|
||||||
assetCatalogKey,
|
|
||||||
commandInvocationDocument,
|
|
||||||
commandResultDocument,
|
|
||||||
compositionDocument,
|
|
||||||
compositionKey,
|
|
||||||
invocationKey,
|
|
||||||
resultKey,
|
|
||||||
surfaceDocument,
|
|
||||||
surfaceKey,
|
|
||||||
thingContract,
|
|
||||||
} from "@gamecult/thing-contract";
|
|
||||||
|
|
||||||
import { PINNED_CLOCK, assetCatalogValue, fullComposition, fullSurface, golden, goldensDir, invocation } from "./builders.js";
|
|
||||||
|
|
||||||
async function open() {
|
|
||||||
const cache = CultCache.builder()
|
|
||||||
.withRegistry(thingContract)
|
|
||||||
.withGenericStore(new SingleFileMessagePackBackingStore(join(goldensDir, "surface.cc")))
|
|
||||||
.build();
|
|
||||||
await cache.pullAllBackingStores();
|
|
||||||
return cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
test("surface.cc opens to one record of each of the five kinds", async () => {
|
|
||||||
const cache = await open();
|
|
||||||
const snapshot = cache.snapshot();
|
|
||||||
assert.equal(snapshot.length, 5);
|
|
||||||
assert.deepEqual(
|
|
||||||
snapshot.map((envelope) => envelope.type).sort(),
|
|
||||||
[
|
|
||||||
"gamecult.thing.asset_catalog",
|
|
||||||
"gamecult.thing.command_invocation",
|
|
||||||
"gamecult.thing.command_result",
|
|
||||||
"gamecult.thing.composition",
|
|
||||||
"gamecult.thing.surface",
|
|
||||||
],
|
|
||||||
);
|
|
||||||
for (const envelope of snapshot) assert.equal(envelope.storedAt, PINNED_CLOCK);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("each record equals its value and re-encodes to its value golden", async () => {
|
|
||||||
const cache = await open();
|
|
||||||
const surface = fullSurface();
|
|
||||||
const composition = fullComposition();
|
|
||||||
const answered = invocation();
|
|
||||||
const result = CommandResult.pending(answered, 1, "working");
|
|
||||||
const catalog = assetCatalogValue();
|
|
||||||
|
|
||||||
const surfaceRecordKey = surfaceKey(surface.providerId, surface.label);
|
|
||||||
const compositionRecordKey = compositionKey(composition.publisher, composition.name, composition.version);
|
|
||||||
const invocationRecordKey = invocationKey(answered.invocationId);
|
|
||||||
const resultRecordKey = resultKey(result.invocationId, result.seq);
|
|
||||||
const catalogRecordKey = assetCatalogKey(catalog.providerId, catalog.catalogId);
|
|
||||||
|
|
||||||
assert.deepStrictEqual(cache.getRequired(surfaceDocument, surfaceRecordKey), surface);
|
|
||||||
assert.deepStrictEqual(cache.getRequired(compositionDocument, compositionRecordKey), composition);
|
|
||||||
assert.deepStrictEqual(cache.getRequired(commandInvocationDocument, invocationRecordKey), answered);
|
|
||||||
assert.deepStrictEqual(cache.getRequired(commandResultDocument, resultRecordKey), result);
|
|
||||||
assert.deepStrictEqual(cache.getRequired(assetCatalogDocument, catalogRecordKey), catalog);
|
|
||||||
|
|
||||||
const goldenOf: Record<string, string> = {
|
|
||||||
[surfaceRecordKey]: "surface-all-arms.bin",
|
|
||||||
[compositionRecordKey]: "composition-all-params.bin",
|
|
||||||
[invocationRecordKey]: "invocation-all-inputs.bin",
|
|
||||||
[resultRecordKey]: "result-pending.bin",
|
|
||||||
[catalogRecordKey]: "asset-catalog.bin",
|
|
||||||
};
|
|
||||||
const snapshot = cache.snapshot();
|
|
||||||
assert.deepEqual(snapshot.map((envelope) => envelope.key).sort(), Object.keys(goldenOf).sort());
|
|
||||||
for (const envelope of snapshot) {
|
|
||||||
assert.deepEqual(documentPayloadBytes(envelope.payload), golden(goldenOf[envelope.key]), envelope.key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
// Compile-time half of the construction rules, compiled by tsconfig.test.json: every @ts-expect-error line must be an
|
|
||||||
// error, or the compile fails. This file runs nothing.
|
|
||||||
import { CommandResult } from "@gamecult/thing-contract";
|
|
||||||
import type { CommandInvocation, Handler, Outcome } from "@gamecult/thing-contract";
|
|
||||||
|
|
||||||
declare const invocation: CommandInvocation;
|
|
||||||
declare const result: CommandResult;
|
|
||||||
declare const plain: { invocationId: string; seq: number; outcome: Outcome };
|
|
||||||
|
|
||||||
// An object literal does not satisfy CommandResult, because the class carries a private brand.
|
|
||||||
// @ts-expect-error
|
|
||||||
export const literal: CommandResult = { invocationId: "x", seq: 1, outcome: { kind: "Failed", reason: "r" } };
|
|
||||||
|
|
||||||
// Nor does a plain value of the same shape, nor a spread of a result.
|
|
||||||
// @ts-expect-error
|
|
||||||
export const shaped: CommandResult = plain;
|
|
||||||
// @ts-expect-error
|
|
||||||
export const spread: CommandResult = { ...result };
|
|
||||||
|
|
||||||
// The constructor is private: even a call whose arguments all type-check (the door argument is typed `never` here) is
|
|
||||||
// refused, so the error is the access, not the arity.
|
|
||||||
// @ts-expect-error
|
|
||||||
export const constructed = new CommandResult(undefined as never, "x", 1, { kind: "Failed", reason: "r" });
|
|
||||||
|
|
||||||
// The fields are read-only.
|
|
||||||
// @ts-expect-error
|
|
||||||
result.seq = 2;
|
|
||||||
// @ts-expect-error
|
|
||||||
result.invocationId = "y";
|
|
||||||
// @ts-expect-error
|
|
||||||
result.outcome = { kind: "Failed", reason: "r" };
|
|
||||||
|
|
||||||
// An Outcome is a tagged value, never a state string.
|
|
||||||
// @ts-expect-error
|
|
||||||
export const stringOutcome: Outcome = "completed";
|
|
||||||
// @ts-expect-error
|
|
||||||
export const stringFactory = CommandResult.failed(invocation, 1, "r", "completed", 3);
|
|
||||||
// @ts-expect-error
|
|
||||||
export const noInvocation = CommandResult.failed("inv-1", 1, "r");
|
|
||||||
// @ts-expect-error
|
|
||||||
export const stateInHandler: Handler = (): string => "completed";
|
|
||||||
|
|
||||||
// The positive cases compile.
|
|
||||||
export const built: CommandResult = CommandResult.failed(invocation, 1, "r");
|
|
||||||
export const handler: Handler = async () => ({ kind: "Pending", message: "m" });
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"declaration": true,
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"newLine": "lf",
|
|
||||||
"noEmitOnError": true,
|
|
||||||
"outDir": "dist",
|
|
||||||
"rootDir": "src",
|
|
||||||
"strict": true,
|
|
||||||
"target": "ES2022"
|
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts"]
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"newLine": "lf",
|
|
||||||
"noEmitOnError": true,
|
|
||||||
"outDir": "dist-test",
|
|
||||||
"rootDir": ".",
|
|
||||||
"strict": true,
|
|
||||||
"target": "ES2022",
|
|
||||||
"types": ["node"]
|
|
||||||
},
|
|
||||||
"include": ["test/**/*.ts", "src/**/*.ts"]
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue