Skip to content

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.

feat(ecs): the six symbols every game imports are frozen, and had to earn it

yhh54dfbd248f34
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 94c944dab..a20990b97 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 0 public · 17 beta · 1488 experimental · 1 deprecated
+Symbols: 6 public · 17 beta · 1482 experimental · 1 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -1773,7 +1773,7 @@ r: number
keyof ThemeColors
```
-## Commands — function @experimental
+## Commands — function @public
```
(): CommandsDescriptor
```
@@ -4512,7 +4512,7 @@ ComponentDef<MotorJointData>
(button: number) => Binding
```
-## Mut — function @experimental
+## Mut — function @public
```
<T extends AnyComponentDef>(component: T): MutWrapper<T>
```
@@ -5707,7 +5707,7 @@ y: number
z: number
```
-## Query — function @experimental
+## Query — function @public
```
<C extends QueryArg[]>(...components: C): QueryBuilder<C>
```
@@ -5964,7 +5964,7 @@ static prototype: ReplicationServer
(payload: Req) => Res | Promise<Res>
```
-## Res — function @experimental
+## Res — function @public
```
<T>(resource: ResourceDef<T>): ResDescriptor<T>
```
@@ -9424,7 +9424,7 @@ PluralSelector
<S extends object>(name: string, def: BehaviorDef<S>): ComponentDef<S>
```
-## defineComponent — function @experimental
+## defineComponent — function @public
```
<T extends object>(name: string, defaults: T, metadata?: ComponentMetadata): ComponentDef<T>
```
@@ -9444,7 +9444,7 @@ PluralSelector
<T>(defaultValue: T, name?: string): ResourceDef<T>
```
-## defineSystem — function @experimental
+## defineSystem — function @public
```
<P extends readonly SystemParam[]>(params: [...P], fn: (...args: InferParams<P>) => void | Promise<void>, options?: SystemOptions): SystemDef
```
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index abd2086e2..e81ab2a48 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.native
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 0 public · 22 beta · 1507 experimental · 1 deprecated
+Symbols: 6 public · 22 beta · 1501 experimental · 1 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -1773,7 +1773,7 @@ r: number
keyof ThemeColors
```
-## Commands — function @experimental
+## Commands — function @public
```
(): CommandsDescriptor
```
@@ -4525,7 +4525,7 @@ ComponentDef<MotorJointData>
(button: number) => Binding
```
-## Mut — function @experimental
+## Mut — function @public
```
<T extends AnyComponentDef>(component: T): MutWrapper<T>
```
@@ -5890,7 +5890,7 @@ y: number
z: number
```
-## Query — function @experimental
+## Query — function @public
```
<C extends QueryArg[]>(...components: C): QueryBuilder<C>
```
@@ -6157,7 +6157,7 @@ static prototype: ReplicationServer
(payload: Req) => Res | Promise<Res>
```
-## Res — function @experimental
+## Res — function @public
```
<T>(resource: ResourceDef<T>): ResDescriptor<T>
```
@@ -9657,7 +9657,7 @@ PluralSelector
<S extends object>(name: string, def: BehaviorDef<S>): ComponentDef<S>
```
-## defineComponent — function @experimental
+## defineComponent — function @public
```
<T extends object>(name: string, defaults: T, metadata?: ComponentMetadata): ComponentDef<T>
```
@@ -9677,7 +9677,7 @@ PluralSelector
<T>(defaultValue: T, name?: string): ResourceDef<T>
```
-## defineSystem — function @experimental
+## defineSystem — function @public
```
<P extends readonly SystemParam[]>(params: [...P], fn: (...args: InferParams<P>) => void | Promise<void>, options?: SystemOptions): SystemDef
```
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index f9e18d951..13e657634 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.node
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 0 public · 19 beta · 1487 experimental · 1 deprecated
+Symbols: 6 public · 19 beta · 1481 experimental · 1 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -1768,7 +1768,7 @@ r: number
keyof ThemeColors
```
-## Commands — function @experimental
+## Commands — function @public
```
(): CommandsDescriptor
```
@@ -4507,7 +4507,7 @@ ComponentDef<MotorJointData>
(button: number) => Binding
```
-## Mut — function @experimental
+## Mut — function @public
```
<T extends AnyComponentDef>(component: T): MutWrapper<T>
```
@@ -5702,7 +5702,7 @@ y: number
z: number
```
-## Query — function @experimental
+## Query — function @public
```
<C extends QueryArg[]>(...components: C): QueryBuilder<C>
```
@@ -5959,7 +5959,7 @@ static prototype: ReplicationServer
(payload: Req) => Res | Promise<Res>
```
-## Res — function @experimental
+## Res — function @public
```
<T>(resource: ResourceDef<T>): ResDescriptor<T>
```
@@ -9419,7 +9419,7 @@ PluralSelector
<S extends object>(name: string, def: BehaviorDef<S>): ComponentDef<S>
```
-## defineComponent — function @experimental
+## defineComponent — function @public
```
<T extends object>(name: string, defaults: T, metadata?: ComponentMetadata): ComponentDef<T>
```
@@ -9439,7 +9439,7 @@ PluralSelector
<T>(defaultValue: T, name?: string): ResourceDef<T>
```
-## defineSystem — function @experimental
+## defineSystem — function @public
```
<P extends readonly SystemParam[]>(params: [...P], fn: (...args: InferParams<P>) => void | Promise<void>, options?: SystemOptions): SystemDef
```
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index e9be7f731..71f14762f 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/minigame
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 0 public · 17 beta · 1508 experimental · 1 deprecated
+Symbols: 6 public · 17 beta · 1502 experimental · 1 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -1768,7 +1768,7 @@ r: number
keyof ThemeColors
```
-## Commands — function @experimental
+## Commands — function @public
```
(): CommandsDescriptor
```
@@ -4752,7 +4752,7 @@ ComponentDef<MotorJointData>
(button: number) => Binding
```
-## Mut — function @experimental
+## Mut — function @public
```
<T extends AnyComponentDef>(component: T): MutWrapper<T>
```
@@ -5947,7 +5947,7 @@ y: number
z: number
```
-## Query — function @experimental
+## Query — function @public
```
<C extends QueryArg[]>(...components: C): QueryBuilder<C>
```
@@ -6204,7 +6204,7 @@ static prototype: ReplicationServer
(payload: Req) => Res | Promise<Res>
```
-## Res — function @experimental
+## Res — function @public
```
<T>(resource: ResourceDef<T>): ResDescriptor<T>
```
@@ -9669,7 +9669,7 @@ PluralSelector
<S extends object>(name: string, def: BehaviorDef<S>): ComponentDef<S>
```
-## defineComponent — function @experimental
+## defineComponent — function @public
```
<T extends object>(name: string, defaults: T, metadata?: ComponentMetadata): ComponentDef<T>
```
@@ -9689,7 +9689,7 @@ PluralSelector
<T>(defaultValue: T, name?: string): ResourceDef<T>
```
-## defineSystem — function @experimental
+## defineSystem — function @public
```
<P extends readonly SystemParam[]>(params: [...P], fn: (...args: InferParams<P>) => void | Promise<void>, options?: SystemOptions): SystemDef
```
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index 1c153f9f2..31314ec90 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/wechat
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 0 public · 17 beta · 1498 experimental · 1 deprecated
+Symbols: 6 public · 17 beta · 1492 experimental · 1 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -1768,7 +1768,7 @@ r: number
keyof ThemeColors
```
-## Commands — function @experimental
+## Commands — function @public
```
(): CommandsDescriptor
```
@@ -4514,7 +4514,7 @@ ComponentDef<MotorJointData>
(button: number) => Binding
```
-## Mut — function @experimental
+## Mut — function @public
```
<T extends AnyComponentDef>(component: T): MutWrapper<T>
```
@@ -5709,7 +5709,7 @@ y: number
z: number
```
-## Query — function @experimental
+## Query — function @public
```
<C extends QueryArg[]>(...components: C): QueryBuilder<C>
```
@@ -5966,7 +5966,7 @@ static prototype: ReplicationServer
(payload: Req) => Res | Promise<Res>
```
-## Res — function @experimental
+## Res — function @public
```
<T>(resource: ResourceDef<T>): ResDescriptor<T>
```
@@ -9446,7 +9446,7 @@ PluralSelector
<S extends object>(name: string, def: BehaviorDef<S>): ComponentDef<S>
```
-## defineComponent — function @experimental
+## defineComponent — function @public
```
<T extends object>(name: string, defaults: T, metadata?: ComponentMetadata): ComponentDef<T>
```
@@ -9466,7 +9466,7 @@ PluralSelector
<T>(defaultValue: T, name?: string): ResourceDef<T>
```
-## defineSystem — function @experimental
+## defineSystem — function @public
```
<P extends readonly SystemParam[]>(params: [...P], fn: (...args: InferParams<P>) => void | Promise<void>, options?: SystemOptions): SystemDef
```
diff --git a/sdk/src/ecs/commands.ts b/sdk/src/ecs/commands.ts
index 1dc0ae9f8..84e285217 100644
--- a/sdk/src/ecs/commands.ts
+++ b/sdk/src/ecs/commands.ts
@@ -19,6 +19,15 @@ export interface CommandsDescriptor {
readonly _type: 'commands';
}
+/**
+ * Ask a system for a command queue: spawning, despawning and adding or removing
+ * components, recorded now and applied together.
+ *
+ * It flushes when the system returns — on a throw too, and after an async body's
+ * await — so structural edits never land mid-iteration of that system's queries.
+ *
+ * @public
+ */
export function Commands(): CommandsDescriptor {
return { _type: 'commands' };
}
diff --git a/sdk/src/ecs/component.ts b/sdk/src/ecs/component.ts
index 778b32b33..f99f0e1bf 100644
--- a/sdk/src/ecs/component.ts
+++ b/sdk/src/ecs/component.ts
@@ -322,6 +322,15 @@ function userComponents(): Map<string, AnyComponentDef> {
return getDefaultContext().componentRegistry as Map<string, AnyComponentDef>;
}
+/**
+ * Declare a component type from its name and the defaults every instance starts
+ * with. `name` is the identity a scene file stores, so it is what a saved entity
+ * is rebound by; defining the same name twice returns the first definition
+ * rather than replacing it, so a hot reload cannot orphan live entities.
+ *
+ * @throws if `name` is already taken by a built-in engine component.
+ * @public
+ */
export function defineComponent<T extends object>(
name: string,
defaults: T,
diff --git a/sdk/src/ecs/query.ts b/sdk/src/ecs/query.ts
index 6b024d133..7055b408d 100644
--- a/sdk/src/ecs/query.ts
+++ b/sdk/src/ecs/query.ts
@@ -19,6 +19,15 @@ export interface MutWrapper<T extends AnyComponentDef> {
readonly _component: T;
}
+/**
+ * Ask a {@link Query} for write access to `component`.
+ *
+ * An unwrapped engine component is yielded as a copy, so assigning to it changes
+ * nothing. Wrapped, the yielded data is written back to the world as iteration
+ * leaves the entity, and the component is marked changed for `Changed()`.
+ *
+ * @public
+ */
export function Mut<T extends AnyComponentDef>(component: T): MutWrapper<T> {
return { _type: 'mut', _component: component };
}
@@ -245,6 +254,15 @@ function createQueryDescriptor<C extends readonly QueryArg[]>(
// Query Factory
// =============================================================================
+/**
+ * Match the entities carrying every one of `components`, yielding the entity
+ * followed by each component's data in the order asked for.
+ *
+ * Read-only unless an argument is wrapped in {@link Mut}; narrow further with
+ * the builder's `with`/`without`, or per-component with `Added()`/`Changed()`.
+ *
+ * @public
+ */
export function Query<C extends QueryArg[]>(...components: C): QueryBuilder<C> {
return createQueryDescriptor(components);
}
diff --git a/sdk/src/ecs/resource.ts b/sdk/src/ecs/resource.ts
index 11999c697..c28ae6af9 100644
--- a/sdk/src/ecs/resource.ts
+++ b/sdk/src/ecs/resource.ts
@@ -42,6 +42,15 @@ export interface ResMutDescriptor<T> {
readonly _resource: ResourceDef<T>;
}
+/**
+ * Ask a system for read access to a resource: the world's single instance of
+ * `resource`, passed to the system body as the stored value itself.
+ *
+ * Not a copy — an object resource's fields are reachable through it. Replacing
+ * the value, and the change tick recording it, is what {@link ResMut} is for.
+ *
+ * @public
+ */
export function Res<T>(resource: ResourceDef<T>): ResDescriptor<T> {
return { _type: 'res', _resource: resource };
}
diff --git a/sdk/src/ecs/system.ts b/sdk/src/ecs/system.ts
index 264060834..dc04ac90f 100644
--- a/sdk/src/ecs/system.ts
+++ b/sdk/src/ecs/system.ts
@@ -112,6 +112,8 @@ export interface SystemOptions {
* the system is registered — including the top-level {@link addSystem}, which
* takes no options of its own. Edges given again at the registration site (or
* on the enclosing {@link SystemSet}) are added to these, not replaced.
+ *
+ * @public
*/
export function defineSystem<P extends readonly SystemParam[]>(
params: [...P],
diff --git a/tools/api-surface.mjs b/tools/api-surface.mjs
index 74e7265c0..654c3f341 100644
--- a/tools/api-surface.mjs
+++ b/tools/api-surface.mjs
@@ -380,7 +380,8 @@ if (fromDts) {
for (const [n, s] of rekinded.slice(0, 15)) console.error(` ${n}: ${s.kind} became ${emitted.get(n)}`);
}
- for (const e of errors) console.error(`POLICY ${e}`);
+ // One violation per symbol, not per entry that re-exports it.
+for (const e of new Set(errors)) console.error(`POLICY ${e}`);
if (broken || errors.length) {
console.error('\napi-surface: the declaration build is not shipping the documented surface.');
process.exit(1);
@@ -419,9 +420,10 @@ for (const [entryName, entryPath] of Object.entries(entryPaths)) {
}
}
-for (const e of errors) console.error(`POLICY ${e}`);
+// One violation per symbol, not per entry that re-exports it.
+for (const e of new Set(errors)) console.error(`POLICY ${e}`);
if (errors.length || drift) {
- console.error(`\napi-surface: ${errors.length} policy violation(s), ${drift} drifted snapshot(s).`);
+ console.error(`\napi-surface: ${new Set(errors).size} policy violation(s), ${drift} drifted snapshot(s).`);
console.error('Fix violations, then: node tools/api-surface.mjs --update');
process.exit(1);
}
diff --git a/tools/check-comment-style.mjs b/tools/check-comment-style.mjs
index 643b176ef..e7f33f0b1 100644
--- a/tools/check-comment-style.mjs
+++ b/tools/check-comment-style.mjs
@@ -107,9 +107,11 @@ function allLines() {
const COMMENT = /^\s*(\/\/|\*|\/\*)/;
/**
* Delimiters, section rules and structured tags carry no prose to measure.
- * `@details` is deliberately absent: it is where prose hides.
+ * `@details` is deliberately absent: it is where prose hides. The release tags
+ * are here because api-surface requires one on every frozen symbol, and a
+ * mandatory tag must not spend the budget meant for the contract.
*/
-const NOT_PROSE = /^\s*(\/\*+\s*$|\*\/|\/\/\s*[=-]+\s*$|\*\s*$|\/\/\s*$)|@(param|returns?|throws|example|see|code|endcode|file|brief|copyright|author|date)\b/;
+const NOT_PROSE = /^\s*(\/\*+\s*$|\*\/|\/\/\s*[=-]+\s*$|\*\s*$|\/\/\s*$)|@(param|returns?|throws|example|see|code|endcode|file|brief|copyright|author|date|public|beta|experimental|internal|deprecated)\b/;
/** A Doxygen file header states why the file exists; that is its job. */
const FILE_HEADER = /@file\b/;
diff --git a/tools/check-freeze-bar.mjs b/tools/check-freeze-bar.mjs
new file mode 100644
index 000000000..c5dc22b68
--- /dev/null
+++ b/tools/check-freeze-bar.mjs
@@ -0,0 +1,203 @@
+#!/usr/bin/env node
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file check-freeze-bar.mjs — what a symbol must have before it may be @public.
+ *
+ * @public says 1.0 is expected not to break it. A symbol nobody documented, no
+ * test pins and no game ever called cannot honour that: there is nothing holding
+ * its shape, so the first thing to move it moves the promise with it.
+ *
+ * So the tag has to be earned:
+ * documented a doc comment with prose, since the freeze is the moment the
+ * contract stops being readable from the implementation
+ * tested named by at least one SDK test
+ * exercised imported from 'esengine' by at least one golden project, so a
+ * real game's chain covers it (values only — a type carries no
+ * runtime behaviour for a package to certify, and the compiler
+ * already checks its shape everywhere it is used)
+ *
+ * A symbol that cannot meet the bar and should still be frozen goes in
+ * {@link EXEMPT} with a reason, the same bargain goldenProjects strikes: the
+ * hole stays visible instead of passing for coverage.
+ *
+ * node tools/check-freeze-bar.mjs
+ */
+import { readFileSync, readdirSync, existsSync } from 'node:fs';
+import { join, relative } from 'node:path';
+import { ROOT, SDK, ETC, ts, ENTRIES, createSdkProgram } from './lib/sdkProgram.mjs';
+import { parseSnapshot } from './lib/apiSnapshot.mjs';
+import { GOLDEN, projectDir } from './goldenProjects.mjs';
+
+/** Frozen symbols that cannot meet part of the bar, and why. */
+export const EXEMPT = {};
+
+/** Snapshot kinds that a game calls at runtime; the rest are shapes. */
+const VALUE_KINDS = new Set(['class', 'enum', 'function', 'const', 'value', 'namespace']);
+
+// ---------------------------------------------------------------------------
+// What the snapshots froze
+// ---------------------------------------------------------------------------
+
+/** Every @public symbol across every entry, as `name -> kind`. */
+function frozenSymbols() {
+ const out = new Map();
+ for (const entryName of Object.keys(ENTRIES)) {
+ const file = join(ETC, `${entryName}.api.md`);
+ if (!existsSync(file)) continue;
+ for (const [name, s] of parseSnapshot(readFileSync(file, 'utf8'))) {
+ if (s.tier === 'public') out.set(name, s.kind);
+ }
+ }
+ return out;
+}
+
+// ---------------------------------------------------------------------------
+// Documented
+// ---------------------------------------------------------------------------
+
+/** The node a doc comment attaches to — for `export const x`, the statement. */
+function docAnchor(decl) {
+ let node = decl;
+ if (ts.isVariableDeclaration(node) && node.parent?.parent) node = node.parent.parent;
+ return node;
+}
+
+/**
+ * A leading `/** *\/` block carrying at least one line that is not a tag.
+ * Read from source text rather than the AST helpers so it says the same thing
+ * about a declaration however TypeScript reshuffles its JSDoc accessors.
+ */
+function hasDocProse(decl) {
+ const node = docAnchor(decl);
+ const text = node.getSourceFile().getFullText();
+ for (const range of ts.getLeadingCommentRanges(text, node.getFullStart()) ?? []) {
+ const comment = text.slice(range.pos, range.end);
+ if (!comment.startsWith('/**')) continue;
+ const prose = comment.split('\n')
+ .map((l) => l.replace(/^\s*\/?\*+\/?/, '').replace(/\*\/\s*$/, '').trim())
+ .filter((l) => l && !l.startsWith('@'));
+ if (prose.length) return true;
+ }
+ return false;
+}
+
+// ---------------------------------------------------------------------------
+// Tested / exercised
+// ---------------------------------------------------------------------------
+
+function walk(dir, onFile, skip) {
+ let entries;
+ try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return; }
+ for (const e of entries) {
+ const p = join(dir, e.name);
+ if (skip(p, e.name)) continue;
+ if (e.isDirectory()) walk(p, onFile, skip);
+ else onFile(p);
+ }
+}
+
+/** Every identifier named anywhere in the SDK's tests. */
+function testedIdentifiers() {
+ const seen = new Set();
+ const skip = (p, name) => name === 'node_modules' || name === 'dist';
+ walk(join(SDK, 'src'), collect, skip);
+ walk(join(SDK, 'tests'), collect, skip);
+ function collect(p) {
+ if (!/\.test\.ts$/.test(p)) return;
+ for (const id of readFileSync(p, 'utf8').match(/[A-Za-z_$][\w$]*/g) ?? []) seen.add(id);
+ }
+ return seen;
+}
+
+const ESENGINE_IMPORT = /import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*['"]esengine['"]/g;
+
+/** Symbols each golden project imports from 'esengine', as `name -> [projectId]`. */
+function exercisedByGolden() {
+ const out = new Map();
+ for (const g of GOLDEN) {
+ const dir = projectDir(g.id);
+ if (!existsSync(dir)) continue;
+ walk(dir, (p) => {
+ if (!/\.ts$/.test(p) || /\.d\.ts$/.test(p)) return;
+ const src = readFileSync(p, 'utf8');
+ for (const m of src.matchAll(ESENGINE_IMPORT)) {
+ for (const raw of m[1].split(',')) {
+ const name = raw.trim().replace(/^type\s+/, '').split(/\s+as\s+/)[0].trim();
+ if (!name) continue;
+ if (!out.has(name)) out.set(name, new Set());
+ out.get(name).add(g.id);
+ }
+ }
+ }, (p, name) => name === '.esengine' || name === 'node_modules' || name === 'dist');
+ }
+ return out;
+}
+
+// ---------------------------------------------------------------------------
+// Report
+// ---------------------------------------------------------------------------
+
+const frozen = frozenSymbols();
+if (frozen.size === 0) {
+ console.log('check-freeze-bar: nothing is @public yet — no promise to hold up.');
+ process.exit(0);
+}
+
+const { program, checker } = createSdkProgram();
+const declarations = new Map();
+for (const entryPath of Object.values(ENTRIES)) {
+ const sourceFile = program.getSourceFile(join(SDK, entryPath));
+ const moduleSymbol = sourceFile && checker.getSymbolAtLocation(sourceFile);
+ if (!moduleSymbol) continue;
+ for (const symbol of checker.getExportsOfModule(moduleSymbol)) {
+ if (declarations.has(symbol.name) || !frozen.has(symbol.name)) continue;
+ const resolved = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
+ const decl = resolved.declarations?.[0];
+ if (decl) declarations.set(symbol.name, decl);
+ }
+}
+
+const tested = testedIdentifiers();
+const exercised = exercisedByGolden();
+
+const failures = [];
+for (const [name, kind] of [...frozen].sort()) {
+ const excuse = EXEMPT[name];
+ const missing = [];
+ const decl = declarations.get(name);
+ if (!decl) {
+ failures.push({ name, say: 'is @public in a snapshot but resolves to no declaration' });
+ continue;
+ }
+ if (!hasDocProse(decl)) missing.push('undocumented');
+ if (!tested.has(name)) missing.push('named by no SDK test');
+ if (VALUE_KINDS.has(kind) && !exercised.has(name)) missing.push('called by no golden project');
+ if (!missing.length) {
+ if (excuse) failures.push({ name, say: `meets the bar but is still listed in EXEMPT — drop the excuse` });
+ continue;
+ }
+ if (excuse) continue;
+ const where = relative(ROOT, decl.getSourceFile().fileName).replace(/\\/g, '/');
+ failures.push({ name, say: `${missing.join(', ')}`, where });
+}
+
+for (const [name, why] of Object.entries(EXEMPT)) {
+ if (!frozen.has(name)) failures.push({ name, say: `is exempt from the freeze bar but is not @public — ${why}` });
+}
+
+const values = [...frozen].filter(([, k]) => VALUE_KINDS.has(k)).length;
+if (failures.length === 0) {
+ const exempt = Object.keys(EXEMPT).length;
+ console.log(`check-freeze-bar: ${frozen.size} @public symbol(s) (${values} called at runtime) — documented, tested, exercised.`);
+ for (const [name, why] of Object.entries(EXEMPT)) console.log(` exempt: ${name} — ${why}`);
+ if (exempt) console.log(` ${exempt} exemption(s) — each is a symbol the corpus does not hold up.`);
+ process.exit(0);
+}
+
+for (const f of failures.sort((a, b) => (a.name < b.name ? -1 : 1))) {
+ console.error(` ${f.name} — ${f.say}${f.where ? ` (${f.where})` : ''}`);
+}
+console.error(`\ncheck-freeze-bar: ${failures.length} symbol(s) carry @public without earning it.`);
+console.error('Document it, pin it with a test, use it in a golden project — or drop the tag.');
+process.exit(1);
diff --git a/tools/gates.mjs b/tools/gates.mjs
index bc2ea76ef..ab7a802f6 100644
--- a/tools/gates.mjs
+++ b/tools/gates.mjs
@@ -37,6 +37,7 @@ export const GATES = [
// Reads the snapshot the gate above just proved current, against the one the
// last release tag shipped — drift says the surface moved, this says a promise did.
{ id: 'api-surface-baseline', run: 'node tools/api-surface.mjs --check-baseline' },
+ { id: 'freeze-bar', run: 'node tools/check-freeze-bar.mjs' },
// Everything below reads what this emits: the declaration snapshot, the
// editor's own type-check and the examples all resolve `esengine` from dist.
{ id: 'sdk-build', run: 'pnpm --filter ./sdk build' },