@wildshard/shard-format 0.85.0 → 0.87.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/format/headless-sections.ts +2 -0
- package/src/format/json-schema.ts +2 -0
- package/src/format/outputFields.ts +1 -0
- package/src/format/platformDataSections.ts +5 -0
- package/src/format/returnProjectionV2.ts +68 -6
- package/src/format/script-side-projections.ts +93 -0
- package/src/format/script-sides.ts +48 -51
- package/src/format/scriptContract.ts +6 -4
- package/src/format/sections.ts +3 -0
- package/src/format/sim-reads-v2.ts +169 -0
- package/src/format/weatherProgram.ts +8 -1
- package/src/tools/runtime-hosts.json +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.87.0",
|
|
4
4
|
"description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -315,6 +315,7 @@
|
|
|
315
315
|
"./registeredJson": "./src/format/registeredJson.ts",
|
|
316
316
|
"./returnProgramDocument": "./src/format/returnProgramDocument.ts",
|
|
317
317
|
"./returnProjectionV2": "./src/format/returnProjectionV2.ts",
|
|
318
|
+
"./sim-reads-v2": "./src/format/sim-reads-v2.ts",
|
|
318
319
|
"./riding": "./src/format/riding.ts",
|
|
319
320
|
"./riggedHulls": "./src/format/riggedHulls.ts",
|
|
320
321
|
"./roamingBossProjection": "./src/format/roamingBossProjection.ts",
|
|
@@ -20,6 +20,8 @@ export const HEADLESS_CONTEXT_SECTIONS = [
|
|
|
20
20
|
'client/plan',
|
|
21
21
|
// SHARD-COMPAT HS6: the server reads its feature rows (the portal ride among them) from its own plan only.
|
|
22
22
|
'server/plan',
|
|
23
|
+
// WASM-HOST H18: what the sim reads of a body or a slot, which the server runs as project modules.
|
|
24
|
+
'sim/reads',
|
|
23
25
|
] as const
|
|
24
26
|
|
|
25
27
|
/** Explicit admitted decision/move context crossing the worker boundary; no ABI is inferred from bytes. */
|
|
@@ -325,6 +325,7 @@ import {
|
|
|
325
325
|
FarSchema,
|
|
326
326
|
SpawnSchema,
|
|
327
327
|
} from './shardSections.ts'
|
|
328
|
+
import { SimReadsV2Schema } from './sim-reads-v2.ts'
|
|
328
329
|
import {
|
|
329
330
|
CreatureSkinClipNameSchema,
|
|
330
331
|
SkinClipNameSchema,
|
|
@@ -792,6 +793,7 @@ const wireRoots: Readonly<Record<string, GenericSchema>> = {
|
|
|
792
793
|
'practiceCourseRows.Controller': PracticeControllerSchema,
|
|
793
794
|
'scalarChannel.ScalarTriplet': ScalarTripletSchema,
|
|
794
795
|
'returnProjectionV2.ReturnProjectionV2': ReturnProjectionV2Schema,
|
|
796
|
+
'sim-reads-v2.SimReadsV2': SimReadsV2Schema,
|
|
795
797
|
'scriptContract.ReturnModules': ReturnModulesSchema,
|
|
796
798
|
'nativePhysics.NativeGroundFile': NativeGroundFileSchema,
|
|
797
799
|
'worldAssembly.WorldAssembly': WorldAssemblySchema,
|
|
@@ -35,6 +35,8 @@ import { WorldPhysicsSchema, type WorldPhysics } from './worldPhysics.ts';
|
|
|
35
35
|
import { WorldTargetsSchema, type WorldTargets } from './worldTargets.ts';
|
|
36
36
|
import { WorldMoversSchema } from './movers.ts';
|
|
37
37
|
import { SimModulesSchema } from './numeric-frame-v2.ts';
|
|
38
|
+
import { SimReadsV2Schema } from './sim-reads-v2.ts';
|
|
39
|
+
import type { SimReadV2Row } from './sim-reads-v2.ts';
|
|
38
40
|
import { ReturnModulesSchema, type ReturnModuleRow, ViewModulesSchema, type ViewModuleRow } from './scriptContract.ts';
|
|
39
41
|
import { NativeRuntimePlanSchema, type NativeRuntimePlanData } from './nativeRuntimePlan.ts';
|
|
40
42
|
import { TreeSetSchema, type TreeSetRows } from './treeSetRows.ts';
|
|
@@ -63,6 +65,8 @@ export interface PlatformDataSections {
|
|
|
63
65
|
'server/world': ServerWorld;
|
|
64
66
|
'view/modules': ViewModuleRow[];
|
|
65
67
|
'sim/modules': v.InferOutput<typeof SimModulesSchema>;
|
|
68
|
+
/** WASM-HOST H18: what the sim reads of a body or slot, as project modules the server runs (simReadsV2.ts). */
|
|
69
|
+
'sim/reads': SimReadV2Row[];
|
|
66
70
|
'held/arms': HeldArmsRows;
|
|
67
71
|
'held/gear': HeldGearRows;
|
|
68
72
|
'held/finishes': HeldFinishesRows;
|
|
@@ -106,6 +110,7 @@ export const PLATFORM_DATA_SECTIONS: Readonly<{ [Name in keyof PlatformDataSecti
|
|
|
106
110
|
'server/world': { schema: ServerWorldSchema },
|
|
107
111
|
'view/modules': { schema: ViewModulesSchema },
|
|
108
112
|
'sim/modules': { schema: SimModulesSchema },
|
|
113
|
+
'sim/reads': { schema: SimReadsV2Schema },
|
|
109
114
|
'held/arms': { schema: HeldArmsSchema },
|
|
110
115
|
'held/gear': { schema: HeldGearSchema },
|
|
111
116
|
'held/finishes': { schema: HeldFinishesSchema },
|
|
@@ -9,18 +9,69 @@ import { layoutV2, type V2Layout } from './scriptWireV2.ts';
|
|
|
9
9
|
const bindingName=v.pipe(v.string(),v.minLength(1),v.maxLength(512),v.regex(/^(?!__proto__$|prototype$|constructor$)/));
|
|
10
10
|
const additionalNames=v.pipe(v.array(bindingName),v.maxLength(256));
|
|
11
11
|
const names=v.pipe(v.array(bindingName),v.minLength(1),v.maxLength(256));
|
|
12
|
+
const queryNames=v.strictTuple([v.literal('groundHeight')]);
|
|
13
|
+
const queriesSchema=v.exactOptional(queryNames);
|
|
14
|
+
const MIN_BATCH_REQUESTS = 2;
|
|
15
|
+
const MAX_BATCH_REQUESTS = 64;
|
|
16
|
+
const MIN_BATCH_ROWS = 1;
|
|
17
|
+
const MAX_BATCH_ROWS = 8192;
|
|
18
|
+
const batchRequests=v.pipe(v.number(),v.integer(),v.minValue(MIN_BATCH_REQUESTS),v.maxValue(MAX_BATCH_REQUESTS));
|
|
19
|
+
const batchRowCount=v.pipe(v.number(),v.integer(),v.minValue(MIN_BATCH_ROWS),v.maxValue(MAX_BATCH_ROWS));
|
|
20
|
+
const batchRows=v.strictObject({requests:batchRequests,rows:batchRowCount});
|
|
21
|
+
const batchSchema=v.exactOptional(batchRows);
|
|
12
22
|
export const ReturnProjectionV2Schema: v.GenericSchema<ReturnProjectionV2RowsInput, ReturnProjectionV2Rows> = v.strictObject({ artifact: v.strictObject({...ScriptArtifactV2Schema.entries,lane:v.literal('project')}),
|
|
13
|
-
fields: names,signals: names,channels: names,additional:v.exactOptional(v.strictObject({fields:additionalNames,signals:additionalNames,channels:additionalNames})),outputCapacity:v.exactOptional(v.pipe(v.number(),v.integer(),v.minValue(1),v.maxValue(128))),bytes: v.pipe(v.string(),v.maxLength(2_000_000)),groups: v.exactOptional(GroupStepV2Schema) });
|
|
23
|
+
fields: names,signals: names,channels: names,additional:v.exactOptional(v.strictObject({fields:additionalNames,signals:additionalNames,channels:additionalNames})),outputCapacity:v.exactOptional(v.pipe(v.number(),v.integer(),v.minValue(1),v.maxValue(128))),queries:queriesSchema,batch:batchSchema,bytes: v.pipe(v.string(),v.maxLength(2_000_000)),groups: v.exactOptional(GroupStepV2Schema) });
|
|
14
24
|
|
|
15
25
|
/** Nine detached field frames retain actor zero plus the original eight ordered
|
|
16
26
|
* candidates. Missing fields remain absent and refuse only if actually read. */
|
|
17
|
-
|
|
27
|
+
/** WASM-HOST H13: a projection that declares `queries` may ask its owner host for the ground height under a point. A
|
|
28
|
+
* height the frame does not answer is a miss (kind 11: the query kind 3 and x, z); the host answers every miss (kind 12
|
|
29
|
+
* replies, each keyed in kind 13 by its kind and seven inputs, then its height) and runs the request again, up to
|
|
30
|
+
* RETURN_PROJECTION_V2_ROUNDS times. Without `queries` the frame is unchanged. */
|
|
31
|
+
const QUERY_MISSES = 16;
|
|
32
|
+
const QUERY_REPLIES = 32;
|
|
33
|
+
const QUERY_KEY = 8;
|
|
34
|
+
const QUERY_ROUNDS = 8;
|
|
35
|
+
const RETURN_PROJECTION_V2_QUERIES: Readonly<{ misses: number; replies: number; key: number; rounds: number }> = Object.freeze({ misses: QUERY_MISSES,replies: QUERY_REPLIES,key: QUERY_KEY,rounds: QUERY_ROUNDS });
|
|
36
|
+
/** WASM-HOST H13: a projection that declares `batch` also answers up to `requests` independent requests in one call (one
|
|
37
|
+
* reset, one crossing; R1-17). Each request has three parameters (kind 4: its signal, its first field row, its row count)
|
|
38
|
+
* and its fields as sparse rows (kind 6: actor * fields + field + 1, present, value; `rows` in all), and tags each output
|
|
39
|
+
* (kind 10) with its request index. Misses and replies scale with `requests`. */
|
|
40
|
+
interface ReturnProjectionV2Batch { readonly requests: number; readonly rows: number }
|
|
41
|
+
/** Region kinds of the projection frame. */
|
|
42
|
+
const KIND = Object.freeze({ binding: 1,parameters: 4,state: 5,fields: 6,outputs: 10,misses: 11,replies: 12,replyData: 13,rng: 21,rngOut: 22 });
|
|
43
|
+
/** Nine field frames per request: the observations and eight candidates; three parameters per batch request. */
|
|
44
|
+
const FRAMES = 9;
|
|
45
|
+
const REQUEST_PARAMETERS = 3;
|
|
46
|
+
const ONE = 1;
|
|
47
|
+
const NONE = 0;
|
|
48
|
+
function validBatch(batch: ReturnProjectionV2Batch): boolean {
|
|
49
|
+
const { requests,rows } = batch;
|
|
50
|
+
return Number.isInteger(requests) && requests >= MIN_BATCH_REQUESTS && requests <= MAX_BATCH_REQUESTS
|
|
51
|
+
&& Number.isInteger(rows) && rows >= MIN_BATCH_ROWS && rows <= MAX_BATCH_ROWS;
|
|
52
|
+
}
|
|
53
|
+
/** The banks a request (or a batch of them) and its ground-height queries need, as [kind, capacity]. */
|
|
54
|
+
function projectionBanks(fields: number,outputCapacity: number,asks: { readonly queries?: readonly ['groundHeight']; readonly batch?: ReturnProjectionV2Batch }): (readonly [number,number])[] {
|
|
55
|
+
const { batch,queries } = asks;
|
|
56
|
+
const requests = batch?.requests ?? ONE;
|
|
57
|
+
const banks: (readonly [number,number])[] = [[KIND.binding,ONE],[KIND.state,ONE],[KIND.rng,ONE],[KIND.rngOut,ONE],
|
|
58
|
+
[KIND.parameters,batch === undefined ? ONE : REQUEST_PARAMETERS*requests],[KIND.fields,Math.max(fields*FRAMES,batch?.rows ?? NONE)],[KIND.outputs,outputCapacity*requests]];
|
|
59
|
+
if (queries !== undefined) {
|
|
60
|
+
banks.push([KIND.misses,QUERY_MISSES*requests],[KIND.replies,QUERY_REPLIES*requests],[KIND.replyData,QUERY_REPLIES*requests*(QUERY_KEY+ONE)]);
|
|
61
|
+
}
|
|
62
|
+
return banks;
|
|
63
|
+
}
|
|
64
|
+
export function returnProjectionV2Layout(fields: number,pages = 1,outputCapacity = 32,groups?:GroupStepRowsV2,queries?:readonly ['groundHeight'],batch?:ReturnProjectionV2Batch): V2Layout {
|
|
18
65
|
if (!Number.isInteger(fields) || fields < 1 || fields > 256) throw new Error('Invalid projection field count');
|
|
19
66
|
if (!Number.isInteger(outputCapacity) || outputCapacity < 1 || outputCapacity > 128) throw new Error('Invalid projection output capacity');
|
|
20
67
|
if(groups!==undefined&&groups.pages!==pages)throw new Error('Shared projection pages differ');
|
|
68
|
+
if (batch !== undefined && (groups !== undefined || !validBatch(batch))) {
|
|
69
|
+
throw new Error('Invalid projection batch');
|
|
70
|
+
}
|
|
21
71
|
const capacities=new Map(groups===undefined?[]:groupStepLayoutV2(groups).regions.map(row=>[row.kind,row.capacity]));
|
|
22
|
-
for(const [kind,capacity]of
|
|
23
|
-
capacities.set(kind,Math.max(capacities.get(kind)??
|
|
72
|
+
for (const [kind,capacity] of projectionBanks(fields,outputCapacity,{ ...(queries === undefined ? {} : { queries }),...(batch === undefined ? {} : { batch }) })) {
|
|
73
|
+
capacities.set(kind,Math.max(capacities.get(kind) ?? NONE,capacity));
|
|
74
|
+
}
|
|
24
75
|
return layoutV2(0,pages,capacities);
|
|
25
76
|
}
|
|
26
77
|
export function parseReturnProjectionV2(input: unknown): ReturnProjectionV2Rows {
|
|
@@ -32,9 +83,9 @@ export function parseReturnProjectionV2(input: unknown): ReturnProjectionV2Rows
|
|
|
32
83
|
/** Check cross-field rules after ReturnProjectionV2Schema has admitted the
|
|
33
84
|
* complete shape. Unknown inputs must use parseReturnProjectionV2 instead.
|
|
34
85
|
* A containing admitted schema can reuse its rows without parsing them again. */
|
|
35
|
-
|
|
86
|
+
function checkReturnProjectionV2Rows(row: ReturnProjectionV2Rows): void {
|
|
36
87
|
if(row.groups!==undefined)parseGroupStepV2(row.groups);
|
|
37
|
-
if (row.artifact.ioBytes !== returnProjectionV2Layout(row.fields.length,row.artifact.pages,row.outputCapacity,row.groups).bytes
|
|
88
|
+
if (row.artifact.ioBytes !== returnProjectionV2Layout(row.fields.length,row.artifact.pages,row.outputCapacity,row.groups,row.queries,row.batch).bytes
|
|
38
89
|
|| [row.fields,row.signals,row.channels].some(list => new Set(list).size !== list.length || list.some((name,i) => i > 0 && (list[i-1] ?? '') >= name))) throw new Error('Invalid projection declaration');
|
|
39
90
|
for(const kind of ['fields','signals','channels'] as const){
|
|
40
91
|
const extra=row.additional?.[kind]??[],declared=row[kind],base=declared.slice(0,declared.length-extra.length);
|
|
@@ -59,6 +110,11 @@ interface ReturnProjectionV2RowsInputFields {
|
|
|
59
110
|
channels: (string)[];
|
|
60
111
|
};
|
|
61
112
|
outputCapacity?: number;
|
|
113
|
+
queries?: ['groundHeight'];
|
|
114
|
+
batch?: {
|
|
115
|
+
requests: number;
|
|
116
|
+
rows: number;
|
|
117
|
+
};
|
|
62
118
|
bytes: string;
|
|
63
119
|
groups?: v.InferInput<typeof GroupStepV2Schema>;
|
|
64
120
|
}
|
|
@@ -78,7 +134,13 @@ interface ReturnProjectionV2RowsFields {
|
|
|
78
134
|
channels: (string)[];
|
|
79
135
|
};
|
|
80
136
|
outputCapacity?: number;
|
|
137
|
+
queries?: ['groundHeight'];
|
|
138
|
+
batch?: {
|
|
139
|
+
requests: number;
|
|
140
|
+
rows: number;
|
|
141
|
+
};
|
|
81
142
|
bytes: string;
|
|
82
143
|
groups?: v.InferOutput<typeof GroupStepV2Schema>;
|
|
83
144
|
}
|
|
84
145
|
export type ReturnProjectionV2Rows = { [Key in keyof ReturnProjectionV2RowsFields]: ReturnProjectionV2RowsFields[Key] };
|
|
146
|
+
export { checkReturnProjectionV2Rows, RETURN_PROJECTION_V2_QUERIES, type ReturnProjectionV2Batch };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// WASM-HOST H13: a page-only host's programme may run a v2 return projection. Its admitted row is then the
|
|
2
|
+
// `actors/return-scripts` project row naming the projection's module, which must be a `view` row (the server never
|
|
3
|
+
// installs one); the programme's ABI-1 script is only the witness that module names.
|
|
4
|
+
import { propOf, textOf } from './script-view-returns.ts'
|
|
5
|
+
|
|
6
|
+
/** The ABI a project row declares. */
|
|
7
|
+
const PROJECTION_ABI = 2
|
|
8
|
+
|
|
9
|
+
/** A page-only host's programme, its script row and the projection it may carry. */
|
|
10
|
+
interface HostedProgram {
|
|
11
|
+
readonly kind: string
|
|
12
|
+
readonly file: string
|
|
13
|
+
readonly script: unknown
|
|
14
|
+
readonly v2: unknown
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The `v2` of the programme whose script row sits at `host` (the row's parent). */
|
|
18
|
+
function programProjection(
|
|
19
|
+
document: unknown,
|
|
20
|
+
host: readonly string[],
|
|
21
|
+
): unknown {
|
|
22
|
+
let found = document
|
|
23
|
+
for (const key of host.filter((name: string): boolean => name !== 'script')) {
|
|
24
|
+
found = propOf(found, key)
|
|
25
|
+
}
|
|
26
|
+
return propOf(found, 'v2')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The value at `keys` under `value`, or `undefined`. */
|
|
30
|
+
function pathOf(value: unknown, keys: readonly string[]): unknown {
|
|
31
|
+
let found = value
|
|
32
|
+
for (const key of keys) {
|
|
33
|
+
found = propOf(found, key)
|
|
34
|
+
}
|
|
35
|
+
return found
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Whether two JSON values are equal by value, whatever their key order. */
|
|
39
|
+
function sameJson(left: unknown, right: unknown): boolean {
|
|
40
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
41
|
+
return (
|
|
42
|
+
Array.isArray(left) &&
|
|
43
|
+
Array.isArray(right) &&
|
|
44
|
+
left.length === right.length &&
|
|
45
|
+
left.every((item: unknown, at: number): boolean =>
|
|
46
|
+
sameJson(item, right[at]),
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
if (typeof left !== 'object' || left === null) {
|
|
51
|
+
return left === right
|
|
52
|
+
}
|
|
53
|
+
const keys = Object.keys(left)
|
|
54
|
+
return (
|
|
55
|
+
typeof right === 'object' &&
|
|
56
|
+
right !== null &&
|
|
57
|
+
Object.keys(right).length === keys.length &&
|
|
58
|
+
keys.every((key: string): boolean =>
|
|
59
|
+
sameJson(propOf(left, key), propOf(right, key)),
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A page-only programme that runs a v2 projection, as refusal lines; `gameplay` refuses a witness that writes any. */
|
|
65
|
+
function pageOnlyProjectionRefusal(
|
|
66
|
+
hosted: HostedProgram,
|
|
67
|
+
returns: readonly unknown[],
|
|
68
|
+
gameplay: (script: unknown, file: string) => string[],
|
|
69
|
+
): string[] {
|
|
70
|
+
const { file, kind, script, v2 } = hosted
|
|
71
|
+
const id = textOf(script, 'id') ?? '(no id)'
|
|
72
|
+
const hash = textOf(propOf(v2, 'artifact'), 'hash') ?? ''
|
|
73
|
+
const admitted = returns.find(
|
|
74
|
+
(row: unknown): boolean =>
|
|
75
|
+
propOf(row, 'abi') === PROJECTION_ABI &&
|
|
76
|
+
textOf(row, 'module') === `blobs/wasm/${hash}.wasm`,
|
|
77
|
+
)
|
|
78
|
+
if (admitted === undefined) {
|
|
79
|
+
return [
|
|
80
|
+
`${kind} program ${id} (${file}) runs a v2 module that is not an actors/return-scripts row`,
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
const side =
|
|
84
|
+
textOf(admitted, 'side') === 'view'
|
|
85
|
+
? []
|
|
86
|
+
: [
|
|
87
|
+
`sim script ${id} runs in page-only feature ${kind} (${file}), which no server host runs`,
|
|
88
|
+
]
|
|
89
|
+
return [...side, ...gameplay(script, file)]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { pageOnlyProjectionRefusal, pathOf, programProjection, sameJson }
|
|
93
|
+
export type { HostedProgram }
|
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
import { CLIENT_FEATURE_SIDES } from './feature-sides.ts'
|
|
8
8
|
import { parseNamedJson } from './json.ts'
|
|
9
9
|
import { splitGrandfathered } from './script-side-grandfather.ts'
|
|
10
|
+
import {
|
|
11
|
+
pageOnlyProjectionRefusal,
|
|
12
|
+
pathOf,
|
|
13
|
+
programProjection,
|
|
14
|
+
sameJson,
|
|
15
|
+
} from './script-side-projections.ts'
|
|
10
16
|
import {
|
|
11
17
|
propOf,
|
|
12
18
|
rowsOf,
|
|
@@ -17,6 +23,7 @@ import {
|
|
|
17
23
|
import type { FeatureSide } from './feature-sides.ts'
|
|
18
24
|
import type { OutputIndex } from './outputIndex.ts'
|
|
19
25
|
import type { ScriptSideShardfile } from './script-side-grandfather.ts'
|
|
26
|
+
import type { HostedProgram } from './script-side-projections.ts'
|
|
20
27
|
import type { NamedFiles } from './script-view-returns.ts'
|
|
21
28
|
import type { ScriptV1CommandName } from './scriptAbiV1.ts'
|
|
22
29
|
import type { V2Lane } from './scriptFuelV2.ts'
|
|
@@ -80,69 +87,46 @@ interface UncheckedFiles {
|
|
|
80
87
|
) => boolean
|
|
81
88
|
}
|
|
82
89
|
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
let found = value
|
|
86
|
-
for (const key of keys) {
|
|
87
|
-
found = propOf(found, key)
|
|
88
|
-
}
|
|
89
|
-
return found
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** Whether two JSON values are equal by value, whatever their key order. */
|
|
93
|
-
function sameJson(left: unknown, right: unknown): boolean {
|
|
94
|
-
if (Array.isArray(left) || Array.isArray(right)) {
|
|
95
|
-
return (
|
|
96
|
-
Array.isArray(left) &&
|
|
97
|
-
Array.isArray(right) &&
|
|
98
|
-
left.length === right.length &&
|
|
99
|
-
left.every((item: unknown, at: number): boolean =>
|
|
100
|
-
sameJson(item, right[at]),
|
|
101
|
-
)
|
|
102
|
-
)
|
|
103
|
-
}
|
|
104
|
-
if (typeof left !== 'object' || left === null) {
|
|
105
|
-
return left === right
|
|
106
|
-
}
|
|
107
|
-
const keys = Object.keys(left)
|
|
108
|
-
return (
|
|
109
|
-
typeof right === 'object' &&
|
|
110
|
-
right !== null &&
|
|
111
|
-
Object.keys(right).length === keys.length &&
|
|
112
|
-
keys.every((key: string): boolean =>
|
|
113
|
-
sameJson(propOf(left, key), propOf(right, key)),
|
|
114
|
-
)
|
|
115
|
-
)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** A page-only host feature's kind, file and the script row inside that file, or `undefined`. */
|
|
90
|
+
/** A page-only host feature's kind, file, the script row inside that file and the projection its programme carries
|
|
91
|
+
* (WASM-HOST H13), or `undefined`. */
|
|
119
92
|
function hostedScript(
|
|
120
93
|
feature: unknown,
|
|
121
94
|
named: NamedJson,
|
|
122
|
-
):
|
|
95
|
+
): HostedProgram | undefined {
|
|
123
96
|
const kind = textOf(feature, 'kind') ?? ''
|
|
124
97
|
const host = PAGE_ONLY_PROGRAM_HOSTS.get(kind)
|
|
125
98
|
const file = textOf(feature, 'file')
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
99
|
+
if (host === undefined || file === undefined) {
|
|
100
|
+
return undefined
|
|
101
|
+
}
|
|
102
|
+
const document = named(file)
|
|
103
|
+
const script = pathOf(document, host)
|
|
104
|
+
return script === undefined
|
|
131
105
|
? undefined
|
|
132
|
-
: { file, kind, script }
|
|
106
|
+
: { file, kind, script, v2: programProjection(document, host) }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A view script's refusal when it writes gameplay (any command but a timer, a cue and a channel), or nothing. */
|
|
110
|
+
function viewGameplayRefusal(script: unknown, file: string): string[] {
|
|
111
|
+
const views: readonly string[] = [...SCRIPT_V1_VIEW_COMMANDS]
|
|
112
|
+
const viewOnly = rowsOf(propOf(script, 'commands')).every(
|
|
113
|
+
(command: unknown): boolean =>
|
|
114
|
+
views.some((name: string): boolean => name === command),
|
|
115
|
+
)
|
|
116
|
+
return viewOnly
|
|
117
|
+
? []
|
|
118
|
+
: [
|
|
119
|
+
`view script ${textOf(script, 'id') ?? '(no id)'} (${file}): ${VIEW_WRITES_GAMEPLAY}`,
|
|
120
|
+
]
|
|
133
121
|
}
|
|
134
122
|
|
|
135
123
|
/** The script a page-only host feature runs, as refusal lines: a copy that is not its admitted `actors/return-scripts`
|
|
136
|
-
* row (so its side and rules are the admitted row's), or a `sim` row, which no server host runs there.
|
|
124
|
+
* row (so its side and rules are the admitted row's), or a `sim` row, which no server host runs there. A programme on
|
|
125
|
+
* a v2 projection answers to its project row instead (`script-side-projections.ts`). */
|
|
137
126
|
function pageOnlyRefusal(
|
|
138
|
-
|
|
139
|
-
named: NamedJson,
|
|
127
|
+
hosted: HostedProgram,
|
|
140
128
|
returns: readonly unknown[],
|
|
141
129
|
): string[] {
|
|
142
|
-
const hosted = hostedScript(feature, named)
|
|
143
|
-
if (hosted === undefined) {
|
|
144
|
-
return []
|
|
145
|
-
}
|
|
146
130
|
const { file, kind, script } = hosted
|
|
147
131
|
const id = textOf(script, 'id') ?? '(no id)'
|
|
148
132
|
const admitted = returns.find(
|
|
@@ -160,6 +144,19 @@ function pageOnlyRefusal(
|
|
|
160
144
|
: []
|
|
161
145
|
}
|
|
162
146
|
|
|
147
|
+
/** A page-only host's programme, as refusal lines: on a v2 projection it answers to its project row. */
|
|
148
|
+
function hostedRefusal(
|
|
149
|
+
hosted: HostedProgram | undefined,
|
|
150
|
+
returns: readonly unknown[],
|
|
151
|
+
): string[] {
|
|
152
|
+
if (hosted === undefined) {
|
|
153
|
+
return []
|
|
154
|
+
}
|
|
155
|
+
return hosted.v2 === undefined
|
|
156
|
+
? pageOnlyRefusal(hosted, returns)
|
|
157
|
+
: pageOnlyProjectionRefusal(hosted, returns, viewGameplayRefusal)
|
|
158
|
+
}
|
|
159
|
+
|
|
163
160
|
/** A `view` row in `sim/scripts`, as a refusal line, or nothing. */
|
|
164
161
|
function serverViewRefusal(row: unknown): string[] {
|
|
165
162
|
if (textOf(row, 'side') !== 'view') {
|
|
@@ -180,7 +177,7 @@ function scriptSideRefusals(
|
|
|
180
177
|
const features = rowsOf(propOf(sections.get('client/plan'), 'features'))
|
|
181
178
|
const returns = rowsOf(sections.get('actors/return-scripts'))
|
|
182
179
|
const hosted = features.flatMap((feature: unknown): string[] =>
|
|
183
|
-
|
|
180
|
+
hostedRefusal(hostedScript(feature, named), returns),
|
|
184
181
|
)
|
|
185
182
|
const decisions = rowsOf(sections.get('sim/scripts')).flatMap(
|
|
186
183
|
(row: unknown): string[] => serverViewRefusal(row),
|
|
@@ -26,8 +26,10 @@ export const ViewModulesSchema: v.GenericSchema<ViewModuleRowsInput, ViewModuleR
|
|
|
26
26
|
|
|
27
27
|
const OwnedSimModuleSchema: v.GenericSchema<OwnedSimModuleRowsInput, OwnedSimModuleRows> = v.strictObject({ ...ViewModuleSchema.entries,side: v.literal('sim'),lane: v.literal('sim') });
|
|
28
28
|
/** Stateless project modules use the same persistent inventory as legacy return
|
|
29
|
-
* policies, never view or scheduled spawn declarations.
|
|
30
|
-
|
|
29
|
+
* policies, never view or scheduled spawn declarations. WASM-HOST H13: a `view`
|
|
30
|
+
* one is a page-only projection (`page.life`'s ambient rules); the server never
|
|
31
|
+
* installs a `view` return row. */
|
|
32
|
+
const ProjectModuleSchema = v.strictObject({ ...ViewModuleSchema.entries,side: v.picklist(['sim','view']),lane: v.literal('project') });
|
|
31
33
|
const ProjectReturnModulesSchema = v.pipe(v.unknown(),v.check(isJsonData,'plain JSON return modules'),
|
|
32
34
|
v.array(v.union([DecisionScriptsSchema.pipe[2].item,ProjectModuleSchema])),v.maxLength(64),
|
|
33
35
|
v.check(rows=>new Set(rows.map(row=>row.id)).size===rows.length,'unique return module ids'),
|
|
@@ -163,9 +165,9 @@ export type ViewModuleRowsInput = (ViewModuleRowInput)[];
|
|
|
163
165
|
export type ViewModuleRows = (ViewModuleRow)[];
|
|
164
166
|
export type ReturnModuleRowsInput = unknown;
|
|
165
167
|
export type ReturnModuleRows = (v.InferOutput<typeof DecisionScriptsSchema>) | (((v.InferOutput<(typeof DecisionScriptsSchema)['pipe'][2]['item']>) | (Omit<ViewModuleRow, keyof ({
|
|
166
|
-
side: 'sim';
|
|
168
|
+
side: 'sim' | 'view';
|
|
167
169
|
lane: 'project';
|
|
168
170
|
})> & {
|
|
169
|
-
side: 'sim';
|
|
171
|
+
side: 'sim' | 'view';
|
|
170
172
|
lane: 'project';
|
|
171
173
|
}))[]);
|
package/src/format/sections.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type { ServerHosts } from './server-hosts.ts';
|
|
|
14
14
|
import type { ServerWorld } from './server-world.ts';
|
|
15
15
|
import type { NativeSweptPolicyRows } from './items.ts';
|
|
16
16
|
import type { OwnedSimModuleRows, ReturnModuleRow, ViewModuleRow } from './scriptContract.ts';
|
|
17
|
+
import type { SimReadV2Row } from './sim-reads-v2.ts';
|
|
17
18
|
import type { WorldScenesSection } from './worldScenes.ts';
|
|
18
19
|
import type { TreeSetRows } from './treeSetRows.ts';
|
|
19
20
|
import type { Vehicles } from './vehicles.ts';
|
|
@@ -56,6 +57,8 @@ export interface PlatformSections {
|
|
|
56
57
|
'view/modules': ViewModuleRow[];
|
|
57
58
|
/** WASM-HOST H13: the ABI v2 modules numeric hosts run. */
|
|
58
59
|
'sim/modules': OwnedSimModuleRows[];
|
|
60
|
+
/** WASM-HOST H18: what the sim reads of a body or slot, as project modules the server runs. */
|
|
61
|
+
'sim/reads': SimReadV2Row[];
|
|
59
62
|
/** Client-only ordered model references, ignored by simulation. */
|
|
60
63
|
'explore/catalogue': ExplorerCatalogue;
|
|
61
64
|
'look/toon': ToonLookRow;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/* oxlint-disable curly, no-magic-numbers, import/exports-last, import/group-exports, typescript/explicit-function-return-type, typescript/prefer-readonly-parameter-types, unicorn/max-nested-calls -- one small schema module: its bounds are its contract, named once beside their checks */
|
|
2
|
+
/** WASM-HOST H18 (W18): a sim read. Whatever the sim reads (a body's height, a slot's pose) runs on the server, never in
|
|
3
|
+
* a view module. A sim read is a stateless ABI v2 project module (a ReturnProjectionV2 row) the server runs at the sim
|
|
4
|
+
* rate, 10 Hz or 30 Hz with a written reason (W9), over one target:
|
|
5
|
+
*
|
|
6
|
+
* - `species`: one request per live body of that species, up to `count`. Its fields are the body's: `dt`, `alive`,
|
|
7
|
+
* `ground`, `x`, `y`, `z`, `yaw`, `seed`, `scale`, `attackPhase`, `mem:<key>` and `has:<key>` (its memory, and
|
|
8
|
+
* whether it holds that key). Its channels: `yOffset`, the body's height over its ground, which the sim reads.
|
|
9
|
+
* - `slot`: one request for the named slot a native owner lends (a fight's frame slot). Its fields are `dt` and
|
|
10
|
+
* `source:<name>`, the values the slot lends; its channels are `cell:<name>`, the cells it reads back.
|
|
11
|
+
*
|
|
12
|
+
* Both may carry state from call to call: each `carry` name is a field `carry:<name>` and a channel of the same name,
|
|
13
|
+
* kept per body (or for the slot) by the server and saved as a named column, never guest memory (H7). A body's carries
|
|
14
|
+
* start at zero; a new body (another seed) starts its own. The page runs its own view modules for what it draws. */
|
|
15
|
+
import {
|
|
16
|
+
array,
|
|
17
|
+
check,
|
|
18
|
+
exactOptional,
|
|
19
|
+
integer,
|
|
20
|
+
literal,
|
|
21
|
+
maxLength,
|
|
22
|
+
maxValue,
|
|
23
|
+
minLength,
|
|
24
|
+
minValue,
|
|
25
|
+
number,
|
|
26
|
+
picklist,
|
|
27
|
+
pipe,
|
|
28
|
+
regex,
|
|
29
|
+
strictObject,
|
|
30
|
+
string,
|
|
31
|
+
variant,
|
|
32
|
+
} from 'valibot'
|
|
33
|
+
|
|
34
|
+
import { ReturnProjectionV2Schema } from './returnProjectionV2.ts'
|
|
35
|
+
|
|
36
|
+
import type { ReturnProjectionV2Rows } from './returnProjectionV2.ts'
|
|
37
|
+
import type { GenericSchema } from 'valibot'
|
|
38
|
+
|
|
39
|
+
/** The most carried values one sim read keeps per body or slot. */
|
|
40
|
+
export const SIM_READ_CARRIES = 16
|
|
41
|
+
/** The most bodies one species sim read reads. */
|
|
42
|
+
export const SIM_READ_BODIES = 64
|
|
43
|
+
/** A species read's body fields, besides `mem:` and `has:` keys and carries. */
|
|
44
|
+
export const SIM_READ_BODY_FIELDS: readonly string[] = Object.freeze([
|
|
45
|
+
'dt',
|
|
46
|
+
'alive',
|
|
47
|
+
'ground',
|
|
48
|
+
'x',
|
|
49
|
+
'y',
|
|
50
|
+
'z',
|
|
51
|
+
'yaw',
|
|
52
|
+
'seed',
|
|
53
|
+
'scale',
|
|
54
|
+
'attackPhase',
|
|
55
|
+
])
|
|
56
|
+
/** A species read's body outputs, besides carries. */
|
|
57
|
+
export const SIM_READ_BODY_OUTPUTS: readonly string[] = Object.freeze([
|
|
58
|
+
'yOffset',
|
|
59
|
+
])
|
|
60
|
+
|
|
61
|
+
const name = pipe(
|
|
62
|
+
string(),
|
|
63
|
+
minLength(1),
|
|
64
|
+
maxLength(128),
|
|
65
|
+
regex(/^[a-z][a-zA-Z0-9.-]*$/u),
|
|
66
|
+
)
|
|
67
|
+
const SpeciesTarget = strictObject({
|
|
68
|
+
kind: literal('species'),
|
|
69
|
+
species: name,
|
|
70
|
+
count: pipe(number(), integer(), minValue(1), maxValue(SIM_READ_BODIES)),
|
|
71
|
+
})
|
|
72
|
+
const SlotTarget = strictObject({ kind: literal('slot'), slot: name })
|
|
73
|
+
|
|
74
|
+
export interface SimReadV2Row {
|
|
75
|
+
readonly id: string
|
|
76
|
+
readonly target:
|
|
77
|
+
| {
|
|
78
|
+
readonly kind: 'species'
|
|
79
|
+
readonly species: string
|
|
80
|
+
readonly count: number
|
|
81
|
+
}
|
|
82
|
+
| { readonly kind: 'slot'; readonly slot: string }
|
|
83
|
+
readonly tick: 10 | 30
|
|
84
|
+
readonly tickReason?: string
|
|
85
|
+
readonly carry: readonly string[]
|
|
86
|
+
readonly projection: ReturnProjectionV2Rows
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function fieldOk(row: SimReadV2Row, field: string): boolean {
|
|
90
|
+
if (field.startsWith('carry:'))
|
|
91
|
+
return row.carry.includes(field.slice('carry:'.length))
|
|
92
|
+
if (row.target.kind === 'slot')
|
|
93
|
+
return (
|
|
94
|
+
field === 'dt' ||
|
|
95
|
+
(field.startsWith('source:') && field.length > 'source:'.length)
|
|
96
|
+
)
|
|
97
|
+
return (
|
|
98
|
+
SIM_READ_BODY_FIELDS.includes(field) || /^(?:mem|has):[\w.-]+$/u.test(field)
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
function channelOk(row: SimReadV2Row, channel: string): boolean {
|
|
102
|
+
if (channel.startsWith('carry:'))
|
|
103
|
+
return row.carry.includes(channel.slice('carry:'.length))
|
|
104
|
+
return row.target.kind === 'slot'
|
|
105
|
+
? channel.startsWith('cell:') && channel.length > 'cell:'.length
|
|
106
|
+
: SIM_READ_BODY_OUTPUTS.includes(channel)
|
|
107
|
+
}
|
|
108
|
+
/** Every problem with one row's names, or none. */
|
|
109
|
+
export function simReadProblems(row: SimReadV2Row): string[] {
|
|
110
|
+
const problems: string[] = [],
|
|
111
|
+
{ fields, channels } = row.projection
|
|
112
|
+
for (const field of fields)
|
|
113
|
+
if (!fieldOk(row, field)) problems.push(`${row.id} reads no field ${field}`)
|
|
114
|
+
for (const channel of channels)
|
|
115
|
+
if (!channelOk(row, channel))
|
|
116
|
+
problems.push(`${row.id} writes no output ${channel}`)
|
|
117
|
+
for (const carry of row.carry) {
|
|
118
|
+
if (
|
|
119
|
+
!fields.includes(`carry:${carry}`) ||
|
|
120
|
+
!channels.includes(`carry:${carry}`)
|
|
121
|
+
)
|
|
122
|
+
problems.push(`${row.id} carries ${carry} without its field and channel`)
|
|
123
|
+
}
|
|
124
|
+
if (new Set(row.carry).size !== row.carry.length)
|
|
125
|
+
problems.push(`${row.id} carries a name twice`)
|
|
126
|
+
if ((row.tick === 30) !== (row.tickReason !== undefined))
|
|
127
|
+
problems.push(
|
|
128
|
+
`${row.id} needs a written reason exactly when it runs at 30 Hz`,
|
|
129
|
+
)
|
|
130
|
+
if (row.projection.batch !== undefined || row.projection.groups !== undefined)
|
|
131
|
+
problems.push(`${row.id} asks one request at a time`)
|
|
132
|
+
return problems
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const SimReadV2Schema: GenericSchema<unknown, SimReadV2Row> = pipe(
|
|
136
|
+
strictObject({
|
|
137
|
+
id: name,
|
|
138
|
+
target: variant('kind', [SpeciesTarget, SlotTarget]),
|
|
139
|
+
tick: picklist([10, 30]),
|
|
140
|
+
tickReason: exactOptional(pipe(string(), minLength(8), maxLength(512))),
|
|
141
|
+
carry: pipe(array(name), maxLength(SIM_READ_CARRIES)),
|
|
142
|
+
projection: ReturnProjectionV2Schema,
|
|
143
|
+
}),
|
|
144
|
+
check(
|
|
145
|
+
row => simReadProblems(row as SimReadV2Row).length === 0,
|
|
146
|
+
"a sim read reads only its target's fields and writes only its outputs and carries",
|
|
147
|
+
),
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
/** The `sim/reads` section: optional; ids are unique, and no two reads write one species or slot. */
|
|
151
|
+
export const SimReadsV2Schema: GenericSchema<unknown, SimReadV2Row[]> = pipe(
|
|
152
|
+
array(SimReadV2Schema),
|
|
153
|
+
maxLength(16),
|
|
154
|
+
check(
|
|
155
|
+
rows => new Set(rows.map(row => row.id)).size === rows.length,
|
|
156
|
+
'unique sim read ids',
|
|
157
|
+
),
|
|
158
|
+
check(
|
|
159
|
+
rows =>
|
|
160
|
+
new Set(
|
|
161
|
+
rows.map(row =>
|
|
162
|
+
row.target.kind === 'slot'
|
|
163
|
+
? `slot:${row.target.slot}`
|
|
164
|
+
: `species:${row.target.species}`,
|
|
165
|
+
),
|
|
166
|
+
).size === rows.length,
|
|
167
|
+
'one sim read per species or slot',
|
|
168
|
+
),
|
|
169
|
+
)
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
+
import { ReturnProjectionV2Schema } from './returnProjectionV2.ts';
|
|
3
|
+
import type { ReturnProjectionV2Rows, ReturnProjectionV2RowsInput } from './returnProjectionV2.ts';
|
|
2
4
|
import { AudioMixExpressionSchema, type AudioMixExpr } from './audioProfiles.ts';
|
|
3
5
|
|
|
4
6
|
const id = v.pipe(v.string(), v.minLength(1), v.maxLength(128));
|
|
@@ -74,6 +76,8 @@ const named = v.pipe(v.array(v.tuple([name, source])), v.maxLength(32));
|
|
|
74
76
|
export const WeatherShelterCirclesSchema: v.GenericSchema<WeatherReactionRows['shelter']['circles']> = v.pipe(v.array(v.tuple([finite, finite, v.pipe(finite, v.minValue(0))])), v.maxLength(256));
|
|
75
77
|
export const WeatherReactionsSchema: v.StrictObjectSchema<WeatherReactionEntries, undefined> = v.strictObject({
|
|
76
78
|
version: v.literal(1), hz: v.pipe(finite, v.minValue(1), v.maxValue(10)), script: v.unknown(), bytes: v.string(),
|
|
79
|
+
/** WASM-HOST H13: the program's ABI-2 candidate beside its ABI-1 witness; the engine's return program admits both. */
|
|
80
|
+
v2: v.exactOptional(ReturnProjectionV2Schema),
|
|
77
81
|
actions: v.exactOptional(v.strictObject({ event: id, unless: v.exactOptional(name) })),
|
|
78
82
|
active: v.pipe(v.array(id), v.maxLength(32)), flash: name,
|
|
79
83
|
shelter: v.strictObject({ margin: v.pipe(finite, v.minValue(0)), circles: WeatherShelterCirclesSchema }),
|
|
@@ -290,6 +294,7 @@ interface WeatherReactionRowsInputFields {
|
|
|
290
294
|
hz: number;
|
|
291
295
|
script: unknown;
|
|
292
296
|
bytes: string;
|
|
297
|
+
v2?: ReturnProjectionV2RowsInput;
|
|
293
298
|
actions?: {
|
|
294
299
|
event: string;
|
|
295
300
|
unless?: string;
|
|
@@ -352,6 +357,7 @@ interface WeatherReactionRowsFields {
|
|
|
352
357
|
hz: number;
|
|
353
358
|
script: unknown;
|
|
354
359
|
bytes: string;
|
|
360
|
+
v2?: ReturnProjectionV2Rows;
|
|
355
361
|
actions?: {
|
|
356
362
|
event: string;
|
|
357
363
|
unless?: string;
|
|
@@ -412,9 +418,10 @@ export type WeatherReactionRows = { [Key in keyof WeatherReactionRowsFields]: We
|
|
|
412
418
|
|
|
413
419
|
/** Keep composition metadata available to inline module admission. */
|
|
414
420
|
type WeatherReactionEntries = {
|
|
415
|
-
[Key in Exclude<keyof WeatherReactionRows, 'actions' | 'hud'>]:
|
|
421
|
+
[Key in Exclude<keyof WeatherReactionRows, 'actions' | 'hud' | 'v2'>]:
|
|
416
422
|
v.GenericSchema<WeatherReactionRowsInput[Key], WeatherReactionRows[Key]>;
|
|
417
423
|
} & {
|
|
424
|
+
v2: v.ExactOptionalSchema<v.GenericSchema<ReturnProjectionV2RowsInput, ReturnProjectionV2Rows>, undefined>;
|
|
418
425
|
actions: v.ExactOptionalSchema<v.GenericSchema<NonNullable<WeatherReactionRowsInput['actions']>,
|
|
419
426
|
NonNullable<WeatherReactionRows['actions']>>, undefined>;
|
|
420
427
|
hud: v.ExactOptionalSchema<v.GenericSchema<NonNullable<WeatherReactionRowsInput['hud']>,
|