@wildshard/engine 0.1.18 → 0.1.19

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 (293) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/budgets/shard-size-baseline.json +10 -4
  3. package/index.html +6 -4
  4. package/lint/engine-sides.json +14 -0
  5. package/lint/ratchet.json +0 -68
  6. package/lint/ratchet.mjs +1 -4
  7. package/package.json +17 -15
  8. package/scripts/agent-sync.mjs +27 -8
  9. package/scripts/app-build/appCook.ts +8 -2
  10. package/scripts/app-build/catalogue.ts +10 -7
  11. package/scripts/app-build/gen.ts +22 -2
  12. package/scripts/app-build/isolation.d.mts +10 -0
  13. package/scripts/app-build/isolation.mjs +47 -0
  14. package/scripts/app-build/outputProducts.mjs +4 -0
  15. package/scripts/app-build/previousDeploy.d.mts +2 -0
  16. package/scripts/app-build/previousDeploy.mjs +10 -1
  17. package/scripts/app-build/serviceWorker.ts +10 -3
  18. package/scripts/app-build/splitOutput.mjs +4 -2
  19. package/scripts/app-build/standaloneOutput.d.mts +1 -1
  20. package/scripts/app-build/standaloneOutput.mjs +5 -3
  21. package/scripts/app-build/titlePreloads.d.mts +8 -0
  22. package/scripts/app-build/titlePreloads.mjs +69 -0
  23. package/scripts/app-build/worldMapAtlas.ts +10 -6
  24. package/scripts/app-build-pipeline.mjs +31 -3
  25. package/scripts/built-product.mjs +1 -1
  26. package/scripts/cell-mem-bench.mjs +81 -23
  27. package/scripts/check-custom-sections-zero.mjs +1 -1
  28. package/scripts/check-devserver.mjs +2 -0
  29. package/scripts/check-models.mjs +2 -0
  30. package/scripts/check-paths.allow.json +0 -115
  31. package/scripts/check-paths.mjs +2 -2
  32. package/scripts/check-platform-ratchets.mjs +2 -3
  33. package/scripts/chromium-keychain.d.mts +1 -1
  34. package/scripts/ci-static.sh +1 -1
  35. package/scripts/committed-fast-checks.mjs +0 -2
  36. package/scripts/content-sw-proof.mjs +2 -1
  37. package/scripts/cook-worker.mjs +9 -3
  38. package/scripts/cook.mjs +18 -5
  39. package/scripts/docs-inputs-proof.mjs +6 -6
  40. package/scripts/e7-voice-staging-proof.mjs +1 -1
  41. package/scripts/gate-related-tests.mjs +1 -1
  42. package/scripts/git-source-view.mjs +1 -1
  43. package/scripts/goldens/capture.mjs +17 -5
  44. package/scripts/grid-crossing-nightly.mjs +59 -0
  45. package/scripts/grid-crossing-qa.mjs +44 -0
  46. package/scripts/grid-crossing-ratchet.d.mts +6 -0
  47. package/scripts/grid-crossing-ratchet.mjs +52 -0
  48. package/scripts/grid-crossing-report.mjs +122 -0
  49. package/scripts/grid-crossing-stages.mjs +47 -0
  50. package/scripts/grid-crossing-tour.mjs +277 -0
  51. package/scripts/grid-crossing-walk-proof.mjs +124 -17
  52. package/scripts/host-ruler/roots.mjs +2 -2
  53. package/scripts/host-ruler.d.mts +91 -0
  54. package/scripts/host-ruler.mjs +565 -0
  55. package/scripts/live-prepush.py +3 -5
  56. package/scripts/loading-flow/benchmax.mjs +3 -1
  57. package/scripts/look-loop/test_look_loop.py +1 -38
  58. package/scripts/memory-proof.mjs +61 -6
  59. package/scripts/mmo-bots.mjs +8 -2
  60. package/scripts/net-lag-proof.mjs +219 -0
  61. package/scripts/night-market-kit-budget.mjs +2 -2
  62. package/scripts/offline-proof-rules.d.mts +2 -2
  63. package/scripts/offline-proof-rules.mjs +15 -4
  64. package/scripts/offline-proof.mjs +74 -13
  65. package/scripts/{shard-platform-output.mjs → output-reader.mjs} +1 -1
  66. package/scripts/page-release/content.d.mts +9 -1
  67. package/scripts/page-release/content.mjs +131 -17
  68. package/scripts/page-release/flow.mjs +36 -10
  69. package/scripts/page-release/stamp-content.mjs +24 -0
  70. package/scripts/page-release.mjs +28 -6
  71. package/scripts/page-size.mjs +2 -1
  72. package/scripts/pin-packs.ts +1 -1
  73. package/scripts/pins.ts +4 -4
  74. package/scripts/precommit-checks.mjs +1 -7
  75. package/scripts/precommit-jobs.mjs +0 -1
  76. package/scripts/precommit-source.py +1 -9
  77. package/scripts/program-discovery.mjs +1 -1
  78. package/scripts/ring-cook.mjs +2 -1
  79. package/scripts/ring-step.ts +1 -1
  80. package/scripts/script-scenario-metrics.mjs +1 -1
  81. package/scripts/shard-output-content.d.mts +1 -1
  82. package/scripts/shard-output-content.mjs +2 -2
  83. package/scripts/shard-outputs.mjs +1 -1
  84. package/scripts/shard-public.mjs +1 -1
  85. package/scripts/shard-wire-meter.mjs +24 -9
  86. package/scripts/side-parity.mjs +4 -2
  87. package/scripts/standalone-smoke.mjs +8 -3
  88. package/scripts/tier-textures.mjs +22 -4
  89. package/scripts/tile-bake-report.mjs +1 -1
  90. package/scripts/tile-bakes.mjs +1 -1
  91. package/scripts/title-assets.generated.json +2 -0
  92. package/scripts/tsconfig.json +0 -2
  93. package/scripts/vendor/basisu/LICENSE +201 -0
  94. package/scripts/vendor/basisu/basis_encoder.cjs +2 -0
  95. package/scripts/vendor/basisu/basis_encoder.wasm +0 -0
  96. package/scripts/vitest-push-guards.config.ts +1 -1
  97. package/scripts/vps/harden-apply.sh +4 -1
  98. package/scripts/vps/harden-prometheus.sh +176 -0
  99. package/scripts/vps/harden.sh +16 -0
  100. package/scripts/vps/rebuild.sh +18 -0
  101. package/scripts/vps/wildshard-config +6 -2
  102. package/scripts/worker-client-play.mjs +6 -2
  103. package/scripts/worktree-reap.mjs +5 -5
  104. package/src/.oxlintrc.json +3 -182
  105. package/src/client/app/entry.ts +10 -2
  106. package/src/client/engine/boot/bootCache.ts +2 -2
  107. package/src/client/engine/boot/bootTrace.ts +12 -4
  108. package/src/client/engine/boot/browserChunkRecovery.ts +4 -0
  109. package/src/client/engine/boot/clearDownloads.ts +5 -2
  110. package/src/client/engine/boot/contentRead.ts +11 -0
  111. package/src/client/engine/boot/gpuFiles.ts +4 -2
  112. package/src/client/engine/boot/lastEnd.ts +99 -12
  113. package/src/client/engine/boot/texturePack.ts +2 -2
  114. package/src/client/engine/net/netPlayer.ts +19 -2
  115. package/src/client/engine/net/otherPlayers.ts +55 -8
  116. package/src/client/engine/net/predictor.ts +33 -9
  117. package/src/client/engine/net/redial.ts +29 -6
  118. package/src/client/engine/pwa/cacheNames.ts +58 -1
  119. package/src/client/engine/pwa/sw.js +41 -11
  120. package/src/client/engine/render/dataLook.ts +152 -40
  121. package/src/client/engine/render/families/detail.ts +89 -0
  122. package/src/client/engine/render/families/pbr.ts +7 -1
  123. package/src/client/engine/render/look.ts +6 -0
  124. package/src/client/engine/render/lookLight.ts +103 -11
  125. package/src/client/engine/render/lookRender.ts +105 -0
  126. package/src/client/engine/saves/indexed.ts +2 -2
  127. package/src/client/engine/telemetry/browserErrors.ts +24 -3
  128. package/src/client/engine/telemetry/staleBuildReport.ts +22 -1
  129. package/src/client/engine/ui/debugOptions.ts +1 -1
  130. package/src/client/engine/ui/lookLightOption.ts +10 -6
  131. package/src/client/engine/ui/namePrompt.ts +7 -0
  132. package/src/client/game/boot/audio.generated.ts +114 -114
  133. package/src/client/game/boot/bytes.generated.ts +118 -220
  134. package/src/client/game/boot/placedSpawn.ts +35 -0
  135. package/src/client/game/boot/spawnDownload.ts +25 -6
  136. package/src/client/game/boot/versions.generated.ts +7 -5
  137. package/src/client/game/devScene/hook.ts +291 -0
  138. package/src/client/game/grid/cellLoading.ts +12 -2
  139. package/src/client/game/grid/live.ts +112 -16
  140. package/src/client/game/grid/liveSession.ts +33 -2
  141. package/src/client/game/grid/mapAtlas.ts +18 -4
  142. package/src/client/game/grid/minimapBlend.ts +15 -5
  143. package/src/client/game/grid/oneWayIn.ts +5 -1
  144. package/src/client/game/grid/placedCells.ts +114 -12
  145. package/src/client/game/grid/placedContent.ts +85 -0
  146. package/src/client/game/grid/prefetch.ts +9 -1
  147. package/src/client/game/grid/productInputs.ts +3 -1
  148. package/src/client/game/grid/productLeases.ts +4 -1
  149. package/src/client/game/grid/products.ts +8 -4
  150. package/src/client/game/grid/roadLook.ts +24 -15
  151. package/src/client/game/grid/roadLookPlatform.ts +4 -2
  152. package/src/client/game/grid/roadResources.ts +24 -0
  153. package/src/client/game/grid/roadSign.worker.ts +4 -3
  154. package/src/client/game/grid/roadSignPaint.ts +16 -5
  155. package/src/client/game/grid/roadSignPreparation.ts +4 -3
  156. package/src/client/game/grid/roadSignScale.ts +8 -0
  157. package/src/client/game/grid/roadTileCapture.worker.ts +3 -1
  158. package/src/client/game/grid/roadTileCaptureWorker.ts +2 -1
  159. package/src/client/game/grid/roadTileWrite.worker.ts +4 -2
  160. package/src/client/game/grid/roadTileWriter.ts +2 -1
  161. package/src/client/game/grid/screenReports.ts +39 -0
  162. package/src/client/game/grid/session.ts +20 -4
  163. package/src/client/game/grid/softWallLook.ts +25 -8
  164. package/src/client/game/mainMenu.ts +6 -2
  165. package/src/client/game/plugin/context.ts +2 -1
  166. package/src/client/game/plugin/followedMovers.ts +7 -1
  167. package/src/client/game/quest/figures.ts +2 -0
  168. package/src/client/game/session/finish.ts +6 -0
  169. package/src/client/game/shardfile/assetCache.ts +4 -4
  170. package/src/client/game/shardfile/client.ts +4 -1
  171. package/src/client/game/shardfile/clientAssets.ts +9 -5
  172. package/src/client/game/shardfile/clientLibrary.ts +1 -1
  173. package/src/client/game/shardfile/clientWater.ts +51 -9
  174. package/src/client/game/shardfile/clientWorker.ts +19 -7
  175. package/src/client/game/shardfile/look.ts +8 -3
  176. package/src/client/game/shardfile/product.ts +34 -7
  177. package/src/client/game/shardfile/productChecks.ts +2 -2
  178. package/src/client/game/shardfile/productCost.ts +2 -2
  179. package/src/client/game/shardfile/readAsset.ts +2 -2
  180. package/src/client/game/shardfile/reflectingWater.ts +73 -0
  181. package/src/client/game/shardfile/seatGrace.ts +9 -0
  182. package/src/client/game/shardfile/skinPlayback.ts +1 -1
  183. package/src/client/game/systems/npc/figureRows.ts +9 -0
  184. package/src/client/host/online/doctor.ts +2 -0
  185. package/src/client/host/online/linkScreens.ts +30 -4
  186. package/src/client/host/standalone/shell.ts +4 -0
  187. package/src/cook/game/astc6Encode.ts +55 -0
  188. package/src/cook/game/astc6Wasm.ts +176 -0
  189. package/src/cook/game/cookJob.ts +30 -6
  190. package/src/cook/game/cookWorker.ts +38 -11
  191. package/src/cook/game/entryTotals.ts +51 -24
  192. package/src/cook/game/shardCook.ts +35 -7
  193. package/src/cook/game/spawnParts.ts +33 -8
  194. package/src/cook/game/tierTextures.ts +87 -14
  195. package/src/server/engine/ai/bossContenders.ts +27 -3
  196. package/src/server/engine/ai/phases.ts +1 -1
  197. package/src/server/engine/entities/creatureRefill.ts +9 -2
  198. package/src/server/engine/net/ledgerBook.ts +2 -0
  199. package/src/server/engine/net/room.ts +15 -0
  200. package/src/server/engine/sim/respawn.ts +8 -0
  201. package/src/server/game/boss/arenaRoomEntry.ts +5 -1
  202. package/src/server/game/boss/arenaRoomNative.ts +2 -0
  203. package/src/server/game/boss/native.ts +2 -1
  204. package/src/server/game/boss/nativeWake.ts +9 -5
  205. package/src/server/game/boss/openArenaNative.ts +2 -2
  206. package/src/server/game/boss/openArenaRoom.ts +3 -1
  207. package/src/server/game/grid/room.ts +44 -3
  208. package/src/server/game/grid/simulation.ts +23 -0
  209. package/src/server/game/population/mixedRoster.ts +11 -3
  210. package/src/server/game/population/nativeBake.ts +8 -3
  211. package/src/server/game/population/nativeReturns.ts +6 -3
  212. package/src/server/game/population/roster.ts +5 -3
  213. package/src/server/game/quest/eliteDrops.ts +15 -4
  214. package/src/server/game/quest/nativeChapter.ts +1 -1
  215. package/src/server/game/quest/nativeComposition.ts +5 -1
  216. package/src/server/game/riding/nativeTaming.ts +10 -6
  217. package/src/server/game/riding/wildRefill.ts +3 -2
  218. package/src/server/game/shardfile/bossRow.ts +4 -2
  219. package/src/server/game/shardfile/homeKeeper.ts +4 -2
  220. package/src/server/host/bake/headlessWorker.ts +1 -1
  221. package/src/server/host/dedicated/cellHost.ts +98 -16
  222. package/src/server/host/dedicated/cellProtocol.ts +16 -1
  223. package/src/server/host/dedicated/cellWorker.ts +8 -5
  224. package/src/server/host/dedicated/dedicatedRoom.ts +16 -6
  225. package/src/server/host/dedicated/gridCells.ts +15 -6
  226. package/src/server/host/dedicated/loopLag.ts +21 -0
  227. package/src/server/host/dedicated/main.ts +13 -5
  228. package/src/server/host/dedicated/packReader.ts +3 -3
  229. package/src/server/host/dedicated/placementFile.ts +3 -2
  230. package/src/server/host/dedicated/roadRoom.ts +34 -4
  231. package/src/server/host/dedicated/serverMetrics.ts +126 -0
  232. package/src/server/host/dedicated/socketPump.ts +21 -4
  233. package/src/server/host/dedicated/workerTable.ts +15 -4
  234. package/src/server/host/dedicated/world.ts +65 -7
  235. package/src/server/host/headless.ts +1 -1
  236. package/src/server/host/headlessRuntime.ts +1 -1
  237. package/src/server/host/standalone/roadWorld.ts +15 -3
  238. package/src/server/host/standalone/serverHost.ts +4 -1
  239. package/src/server/host/standalone/serverProduct.ts +41 -11
  240. package/src/shared/engine/ai/BossBrain.ts +8 -0
  241. package/src/shared/game/boss/wake.ts +6 -0
  242. package/src/shared/game/devColliders.ts +47 -0
  243. package/src/shared/game/eliteSystem.ts +8 -0
  244. package/src/shared/game/grid/allocator.ts +3 -0
  245. package/src/shared/game/grid/placementRows.ts +5 -2
  246. package/src/shared/game/plugin/bossRecord.ts +3 -2
  247. package/src/shared/game/shardfile/ktx2Targets.ts +23 -3
  248. package/src/shared/game/shardfile/outputDescriptor.ts +9 -5
  249. package/src/shared/game/shardfile/packReads.ts +28 -3
  250. package/src/shared/game/shardfile/serverPack.ts +9 -0
  251. package/src/shared/game/systems/looks/trampleField.ts +2 -0
  252. package/src/shared/host/formatJsonSchema.ts +2 -2
  253. package/src/tsconfig.json +1 -27
  254. package/lint/host-reviews.json +0 -14
  255. package/lint/listed-view-code.json +0 -13
  256. package/lint/platform-pending-users.json +0 -2520
  257. package/lint/platform-pending-users.md +0 -18
  258. package/scripts/cell-mem/metrics-preload.mjs +0 -65
  259. package/scripts/check-closed-components.d.mts +0 -7
  260. package/scripts/check-closed-components.mjs +0 -87
  261. package/scripts/g571-hosts.d.mts +0 -3
  262. package/scripts/g571-hosts.mjs +0 -54
  263. package/scripts/host-ruler/register-migrate.mjs +0 -242
  264. package/scripts/listed-view-code.d.mts +0 -7
  265. package/scripts/listed-view-code.mjs +0 -93
  266. package/scripts/look-loop/fit-lut.py +0 -142
  267. package/scripts/look-loop/palette-delta.py +0 -183
  268. package/scripts/look-loop/regions/driftwood-isle.json +0 -25
  269. package/scripts/look-loop/regions/far-reach.json +0 -225
  270. package/scripts/look-loop/regions/open-plot-night-market.json +0 -855
  271. package/scripts/look-loop/regions/pine-hollow.json +0 -22
  272. package/scripts/look-loop/regions/sunscar-dunes.json +0 -281
  273. package/scripts/platform-chargebacks.d.mts +0 -9
  274. package/scripts/platform-chargebacks.mjs +0 -135
  275. package/scripts/shard-component-spans.d.mts +0 -15
  276. package/scripts/shard-component-spans.mjs +0 -18
  277. package/scripts/shard-components.d.mts +0 -16
  278. package/scripts/shard-components.mjs +0 -363
  279. package/scripts/shard-platform-hosts.d.mts +0 -2
  280. package/scripts/shard-platform-hosts.mjs +0 -93
  281. package/scripts/shard-platform-sections.d.mts +0 -2
  282. package/scripts/shard-platform-sections.mjs +0 -9
  283. package/scripts/shard-platform.d.mts +0 -76
  284. package/scripts/shard-platform.mjs +0 -1072
  285. package/src/.oxfmtrc.json +0 -48
  286. package/src/scripts/ask-new.sh +0 -29
  287. package/src/scripts/asks.mjs +0 -142
  288. package/src/scripts/herdr-prompt.sh +0 -34
  289. package/src/scripts/herdr-question-open.sh +0 -67
  290. package/src/scripts/md-wrap.mjs +0 -229
  291. /package/scripts/{shard-platform-format.d.mts → node-format.d.mts} +0 -0
  292. /package/scripts/{shard-platform-format.mjs → node-format.mjs} +0 -0
  293. /package/scripts/{shard-platform-output.d.mts → output-reader.d.mts} +0 -0
@@ -27,12 +27,16 @@
27
27
  // world, a staging-like seat wait included. `--report` prints the same and exits 0. CI never runs this (FM11: no browser proof
28
28
  // in pre-push or CI); it is not in scripts/ci-pack.mjs.
29
29
  //
30
+ // `--one-origin` (OF12) serves both channels on the staging-like origin, from one profile: the proxy stamps the world only while
31
+ // the staging pass runs. Passes preview, staging, then preview again (offline, from what the first pass warmed), so each
32
+ // channel's worker activating over the other's on one origin must leave the other's caches whole.
33
+ //
30
34
  // `--walkthrough <slug>` is Jake's walk-through (OF21) on the staging-like build, on a fresh profile: online, Shard select to
31
35
  // the shard, play about 30 s moving around, close the browser, reopen it offline, Shard select to the same shard. Green only
32
36
  // when START, DOWNLOAD and LOAD finish from the cache, the player is in the world, and then the connection card shows.
33
37
  //
34
38
  // scripts/browser-lane.sh node scripts/offline-proof.mjs [--channel=staging|preview|both] [--mode=offline|slow|nobackend]
35
- // [--shard=<slug>[,<slug>]] [--entry=deck|resume|both] [--jobs=<n>] [--base=<served build>] [--out=<dir>] [--require-world] [--staging-port=<n>] [--report]
39
+ // [--shard=<slug>[,<slug>]] [--entry=deck|resume|both] [--jobs=<n>] [--base=<served build>] [--out=<dir>] [--require-world] [--staging-port=<n>] [--one-origin] [--cells=<n>] [--cold] [--report]
36
40
  // scripts/browser-lane.sh node scripts/offline-proof.mjs --walkthrough <slug> [--base=…] [--out=…] [--report]
37
41
  // With no `--base` it builds this working tree with scripts/serve-build.sh and stops that server at the end. `--jobs` above 1
38
42
  // gives each shard its own profile (one profile can't hold two browsers), which trades the shared-device shape for time.
@@ -74,6 +78,11 @@ if (!Number.isInteger(jobs) || jobs < 1) throw new Error(`--jobs is a whole numb
74
78
  /** OF5 and OF9 on: an entry that ends anywhere but in the world is red (a staging-like seat wait included). */
75
79
  const requireWorld = argv.includes('--require-world');
76
80
  const report = argv.includes('--report');
81
+ /** OF13: `--cold` enters a shard this profile never visited (no warm visits), as a device that downloaded only other shards. */
82
+ const cold = argv.includes('--cold');
83
+ /** OF12: both channels on one origin and one profile (see above). */
84
+ const oneOrigin = argv.includes('--one-origin');
85
+ if (oneOrigin && (jobs !== 1 || walkthrough !== undefined)) throw new Error('--one-origin runs one profile: --jobs=1, no --walkthrough');
77
86
  const out = resolvePath(ROOT, option('out') ?? join('tmp', 'offline-proof', new Date().toISOString().replaceAll(/[:.]/gu, '-')));
78
87
  mkdirSync(out, { recursive: true });
79
88
  const STAGING = CHANNELS.staging;
@@ -81,7 +90,10 @@ const STAGING = CHANNELS.staging;
81
90
  * tree (the default, or a `--base` served from it), not a build of another commit. */
82
91
  const CATALOGUE = JSON.parse(readFileSync(join(ROOT, 'src/shared/game/grid/singleplayer.json'), 'utf8'));
83
92
  /** The stand-in door's world word: every proof shard on staging's grid. */
84
- const WORLD_WORD = Buffer.concat([Buffer.from([9]), Buffer.from(JSON.stringify({ cells: 20, shards: [...ALL_SHARDS] }))]);
93
+ /** OF5b: `--cells=1` makes the stand-in door say production's one-cell word, so every page takes the one-shard `client` route. */
94
+ const WORD_CELLS = Number(option('cells') ?? 20);
95
+ if (!Number.isInteger(WORD_CELLS) || WORD_CELLS < 1) throw new Error(`--cells is a whole number from 1, not ${String(option('cells'))}`);
96
+ const WORLD_WORD = Buffer.concat([Buffer.from([9]), Buffer.from(JSON.stringify({ cells: WORD_CELLS, shards: [...ALL_SHARDS] }))]);
85
97
  const IPHONE = 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1';
86
98
  /** @param {number} ms */
87
99
  const sleep = ms => new Promise(resolve => { setTimeout(resolve, ms); });
@@ -113,6 +125,8 @@ const RELEASE_PATH = '/__offline-proof/staging.json';
113
125
  /** @type {Promise<string> | undefined} */
114
126
  let signedRelease;
115
127
  let stamperHits = 0, proxyOffline = false;
128
+ /** OF12 `--one-origin`: off while the preview pass runs, so the one origin serves the build as built. */
129
+ let stampOn = true;
116
130
  /** @type {string[]} the last reads the proxy answered, to name an offline leak */
117
131
  const stamperSeen = [];
118
132
  /** @param {import('node:http').IncomingMessage} request @param {import('node:http').ServerResponse} response */
@@ -146,7 +160,10 @@ async function stamp(request, response) {
146
160
  const sent = {};
147
161
  answer.headers.forEach((value, name) => { if (!['content-length', 'transfer-encoding', 'connection', 'keep-alive'].includes(name)) sent[name] = value; });
148
162
  const html = (answer.headers.get('content-type') ?? '').includes('text/html');
149
- if (html || new URL(request.url ?? '/', upstream).pathname.startsWith('/sw-core/')) {
163
+ const workerCore = new URL(request.url ?? '/', upstream).pathname.startsWith('/sw-core/');
164
+ // OF12: one origin, two documents under one name: neither may come from the HTTP cache, or a channel switch never lands
165
+ if (oneOrigin && (html || workerCore)) { for (const name of ['etag', 'last-modified']) Reflect.deleteProperty(sent, name); sent['cache-control'] = 'no-store'; }
166
+ if (stampOn && (html || workerCore)) {
150
167
  const text = body.toString('utf8');
151
168
  if (!text.includes('globalThis.__WS_BUILD_ID__=')) { response.writeHead(500).end('offline-proof: a document without the build stamp'); return; }
152
169
  // in the worker's copy the stamp sits inside a JSON string, so it goes in escaped
@@ -170,7 +187,7 @@ await new Promise((resolve, reject) => { stamper.once('error', reject); stamper.
170
187
  const stamperAddress = stamper.address();
171
188
  if (stamperAddress === null || typeof stamperAddress === 'string') throw new Error('offline-proof: the stamping server has no port');
172
189
  /** @type {Record<Channel, string>} */
173
- const ORIGINS = { preview: upstream.origin, staging: `http://127.0.0.1:${String(stamperAddress.port)}` };
190
+ const ORIGINS = { preview: oneOrigin ? `http://127.0.0.1:${String(stamperAddress.port)}` : upstream.origin, staging: `http://127.0.0.1:${String(stamperAddress.port)}` };
174
191
  STAMP = `globalThis.__WS_WORLD__=${JSON.stringify({ release: `${ORIGINS.staging}${RELEASE_PATH}`, key: RELEASE_PUBLIC_KEY })};`;
175
192
 
176
193
  /** A free loopback port for a browser's own DevTools endpoint. */
@@ -199,6 +216,9 @@ const readScreen = () => {
199
216
  const title = main instanceof HTMLElement && main.offsetParent !== null;
200
217
  const fail = [...document.querySelectorAll('[class^="ws-fail"],[class*=" ws-fail"]')].find(node => node instanceof HTMLElement && node.offsetParent !== null);
201
218
  const world = /** @type {{ __wildshard?: { world?: { player?: unknown } } }} */ (/** @type {unknown} */ (window)).__wildshard?.world;
219
+ /** @type {string | null | undefined} */ let grid;
220
+ // the probe's area (T2E-1b): a grid cell's instance, null between cells (the road); a one-shard page's area has no instance
221
+ try { const area = /** @type {any} */ (window).__wildshard?.area?.(); grid = area === null ? null : typeof area?.instance === 'string' ? area.instance : undefined; } catch { grid = undefined; }
202
222
  return {
203
223
  card, title: title && !card, player: world?.player !== undefined && world.player !== null && !card,
204
224
  phase: card ? (on instanceof HTMLElement ? on.dataset.phase ?? 'none' : 'none') : title ? 'title' : 'page',
@@ -210,6 +230,8 @@ const readScreen = () => {
210
230
  failCard: fail instanceof HTMLElement ? fail.innerText.replaceAll(/\s+/gu, ' ').slice(0, 300) : '',
211
231
  // oxlint-disable-next-line unicorn/prefer-dom-node-text-content -- the text a player sees, not hidden templates
212
232
  text: (document.body?.innerText ?? '').replaceAll(/\s+/gu, ' ').slice(0, 3000), url: location.href, world: Reflect.get(globalThis, '__WS_WORLD__') !== undefined,
233
+ // GC26: the grid cell the player stands in (absent on a one-shard page, null on the road)
234
+ ...grid === undefined ? {} : { inside: grid },
213
235
  };
214
236
  };
215
237
 
@@ -291,8 +313,9 @@ async function enter(run) {
291
313
  if (screen !== undefined) {
292
314
  last = screen; phase = screen.phase; step = screen.step;
293
315
  const previous = samples.at(-1);
294
- const sample = { t: at(), phase: screen.phase, step: screen.step, card: screen.card, title: screen.title, player: screen.player, failCard: screen.failCard, text: screen.text };
295
- if (previous === undefined || previous.phase !== sample.phase || previous.step !== sample.step || previous.title !== sample.title || previous.player !== sample.player || previous.failCard !== sample.failCard || previous.text.slice(0, 400) !== sample.text.slice(0, 400)) samples.push(sample);
316
+ /** @type {ScreenSample} */
317
+ const sample = { t: at(), phase: screen.phase, step: screen.step, card: screen.card, title: screen.title, player: screen.player, failCard: screen.failCard, text: screen.text, ...screen.inside === undefined ? {} : { inside: screen.inside } };
318
+ if (previous === undefined || previous.phase !== sample.phase || previous.step !== sample.step || previous.title !== sample.title || previous.player !== sample.player || previous.failCard !== sample.failCard || previous.inside !== sample.inside || previous.text.slice(0, 400) !== sample.text.slice(0, 400)) samples.push(sample);
296
319
  }
297
320
  };
298
321
  const poller = setInterval(() => { void poll(); }, 250);
@@ -311,7 +334,7 @@ async function enter(run) {
311
334
  let linked = open !== '/?mute=1';
312
335
  if (linked) phase = 'none';
313
336
  const hitsBefore = stamperHits;
314
- proxyOffline = mode === 'offline' && channel === 'staging' && jobs === 1;
337
+ proxyOffline = mode === 'offline' && (channel === 'staging' || oneOrigin) && jobs === 1;
315
338
  leakFrom = () => stamperHits - hitsBefore;
316
339
  leakedUrls = () => stamperSeen.slice(-Math.min(stamperSeen.length, stamperHits - hitsBefore));
317
340
  await page.goto(new URL(open, ORIGINS[channel]).href, { waitUntil: 'commit', timeout: 60_000 }).catch((/** @type {unknown} */ error) => { consoleLines.push(`goto ${String(error).slice(0, 200)}`); });
@@ -382,7 +405,7 @@ async function enter(run) {
382
405
  for (const name of await globalThis.caches.keys()) counts[name] = (await (await globalThis.caches.open(name)).keys()).length;
383
406
  return counts;
384
407
  }), 10_000) ?? {};
385
- const reached = mode === 'offline' && channel === 'staging' ? leakFrom() : 0;
408
+ const reached = mode === 'offline' && (channel === 'staging' || oneOrigin) ? leakFrom() : 0;
386
409
  if (reached > 0) consoleLines.push(`offline ${proxyOffline ? 'reads refused by the offline proxy' : 'leak'}: ${leakedUrls().join(' ')}`);
387
410
  // refused reads failed as they would on a phone, so they aren't a leak; with --jobs above 1 the proxy can't go offline
388
411
  const leaks = proxyOffline ? 0 : reached;
@@ -406,17 +429,53 @@ async function installApp(profile) {
406
429
  } finally { await context.close().catch(() => undefined); }
407
430
  }
408
431
 
432
+ /**
433
+ * OF12 `--one-origin`: hand the one origin to a channel. The page is served by the worker in control, whose copy of the document
434
+ * is the old channel's, so the new channel's worker is installed by an update check and adopted (SKIP_WAITING), as a deploy's is,
435
+ * until a fresh load of `/` carries the channel's stamp (or none). Logs the origin's caches after the switch.
436
+ * @param {string} profile @param {Channel} channel
437
+ */
438
+ async function switchChannel(profile, channel) {
439
+ const context = await chromium.launchPersistentContext(profile, { headless: true, viewport: { width: 402, height: 874 }, deviceScaleFactor: 3, hasTouch: true, isMobile: true, userAgent: IPHONE,
440
+ serviceWorkers: 'allow', args: ['--use-angle=metal', ...KEYCHAIN_ARGS, '--mute-audio'] });
441
+ try {
442
+ const page = context.pages()[0] ?? await context.newPage();
443
+ for (let attempt = 0; attempt < 4; attempt++) {
444
+ await page.goto(new URL('/?mute=1', ORIGINS[channel]).href, { waitUntil: 'load', timeout: 60_000 });
445
+ const world = await page.evaluate(() => Reflect.get(globalThis, '__WS_WORLD__') !== undefined);
446
+ const controlled = await page.evaluate(() => navigator.serviceWorker.controller !== null);
447
+ if (world === (channel === 'staging') && controlled) {
448
+ const names = await page.evaluate(async () => (await caches.keys()).sort());
449
+ log(`one origin is ${channel}'s (attempt ${String(attempt + 1)}); caches: ${names.join(' ')}`);
450
+ return;
451
+ }
452
+ await page.evaluate(async () => {
453
+ const registration = await navigator.serviceWorker.getRegistration();
454
+ await registration?.update().catch(() => undefined);
455
+ const next = registration?.installing ?? registration?.waiting;
456
+ if (next === null || next === undefined) return;
457
+ if (next.state === 'installing') await new Promise(resolve => { next.addEventListener('statechange', () => { if (next.state !== 'installing') resolve(null); }); });
458
+ // oxlint-disable-next-line unicorn/require-post-message-target-origin -- a ServiceWorker's postMessage takes no origin
459
+ next.postMessage({ type: 'SKIP_WAITING' });
460
+ await new Promise(resolve => { navigator.serviceWorker.addEventListener('controllerchange', () => { resolve(null); }); setTimeout(resolve, 10_000); });
461
+ }).catch(() => undefined);
462
+ }
463
+ throw new Error(`offline-proof: the one origin never turned to ${channel}`);
464
+ } finally { await context.close().catch(() => undefined); }
465
+ }
466
+
409
467
  /**
410
468
  * One shard on one channel: warm (once per profile), then the mode's entries.
411
469
  * @param {Channel} channel @param {Mode} mode @param {string} slug @param {string} profile
412
470
  */
413
471
  async function proveShard(channel, mode, slug, profile) {
414
472
  // beside its own profile, so a different --jobs layout (a cold profile) warms again
415
- const warmFile = join(`${profile}.warm-${slug}.json`);
473
+ const warmFile = join(oneOrigin ? `${profile}.warm-${channel}-${slug}.json` : `${profile}.warm-${slug}.json`);
416
474
  const results = [];
417
475
  /** @type {Set<string> | undefined} */
418
476
  let warm;
419
477
  if (existsSync(warmFile)) warm = new Set(/** @type {string[]} */ (JSON.parse(readFileSync(warmFile, 'utf8'))));
478
+ else if (cold) { log(`${channel}-${slug}: --cold, never visited on this profile`); warm = new Set(); }
420
479
  else {
421
480
  const label = `${channel}-warm-${slug}`;
422
481
  // Two visits: the first installs the worker (a fresh page isn't controlled), the second reads through it. A staging-like
@@ -448,10 +507,11 @@ function record(channel, mode, slug, entry, visit, warm, extra = {}) {
448
507
  const label = `${channel}-${mode}-${slug}-${entry}`;
449
508
  writeFileSync(join(out, `${label}-requests.json`), JSON.stringify(visit.rows));
450
509
  writeFileSync(join(out, `${label}-screens.json`), JSON.stringify({ samples: visit.samples, console: visit.consoleLines }));
451
- const layout = channel === 'staging' && mode === 'offline' && (entry === 'deck' || extra.walkthrough === true);
510
+ const layout = channel === 'staging' && mode === 'offline' && WORD_CELLS > 1 && (entry === 'deck' || extra.walkthrough === true); // a one-cell world (--cells=1) enters no grid
452
511
  const failures = judge({ shard: slug, channel, mode, entry, rows: visit.rows, samples: visit.samples,
453
512
  outcome: visit.outcome, ...warm === undefined ? {} : { warm }, layout, proofError: visit.proofError, leaks: visit.leaks,
454
- requireWorld: requireWorld && !mode.startsWith('warm'), placed: gridPlaces(slug, CATALOGUE), ...extra });
513
+ requireWorld: requireWorld && !mode.startsWith('warm'), placed: gridPlaces(slug, CATALOGUE),
514
+ linked: entry === 'deck' && (OPEN_PLOTS.includes(slug) || visit.consoleLines.some(line => line.startsWith('no deck card'))), ...extra });
455
515
  if (channel === 'staging' && !visit.world) failures.unshift({ shard: slug, rule: 'proof-not-a-world-build', detail: 'the page had no __WS_WORLD__ stamp' });
456
516
  const result = { shard: slug, channel, mode, entry, outcome: visit.outcome, ms: visit.ms, lastCard: visit.lastCard, served: servedCounts(visit.rows),
457
517
  swSoloReads: visit.rows.filter(row => row.origin === 'sw' && /serverWorker|serverRuntime|\/assets\/spawn\/server\//u.test(row.url)).length,
@@ -480,14 +540,15 @@ try {
480
540
  const offline = await enter({ channel: 'staging', profile, slug: walkthrough, mode: 'offline', entry: 'deck', label: `staging-walk-offline-${walkthrough}` });
481
541
  results.push(record('staging', 'offline', walkthrough, 'deck', offline, warm, { walkthrough: true }));
482
542
  } else {
483
- const channels = /** @type {Channel[]} */ (channelArg === 'both' ? ['preview', 'staging'] : [channelArg]);
543
+ const channels = /** @type {Channel[]} */ (oneOrigin ? ['preview', 'staging', 'preview'] : channelArg === 'both' ? ['preview', 'staging'] : [channelArg]);
484
544
  for (const channel of channels) {
485
545
  const mode = /** @type {Mode} */ (modeArg);
486
546
  if (channel === 'preview' && mode === 'nobackend') { log('preview has no world: --mode=nobackend skipped'); continue; }
547
+ if (oneOrigin) { stampOn = channel === 'staging'; await switchChannel(join(out, 'profile-one-origin'), channel); }
487
548
  const queue = [...shards];
488
549
  const worker = async (/** @type {number} */ lane) => {
489
550
  for (let slug = queue.shift(); slug !== undefined; slug = queue.shift()) {
490
- const profile = join(out, jobs > 1 ? `profile-${channel}-${slug}` : `profile-${channel}`);
551
+ const profile = join(out, oneOrigin ? 'profile-one-origin' : jobs > 1 ? `profile-${channel}-${slug}` : `profile-${channel}`);
491
552
  try { results.push(...await proveShard(channel, mode, slug, profile)); } catch (error) { log(`lane ${String(lane)} ${slug} broke: ${String(error)}`); results.push({ shard: slug, channel, mode, entry: 'deck', outcome: 'error', ms: 0, lastCard: '', served: {}, swSoloReads: 0, caches: {}, world: false, failures: [{ shard: slug, rule: 'proof-error', detail: String(error).slice(0, 300) }] }); }
492
553
  }
493
554
  };
@@ -3,7 +3,7 @@
3
3
  import { existsSync, readFileSync } from 'node:fs';
4
4
  import { createHash } from 'node:crypto';
5
5
  import { resolve } from 'node:path';
6
- import { outputFormat, platformFileFamiliesFormat } from './shard-platform-format.mjs';
6
+ import { outputFormat, platformFileFamiliesFormat } from './node-format.mjs';
7
7
  import { shardOutputs } from './shard-outputs.mjs';
8
8
 
9
9
  const {parseOutputIndex}=outputFormat;
@@ -7,9 +7,12 @@ export interface ContentStore {
7
7
  exists: (key: string) => Promise<boolean>;
8
8
  put: (puts: readonly Put[]) => Promise<void>;
9
9
  read: (key: string, origin: string) => Promise<Read>;
10
+ sets?: () => Promise<string[]>;
11
+ copy?: (from: string, to: string, headers: Headers, bytes: number) => Promise<void>;
10
12
  }
11
13
  export interface ContentSummary {
12
14
  set: string; base: string; files: number; bytes: number; uploaded: number; uploadedBytes: number; held: number;
15
+ copied: number; copiedBytes: number;
13
16
  kinds: Record<string, { files: number; bytes: number }>; cors: string;
14
17
  }
15
18
  export const BUCKET: string;
@@ -18,6 +21,7 @@ export const CONTENT_ROOT: string;
18
21
  export const GAME_ORIGIN: string;
19
22
  export const KIND_NAMES: readonly Kind[];
20
23
  export function contentHeaders(key: string): Headers;
24
+ export const UNREAD_PACK: RegExp;
21
25
  export function contentKind(path: string, shards: ReadonlySet<string>): Kind | undefined;
22
26
  export function contentKey(set: string, path: string): string;
23
27
  export function contentBaseOf(set: string): string;
@@ -27,4 +31,8 @@ export function contentIndex(set: string, files: readonly ContentFile[]): Buffer
27
31
  export function readBack(store: ContentStore, key: string, expected: string, origin: string, sleep: (ms: number) => Promise<void>): Promise<number>;
28
32
  export function publishContent(options: { dir: string; store: ContentStore; scratch: string; origin?: string; dryRun?: boolean; log: (line: string) => void; sleep?: (ms: number) => Promise<void> }): Promise<ContentSummary>;
29
33
  export function sampleContent(options: { dir: string; store: ContentStore; count: number; origins: readonly string[]; log: (line: string) => void; sleep?: (ms: number) => Promise<void> }): Promise<{ set: string; checked: Record<string, number> }>;
30
- export function r2Content(options: { root: string; scratch: string; token?: string; fetch?: typeof fetch; exec?: (file: string, args: string[], options: { cwd: string; env: NodeJS.ProcessEnv; timeout?: number }, secrets: string[]) => string }): ContentStore;
34
+ export const DONOR_SETS: number;
35
+ export const COPY_SAMPLE: number;
36
+ export function copyFromSets(options: { set: string; missing: readonly ContentFile[]; store: ContentStore; origin: string; log: (line: string) => void; sleep: (ms: number) => Promise<void> }): Promise<ContentFile[]>;
37
+ export function r2Copies(env: NodeJS.ProcessEnv): { sets: () => Promise<string[]>; copy: (from: string, to: string, headers: Headers, bytes: number) => Promise<void>; put: (puts: readonly Put[]) => Promise<void>; secrets: string[]; close: () => void } | undefined;
38
+ export function r2Content(options: { root: string; scratch: string; token?: string; fetch?: typeof fetch; copies?: Pick<ContentStore, 'sets' | 'copy'> & { put?: ContentStore['put'] }; exec?: (file: string, args: string[], options: { cwd: string; env: NodeJS.ProcessEnv; timeout?: number }, secrets: string[]) => string }): ContentStore;
@@ -8,8 +8,12 @@
8
8
  // SHA-256 over every published path, its SHA-256 and its size. PZ3's `contentBase` is one base that mirrors page paths,
9
9
  // so the set keeps page paths under one content-named prefix: a build that changes no content names the same set and
10
10
  // uploads nothing, and every key is immutable. The set's index, `content/<set>/content.json`, goes last; its presence
11
- // with the same bytes means the set is complete. (A new set re-uploads files an older set already holds: cross-set
12
- // dedupe is a follow-up, with PZ10's content cache.)
11
+ // with the same bytes means the set is complete.
12
+ //
13
+ // Cross-set dedupe (PZ6): a new set copies, server side (S3 CopyObject, R2_ACCOUNT_ID and R2_PACKS_* from the
14
+ // environment, the same bucket-scoped keys server-release uses), every missing file whose bytes a recent complete set
15
+ // already holds, so a content change uploads only the files that changed, not the whole ~2.2 GB. A copy is checked by its
16
+ // size on R2, and a sample of copies is read back through the CDN like an upload; a failed copy is uploaded instead.
13
17
  //
14
18
  // A key that already answers (a cache-busted HEAD on packs.wildshard.io) is skipped only when it reads back with the
15
19
  // same decoded bytes and CORS; one with other bytes is uploaded again. The rest go up through
@@ -22,6 +26,7 @@ import {mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync} f
22
26
  import {join, resolve} from 'node:path';
23
27
  import {setTimeout as delay} from 'node:timers/promises';
24
28
  import {brotliDecompressSync} from 'node:zlib';
29
+ import {CopyObjectCommand, HeadObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client} from '@aws-sdk/client-s3';
25
30
  import {carriedPaths, classify, shardNames} from '../page-size.mjs';
26
31
  import {PACKS_ORIGIN} from './flow.mjs';
27
32
  import {runRedacted} from './redact.mjs';
@@ -46,9 +51,17 @@ const sha256 = (/** @type {Uint8Array} */ bytes) => createHash('sha256').update(
46
51
  * @property {(key: string) => Promise<boolean>} exists The key answers 200 now (never a cached 404).
47
52
  * @property {(puts: readonly Put[]) => Promise<void>} put
48
53
  * @property {(key: string, origin: string) => Promise<Read>} read A cache-busted CORS GET, decoded.
54
+ * @property {() => Promise<string[]>} [sets] PZ6: the complete sets (their `content.json` present), newest first.
55
+ * @property {(from: string, to: string, headers: Headers, bytes: number) => Promise<void>} [copy] PZ6: a server-side
56
+ * copy with the target's headers, refused unless the copy holds `bytes`.
49
57
  */
50
58
  /** @typedef {{set: string, base: string, files: number, bytes: number, uploaded: number, uploadedBytes: number, held: number,
51
- * kinds: Record<string, {files: number, bytes: number}>, cors: string}} ContentSummary */
59
+ * copied: number, copiedBytes: number, kinds: Record<string, {files: number, bytes: number}>, cors: string}} ContentSummary
60
+ * `uploaded` counts every key this run wrote (put or copied), `uploadedBytes` only the bytes it sent; `copied` and
61
+ * `copiedBytes` are the keys and bytes copied from an older set on R2 (PZ6). */
62
+ /** PZ6: how many recent complete sets a new set may copy from, and how many copies each publish reads back in full. */
63
+ export const DONOR_SETS = 4;
64
+ export const COPY_SAMPLE = 24;
52
65
 
53
66
  /** The cook's object headers (`objectHeaders()`, src/cook/game/cookWorker.ts), every key immutable: a set is content-named.
54
67
  * @param {string} key @returns {Headers} */
@@ -58,9 +71,16 @@ export function contentHeaders(key) {
58
71
  return {type, cache: IMMUTABLE};
59
72
  }
60
73
 
61
- /** The kind a page path publishes as, or undefined when it stays on the page (code, shell, runtime, maps).
74
+ /** PZ7: a shard file's I5 packs (`shardfiles/<slug>/blobs/pack/`, 475 MB). The wire meter read none of them on any deck
75
+ * card or the grid, phone and desktop (meta docs/plans/page-size/pz7-wire-meter-2026-11-13.json): spawn downloads read
76
+ * the loose blobs, and every pack reader falls back to them (`packOrLoose`, src/shared/game/shardfile/packReads.ts). */
77
+ export const UNREAD_PACK = /^shardfiles\/[^/]+\/blobs\/pack\//u;
78
+
79
+ /** The kind a page path publishes as, or undefined when it stays on the page (code, shell, runtime, maps) or nobody reads
80
+ * it (PZ7's S1 packs).
62
81
  * @param {string} path @param {ReadonlySet<string>} shards @returns {Kind | undefined} */
63
82
  export function contentKind(path, shards) {
83
+ if (UNREAD_PACK.test(path)) return undefined;
64
84
  const {kind, part} = classify(path, shards);
65
85
  if (kind === 'shard content') return /** @type {Kind} */ (part);
66
86
  return kind === 'engine art' ? 'E1' : undefined;
@@ -134,8 +154,8 @@ export async function publishContent({dir, store, scratch, origin = GAME_ORIGIN,
134
154
  const kinds = Object.fromEntries(KIND_NAMES.map(kind => [kind, {files: 0, bytes: 0}]));
135
155
  for (const file of files) { const row = kinds[file.kind]; if (row !== undefined) { row.files++; row.bytes += file.bytes; } }
136
156
  const bytes = files.reduce((sum, file) => sum + file.bytes, 0);
137
- const summary = (/** @type {number} */ uploaded, /** @type {number} */ uploadedBytes) =>
138
- ({set, base: contentBaseOf(set), files: files.length, bytes, uploaded, uploadedBytes, held: files.length - uploaded, kinds, cors: origin});
157
+ const summary = (/** @type {number} */ uploaded, /** @type {number} */ uploadedBytes, copied = 0, copiedBytes = 0) =>
158
+ ({set, base: contentBaseOf(set), files: files.length, bytes, uploaded, uploadedBytes, held: files.length - uploaded, copied, copiedBytes, kinds, cors: origin});
139
159
  const indexKey = contentKey(set, 'content.json');
140
160
  if (dryRun) {
141
161
  log(`DRY-RUN would publish ${files.length} files (${mb(bytes)} MB) as ${contentBaseOf(set)}: HEAD each on ${PACKS_ORIGIN}, wrangler r2 bulk put the missing ones to ${BUCKET}, read each back with CORS ${origin}, then ${indexKey}`);
@@ -160,8 +180,12 @@ export async function publishContent({dir, store, scratch, origin = GAME_ORIGIN,
160
180
  missing.push(file);
161
181
  });
162
182
  missing.sort((a, b) => (a.path < b.path ? -1 : 1));
183
+ const written = missing.length;
184
+ const copied = await copyFromSets({set, missing, store, origin, log, sleep});
185
+ const copiedBytes = copied.reduce((sum, file) => sum + file.bytes, 0);
186
+ if (copied.length > 0) { const done = new Set(copied); missing.splice(0, missing.length, ...missing.filter(file => !done.has(file))); }
163
187
  const uploadedBytes = missing.reduce((sum, file) => sum + file.bytes, 0);
164
- log(`content ${set}: ${files.length} files (${mb(bytes)} MB), ${files.length - missing.length} held (read back equal), ${missing.length} to upload (${mb(uploadedBytes)} MB, ${wrong} present with other bytes)`);
188
+ log(`content ${set}: ${files.length} files (${mb(bytes)} MB), ${files.length - written} held (read back equal), ${copied.length} copied on R2 (${mb(copiedBytes)} MB), ${missing.length} to upload (${mb(uploadedBytes)} MB, ${wrong} present with other bytes)`);
165
189
  if (missing.length > 0) {
166
190
  // `wrangler r2 bulk put` stops at the first failed object (a 502 and a 429 were seen); what landed answers a HEAD, so a retry
167
191
  // puts only the rest.
@@ -192,8 +216,95 @@ export async function publishContent({dir, store, scratch, origin = GAME_ORIGIN,
192
216
  await store.put([{key: indexKey, file: indexFile, headers: contentHeaders(indexKey)}]);
193
217
  await readBack(store, indexKey, sha256(index), origin, sleep);
194
218
  } finally { rmSync(indexFile, {force: true}); }
195
- log(`content ${set}: ${missing.length} uploaded (${mb(uploadedBytes)} MB), ${files.length - missing.length} held, all read back with CORS ${origin}; base ${contentBaseOf(set)}`);
196
- return summary(missing.length, uploadedBytes);
219
+ log(`content ${set}: ${missing.length} uploaded (${mb(uploadedBytes)} MB), ${copied.length} copied (${mb(copiedBytes)} MB), ${files.length - written} held, read back with CORS ${origin}; base ${contentBaseOf(set)}`);
220
+ return summary(written, uploadedBytes, copied.length, copiedBytes);
221
+ }
222
+
223
+ /**
224
+ * PZ6: copy each missing file whose bytes a recent complete set holds, server side, under this set's key with this
225
+ * path's headers. Returns the files copied; the rest are left to the upload. Each copy is size-checked by the store, and
226
+ * a sample of them is read back in full through the CDN with the game's CORS.
227
+ * @param {{set: string, missing: readonly ContentFile[], store: ContentStore, origin: string, log: (line: string) => void, sleep: (ms: number) => Promise<void>}} options
228
+ * @returns {Promise<ContentFile[]>}
229
+ */
230
+ export async function copyFromSets({set, missing, store, origin, log, sleep}) {
231
+ const {sets, copy} = store;
232
+ if (sets === undefined || copy === undefined || missing.length === 0) return [];
233
+ const donors = (await sets()).filter(name => name !== set).slice(0, DONOR_SETS);
234
+ /** @type {Map<string, string>} sha256 and size to a donor key, the newest set first */
235
+ const held = new Map();
236
+ for (const donor of donors) {
237
+ const read = await store.read(contentKey(donor, 'content.json'), origin);
238
+ if (read.status !== 200) { log(`content ${set}: donor ${donor}'s index answered ${read.status}; skipped`); continue; }
239
+ /** @type {{files?: {path: string, bytes: number, sha256: string}[]}} */ const index = JSON.parse(Buffer.from(read.bytes).toString('utf8'));
240
+ for (const file of index.files ?? []) {
241
+ const id = `${file.sha256}:${file.bytes}`;
242
+ if (!held.has(id)) held.set(id, contentKey(donor, file.path));
243
+ }
244
+ }
245
+ /** @type {ContentFile[]} */ const copied = [];
246
+ let failed = 0;
247
+ await pool(missing.filter(file => held.has(`${file.sha256}:${file.bytes}`)), 32, async file => {
248
+ const from = held.get(`${file.sha256}:${file.bytes}`) ?? '';
249
+ try { await copy(from, contentKey(set, file.path), contentHeaders(file.path), file.bytes); copied.push(file); }
250
+ catch (error) { failed++; log(`content ${set}: copy ${from} failed (${error instanceof Error ? error.message : String(error)}); uploading it`); }
251
+ });
252
+ copied.sort((a, b) => (a.path < b.path ? -1 : 1));
253
+ // a copy keeps R2's bytes, so a sample proves the headers and the CDN answer; every upload is still read back in full
254
+ const left = [...copied], sample = [];
255
+ while (sample.length < COPY_SAMPLE && left.length > 0) sample.push(...left.splice(randomInt(left.length), 1));
256
+ await pool(sample, 8, file => readBack(store, contentKey(set, file.path), file.decoded, origin, sleep).then(() => undefined));
257
+ if (donors.length > 0) log(`content ${set}: ${copied.length} copied from ${donors.join(', ')}, ${failed} copies failed, ${Math.min(COPY_SAMPLE, copied.length)} read back`);
258
+ return copied;
259
+ }
260
+
261
+ /**
262
+ * PZ6: R2's S3 API on the packs bucket, for the store's `sets` and `copy`. Credentials from the environment
263
+ * (R2_ACCOUNT_ID, R2_PACKS_ACCESS_KEY_ID, R2_PACKS_SECRET_ACCESS_KEY: server-release's bucket-scoped keys), else none.
264
+ * @param {NodeJS.ProcessEnv} env
265
+ * With them the store also puts through S3 (16 at a time), not `wrangler r2 bulk put`, so a CI token needs no R2 write.
266
+ * @returns {{sets: () => Promise<string[]>, copy: (from: string, to: string, headers: Headers, bytes: number) => Promise<void>, put: (puts: readonly Put[]) => Promise<void>, secrets: string[], close: () => void} | undefined}
267
+ */
268
+ export function r2Copies(env) {
269
+ const account = env.R2_ACCOUNT_ID?.trim(), accessKeyId = env.R2_PACKS_ACCESS_KEY_ID?.trim(), secretAccessKey = env.R2_PACKS_SECRET_ACCESS_KEY?.trim();
270
+ if (account === undefined || accessKeyId === undefined || secretAccessKey === undefined || account === '' || accessKeyId === '' || secretAccessKey === '') return undefined;
271
+ if (!/^[0-9a-f]{32}$/u.test(account)) throw new Error('Invalid R2_ACCOUNT_ID');
272
+ const client = new S3Client({region: 'auto', endpoint: `https://${account}.r2.cloudflarestorage.com`, credentials: {accessKeyId, secretAccessKey}});
273
+ return {
274
+ secrets: [accessKeyId, secretAccessKey],
275
+ close: () => client.destroy(),
276
+ async sets() {
277
+ /** @type {string[]} */ const prefixes = [];
278
+ for (let token; ;) {
279
+ const page = await client.send(new ListObjectsV2Command({Bucket: BUCKET, Prefix: `${CONTENT_ROOT}/`, Delimiter: '/', ContinuationToken: token}));
280
+ for (const row of page.CommonPrefixes ?? []) if (row.Prefix !== undefined) prefixes.push(row.Prefix);
281
+ if (page.IsTruncated !== true || page.NextContinuationToken === undefined) break;
282
+ token = page.NextContinuationToken;
283
+ }
284
+ /** @type {{set: string, at: number}[]} */ const complete = [];
285
+ await pool(prefixes, 8, async prefix => {
286
+ const set = prefix.slice(CONTENT_ROOT.length + 1, -1);
287
+ if (!/^[0-9a-f]{16}$/u.test(set)) return;
288
+ try {
289
+ const head = await client.send(new HeadObjectCommand({Bucket: BUCKET, Key: contentKey(set, 'content.json')}));
290
+ complete.push({set, at: head.LastModified?.getTime() ?? 0});
291
+ } catch (error) { if (!(error instanceof Error && (error.name === 'NotFound' || error.name === 'NoSuchKey'))) throw error; }
292
+ });
293
+ return complete.sort((a, b) => b.at - a.at).map(row => row.set);
294
+ },
295
+ async put(puts) {
296
+ await pool(puts, 16, async item => {
297
+ await client.send(new PutObjectCommand({Bucket: BUCKET, Key: item.key, Body: readFileSync(item.file),
298
+ ContentType: item.headers.type, CacheControl: item.headers.cache, ...(item.headers.encoding === undefined ? {} : {ContentEncoding: item.headers.encoding})}));
299
+ });
300
+ },
301
+ async copy(from, to, headers, bytes) {
302
+ await client.send(new CopyObjectCommand({Bucket: BUCKET, Key: to, CopySource: `${BUCKET}/${from.split('/').map(encodeURIComponent).join('/')}`,
303
+ MetadataDirective: 'REPLACE', ContentType: headers.type, CacheControl: headers.cache, ...(headers.encoding === undefined ? {} : {ContentEncoding: headers.encoding})}));
304
+ const head = await client.send(new HeadObjectCommand({Bucket: BUCKET, Key: to}));
305
+ if (head.ContentLength !== bytes) throw new Error(`${to} holds ${head.ContentLength} bytes after the copy, not ${bytes}`);
306
+ },
307
+ };
197
308
  }
198
309
 
199
310
  /**
@@ -219,10 +330,11 @@ export async function sampleContent({dir, store, count, origins, log, sleep = de
219
330
 
220
331
  /**
221
332
  * The real store: HEAD and GET through packs.wildshard.io, writes through `wrangler r2 bulk put`, one call per header set.
222
- * @param {{root: string, scratch: string, token?: string, fetch?: typeof fetch, exec?: typeof runRedacted}} options
333
+ * PZ6: with `copies` (r2Copies) the store also lists complete sets, copies keys server side, and puts through S3.
334
+ * @param {{root: string, scratch: string, token?: string, fetch?: typeof fetch, exec?: typeof runRedacted, copies?: Pick<ContentStore, 'sets' | 'copy'> & {put?: ContentStore['put']}}} options
223
335
  * @returns {ContentStore}
224
336
  */
225
- export function r2Content({root, scratch, token, fetch: get = fetch, exec = runRedacted}) {
337
+ export function r2Content({root, scratch, token, fetch: get = fetch, exec = runRedacted, copies}) {
226
338
  let reads = 0;
227
339
  const bust = (/** @type {string} */ key) => {
228
340
  const url = new URL(`/${key}`, PACKS_ORIGIN);
@@ -231,6 +343,7 @@ export function r2Content({root, scratch, token, fetch: get = fetch, exec = runR
231
343
  };
232
344
  const secrets = token === undefined || token === '' ? [] : [token];
233
345
  return {
346
+ ...(copies?.sets === undefined || copies.copy === undefined ? {} : {sets: copies.sets, copy: copies.copy}),
234
347
  async exists(key) {
235
348
  for (let attempt = 0; ; attempt++) {
236
349
  const response = await get(bust(key), {method: 'HEAD', cache: 'no-store', redirect: 'error', signal: AbortSignal.timeout(30_000)}).catch((/** @type {unknown} */ error) => { if (attempt < 3) return undefined; throw error; });
@@ -241,7 +354,7 @@ export function r2Content({root, scratch, token, fetch: get = fetch, exec = runR
241
354
  await delay(2_000);
242
355
  }
243
356
  },
244
- put(puts) {
357
+ put: copies?.put ?? (puts => {
245
358
  /** @type {Map<string, Put[]>} */
246
359
  const groups = new Map();
247
360
  for (const item of puts) {
@@ -260,7 +373,7 @@ export function r2Content({root, scratch, token, fetch: get = fetch, exec = runR
260
373
  } finally { rmSync(list, {force: true}); }
261
374
  }
262
375
  return Promise.resolve();
263
- },
376
+ }),
264
377
  async read(key, origin) {
265
378
  for (let attempt = 0; ; attempt++) {
266
379
  try {
@@ -277,10 +390,11 @@ async function main() {
277
390
  const value = (/** @type {string} */ name) => args.find(arg => arg.startsWith(`--${name}=`))?.split('=').slice(1).join('=');
278
391
  const dir = args.find(arg => !arg.startsWith('--'));
279
392
  if (dir === undefined) throw new Error('usage: node scripts/page-release/content.mjs <dist> [--origin=<page origin>] [--sample=<n>] [--dry-run]');
280
- const root = resolve(import.meta.dirname, '../..'), token = process.env.CLOUDFLARE_API_TOKEN;
281
- const hide = (/** @type {string} */ text) => token === undefined || token === '' ? text : text.split(token).join('<token>');
393
+ const root = resolve(import.meta.dirname, '../..'), token = process.env.CLOUDFLARE_API_TOKEN, copies = r2Copies(process.env);
394
+ const secrets = [...(token === undefined || token === '' ? [] : [token]), ...copies?.secrets ?? []];
395
+ const hide = (/** @type {string} */ text) => secrets.reduce((out, secret) => out.split(secret).join('<token>'), text);
282
396
  const log = (/** @type {string} */ line) => console.log(hide(line));
283
- const scratch = join(root, 'tmp/page-release/content'), store = r2Content({root, scratch, token});
397
+ const scratch = join(root, 'tmp/page-release/content'), store = r2Content({root, scratch, token, copies});
284
398
  const sample = value('sample');
285
399
  try {
286
400
  if (sample !== undefined) {
@@ -293,7 +407,7 @@ async function main() {
293
407
  } catch (error) {
294
408
  console.error(hide(`content failed: ${error instanceof Error ? error.message : String(error)}`));
295
409
  process.exitCode = 1;
296
- }
410
+ } finally { copies?.close(); }
297
411
  }
298
412
 
299
413
  if (process.argv[1] !== undefined && resolve(process.argv[1]) === import.meta.filename) await main();
@@ -78,7 +78,7 @@ export class RefusedError extends Error {
78
78
  * Parts first, the book last; an existing object must already have the same bytes.
79
79
  * @property {(context: {root: string, build: string, cors: string}) => Promise<PacksSummary>} verify Read-only.
80
80
  *
81
- * @typedef {{set: string, base: string, files: number, bytes: number, uploaded: number, uploadedBytes: number, held: number, cors: string}} ContentSummary
81
+ * @typedef {{set: string, base: string, files: number, bytes: number, uploaded: number, uploadedBytes: number, held: number, copied?: number, copiedBytes?: number, cors: string}} ContentSummary
82
82
  * @typedef {object} ContentPublisher
83
83
  * @property {(context: {dir: string, cors: string, dryRun: boolean}) => Promise<ContentSummary>} publish
84
84
  * PAGE-SIZE PZ2: the page's shard content and engine art to the packs bucket, read back with CORS (content.mjs).
@@ -90,7 +90,7 @@ export class RefusedError extends Error {
90
90
  * @property {PageHost} host
91
91
  * @property {PackStore} packs
92
92
  * @property {ContentPublisher} [content] PZ2: publish the page's content set before the page goes up (page-release.mjs
93
- * --content). Nothing stamps its base into the page yet: PZ4 and PZ6 do.
93
+ * --content). PZ6: the build then stamps the set's base into the page and keeps the split (dist-content/ is published).
94
94
  * @property {(file: string, args: string[], env: Record<string, string>) => void} run
95
95
  * @property {(url: string) => Promise<unknown>} fetchJSON 200 only, no cache, no redirects.
96
96
  * @property {(url: string) => Promise<string>} fetchText
@@ -146,17 +146,32 @@ export async function runPhase(phase, deps) {
146
146
  for (const line of deps.host.describe('prepare', context)) plan(line);
147
147
  if (!dry) await deps.host.prepare(context);
148
148
  plan(`run pnpm build:game with ${channel.solo ? 'no release file (solo)' : `WILDSHARD_RELEASE_URL=${env.WILDSHARD_RELEASE_URL}`} WILDSHARD_CATALOGUE=${env.WILDSHARD_CATALOGUE} WS_BUILD_ID=${deps.build} WS_CHANNEL=${channel.channel}`);
149
- if (!dry) deps.run('pnpm', ['build:game'], {...env, ...deps.host.buildEnv(context)});
150
- // PAGE-SIZE PZ4: build:game splits the page (dist/) from its content (dist-content/). No channel stamps a contentBase
151
- // yet, so each page still serves its own content: join the two before packaging, until PZ8 ships the split.
152
- plan('join dist-content/ back into dist/ (no channel has a contentBase yet)');
153
- if (!dry) deps.run('node', ['scripts/app-build/splitOutput.mjs', 'dist', '--join'], {});
149
+ // PZ5/PZ6: a build that publishes its content names its code only in deploy-chunks.json (`content: true`), so the
150
+ // next release carries its code only (app-build-pipeline.mjs reads WS_CONTENT_BASE)
151
+ const contentEnv = deps.content === undefined ? {} : {WS_CONTENT_BASE: `${PACKS_ORIGIN}/content/`};
152
+ if (!dry) deps.run('pnpm', ['build:game'], {...env, ...contentEnv, ...deps.host.buildEnv(context)});
153
+ // PAGE-SIZE PZ4: build:game splits the page (dist/) from its content (dist-content/). A release that publishes its
154
+ // content (--content, PZ6) stamps the set's base into the page and keeps the split; one that doesn't joins the two, so
155
+ // the page serves its own content.
156
+ if (deps.content === undefined) {
157
+ plan('join dist-content/ back into dist/ (no content base: the page serves its own content)');
158
+ if (!dry) deps.run('node', ['scripts/app-build/splitOutput.mjs', 'dist', '--join'], {});
159
+ } else {
160
+ plan(`stamp dist/index.html with the content set's base on ${PACKS_ORIGIN}/content/ and bake its service worker again (PZ6)`);
161
+ if (!dry) deps.run('node', ['--import', './scripts/bake-loader.mjs', 'scripts/page-release/stamp-content.mjs', 'dist'], {});
162
+ }
154
163
  for (const line of deps.host.describe('package', context)) plan(line);
155
164
  if (!dry) await deps.host.package(context);
156
165
  plan(`check ${deps.host.outputDir(context)} names ${channel.solo ? 'no release file' : channel.release} and build ${deps.build}`);
157
166
  if (dry) return {refusals};
158
167
  const files = checkOutput(channel, deps, context, refuse);
159
- deps.state.write('build', {build: deps.build, channel: channel.channel, host: deps.host.name, files});
168
+ /** @type {string|undefined} */
169
+ let contentBase;
170
+ if (deps.content !== undefined) {
171
+ contentBase = contentBaseIn(Buffer.from(deps.readFile(`${deps.host.outputDir(context)}/index.html`)).toString('utf8'));
172
+ if (contentBase === undefined || !contentBase.startsWith(`${PACKS_ORIGIN}/content/`)) refuse(`index.html content base is ${contentBase ?? 'missing'}, not a set on ${PACKS_ORIGIN}`);
173
+ }
174
+ deps.state.write('build', {build: deps.build, channel: channel.channel, host: deps.host.name, files, ...(contentBase === undefined ? {} : {contentBase})});
160
175
  deps.log(`PASS ${channel.channel} page built for ${deps.build}; nothing uploaded, alias not moved`);
161
176
  return {refusals};
162
177
  }
@@ -172,9 +187,11 @@ export async function runPhase(phase, deps) {
172
187
  /** @type {ContentSummary|undefined} */
173
188
  let content;
174
189
  if (deps.content !== undefined) {
175
- plan(`publish the page's content (S1 to S7, E1) from ${deps.host.outputDir(context)} to ${PACKS_ORIGIN}/content/<set>/ with CORS ${channel.origin} (PZ2, before the page)`);
176
- content = await deps.content.publish({dir: deps.host.outputDir(context), cors: channel.origin, dryRun: dry});
190
+ const contentDir = `${deps.host.outputDir(context)}-content`;
191
+ plan(`publish the page's content (S1 to S7, E1) from ${contentDir} to ${PACKS_ORIGIN}/content/<set>/ with CORS ${channel.origin} (PZ2, before the page)`);
192
+ content = await deps.content.publish({dir: contentDir, cors: channel.origin, dryRun: dry});
177
193
  if (!dry && content.held + content.uploaded !== content.files) refuse(`content: ${content.held} held + ${content.uploaded} uploaded is not ${content.files}`);
194
+ if (!dry && content.base !== built.contentBase) refuse(`content: published ${content.base}, but the page is stamped with ${built.contentBase ?? 'no base'}`);
178
195
  }
179
196
  /** @type {PacksSummary|undefined} */
180
197
  let packs;
@@ -261,6 +278,15 @@ export function buildEnv(channel, deps) {
261
278
  : {...common, WILDSHARD_RELEASE_URL: channel.release, WILDSHARD_RELEASE_KEY: deps.releaseKey ?? RELEASE_PUBLIC_KEY};
262
279
  }
263
280
 
281
+ /** PZ6: the boot bank's `contentBase` in a built document (undefined when it has none, or it is empty).
282
+ * @param {string} html @returns {string|undefined} */
283
+ export function contentBaseIn(html) {
284
+ const bank = /<script type="application\/json" id="boot-module-files">([^<]+)<\/script>/u.exec(html)?.[1];
285
+ if (bank === undefined) return undefined;
286
+ const base = JSON.parse(bank).contentBase;
287
+ return typeof base === 'string' && base !== '' ? base : undefined;
288
+ }
289
+
264
290
  /**
265
291
  * The packaged page names this build, this channel's release file and key, and never the other channel's file.
266
292
  * @param {ChannelConfig} channel @param {Deps} deps @param {HostContext} context @param {(message: string) => void} refuse
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ // PAGE-SIZE PZ6 (meta docs/plans/PAGE-SIZE-PLAN.md, J276): a split page (`dist/`, its content in `dist-content/`) reads its
3
+ // content from the CDN. The content set is named by the files content.mjs publishes from `dist-content/`, so the base is
4
+ // known before the upload: stamp it into `dist/index.html`, then bake the service worker again from the stamped document
5
+ // (content-sw-proof's order; the worker's precache lists move to CDN URLs). page-release.mjs runs this in the build phase
6
+ // when it publishes content, and its upload phase refuses a published set whose base differs from the stamped one.
7
+ //
8
+ // node --import ./scripts/bake-loader.mjs scripts/page-release/stamp-content.mjs <dist>
9
+ import {existsSync, readFileSync, writeFileSync} from 'node:fs';
10
+ import {join, resolve} from 'node:path';
11
+ import {stampContentBase} from '../app-build/contentBase.mjs';
12
+ import {contentBaseOf, contentSet, scanContent} from './content.mjs';
13
+
14
+ const dist = process.argv[2];
15
+ if (dist === undefined) throw new Error('usage: node --import ./scripts/bake-loader.mjs scripts/page-release/stamp-content.mjs <dist>');
16
+ const page = resolve(dist), content = `${page}-content`, root = resolve(import.meta.dirname, '../..');
17
+ if (!existsSync(content)) throw new Error(`${content} is missing: stamp a split page (pnpm build:game splits it)`);
18
+ const files = scanContent(content);
19
+ if (files.length === 0) throw new Error(`${content} holds no content`);
20
+ const base = contentBaseOf(contentSet(files));
21
+ writeFileSync(join(page, 'index.html'), stampContentBase(readFileSync(join(page, 'index.html'), 'utf8'), base));
22
+ const {writeServiceWorker} = await import('../app-build/serviceWorker.ts');
23
+ await writeServiceWorker(page, root);
24
+ console.log(`stamped ${dist}/index.html with ${base} (${files.length} content files) and baked its service worker again`);