@wildshard/engine 0.1.19 → 0.1.20

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 (79) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lint/engine-sides.json +4 -0
  3. package/package.json +4 -2
  4. package/scripts/app-build/gen.ts +11 -0
  5. package/scripts/cell-mem-bench.mjs +2 -0
  6. package/scripts/check-devserver.mjs +1 -1
  7. package/scripts/grid-crossing-tour.mjs +11 -4
  8. package/scripts/grid-crossing-walk-proof.mjs +4 -2
  9. package/scripts/land.mjs +2 -1
  10. package/scripts/loading-flow/benchmax.mjs +34 -11
  11. package/scripts/loading-flow/deskbench.mjs +276 -0
  12. package/scripts/loading-flow/stalls.d.mts +17 -3
  13. package/scripts/loading-flow/stalls.mjs +82 -3
  14. package/scripts/nightly-model.ts +9 -6
  15. package/scripts/offline-proof.mjs +7 -1
  16. package/scripts/parity/boot-smoke.mjs +13 -2
  17. package/scripts/pin-format.ts +5 -2
  18. package/scripts/pins-reuse.d.mts +1 -0
  19. package/scripts/pins-reuse.mjs +22 -0
  20. package/scripts/scratch-dir.mjs +95 -0
  21. package/scripts/scratch-sweep.mjs +182 -0
  22. package/scripts/tsconfig.json +2 -12
  23. package/scripts/vps/harden-prometheus.sh +3 -0
  24. package/scripts/worktree-reap.mjs +54 -8
  25. package/scripts/worktree.mjs +19 -5
  26. package/src/client/engine/anim/rigParser.ts +2 -2
  27. package/src/client/engine/core/Game.ts +63 -19
  28. package/src/client/engine/core/gpuOnly.ts +10 -0
  29. package/src/client/engine/core/renderBudget.ts +134 -0
  30. package/src/client/engine/net/redial.ts +40 -5
  31. package/src/client/engine/render/dataLook.ts +70 -7
  32. package/src/client/engine/render/families/pbr.ts +2 -0
  33. package/src/client/engine/render/families/registry.ts +11 -2
  34. package/src/client/engine/render/families/sceneSurface.ts +116 -0
  35. package/src/client/engine/render/look.ts +7 -1
  36. package/src/client/engine/render/precompile.ts +4 -2
  37. package/src/client/engine/render/tiers.ts +4 -1
  38. package/src/client/engine/world/declaredProps.ts +5 -1
  39. package/src/client/engine/world/skyRig.ts +4 -1
  40. package/src/client/engine/world/terrainTileView.ts +64 -23
  41. package/src/client/game/devScene/hook.ts +149 -12
  42. package/src/client/game/devScene/liveLook.ts +21 -0
  43. package/src/client/game/grid/live.ts +45 -8
  44. package/src/client/game/grid/liveSession.ts +23 -4
  45. package/src/client/game/grid/pageEntry.ts +12 -1
  46. package/src/client/game/grid/productInputs.ts +22 -11
  47. package/src/client/game/grid/session.ts +13 -4
  48. package/src/client/game/session/finish.ts +4 -1
  49. package/src/client/game/shardfile/client.ts +24 -7
  50. package/src/client/game/shardfile/clientPropMaterials.ts +4 -1
  51. package/src/client/game/shardfile/clientViews.ts +36 -8
  52. package/src/client/game/shardfile/constructionCheckpoint.ts +2 -2
  53. package/src/client/game/shardfile/groundMerge.ts +57 -5
  54. package/src/client/game/shardfile/hybrid.ts +2 -0
  55. package/src/client/game/shardfile/look.ts +1 -1
  56. package/src/client/game/shardfile/slabLibrary.ts +115 -49
  57. package/src/client/game/shardfile/tileContent.ts +1 -1
  58. package/src/client/game/shardfile/tileDriver.ts +38 -11
  59. package/src/client/game/shardfile/wirePage.ts +7 -3
  60. package/src/client/game/shardfile/worldScenes.ts +17 -10
  61. package/src/client/host/online/doctor.ts +20 -7
  62. package/src/client/host/online/doctorView.ts +2 -0
  63. package/src/client/host/online/linkScreens.ts +83 -5
  64. package/src/client/host/online/shell.ts +13 -4
  65. package/src/client/host/standalone/shell.ts +37 -1
  66. package/src/server/game/quest/eliteDrops.ts +7 -3
  67. package/src/server/game/riding/nativeTaming.ts +13 -2
  68. package/src/server/host/dedicated/cellHost.ts +14 -2
  69. package/src/server/host/dedicated/cellProtocol.ts +2 -0
  70. package/src/server/host/dedicated/dedicatedRoom.ts +24 -7
  71. package/src/server/host/dedicated/serverMetrics.ts +9 -0
  72. package/src/server/host/dedicated/workerTable.ts +31 -24
  73. package/src/server/host/standalone/serverHost.ts +56 -10
  74. package/src/server/host/standalone/serverProduct.ts +9 -7
  75. package/src/server/host/standalone/serverRuntime.ts +1 -1
  76. package/src/shared/engine/core/framePacing.ts +12 -1
  77. package/src/shared/engine/physics/terrainTiles.ts +20 -4
  78. package/src/shared/game/devColliders.ts +60 -0
  79. package/src/shared/game/devGameplay.ts +41 -0
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+ // repo-kit's scratch folder maker (meta docs/plans/REPO-DISK-PLAN.md row DK3). One copy lives in repo-kit; every org
3
+ // repo and singleplayer carries a byte-identical copy at scripts/scratch-dir.mjs (DK8 checks the copies).
4
+ //
5
+ // node scripts/scratch-dir.mjs <task> "<purpose>"
6
+ //
7
+ // creates <repo>/tmp/<task>/ and tmp/<task>/.owner, then prints the folder's absolute path. .owner is JSON: the session
8
+ // id ($CLAUDE_SESSION_ID, else $CLAUDE_CODE_SESSION_ID, else the Codex lane name in $WS_LANE_NAME), the lane name, the
9
+ // herdr pane ($HERDR_PANE_ID), the start time and the purpose. DK4's SessionEnd hook removes the folders whose .owner
10
+ // names the ending session; a .keep file in the folder (one line: why to keep it) stops that and DK6's 3-day sweep.
11
+ //
12
+ // <task> is one plain folder name: letters, digits, '.', '_' and '-', not starting with '.', never containing '/' or
13
+ // '..'. The helper deletes nothing. It refuses a folder that already exists unless that folder's .owner names this
14
+ // same session (then it prints the path again), so it never takes over another lane's or an ownerless folder.
15
+ import { mkdirSync, readFileSync, rmdirSync, writeFileSync } from 'node:fs';
16
+ import { join, resolve } from 'node:path';
17
+ import { pathToFileURL } from 'node:url';
18
+
19
+ const ROOT = resolve(import.meta.dirname, '..');
20
+ const TASK = /^[A-Za-z0-9_-][A-Za-z0-9._-]*$/u;
21
+
22
+ /** Why a task name is refused, or null when it is a plain folder name.
23
+ * @param {string} task @returns {string | null} */
24
+ export function refuseTask(task) {
25
+ if (typeof task !== 'string' || task === '') return 'a task name is required';
26
+ if (task.includes('/') || task.includes('\\')) return `task "${task}" contains a path separator`;
27
+ if (task.includes('..')) return `task "${task}" contains ".."`;
28
+ if (task.length > 100) return `task "${task}" is longer than 100 characters`;
29
+ if (!TASK.test(task)) return `task "${task}" must be letters, digits, ".", "_" and "-", not starting with "."`;
30
+ return null;
31
+ }
32
+
33
+ /** The .owner record for a new folder.
34
+ * @param {string} task @param {string} purpose @param {NodeJS.ProcessEnv} env @param {Date} now */
35
+ export function ownerRecord(task, purpose, env, now) {
36
+ const lane = env.WS_LANE_NAME || null;
37
+ return {
38
+ task,
39
+ session: env.CLAUDE_SESSION_ID || env.CLAUDE_CODE_SESSION_ID || lane,
40
+ lane,
41
+ pane: env.HERDR_PANE_ID || null,
42
+ started: now.toISOString(),
43
+ purpose,
44
+ };
45
+ }
46
+
47
+ /** @param {string} path @returns {{session?: unknown} | null} */
48
+ function readOwner(path) {
49
+ try { return JSON.parse(readFileSync(path, 'utf8')); } catch { return null; }
50
+ }
51
+
52
+ /** Make <root>/tmp/<task>/ and its .owner; returns the folder's absolute path. Throws on a refused name, an empty
53
+ * purpose, or a folder that exists and is not this session's.
54
+ * @param {string} task @param {string} purpose
55
+ * @param {{root?: string, env?: NodeJS.ProcessEnv, now?: Date}} [options] */
56
+ export function scratchDir(task, purpose, { root = ROOT, env = process.env, now = new Date() } = {}) {
57
+ const refusal = refuseTask(task);
58
+ if (refusal) throw new Error(refusal);
59
+ if (typeof purpose !== 'string' || purpose.trim() === '') throw new Error('a purpose is required');
60
+ const tmp = join(resolve(root), 'tmp');
61
+ const dir = join(tmp, task);
62
+ const owner = ownerRecord(task, purpose.trim(), env, now);
63
+ mkdirSync(tmp, { recursive: true });
64
+ try {
65
+ mkdirSync(dir);
66
+ } catch (error) {
67
+ if (!(error instanceof Error && 'code' in error && error.code === 'EEXIST')) throw error;
68
+ const existing = readOwner(join(dir, '.owner'));
69
+ if (existing && owner.session && existing.session === owner.session) return dir;
70
+ throw new Error(existing
71
+ ? `${dir} already belongs to session ${String(existing.session)}; pick another task name`
72
+ : `${dir} already exists with no .owner; pick another task name`);
73
+ }
74
+ try {
75
+ writeFileSync(join(dir, '.owner'), `${JSON.stringify(owner, null, 2)}\n`, { flag: 'wx' });
76
+ } catch (error) {
77
+ rmdirSync(dir); // only the empty folder this call just made
78
+ throw error;
79
+ }
80
+ return dir;
81
+ }
82
+
83
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
84
+ const [task = '', purpose = '', ...rest] = process.argv.slice(2);
85
+ if (rest.length > 0 || task === '--help' || task === '-h') {
86
+ console.error('usage: node scripts/scratch-dir.mjs <task> "<purpose>"');
87
+ process.exit(2);
88
+ }
89
+ try {
90
+ console.log(scratchDir(task, purpose));
91
+ } catch (error) {
92
+ console.error(`scratch-dir: ${error instanceof Error ? error.message : String(error)}`);
93
+ process.exit(1);
94
+ }
95
+ }
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env node
2
+ // repo-kit's 3-day scratch sweep (meta REPO-DISK-PLAN DK6, was TEMP-HYGIENE T7). One copy lives in repo-kit; every org
3
+ // repo carries a byte-identical copy at scripts/scratch-sweep.mjs, beside scratch-dir.mjs (DK3) and vite-tmp.mjs.
4
+ //
5
+ // node scripts/scratch-sweep.mjs [--live] [--root <repo>] [--days <n>]
6
+ //
7
+ // It looks at each folder directly under <repo>/tmp/ and would remove one in which nothing (the folder or anything in
8
+ // it) changed for <n> days (3 by default), with or without a DK3 `.owner`. It keeps:
9
+ // - a folder holding `.keep`, or named in `tmp/keep` (one name per line, `#` comments); `tmp/keep` itself when it is a
10
+ // folder (singleplayer keeps hand-kept work there);
11
+ // - a folder that is, or holds, some process's cwd (lsof -d cwd; /proc on Linux); an unreadable table keeps all;
12
+ // - a folder holding a Git root with dirty files or commits no remote has (DS14's list: the reason names the root);
13
+ // - dot folders, symlinks, and `tmp/vitest` (vite-tmp.mjs's own).
14
+ // Dry run is the default until Jake's yes (REPO-DISK decision 1) and a week of dry-run log; `--live` removes. Every
15
+ // decision is appended to tmp/.sweep.log, one line each, and a summary line goes to stdout.
16
+ import { spawnSync } from 'node:child_process';
17
+ import { appendFileSync, lstatSync, readdirSync, readFileSync, readlinkSync, realpathSync, rmSync } from 'node:fs';
18
+ import { join, resolve, sep } from 'node:path';
19
+ import { pathToFileURL } from 'node:url';
20
+
21
+ const DEFAULT_DAYS = 3;
22
+ const MINUTES_A_DAY = 1440;
23
+ const OWNED_ELSEWHERE = new Set(['vitest']);
24
+
25
+ /** Every process cwd as a real path, or null when the table can't be read (the same read as scratch-end.mjs). */
26
+ export function processCwds() {
27
+ if (process.platform === 'linux') {
28
+ let pids;
29
+ try {
30
+ pids = readdirSync('/proc').filter(name => /^\d+$/u.test(name));
31
+ } catch {
32
+ return null;
33
+ }
34
+ const cwds = [];
35
+ for (const pid of pids) {
36
+ try {
37
+ cwds.push(readlinkSync(`/proc/${pid}/cwd`).replace(/ \(deleted\)$/u, ''));
38
+ } catch {}
39
+ }
40
+ return cwds;
41
+ }
42
+ // A timed-out or failed lsof printed only part of the table: treat it as unreadable.
43
+ const lsof = spawnSync('lsof', ['-nP', '-w', '-d', 'cwd', '-Fn'], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, timeout: 10_000 });
44
+ if (lsof.error || lsof.signal || lsof.status !== 0) return null;
45
+ const cwds = (lsof.stdout || '').split('\n').filter(line => line.startsWith('n')).map(line => line.slice(1));
46
+ return cwds.length > 0 ? cwds : null;
47
+ }
48
+
49
+ /** @param {string} path */
50
+ function stat(path) {
51
+ try {
52
+ return lstatSync(path);
53
+ } catch {
54
+ return null;
55
+ }
56
+ }
57
+
58
+ /** Names in tmp/keep. @param {string} tmp */
59
+ function keepList(tmp) {
60
+ let text = '';
61
+ try {
62
+ text = readFileSync(join(tmp, 'keep'), 'utf8');
63
+ } catch {
64
+ return new Set();
65
+ }
66
+ return new Set(text.split('\n').map(line => line.replace(/#.*/u, '').trim()).filter(Boolean));
67
+ }
68
+
69
+ /** True when anything under `dir` (itself included) changed in the last `days` days, or the walk failed.
70
+ * @param {string} dir @param {number} days */
71
+ function touched(dir, days) {
72
+ const find = spawnSync('find', [dir, '-mmin', `-${String(days * MINUTES_A_DAY)}`, '-print', '-quit'], { encoding: 'utf8', maxBuffer: 1024 * 1024 });
73
+ return find.status !== 0 || find.stdout.trim() !== '';
74
+ }
75
+
76
+ /** @param {string} root @param {readonly string[]} args */
77
+ function git(root, args) {
78
+ // GIT_OPTIONAL_LOCKS=0: `git status` must not refresh the index, or reading a stale clone would touch it.
79
+ const run = spawnSync('git', ['-C', root, ...args], { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024, env: { ...process.env, GIT_OPTIONAL_LOCKS: '0' } });
80
+ return run.status === 0 ? run.stdout.trim() : null;
81
+ }
82
+
83
+ /** The first Git root under `dir` with dirty files or unpublished commits, and why; a Git error counts as unpublished.
84
+ * @param {string} dir @returns {string | null} */
85
+ function unpublished(dir) {
86
+ const find = spawnSync('find', [dir, '-maxdepth', '4', '-name', '.git', '-prune', '-print'], { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 });
87
+ if (find.status !== 0) return `${dir}: Git roots unreadable`;
88
+ for (const marker of find.stdout.split('\n').filter(Boolean)) {
89
+ const root = resolve(marker, '..');
90
+ const status = git(root, ['status', '--porcelain', '--ignore-submodules']);
91
+ if (status === null) return `${root}: git status failed`;
92
+ if (status !== '') return `${root}: dirty files`;
93
+ const ahead = git(root, ['log', '--branches', '--tags', '--not', '--remotes', '--oneline', '-1']);
94
+ if (ahead === null) return `${root}: git log failed`;
95
+ if (ahead !== '') return `${root}: commits no remote has`;
96
+ }
97
+ return null;
98
+ }
99
+
100
+ /** Each tmp/ folder and what the sweep does with it, removing nothing.
101
+ * @param {{ root: string, days?: number, cwds?: readonly string[] | null }} options
102
+ * @returns {{ name: string, action: 'remove' | 'keep', reason: string }[]} */
103
+ export function plan({ root, days = DEFAULT_DAYS, cwds = processCwds() }) {
104
+ const tmp = join(root, 'tmp');
105
+ const rows = [];
106
+ let names = [];
107
+ try {
108
+ names = readdirSync(tmp).toSorted();
109
+ } catch {
110
+ return rows;
111
+ }
112
+ const kept = keepList(tmp);
113
+ const real = cwds?.map(cwd => {
114
+ try {
115
+ return realpathSync(cwd);
116
+ } catch {
117
+ return cwd;
118
+ }
119
+ });
120
+ for (const name of names) {
121
+ const dir = join(tmp, name), info = stat(dir);
122
+ if (info === null || !info.isDirectory() || name.startsWith('.') || OWNED_ELSEWHERE.has(name)) continue;
123
+ const at = realpathSync(dir);
124
+ /** @param {string} reason */
125
+ const keep = reason => rows.push({ name, action: /** @type {const} */ ('keep'), reason });
126
+ if (stat(join(dir, '.keep')) !== null) keep('.keep');
127
+ else if (kept.has(name)) keep('tmp/keep');
128
+ else if (name === 'keep') keep('tmp/keep is a folder of kept work');
129
+ else if (real === undefined || real === null) keep('process table unreadable');
130
+ else if (real.some(cwd => cwd === at || cwd.startsWith(at + sep))) keep('busy: a process cwd inside');
131
+ else if (touched(dir, days)) keep(`changed within ${String(days)} days`);
132
+ else {
133
+ const why = unpublished(dir);
134
+ if (why === null) rows.push({ name, action: /** @type {const} */ ('remove'), reason: `untouched ${String(days)} days` });
135
+ else keep(`unpublished (DS14): ${why}`);
136
+ }
137
+ }
138
+ return rows;
139
+ }
140
+
141
+ /** Plans, logs every row to tmp/.sweep.log, and removes the planned folders when live.
142
+ * @param {{ root: string, live?: boolean, days?: number, cwds?: readonly string[] | null, now?: Date }} options */
143
+ export function sweep({ root, live = false, days = DEFAULT_DAYS, cwds, now = new Date() }) {
144
+ const rows = plan({ root, days, ...(cwds === undefined ? {} : { cwds }) });
145
+ const stamp = now.toISOString(), lines = [];
146
+ let removed = 0;
147
+ for (const row of rows) {
148
+ let verb = row.action === 'keep' ? `keep (${row.reason})` : 'would remove';
149
+ if (row.action === 'remove' && live) {
150
+ try {
151
+ rmSync(join(root, 'tmp', row.name), { recursive: true, force: true });
152
+ verb = 'removed';
153
+ removed += 1;
154
+ } catch (error) {
155
+ verb = `remove failed (${error instanceof Error ? error.message : String(error)})`;
156
+ }
157
+ }
158
+ lines.push(`${stamp} ${verb} tmp/${row.name}${row.action === 'remove' ? ` (${row.reason})` : ''}\n`);
159
+ }
160
+ if (lines.length > 0) {
161
+ try {
162
+ appendFileSync(join(root, 'tmp/.sweep.log'), lines.join(''));
163
+ } catch {}
164
+ }
165
+ const planned = rows.filter(row => row.action === 'remove').length;
166
+ return { rows, planned, removed };
167
+ }
168
+
169
+ if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
170
+ const args = process.argv.slice(2);
171
+ const flag = (/** @type {string} */ name) => {
172
+ const at = args.indexOf(name);
173
+ return at === -1 ? undefined : args[at + 1];
174
+ };
175
+ const days = Number(flag('--days') ?? DEFAULT_DAYS);
176
+ if (!Number.isInteger(days) || days < 1) throw new Error('--days takes a whole number of days, 1 or more');
177
+ const root = resolve(flag('--root') ?? resolve(import.meta.dirname, '..'));
178
+ const live = args.includes('--live');
179
+ const { rows, planned, removed } = sweep({ root, live, days });
180
+ const keptRows = rows.filter(row => row.action === 'keep');
181
+ process.stdout.write(`scratch-sweep ${live ? 'live' : '(dry run)'} ${root}/tmp: ${live ? `removed ${String(removed)} of ${String(planned)}` : `would remove ${String(planned)}`}, kept ${String(keptRows.length)}; log tmp/.sweep.log\n`);
182
+ }
@@ -45,6 +45,8 @@
45
45
  "ci-native-fixtures.mjs",
46
46
  "agent-parity.mjs",
47
47
  "agent-sync.mjs",
48
+ "scratch-dir.mjs",
49
+ "scratch-sweep.mjs",
48
50
  "goldens/capture.mjs",
49
51
  "goldens/native-residency.mjs",
50
52
  "look-loop/views.mjs",
@@ -61,16 +63,13 @@
61
63
  "../test/author-errors.test.ts",
62
64
  "../test/author-lut-sampling.test.ts",
63
65
  "../test/author-placement-parity.test.ts",
64
- "../test/authored-html.test.ts",
65
66
  "../test/bake-collider-kernels.test.ts",
66
67
  "../test/balbal-program.test.ts",
67
68
  "../test/balbal-v2.test.ts",
68
69
  "../test/basis-glb-variant.test.ts",
69
70
  "../test/boot-audio-packs.test.ts",
70
- "../test/boot-extras.test.ts",
71
71
  "../test/boot-settings-interaction.test.ts",
72
72
  "../test/build-cache-report.test.ts",
73
- "../test/build-validation-receipts.test.ts",
74
73
  "../test/carried-quest-host.test.ts",
75
74
  "../test/channel-programs-gather.test.ts",
76
75
  "../test/ci12-ghost-owners.test.ts",
@@ -86,7 +85,6 @@
86
85
  "../test/contract-page-admission.test.ts",
87
86
  "../test/contract-program-owner.test.ts",
88
87
  "../test/contracts-platform.test.ts",
89
- "../test/control-chunks.test.ts",
90
88
  "../test/creature-refill.test.ts",
91
89
  "../test/creature-spawner.test.ts",
92
90
  "../test/debug-authored-rows.test.ts",
@@ -107,7 +105,6 @@
107
105
  "../test/elite-native-roster.test.ts",
108
106
  "../test/encounter-room.test.ts",
109
107
  "../test/encounter-slots.test.ts",
110
- "../test/engine-sides.test.ts",
111
108
  "../test/entry-styles.test.ts",
112
109
  "../test/faceted-ao-scope.test.ts",
113
110
  "../test/faceted-author-compiler.test.ts",
@@ -131,7 +128,6 @@
131
128
  "../test/fixtures/driftwood-rock-author.ts",
132
129
  "../test/fixtures/driftwood-trade-native.ts",
133
130
  "../test/fixtures/geometry-cache-author-observation.ts",
134
- "../test/fixtures/graph-scene-author-observation.ts",
135
131
  "../test/fixtures/half-float-before-control.ts",
136
132
  "../test/fixtures/headless/driftwood-optional-run.ts",
137
133
  "../test/fixtures/headless/driftwood-story-run.ts",
@@ -243,7 +239,6 @@
243
239
  "../test/graph-foliage-normal.test.ts",
244
240
  "../test/graph-instance-transform.test.ts",
245
241
  "../test/graph-optional-attribute.test.ts",
246
- "../test/graph-scene-author-ports.test.ts",
247
242
  "../test/graph-shadow-depth.test.ts",
248
243
  "../test/graph-shadow-offset.test.ts",
249
244
  "../test/graph-toon-caustics.test.ts",
@@ -326,10 +321,7 @@
326
321
  "../test/nine-source-rows.test.ts",
327
322
  "../test/nine-verb-tape.test.ts",
328
323
  "../test/no-base64.test.ts",
329
- "../test/no-generated-import.test.ts",
330
324
  "../test/no-shard-runtime.test.ts",
331
- "../test/open-plots-capture.test.ts",
332
- "../test/open-plots-config.test.ts",
333
325
  "../test/original-script-order.test.ts",
334
326
  "../test/output-runtime.test.ts",
335
327
  "../test/packed-specimen-files.test.ts",
@@ -476,7 +468,6 @@
476
468
  "../test/splat-family-props.test.ts",
477
469
  "../test/stealth-crouch-kernel.test.ts",
478
470
  "../test/stealth-detection.test.ts",
479
- "../test/sunscar-generation-inputs.test.ts",
480
471
  "../test/taming-binding-order.test.ts",
481
472
  "../test/taming-guest-legacy.test.ts",
482
473
  "../test/taming-world-actions.test.ts",
@@ -493,7 +484,6 @@
493
484
  "../test/titan-world-commands.test.ts",
494
485
  "../test/uniform-tile-grid.test.ts",
495
486
  "../test/view-author-metadata.test.ts",
496
- "../test/vite-boot-modules.test.ts",
497
487
  "../test/vitest-module-cache.test.ts",
498
488
  "../test/wet-product-loans.test.ts",
499
489
  "../test/whole-library-cache.test.ts",
@@ -129,6 +129,9 @@ if put "$NODE_DROPIN" < <(node_dropin); then units_changed=1; fi
129
129
  # promtool comes with the package, so the very first config is checked after the install, before anything restarts.
130
130
  check=; if command -v promtool >/dev/null 2>&1; then check='promtool check config'; fi
131
131
  if put "$CONFIG" "$check" < <(config); then config_changed=1; fi
132
+ # The box's root umask (027, VH16) leaves a new /etc/prometheus root-only, and the prometheus user then cannot open its
133
+ # config (v0.1.19 staging, 2026-11-14: "open /etc/prometheus/wildshard.yml: permission denied"). It holds no secret.
134
+ chmod 755 "$(dirname "$CONFIG")" || exit 1
132
135
  if [ "$units_changed" = 1 ]; then systemctl daemon-reload; fi
133
136
 
134
137
  installed() { dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -q 'ok installed'; }
@@ -13,23 +13,28 @@
13
13
  // commit, and `origin plan/<slug>` deleted (`git push --delete`, which the pre-push lets through without a gate)
14
14
  // only if the remote branch is landed too, under a lease on the SHA it had. A worktree that fails any check is kept
15
15
  // and named with the reason; an unlanded branch, local or remote, is never touched. Every run appends one receipt.
16
+ // REPO-DISK DK11: a removed worktree takes its tmp/ and build output with it (they are ignored files inside it), and
17
+ // a real run's receipt records the `df` bytes it freed (other writers move df too, so it is a measure, not a ledger).
18
+ // A worktree kept because it is unlanded or dirty and untouched for --stale hours (default 72) is named in the
19
+ // receipt with its `du` size, so the coordinator's brief can put it to its owner.
16
20
  import {execFileSync,spawnSync} from 'node:child_process';
17
- import {appendFileSync,existsSync,mkdirSync,readdirSync,readlinkSync,realpathSync,statSync} from 'node:fs';
21
+ import {appendFileSync,existsSync,mkdirSync,readdirSync,readlinkSync,realpathSync,statSync,statfsSync} from 'node:fs';
18
22
  import {homedir} from 'node:os';
19
23
  import {basename,dirname,join,resolve,sep} from 'node:path';
20
24
  import {pidLock} from './pid-lock.mjs';
21
25
  import {WORKTREES} from './worktree-ignore.mjs';
22
26
 
23
- const REAP_USAGE='usage: node scripts/worktree.mjs reap [--dry-run] [--grace=HOURS] [--no-remote]';
27
+ const REAP_USAGE='usage: node scripts/worktree.mjs reap [--dry-run] [--grace=HOURS] [--stale=HOURS] [--no-remote]';
24
28
 
25
- /** @param {string[]} argv the arguments after `reap` @returns {{dryRun:boolean,graceHours:number,remote:boolean}} */
29
+ /** @param {string[]} argv the arguments after `reap` @returns {{dryRun:boolean,graceHours:number,staleHours:number,remote:boolean}} */
26
30
  export function parseReapArgs(argv){
27
- const options={dryRun:false,graceHours:24,remote:true};
31
+ const options={dryRun:false,graceHours:24,staleHours:72,remote:true};
28
32
  for(const arg of argv){
29
33
  const [name,value]=arg.split('=',2);
30
34
  if(arg==='--dry-run')options.dryRun=true;
31
35
  else if(arg==='--no-remote')options.remote=false;
32
36
  else if(name==='--grace'&&value!==undefined&&/^\d+(?:\.\d+)?$/u.test(value))options.graceHours=Number(value);
37
+ else if(name==='--stale'&&value!==undefined&&/^\d+(?:\.\d+)?$/u.test(value))options.staleHours=Number(value);
33
38
  else throw new Error(`unknown option ${arg}\n${REAP_USAGE}`);
34
39
  }
35
40
  return options;
@@ -109,6 +114,24 @@ export function lastActivity(tree,gitDir){
109
114
  return newest;
110
115
  }
111
116
 
117
+ /** Free bytes on the volume holding `path` (what `df` shows as available). @param {string} path */
118
+ export function freeBytes(path){
119
+ const volume=statfsSync(path);
120
+ return volume.bavail*volume.bsize;
121
+ }
122
+
123
+ /** `du -sk` of `path` as GiB text, within `budgetMs` (all of a run's `du` calls share one budget), or why not.
124
+ * @param {string} path @param {number} budgetMs */
125
+ function duSize(path,budgetMs){
126
+ if(budgetMs<1000)return 'size not measured (du budget spent)';
127
+ const listed=spawnSync('du',['-sk',path],{encoding:'utf8',timeout:budgetMs});
128
+ const kib=Number((listed.stdout??'').split('\t')[0]);
129
+ return listed.status===0&&Number.isFinite(kib)&&kib>0?`${(kib/1_048_576).toFixed(1)} GiB`:'size unknown';
130
+ }
131
+
132
+ /** Signed MiB text for a byte count; the sign is taken after rounding, so a tiny change reads +0. @param {number} bytes */
133
+ const mib=bytes=>{const size=Math.round(bytes/1_048_576);return `${size<0?'-':'+'}${Math.abs(size).toLocaleString('en-US')} MiB`;};
134
+
112
135
  /** Is `sha` on origin/main itself? @param {string} canonical @param {string} sha */
113
136
  export const onMain=(canonical,sha)=>sha!==''&&tryGit(canonical,['merge-base','--is-ancestor',sha,'origin/main']).status===0;
114
137
  /** Commits of `sha` that origin/main lacks. @param {string} canonical @param {string} sha */
@@ -141,9 +164,30 @@ export function reap(canonical,options,env,say){
141
164
  const fetched=tryGit(canonical,['fetch','--quiet','origin','+refs/heads/main:refs/remotes/origin/main']);
142
165
  if(fetched.status!==0){say(`reap STOP cannot fetch origin main: ${fetched.stderr.trim()}`);return 1;}
143
166
  const directories=processDirectories();
144
- const realRoot=realpathSync(canonical),now=Date.now();
167
+ const realRoot=realpathSync(canonical),now=Date.now(),freeBefore=freeBytes(canonical);
145
168
  /** @type {string[]} */const reaped=[];
146
169
  /** @type {string[]} */const kept=[];
170
+ /** @type {string[]} */const stale=[];
171
+ const duUntil=now+60_000;
172
+ /** DK11: an unlanded or dirty worktree untouched for --stale hours goes on the receipt with its size. Untouched
173
+ * means no Git activity, no change to a dirty path, and no process inside.
174
+ * @param {string} slug @param {string} path @param {string} why @param {string[]} [dirty] porcelain lines */
175
+ const staleCheck=(slug,path,why,dirty=[])=>{
176
+ let gitDir='',physical='';
177
+ try{gitDir=git(path,['rev-parse','--absolute-git-dir']).trim();physical=realpathSync(path);}catch{return;}
178
+ if(directories===undefined||[...directories.values()].some(cwd=>cwd===physical||cwd.startsWith(`${physical}${sep}`)))return;
179
+ let newest=0;
180
+ try{newest=lastActivity(path,gitDir);}catch{return;}
181
+ for(const line of dirty.slice(0,500)){
182
+ const name=line.slice(3).split(' -> ').at(-1)??'';
183
+ try{newest=Math.max(newest,statSync(join(path,name.replaceAll(/^"|"$/gu,''))).mtimeMs);}catch{/* Deleted: no mtime. */}
184
+ }
185
+ const idle=(now-newest)/3_600_000;
186
+ if(idle<options.staleHours)return;
187
+ const entry=`${slug} (${duSize(path,duUntil-Date.now())}, idle ${(idle/24).toFixed(1)} d, ${why})`;
188
+ stale.push(entry);
189
+ say(`stale ${entry}`);
190
+ };
147
191
  /** @type {string[]} */const remotes=[];
148
192
  for(const tree of linkedWorktrees(canonical)){
149
193
  const slug=basename(tree.path),branch=`refs/heads/plan/${slug}`;
@@ -156,9 +200,9 @@ export function reap(canonical,options,env,say){
156
200
  if(tree.branch!==branch){keep(`on ${tree.branch===''?'a detached HEAD':tree.branch}, not plan/${slug}`);continue;}
157
201
  if(!existsSync(tree.path)){keep('its folder is gone; `git worktree prune` clears it');continue;}
158
202
  // Landed means the tip is on main itself (land fast-forwards): \`git cherry\` would miss a merge's own changes.
159
- if(!onMain(canonical,tree.head)){keep(`${String(aheadOfMain(canonical,tree.head))} commit(s) not on main`);continue;}
203
+ if(!onMain(canonical,tree.head)){const why=`${String(aheadOfMain(canonical,tree.head))} commit(s) not on main`;keep(why);staleCheck(slug,tree.path,why);continue;}
160
204
  const dirty=git(tree.path,['--no-optional-locks','status','--porcelain','--untracked-files=all']).split('\n').filter(Boolean);
161
- if(dirty.length>0){keep(`${String(dirty.length)} uncommitted path(s), first ${dirty[0]?.slice(3)}`);continue;}
205
+ if(dirty.length>0){const why=`${String(dirty.length)} uncommitted path(s)`;keep(`${why}, first ${dirty[0]?.slice(3)}`);staleCheck(slug,tree.path,why,dirty);continue;}
162
206
  const gitDir=git(tree.path,['rev-parse','--absolute-git-dir']).trim();
163
207
  const busy=(/** @type {Map<number,string>|undefined} */ seen)=>seen===undefined?'cannot list process working directories'
164
208
  :[...seen].filter(([,path])=>path===physical||path.startsWith(`${physical}${sep}`)).map(([pid])=>String(pid)).join(', ');
@@ -206,8 +250,10 @@ export function reap(canonical,options,env,say){
206
250
  else{remotes.push(`${slug} delete failed`);say(` ${slug}: origin plan/${slug} not deleted: ${pushed.stderr.trim()}`);}
207
251
  }
208
252
  if(!options.dryRun)tryGit(canonical,['worktree','prune']);
253
+ const freed=options.dryRun?'':`; df ${mib(freeBytes(canonical)-freeBefore)}`;
254
+ if(freed!=='')say(`df free changed ${freed.slice(5)} during the run`);
209
255
  const lane=/^[a-z][a-z0-9_-]*$/u.test(env.WS_LANE_NAME??'')?String(env.WS_LANE_NAME):'reaper';
210
- const line=`${new Date().toISOString().slice(11,16)} UTC ${lane} worktree reap ${basename(canonical)}${options.dryRun?' (dry run)':''}: ${reaped.length===0?'none':`${options.dryRun?'would reap':'reaped'} ${reaped.join(', ')}`}; kept ${kept.length===0?'none':kept.join(', ')}${remotes.length===0?'':`; origin ${remotes.join(', ')}`}`;
256
+ const line=`${new Date().toISOString().slice(11,16)} UTC ${lane} worktree reap ${basename(canonical)}${options.dryRun?' (dry run)':''}: ${reaped.length===0?'none':`${options.dryRun?'would reap':'reaped'} ${reaped.join(', ')}`}; kept ${kept.length===0?'none':kept.join(', ')}${remotes.length===0?'':`; origin ${remotes.join(', ')}`}${freed}${stale.length===0?'':`; stale ${String(options.staleHours)} h+: ${stale.join(', ')}`}`;
211
257
  const file=resolve(env.WS_LANE_RECEIPTS??join(homedir(),'.cache/wildshard/lane-receipts.log'));
212
258
  try{mkdirSync(dirname(file),{recursive:true});appendFileSync(file,`${line}\n`);}catch(error){say(`reap receipt unavailable: ${String(error)}`);}
213
259
  return 0;
@@ -13,7 +13,9 @@
13
13
  //
14
14
  // Never copied: .env*, tmp/, .review/, .cache/, browser profiles, leases, ports, push proofs; the worktree gets
15
15
  // only tracked files and its own install. Each step's seconds go to <worktree>/tmp/worktree-setup.json and, with
16
- // WS_LANE_NAME set, one line in ~/.cache/wildshard/lane-receipts.log. Removal is DS13's reaper: `reap`
16
+ // WS_LANE_NAME set, one line in ~/.cache/wildshard/lane-receipts.log. REPO-DISK DK10: the record and the receipt also
17
+ // carry the volume's `df` free bytes before and after and the worktree's `du`: build output inside a worktree costs
18
+ // nothing until written (clones), so `df` shows the real cost and `du` the apparent one. Removal is DS13's reaper: `reap`
17
19
  // (scripts/worktree-reap.mjs) removes landed, clean, idle worktrees with their branches, local and on origin.
18
20
  import {execFileSync,spawn,spawnSync} from 'node:child_process';
19
21
  import {randomBytes} from 'node:crypto';
@@ -22,7 +24,7 @@ import {homedir} from 'node:os';
22
24
  import {basename,dirname,join,resolve} from 'node:path';
23
25
  import {pathToFileURL} from 'node:url';
24
26
  import {WORKTREES} from './worktree-ignore.mjs';
25
- import {parseReapArgs,reap} from './worktree-reap.mjs';
27
+ import {freeBytes,parseReapArgs,reap} from './worktree-reap.mjs';
26
28
 
27
29
  export const SLUG=/^[a-z0-9][a-z0-9._-]{0,63}$/u;
28
30
  const REGULAR=/^100(?:644|755)$/u;
@@ -247,12 +249,22 @@ function run(cwd,command,args,env){
247
249
  if(result.status!==0)throw new StopError(`${command} ${args.join(' ')} exited ${String(result.status)}`);
248
250
  }
249
251
 
252
+ /** DK10: what the new worktree cost the volume (`df` free before minus after; other writers move it too) and what
253
+ * `du` counts in it (clones in full). @param {string} tree @param {number} freeBefore free bytes before setup */
254
+ export function diskCost(tree,freeBefore){
255
+ const freeAfter=freeBytes(tree),listed=spawnSync('du',['-sk',tree],{encoding:'utf8',timeout:120_000});
256
+ const kib=Number((listed.stdout??'').split('\t')[0]),duKib=listed.status===0&&Number.isFinite(kib)?kib:undefined;
257
+ const cost=freeBefore-freeAfter,costMib=Math.round(cost/1_048_576);
258
+ const text=`df ${costMib<0?'gained':'cost'} ${Math.abs(costMib).toLocaleString('en-US')} MiB, du ${duKib===undefined?'unknown':`${(duKib/1_048_576).toFixed(2)} GiB`}, free ${(freeAfter/2**30).toFixed(1)} GiB`;
259
+ return {freeBefore,freeAfter,dfCostBytes:cost,duKib,text};
260
+ }
261
+
250
262
  /** @param {string[]} argv @param {string} [cwd] @param {NodeJS.ProcessEnv} [env] @returns {number} */
251
263
  export function worktreeNew(argv,cwd=process.cwd(),env=process.env){
252
264
  const options=parseArgs(argv),canonical=canonicalRoot(cwd),common=join(canonical,'.git');
253
265
  const relative=`${WORKTREES}/${options.slug}`,tree=join(canonical,relative),branch=`plan/${options.slug}`;
254
266
  /** @type {{step:string,seconds:number,detail?:string}[]} */const steps=[];
255
- const began=performance.now();
267
+ const began=performance.now(),freeBefore=freeBytes(canonical);
256
268
  /** @param {string} step @param {() => (string|void)} work */
257
269
  const timed=(step,work)=>{
258
270
  const started=performance.now(),detail=work();
@@ -307,13 +319,15 @@ export function worktreeNew(argv,cwd=process.cwd(),env=process.env){
307
319
  catch(error){process.stderr.write(`worktree: timings refresh not started (${error instanceof Error?error.message:String(error)})\n`);}
308
320
  }
309
321
  const total=Number(((performance.now()-began)/1000).toFixed(2));
310
- const record={slug:options.slug,branch,base,tree,total,steps,finished:new Date().toISOString()};
322
+ const disk=diskCost(tree,freeBefore);
323
+ process.stdout.write(`worktree disk ${disk.text}\n`);
324
+ const record={slug:options.slug,branch,base,tree,total,steps,disk,finished:new Date().toISOString()};
311
325
  mkdirSync(join(tree,'tmp'),{recursive:true});
312
326
  writeFileSync(join(tree,'tmp/worktree-setup.json'),`${JSON.stringify(record,null,2)}\n`);
313
327
  const lane=/^[a-z][a-z0-9_-]*$/u.test(env.WS_LANE_NAME??'')?String(env.WS_LANE_NAME):'';
314
328
  if(lane!==''){
315
329
  const file=resolve(env.WS_LANE_RECEIPTS??join(homedir(),'.cache/wildshard/lane-receipts.log'));
316
- try{mkdirSync(dirname(file),{recursive:true});appendFileSync(file,`${new Date().toISOString().slice(11,16)} UTC ${lane} worktree new ${basename(canonical)}/${relative} on ${branch} from ${base.slice(0,10)} in ${total.toFixed(1)} s (${steps.map(row=>`${row.step} ${row.seconds.toFixed(1)}`).join(', ')})\n`);}
330
+ try{mkdirSync(dirname(file),{recursive:true});appendFileSync(file,`${new Date().toISOString().slice(11,16)} UTC ${lane} worktree new ${basename(canonical)}/${relative} on ${branch} from ${base.slice(0,10)} in ${total.toFixed(1)} s (${steps.map(row=>`${row.step} ${row.seconds.toFixed(1)}`).join(', ')}); ${disk.text}\n`);}
317
331
  catch(error){process.stderr.write(`worktree receipt unavailable: ${String(error)}\n`);}
318
332
  }
319
333
  const name=lane===''?'<lane>':lane;
@@ -5,7 +5,7 @@ import { installGltfKtx2 } from '../core/ktx2';
5
5
  import { pageScope } from '../../../shared/engine/app/resources';
6
6
  import { waitFor } from '../../../shared/engine/boot/waits';
7
7
  import { buildYield, WORK_SLICE_MS, workSlice, type WorkSlice } from '../../../shared/engine/core/workSlice';
8
- import { buildHeld, frameBudgetSpent, frameDue, presenting } from '../../../shared/engine/core/framePacing';
8
+ import { buildHeld, buildUrgent, frameBudgetSpent, frameDue, presenting } from '../../../shared/engine/core/framePacing';
9
9
 
10
10
  // FileLoader starts every network read immediately. Only the parser's temporary
11
11
  // meshopt/image/geometry allocations share this page-wide decode slot.
@@ -38,7 +38,7 @@ class BoundedRigLoader extends GLTFLoader implements RigLoader {
38
38
  // The previous read/consumer can span drawn frames. Its wall clock
39
39
  // cannot charge that wait to this parse's current live CPU budget.
40
40
  const pause = presenting()
41
- ? (buildHeld() || !frameDue()) && !frameBudgetSpent(WORK_SLICE_MS) ? undefined : buildYield(pageScope)
41
+ ? (buildHeld() || buildUrgent() || !frameDue()) && !frameBudgetSpent(WORK_SLICE_MS) ? undefined : buildYield(pageScope)
42
42
  : (decodeSlice ??= workSlice(undefined, pageScope)).check();
43
43
  await waitFor('GLTF decode pacing', Promise.resolve(pause), 'work');
44
44
  }