@wildshard/engine 0.1.21 → 0.1.23

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 (144) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/lint/engine-sides.json +5 -0
  3. package/lint/shardfile-boundaries.mjs +4 -2
  4. package/lint/sim-players.json +2 -13
  5. package/lint/wildshard-plugin.js +1 -1
  6. package/package.json +10 -2
  7. package/scripts/apfs-clone.mjs +5 -2
  8. package/scripts/app-build/catalogue.ts +39 -8
  9. package/scripts/app-build/serviceWorker.ts +4 -1
  10. package/scripts/app-build/splitOutput.mjs +33 -11
  11. package/scripts/audio-download-proof.mjs +1 -1
  12. package/scripts/check-spelled-paths.mjs +6 -3
  13. package/scripts/ci-pack.mjs +3 -3
  14. package/scripts/committed-fast-checks.mjs +2 -2
  15. package/scripts/engine-ci-shard.mjs +11 -0
  16. package/scripts/failmode-cases.mjs +1 -1
  17. package/scripts/failmode-proof.mjs +35 -11
  18. package/scripts/fight-page-census.mjs +131 -0
  19. package/scripts/goldens/board.py +44 -11
  20. package/scripts/goldens/native-residency.d.mts +1 -0
  21. package/scripts/goldens/native-residency.mjs +18 -4
  22. package/scripts/grid-crossing-walk-proof.mjs +3 -3
  23. package/scripts/hover-speed-probe.mjs +2 -2
  24. package/scripts/keep-copy.mjs +120 -0
  25. package/scripts/land.mjs +36 -6
  26. package/scripts/lane-live.mjs +136 -0
  27. package/scripts/leftovers-report.mjs +47 -0
  28. package/scripts/loading-card-proof.mjs +42 -9
  29. package/scripts/loading-flow/benchmax.mjs +57 -7
  30. package/scripts/loading-flow/stalls.d.mts +2 -0
  31. package/scripts/loading-flow/stalls.mjs +13 -0
  32. package/scripts/mmo-bots.mjs +11 -5
  33. package/scripts/mmo-grid-proof.mjs +74 -0
  34. package/scripts/mmo-seat-proof.mjs +43 -0
  35. package/scripts/net-lag-proof.mjs +1 -1
  36. package/scripts/nightly-heads.ts +13 -13
  37. package/scripts/nightly-model.ts +26 -12
  38. package/scripts/nightly.proof.ts +18 -5
  39. package/scripts/nightly.ts +13 -8
  40. package/scripts/no-astc-boot.mjs +77 -0
  41. package/scripts/online-rig.mjs +7 -7
  42. package/scripts/parity/boot-smoke.mjs +1 -1
  43. package/scripts/physics-route.json +6 -6
  44. package/scripts/pins-reuse.mjs +1 -0
  45. package/scripts/pins-staging.ts +54 -0
  46. package/scripts/pins.ts +5 -0
  47. package/scripts/release-cook.mjs +6 -2
  48. package/scripts/ring3.proof.ts +71 -0
  49. package/scripts/ring3.ts +100 -0
  50. package/scripts/scratch-dir.mjs +31 -12
  51. package/scripts/scratch-sweep.mjs +15 -23
  52. package/scripts/server-release/items.d.mts +7 -0
  53. package/scripts/server-release/items.mjs +28 -0
  54. package/scripts/server-release/publish.mjs +9 -1
  55. package/scripts/side-parity.mjs +1 -1
  56. package/scripts/test-products.json +1 -21
  57. package/scripts/tsconfig.json +2 -0
  58. package/scripts/vitest-ci-files.ts +5 -1
  59. package/scripts/vps/cook-follow.d.mts +6 -0
  60. package/scripts/vps/cook-follow.mjs +45 -0
  61. package/scripts/vps/harden-apply.sh +10 -1
  62. package/scripts/vps/rebuild.sh +104 -36
  63. package/scripts/vps/wildshard-config +106 -3
  64. package/scripts/warm-native-chrome.mjs +9 -3
  65. package/scripts/worker-client-fights.mjs +9 -3
  66. package/scripts/worktree-reap.mjs +15 -131
  67. package/scripts/worktree.mjs +92 -12
  68. package/src/client/app/entry.ts +2 -3
  69. package/src/client/engine/audio/audioLog.ts +7 -2
  70. package/src/client/engine/boot/contentRead.ts +24 -4
  71. package/src/client/engine/boot/diagnostics.ts +69 -1
  72. package/src/client/engine/boot/downloadGiveUp.ts +34 -0
  73. package/src/client/engine/combat/EquipmentService.ts +2 -0
  74. package/src/client/engine/core/Game.ts +6 -2
  75. package/src/client/engine/core/ktx2.ts +5 -3
  76. package/src/client/engine/core/ktx2Zstd.ts +2 -1
  77. package/src/client/engine/pwa/sw.js +26 -8
  78. package/src/client/engine/render/dataLook.ts +14 -7
  79. package/src/client/engine/render/lookLight.ts +64 -20
  80. package/src/client/engine/ui/Loading.ts +6 -8
  81. package/src/client/engine/ui/downloadFailed.ts +54 -0
  82. package/src/client/engine/ui/lookLightOption.ts +1 -1
  83. package/src/client/game/audio/cueDirector.ts +2 -1
  84. package/src/client/game/boot/spawnDownload.ts +12 -1
  85. package/src/client/game/boss/arenaRoom.ts +4 -3
  86. package/src/client/game/boss/roamingProjection.ts +1 -1
  87. package/src/client/game/devScene/hook.ts +1 -1
  88. package/src/client/game/devScene/liveLook.ts +1 -1
  89. package/src/client/game/grid/copyPrompts.ts +3 -4
  90. package/src/client/game/grid/dataCellKit.ts +99 -0
  91. package/src/client/game/grid/enteredEquipment.ts +11 -2
  92. package/src/client/game/grid/live.ts +9 -299
  93. package/src/client/game/grid/liveSession.ts +31 -8
  94. package/src/client/game/grid/neighbourLife.ts +50 -32
  95. package/src/client/game/grid/products.ts +21 -7
  96. package/src/client/game/grid/reveal.ts +7 -2
  97. package/src/client/game/grid/session.ts +10 -74
  98. package/src/client/game/plugin/weaponFamily.ts +6 -0
  99. package/src/client/game/population/signals.ts +1 -1
  100. package/src/client/game/quest/chapterDirector.ts +1 -0
  101. package/src/client/game/shardfile/clientBossTelegraph.ts +4 -3
  102. package/src/client/game/shardfile/clientWorker.ts +35 -9
  103. package/src/client/game/shardfile/look.ts +1 -1
  104. package/src/client/game/shardfile/runtimeProduct.ts +9 -5
  105. package/src/client/game/shardfile/wirePage.ts +5 -2
  106. package/src/client/game/shardfile/worldSceneTextures.ts +15 -9
  107. package/src/client/host/online/shell.ts +37 -13
  108. package/src/cook/game/cookWorker.ts +8 -5
  109. package/src/cook/game/tierTextures.ts +5 -3
  110. package/src/server/engine/net/simWorld.ts +3 -4
  111. package/src/server/game/grid/cellHome.ts +58 -0
  112. package/src/server/game/grid/room.ts +2 -38
  113. package/src/server/game/grid/simulation.ts +5 -4
  114. package/src/server/game/plugin/mover.ts +18 -14
  115. package/src/server/game/shardfile/declaredKitItems.ts +39 -9
  116. package/src/server/host/bake/headlessWorker.ts +3 -3
  117. package/src/server/host/dedicated/cellHost.ts +2 -2
  118. package/src/server/host/dedicated/cellProtocol.ts +1 -1
  119. package/src/server/host/dedicated/cellWorker.ts +5 -3
  120. package/src/server/host/dedicated/dedicatedRoom.ts +8 -3
  121. package/src/server/host/dedicated/gridCells.ts +5 -3
  122. package/src/server/host/dedicated/main.ts +12 -7
  123. package/src/server/host/dedicated/packReader.ts +15 -2
  124. package/src/server/host/dedicated/playerStore.ts +1 -1
  125. package/src/server/host/dedicated/workerTable.ts +0 -10
  126. package/src/server/host/dedicated/world.ts +39 -5
  127. package/src/server/host/headlessRuntime.ts +11 -6
  128. package/src/server/host/standalone/cellWorld.ts +21 -7
  129. package/src/server/host/standalone/gridServer.ts +3 -1
  130. package/src/server/host/standalone/roadWorld.ts +6 -0
  131. package/src/shared/engine/physics/gridBorders.ts +15 -1
  132. package/src/shared/engine/saves/shape.ts +17 -2
  133. package/src/shared/engine/sim/snapshot.ts +5 -5
  134. package/src/shared/engine/strings.ts +10 -0
  135. package/src/shared/game/grid/placementRows.ts +4 -3
  136. package/src/shared/game/ledger.ts +13 -4
  137. package/src/shared/game/loot/platformCatalogue.ts +14 -0
  138. package/src/shared/game/quest/ledger.ts +3 -3
  139. package/src/shared/game/shardfile/items.ts +9 -1
  140. package/src/shared/host/headlessJourney.ts +3 -3
  141. package/src/shared/host/headlessTape.ts +7 -6
  142. package/src/shared/host/releaseRows.ts +4 -1
  143. package/src/client/game/grid/cellLoading.ts +0 -110
  144. package/src/client/game/grid/cellScreens.ts +0 -48
@@ -14,7 +14,7 @@
14
14
  # is signed, so a host that still holds OpenClaw, Coolify, clawdbot or Ollama state is refused in both modes.
15
15
  # Port 443 and `rooms.wildshard.io` are Jake's, after VPS-HARDENING VH16 (J179): Caddy is installed and left off.
16
16
  set -euo pipefail
17
- CHECK=0 COOK_ONLY=0
17
+ CHECK=0 COOK_ONLY=0 PHASE2=0
18
18
  if [ "$#" = 1 ] && [ "$1" = --check ]; then CHECK=1
19
19
  elif [ "$#" = 1 ] && [ "$1" = --cook ]; then COOK_ONLY=1
20
20
  elif [ "$#" != 0 ]; then printf 'stop Expected no arguments, --check or --cook\n'; exit 1; fi
@@ -22,7 +22,8 @@ HERE=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
22
22
  ETC=/etc/wildshard HOME_DIR=/var/lib/wildshard SYSTEMD=/etc/systemd/system
23
23
  PG_VERSION=16 NODE=/usr/bin/node NODE_MAJOR=24 PNPM=pnpm@10.34.9
24
24
  KEY_DIR=/home/raynos/wildshard-e7 KEY_FILE=/home/raynos/wildshard-e7/release-public-key.hex
25
- COOK_ENV=/etc/wildshard/cook.env COOK_HOME=/var/lib/wildshard-cook COOK_SRC=/opt/wildshard/engine COOK_LIB=/usr/local/lib/wildshard-cook
25
+ COOK_ENV=/etc/wildshard/cook.env COOK_STATE=/etc/wildshard/cook-release.env COOK_HOME=/var/lib/wildshard-cook COOK_SRC=/opt/wildshard/engine COOK_LIB=/usr/local/lib/wildshard-cook
26
+ COOK_PNPM_STORE=/var/lib/wildshard-pnpm-store
26
27
  COOK_GROUP=wildshard-cook
27
28
  COOK_SETTINGS=/etc/wildshard/cook.settings
28
29
  # 8790 and 8791 are the game's loopback ports; the cook worker's own default was 8791 too.
@@ -84,14 +85,16 @@ env_value() { sed -n "s/^$2=//p" "$1" 2>/dev/null | tail -n 1; }
84
85
  # The cook worker starts only once its env file names a build, an API, a token and one store (R2's four rows or a folder).
85
86
  cook_env_complete() {
86
87
  local file=$1 name
87
- for name in COOK_ENGINE_REF WILDSHARD_BUILD WILDSHARD_API_URL COOK_NOTIFY_TOKEN; do [ -n "$(cook_value "$file" "$name")" ] || return 1; done
88
- if [ -n "$(cook_value "$file" COOK_STORE_DIR)" ]; then return 0; fi
89
- for name in R2_ACCOUNT_ID R2_BUCKET_PACKS R2_PACKS_ACCESS_KEY_ID R2_PACKS_SECRET_ACCESS_KEY; do [ -n "$(cook_value "$file" "$name")" ] || return 1; done
88
+ # The signed staging release supplies the ref and build. cook.env has credentials only.
89
+ for name in COOK_NOTIFY_TOKEN; do [ -n "$(env_value "$file" "$name")" ] || return 1; done
90
+ if [ -n "$(env_value "$file" COOK_STORE_DIR)" ]; then return 0; fi
91
+ for name in R2_ACCOUNT_ID R2_BUCKET_PACKS R2_PACKS_ACCESS_KEY_ID R2_PACKS_SECRET_ACCESS_KEY; do [ -n "$(env_value "$file" "$name")" ] || return 1; done
90
92
  }
91
- # AUTO-RELEASE AR3 (J355): `wildshard-config cook <tag>` writes COOK_ENGINE_REF and WILDSHARD_BUILD to cook.settings, which
92
- # the unit reads after cook.env. A key there wins, blank too, exactly as systemd reads the two files; otherwise cook.env's.
93
+ # AUTO-RELEASE AR3 (J355) writes an explicit tag and build to cook.settings. It wins over staging's signed follow state,
94
+ # which wins over legacy cook.env values, exactly as the service's EnvironmentFile order does.
93
95
  cook_value() {
94
- if [ -n "${COOK_SETTINGS:-}" ] && [ -r "$COOK_SETTINGS" ] && grep -q "^$2=" "$COOK_SETTINGS"; then env_value "$COOK_SETTINGS" "$2"
96
+ if [ -r "$COOK_SETTINGS" ] && grep -q "^$2=" "$COOK_SETTINGS"; then env_value "$COOK_SETTINGS" "$2"
97
+ elif [ -r "$COOK_STATE" ] && grep -q "^$2=" "$COOK_STATE"; then env_value "$COOK_STATE" "$2"
95
98
  else env_value "$1" "$2"; fi
96
99
  }
97
100
  # Caddy's package ships a page on port 80. Only that file, byte for byte as dpkg recorded it, or this script's own
@@ -119,12 +122,17 @@ if [ "$CHECK" = 0 ] && [ "$(id -u)" != 0 ]; then say stop 'Run with sudo, or pas
119
122
  # AUTO-RELEASE AR3: one rebuild at a time, whichever way it was started (a full run, --cook from wildshard-config cook,
120
123
  # wildshard-apply <tag> rebuild), so two never move the cook's checkout or install into it at once.
121
124
  if [ "$CHECK" = 0 ]; then exec 9>/run/wildshard-rebuild.lock; flock 9; fi
122
- for name in setup.sh setup-state.mjs pull.mjs dump.sh restore-check.sh uptime.sh health-stub.mjs wildshard-config wildshard-apply.mjs wildshard-agent.pub; do
125
+ REQUIRED=(setup.sh setup-state.mjs pull.mjs dump.sh restore-check.sh uptime.sh health-stub.mjs wildshard-config wildshard-apply.mjs wildshard-agent.pub)
126
+ if [ "$COOK_ONLY" = 1 ]; then REQUIRED=(cook-follow.mjs); fi
127
+ for name in "${REQUIRED[@]}"; do
123
128
  if [ ! -f "$HERE/$name" ]; then say stop "$name must sit beside rebuild.sh"; exit 1; fi
124
129
  done
125
130
  # The one trusted public key lives in setup.sh; this stages a copy of it, never another.
126
- EXPECTED_KEY=$(sed -n 's/^EXPECTED_RELEASE_PUBLIC_KEY=\([0-9a-f]*\)$/\1/p' "$HERE/setup.sh")
127
- if ! [[ "$EXPECTED_KEY" =~ ^302a300506032b6570032100[0-9a-f]{64}$ ]]; then say stop 'Cannot read the release public key from setup.sh'; exit 1; fi
131
+ EXPECTED_KEY=''
132
+ if [ "$COOK_ONLY" = 0 ]; then
133
+ EXPECTED_KEY=$(sed -n 's/^EXPECTED_RELEASE_PUBLIC_KEY=\([0-9a-f]*\)$/\1/p' "$HERE/setup.sh")
134
+ if ! [[ "$EXPECTED_KEY" =~ ^302a300506032b6570032100[0-9a-f]{64}$ ]]; then say stop 'Cannot read the release public key from setup.sh'; exit 1; fi
135
+ fi
128
136
  # shellcheck source=/dev/null
129
137
  . /etc/os-release
130
138
  if [ "${VERSION_CODENAME:-}" != noble ]; then say stop "Written for Ubuntu 24.04 (noble), and this is ${PRETTY_NAME:-unknown}"; exit 1; fi
@@ -135,7 +143,6 @@ CPUS=$(nproc) SHARED_CPUS='AllowedCPUs=13-15'
135
143
  if [ "$CPUS" -lt 16 ]; then say warn "The units' AllowedCPUs assume 16 cores, and this has $CPUS"; SHARED_CPUS="# AllowedCPUs=13-15 needs 16 cores; this box has $CPUS"; fi
136
144
 
137
145
  # AUTO-RELEASE AR3: --cook is step 4 alone; the box already has what steps 1 to 3 make.
138
- PHASE2=0
139
146
  if [ "$COOK_ONLY" = 0 ]; then
140
147
  # --- 1. Packages
141
148
  APT_UPDATED=0
@@ -379,7 +386,6 @@ if [ -f "$HERE/harden.sh" ]; then
379
386
  else say skip 'harden.sh is not written yet (VPS-HARDENING-PLAN); it must pass VH16 before port 443'; fi
380
387
 
381
388
  # --- 3. Phase 2, once the box is on the tailnet
382
- PHASE2=0
383
389
  if ! tailnet_up; then
384
390
  if [ "$CHECK" = 1 ] && [ ! -x "$NODE" ]; then say would 'run setup.sh once Tailscale is installed and up'
385
391
  else wait_for 'Tailscale is not logged in: run `sudo tailscale up --ssh`, then run rebuild.sh again (Phase 2 needs the node name)'; fi
@@ -401,14 +407,24 @@ COOK_FOLDERS=("$COOK_HOME" "$COOK_HOME/scratch" "$COOK_HOME/server" "$COOK_HOME/
401
407
  have_cook_folders() { local path; for path in "${COOK_FOLDERS[@]}"; do [ -d "$path" ] && metadata_ok "$path" 750 wildshard-cook:wildshard-cook || return 1; done; }
402
408
  make_cook_folders() { install -d -m 750 -o wildshard-cook -g wildshard-cook "${COOK_FOLDERS[@]}"; }
403
409
  step 'cook folders' have_cook_folders make_cook_folders
410
+ # GVS G9: pnpm must not choose /root's store (hidden by ProtectHome), and the
411
+ # cook account must only read the packages root installed. Keep the whole tree
412
+ # below a root-owned parent so the worker cannot replace a path the installer uses.
413
+ cook_store_unreadable() {
414
+ find "$COOK_PNPM_STORE" ! -type l \( ! -user root -o ! -group "$COOK_GROUP" -o ! -perm -g+r -o -perm -g+w -o -perm -o+w \
415
+ -o \( -type d ! -perm -g+x \) \) -print -quit
416
+ }
417
+ have_cook_store() { [ -d "$COOK_PNPM_STORE" ] && [ -z "$(cook_store_unreadable)" ]; }
418
+ make_cook_store() {
419
+ install -d -m 750 -o root -g "$COOK_GROUP" "$COOK_PNPM_STORE"
420
+ find "$COOK_PNPM_STORE" ! -type l -exec chown root:"$COOK_GROUP" {} +
421
+ find "$COOK_PNPM_STORE" ! -type l -exec chmod g+rX,g-w,o-w {} +
422
+ }
423
+ step "cook pnpm store $COOK_PNPM_STORE" have_cook_store make_cook_store
404
424
  if [ "$(id -u)" != 0 ] && [ -d "$ETC" ] && [ ! -x "$ETC" ]; then say 'cannot verify' "$COOK_ENV (needs sudo)"
405
425
  elif put_once "$COOK_ENV" 600 root:root <<'EOF'
406
- # C4: the cook worker. It starts once the rows below are filled; then run rebuild.sh again.
407
- # The engine tag it runs, and that build's id: the same build production serves (its version.json `build`).
408
- COOK_ENGINE_REF=
409
- WILDSHARD_BUILD=
410
- # Where it lists the catalogue and downloads shardfiles
411
- WILDSHARD_API_URL=https://api.wildshard.io
426
+ # C4: the cook worker. Its signed staging release chooses its engine tag and build.
427
+ # Only credentials belong here; run rebuild.sh again after filling them.
412
428
  # The bearer token api-server's notify call sends (J30). The same value goes in api-server's settings.
413
429
  COOK_NOTIFY_TOKEN=
414
430
  # Where packs go: the four R2 rows, or, on a scratch box only, COOK_STORE_DIR (a folder under /var/lib/wildshard-cook).
@@ -442,10 +458,22 @@ EOF
442
458
  then if [ "$CHECK" = 0 ]; then apparmor_parser -r /etc/apparmor.d/wildshard-cook-unshare; fi; fi
443
459
  else say ok 'unprivileged user namespaces are not restricted here; no AppArmor profile needed'; fi
444
460
 
445
- COOK_REF='' COOK_READY=0
446
- if [ -r "$COOK_ENV" ] && cook_env_complete "$COOK_ENV"; then COOK_READY=1; COOK_REF=$(cook_value "$COOK_ENV" COOK_ENGINE_REF); fi
461
+ COOK_REF='' COOK_BUILD='' COOK_READY=0
462
+ cook_follow() {
463
+ if [ "$CHECK" = 1 ]; then "$NODE" "$HERE/cook-follow.mjs" --check --env "$ETC/staging.env" --state "$COOK_STATE"
464
+ else "$NODE" "$HERE/cook-follow.mjs" --env "$ETC/staging.env" --state "$COOK_STATE"; fi
465
+ }
466
+ if [ -r "$COOK_ENV" ] && cook_env_complete "$COOK_ENV"; then
467
+ if cook_follow; then
468
+ COOK_REF=$(cook_value "$COOK_ENV" COOK_ENGINE_REF)
469
+ COOK_BUILD=$(cook_value "$COOK_ENV" WILDSHARD_BUILD)
470
+ [ -n "$COOK_REF" ] && [ -n "$COOK_BUILD" ] && COOK_READY=1
471
+ else
472
+ wait_for 'The signed staging release did not supply a usable cook ref and build; the cook stays off'
473
+ fi
474
+ fi
447
475
  if [ "$COOK_READY" = 0 ]; then
448
- if [ -r "$COOK_ENV" ] || [ "$CHECK" = 0 ]; then wait_for "Fill $COOK_ENV (engine tag, build, notify token, and R2 or a folder), then run rebuild.sh again"
476
+ if [ -r "$COOK_ENV" ] || [ "$CHECK" = 0 ]; then wait_for "Fill $COOK_ENV (notify token and R2 or a folder), then run rebuild.sh again"
449
477
  elif [ "$(id -u)" = 0 ]; then say would "wait for $COOK_ENV to be filled"
450
478
  else say 'cannot verify' "$COOK_ENV (needs sudo)"; fi
451
479
  fi
@@ -456,8 +484,9 @@ org_git() { env GIT_CONFIG_COUNT=2 GIT_CONFIG_KEY_0=url.https://github.com/proje
456
484
  GIT_CONFIG_KEY_1=url.https://github.com/project-wildshard/.insteadof GIT_CONFIG_VALUE_1=ssh://git@github.com/project-wildshard/ "$@"; }
457
485
  cook_commit() { git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" rev-parse HEAD 2>/dev/null; }
458
486
  have_cook_source() {
459
- [ -f "$COOK_SRC/.wildshard-installed" ] && [ "$(cat "$COOK_SRC/.wildshard-installed")" = "$COOK_REF $(cook_commit)" ] \
460
- && [ "$(git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" rev-parse "$COOK_REF^{commit}" 2>/dev/null)" = "$(cook_commit)" ]
487
+ [ -f "$COOK_SRC/.wildshard-installed" ] && [ "$(cat "$COOK_SRC/.wildshard-installed")" = "$COOK_REF $COOK_BUILD" ] \
488
+ && [ "$(cook_commit)" = "$COOK_BUILD" ] \
489
+ && [ "$(git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" rev-parse "$COOK_REF^{commit}" 2>/dev/null)" = "$COOK_BUILD" ]
461
490
  }
462
491
  make_cook_source() {
463
492
  install -d -m 755 -o root -g root "$(dirname "$COOK_SRC")"
@@ -466,14 +495,12 @@ make_cook_source() {
466
495
  git -C "$COOK_SRC" sparse-checkout set --no-cone '/*' '!/progress/' '!/art/' '!/sources/'
467
496
  fi
468
497
  git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" fetch --quiet --tags origin
469
- git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" checkout --quiet --force --detach "$COOK_REF^{commit}"
470
- # --cook (AR3): the tag must still be the build wildshard-config verified, or the worker would run other code than it reports.
471
- if [ "$COOK_ONLY" = 1 ] && [ "$(cook_commit)" != "$(cook_value "$COOK_ENV" WILDSHARD_BUILD)" ]; then
472
- say stop "$COOK_REF is $(cook_commit) on GitHub now, not the verified WILDSHARD_BUILD"; exit 1
473
- fi
498
+ if [ "$(git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" rev-parse "$COOK_REF^{commit}" 2>/dev/null)" != "$COOK_BUILD" ]; then say stop "The signed release's $COOK_REF does not resolve to $COOK_BUILD"; exit 1; fi
474
499
  rm -f "$COOK_SRC/.wildshard-installed"
475
- (cd "$COOK_SRC" && org_git env CI=1 HOME=/root COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack "$PNPM" install --frozen-lockfile --ignore-scripts --config.confirmModulesPurge=false)
476
- printf '%s %s\n' "$COOK_REF" "$(cook_commit)" > "$COOK_SRC/.wildshard-installed"
500
+ git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" checkout --quiet --force --detach "$COOK_BUILD"
501
+ (cd "$COOK_SRC" && org_git env CI=1 HOME=/root COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack "$PNPM" install --frozen-lockfile --ignore-scripts --config.confirmModulesPurge=false --config.ci=false --store-dir "$COOK_PNPM_STORE" --virtual-store-dir "$COOK_PNPM_STORE/links")
502
+ (cd "$COOK_SRC" && "$NODE" scripts/assert-store-layout.mjs)
503
+ printf '%s %s\n' "$COOK_REF" "$COOK_BUILD" > "$COOK_SRC/.wildshard-installed"
477
504
  chmod -R go-w "$COOK_SRC"
478
505
  }
479
506
  # MMO-SERVER MS2.4b: root clones under the box's umask 027, so the checkout came out 750 root:root and the cook, its own user,
@@ -494,11 +521,16 @@ if [ "$COOK_READY" = 1 ]; then
494
521
  step "cook source $COOK_SRC at $COOK_REF" have_cook_source make_cook_source
495
522
  if [ "$CHECK" = 0 ] && ! have_cook_read; then COOK_SOURCE_CHANGED=1; fi
496
523
  step "cook source readable by $COOK_GROUP" have_cook_read make_cook_read
524
+ step "cook pnpm store readable by $COOK_GROUP" have_cook_store make_cook_store
497
525
  fi
498
- # What the running worker last read of cook.env and cook.settings, as a hash in its root-owned checkout: a changed file
499
- # restarts it. With no cook.settings the hash is cook.env's alone, as it was before AR3.
526
+ # What the running worker last read of cook.env, signed follow state and cook.settings, as a hash in its root-owned checkout.
527
+ # A changed value restarts it; absent optional files preserve the legacy cook.env-only hash.
500
528
  cook_env_hash() {
501
- { cat "$COOK_ENV"; cat "$COOK_SETTINGS" 2>/dev/null || true; } | sha256sum | cut -d' ' -f1
529
+ {
530
+ cat "$COOK_ENV"
531
+ if [ -r "${COOK_STATE:-}" ]; then cat "$COOK_STATE"; fi
532
+ if [ -r "${COOK_SETTINGS:-}" ]; then cat "$COOK_SETTINGS"; fi
533
+ } | sha256sum | cut -d' ' -f1
502
534
  }
503
535
 
504
536
  if put "$SYSTEMD/wildshard-cook.service" 644 root:root <<EOF
@@ -514,8 +546,11 @@ User=wildshard-cook
514
546
  Group=wildshard-cook
515
547
  WorkingDirectory=$COOK_SRC
516
548
  EnvironmentFile=$COOK_ENV
517
- # AUTO-RELEASE AR3: the engine tag and build wildshard-config cook sets, read after the secrets so they win. Optional.
549
+ EnvironmentFile=$COOK_STATE
550
+ # AUTO-RELEASE AR3: explicit engine ref/build read after signed state and credentials, so they win. Optional.
518
551
  EnvironmentFile=-$COOK_SETTINGS
552
+ # The catalogue is public configuration, not cook.env state.
553
+ Environment=WILDSHARD_API_URL=https://api.wildshard.io
519
554
  # MS2.4b: the checkout is root's and the worker runs git in it as wildshard-cook, which git refuses ("dubious ownership")
520
555
  # unless the path is a safe.directory. Set here, not in a gitconfig the worker's home would have to hold.
521
556
  Environment=GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=safe.directory GIT_CONFIG_VALUE_0=$COOK_SRC
@@ -548,8 +583,41 @@ WantedBy=multi-user.target
548
583
  EOF
549
584
  then COOK_UNIT_CHANGED=1; else COOK_UNIT_CHANGED=0; fi
550
585
 
586
+ if put "$SYSTEMD/wildshard-cook-follow.service" 644 root:root <<EOF
587
+ [Unit]
588
+ Description=Follow staging's signed release for the Wildshard cook
589
+ After=network-online.target
590
+ Wants=network-online.target
591
+ ConditionPathExists=$COOK_ENV
592
+
593
+ [Service]
594
+ Type=oneshot
595
+ User=root
596
+ ExecStart=/usr/bin/bash $COOK_LIB/rebuild.sh --cook
597
+ EOF
598
+ then COOK_FOLLOW_UNIT_CHANGED=1; else COOK_FOLLOW_UNIT_CHANGED=0; fi
599
+ if put "$SYSTEMD/wildshard-cook-follow.timer" 644 root:root <<'EOF'
600
+ [Unit]
601
+ Description=Check staging's signed release for the Wildshard cook every five minutes
602
+
603
+ [Timer]
604
+ OnBootSec=2min
605
+ OnUnitActiveSec=5min
606
+ Persistent=true
607
+
608
+ [Install]
609
+ WantedBy=timers.target
610
+ EOF
611
+ then COOK_TIMER_CHANGED=1; else COOK_TIMER_CHANGED=0; fi
612
+
551
613
  if [ "$CHECK" = 0 ]; then
614
+ install -d -m 755 -o root -g root "$COOK_LIB"
615
+ if [ "$HERE" != "$COOK_LIB" ]; then
616
+ install -m 750 -o root -g root "$HERE/rebuild.sh" "$COOK_LIB/rebuild.sh"
617
+ install -m 750 -o root -g root "$HERE/cook-follow.mjs" "$COOK_LIB/cook-follow.mjs"
618
+ fi
552
619
  systemctl daemon-reload
620
+ systemctl enable --quiet wildshard-cook-follow.timer
553
621
  if [ "$COOK_READY" = 1 ]; then
554
622
  if systemctl is-active --quiet wildshard-cook.service && [ "$COOK_UNIT_CHANGED" = 0 ] && [ "$COOK_SOURCE_CHANGED" = 0 ] \
555
623
  && [ "$(cat "$COOK_SRC/.wildshard-env" 2>/dev/null)" = "$(cook_env_hash)" ]; then say ok 'cook worker running'
@@ -572,4 +640,4 @@ if [ "$PHASE2" = 1 ] && [ "$CHECK" = 0 ]; then
572
640
  fi
573
641
  if [ "${#WAITING[@]}" != 0 ]; then say waiting "${#WAITING[@]} input(s) above; everything else is done"; exit 2; fi
574
642
  if [ "$CHECK" = 1 ]; then say check 'Read-only pass complete'; exit 0; fi
575
- say 'done' 'Rebuild complete: Phase 1, Phase 2 and the cook worker'
643
+ if [ "$COOK_ONLY" = 1 ]; then say done 'Cook follow complete'; else say done 'Rebuild complete: Phase 1, Phase 2 and the cook worker'; fi
@@ -8,6 +8,9 @@
8
8
  # wildshard-config cook <tag> AUTO-RELEASE AR4 (J355): move the cook worker to vX.Y.Z and
9
9
  # the build a signed release names for it; roll back on failure
10
10
  # wildshard-config show cook print the cook worker's tag and build
11
+ # wildshard-config saves list [--production] QA 11-15 row 24: every player's id, name and created_at
12
+ # wildshard-config saves delete-test <id>... [--production] [--yes]
13
+ # a test or bot player's rows, a dry run unless --yes
11
14
  # Settings live in /etc/wildshard/<channel>.settings (640 root:wildshard-<channel>), which the units read after <channel>.env.
12
15
  # Secrets stay in the root-only .env, and this never prints one or writes one (it reads only the placement rows there, for
13
16
  # the pair check below): only the keys in SETTINGS below, each
@@ -45,7 +48,6 @@ SETTINGS = {
45
48
  'RECORD_TAG': lambda value, channel: re.fullmatch(r'[A-Za-z0-9._-]{0,64}', value) is not None,
46
49
  'ALLOWED_ORIGINS': lambda value, channel: (set(value.split(',')) <= set(GAME_HOSTS) and len(set(value.split(','))) == len(value.split(','))
47
50
  and GAME_HOSTS[CHANNELS[channel]['host']] in value.split(',')),
48
- 'WORLD_CROSSING': lambda value, channel: value in ('off', 'worker'),
49
51
  'PLACEMENT_URL': lambda value, channel: value in ('', placements(channel)),
50
52
  'PLACEMENT_PUBLIC_KEY': lambda value, channel: value in ('', PLACEMENT_PUBLIC_KEY),
51
53
  # SC2: the channel's own port, which the box's Prometheus scrapes, or blank (off). The server binds it on 127.0.0.1 only.
@@ -56,7 +58,6 @@ RULES = {'WORLD_CELLS': "'grid' or comma-separated cell names (a-z, 0-9, -), non
56
58
  'WORLD_SEATS': 'a whole number from 1 to 2000', 'RECORD_TAG': 'up to 64 of A-Z a-z 0-9 . _ -',
57
59
  'ALLOWED_ORIGINS': "comma-separated, none twice, from https://play.wildshard.io, https://staging.wildshard.io and "
58
60
  "https://preview.wildshard.io, keeping the channel's own (production play, staging staging)",
59
- 'WORLD_CROSSING': 'off or worker',
60
61
  'PLACEMENT_URL': "https://packs.wildshard.io/releases/<channel>-placements.json for this channel, or blank",
61
62
  'PLACEMENT_PUBLIC_KEY': f'the API placement key {PLACEMENT_PUBLIC_KEY}, or blank',
62
63
  'METRICS_PORT': "the channel's own metrics port (production 9790, staging 9791), or blank (off)"}
@@ -276,9 +277,111 @@ def cook(args):
276
277
  return 1
277
278
 
278
279
 
280
+ # QA 11-15 row 24 (Jake: "why dont you have an admin tool you can run on the VPS to clean it up yourself"): the agents clear
281
+ # the players their own probes and bots left in a saves database, and nobody else. Staging unless --production; a delete is a
282
+ # dry run unless --yes. Only a name a test or a bot takes can go: a probe's r<N><shard> (r13pine), the live proofs' Agent X,
283
+ # and Bot. Every table with a player_id column loses that player's rows and `player` its row, in one transaction that checks
284
+ # the names again under a row lock; the box journal (tag wildshard-saves) records each delete.
285
+ SAVES_ID = r'[A-Za-z0-9:._-]{1,128}'
286
+ TEST_NAMES = r'r[0-9]+[a-z][a-z0-9-]*|Agent( [A-Za-z0-9]+)+|[Bb]ot([ _-]?[A-Za-z0-9]+)?'
287
+ SAVES_MAX = 50
288
+ SAVES_TABLE = r'[a-z_][a-z0-9_]{0,62}'
289
+
290
+
291
+ def psql(channel, sql, variables=None):
292
+ """Rows (tab-separated fields) from SQL on the channel's saves database, run as postgres. The ids reach it only as psql
293
+ variables (:'ids'), never inside the SQL text."""
294
+ if TEST:
295
+ command = os.environ.get('WILDSHARD_CONFIG_TEST_PSQL', '/nonexistent').split(' ')
296
+ else:
297
+ command = ['/usr/sbin/runuser', '-u', 'postgres', '--', '/usr/bin/psql', '--cluster', '16/main', '-d', f'saves_{channel}']
298
+ command += ['-X', '-q', '-t', '-A', '-F', '\t', '-v', 'ON_ERROR_STOP=1']
299
+ for key, value in (variables or {}).items():
300
+ command += ['-v', f'{key}={value}']
301
+ try:
302
+ run = subprocess.run(command, input=sql, capture_output=True, text=True, cwd='/', env=helper_env())
303
+ except OSError as error:
304
+ stop(f'psql did not start: {error}')
305
+ if run.returncode != 0:
306
+ stop(f'psql on saves_{channel} exited {run.returncode}: {(run.stderr.strip().splitlines() or ["no message"])[-1]}')
307
+ return [line.split('\t') for line in run.stdout.splitlines() if line != '']
308
+
309
+
310
+ def journal(line):
311
+ """One line in the box journal, tag wildshard-saves; the test's stand-in logger instead (never as root)."""
312
+ logger = os.environ.get('WILDSHARD_CONFIG_TEST_LOGGER') if TEST else '/usr/bin/logger'
313
+ if logger:
314
+ subprocess.run([logger, '-t', 'wildshard-saves', '-p', 'auth.notice', '--', line], cwd='/', env=helper_env())
315
+
316
+
317
+ def saves(args, production):
318
+ channel = 'production' if production else 'staging'
319
+ if args[1:2] == ['list'] and len(args) == 2:
320
+ for row in psql(channel, "select id, name, to_char(created_at at time zone 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') "
321
+ 'from player order by created_at, id;'):
322
+ print(' '.join(row))
323
+ return 0
324
+ if args[1:2] != ['delete-test']:
325
+ stop('usage: wildshard-config saves list [--production] | saves delete-test <id>... [--production] [--yes]')
326
+ sure = '--yes' in args
327
+ ids = [arg for arg in args[2:] if arg != '--yes']
328
+ if not ids or len(ids) > SAVES_MAX or len(set(ids)) != len(ids):
329
+ stop(f'name 1 to {SAVES_MAX} player ids, none twice')
330
+ for player in ids:
331
+ if re.fullmatch(SAVES_ID, player) is None:
332
+ stop(f'{player!r} is not a player id (A-Z a-z 0-9 : . _ -)')
333
+ variables = {'ids': '{' + ','.join(f'"{player}"' for player in ids) + '}', 'names': f'^({TEST_NAMES})$', 'n': str(len(ids))}
334
+ names = dict(psql(channel, "select id, name from player where id = any(:'ids'::text[]);", variables))
335
+ missing = [player for player in ids if player not in names]
336
+ if missing:
337
+ stop(f'no player {", ".join(missing)} in saves_{channel}; nothing deleted')
338
+ kept = [f'{player} ({names[player]!r})' for player in ids if re.fullmatch(TEST_NAMES, names[player]) is None]
339
+ if kept:
340
+ stop(f'not a test or bot name, so refused: {", ".join(kept)}; nothing deleted')
341
+ tables = [row[0] for row in psql(channel, "select table_name from information_schema.columns where table_schema = 'public' "
342
+ "and column_name = 'player_id' and table_name <> 'player' order by table_name;")]
343
+ for table in tables:
344
+ if re.fullmatch(SAVES_TABLE, table) is None:
345
+ stop(f'unexpected table name {table!r}; nothing deleted')
346
+ counts = {}
347
+ if tables:
348
+ union = ' union all '.join(f"select '{table}', player_id, count(*) from public.\"{table}\" where player_id = any(:'ids'::text[]) "
349
+ 'group by player_id' for table in tables)
350
+ for table, player, count in psql(channel, union + ';', variables):
351
+ counts.setdefault(player, []).append(f'{table} {count}')
352
+ for player in ids:
353
+ print(f'{"delete" if sure else "would":<7} saves_{channel} {player} {names[player]!r}: {", ".join(counts.get(player, [])) or "no rows"} and its player row')
354
+ if not sure:
355
+ print('dry run: nothing deleted; add --yes to delete')
356
+ return 0
357
+ # Under a row lock the names are read again, so a player who took a real name since is never deleted.
358
+ deletes = '\n'.join(f"with gone as (delete from public.\"{table}\" where player_id = any(:'ids'::text[]) returning 1) "
359
+ f"select '{table}', count(*) from gone;" for table in tables)
360
+ done = psql(channel, f"""begin;
361
+ select count(*) = :n as matched from (select id from player where id = any(:'ids'::text[]) and name ~ :'names' for update) locked \\gset
362
+ \\if :matched
363
+ {deletes}
364
+ with gone as (delete from player where id = any(:'ids'::text[]) returning 1) select 'player', count(*) from gone;
365
+ commit;
366
+ \\else
367
+ rollback;
368
+ select 'changed', 0;
369
+ \\endif
370
+ """, variables)
371
+ if ['changed', '0'] in done:
372
+ stop('a player changed its name or left while this ran; nothing deleted')
373
+ summary = ', '.join(f'{table} {count}' for table, count in done)
374
+ who = os.environ.get('SUDO_USER', 'root')
375
+ journal(f'saves delete-test saves_{channel} by {who}: ' + ' '.join(f'{player}={names[player]!r}' for player in ids) + f' ({summary})')
376
+ print(f'ok saves_{channel} deleted {summary}; the box journal has it (journalctl -t wildshard-saves)')
377
+ return 0
378
+
379
+
279
380
  def main(argv):
280
381
  production = '--production' in argv
281
382
  args = [arg for arg in argv if arg != '--production']
383
+ if args and args[0] == 'saves':
384
+ return saves(args, production)
282
385
  if args and args[0] == 'cook':
283
386
  return cook(args)
284
387
  if args[:2] == ['show', 'cook'] and len(args) == 2:
@@ -287,7 +390,7 @@ def main(argv):
287
390
  stop('the cook worker moves with: wildshard-config cook vX.Y.Z')
288
391
  if not args or args[0] not in ('show', 'set', 'split'):
289
392
  stop('usage: wildshard-config show <channel> | set <channel> <KEY> <value> [<KEY> <value>]... [--production] | split <channel> '
290
- '| cook vX.Y.Z | show cook')
393
+ '| cook vX.Y.Z | show cook | saves list|delete-test ...')
291
394
  verb = args[0]
292
395
  if len(args) < 2 or args[1] not in CHANNELS:
293
396
  stop('the channel is production or staging')
@@ -3,15 +3,21 @@ import {existsSync} from 'node:fs';
3
3
  import {open, readdir, realpath} from 'node:fs/promises';
4
4
  import {dirname, join, resolve} from 'node:path';
5
5
  import {pathToFileURL} from 'node:url';
6
- import {chromium} from 'playwright';
6
+ import {createRequire} from 'node:module';
7
7
 
8
8
  /** The native control and its untimed disk preparation must select the same
9
9
  * installed browser. Explicit selection wins, with no fallback after failure.
10
10
  * @returns {string} */
11
11
  export function nativeChromeExecutable() {
12
12
  const candidates=[process.env.CHROME_PATH,process.env.CHROME_BIN,
13
- ...(process.platform==='linux'?['/usr/bin/google-chrome','/usr/bin/chromium']:[]),chromium.executablePath()];
14
- const executable=candidates.find(file=>file!==undefined&&existsSync(file));
13
+ ...(process.platform==='linux'?['/usr/bin/google-chrome','/usr/bin/chromium']:[])];
14
+ const selected=candidates.find(file=>file!==undefined&&existsSync(file));
15
+ if(selected!==undefined)return selected;
16
+ // Native controls with an explicit executable need no automation graph.
17
+ // Keep the ordinary installed-Playwright fallback for unprepared local runs.
18
+ const {chromium}=createRequire(import.meta.url)('playwright');
19
+ const fallback=chromium.executablePath();
20
+ const executable=existsSync(fallback)?fallback:undefined;
15
21
  if(executable===undefined)throw new Error('No installed Chromium for the original trusted-input control');
16
22
  return executable;
17
23
  }
@@ -12,9 +12,12 @@ const listen = page => page.evaluate(() => {
12
12
  for (const name of ['combat', 'sting']) record(world.music, name);
13
13
  });
14
14
  const heardOf = page => page.evaluate(() => (window.__said ?? []).slice(-14));
15
+ /** EG-15: when the census sets `sink`, it sees every page these journeys open (`opened`) and reads each one last as its context closes. */
16
+ export const pageCensus = { sink: null };
15
17
  /** Open one shard with the row on, entered and on the wire. */
16
18
  async function open(browser, phone, base, slug, query = '') {
17
- const context = await browser.newContext(phone), page = await context.newPage(), errors = [];
19
+ const context = await browser.newContext(phone), page = await context.newPage(), errors = [], { sink } = pageCensus;
20
+ if (sink !== null) { const close = context.close.bind(context); context.close = async () => { await sink.closing(slug, page); return close(); }; }
18
21
  page.on('pageerror', error => { errors.push(error.message.slice(0, 300)); });
19
22
  page.on('console', line => { if (line.type() === 'error') errors.push(line.text().slice(0, 300)); });
20
23
  await saveFixture(context, { scope: 'device', key: 'devMode', data: true });
@@ -23,8 +26,11 @@ async function open(browser, phone, base, slug, query = '') {
23
26
  await page.waitForFunction(() => typeof window.__workerClient === 'function', undefined, { timeout: 150_000 });
24
27
  await page.evaluate(FLOOR_GRID_ENTER);
25
28
  await page.waitForFunction(() => window.__workerClient().frames > 30, undefined, { timeout: 60_000 });
29
+ if (sink !== null) sink.opened(slug, page);
26
30
  return { context, page, errors };
27
31
  }
32
+ /** A fresh boot of the same shard by its own URL, as a player reopens it. A reload can't: a started page drops its query, so it lands on the title. */
33
+ const reboot = (page, base, slug, query = '') => page.goto(new URL(`/?chunk=${slug}&mute=1&nolock=1${query}`, base).href, { waitUntil: 'load' });
28
34
  const report = page => page.evaluate(() => window.__workerClient());
29
35
  const fight = (page, id) => page.evaluate(want => window.__workerClientFights().find(row => row.id === want) ?? null, id);
30
36
  const place = (page, x, y, z) => page.evaluate(([px, py, pz]) => { window.__wildshard.world.player.link.place(px, py, pz, 0); }, [x, y, z]);
@@ -721,7 +727,7 @@ async function qaraJourney(browser, phone, base, step) {
721
727
  await step('qara: a save keeps him fallen and a page\'s fresh boot reads it back', async () => {
722
728
  await page.evaluate(() => Promise.race([window.__workerClientSave(), new Promise(resolve => { setTimeout(resolve, 20_000); })]));
723
729
  const before = await fight(page, id);
724
- await page.reload({ waitUntil: 'load' });
730
+ await reboot(page, base, 'nalati-grasslands', '&bossGod');
725
731
  await page.waitForFunction(() => window.__wildshard?.world?.player !== undefined, undefined, { timeout: 150_000 });
726
732
  await page.waitForFunction(() => typeof window.__workerClient === 'function', undefined, { timeout: 150_000 });
727
733
  await page.evaluate(FLOOR_GRID_ENTER);
@@ -810,7 +816,7 @@ async function qyranJourney(browser, phone, base, step) {
810
816
  await step('qyran: a save keeps him fallen and a page\'s fresh boot reads it back', async () => {
811
817
  await page.evaluate(() => Promise.race([window.__workerClientSave(), new Promise(resolve => { setTimeout(resolve, 20_000); })]));
812
818
  const before = await fight(page, id);
813
- await page.reload({ waitUntil: 'load' });
819
+ await reboot(page, base, 'nalati-grasslands');
814
820
  await page.waitForFunction(() => window.__wildshard?.world?.player !== undefined, undefined, { timeout: 150_000 });
815
821
  await page.waitForFunction(() => typeof window.__workerClient === 'function', undefined, { timeout: 150_000 });
816
822
  await page.evaluate(FLOOR_GRID_ENTER);