@wildshard/shard-format 0.4.9 → 0.5.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.
Files changed (46) hide show
  1. package/corpus/brasscap-mesa/sections/look/look.json +1 -1
  2. package/corpus/brasscap-mesa/shard.json +1 -1
  3. package/corpus/brasscap-mesa/validation.json +1 -1
  4. package/package.json +16 -15
  5. package/src/cli/main.ts +2 -2
  6. package/src/cli/pack.ts +3 -3
  7. package/src/cli/validate.ts +33 -27
  8. package/src/format/assembly-hosts.ts +77 -0
  9. package/src/format/assetAdmission.ts +5 -5
  10. package/src/format/cook-preparation.ts +2 -2
  11. package/src/format/deviceMemoryCost.ts +2 -2
  12. package/src/format/{directorProduct.ts → directorDocument.ts} +3 -3
  13. package/src/format/entryClearance.ts +1 -1
  14. package/src/format/glbCost.ts +1 -1
  15. package/src/format/immutable.ts +1 -1
  16. package/src/format/issue-codes.ts +1 -1
  17. package/src/format/ktx2Cost.ts +1 -1
  18. package/src/format/look-light.ts +78 -0
  19. package/src/format/materials.ts +1 -1
  20. package/src/format/namedJsonContracts.ts +1 -1
  21. package/src/format/nearPlaceholderAssets.ts +1 -1
  22. package/src/format/outputDownload.ts +1 -1
  23. package/src/format/outputIndex.ts +1 -1
  24. package/src/format/platformFileFamilies.ts +3 -2
  25. package/src/format/receipt-cost.ts +3 -3
  26. package/src/format/registeredJson.ts +4 -4
  27. package/src/format/script-side-grandfather.ts +12 -13
  28. package/src/format/script-sides.ts +36 -38
  29. package/src/format/script-view-returns.ts +142 -0
  30. package/src/format/shardSchema.ts +7 -5
  31. package/src/format/{product-audio.ts → shardfile-audio.ts} +7 -7
  32. package/src/format/{product-stream-admit.ts → shardfile-stream-admit.ts} +11 -8
  33. package/src/format/{product-stream-assets.ts → shardfile-stream-assets.ts} +7 -7
  34. package/src/format/{product-stream-facts.ts → shardfile-stream-facts.ts} +3 -3
  35. package/src/format/{product-stream-node.ts → shardfile-stream-node.ts} +2 -2
  36. package/src/format/{product-stream-packs.ts → shardfile-stream-packs.ts} +1 -1
  37. package/src/format/{product-stream-rows.ts → shardfile-stream-rows.ts} +6 -6
  38. package/src/format/{product-stream.ts → shardfile-stream.ts} +25 -25
  39. package/src/format/{productValidation.ts → shardfileValidation.ts} +14 -14
  40. package/src/format/sourceResidency.ts +4 -4
  41. package/src/format/tar.ts +1 -1
  42. package/src/format/validationReceipt.ts +2 -2
  43. /package/src/format/{product.ts → shardfile-assets.ts} +0 -0
  44. /package/src/format/{product-reads.ts → shardfile-reads.ts} +0 -0
  45. /package/src/format/{product-stream-miss.ts → shardfile-stream-miss.ts} +0 -0
  46. /package/src/format/{product-stream-tar.ts → shardfile-stream-tar.ts} +0 -0
@@ -8,6 +8,15 @@
8
8
  * per metre above it. It adds to the day keys' distance fog, so a shard can drop that to 0 and keep mist only low.
9
9
  * - `pools`: warm light pools on the ground under lamps, drawn as one additive decal draw (no dynamic light per lamp):
10
10
  * a disc of `radius` metres at each `at` point, in `colour` × `intensity`.
11
+ * - `lamps` (meta TEMPLATES-CLEANROOM B2): real point lights for lanterns, tent lamps and fires, at most 16, each at
12
+ * `at` in linear `colour` × `intensity` (candela), out to `distance` metres with physical (2) decay, no shadow.
13
+ * - `bounce` (B2): a warm fill from the ground: one shadowless directional light from the anti-sun heading, lifted
14
+ * by `lift` (0 level, 1 straight up), in linear `colour` × `intensity`.
15
+ * - `environment` (B2): sky-derived ambient: an environment filtered once from the look's own sky (its keys' zenith
16
+ * and horizon) over a `ground` colour (linear), lighting every PBR surface at `intensity`.
17
+ *
18
+ * `look.grade.tone` (B2) picks the display curve: `agx` (absent: the engine's AgX, as before) or `neutral` (Khronos PBR
19
+ * Neutral, which keeps saturated albedo saturated).
11
20
  *
12
21
  * Plain data and checks, no three.js. Absent keys stay absent (no filled default), so a product built before these keys
13
22
  * parses to the same bytes and keeps its source hash.
@@ -21,6 +30,7 @@ import {
21
30
  minLength,
22
31
  minValue,
23
32
  number,
33
+ picklist,
24
34
  pipe,
25
35
  strictObject,
26
36
  tuple,
@@ -48,6 +58,13 @@ const POOL_INTENSITY_MAX = 4
48
58
  const POOL_RADIUS_MIN = 0.1
49
59
  const POOL_RADIUS_MAX = 20
50
60
  const BLOOM_INTENSITY_MAX = 4
61
+ /** At most this many lamps in one look (real point lights: each costs every lit draw a light loop step). */
62
+ const LOOK_LIGHT_LAMPS_MAX = 16
63
+ const LAMP_INTENSITY_MAX = 100
64
+ const LAMP_DISTANCE_MIN = 0.1
65
+ const LAMP_DISTANCE_MAX = 50
66
+ const BOUNCE_INTENSITY_MAX = 4
67
+ const ENVIRONMENT_INTENSITY_MAX = 4
51
68
 
52
69
  /** Contact shadows: the engine's screen-space AO at this intensity and world radius (metres). */
53
70
  interface LookAo {
@@ -73,13 +90,36 @@ interface LookPools {
73
90
  radius: number
74
91
  at: Point[]
75
92
  }
93
+ /** One lamp: a point light at `at`, `colour` × `intensity` (candela), out to `distance` metres, decay 2, no shadow. */
94
+ interface LookLamp {
95
+ at: Point
96
+ colour: Rgb
97
+ intensity: number
98
+ distance: number
99
+ }
100
+ /** A warm fill from the ground: a shadowless directional light from the anti-sun heading, lifted by `lift`. */
101
+ interface LookBounce {
102
+ colour: Rgb
103
+ intensity: number
104
+ lift: number
105
+ }
106
+ /** Sky-derived ambient: the look's sky over a `ground` colour, filtered once, at `intensity`. */
107
+ interface LookEnvironment {
108
+ intensity: number
109
+ ground: Rgb
110
+ }
76
111
  /** `look.light`: each setting off when absent. */
77
112
  interface LookLight {
78
113
  ao?: LookAo
79
114
  rim?: LookRim
80
115
  heightFog?: LookHeightFog
81
116
  pools?: LookPools
117
+ lamps?: LookLamp[]
118
+ bounce?: LookBounce
119
+ environment?: LookEnvironment
82
120
  }
121
+ /** `look.grade.tone`: the display curve; absent is the engine's AgX. */
122
+ type LookTone = 'agx' | 'neutral'
83
123
  /** `look.grade.bloom`: the engine bloom's intensity and luminance threshold. */
84
124
  interface LookBloom {
85
125
  intensity: number
@@ -119,13 +159,42 @@ const LookPoolsSchema: GenericSchema<LookPools, LookPools> = strictObject({
119
159
  radius: range(POOL_RADIUS_MIN, POOL_RADIUS_MAX),
120
160
  at: pipe(array(point), minLength(FULL), maxLength(LOOK_LIGHT_POOLS_MAX)),
121
161
  })
162
+ const LookLampSchema: GenericSchema<LookLamp, LookLamp> = strictObject({
163
+ at: point,
164
+ colour,
165
+ intensity: range(NONE, LAMP_INTENSITY_MAX),
166
+ distance: range(LAMP_DISTANCE_MIN, LAMP_DISTANCE_MAX),
167
+ })
168
+ const LookLampsSchema: GenericSchema<LookLamp[], LookLamp[]> = pipe(
169
+ array(LookLampSchema),
170
+ minLength(FULL),
171
+ maxLength(LOOK_LIGHT_LAMPS_MAX),
172
+ )
173
+ const LookBounceSchema: GenericSchema<LookBounce, LookBounce> = strictObject({
174
+ colour,
175
+ intensity: range(NONE, BOUNCE_INTENSITY_MAX),
176
+ lift: range(NONE, FULL),
177
+ })
178
+ const LookEnvironmentSchema: GenericSchema<LookEnvironment, LookEnvironment> =
179
+ strictObject({
180
+ intensity: range(NONE, ENVIRONMENT_INTENSITY_MAX),
181
+ ground: colour,
182
+ })
122
183
  /** `look.light`: the optional light and post settings. */
123
184
  const LookLightSchema: GenericSchema<LookLight, LookLight> = strictObject({
124
185
  ao: exactOptional(LookAoSchema),
125
186
  rim: exactOptional(LookRimSchema),
126
187
  heightFog: exactOptional(LookHeightFogSchema),
127
188
  pools: exactOptional(LookPoolsSchema),
189
+ lamps: exactOptional(LookLampsSchema),
190
+ bounce: exactOptional(LookBounceSchema),
191
+ environment: exactOptional(LookEnvironmentSchema),
128
192
  })
193
+ /** `look.grade.tone`: absent is AgX, as before. */
194
+ const LookToneSchema: GenericSchema<LookTone, LookTone> = picklist([
195
+ 'agx',
196
+ 'neutral',
197
+ ])
129
198
  /** `look.grade.bloom`: absent is no bloom, as before. */
130
199
  const LookBloomSchema: GenericSchema<LookBloom, LookBloom> = strictObject({
131
200
  intensity: range(NONE, BLOOM_INTENSITY_MAX),
@@ -133,21 +202,30 @@ const LookBloomSchema: GenericSchema<LookBloom, LookBloom> = strictObject({
133
202
  })
134
203
 
135
204
  export {
205
+ LOOK_LIGHT_LAMPS_MAX,
136
206
  LOOK_LIGHT_POOLS_MAX,
137
207
  LookAoSchema,
138
208
  LookBloomSchema,
209
+ LookBounceSchema,
210
+ LookEnvironmentSchema,
139
211
  LookHeightFogSchema,
212
+ LookLampSchema,
140
213
  LookLightSchema,
141
214
  LookPoolsSchema,
142
215
  LookRimSchema,
216
+ LookToneSchema,
143
217
  }
144
218
  export type {
145
219
  LookAo,
146
220
  LookBloom,
147
221
  LookBloomInput,
222
+ LookBounce,
223
+ LookEnvironment,
148
224
  LookHeightFog,
225
+ LookLamp,
149
226
  LookLight,
150
227
  LookLightInput,
151
228
  LookPools,
152
229
  LookRim,
230
+ LookTone,
153
231
  }
@@ -52,7 +52,7 @@ export function graphFileJson(hash: string, file: (hash: string) => Uint8Array |
52
52
  * preset reference or a missing or invalid file.
53
53
  */
54
54
  export function materialGraphIr(entry: MaterialEntry, file: (hash: string) => Uint8Array | undefined): GraphIr {
55
- if (entry.family !== 'graph' || !('file' in entry)) throw new Error('material graph IR needs a graph file (a built product carries no inline graph)');
55
+ if (entry.family !== 'graph' || !('file' in entry)) throw new Error('material graph IR needs a graph file (a built shard file carries no inline graph)');
56
56
  const checked = validateGraph(graphFileJson(entry.file, file), { trustedBudget: true });
57
57
  if (!checked.ok) throw new Error(`material graph file ${entry.file}: ${checked.errors.join('; ')}`);
58
58
  return checked.graph;
@@ -82,7 +82,7 @@ export const HEADLESS_ASSEMBLY_JSON_SCHEMA: { $schema: string; type: string; add
82
82
  ] } } } },
83
83
  },
84
84
  properties: { version: { const: 1 }, modules: { type: 'object', propertyNames: {
85
- type: 'string', pattern: '^(?:@wildshard/[a-z]+/|src/(?:shards|game|engine|sdk)/)[A-Za-z0-9_./-]+$',
85
+ type: 'string', pattern: '^src/(?:shards|game|engine|sdk)/[A-Za-z0-9_./-]+$',
86
86
  }, additionalProperties: { type: 'array', maxItems: 256, uniqueItems: true, items: { $ref: '#/definitions/key' } } },
87
87
  constants: { $ref: '#/definitions/value' }, prepare: { $ref: '#/definitions/rows' }, install: { $ref: '#/definitions/installRows' },
88
88
  level: { $ref: '#/definitions/value' }, ports: { $ref: '#/definitions/value' }, entries: { $ref: '#/definitions/value' } },
@@ -1,7 +1,7 @@
1
1
  import type { NearPlaceholder } from './nearPlaceholder.ts';
2
2
  import { decodeTerrainTile } from './terrainTileBytes.ts';
3
3
  import { CELL_ABOVE, CELL_BELOW, CHUNK_HALF } from './contentBounds.ts';
4
- import { visitGlbTriangles } from './product.ts';
4
+ import { visitGlbTriangles } from './shardfile-assets.ts';
5
5
 
6
6
  /** Validate actual visual payloads: exact L1 tiles and cell-local GLBs, with no collider-only terrain. */
7
7
  export function validateNearPlaceholderAssets(near: NearPlaceholder, assets: ReadonlyMap<string, Uint8Array>): void {
@@ -29,6 +29,6 @@ export function readOutputDownloadIndex(input: unknown): OutputDownloadIndex {
29
29
  packs: v.exactOptional(v.pipe(v.array(v.object({ ...measured, entries: v.pipe(v.array(v.object({ hash, offset: bytes, bytes })), v.maxLength(8192)) })), v.maxLength(64))),
30
30
  }), input);
31
31
  const paths = ['shard.json', 'validation.json', ...index.sections.map(row => row.path), ...index.schemas.map(row => row.path), ...index.files.map(row => row.path)];
32
- if (new Set(paths).size !== paths.length) throw new Error('Duplicate product download path');
32
+ if (new Set(paths).size !== paths.length) throw new Error('Duplicate shard file download path');
33
33
  return index;
34
34
  }
@@ -62,7 +62,7 @@ export function parseOutputDescriptorIndex(input: unknown): OutputIndex | null {
62
62
  }
63
63
  function parseOutputIndexRows(input: unknown): OutputIndex {
64
64
  const index = v.parse(OutputIndexSchema, input);
65
- if (index.sdk === '0.3' && index.cook === undefined) { throw new Error(`Missing cook preparation: run wildshard prepare <product-dir> --base <exact-preview-url> (${index.identity.slug})`); }
65
+ if (index.sdk === '0.3' && index.cook === undefined) { throw new Error(`Missing cook preparation: run wildshard prepare <folder> --base <exact-preview-url> (${index.identity.slug})`); }
66
66
  if (index.sdk === '0.3' && index.cook !== undefined && index.cook.bytes > MAX_COOK_BYTES) { throw new Error('Cook preparation exceeds byte cap'); }
67
67
  const paths = new Set(['shard.json', 'validation.json']), names = new Set<string>();
68
68
  if (index.ktx2Costs !== undefined) {
@@ -57,7 +57,7 @@ import { PageLifeSchema } from './pageLife.ts';
57
57
  import { ChapterDirectorSchema, ChapterWakeSchema } from './chapterDirector.ts';
58
58
  import { QuestPageInteractionsSchema } from './questInteractions.ts';
59
59
  import { QuestServiceActionsSchema, QuestHintRowsSchema, CarriedQuestSchema } from './questSteps.ts';
60
- import { DirectorProductSchema } from './directorProduct.ts';
60
+ import { DirectorDocumentSchema } from './directorDocument.ts';
61
61
  import { NativeAssemblySchema, NativeAssemblyDataSchema, NATIVE_ASSEMBLY_SCHEMA, NATIVE_ASSEMBLY_DATA_SCHEMA } from './nativeAssembly.ts';
62
62
  import { QuestPanelCatalogueSchema } from './panelTemplate.ts';
63
63
  import { ForestWeatherSchema } from './forestWeather.ts';
@@ -224,7 +224,8 @@ export const PLATFORM_FILE_FAMILIES: readonly PlatformFileFamily[] = [
224
224
  source: '@wildshard/format/questInteractions#QuestPageInteractionsSchema', reader: 'src/game/quest/pageComposition.ts' },
225
225
  { pattern: /^quests\/services\.json$/u, schema: QuestServiceActionsSchema,
226
226
  source: '@wildshard/format/questSteps#QuestServiceActionsSchema', reader: 'src/game/quest/effects.ts' },
227
- { pattern: /^directors\/main\.json$/u, schema: DirectorProductSchema,
227
+ // SA23: the source string is shard file data (each file's `jsonSchema.$comment`), so it keeps the old module name.
228
+ { pattern: /^directors\/main\.json$/u, schema: DirectorDocumentSchema,
228
229
  source: '@wildshard/format/directorProduct#DirectorProductSchema', reader: 'src/game/plugin/director.ts' },
229
230
  { pattern: /^quests\/panels\.json$/u, schema: QuestPanelCatalogueSchema,
230
231
  source: '@wildshard/format/panelTemplate#QuestPanelCatalogueSchema', reader: 'src/game/ui/dataPanels.ts' },
@@ -2,9 +2,9 @@
2
2
  import { preflightDeclaredCosts } from './assetAdmission.ts'
3
3
  import { structuralGridEvidence } from './gridReadiness.ts'
4
4
  import { postStackCost } from './postStack.ts'
5
- import { offlineMemoryAdmission } from './product.ts'
5
+ import { offlineMemoryAdmission } from './shardfile-assets.ts'
6
6
  import {
7
- productWireBytes,
7
+ shardfileWireBytes,
8
8
  publishedSourceResidency,
9
9
  } from './sourceResidency.ts'
10
10
 
@@ -59,7 +59,7 @@ function receiptResidencyShortfall(
59
59
  shard: Shardfile,
60
60
  ): string | undefined {
61
61
  const stamped = stampedResidency(receipt)
62
- const wire = productWireBytes(shard)
62
+ const wire = shardfileWireBytes(shard)
63
63
  if (stamped === undefined || stamped >= wire) {
64
64
  return undefined
65
65
  }
@@ -46,7 +46,7 @@ import { CaveFileSchema, CaveInteriorSchema } from './caveInterior.ts';
46
46
  import * as v from 'valibot';
47
47
  import { NativePopulationRowsSchema, parseNativePopulationRows, TamingPoseFileSchema } from './populationRoster.ts';
48
48
  import { EliteFeatureSchema, parseEliteFeature } from './eliteFeature.ts';
49
- import { DirectorProductSchema } from './directorProduct.ts';
49
+ import { DirectorDocumentSchema } from './directorDocument.ts';
50
50
  import { AudioSceneSchema } from './audioScene.ts';
51
51
  import { KitFigureCardsSchema } from './questFigures.ts';
52
52
  import {SceneBuffersSchema,parseSceneBuffers} from './sceneBuffers.ts';
@@ -128,7 +128,7 @@ export interface RegisteredJsonContracts {
128
128
  readonly 'world/dressing-phone.json':{readonly schema:typeof SceneDressingSchema;readonly source:'@wildshard/format/sceneDressing#SceneDressingSchema'};
129
129
  readonly 'world/building-sites.json':{readonly schema:typeof LivingPageSitesSchema;readonly source:'@wildshard/format/forestPage#LivingPageSitesSchema'};
130
130
  readonly 'models/shape-book.json':{readonly schema:typeof FixedDrawRowsSchema;readonly source:'@wildshard/format/fixedDraws#FixedDrawRowsSchema'};
131
- readonly 'directors/main.json':{readonly schema:typeof DirectorProductSchema;readonly source:'@wildshard/format/directorProduct#DirectorProductSchema'};
131
+ readonly 'directors/main.json':{readonly schema:typeof DirectorDocumentSchema;readonly source:'@wildshard/format/directorProduct#DirectorProductSchema'};
132
132
  readonly 'scenes/cascade.json':{readonly schema:typeof WorldSceneSchema;readonly source:'@wildshard/format/clientChannels#WorldSceneSchema'};
133
133
  readonly 'scenes/cove.json':{readonly schema:typeof WorldSceneSchema;readonly source:'@wildshard/format/clientChannels#WorldSceneSchema'};
134
134
  readonly 'scenes/hibiscus.json':{readonly schema:typeof WorldSceneSchema;readonly source:'@wildshard/format/clientChannels#WorldSceneSchema'};
@@ -250,7 +250,7 @@ export const REGISTERED_JSON:RegisteredJsonContracts = {
250
250
  'world/dressing-phone.json':{schema:SceneDressingSchema,source:'@wildshard/format/sceneDressing#SceneDressingSchema'},
251
251
  'world/building-sites.json':{schema:LivingPageSitesSchema,source:'@wildshard/format/forestPage#LivingPageSitesSchema'},
252
252
  'models/shape-book.json':{schema:FixedDrawRowsSchema,source:'@wildshard/format/fixedDraws#FixedDrawRowsSchema'},
253
- 'directors/main.json':{schema:DirectorProductSchema,source:'@wildshard/format/directorProduct#DirectorProductSchema'},
253
+ 'directors/main.json':{schema:DirectorDocumentSchema,source:'@wildshard/format/directorProduct#DirectorProductSchema'},
254
254
  'scenes/cascade.json':{schema:WorldSceneSchema,source:'@wildshard/format/clientChannels#WorldSceneSchema'},
255
255
  'scenes/cove.json':{schema:WorldSceneSchema,source:'@wildshard/format/clientChannels#WorldSceneSchema'},
256
256
  'scenes/hibiscus.json':{schema:WorldSceneSchema,source:'@wildshard/format/clientChannels#WorldSceneSchema'},
@@ -476,7 +476,7 @@ export function validateRegisteredJson(name:string,value:unknown):void {
476
476
  case 'world/weather-observations.json':v.parse(ForestWeatherObservationSchema,value);break;
477
477
  case 'look/post.json':parsePostGraphDocument(value);break;
478
478
  case 'people/cards.json':v.parse(KitFigureCardsSchema,value);break;
479
- case 'directors/main.json':v.parse(DirectorProductSchema,value);break;
479
+ case 'directors/main.json':v.parse(DirectorDocumentSchema,value);break;
480
480
  case 'actors/roster.json':parseNativePopulationRows(value);break;
481
481
  case 'actors/elites.json':parseEliteFeature(value);break;
482
482
  case 'sim/keeper.json':v.parse(PopulationKeeperRowsSchema,value);break;
@@ -1,15 +1,15 @@
1
1
  // SERVER-PARITY SS7's grandfather list (meta docs/plans/SERVER-PARITY-PLAN.md): the live products admitted with a
2
- // warning in place of a script side refusal (`script-sides.ts`). SS11 empties it.
2
+ // warning in place of a script side refusal (`script-sides.ts`). SS11 emptied it.
3
3
 
4
4
  /** The product a validator is admitting: its slug and declared source hash. Both validators check that hash against
5
5
  * the admitted sections before they return, so a forged index cannot borrow a grandfathered product's. */
6
- interface ScriptSideProduct {
6
+ interface ScriptSideShardfile {
7
7
  readonly slug: string
8
8
  readonly sourceHash: string
9
9
  }
10
10
 
11
11
  /** One live product admitted with a warning in place of a script side refusal. */
12
- interface GrandfatheredScript extends ScriptSideProduct {
12
+ interface GrandfatheredScript extends ScriptSideShardfile {
13
13
  /** The script id the refusal names. */
14
14
  readonly script: string
15
15
  /** Why it still passes, and the row that removes it. */
@@ -17,20 +17,19 @@ interface GrandfatheredScript extends ScriptSideProduct {
17
17
  }
18
18
 
19
19
  /**
20
- * GRANDFATHERED (SERVER-PARITY SS7, 2026-11-12; removed by SS11 in meta `docs/plans/SERVER-PARITY-PLAN.md`): live
21
- * products that still break a script side rule, admitted with a warning so engine can take this format. Each entry is
22
- * one exact product (slug and source hash) and one script id; any other product, a new upload of the same shard
23
- * included, is still refused. Drop the entry's line when SS11 re-uploads the shard without the pattern.
20
+ * GRANDFATHERED (SERVER-PARITY SS7, 2026-11-12): live products that still broke a script side rule, admitted with a
21
+ * warning so engine could take this format. Each entry is one exact product (slug and source hash) and one script id; any
22
+ * other product, a new upload of the same shard included, is still refused. Empty since SS11 (2026-11-13): Pine Hollow
23
+ * revision 4 (`1b6dcfb1`, live on every channel) runs `page.life` on the view row `pine.ambient`, so no live product
24
+ * needs a line. A new entry needs a meta SERVER-PARITY row that removes it.
24
25
  */
25
26
  // prettier-ignore
26
- const SCRIPT_SIDE_GRANDFATHER: readonly GrandfatheredScript[] = [
27
- { slug: 'pine-hollow', sourceHash: 'a255585456ff289330fc0a8f7b417b67dca608ebeebcec59b676a7b361f79c15', script: 'pine.life', why: 'the live product; SS5 (engine 2f5e6965) runs its hollow-log secret on the server too, and SS11 moves its page half to a view row' },
28
- ]
27
+ const SCRIPT_SIDE_GRANDFATHER: readonly GrandfatheredScript[] = []
29
28
 
30
29
  /** The grandfather entry that covers one refusal line of this product, or `undefined`. */
31
30
  function grandfatherFor(
32
31
  line: string,
33
- product: ScriptSideProduct,
32
+ product: ScriptSideShardfile,
34
33
  ): GrandfatheredScript | undefined {
35
34
  return SCRIPT_SIDE_GRANDFATHER.find(
36
35
  (entry: GrandfatheredScript): boolean =>
@@ -43,7 +42,7 @@ function grandfatherFor(
43
42
  /** A product's side refusal lines, split: lines a grandfather entry covers become warnings, the rest stay refusals. */
44
43
  function splitGrandfathered(
45
44
  lines: readonly string[],
46
- product: ScriptSideProduct,
45
+ product: ScriptSideShardfile,
47
46
  ): { refused: string[]; warnings: string[] } {
48
47
  const refused: string[] = []
49
48
  const warnings: string[] = []
@@ -59,4 +58,4 @@ function splitGrandfathered(
59
58
  }
60
59
 
61
60
  export { SCRIPT_SIDE_GRANDFATHER, splitGrandfathered }
62
- export type { GrandfatheredScript, ScriptSideProduct }
61
+ export type { GrandfatheredScript, ScriptSideShardfile }
@@ -2,14 +2,22 @@
2
2
  // row says `sim` or `view` (`decisionScripts.ts`), and a `view` row writes no gameplay (a row rule there). Against the
3
3
  // whole product: a `sim` row that a page-only feature runs has no server half there, and a `view` row in `sim/scripts`
4
4
  // would run on the server's decision host. v1 sides and v2 lanes map onto SS2's side words (`feature-sides.ts`).
5
+ // SS12 (`script-view-returns.ts`): a program that runs a `view` return row is refused anywhere but a page-only host.
5
6
  // oxlint-disable typescript/prefer-readonly-parameter-types -- OutputIndex and the byte arrays are only read
6
7
  import { CLIENT_FEATURE_SIDES } from './feature-sides.ts'
7
8
  import { parseNamedJson } from './json.ts'
8
9
  import { splitGrandfathered } from './script-side-grandfather.ts'
10
+ import {
11
+ propOf,
12
+ rowsOf,
13
+ textOf,
14
+ viewReturnRefusals,
15
+ } from './script-view-returns.ts'
9
16
 
10
17
  import type { FeatureSide } from './feature-sides.ts'
11
18
  import type { OutputIndex } from './outputIndex.ts'
12
- import type { ScriptSideProduct } from './script-side-grandfather.ts'
19
+ import type { ScriptSideShardfile } from './script-side-grandfather.ts'
20
+ import type { NamedFiles } from './script-view-returns.ts'
13
21
  import type { ScriptV1CommandName } from './scriptAbiV1.ts'
14
22
  import type { V2Lane } from './scriptFuelV2.ts'
15
23
 
@@ -48,7 +56,7 @@ function isViewCommand(command: ScriptV1CommandName): boolean {
48
56
  * The `view` feature kinds whose named file (`file`) carries a return program that only the page runs, with the path
49
57
  * of the script row inside that file. A `sim` row run here is page-only gameplay: Pine's `pine.life` sets
50
58
  * `secret:log` from engine's client `pageLife` alone (SERVER-PARITY inventory row 3). SS5 runs it on the server too,
51
- * and the live product passes on `SCRIPT_SIDE_GRANDFATHER` until SS11.
59
+ * and SS11 (Pine revision 4) moved its page half to the view row `pine.ambient`, so the grandfather list is empty.
52
60
  *
53
61
  * `practice.course` has the same shape (a `sim` row only the page runs) but is cosmetic; it joins this table once
54
62
  * Nalati and Nine Dragon declare their `practice.course` rows `view`.
@@ -61,7 +69,7 @@ const PAGE_ONLY_PROGRAM_HOSTS: ReadonlyMap<string, readonly string[]> = new Map(
61
69
  type NamedJson = (name: string) => unknown
62
70
 
63
71
  /** The product files a validator reads before its inventory pass, and its hash check (`whole` as in
64
- * `ProductValidationPorts.verify`). */
72
+ * `ShardfileValidationPorts.verify`). */
65
73
  interface UncheckedFiles {
66
74
  readonly read: (path: string, bytes: number) => Uint8Array | undefined
67
75
  readonly paths: () => Iterable<string>
@@ -72,31 +80,6 @@ interface UncheckedFiles {
72
80
  ) => boolean
73
81
  }
74
82
 
75
- /** An own property of a plain object, or `undefined`. */
76
- function propOf(value: unknown, key: string): unknown {
77
- if (
78
- typeof value !== 'object' ||
79
- value === null ||
80
- Array.isArray(value) ||
81
- !Object.hasOwn(value, key)
82
- ) {
83
- return undefined
84
- }
85
- const found: unknown = Reflect.get(value, key)
86
- return found
87
- }
88
-
89
- /** A string property, or `undefined`. */
90
- function textOf(value: unknown, key: string): string | undefined {
91
- const text = propOf(value, key)
92
- return typeof text === 'string' ? text : undefined
93
- }
94
-
95
- /** An array, or an empty list. */
96
- function rowsOf(value: unknown): readonly unknown[] {
97
- return Array.isArray(value) ? value : []
98
- }
99
-
100
83
  /** The value at `keys` under `value`, or `undefined`. */
101
84
  function pathOf(value: unknown, keys: readonly string[]): unknown {
102
85
  let found = value
@@ -188,10 +171,11 @@ function serverViewRefusal(row: unknown): string[] {
188
171
  ]
189
172
  }
190
173
 
191
- /** Every side refusal in a product: its parsed sections, and a reader of its named JSON files. */
174
+ /** Every side refusal in a product: its sections, a reader of its named JSON files and their names (SS12 reads each). */
192
175
  function scriptSideRefusals(
193
176
  sections: ReadonlyMap<string, unknown>,
194
177
  named: NamedJson,
178
+ names: readonly string[] = [],
195
179
  ): string[] {
196
180
  const features = rowsOf(propOf(sections.get('client/plan'), 'features'))
197
181
  const returns = rowsOf(sections.get('actors/return-scripts'))
@@ -201,14 +185,24 @@ function scriptSideRefusals(
201
185
  const decisions = rowsOf(sections.get('sim/scripts')).flatMap(
202
186
  (row: unknown): string[] => serverViewRefusal(row),
203
187
  )
204
- return [...new Set([...hosted, ...decisions])]
188
+ const views = viewReturnRefusals(
189
+ sections,
190
+ { names, read: named },
191
+ PAGE_ONLY_PROGRAM_HOSTS,
192
+ )
193
+ return [...new Set([...hosted, ...decisions, ...views])]
205
194
  }
206
195
 
207
- /** A reader of the product's named JSON files that never throws and reads only bytes that match the index: a missing,
208
- * resized, changed or malformed file is `undefined` here, and the inventory or its schema refuses it later. */
209
- function namedJsonReader(index: OutputIndex, files: UncheckedFiles): NamedJson {
196
+ /** The product's named JSON files, by the index: their names, and a reader that never throws and reads only bytes that
197
+ * match the index (a missing, resized, changed or malformed file is `undefined` here, and the inventory or its schema
198
+ * refuses it later). */
199
+ function namedJsonFiles(index: OutputIndex, files: UncheckedFiles): NamedFiles {
210
200
  const present = new Set(files.paths())
211
- return (name: string): unknown => {
201
+ const names = index.files.flatMap(
202
+ (file: OutputIndex['files'][number]): string[] =>
203
+ file.kind === 'json' && file.name !== undefined ? [file.name] : [],
204
+ )
205
+ const read = (name: string): unknown => {
212
206
  const file = index.files.find(
213
207
  (entry: OutputIndex['files'][number]): boolean =>
214
208
  entry.kind === 'json' && entry.name === name,
@@ -226,15 +220,19 @@ function namedJsonReader(index: OutputIndex, files: UncheckedFiles): NamedJson {
226
220
  return undefined
227
221
  }
228
222
  }
223
+ return { names, read }
229
224
  }
230
225
 
231
226
  /** A product's side refusals, split: lines a grandfather entry covers become warnings, the rest stay refusals. */
232
227
  function scriptSideVerdict(
233
228
  sections: ReadonlyMap<string, unknown>,
234
- named: NamedJson,
235
- product: ScriptSideProduct,
229
+ files: NamedFiles,
230
+ product: ScriptSideShardfile,
236
231
  ): { refused: string[]; warnings: string[] } {
237
- return splitGrandfathered(scriptSideRefusals(sections, named), product)
232
+ return splitGrandfathered(
233
+ scriptSideRefusals(sections, files.read, files.names),
234
+ product,
235
+ )
238
236
  }
239
237
 
240
238
  /** Refuse a product whose scripts run on the wrong side, and return its grandfathered lines as warnings. Both
@@ -246,7 +244,7 @@ function assertScriptSides(
246
244
  ): string[] {
247
245
  const { refused, warnings } = scriptSideVerdict(
248
246
  sections,
249
- namedJsonReader(index, files),
247
+ namedJsonFiles(index, files),
250
248
  { slug: index.identity.slug, sourceHash: index.build.sourceHash },
251
249
  )
252
250
  const [first, ...rest] = refused
@@ -0,0 +1,142 @@
1
+ // SERVER-PARITY SS12 (engine 1e99d663, meta docs/plans/SERVER-PARITY-PLAN.md): the server drops `view` rows from
2
+ // `actors/return-scripts` before it lends return modules (`serverReturnRows`), so a program the server runs that points
3
+ // at one fails at install (`Missing admitted raw return module loan`). Format cannot tell which named files the server
4
+ // reads, so a view return row may run only from a page-only host's program path (`script-sides.ts`). The JSON row
5
+ // readers here serve both files.
6
+
7
+ /** The product's named JSON files: a reader by name (`undefined` when absent or not JSON) and every name. */
8
+ interface NamedFiles {
9
+ readonly read: (name: string) => unknown
10
+ readonly names: readonly string[]
11
+ }
12
+
13
+ /** A program found in a product document: where it is, as `<document> (<dot path>)`, and its script row. */
14
+ interface FoundProgram {
15
+ readonly at: string
16
+ readonly script: unknown
17
+ }
18
+
19
+ const RETURN_SCRIPTS = 'actors/return-scripts'
20
+
21
+ /** An own property of a plain object, or `undefined`. */
22
+ function propOf(value: unknown, key: string): unknown {
23
+ if (
24
+ typeof value !== 'object' ||
25
+ value === null ||
26
+ Array.isArray(value) ||
27
+ !Object.hasOwn(value, key)
28
+ ) {
29
+ return undefined
30
+ }
31
+ const found: unknown = Reflect.get(value, key)
32
+ return found
33
+ }
34
+
35
+ /** A string property, or `undefined`. */
36
+ function textOf(value: unknown, key: string): string | undefined {
37
+ const text = propOf(value, key)
38
+ return typeof text === 'string' ? text : undefined
39
+ }
40
+
41
+ /** An array, or an empty list. */
42
+ function rowsOf(value: unknown): readonly unknown[] {
43
+ return Array.isArray(value) ? value : []
44
+ }
45
+
46
+ /** Every return program (an object whose `script` names a `module`) under `node`, with its dot path from `keys`. */
47
+ function programsIn(
48
+ document: string,
49
+ node: unknown,
50
+ keys: readonly string[] = [],
51
+ ): FoundProgram[] {
52
+ if (typeof node !== 'object' || node === null) {
53
+ return []
54
+ }
55
+ const children: [string, unknown][] = Array.isArray(node)
56
+ ? node.map((item: unknown, at: number): [string, unknown] => [
57
+ String(at),
58
+ item,
59
+ ])
60
+ : Object.keys(node).map((key: string): [string, unknown] => [
61
+ key,
62
+ propOf(node, key),
63
+ ])
64
+ const script = propOf(node, 'script')
65
+ const own: FoundProgram[] =
66
+ textOf(script, 'module') === undefined
67
+ ? []
68
+ : [{ at: `${document} (${keys.join('.')})`, script }]
69
+ return [
70
+ ...own,
71
+ ...children.flatMap(
72
+ ([key, child]: readonly [string, unknown]): FoundProgram[] =>
73
+ programsIn(document, child, [...keys, key]),
74
+ ),
75
+ ]
76
+ }
77
+
78
+ /** The only places a view return row may run: each page-only host's program (its script path less `script`), as
79
+ * `<file> (<dot path>)`. */
80
+ function pageOnlyPrograms(
81
+ sections: ReadonlyMap<string, unknown>,
82
+ hosts: ReadonlyMap<string, readonly string[]>,
83
+ ): Set<string> {
84
+ const features = rowsOf(propOf(sections.get('client/plan'), 'features'))
85
+ return new Set(
86
+ features.flatMap((feature: unknown): string[] => {
87
+ const host = hosts.get(textOf(feature, 'kind') ?? '')
88
+ const file = textOf(feature, 'file')
89
+ const program = host?.join('.').replace(/(?:^|\.)script$/u, '')
90
+ return program === undefined || file === undefined
91
+ ? []
92
+ : [`${file} (${program})`]
93
+ }),
94
+ )
95
+ }
96
+
97
+ /** Programs that run a `view` return row anywhere but a page-only host, as refusal lines. A program runs the row whose
98
+ * module it names: the engine lends return modules by hash, and admission refuses a module that a `sim` and a `view`
99
+ * row share (`decisionModuleContracts`). A copy with inline bytes needs no loan but is refused too: the row's side says
100
+ * only the page runs it.
101
+ * Only a product with a view return row is walked: every section but the return rows, and every named JSON file. */
102
+ function viewReturnRefusals(
103
+ sections: ReadonlyMap<string, unknown>,
104
+ files: NamedFiles,
105
+ hosts: ReadonlyMap<string, readonly string[]>,
106
+ ): string[] {
107
+ const views = rowsOf(sections.get(RETURN_SCRIPTS)).filter(
108
+ (row: unknown): boolean => textOf(row, 'side') === 'view',
109
+ )
110
+ const [first] = views
111
+ if (first === undefined) {
112
+ return []
113
+ }
114
+ const allowed = pageOnlyPrograms(sections, hosts)
115
+ const documents: [string, unknown][] = [
116
+ ...[...sections].filter(
117
+ ([name]: readonly [string, unknown]): boolean => name !== RETURN_SCRIPTS,
118
+ ),
119
+ ...files.names.map((name: string): [string, unknown] => [
120
+ name,
121
+ files.read(name),
122
+ ]),
123
+ ]
124
+ const found = documents.flatMap(
125
+ ([document, value]: readonly [string, unknown]): FoundProgram[] =>
126
+ programsIn(document, value),
127
+ )
128
+ return found.flatMap(({ at, script }: FoundProgram): string[] => {
129
+ const view = views.find(
130
+ (row: unknown): boolean =>
131
+ textOf(row, 'module') === textOf(script, 'module'),
132
+ )
133
+ return view === undefined || allowed.has(at)
134
+ ? []
135
+ : [
136
+ `view script ${textOf(view, 'id') ?? '(no id)'} is a program in ${at}, which the server may run; only a page-only host runs a view row`,
137
+ ]
138
+ })
139
+ }
140
+
141
+ export { propOf, rowsOf, textOf, viewReturnRefusals }
142
+ export type { NamedFiles }