A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(audit): the engine's decisions, and who can see them
esengineae91b9a1846a
diff --git a/tools/check-decision-inventory.mjs b/tools/check-decision-inventory.mjsnew file mode 100644index 000000000..9bfd29cae--- /dev/null+++ b/tools/check-decision-inventory.mjs@@ -0,0 +1,118 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file check-decision-inventory.mjs — the declared runtime decisions still say+ * something true, and the debt between their three surfaces is counted.+ *+ * runtimeDecisions.mjs names, for each choice the engine makes on a creator's+ * behalf, whether the runtime records WHY, whether the editor shows it, and+ * whether the automation surface answers the same question. This holds those+ * claims against the tree: a probe that no longer finds its subject is a finding,+ * not documentation, and an `owed` that has quietly been paid is bookkeeping that+ * stopped being true.+ *+ * It reports rather than ratchets. The debt here is a roadmap, not a regression:+ * failing on its size would only invite entries to be deleted. What it FAILS on+ * is a lie — a citation pointing nowhere, or a surface claimed and unfindable.+ *+ * node tools/check-decision-inventory.mjs [--list]+ */+import { readFileSync, existsSync, readdirSync, statSync } from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+import { DECISIONS } from './lib/runtimeDecisions.mjs';++const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');+const SURFACES = ['runtime', 'editor', 'agent'];++const read = (rel) => readFileSync(path.join(ROOT, rel), 'utf8');++/** Every file under a directory, so a directory citation can be probed. */+function filesUnder(dir, out = []) {+ for (const entry of readdirSync(dir)) {+ const full = path.join(dir, entry);+ if (statSync(full).isDirectory()) filesUnder(full, out);+ else out.push(full);+ }+ return out;+}++/** Null when the citation still finds what it says, else why not. */+function probeHolds(cite) {+ const full = path.join(ROOT, cite.path);+ if (!existsSync(full)) return 'does not exist';+ if (cite.dir) {+ for (const f of filesUnder(full)) {+ if (cite.probe.test(readFileSync(f, 'utf8'))) return null;+ }+ return `no file under it matches ${cite.probe}`;+ }+ return cite.probe.test(read(cite.path)) ? null : `does not match ${cite.probe}`;+}++// The editor is an optional submodule; a citation into it cannot be judged+// without one. Named, never rounded down to a pass.+const HAS_EDITOR = existsSync(path.join(ROOT, 'desktop', 'src'));++const problems = [];+const skipped = [];+const owed = [];+let claimed = 0;++for (const d of DECISIONS) {+ const cites = [['owner', d.owner], ...SURFACES.map((s) => [s, d[s]?.has ? d[s].cite : null])];+ for (const [role, cite] of cites) {+ if (!cite) continue;+ if (!HAS_EDITOR && cite.path.startsWith('desktop/')) { skipped.push(`${d.id} → ${role}`); continue; }+ claimed++;+ const why = probeHolds(cite);+ if (why) problems.push(`${d.id} → ${role}: ${cite.path} ${why}`);+ }+ for (const s of SURFACES) {+ const surface = d[s];+ if (!surface) { problems.push(`${d.id} says nothing about its ${s} surface`); continue; }+ if (!surface.has && !surface.owed) problems.push(`${d.id} → ${s} is absent with no reason`);+ if (!surface.has) owed.push({ id: d.id, kind: d.kind, surface: s, why: surface.owed });+ }+}++/**+ * The shapes worth naming apart, in the order they are worth fixing. `human >+ * agent` is last because it breaks no principle — automation is not owed more+ * than a person — and is still a surface that is not finished.+ */+const imbalance = (d) => {+ if (!d.runtime?.has) return 'decision > explanation';+ if (d.agent?.has && !d.editor?.has) return 'agent > human';+ if (!d.editor?.has) return 'runtime > editor';+ if (!d.agent?.has) return 'human > agent';+ return null;+};++if (process.argv.includes('--list')) {+ const width = Math.max(...DECISIONS.map((d) => d.id.length));+ console.log(`${'decision'.padEnd(width)} runtime editor agent imbalance`);+ for (const d of DECISIONS) {+ const mark = (s) => (d[s]?.has ? ' ok ' : ' owed ');+ console.log(`${d.id.padEnd(width)} ${mark('runtime')}${mark('editor')}${mark('agent')} ${imbalance(d) ?? 'complete'}`);+ }+ console.log(`\nowed (${owed.length}):`);+ for (const o of owed) console.log(` ${o.id} → ${o.surface}: ${o.why}`);+}++if (skipped.length) {+ console.log(`check-decision-inventory: no editor checkout — ${skipped.length} citation(s) not judged:`+ + ` ${skipped.join(', ')}`);+}+if (problems.length) {+ console.error(`check-decision-inventory: ${problems.length} problem(s)`);+ for (const p of problems) console.error(` ${p}`);+ console.error('\n A citation that no longer finds its subject is a finding: either the decision moved'+ + '\n and the entry follows it, or the entry was never true.');+ process.exit(1);+}+const counts = {};+for (const d of DECISIONS) counts[imbalance(d) ?? 'complete'] = (counts[imbalance(d) ?? 'complete'] ?? 0) + 1;+console.log(`check-decision-inventory: ${DECISIONS.length} decision(s), ${claimed} citation(s) hold — `+ + Object.entries(counts).map(([k, n]) => `${n} ${k}`).join(', ')+ + ` (${owed.length} owed surface(s); --list names them).`);diff --git a/tools/check-mutator-parity.mjs b/tools/check-mutator-parity.mjsnew file mode 100644index 000000000..ec75f18f6--- /dev/null+++ b/tools/check-mutator-parity.mjs@@ -0,0 +1,145 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file check-mutator-parity.mjs — automation may not reach a project setting a+ * person cannot.+ *+ * The editor has a built-in agent, and every project mutator is exposed to it+ * through one facade. That is the right shape until a mutator has ONLY that+ * caller: `setAudio` writes bus volumes, effects and duck rules, is reachable+ * from the automation surface, and has no button, row or panel anywhere — so an+ * agent can author the project mixer and the person who owns the project cannot.+ * `setSpineVersion` decides which Spine runtime ships, with the same asymmetry.+ *+ * Neither was a decision. Both were a UI nobody got to, behind a facade that+ * reaches everything by construction — which is why this is discovered rather+ * than declared: the list of what a person can do is not one anybody maintains.+ *+ * The rule is one-directional on purpose. A person reaching something automation+ * cannot is fine; automation reaching what a person cannot is the product saying+ * the model is the creator.+ *+ * node tools/check-mutator-parity.mjs [--list]+ */+import { readFileSync, existsSync, readdirSync, statSync } from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';++const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');+const EDITOR = path.join(ROOT, 'desktop', 'src');+const STORE = path.join(EDITOR, 'project', 'ProjectStore.ts');+/** The automation facade and the surface behind it: a call from here is the AGENT's. */+const AUTOMATION = new Set([+ path.join(EDITOR, 'main.tsx'),+ path.join(EDITOR, 'engine', 'EditorControlSurface.ts'),+]);++/**+ * Mutators a person reaches through a DIFFERENT door, and which one. Not+ * exemptions: each names the sibling that carries the human path, and the gate+ * checks that sibling is itself reachable — an alias for a hole is a hole.+ */+const REACHED_VIA = {+ setImportSettings: 'setImportSettingsMany',+};++/**+ * The two that are violations, recorded as violations. Debt, not exemption: an+ * entry leaves this block by growing a human door, never by being explained, and+ * adding one is a visible diff — which is the only ratchet a discovered list can+ * have without becoming a place to put the next one.+ */+const OWED = {+ setAudio: 'bus volumes, effects and duck rules ship in every build and there is no Mixer panel '+ + 'and no project.audio.* row — Audio Authoring v1',+ setSpineVersion: 'which Spine runtime the project bundles, a size and compatibility decision with '+ + 'only a read-only diagnostics line in the UI',+};++if (!existsSync(EDITOR)) {+ console.log('check-mutator-parity: no editor checkout — no mutator was judged.');+ process.exit(0);+}++function sources(dir, out = []) {+ for (const entry of readdirSync(dir)) {+ const full = path.join(dir, entry);+ if (statSync(full).isDirectory()) sources(full, out);+ else if (/\.tsx?$/.test(entry)) out.push(full);+ }+ return out;+}++const store = readFileSync(STORE, 'utf8');+// The public write door: every `set*`/`patch*` method the store declares.+const mutators = [...new Set([...store.matchAll(/^\s{2}(?:async\s+)?(set[A-Z]\w*|patch[A-Z]\w*)\s*[(<]/gm)]+ .map((m) => m[1]))];++const files = sources(EDITOR).filter((f) => f !== STORE);+/** Who calls each mutator, split by whose hand is on it. */+const callers = new Map(mutators.map((m) => [m, { agent: 0, human: 0 }]));+for (const file of files) {+ const src = readFileSync(file, 'utf8');+ const agent = AUTOMATION.has(file);+ for (const m of mutators) {+ const hits = (src.match(new RegExp(`ProjectStore\\.${m}\\s*\\(`, 'g')) ?? []).length;+ if (!hits) continue;+ callers.get(m)[agent ? 'agent' : 'human'] += hits;+ }+}++const problems = [];+// The fact first, the bookkeeping second: a mutator automation calls and no UI+// does is automation-only whether or not somebody has written a note about it.+const agentOnly = [...callers].filter(([, c]) => c.agent > 0 && c.human === 0).map(([m]) => m);+const onlyAgent = [];+for (const m of agentOnly) {+ const via = REACHED_VIA[m];+ if (!via) { onlyAgent.push(m); continue; }+ if (!callers.has(via)) {+ problems.push(`REACHED_VIA.${m} names "${via}", which ProjectStore does not declare`);+ } else if (callers.get(via).human === 0) {+ problems.push(`${m} is declared reachable through ${via}, and ${via} has no human caller either`+ + ' — the alias points at the same hole');+ }+}+const owed = [];+for (const m of onlyAgent) {+ if (OWED[m]) { owed.push(` ${m} — ${OWED[m]}`); continue; }+ problems.push(`ProjectStore.${m} is called by the automation facade and by nothing a person can`+ + ' touch — an agent can change this project setting and its owner cannot. Give it a row, a'+ + ' button or a panel, or name the door a person uses in REACHED_VIA');+}+for (const m of Object.keys(OWED)) {+ if (!agentOnly.includes(m)) {+ problems.push(`OWED names ${m}, which a person can now reach — drop the entry rather than`+ + ' leaving a paid debt on the books');+ }+}+// A named door for a mutator that needs no door is a sentence nobody rereads,+// and the next reader takes it for a decision.+for (const m of Object.keys(REACHED_VIA)) {+ if (!agentOnly.includes(m)) {+ problems.push(`REACHED_VIA names ${m}, which is not automation-only — the entry answers a`+ + ' question nothing asks');+ }+}++if (process.argv.includes('--list')) {+ const width = Math.max(...mutators.map((m) => m.length));+ console.log(`${'mutator'.padEnd(width)} agent human`);+ for (const [m, c] of [...callers].sort((a, b) => a[1].human - b[1].human)) {+ console.log(`${m.padEnd(width)} ${String(c.agent).padStart(5)} ${String(c.human).padStart(5)}`+ + `${REACHED_VIA[m] ? ` via ${REACHED_VIA[m]}` : ''}`);+ }+}++if (problems.length) {+ console.error(`check-mutator-parity: ${problems.length} problem(s)`);+ for (const p of problems) console.error(` - ${p}`);+ process.exit(1);+}+if (owed.length) console.log(`check-mutator-parity: ${owed.length} owed a human door:\n${owed.join('\n')}`);+console.log(`check-mutator-parity: ${mutators.length} project mutator(s), `+ + `${Object.keys(REACHED_VIA).length} reached through a named sibling, ${owed.length} owed —`+ + ' no NEW setting automation can reach and a person cannot.');diff --git a/tools/gates.mjs b/tools/gates.mjsindex 9e4211fdf..439f47466 100644--- a/tools/gates.mjs+++ b/tools/gates.mjs@@ -186,6 +186,8 @@ export const GATES = [{ id: 'import-settings', run: 'node tools/check-import-settings.mjs' },{ id: 'gizmo-coverage', run: 'node tools/check-gizmo-coverage.mjs', needs: 'editor' },{ id: 'lod-authoring', run: 'node tools/check-lod-authoring.mjs', needs: 'editor' },+ { id: 'decision-inventory', run: 'node tools/check-decision-inventory.mjs', needs: 'editor' },+ { id: 'mutator-parity', run: 'node tools/check-mutator-parity.mjs', needs: 'editor' },{ id: 'dirty-source', run: 'node tools/check-dirty-source.mjs', needs: 'editor' },{ id: 'path-sandbox', run: 'node tools/check-path-sandbox.mjs' },{ id: 'key-codes', run: 'node tools/check-key-codes.mjs' },diff --git a/tools/lib/runtimeDecisions.mjs b/tools/lib/runtimeDecisions.mjsnew file mode 100644index 000000000..d07a73b9e--- /dev/null+++ b/tools/lib/runtimeDecisions.mjs@@ -0,0 +1,153 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file runtimeDecisions.mjs — the choices the engine makes for a creator, and+ * whether the creator can see, understand and take them.+ *+ * A DECISION is a place where the runtime picks between outcomes a creator+ * cares about and could not have predicted from what they typed: which mesh a+ * view draws, which light gets a shadow tile, how much of a request a device+ * granted. Every one of them was authored by somebody who then had no way to+ * watch it happen.+ *+ * Three surfaces, and the gaps between them are the point:+ *+ * runtime the choice is made, and something records enough to explain it+ * editor a person can see the choice and the reason, where they authored it+ * agent the automation surface answers the same question+ *+ * runtime > editor the engine knows and nobody asks (worldResidencyReport)+ * agent > human automation can reach what a person cannot (spineVersion)+ * decision > explanation a real choice with nothing recording why (shadow atlas)+ *+ * Like contractFacts.mjs, every citation carries a `probe`, so an entry that+ * stops being true is a FINDING rather than documentation nobody reread. What+ * this file cannot do is discover a decision: nothing in a name marks one, and+ * a rule invented for the ones that do not exist yet is how a hand-written list+ * becomes the blind spot it was written to prevent (see check-gizmo-coverage).+ * New entries arrive by somebody deciding, which is why `owed` reads as work.+ */++/**+ * @typedef {{ path: string, dir?: boolean, probe: RegExp }} Cite+ * @typedef {{ has: true, cite: Cite } | { has: false, owed: string }} Surface+ */++export const DECISIONS = [+ {+ id: 'lod.selection',+ what: 'Which stand-in mesh a view draws for an object, and whether hysteresis is holding it.',+ kind: 'view-dependent',+ owner: { path: 'src/esengine/renderer/lod/LodSelection.hpp', probe: /inline u8 selectLevel/ },+ runtime: { has: true, cite: { path: 'src/esengine/renderer/lod/LodViewState.hpp', probe: /unbiased/ } },+ editor: { has: true, cite: { path: 'desktop/src/panels/inspector/componentDecorators.tsx', probe: /Renderer\.lodInspect\(/ } },+ agent: { has: true, cite: { path: 'desktop/shared/toolCatalog.mjs', probe: /'get_lod_decision'/ } },+ },+ {+ id: 'postfx.msaa',+ what: 'How much of a multisampling request the device granted.',+ kind: 'request-vs-capability',+ owner: { path: 'src/esengine/renderer/frame/PostProcessPipeline.cpp', probe: /scene_samples_ = std::clamp/ },+ runtime: { has: true, cite: { path: 'src/esengine/bindings/PostProcessBindings.cpp', probe: /postprocess_maxMsaaSamples/ } },+ editor: { has: true, cite: { path: 'desktop/src/settings/projectSettings.ts', probe: /msaaCapability\(\)/ } },+ agent: {+ has: false,+ owed: 'the effective count is on no tool; an agent tuning quality reads the request back and '+ + 'cannot tell whether the device granted it',+ },+ },+ {+ id: 'residency.cellDemand',+ what: 'Which cells exist right now, which source demanded each, and whether a prefetch was ready in time.',+ kind: 'view-dependent',+ owner: { path: 'sdk/src/residency/cells.ts', probe: /export function desiredResidency/ },+ // The whole explanation is already built, per cell, every frame.+ runtime: { has: true, cite: { path: 'sdk/src/residency/report.ts', probe: /prefetchHits/ } },+ editor: {+ has: false,+ owed: 'worldResidencyReport answers resident/prepared/loading per cell, prefetch hits and misses, '+ + 'and demand-to-resident latency — and has no consumer outside the SDK barrel. The runtime '+ + 'already knows; nothing asks',+ },+ agent: { has: false, owed: 'same report, same absence of a reader' },+ },+ {+ id: 'shadow.atlasAllocation',+ what: 'Which casters get shadow tiles, how many cascades the sun keeps, and who is denied.',+ kind: 'contended-resource',+ owner: { path: 'src/esengine/renderer/frame/RenderFrame.cpp', probe: /shadow_atlas_\.allocate\(want, kShadowCascadeCells\)/ },+ runtime: {+ has: false,+ owed: 'a caster the atlas cannot fit keeps plan[i].count == 0 and casts nothing. Tiles and draws '+ + 'are counted; DENIALS are not, and no log names the light. The light cap two hundred lines '+ + 'up warns — this one is silent, in the same file',+ },+ editor: { has: false, owed: 'a light stops casting and the viewport gives no reason' },+ agent: { has: false, owed: 'nothing to read' },+ },+ {+ id: 'light.cap',+ what: 'Which lights survive MAX_LIGHTS, and that the rest were dropped by brightness.',+ kind: 'contended-resource',+ owner: { path: 'src/esengine/renderer/frame/RenderFrame.cpp', probe: /lights exceed the \{\}-light cap/ },+ runtime: { has: true, cite: { path: 'src/esengine/renderer/frame/RenderFrame.cpp', probe: /ES_LOG_WARN\("collectLights/ } },+ editor: {+ has: false,+ owed: 'a warning in the log, attributed to no entity — the lights that went dark are not the '+ + 'ones the Outliner marks, so the reader has to guess which',+ },+ agent: { has: false, owed: 'not in get_diagnostics' },+ },+ {+ id: 'postfx.hdrFormat',+ what: 'Whether a linear-colour project got half-float intermediates or was quietly kept at LDR precision.',+ kind: 'request-vs-capability',+ owner: { path: 'src/esengine/renderer/frame/PostProcessPipeline.cpp', probe: /supportsFloatTargets\(\) \? GfxPixelFormat::RGBA16F/ },+ runtime: { has: false, owed: 'the fallback is taken inside interFormat() and recorded nowhere' },+ editor: {+ has: false,+ owed: 'Project Settings offers colorSpace: linear and never says the device could not carry it; '+ + 'bloom and tonemap then see values crushed at the 8-bit store',+ },+ agent: { has: false, owed: 'nothing to read' },+ },+ {+ id: 'texture.compressedFormat',+ what: 'Whether a cooked compressed texture was uploaded compressed, or decoded to full RGBA.',+ kind: 'request-vs-capability',+ owner: { path: 'sdk/src/asset/loaders/TextureLoader.ts', probe: /chooseEngineTargetFormat/ },+ runtime: {+ has: false,+ owed: 'the RGBA path is the else-branch of a capability test and counts nothing; a project that '+ + 'spent cook time on compression pays 4x the VRAM with no sign of it',+ },+ editor: { has: false, owed: 'the Import Settings row says what was asked for, never what was uploaded' },+ agent: { has: false, owed: 'resource_census counts bytes, not why they are that many' },+ },+ {+ id: 'project.spineVersion',+ what: 'Which Spine runtime the project bundles — a size and compatibility decision.',+ kind: 'agent-parity',+ owner: { path: 'desktop/src/project/ProjectStore.ts', probe: /async setSpineVersion/ },+ runtime: { has: true, cite: { path: 'pipeline/src/project/format.ts', probe: /spineVersion\?: string/ } },+ editor: {+ has: false,+ owed: 'ProjectStore.setSpineVersion has exactly one caller and it is the automation facade. The '+ + 'only mention in the UI is a read-only diagnostics line naming the version already running',+ },+ agent: { has: true, cite: { path: 'desktop/src/main.tsx', probe: /spineVersion: \(v\) => ProjectStore\.setSpineVersion/ } },+ },+ {+ id: 'project.audioConfig',+ what: 'Bus volumes, effects and duck rules — the project mixer.',+ kind: 'agent-parity',+ owner: { path: 'desktop/src/project/ProjectStore.ts', probe: /async setAudio/ },+ runtime: { has: true, cite: { path: 'pipeline/src/project/runtimeConfig.ts', probe: /audioConfig/ } },+ editor: {+ has: false,+ owed: 'setAudio has one caller and it is the automation facade; there is no Mixer panel and no '+ + 'project.audio.* settings row, so a person edits project.esproject by hand',+ },+ agent: { has: true, cite: { path: 'desktop/src/main.tsx', probe: /audio: \(v\) => ProjectStore\.setAudio/ } },+ },+];