@wildshard/engine 0.1.22 → 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 (100) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lint/engine-sides.json +2 -0
  3. package/lint/sim-players.json +2 -13
  4. package/package.json +9 -2
  5. package/scripts/apfs-clone.mjs +5 -2
  6. package/scripts/app-build/catalogue.ts +39 -8
  7. package/scripts/app-build/serviceWorker.ts +4 -1
  8. package/scripts/app-build/splitOutput.mjs +33 -11
  9. package/scripts/ci-pack.mjs +3 -3
  10. package/scripts/engine-ci-shard.mjs +11 -0
  11. package/scripts/fight-page-census.mjs +131 -0
  12. package/scripts/goldens/board.py +44 -11
  13. package/scripts/goldens/native-residency.d.mts +1 -0
  14. package/scripts/goldens/native-residency.mjs +18 -4
  15. package/scripts/keep-copy.mjs +120 -0
  16. package/scripts/land.mjs +36 -6
  17. package/scripts/lane-live.mjs +136 -0
  18. package/scripts/leftovers-report.mjs +47 -0
  19. package/scripts/loading-card-proof.mjs +42 -9
  20. package/scripts/loading-flow/benchmax.mjs +57 -7
  21. package/scripts/loading-flow/stalls.d.mts +2 -0
  22. package/scripts/loading-flow/stalls.mjs +13 -0
  23. package/scripts/mmo-bots.mjs +5 -3
  24. package/scripts/mmo-grid-proof.mjs +74 -0
  25. package/scripts/mmo-seat-proof.mjs +43 -0
  26. package/scripts/nightly-heads.ts +13 -13
  27. package/scripts/nightly-model.ts +26 -12
  28. package/scripts/nightly.proof.ts +18 -5
  29. package/scripts/nightly.ts +13 -8
  30. package/scripts/no-astc-boot.mjs +77 -0
  31. package/scripts/physics-route.json +6 -6
  32. package/scripts/pins-reuse.mjs +1 -0
  33. package/scripts/pins-staging.ts +54 -0
  34. package/scripts/pins.ts +5 -0
  35. package/scripts/ring3.proof.ts +71 -0
  36. package/scripts/ring3.ts +100 -0
  37. package/scripts/scratch-dir.mjs +31 -12
  38. package/scripts/scratch-sweep.mjs +15 -23
  39. package/scripts/server-release/items.d.mts +7 -0
  40. package/scripts/server-release/items.mjs +28 -0
  41. package/scripts/server-release/publish.mjs +9 -1
  42. package/scripts/side-parity.mjs +1 -1
  43. package/scripts/test-products.json +1 -0
  44. package/scripts/tsconfig.json +2 -0
  45. package/scripts/vitest-ci-files.ts +5 -1
  46. package/scripts/vps/wildshard-config +106 -1
  47. package/scripts/warm-native-chrome.mjs +9 -3
  48. package/scripts/worker-client-fights.mjs +9 -3
  49. package/scripts/worktree-reap.mjs +15 -131
  50. package/scripts/worktree.mjs +92 -12
  51. package/src/client/engine/audio/audioLog.ts +7 -2
  52. package/src/client/engine/boot/diagnostics.ts +69 -1
  53. package/src/client/engine/core/ktx2.ts +5 -3
  54. package/src/client/engine/core/ktx2Zstd.ts +2 -1
  55. package/src/client/engine/pwa/sw.js +26 -8
  56. package/src/client/engine/render/dataLook.ts +14 -7
  57. package/src/client/engine/render/lookLight.ts +64 -20
  58. package/src/client/engine/ui/Loading.ts +6 -8
  59. package/src/client/engine/ui/lookLightOption.ts +1 -1
  60. package/src/client/game/audio/cueDirector.ts +2 -1
  61. package/src/client/game/boss/arenaRoom.ts +4 -3
  62. package/src/client/game/boss/roamingProjection.ts +1 -1
  63. package/src/client/game/devScene/hook.ts +1 -1
  64. package/src/client/game/devScene/liveLook.ts +1 -1
  65. package/src/client/game/grid/dataCellKit.ts +9 -1
  66. package/src/client/game/grid/products.ts +21 -7
  67. package/src/client/game/grid/session.ts +6 -4
  68. package/src/client/game/population/signals.ts +1 -1
  69. package/src/client/game/quest/chapterDirector.ts +1 -0
  70. package/src/client/game/shardfile/clientBossTelegraph.ts +4 -3
  71. package/src/client/game/shardfile/clientWorker.ts +22 -6
  72. package/src/client/game/shardfile/look.ts +1 -1
  73. package/src/client/game/shardfile/runtimeProduct.ts +9 -5
  74. package/src/client/game/shardfile/wirePage.ts +5 -2
  75. package/src/client/game/shardfile/worldSceneTextures.ts +15 -9
  76. package/src/cook/game/cookWorker.ts +8 -5
  77. package/src/cook/game/tierTextures.ts +5 -3
  78. package/src/server/engine/net/simWorld.ts +3 -4
  79. package/src/server/game/grid/cellHome.ts +58 -0
  80. package/src/server/game/grid/simulation.ts +5 -4
  81. package/src/server/game/plugin/mover.ts +18 -14
  82. package/src/server/game/shardfile/declaredKitItems.ts +31 -7
  83. package/src/server/host/bake/headlessWorker.ts +3 -3
  84. package/src/server/host/dedicated/cellWorker.ts +4 -2
  85. package/src/server/host/dedicated/main.ts +7 -4
  86. package/src/server/host/dedicated/packReader.ts +15 -2
  87. package/src/server/host/dedicated/playerStore.ts +1 -1
  88. package/src/server/host/headlessRuntime.ts +11 -6
  89. package/src/server/host/standalone/cellWorld.ts +20 -6
  90. package/src/server/host/standalone/gridServer.ts +3 -1
  91. package/src/server/host/standalone/roadWorld.ts +6 -0
  92. package/src/shared/engine/physics/gridBorders.ts +15 -1
  93. package/src/shared/engine/sim/snapshot.ts +5 -5
  94. package/src/shared/game/ledger.ts +13 -4
  95. package/src/shared/game/loot/platformCatalogue.ts +14 -0
  96. package/src/shared/game/quest/ledger.ts +3 -3
  97. package/src/shared/game/shardfile/items.ts +9 -1
  98. package/src/shared/host/headlessJourney.ts +3 -3
  99. package/src/shared/host/headlessTape.ts +7 -6
  100. package/src/shared/host/releaseRows.ts +4 -1
@@ -0,0 +1,54 @@
1
+ // Row 23: a reviewed staging snapshot, independent of production's live pointers.
2
+ import {createHash} from 'node:crypto';
3
+ import {mkdirSync, readFileSync, writeFileSync} from 'node:fs';
4
+ import {pathToFileURL} from 'node:url';
5
+ import {catalogueSlugs, documentSlugs, unlistedMessage, unlistedSlugs} from './pins-catalogue.ts';
6
+
7
+ interface Pin {slug: string; revision: number; hash: string; bytes: number}
8
+ interface Document {shards: Omit<Pin, 'bytes'>[]; missing: unknown[]; placements: {slug: string}[]; grid: {cells: {slug: string}[]}}
9
+ export interface StagingPins {version: 1; channel: 'staging'; api: string; catalogueHash: string; releaseHash: null; catalogue: Document; shards: Pin[]}
10
+ const file = 'test/pins/staging.json';
11
+ const json = (value: unknown): string => `${JSON.stringify(value, null, 2)}\n`;
12
+ const hash = (value: unknown): string => createHash('sha256').update(JSON.stringify(value)).digest('hex');
13
+
14
+ export function checkStaging(value: StagingPins): void {
15
+ if (value.version !== 1 || value.channel !== 'staging' || value.releaseHash !== null || value.catalogueHash !== hash(value.catalogue)) throw new Error('Invalid staging snapshot identity');
16
+ const {catalogue, shards} = value;
17
+ if (!Array.isArray(catalogue.missing) || catalogue.missing.length > 0 || !Array.isArray(shards) || shards.length === 0 || new Set(shards.map(row => row.slug)).size !== shards.length) throw new Error('Incomplete staging catalogue');
18
+ if (shards.some(row => !/^[a-z0-9-]+$/u.test(row.slug) || !/^[a-f0-9]{64}$/u.test(row.hash) || !Number.isSafeInteger(row.revision) || row.revision < 1 || !Number.isSafeInteger(row.bytes) || row.bytes <= 0)) throw new Error('Invalid staging pin');
19
+ if (catalogue.shards.length !== shards.length || catalogue.shards.some(row => !shards.some(pin => pin.slug === row.slug && pin.hash === row.hash && pin.revision === row.revision))) throw new Error('Staging pins disagree with catalogue');
20
+ const unlisted = unlistedSlugs(catalogueSlugs(catalogue), {staging: documentSlugs(catalogue)});
21
+ if (unlisted.length > 0) throw new Error(unlistedMessage(unlisted));
22
+ }
23
+
24
+ export async function refreshStaging(api: string): Promise<void> {
25
+ const get = async (path: string): Promise<unknown> => {
26
+ const response = await fetch(`${api}${path}`);
27
+ if (!response.ok) throw new Error(`${path}: HTTP ${response.status}`);
28
+ return response.json();
29
+ };
30
+ const [document, listing] = await Promise.all([get('/api/catalogue.json?channel=staging'), get('/api/shardfiles')]);
31
+ const catalogue = document as Document;
32
+ const sizes = new Map((listing as {shardfiles: {hash: string; bytes: number}[]}).shardfiles.map(row => [row.hash, row.bytes]));
33
+ const snapshot: StagingPins = {version: 1, channel: 'staging', api, catalogueHash: hash(catalogue),
34
+ // AP-26 has no public release identity yet. Never call a catalogue digest a release hash.
35
+ releaseHash: null, catalogue, shards: catalogue.shards.map(row => ({slug: row.slug, revision: row.revision, hash: row.hash, bytes: sizes.get(row.hash) ?? 0}))};
36
+ checkStaging(snapshot);
37
+ mkdirSync('test/pins', {recursive: true});
38
+ writeFileSync(file, json(snapshot));
39
+ console.log(`Pinned ${snapshot.shards.length} staging heads; release-hash verification waits on api-server AP-26`);
40
+ }
41
+
42
+ /** Materialize only in an explicitly selected test checkout; installers and both rings keep one input path. */
43
+ export function selectStaging(): void {
44
+ const snapshot = JSON.parse(readFileSync(file, 'utf8')) as StagingPins;
45
+ checkStaging(snapshot);
46
+ writeFileSync('test/pins/shardfiles.json', json({api: snapshot.api, shards: snapshot.shards}));
47
+ writeFileSync('test/pins/catalogue.json', json(snapshot.catalogue));
48
+ console.log(`Selected staging catalogue ${snapshot.catalogueHash}; release hash is unverified (AP-26)`);
49
+ }
50
+
51
+ if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
52
+ if (process.argv[2] === 'select') selectStaging();
53
+ else throw new Error('Use pins.ts refresh --channel staging, or pins-staging.ts select in a disposable test checkout');
54
+ }
package/scripts/pins.ts CHANGED
@@ -462,8 +462,13 @@ function status(): void {
462
462
 
463
463
  const [command = 'status', ...rest] = process.argv.slice(2);
464
464
  if (command === 'refresh') {
465
+ if (rest.length === 2 && rest[0] === '--channel' && rest[1] === 'staging') {
466
+ const {refreshStaging} = await import('./pins-staging.ts');
467
+ await refreshStaging(API);
468
+ } else {
465
469
  if (rest.some((arg, at) => arg.startsWith('-') ? arg !== '--drop' : rest[at - 1] !== '--drop')) throw new Error('usage: pins.ts refresh [--drop slug[,slug]]...');
466
470
  await refresh(rest.flatMap((arg, at) => rest[at - 1] === '--drop' ? arg.split(',') : []));
471
+ }
467
472
  }
468
473
  else if (command === 'install' && rest[0] === '--ring') await installRing(rest[1] ?? '1');
469
474
  else if (command === 'install' && rest[0] === '--from-format') await install(rest.slice(1), 'format');
@@ -0,0 +1,71 @@
1
+ // Standalone integration checks of the sender against a controlled GitHub API.
2
+ import {test} from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import {prepare, runRing3, shardRepos, type Api} from './ring3.ts';
5
+
6
+ const candidate = 'a'.repeat(40), shard = 'b'.repeat(40);
7
+ interface Call {method: string; path: string; body?: unknown}
8
+ function fixture(options: {red?: string; malformed?: boolean; pending?: boolean; wrongRun?: boolean; denied?: string; existing?: boolean} = {}): {api: Api; calls: Call[]} {
9
+ const calls: Call[] = [];
10
+ const api: Api = (method, path, body) => Promise.resolve().then(() => {
11
+ calls.push({method, path, body});
12
+ const repo = path.split('/')[2];
13
+ if (repo === undefined || !shardRepos.includes(repo as typeof shardRepos[number])) throw new Error(`Unexpected repository: ${path}`);
14
+ const id = shardRepos.indexOf(repo as typeof shardRepos[number]) + 100;
15
+ if (method === 'POST' && path.endsWith('/dispatches')) {
16
+ if (repo === options.denied) throw new Error('HTTP 403');
17
+ assert.deepEqual(body, {ref: 'main', inputs: {engine: candidate}, return_run_details: true});
18
+ return options.malformed ? {} : {workflow_run_id: id};
19
+ }
20
+ if (method === 'GET' && path.endsWith(`/actions/runs/${id}`)) return {id: options.wrongRun ? id + 1 : id, event: 'workflow_dispatch', path: '.github/workflows/ci.yml', head_sha: shard, run_attempt: 1,
21
+ status: options.pending ? 'queued' : 'completed', conclusion: repo === options.red ? 'failure' : 'success'};
22
+ if (method === 'GET' && path.includes('/issues?')) return options.existing ? [{title: `[Ring 3] engine ${candidate}`, html_url: 'existing-issue'}] : [];
23
+ if (method === 'POST' && path.endsWith('/issues')) return {html_url: `https://github.com/project-wildshard/${repo}/issues/1`};
24
+ throw new Error(`Unexpected API call: ${method} ${path}`);
25
+ });
26
+ return {api, calls};
27
+ }
28
+
29
+ await test('all seven exact candidate dispatches must complete green on their returned run IDs', async () => {
30
+ const {api, calls} = fixture(), report = await runRing3(prepare(candidate, 'sender'), {api});
31
+ assert.equal(report.ok, true);
32
+ assert.deepEqual(report.rows.map(row => row.repo), shardRepos);
33
+ assert.equal(report.rows.every(row => row.shardSha === shard && row.status === 'success'), true);
34
+ assert.equal(calls.filter(call => call.method === 'POST').length, 7);
35
+ assert.equal(calls.some(call => call.path.includes('/runs?')), false, 'Never substitutes another candidate run');
36
+ });
37
+ await test('one red receiver holds the aggregate and files only that shard issue', async () => {
38
+ const {api, calls} = fixture({red: 'shard-dunes'}), report = await runRing3(prepare(candidate, 'sender'), {api});
39
+ assert.equal(report.ok, false);
40
+ assert.equal(report.rows.filter(row => row.status === 'success').length, 6);
41
+ assert.equal(report.rows[0].issue, 'https://github.com/project-wildshard/shard-dunes/issues/1');
42
+ assert.equal(calls.filter(call => call.method === 'POST' && call.path.endsWith('/issues')).length, 1);
43
+ });
44
+ await test('a repeat red candidate reuses its existing issue', async () => {
45
+ const {api, calls} = fixture({red: 'shard-dunes', existing: true}), report = await runRing3(prepare(candidate, 'sender'), {api});
46
+ assert.equal(report.rows[0].issue, 'existing-issue');
47
+ assert.equal(calls.filter(call => call.method === 'POST' && call.path.endsWith('/issues')).length, 0);
48
+ });
49
+ await test('a refused shard dispatch cannot prevent the other six receivers from running', async () => {
50
+ const {api} = fixture({denied: 'shard-dunes'}), report = await runRing3(prepare(candidate, 'sender'), {api});
51
+ assert.equal(report.ok, false);
52
+ assert.equal(report.rows[0].status, 'error');
53
+ assert.equal(report.rows.filter(row => row.status === 'success').length, 6);
54
+ });
55
+ await test('missing IDs and unrelated green runs can never qualify the candidate', async () => {
56
+ for (const option of [{malformed: true}, {wrongRun: true}]) {
57
+ const {api} = fixture(option), report = await runRing3(prepare(candidate, 'sender'), {api});
58
+ assert.equal(report.ok, false);
59
+ assert.equal(report.rows.every(row => row.status === 'error'), true);
60
+ }
61
+ });
62
+ await test('queued receivers hit a bounded deadline and remain red with their run links', async () => {
63
+ let now = 0;
64
+ const {api} = fixture({pending: true}), report = await runRing3(prepare(candidate, 'sender'), {api, now: () => now, sleep: ms => {now += ms; return Promise.resolve();}, deadlineMs: 100, pollMs: 20});
65
+ assert.equal(now, 100);
66
+ assert.equal(report.ok, false);
67
+ assert.equal(report.rows.every(row => row.status === 'timeout' && row.runUrl !== undefined), true);
68
+ });
69
+ await test('moving refs and shell text refuse before a dispatch can be prepared', () => {
70
+ for (const ref of ['main', 'a'.repeat(39), '$(echo injected)', 'A'.repeat(40)]) assert.throws(() => prepare(ref, 'sender'), /full engine commit/u);
71
+ });
@@ -0,0 +1,100 @@
1
+ // Ring 3: dispatch the exact candidate, then follow the returned run ID.
2
+ // workflow_dispatch reaches the same receiver as engine-candidate, and its
3
+ // return_run_details response avoids guessing which concurrent run is ours.
4
+ import {mkdirSync, readFileSync, writeFileSync} from 'node:fs';
5
+ import {join} from 'node:path';
6
+ import {pathToFileURL} from 'node:url';
7
+
8
+ export const shardRepos = ['shard-dunes', 'shard-sky-reach', 'shard-nalati', 'shard-nine-dragon', 'shard-driftwood', 'shard-pine-hollow', 'shard-open-plots'] as const;
9
+ interface Row {repo: string; status: 'pending' | 'success' | 'failure' | 'error' | 'timeout'; runId?: number; runUrl?: string; shardSha?: string; conclusion?: string | null; issue?: string; error?: string}
10
+ export interface Aggregate {version: 1; engine: string; originRun: string; ok: boolean; rows: Row[]}
11
+ export type Api = (method: 'GET' | 'POST', path: string, body?: unknown) => Promise<unknown>;
12
+ interface Options {api: Api; now?: () => number; sleep?: (ms: number) => Promise<void>; deadlineMs?: number; pollMs?: number; checkpoint?: (report: Aggregate) => void}
13
+ const errorText = (error: unknown): string => String(error).replaceAll(/[\r\n]/gu, ' ').slice(0, 1000);
14
+
15
+ export function prepare(engine: string, originRun: string): Aggregate {
16
+ if (!/^[a-f0-9]{40}$/u.test(engine)) throw new Error('Ring 3 requires the full engine commit hash');
17
+ return {version: 1, engine, originRun, ok: false, rows: shardRepos.map(repo => ({repo, status: 'pending'}))};
18
+ }
19
+
20
+ export async function runRing3(report: Aggregate, options: Options): Promise<Aggregate> {
21
+ const {api, now = Date.now, sleep = (ms: number): Promise<void> => new Promise(resolve => {setTimeout(resolve, ms);}), deadlineMs = 20 * 60_000, pollMs = 15_000, checkpoint = () => { /* Embedded callers may omit persisted receipts. */ }} = options;
22
+ const until = now() + deadlineMs;
23
+ // All seven requests are independent; a refused shard must not hide the others.
24
+ await Promise.all(report.rows.map(async row => {
25
+ try {
26
+ const response = await api('POST', `repos/project-wildshard/${row.repo}/actions/workflows/ci.yml/dispatches`,
27
+ {ref: 'main', inputs: {engine: report.engine}, return_run_details: true}) as {workflow_run_id?: number; html_url?: string};
28
+ if (!Number.isSafeInteger(response.workflow_run_id) || (response.workflow_run_id ?? 0) <= 0) throw new Error('Dispatch returned no exact run ID; refusing to guess a run');
29
+ row.runId = response.workflow_run_id;
30
+ row.runUrl = `https://github.com/project-wildshard/${row.repo}/actions/runs/${row.runId}`;
31
+ } catch (error) {row.status = 'error'; row.error = errorText(error);}
32
+ checkpoint(report);
33
+ }));
34
+ while (report.rows.some(row => row.status === 'pending') && now() < until) {
35
+ await Promise.all(report.rows.filter(row => row.status === 'pending').map(async row => {
36
+ try {
37
+ const run = await api('GET', `repos/project-wildshard/${row.repo}/actions/runs/${row.runId}`) as {id: number; event: string; path: string; head_sha: string; status: string; conclusion: string | null; run_attempt: number};
38
+ if (run.id !== row.runId || run.event !== 'workflow_dispatch' || run.path.split('@')[0] !== '.github/workflows/ci.yml' || !/^[a-f0-9]{40}$/u.test(run.head_sha) || run.run_attempt !== 1) throw new Error('Receiver run identity changed; new qualification required');
39
+ row.shardSha = run.head_sha;
40
+ if (run.status === 'completed') {row.conclusion = run.conclusion; row.status = run.conclusion === 'success' ? 'success' : 'failure';}
41
+ } catch (error) {row.status = 'error'; row.error = errorText(error);}
42
+ checkpoint(report);
43
+ }));
44
+ if (report.rows.some(row => row.status === 'pending')) await sleep(Math.max(0, Math.min(pollMs, until - now())));
45
+ }
46
+ for (const row of report.rows) if (row.status === 'pending') {row.status = 'timeout'; row.error = 'Receiver did not complete within the Ring 3 deadline';}
47
+ // Deduplicate per candidate in each shard; cancelled/skipped/incomplete is never green.
48
+ await Promise.all(report.rows.filter(row => row.status !== 'success' && row.runId !== undefined).map(async row => {
49
+ try {
50
+ const title = `[Ring 3] engine ${report.engine}`;
51
+ const existing = await api('GET', `repos/project-wildshard/${row.repo}/issues?state=all&per_page=100&sort=created&direction=desc`) as {title: string; html_url: string; pull_request?: unknown}[];
52
+ const prior = existing.find(issue => issue.pull_request === undefined && issue.title === title);
53
+ if (prior !== undefined) row.issue = prior.html_url;
54
+ else {
55
+ const issue = await api('POST', `repos/project-wildshard/${row.repo}/issues`, {title,
56
+ body: `Engine candidate: \`${report.engine}\`\n\nReceiver: ${row.runUrl}\n\nShard commit: \`${row.shardSha ?? 'unavailable'}\`\n\nVerdict: ${row.status} (${row.conclusion ?? row.error ?? 'incomplete'}).\n\nSender: ${report.originRun}\n\nFix forward (J165); this candidate is not release-qualified.`}) as {html_url: string};
57
+ row.issue = issue.html_url;
58
+ }
59
+ } catch (error) {row.error = `${row.error ?? ''} Issue creation failed: ${errorText(error)}`.trim();}
60
+ checkpoint(report);
61
+ }));
62
+ report.ok = report.rows.length === shardRepos.length && report.rows.every(row => row.status === 'success');
63
+ checkpoint(report);
64
+ return report;
65
+ }
66
+
67
+ export function markdown(report: Aggregate): string {
68
+ return [`# Ring 3: ${report.ok ? 'GREEN' : 'RED — RELEASE HELD'}`, '', `Engine: \`${report.engine}\``, '',
69
+ '| Shard | Candidate run | Shard commit | Verdict | Issue |', '| --- | --- | --- | --- | --- |',
70
+ ...report.rows.map(row => `| ${row.repo} | ${row.runUrl === undefined ? 'not dispatched' : `[${row.runId}](${row.runUrl})`} | ${row.shardSha?.slice(0, 12) ?? 'unknown'} | ${row.status} | ${row.issue === undefined ? '' : `[issue](${row.issue})`} |`),
71
+ '', ...report.rows.filter(row => row.error !== undefined).map(row => `- ${row.repo}: ${row.error?.replaceAll(/[|<>]/gu, ' ')}`),
72
+ '', 'This artifact aggregates candidate checks. It does not create a tag, release, upload or deployment.', ''].join('\n');
73
+ }
74
+
75
+ if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
76
+ const [command, directory = 'tmp/ring3'] = process.argv.slice(2);
77
+ const save = (report: Aggregate): void => {mkdirSync(directory, {recursive: true}); writeFileSync(join(directory, 'verdict.json'), `${JSON.stringify(report, null, 2)}\n`); writeFileSync(join(directory, 'summary.md'), markdown(report));};
78
+ if (command === 'prepare') save(prepare(process.env.RING3_ENGINE ?? '', process.env.RING3_ORIGIN_RUN ?? 'local'));
79
+ else if (command === 'run') {
80
+ const report = JSON.parse(readFileSync(join(directory, 'verdict.json'), 'utf8')) as Aggregate;
81
+ // Revalidate the persisted candidate before any write request.
82
+ if (JSON.stringify(report) !== JSON.stringify(prepare(report.engine, report.originRun))) throw new Error('Ring 3 must start from a fresh prepared aggregate');
83
+ const token = process.env.GH_TOKEN;
84
+ if (token === undefined || token === '') throw new Error('Ring 3 needs the dedicated nightly App token');
85
+ const api: Api = async (method, path, body) => {
86
+ const response = await fetch(`https://api.github.com/${path}`, {method, signal: AbortSignal.timeout(20_000),
87
+ headers: {accept: 'application/vnd.github+json', authorization: `Bearer ${token}`, 'x-github-api-version': '2022-11-28', ...(body === undefined ? {} : {'content-type': 'application/json'})},
88
+ ...(body === undefined ? {} : {body: JSON.stringify(body)})});
89
+ if (!response.ok) throw new Error(`GitHub ${method} ${path}: HTTP ${response.status}; check nightly App installation and Actions/Issues permissions`);
90
+ return response.json();
91
+ };
92
+ await runRing3(report, {api, checkpoint: save});
93
+ console.log(markdown(report));
94
+ if (!report.ok) process.exitCode = 1;
95
+ } else if (command === 'report') {
96
+ const report = JSON.parse(readFileSync(join(directory, 'verdict.json'), 'utf8')) as Aggregate;
97
+ console.log(markdown(report));
98
+ if (!report.ok) process.exitCode = 1;
99
+ } else throw new Error('Use ring3.ts prepare|run|report [directory]');
100
+ }
@@ -2,7 +2,7 @@
2
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
3
  // repo and singleplayer carries a byte-identical copy at scripts/scratch-dir.mjs (DK8 checks the copies).
4
4
  //
5
- // node scripts/scratch-dir.mjs <task> "<purpose>"
5
+ // node scripts/scratch-dir.mjs <task> "<purpose>" [--row <plan-row>]
6
6
  //
7
7
  // creates <repo>/tmp/<task>/ and tmp/<task>/.owner, then prints the folder's absolute path. .owner is JSON: the session
8
8
  // id ($CLAUDE_SESSION_ID, else $CLAUDE_CODE_SESSION_ID, else the Codex lane name in $WS_LANE_NAME), the lane name, the
@@ -12,7 +12,8 @@
12
12
  // <task> is one plain folder name: letters, digits, '.', '_' and '-', not starting with '.', never containing '/' or
13
13
  // '..'. The helper deletes nothing. It refuses a folder that already exists unless that folder's .owner names this
14
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';
15
+ import { mkdirSync, readFileSync, renameSync, rmdirSync, statSync, writeFileSync } from 'node:fs';
16
+ import { homedir } from 'node:os';
16
17
  import { join, resolve } from 'node:path';
17
18
  import { pathToFileURL } from 'node:url';
18
19
 
@@ -31,14 +32,21 @@ export function refuseTask(task) {
31
32
  }
32
33
 
33
34
  /** 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) {
35
+ * @param {string} task @param {string} purpose @param {NodeJS.ProcessEnv} env @param {Date} now
36
+ * @param {string | null} row */
37
+ export function ownerRecord(task, purpose, env, now, row = null) {
36
38
  const lane = env.WS_LANE_NAME || null;
39
+ let receiptOffset = null;
40
+ try { receiptOffset = statSync(env.WS_LANE_RECEIPTS ?? join(homedir(), '.cache/wildshard/lane-receipts.log')).size; }
41
+ catch (error) { if (error instanceof Error && 'code' in error && error.code === 'ENOENT') receiptOffset = 0; }
37
42
  return {
38
43
  task,
39
- session: env.CLAUDE_SESSION_ID || env.CLAUDE_CODE_SESSION_ID || lane,
44
+ session: env.CLAUDE_SESSION_ID || env.CLAUDE_CODE_SESSION_ID || env.CODEX_THREAD_ID || lane,
40
45
  lane,
41
46
  pane: env.HERDR_PANE_ID || null,
47
+ agent: env.CLAUDE_SESSION_ID || env.CLAUDE_CODE_SESSION_ID ? 'claude' : env.CODEX_THREAD_ID || lane ? 'codex' : 'unknown',
48
+ row,
49
+ receiptOffset,
42
50
  started: now.toISOString(),
43
51
  purpose,
44
52
  };
@@ -52,21 +60,29 @@ function readOwner(path) {
52
60
  /** Make <root>/tmp/<task>/ and its .owner; returns the folder's absolute path. Throws on a refused name, an empty
53
61
  * purpose, or a folder that exists and is not this session's.
54
62
  * @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() } = {}) {
63
+ * @param {{root?: string, env?: NodeJS.ProcessEnv, now?: Date, row?: string | null}} [options] */
64
+ export function scratchDir(task, purpose, { root = ROOT, env = process.env, now = new Date(), row = null } = {}) {
57
65
  const refusal = refuseTask(task);
58
66
  if (refusal) throw new Error(refusal);
59
67
  if (typeof purpose !== 'string' || purpose.trim() === '') throw new Error('a purpose is required');
60
68
  const tmp = join(resolve(root), 'tmp');
61
69
  const dir = join(tmp, task);
62
- const owner = ownerRecord(task, purpose.trim(), env, now);
70
+ if (row !== null && !/^[A-Z][A-Z0-9-]*\d+[a-z]?$/u.test(row)) throw new Error(`row "${row}" is not a plan row`);
71
+ const owner = ownerRecord(task, purpose.trim(), env, now, row);
63
72
  mkdirSync(tmp, { recursive: true });
64
73
  try {
65
74
  mkdirSync(dir);
66
75
  } catch (error) {
67
76
  if (!(error instanceof Error && 'code' in error && error.code === 'EEXIST')) throw error;
68
77
  const existing = readOwner(join(dir, '.owner'));
69
- if (existing && owner.session && existing.session === owner.session) return dir;
78
+ if (existing && owner.session && existing.session === owner.session) {
79
+ // A lane name can outlive a task. Advance its cursor when it resumes,
80
+ // without ever exposing a half-written ownership record.
81
+ const next = join(dir, `.owner-${process.pid}`);
82
+ writeFileSync(next, `${JSON.stringify(owner, null, 2)}\n`, { flag: 'wx' });
83
+ renameSync(next, join(dir, '.owner'));
84
+ return dir;
85
+ }
70
86
  throw new Error(existing
71
87
  ? `${dir} already belongs to session ${String(existing.session)}; pick another task name`
72
88
  : `${dir} already exists with no .owner; pick another task name`);
@@ -82,12 +98,15 @@ export function scratchDir(task, purpose, { root = ROOT, env = process.env, now
82
98
 
83
99
  if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
84
100
  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>"');
101
+ const rowAt = rest.indexOf('--row');
102
+ const row = rowAt === -1 ? null : rest[rowAt + 1] ?? null;
103
+ const other = rowAt === -1 ? rest : rest.filter((_, index) => index !== rowAt && index !== rowAt + 1);
104
+ if (other.length > 0 || task === '--help' || task === '-h' || rowAt !== -1 && row === null) {
105
+ console.error('usage: node scripts/scratch-dir.mjs <task> "<purpose>" [--row <plan-row>]');
87
106
  process.exit(2);
88
107
  }
89
108
  try {
90
- console.log(scratchDir(task, purpose));
109
+ console.log(scratchDir(task, purpose, { row }));
91
110
  } catch (error) {
92
111
  console.error(`scratch-dir: ${error instanceof Error ? error.message : String(error)}`);
93
112
  process.exit(1);
@@ -1,8 +1,8 @@
1
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
2
+ // repo-kit's report-only scratch sweep (meta REPO-DISK-PLAN J358, was TEMP-HYGIENE T7). One copy lives in repo-kit; every org
3
3
  // repo carries a byte-identical copy at scripts/scratch-sweep.mjs, beside scratch-dir.mjs (DK3) and vite-tmp.mjs.
4
4
  //
5
- // node scripts/scratch-sweep.mjs [--live] [--root <repo>] [--days <n>]
5
+ // node scripts/scratch-sweep.mjs [--root <repo>] [--days <n>]
6
6
  //
7
7
  // It looks at each folder directly under <repo>/tmp/ and would remove one in which nothing (the folder or anything in
8
8
  // it) changed for <n> days (3 by default), with or without a DK3 `.owner`. It keeps:
@@ -11,12 +11,13 @@
11
11
  // - a folder that is, or holds, some process's cwd (lsof -d cwd; /proc on Linux); an unreadable table keeps all;
12
12
  // - a folder holding a Git root with dirty files or commits no remote has (DS14's list: the reason names the root);
13
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.
14
+ // J358 cancelled the 11-20 go-live: this script never removes files. Every decision is appended to
15
+ // tmp/.sweep.log, one line each, and a summary line goes to stdout for a human daily audit.
16
16
  import { spawnSync } from 'node:child_process';
17
- import { appendFileSync, lstatSync, readdirSync, readFileSync, readlinkSync, realpathSync, rmSync } from 'node:fs';
17
+ import { appendFileSync, lstatSync, readdirSync, readFileSync, readlinkSync, realpathSync } from 'node:fs';
18
18
  import { join, resolve, sep } from 'node:path';
19
19
  import { pathToFileURL } from 'node:url';
20
+ import { laneLive } from './lane-live.mjs';
20
21
 
21
22
  const DEFAULT_DAYS = 3;
22
23
  const MINUTES_A_DAY = 1440;
@@ -138,23 +139,14 @@ export function plan({ root, days = DEFAULT_DAYS, cwds = processCwds() }) {
138
139
  return rows;
139
140
  }
140
141
 
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() }) {
142
+ /** Plans and logs every row to tmp/.sweep.log. J358: humans, not this script, remove leftovers.
143
+ * @param {{ root: string, days?: number, cwds?: readonly string[] | null, now?: Date }} options */
144
+ export function sweep({ root, days = DEFAULT_DAYS, cwds, now = new Date() }) {
144
145
  const rows = plan({ root, days, ...(cwds === undefined ? {} : { cwds }) });
145
146
  const stamp = now.toISOString(), lines = [];
146
- let removed = 0;
147
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
- }
148
+ const liveness = laneLive(join(root, 'tmp', row.name));
149
+ const verb = row.action === 'keep' ? `keep (${row.reason}; ${liveness.state}: ${liveness.reason})` : `leftover (manual audit; ${liveness.state}: ${liveness.reason})`;
158
150
  lines.push(`${stamp} ${verb} tmp/${row.name}${row.action === 'remove' ? ` (${row.reason})` : ''}\n`);
159
151
  }
160
152
  if (lines.length > 0) {
@@ -163,7 +155,7 @@ export function sweep({ root, live = false, days = DEFAULT_DAYS, cwds, now = new
163
155
  } catch {}
164
156
  }
165
157
  const planned = rows.filter(row => row.action === 'remove').length;
166
- return { rows, planned, removed };
158
+ return { rows, planned };
167
159
  }
168
160
 
169
161
  if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
@@ -175,8 +167,8 @@ if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.a
175
167
  const days = Number(flag('--days') ?? DEFAULT_DAYS);
176
168
  if (!Number.isInteger(days) || days < 1) throw new Error('--days takes a whole number of days, 1 or more');
177
169
  const root = resolve(flag('--root') ?? resolve(import.meta.dirname, '..'));
178
- const live = args.includes('--live');
179
- const { rows, planned, removed } = sweep({ root, live, days });
170
+ if (args.includes('--live')) throw new Error('--live was removed by REPO-DISK J358: this command only reports leftovers');
171
+ const { rows, planned } = sweep({ root, days });
180
172
  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`);
173
+ process.stdout.write(`scratch-sweep report ${root}/tmp: ${String(planned)} leftover(s) for manual audit, kept ${String(keptRows.length)}; log tmp/.sweep.log\n`);
182
174
  }
@@ -0,0 +1,7 @@
1
+ import type { S3Client } from '@aws-sdk/client-s3';
2
+ import type { ReleaseFile } from '../../src/shared/host/releaseRows';
3
+
4
+ type ItemReference = NonNullable<ReleaseFile['items']>;
5
+ export function itemDigest(body: Uint8Array): string;
6
+ export function itemBytesMatch(body: Uint8Array, reference: ItemReference): boolean;
7
+ export function copyItemCatalogue(client: S3Client, bucket: string, read?: typeof fetch): Promise<ItemReference>;
@@ -0,0 +1,28 @@
1
+ // Q37: only publication contacts api-server. The running game reads this immutable R2 copy.
2
+ import {createHash} from 'node:crypto';
3
+ import {GetObjectCommand,PutObjectCommand,S3ServiceException} from '@aws-sdk/client-s3';
4
+ import {MAX_ITEM_CATALOGUE_BYTES,platformItemCatalogueBytes} from '../../src/shared/game/loot/platformCatalogue.ts';
5
+
6
+ /** @typedef {NonNullable<import('../../src/shared/host/releaseRows.ts').ReleaseFile['items']>} ItemReference */
7
+ /** @param {Uint8Array} body */
8
+ export const itemDigest=body=>createHash('sha256').update(body).digest('hex');
9
+ /** @param {Uint8Array} body @param {ItemReference} reference */
10
+ export const itemBytesMatch=(body,reference)=>body.byteLength===reference.bytes&&itemDigest(body)===reference.sha256;
11
+
12
+ /** Copy admitted, canonical API bytes before signing any channel. A hash-named object is never overwritten.
13
+ * @param {import('@aws-sdk/client-s3').S3Client} client @param {string} bucket @param {typeof fetch} [read] @returns {Promise<ItemReference>} */
14
+ export async function copyItemCatalogue(client,bucket,read=fetch){
15
+ const response=await read('https://api.wildshard.io/api/items.json',{cache:'no-store',signal:AbortSignal.timeout(30_000)});
16
+ if(!response.ok)throw new Error(`Item catalogue answered ${response.status}`);
17
+ const text=await response.text();
18
+ if(new TextEncoder().encode(text).byteLength>MAX_ITEM_CATALOGUE_BYTES)throw new Error('Item catalogue is too large');
19
+ const body=platformItemCatalogueBytes(JSON.parse(text)),sha256=itemDigest(body),reference={path:`assets/catalogue/items-${sha256}.json`,sha256,bytes:body.byteLength};
20
+ try{await client.send(new PutObjectCommand({Bucket:bucket,Key:reference.path,Body:body,ContentType:'application/json',CacheControl:'public,max-age=31536000,immutable',IfNoneMatch:'*'}));}
21
+ catch(error){
22
+ if(!(error instanceof S3ServiceException&&error.$metadata.httpStatusCode===412))throw error;
23
+ const existing=await client.send(new GetObjectCommand({Bucket:bucket,Key:reference.path}));
24
+ const kept=await existing.Body?.transformToByteArray();
25
+ if(kept===undefined||!itemBytesMatch(kept,reference))throw new Error('Existing item catalogue hash mismatch',{cause:error});
26
+ }
27
+ return reference;
28
+ }
@@ -8,6 +8,7 @@ import { GetObjectCommand, HeadObjectCommand, PutObjectCommand, S3Client, S3Serv
8
8
  import * as v from 'valibot';
9
9
  import { readServerPackBook, serverPackBookPath } from '../../src/shared/game/shardfile/serverPack.ts';
10
10
  import { bundleDescriptor, COMMIT, DEFAULT_SERVER_SHARDS, publication, readPublication, releasePublicKey, releaseShards, signRelease } from './sign.mjs';
11
+ import { copyItemCatalogue, itemBytesMatch } from './items.mjs';
11
12
 
12
13
  /** @typedef {import('../../src/shared/host/releaseRows.ts').ReleaseFile} ReleaseFile */
13
14
  /** @typedef {{client: S3Client, bucket: string, candidate: ReleaseFile, privateKey: string, publicKey: string, isAncestor: (older: string, newer: string) => boolean,
@@ -22,6 +23,12 @@ const missing = error => error instanceof S3ServiceException && (error.name ===
22
23
  * no book strands every check behind it. Null when the book and every part the release's shards and grid need are in the bucket.
23
24
  * @param {S3Client} client @param {string} bucket @param {ReleaseFile} release @returns {Promise<string | null>} */
24
25
  export async function serverPacksReady(client, bucket, release) {
26
+ if (release.items !== undefined) {
27
+ let body;
28
+ try { body = await (await client.send(new GetObjectCommand({ Bucket: bucket, Key: release.items.path }))).Body?.transformToByteArray(); }
29
+ catch (error) { if (missing(error)) return `no item catalogue at ${release.items.path}`; throw error; }
30
+ if (body === undefined || !itemBytesMatch(body, release.items)) return `item catalogue hash mismatch at ${release.items.path}`;
31
+ }
25
32
  const key = serverPackBookPath(release.engineBuild);
26
33
  let text;
27
34
  try { text = await (await client.send(new GetObjectCommand({ Bucket: bucket, Key: key }))).Body?.transformToString(); }
@@ -126,7 +133,8 @@ async function main() {
126
133
  const client = new S3Client({ region: 'auto', endpoint: `https://${account}.r2.cloudflarestorage.com`, credentials });
127
134
  try {
128
135
  const packsReady = (/** @type {ReleaseFile} */ release) => serverPacksReady(client, bucket, release);
129
- const result = await publishChannel({ client, bucket, candidate, privateKey, publicKey, isAncestor, align, packsReady });
136
+ const items = await copyItemCatalogue(client, bucket);
137
+ const result = await publishChannel({ client, bucket, candidate: { ...candidate, items }, privateKey, publicKey, isAncestor, align, packsReady });
130
138
  writeFileSync(values.out, `${result.signed}\n`);
131
139
  console.log(JSON.stringify({ status: result.status, channel: result.release.channel, serial: result.release.serial, engineBuild: result.release.engineBuild, object: `releases/${result.release.channel}.json`,
132
140
  ...result.reason === undefined ? {} : { held: candidate.engineBuild, reason: result.reason } }));
@@ -169,7 +169,7 @@ export function sideParityDiff(paged, server, at, allow = {}, { slack = 1, same
169
169
  if (best !== null) { used.add(best); return; }
170
170
  const shape = all.find(other => close(row, other));
171
171
  const inside = (outer, inner) => [0, 1, 2].every(i => inner[i] >= outer[i] - slack && inner[i + 3] <= outer[i + 3] + slack);
172
- if (shape === undefined && side === 'page' && !row.sensor && !row.dynamic && all.some(other => other.material === 'edge' && !other.sensor && inside(other.box, row.box))) return;
172
+ if (shape === undefined && side === 'page' && !row.sensor && !row.dynamic && all.some(other => other.material === 'edge' && !other.sensor && !Object.hasOwn(allow, allowKey(other)) && inside(other.box, row.box))) return;
173
173
  if (shape === undefined) { note(`${side}|${matchKey(row)}|${row.dynamic}`, row.box, (count, box) => side === 'page'
174
174
  ? `${describe(row)}: ${count} page collider(s) with no server match, e.g. [${box.join(', ')}]`
175
175
  : `${describe(row)}: ${count} server collider(s) near the page's player with no page match, e.g. [${box.join(', ')}]`); return; }
@@ -1,4 +1,5 @@
1
1
  {
2
+ "test/admitted-product-cache.test.ts": [],
2
3
  "test/net-link-play.test.ts": ["driftwood-isle"],
3
4
  "test/engine-rule-successors.test.ts": ["pine-hollow", "nalati-grasslands", "driftwood-isle"],
4
5
  "test/engine-rule-successors-titan.test.ts": ["nalati-grasslands"],
@@ -36,6 +36,7 @@
36
36
  }
37
37
  ],
38
38
  "include": [
39
+ "../.agents/hooks/active-hours.mjs",
39
40
  "**/*.mjs",
40
41
  "**/*.ts",
41
42
  "**/*.mts",
@@ -551,6 +552,7 @@
551
552
  "webkit-mem-reading.mjs",
552
553
  "webkit-render-smoke.mjs",
553
554
  "worker-client-fights.mjs",
555
+ "fight-page-census.mjs",
554
556
  "worker-client-moments.mjs",
555
557
  "worker-client-play.mjs",
556
558
  "worker-client-proof.mjs",
@@ -18,7 +18,11 @@ export const CI_NATIVE_GROUPS = {
18
18
  // MP1C.4: a real crossing on the real clock, then a reboot; kept off sibling workers like net-fuzz's crossing.
19
19
  'test/grid-crossing-crash.test.ts',
20
20
  ],
21
- 'native-direct-worker': ['test/headless-direct-worker.test.ts'],
21
+ 'native-direct-worker': [
22
+ 'test/headless-direct-worker.test.ts',
23
+ // Six real SDK workers, with a fixed 20 s parent fence: no sibling files.
24
+ 'test/headless-verb-tape-worker.test.ts',
25
+ ],
22
26
  'native-host-transport': ['test/sim-transport.test.ts'],
23
27
  'native-restores': [
24
28
  'test/pinned-restore-play.test.ts',