aiecsjs 0.4.0 → 0.4.1

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 (35) hide show
  1. package/README_ZHTW.md +3 -3
  2. package/api.json +1 -1
  3. package/dist/{chunk-RHH5JA74.cjs → chunk-2CF2MNMH.cjs} +2 -2
  4. package/dist/{chunk-RHH5JA74.cjs.map → chunk-2CF2MNMH.cjs.map} +1 -1
  5. package/dist/{chunk-SJDWI3OZ.cjs → chunk-7NNM4PGP.cjs} +2 -2
  6. package/dist/{chunk-SJDWI3OZ.cjs.map → chunk-7NNM4PGP.cjs.map} +1 -1
  7. package/dist/{chunk-CTESP3XL.js → chunk-AW254W5F.js} +2 -2
  8. package/dist/{chunk-CTESP3XL.js.map → chunk-AW254W5F.js.map} +1 -1
  9. package/dist/{chunk-B777DQR7.cjs → chunk-XU3BVVCJ.cjs} +2 -2
  10. package/dist/{chunk-B777DQR7.cjs.map → chunk-XU3BVVCJ.cjs.map} +1 -1
  11. package/dist/{chunk-F7KNZ27O.js → chunk-YAHZHZNR.js} +2 -2
  12. package/dist/{chunk-F7KNZ27O.js.map → chunk-YAHZHZNR.js.map} +1 -1
  13. package/dist/{chunk-SQWZUC2Q.js → chunk-ZNLOJVCV.js} +2 -2
  14. package/dist/{chunk-SQWZUC2Q.js.map → chunk-ZNLOJVCV.js.map} +1 -1
  15. package/dist/commands.cjs +1 -1
  16. package/dist/commands.js +1 -1
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.d.cts +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/observers.cjs +1 -1
  22. package/dist/observers.js +1 -1
  23. package/dist/relations.cjs +1 -1
  24. package/dist/relations.js +1 -1
  25. package/dist/serialize.cjs +1 -1
  26. package/dist/serialize.js +1 -1
  27. package/dist/worker.cjs +1 -1
  28. package/dist/worker.js +1 -1
  29. package/llms-full.txt +13 -4
  30. package/package.json +5 -8
  31. package/CHANGELOG.md +0 -292
  32. package/STABILITY.md +0 -156
  33. package/STABILITY_ZHTW.md +0 -155
  34. package/docs/MIGRATION.md +0 -252
  35. package/docs/MIGRATION_ZHTW.md +0 -252
package/CHANGELOG.md DELETED
@@ -1,292 +0,0 @@
1
- # Changelog
2
-
3
- [English](CHANGELOG.md) | [繁體中文](CHANGELOG_ZHTW.md)
4
-
5
- All notable changes to `aiecsjs` are recorded in this file.
6
-
7
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
-
9
- ## [0.4.0] - 2026-05-29
10
-
11
- ### Added
12
-
13
- - **`getRelationData(world, source, rel, target)`**: new stable export on `aiecsjs/relations`. Returns the `data` payload attached via `addRelation`, or `undefined` when no such edge exists or no data was stored. Closes the write-only-data asymmetry present since 0.1: `addRelation` accepted a data argument but there was no corresponding public read path.
14
-
15
- ### Changed
16
-
17
- - **`aiecsjs/relations` graduated from experimental to stable.** The graph API (`defineRelation`, `addRelation`, `removeRelation`, `getRelationTargets`, `getRelationData`) and the built-in `ChildOf` relation are now frozen for the 1.x track. See [`STABILITY.md`](./STABILITY.md) for the full stability contract, including the raw slot-keying ABA semantic.
18
- - **`aiecsjs/worker` remains experimental.** True SAB shared-memory column aliasing is deferred; the worker sub-path continues on snapshot-copy semantics.
19
-
20
- ### Build & Tooling
21
-
22
- - **size-limit → `scripts/check-size.mjs`**: replaced the `size-limit` + `@size-limit/file` dev dependencies with a zero-dependency script that measures transitive chunk-closure gzip size per ESM entry. Required because `tsup splitting: true` (introduced in 0.3.1) makes each entry a thin re-export shell; the vanilla single-file measurement reported ~899 B for index when the true closure is ~7295 B. The new script resolves chunk imports recursively via BFS, sums per-file gzip, and enforces per-entry budgets.
23
- - **npm → pnpm**: migrated from `package-lock.json` to `pnpm-lock.yaml`. Added `"packageManager": "pnpm@9.12.3"` and `"publishConfig": { "access": "public" }`. CI and publish workflows updated to use `pnpm/action-setup@v6` + `pnpm install --frozen-lockfile`. `npm publish --provenance --access public` in the publish workflow is intentionally preserved (OIDC trusted publishing requires npm CLI, not pnpm publish).
24
- - **Coverage tests added + unreachable gaps documented**: new tests cover previously-unreachable paths in `serialize.ts`, `component.ts`, `query.ts`, and `loop.ts`. Thresholds updated to the honestly-achieved floor (statements 95 / branches 81 / functions 98 / lines 99). Unreachable-by-design gaps are now documented in `vitest.config.ts` with Chesterton rationale.
25
-
26
- ## [0.3.1] - 2026-05-29
27
-
28
- ### Fixed
29
-
30
- - **Packed EntityId signed-overflow for generation ≥ 128**: `createEntity` returned a negative number diverging from the unsigned value stored in archetype row arrays (`Uint32Array`), so query iteration (`runQuery`/`iterQuery`/`forEachEntity`) yielded an eid that failed `entityRow` lookups; `refOf`/`entityExists`/`deref` on a query-iterated high-generation entity misbehaved (`refOf` threw on a live entity). `packEid`/`packEntity` now normalise with `>>> 0`. No public-bundle behaviour change beyond the corrected eid representation (EntityId is opaque + in-memory-only).
31
- - **`toJSON` silently dropped high-generation entities** (gen ≥ 128 with default 8-bit generation): `toJSON` contained its own inline pack expression that produced a signed (negative) result, diverging from the unsigned key stored in `arch.entityRow`. The affected entity passed the archetype check but failed `entityRow.has()`, so it was omitted from every snapshot and `serializeWorld` call. Fixed by replacing the inline expression with the canonical `packEid` (which applies `>>> 0`). SPOT principle: one pack source of truth.
32
- - **Cross-subpath registry isolation** (`tsup splitting: false` → `splitting: true`): each compiled entry point (`dist/index.js`, `dist/serialize.js`, etc.) previously bundled its own private copy of `internal/world.ts`, including the module-scope `worldRegistry`. A world created via the core subpath was invisible to `serializeWorld`/`getRelationTargets`/`transferableSnapshot` imported from their respective subpaths, causing `world N is destroyed or unknown` at runtime. With `splitting: true`, esbuild extracts a shared chunk used by all entries; ESM and CJS are both verified by the new `scripts/check-dist-subpaths.mjs` smoke script.
33
- - **`getRelationTargets` returned raw index as `EntityId`** (gen always 0): `addRelation` stores the target as a raw slot index (`& indexMask`). The previous return path cast this raw index directly to `EntityId`, which is equivalent to a packed id with generation 0. For any target that had been recycled (gen > 0), callers received a stale id that failed `entityExists`, `entityRow` lookups, and component access. Fixed by re-packing each raw index against the current generation via `packEid` before returning.
34
- - **`resolveOptions` did not validate `indexBits + generationBits ≤ 32`**: the individual range checks (`indexBits ∈ [1, 24]`, `generationBits ∈ [0, 16]`) allowed combinations such as `indexBits=24, generationBits=16` (40 bits), where `gen << 24` silently overflowed and high-generation bits were lost. A sum check is now enforced with a clear error message. The `[Unreleased]` example corrected accordingly (`indexBits: 16, generationBits: 16` = 32 bits).
35
-
36
- ### Known Limitations
37
-
38
- - **`createDeltaSerializer.apply` with a recycled target world**: `apply` uses the raw entity index from the delta snapshot as the `EntityId` directly. When the target world has already recycled any of those slots (generation > 0), component operations silently act on the wrong packed id. This is a known limitation of the experimental delta API; the common usage (delta → a fresh gen-0 render-mirror world) is unaffected. A proper raw-index-to-packed-id mapping is planned for 0.4. Avoid `apply` against a world that has previously destroyed entities.
39
-
40
- ### Documentation
41
-
42
- - README / README_ZHTW updated to reflect the shipped 0.3.0 `EntityRef` API: the previous README still described EntityRef as "targeted for 0.3+" and `getEntityGeneration`/`packEntity` as experimental. Both files now correctly state EntityId has been packed since 0.3, and `EntityRef` / `refOf` / `deref` / `aliveRef` / `EntityNotAliveError` are all stable since 0.3.0. API table entries for these symbols added.
43
-
44
- ### Build & Tooling
45
-
46
- - Coverage gate: `@vitest/coverage-v8` installed and wired into `prepublishOnly` (replaces `npm run test`) and CI. Thresholds: statements 95 / branches 80 / functions 97 / lines 98 — the achievable bar on pristine source. The branch figure honours the `?? 0` / `noUncheckedIndexedAccess` idiom on TypedArray reads (nullish-fallback branches unreachable by design); thresholds are raised only by adding tests, never by stripping defensive guards or scattering `/* v8 ignore */`.
47
- - `fast-check` property tests (`tests/properties.test.ts`): pack/unpack round-trip invariant (asserts `e >= 0` to guard the P0 regression) and ABA-deref always-null invariant.
48
- - Dispose three-cycle tests, error-path tests, and observer handler-throw behaviour documented in `tests/world.test.ts` / `tests/observers.test.ts`.
49
- - `scripts/check-dist-subpaths.mjs` (`npm run verify:dist`): post-build smoke test that imports `createWorld`+`createEntity` from the core subpath and calls `serializeWorld`, `addRelation`/`getRelationTargets`, and `transferableSnapshot` from their respective subpaths for both ESM (`dist/*.js`) and CJS (`dist/*.cjs`). Wired into `prepublishOnly` (after `build`) and CI.
50
-
51
- ## [Unreleased]
52
-
53
- ### Planned for 0.4+
54
-
55
- - Add `pipeAsync` for async system composition.
56
- - Doc-test harness so README code blocks are mechanically verified.
57
- - Promote `aiecsjs/worker` to `stable` once true SAB shared-memory column aliasing is implemented.
58
- - Document the 8-bit generation wrap caveat in [STABILITY.md](./STABILITY.md): with the
59
- default `generationBits=8`, a single slot recycled 256 times wraps back to its
60
- starting generation, briefly re-opening the ABA window. Safe for v0.5 shmup
61
- workloads (~5000 frame to wrap a single slot at 60 fps × ~1k destroys); high-churn
62
- pools should set `createWorld({ indexBits: 16, generationBits: 16 })` (16 + 16 = 32 bits;
63
- 65 536 entities × 65 536 generations). See test
64
- [tests/ref.test.ts](./tests/ref.test.ts) `generation wrap` describe block.
65
-
66
- ## [0.3.0] - 2026-05-29
67
-
68
- ### Added (API)
69
-
70
- - **`EntityRef<T>`** — ABA-safe entity reference. `refOf(world, eid)` builds one;
71
- `deref(world, ref)` returns the entity id when still alive (generation match)
72
- or `null` otherwise; `aliveRef(world, ref)` is the boolean guard form. Phantom
73
- type `T` lets callers distinguish ref kinds (e.g. `EntityRef<'bullet'>`) without
74
- runtime cost. Refs are in-memory only — not serializable across worker / disk.
75
- - **`EntityNotAliveError`** — thrown by `refOf` when the entity is dead or invalid.
76
- `deref` / `aliveRef` never throw.
77
-
78
- ### Changed
79
-
80
- - **`EntityId` now packs index + generation** into a single 32-bit number
81
- `(generation << indexBits) | index` (default `indexBits=24, generationBits=8`).
82
- `EntityId` remains opaque per STABILITY contract; the layout is implementation
83
- detail. **Migration note**: do not compare `EntityId` numbers directly
84
- (`eid === 42` will break across slot recycles); use
85
- `getEntityIndex(eid)` for index comparison or `refOf(world, eid).id` for
86
- identity matching that survives slot reuse.
87
- - **`getEntityGeneration` / `packEntity` graduate to `stable`** (were `experimental`
88
- since 0.2.0). Both now return real values. These functions use default 24/8 bit
89
- layout; for non-default `createWorld({ indexBits, generationBits })`, use
90
- `EntityRef` and `deref` instead of manual unpacking.
91
-
92
- ### Fixed
93
-
94
- - **ABA bug on entity slot recycle**: previously `entityExists` and `isAliveInternal`
95
- only checked archetype membership; a stale `EntityId` pointing at a recycled slot
96
- would silently report alive. With packed generation + `deref` generation match,
97
- stale refs now correctly invalidate.
98
- - **`destroyEntity` generation wrap mask aligned with `options.generationBits`**
99
- (was hard-coded `& 0xffff`). The mask now correctly uses
100
- `state.options.generationMask`, fixing inconsistency for non-default
101
- `generationBits` values.
102
-
103
- ### Documentation
104
-
105
- - `onSet` JSDoc clarifies that `addComponent` does NOT trigger `onSet`, and
106
- direct writes to column views returned by `getComponent` (e.g. `col.x[idx] = 5`)
107
- also do NOT trigger `onSet`. Only `setComponent` on an already-present
108
- component fires the callback. Anti-pattern example included.
109
-
110
- ### Compatibility
111
-
112
- - `EntityId` layout change is **not** breaking at the type system level (opaque
113
- branded number), but consumers who relied on `eid === N` direct comparison
114
- will need to migrate (see Migration note above).
115
- - All existing `stable` exports unchanged.
116
- - `aiecsjs/worker` snapshot wire format unchanged (still uses raw indices).
117
- - `aiecsjs/serialize` wire format unchanged.
118
-
119
- ### Build & tooling
120
-
121
- - `VERSION` constant bumped to `0.3.0`.
122
-
123
- ## [0.2.1] - 2026-05-28
124
-
125
- ### Security
126
-
127
- - **Resolve two Dependabot moderate advisories** on the transitive dev-only graph by upgrading `vitest` 1.6.0 → 4.1.7. Adds `vite` 8.0.14 as a direct devDependency to satisfy vitest 4's peer range (`^6 || ^7 || ^8`). These are dev-only — runtime surface unchanged.
128
- - [GHSA-67mh-4wv8-2f99](https://github.com/advisories/GHSA-67mh-4wv8-2f99) `esbuild <=0.24.2` CORS development server data leak (fixed in 0.25.0).
129
- - [GHSA-4w7w-66w2-5vf9](https://github.com/advisories/GHSA-4w7w-66w2-5vf9) `vite <=6.4.1` path traversal in optimized deps `.map` handling (fixed in 6.4.2 / 7.3.2 / 8.0.5).
130
-
131
- ### Changed
132
-
133
- - **README opening unified across the ai*js family**: five-badge shields row (npm + CI + License + AI Generated + 繁體中文/English), one-line tagline as blockquote, ecosystem footer linking to the other two packages. Replaces the previous mixed style (text language switcher + 5 ad-hoc badges).
134
- - **`VERSION` constant bumped to 0.2.1** ([src/version.ts](src/version.ts)) so `world.version` and snapshot meta reflect this release.
135
-
136
- Runtime surface unchanged. Production bundles are byte-identical to 0.2.0.
137
-
138
- ## [0.2.0] - 2026-05-28
139
-
140
- ### Fixed (correctness + security)
141
-
142
- - **Prototype-pollution hardening in AoS `writeInitial`** ([src/internal/component.ts](src/internal/component.ts)): replaced `Object.assign(inst, initial)` with an explicit own-key copy that filters `__proto__` / `constructor` / `prototype`. Closes a path where a malicious `JSON.parse` payload reaching `addComponent` / `setComponent` / `fromJSON` / `deserializeWorld` could clobber the per-instance prototype.
143
- - **Observer dispatch is now safe against unsubscribe-during-iteration** ([src/observers.ts](src/observers.ts)): every `fire*` walks a snapshot of `state.observers` (`Array.from(...)` + `includes` guard) so a handler that calls its own returned disposer no longer skips sibling observers in the same fire round.
144
- - **`removeComponent` writes the new entity mask BEFORE firing observers** ([src/internal/component.ts](src/internal/component.ts)): query-targeted `remove` observers read `state.entityMask` to decide if the entity left the matching set; with the previous ordering the bit was still set during dispatch and the remove never fired. Brings `removeComponent` in line with `addComponent`'s "mutate then fire" order.
145
- - **`destroyEntity` now emits query-targeted `remove` events** ([src/observers.ts](src/observers.ts) `dispatchDestroyObservers`): in addition to per-component `onRemove`, the destroy hook now walks query observers and fires `remove` for any query the entity was matching pre-destroy. `wasMatch` is computed against a **snapshot of the pre-destroy mask** (not live `state.entityMask`) so a Phase 1 reentrant handler that mutates the entity's mask cannot suppress query removes in Phase 2 (regression caught by the round-2 review).
146
- - **`deserializeWorld` / `attachWorld` / `adoptSnapshot` binary length fields are bounds-checked** ([src/serialize.ts](src/serialize.ts)): `verLen` and `jsonLen` carry explicit `off + len <= bytes.length` assertions and a 64 MiB cap. `attachWorld` and `adoptSnapshot` ([src/worker.ts](src/worker.ts)) both carry SECURITY JSDocs that document the trust boundary expectation for SAB / TransferableSnapshot transports.
147
-
148
- ### Added (API)
149
-
150
- - **`disposeWorld(world)`** — new export that aliases `destroyWorld`. Aligns with the ai*js ecosystem `dispose()` convention (`aifsmjs.Runtime.dispose`, `aibridgejs.Bridge.dispose`). Prefer this name in new code; `destroyWorld` is retained as a deprecated alias and is scheduled for removal in 1.0.
151
- - **`{ signal?: AbortSignal }` on every observer**: `onAdd`, `onRemove`, `onSet`, and `observe` now accept an options object. When the signal aborts, the observer auto-unsubscribes. The returned unsubscribe function remains valid and idempotent. New exported type `ObserverOptions` documents the shape. This closes a long-running gap noted in the AI ecosystem audit — long-lived observers on user-controlled lifecycles (UI components, async pipelines) no longer require manual cleanup wiring.
152
-
153
- ### Changed (stability)
154
-
155
- - `getEntityGeneration` and `packEntity` re-classified from `stable` → `experimental` in `STABILITY.md` and `api.json`. In 0.1 these returned `0` / identity and that has not changed — the relabel honestly admits the deferred encoding work. Real values arrive when ABA-safe `EntityRef` lands.
156
- - `destroyWorld` re-classified from `stable` → `deprecated`. Behaviour unchanged; the deprecation is the API-naming alignment described above. Use `disposeWorld` instead.
157
-
158
- ### Documentation
159
-
160
- - `onSet` now carries a JSDoc and README paragraph clarifying that it is a **low-level mutation hook**, not a reactive value-predicate query. `enterQuery` / `exitQuery` continue to be the structural-change surface; reactive value tracking remains an explicit non-goal of the core.
161
- - README observer section gains an `AbortController`-based unsubscribe example.
162
-
163
- ### Build & tooling
164
-
165
- - Added [Biome](https://biomejs.dev/) lint + format (`biome.json`, `npm run lint`, `npm run format`). Brings parity with `aifsmjs` and `aibridgejs` and surfaces `noExplicitAny` warnings in legacy `src/internal/*` for follow-up cleanup.
166
- - Added `scripts/verify-exports.mjs` and the `npm run verify:exports` script; gates that every `package.json#exports` entry has a real file in `dist/`. Wired into `prepublishOnly`.
167
- - New `CONTRIBUTING.md` with the same shape used by `aifsmjs` (quick start, scope policy, release flow).
168
-
169
- ### Compatibility
170
-
171
- This release is **non-breaking at runtime**. All existing code that called `destroyWorld(world)`, registered observers without options, or read `getEntityGeneration` continues to work. The stability label change is documentation-only.
172
-
173
- ## [0.1.4] - 2026-05-28
174
-
175
- Docs-only release. Adds a cross-package integration section pointing at the `aibridgejs` JSON envelope contract; no source code changes.
176
-
177
- ### Documentation
178
-
179
- - README and README_ZHTW gained an "Integration with aibridgejs" section explaining that `bridge.call` / `bridge.emit` enforce JSON-safe payloads and silently drop `Date`, `Map`, `Set`, and class instances. The correct shape for streaming world state across the bridge is `toJSON(world)` (or `serializeWorld(world)` wrapped in a JSON envelope) before emitting, not `getComponent(...)` direct. See [aiecsjs README · Integration with aibridgejs](README.md#integration-with-aibridgejs).
180
- - Verified via the `aijs-integration-smoke` companion project: every named export from `aifsmjs@0.1.2`, `aibridgejs@0.1.3`, and `aiecsjs@0.1.3` can coexist in a single TypeScript module with zero identifier collisions under `tsc --noEmit --strict`.
181
-
182
- ## [0.1.3] - 2026-05-28
183
-
184
- A "no known silent bugs" release. Two correctness fixes, one hot-path allocation removal, and a small batch of style cleanups. No public API behaviour changes; `_getWorldState` is removed from the root export (was undocumented, unused by every sub-path, leading underscore signalled internal).
185
-
186
- ### Fixed
187
-
188
- - `aiecsjs/relations` relation data store no longer keys edges by `srcEid * worldCapacity + tgtEid`. After the world grew, the same `(src, tgt)` pair computed a different key and earlier entries became orphaned. Storage is now a nested `Map<srcEid, Map<tgtEid, data>>`, independent of capacity. The cleanup hook on `destroyEntity` was updated to match. v0.1 has no public retrieve API so the bug was user-invisible, but it would have surfaced the moment a retrieve surface landed in 0.2.
189
- - Per-world resolved query bitmasks no longer live on the module-global `QueryInternal`. When the same `defineQuery(...)` handle was used by two worlds whose component registration orders differed, the second world's per-world mask overwrote the first world's, and `runQuery` silently returned wrong rows in world A. Masks now live in `WorldState.queryMasks: Map<queryId, QueryMaskBundle>`, isolated per world. Regression test in `tests/multi-world.test.ts` exercises the cross-order scenario.
190
-
191
- ### Changed (internal)
192
-
193
- - Observer dispatch (`dispatchQueryObservers`) no longer allocates a temporary `Uint32Array` on every mutation event. Added `matchesEntityMask` helper in `bitmask.ts` that reads directly from `state.entityMask` at a base offset.
194
- - Shared bit-iteration extracted as `forEachSetBit(mask, base, words, fn)` in `bitmask.ts`. `clearAllEntityStorages` (`component.ts`) and `dispatchDestroyObservers` (`observers.ts`) now share that single implementation instead of inlining the same `word & -word` / `Math.clz32` pattern three times.
195
- - `state.generations[idx]` is written without an `as any` cast. `Uint8Array | Uint16Array` already supports indexed read/write.
196
- - Removed the `void oldCap` no-op from `growEntityArrays`.
197
- - Removed `_getWorldState` from the root `aiecsjs` export. Sub-paths (`aiecsjs/serialize`, `aiecsjs/worker`) already import `getWorldState` directly from the internal module; the leading-underscore root re-export had no consumer.
198
-
199
- ### Planned for 0.3
200
-
201
- - Promote `aiecsjs/relations` and `aiecsjs/worker` to `stable`.
202
- - Stabilize the network delta wire format.
203
- - Add automated benchmark suite committed to repo.
204
-
205
- ### Planned for 1.0
206
-
207
- - API freeze for the 1.x line.
208
- - Drop the experimental status label.
209
-
210
- ## [0.1.2] - 2026-05-28
211
-
212
- CI/CD smoke-test release. No user-facing source or behavioural changes since 0.1.1; this bump exists solely to validate the tag-triggered publish workflow (see `.github/workflows/publish.yml`) end-to-end against the npm registry with provenance attestation.
213
-
214
- ### Build & tooling
215
-
216
- - Confirmed that pushing a `v*.*.*` tag triggers `.github/workflows/publish.yml`, runs `prepublishOnly` (typecheck + tests + build + size budget), and publishes to npm with sigstore provenance.
217
-
218
- ## [0.1.1] - 2026-05-28
219
-
220
- The "documentation honesty + test backstop" release. No new public APIs; this is the version of 0.1.0 that ships with the public surface, the documentation, and the test coverage in agreement.
221
-
222
- ### Fixed
223
-
224
- - `destroyEntity` now clears the SoA columns and undefines the AoS slots that the destroyed entity owned. Previously only the entity mask was cleared, leaving stale data at the slot visible to debug snapshots and the serialisation path. Public `hasComponent` / query behaviour was already correct, so user-visible behaviour is unchanged; this closes the gap surfaced by the new `destroyEntity zeroes the destroyed entity’s SoA slot` test.
225
-
226
- ### Changed (docs hygiene)
227
-
228
- - README and STABILITY now describe `aiecsjs/worker` honestly as a snapshot-copy transport for 0.1; true shared columns remain a 0.2 target. README description and `package.json` description updated accordingly.
229
- - README clarifies that 0.1 `EntityId` is a bare slot index; internal generation is tracked for slot reuse but not encoded in the ID. ABA-safe `EntityRef` is on the 0.2 roadmap.
230
- - Sub-paths (`loop` / `commands` / `observers` / `serialize` / `worker` / `relations`) re-positioned in STABILITY as utility / adapter sub-paths; the root `aiecsjs` is the stable core surface. Tree-shakers should drop any sub-path the app does not import.
231
- - README adds a "What aiecsjs does NOT do" section listing explicit non-goals (system scheduler, render binding, physics, network replication, value-predicate reactive queries, prefab/inheritance).
232
- - Language version filenames renamed from `*.zh-TW.md` to `*_ZHTW.md`. Cross-links, `llms.txt`, and `package.json` `files` updated. Future language variants follow the same uppercase ISO 639-1 pattern.
233
- - Removed emoji from documentation prose (language switchers, status banners).
234
-
235
- ### Build & tooling
236
-
237
- - tsup build now runs with `minify: true`.
238
- - `size-limit` added as a dev dependency; per-export gzip budgets enforced via `npm run size`. Current measurements: core 5.49 kB, all sub-paths combined 12.6 kB gzip.
239
- - GitHub Actions CI workflow added: typecheck → test → build → size check on push and PR to `main`.
240
- - `prepublishOnly` now runs typecheck, tests, build, and the size budget gate before allowing publish.
241
-
242
- ### Tests
243
-
244
- - Test count increased from 84 to 140. New file `tests/internal/bitmask.test.ts` covers the multi-word bitmask helpers in isolation (27 cases including `matches` truth table). New file `tests/multi-world.test.ts` covers per-world isolation when the same component is reused. Existing files gained: naive linear-filter cross-check against `runQuery` for all clause combinations, archetype migration boundary path, query mid-traversal stability and lazy cache behaviour, SoA field clear assertions on both `removeComponent` and `destroyEntity`, SoA vector-length round trip, `maxEntities` / `maxComponents` boundary throws, observer fan-out for destroy across multiple components, `onSet` value content, query observer ignores unrelated mutation, relation source-side destroy cleanup, exclusive relation storage resize, worker `readOnly` rejects add / remove / destroy, serialize `options.components` filter, `onUnknownVersion: throw | best-effort` paths, command buffer placeholder resolves into a queryable entity, slot-reuse limitation made explicit. Loop tests rewritten on top of `vi.useFakeTimers({ toFake: ['performance', ...] })` for deterministic dt validation.
245
-
246
- ## [0.1.0] - 2026-05-27
247
-
248
- **Initial release.** All 50 documented exports across 7 modules are implemented and covered by 84 passing Vitest behaviour tests. Built with tsup to dual ESM + CJS, ships `.d.ts` declarations and source maps.
249
-
250
- ### Implementation notes
251
-
252
- - **Storage**: world-level TypedArray columns per SoA component field, sized to world capacity. Archetypes track entity membership (a `Uint32Array entities[]`) but do not own column data. This makes archetype migration O(1) and lets `Position.x[eid]` work directly without per-archetype indirection. Trade-off: iteration over archetypes reads columns at potentially non-contiguous offsets; for hot data this stays in L1.
253
- - **EntityId is unversioned in 0.1**: `EntityId` is the entity index. Generation is tracked internally for slot reuse but not encoded in the ID. `getEntityIndex` / `getEntityGeneration` / `packEntity` are identity helpers. ABA-safe references via a separate `EntityRef` type are planned for 0.2.
254
- - **Bitmask queries**: multi-word Uint32 masks, default 8 words (256 components). Per-world bit allocation, global component identity.
255
- - **Worker / SAB**: 0.1 implements snapshot-copy semantics (serialize-into-SAB on send, deserialize-on-adopt) rather than true shared-memory column aliasing. The API surface matches the documented contract; true shared columns ship in 0.2.
256
- - **Binary serialization**: a JSON payload wrapped in a 4-byte magic + version header. Compact binary column encoding is planned for 0.2.
257
-
258
- ### Added
259
-
260
- - `README.md` (English) and `README_ZHTW.md` (Traditional Chinese) with quick start, guide, API reference, performance notes, multi-threading guide, WebGPU interop section, serialization guide, migration guides, and "For AI Agents" section.
261
- - `llms.txt` — Jeremy Howard format AI-discovery file.
262
- - `llms-full.txt` — Single-file complete reference for LLM consumption.
263
- - `api.json` — Machine-readable export manifest with stability and `since` fields on every entry.
264
- - `STABILITY.md` and `STABILITY_ZHTW.md` — Per-export stability contract.
265
- - `docs/MIGRATION.md` and `docs/MIGRATION_ZHTW.md` — Migration guides from bitECS 0.4, miniplex 2.0, and ECSY.
266
-
267
- ### API surface declared
268
-
269
- - Core: `createWorld`, `destroyWorld`, `resetWorld`, `getWorldSize`, `getWorldCapacity`.
270
- - Entity: `createEntity`, `destroyEntity`, `entityExists`, `getEntityIndex`, `getEntityGeneration`, `packEntity`.
271
- - Component: `defineComponent`, `defineTag`, `defineObjectComponent`, `addComponent`, `removeComponent`, `hasComponent`, `getComponent`, `setComponent`, `Types`.
272
- - Query: `defineQuery`, `runQuery`, `forEachEntity`, `iterQuery`, `enterQuery`, `exitQuery`, `queryArchetypes` (experimental).
273
- - System: `pipe`.
274
- - Subpath `aiecsjs/loop`: `createLoop`.
275
- - Subpath `aiecsjs/commands`: `createCommandBuffer`, `flush`, `withCommandBuffer`.
276
- - Subpath `aiecsjs/observers`: `observe`, `onAdd`, `onRemove`, `onSet`.
277
- - Subpath `aiecsjs/serialize`: `serializeWorld`, `deserializeWorld`, `toJSON`, `fromJSON`, `createDeltaSerializer` (experimental).
278
- - Subpath `aiecsjs/worker` (experimental): `transferableSnapshot`, `adoptSnapshot`, `attachWorld`, `detachWorld`.
279
- - Subpath `aiecsjs/relations` (experimental, not implemented): `defineRelation`, `addRelation`, `removeRelation`, `getRelationTargets`, `ChildOf`.
280
- - Utility: `VERSION`, `IS_SAB_SUPPORTED`, `isWorld`, `isEntity`.
281
-
282
- ### Known limitations in 0.1
283
-
284
- - `aiecsjs/relations` and `aiecsjs/worker` are implemented but tagged experimental; API may shift.
285
- - Network delta wire format is JSON-based; binary patch format is planned for 0.2.
286
- - AoS components are main-thread only; cannot be shared via SharedArrayBuffer.
287
- - No automatic system scheduler / parallel execution.
288
- - Worker/SAB uses snapshot-copy in 0.1 rather than true shared-memory aliasing.
289
- - EntityId is unversioned; ABA-safe references arrive with `EntityRef` in 0.2.
290
-
291
- [Unreleased]: https://github.com/yshengliao/aiecsjs/compare/v0.1.0...HEAD
292
- [0.1.0]: https://github.com/yshengliao/aiecsjs/releases/tag/v0.1.0
package/STABILITY.md DELETED
@@ -1,156 +0,0 @@
1
- # Stability Contract
2
-
3
- [English](STABILITY.md) | [繁體中文](STABILITY_ZHTW.md)
4
-
5
- This document is the per-export stability promise for `aiecsjs`. It is the contract AI tools and human users can rely on when pinning versions and writing import paths.
6
-
7
- ## Policy
8
-
9
- aiecsjs follows [semver](https://semver.org/). Within the **0.x** series:
10
- - **`stable`** exports do not change in breaking ways across minor versions (e.g. 0.1 → 0.2).
11
- - **`experimental`** exports may change shape, name, or behaviour in any minor release. Pin the exact version if you depend on them.
12
- - **`internal`** is not part of the API. May change in any patch release. Do not import.
13
- - **`deprecated`** still works as documented but is scheduled for removal. The deprecation notice states the target version.
14
-
15
- At **1.0**, the `stable` surface freezes for the entire 1.x series.
16
-
17
- The full machine-readable export list lives in [`api.json`](./api.json), with the `stability` and `since` fields on every entry.
18
-
19
- ## By module
20
-
21
- The **root** entry (`aiecsjs`) is the stable core: world, entity, component, query, system. Everything under a sub-path (`aiecsjs/<name>`) is a **utility or adapter sub-path** — useful but non-essential, decoupled from the core, and importable a la carte. Tree-shakers should be able to drop any sub-path the application does not import.
22
-
23
- ### `aiecsjs` (root core)
24
-
25
- | Export | Stability | Since | Notes |
26
- |---|---|---|---|
27
- | `createWorld` | stable | 0.1.0 | |
28
- | `disposeWorld` | stable | 0.2.0 | Alias for `destroyWorld`; aligns with the ai*js ecosystem `dispose()` convention. Prefer this name in new code. |
29
- | `destroyWorld` | **deprecated** | 0.1.0 | Use `disposeWorld` instead. Scheduled for removal in 1.0. |
30
- | `resetWorld` | stable | 0.1.0 | |
31
- | `getWorldSize` | stable | 0.1.0 | |
32
- | `getWorldCapacity` | stable | 0.1.0 | |
33
- | `createEntity` | stable | 0.1.0 | |
34
- | `destroyEntity` | stable | 0.1.0 | |
35
- | `entityExists` | stable | 0.1.0 | |
36
- | `getEntityIndex` | stable | 0.1.0 | |
37
- | `getEntityGeneration` | stable | 0.3.0 | Returns real generation value packed into EntityId (default 24-bit index, 8-bit generation). For non-default `createWorld({ indexBits, generationBits })`, use `EntityRef` + `deref` instead. |
38
- | `packEntity` | stable | 0.3.0 | Packs index + generation into an EntityId using default 24/8 bit layout. For non-default bit sizes, use `EntityRef` + `deref` instead. |
39
- | `refOf` | stable | 0.3.0 | Throws `EntityNotAliveError` for dead entity. |
40
- | `deref` | stable | 0.3.0 | Returns null for stale / cross-world refs; never throws. |
41
- | `aliveRef` | stable | 0.3.0 | Boolean guard form of `deref`; never throws. |
42
- | `EntityRef` (type) | stable | 0.3.0 | In-memory only; not serializable. |
43
- | `EntityNotAliveError` | stable | 0.3.0 | Thrown only by `refOf`. |
44
- | `defineComponent` | stable | 0.1.0 | |
45
- | `defineTag` | stable | 0.1.0 | |
46
- | `defineObjectComponent` | stable | 0.1.0 | AoS components are main-thread only; not SAB-shareable. |
47
- | `addComponent` | stable | 0.1.0 | Argument order `(world, eid, component, init?)` is final. |
48
- | `removeComponent` | stable | 0.1.0 | |
49
- | `hasComponent` | stable | 0.1.0 | |
50
- | `getComponent` | stable | 0.1.0 | |
51
- | `setComponent` | stable | 0.1.0 | |
52
- | `Types` | stable | 0.1.0 | Constant map; field names are part of the contract. |
53
- | `defineQuery` | stable | 0.1.0 | |
54
- | `runQuery` | stable | 0.1.0 | |
55
- | `forEachEntity` | stable | 0.1.0 | |
56
- | `iterQuery` | stable | 0.1.0 | |
57
- | `enterQuery` | stable | 0.1.0 | |
58
- | `exitQuery` | stable | 0.1.0 | |
59
- | `queryArchetypes` | **experimental** | 0.1.0 | `Archetype.id` is opaque-internal; the shape of `Archetype` may grow. |
60
- | `pipe` | stable | 0.1.0 | |
61
- | `VERSION` | stable | 0.1.0 | |
62
- | `IS_SAB_SUPPORTED` | stable | 0.1.0 | |
63
- | `isWorld` | stable | 0.1.0 | |
64
- | `isEntity` | stable | 0.1.0 | |
65
-
66
- ### `aiecsjs/loop` (utility sub-path)
67
-
68
- Fixed-timestep accumulator loop. Drop this sub-path if you already drive frame updates yourself (PixiJS `Ticker`, requestAnimationFrame, server-side simulation).
69
-
70
- | Export | Stability | Since | Notes |
71
- |---|---|---|---|
72
- | `createLoop` | stable | 0.1.0 | |
73
-
74
- ### `aiecsjs/commands` (utility sub-path)
75
-
76
- Deferred structural mutations so systems can mutate world structure mid-iteration without invalidating queries.
77
-
78
- | Export | Stability | Since | Notes |
79
- |---|---|---|---|
80
- | `createCommandBuffer` | stable | 0.1.0 | |
81
- | `flush` | stable | 0.1.0 | |
82
- | `withCommandBuffer` | stable | 0.1.0 | |
83
-
84
- ### `aiecsjs/observers` (utility sub-path)
85
-
86
- Component lifecycle hooks. The core does not require observers; install this sub-path only if a system needs add/remove/set callbacks.
87
-
88
- | Export | Stability | Since | Notes |
89
- |---|---|---|---|
90
- | `observe` | stable | 0.1.0 | Accepts `{ signal?: AbortSignal }` since 0.2.0. |
91
- | `onAdd` | stable | 0.1.0 | Accepts `{ signal?: AbortSignal }` since 0.2.0. |
92
- | `onRemove` | stable | 0.1.0 | Accepts `{ signal?: AbortSignal }` since 0.2.0. |
93
- | `onSet` | stable | 0.1.0 | Low-level mutation hook; NOT a reactive value-predicate query. Accepts `{ signal?: AbortSignal }` since 0.2.0. |
94
-
95
- ### `aiecsjs/serialize` (utility sub-path)
96
-
97
- | Export | Stability | Since | Notes |
98
- |---|---|---|---|
99
- | `serializeWorld` | stable | 0.1.0 | Binary format includes a version stamp. |
100
- | `deserializeWorld` | stable | 0.1.0 | |
101
- | `toJSON` | stable | 0.1.0 | |
102
- | `fromJSON` | stable | 0.1.0 | |
103
- | `createDeltaSerializer` | **experimental** | 0.1.0 | Wire format may change before 1.0. |
104
-
105
- ### `aiecsjs/worker` (experimental adapter sub-path)
106
-
107
- The entire subpath is **experimental** in 0.x. **In 0.x the implementation is a snapshot-copy transport** — serialize the world into the SAB on send, deserialize into a fresh world on adopt. It is not true shared-memory column aliasing. The API surface matches the documented contract; true shared columns are targeted for **0.3+**. Snapshot layout and capability flags may change.
108
-
109
- | Export | Stability | Since | Notes |
110
- |---|---|---|---|
111
- | `transferableSnapshot` | experimental | 0.1.0 | |
112
- | `adoptSnapshot` | experimental | 0.1.0 | |
113
- | `attachWorld` | experimental | 0.1.0 | |
114
- | `detachWorld` | experimental | 0.1.0 | |
115
-
116
- ### `aiecsjs/relations` (stable sub-path since 0.4.0)
117
-
118
- The relations sub-path is **stable** as of 0.4.0. The graph API (`defineRelation`, `addRelation`, `removeRelation`, `getRelationTargets`, `getRelationData`) and the built-in `ChildOf` relation are frozen for the 1.x track.
119
-
120
- **Raw slot-keying ABA semantic:** relation storage keys edges by raw entity slot index (`entityId & indexMask`), not by the full packed EntityId (which includes a generation counter). If entity A is destroyed and a different entity B is later created occupying the same slot, B will inherit A's outgoing and incoming edges unless the destroy cleanup hook ran. The cleanup hook fires automatically when `destroyEntity` is called, so normal usage is safe. Callers holding cached EntityId values across destroy/recreate cycles should validate liveness with `entityExists` before reading relation data if ABA is a concern.
121
-
122
- | Export | Stability | Since | Notes |
123
- |---|---|---|---|
124
- | `defineRelation` | stable | 0.1.0 | |
125
- | `addRelation` | stable | 0.1.0 | |
126
- | `removeRelation` | stable | 0.1.0 | |
127
- | `getRelationTargets` | stable | 0.1.0 | |
128
- | `ChildOf` (constant) | stable | 0.1.0 | Built-in exclusive relation. |
129
- | `getRelationData` | stable | 0.4.0 | Returns the data payload attached via `addRelation`, or `undefined` if no such edge or no data was stored. Subject to the raw slot-keying ABA semantic described above. |
130
-
131
- ### `aiecsjs/internal/*`
132
-
133
- Everything under this prefix is **internal**. It exists for the implementation's own use and may break in any release. Do not import.
134
-
135
- ## Roadmap
136
-
137
- | Version | Focus | Stability shift |
138
- |---|---|---|
139
- | 0.1.x | Core surface (world, entity, component, query, system, loop, commands, observers, serialize) | Initial publish; all marked experimental at the package level but per-export stable where listed. |
140
- | 0.2.0 | Safety + alignment | Prototype-pollution hardening, observer `{ signal? }`, `disposeWorld` alias, `getEntityGeneration` / `packEntity` re-labelled experimental, `verify:llms` gate. See [CHANGELOG.md](./CHANGELOG.md#020---2026-05-28). |
141
- | 0.3.x | EntityRef + generation packing | ABA-safe; `getEntityGeneration` / `packEntity` → stable. |
142
- | 0.4.0 | Relations stabilisation | `aiecsjs/relations` graduated to stable; `getRelationData` added. `aiecsjs/worker` remains experimental (true SAB shared-memory columns deferred). |
143
- | 0.6+ | Multi-World snapshot diff transport (placeholder) | experimental — design TBD. |
144
- | 1.0.0 | API freeze | All `stable` exports frozen for 1.x. |
145
-
146
- ## How to check stability at runtime
147
-
148
- ```ts
149
- import { VERSION } from 'aiecsjs'
150
-
151
- if (VERSION.startsWith('0.')) {
152
- console.warn('aiecsjs is in pre-1.0; API surface may shift')
153
- }
154
- ```
155
-
156
- For programmatic introspection, parse [`api.json`](./api.json) — each entry has `stability` and `since` fields.
package/STABILITY_ZHTW.md DELETED
@@ -1,155 +0,0 @@
1
- # 穩定度契約
2
-
3
- [English](STABILITY.md) | [繁體中文](STABILITY_ZHTW.md)
4
-
5
- 本文件為 `aiecsjs` 中各匯出的穩定度承諾。AI 工具與人類使用者可依此契約來鎖定版本與書寫 import 路徑。
6
-
7
- ## 規範
8
-
9
- aiecsjs 遵循 [semver](https://semver.org/)。在 **0.x** 系列內:
10
- - **`stable`** 匯出於 minor 版本之間(例如 0.1 → 0.2)不會破壞性變更。
11
- - **`experimental`** 匯出可能在任何 minor 釋出時改變形狀、命名或行為。若有依賴請鎖定明確版本。
12
- - **`internal`** 不屬於 API 表面,可能在任何 patch 釋出時改變。請勿匯入。
13
- - **`deprecated`** 仍可正常運作但已排入移除計畫。棄用通知中會載明目標版本。
14
-
15
- 至 **1.0** 時,`stable` 表面為整個 1.x 系列凍結。
16
-
17
- 完整機器可讀的匯出清單位於 [`api.json`](./api.json),每筆都有 `stability` 與 `since` 欄位。
18
-
19
- ## 依模組分類
20
-
21
- **根目錄** entry(`aiecsjs`)為穩定核心:world、entity、component、query、system。任何 sub-path(`aiecsjs/<名稱>`)為 **utility 或 adapter sub-path** — 實用但非核心,與 core 解耦,可單獨 a la carte import。Tree-shaker 應能丟掉未引用的任何 sub-path。
22
-
23
- ### `aiecsjs`(根核心)
24
-
25
- | 匯出 | 穩定度 | 起始版本 | 備註 |
26
- |---|---|---|---|
27
- | `createWorld` | stable | 0.1.0 | |
28
- | `destroyWorld` | **deprecated** | 0.1.0 | 請改用 `disposeWorld`。預計於 1.0 移除。 |
29
- | `resetWorld` | stable | 0.1.0 | |
30
- | `getWorldSize` | stable | 0.1.0 | |
31
- | `getWorldCapacity` | stable | 0.1.0 | |
32
- | `createEntity` | stable | 0.1.0 | |
33
- | `destroyEntity` | stable | 0.1.0 | |
34
- | `entityExists` | stable | 0.1.0 | |
35
- | `getEntityIndex` | stable | 0.1.0 | |
36
- | `getEntityGeneration` | stable | 0.3.0 | 回傳 EntityId 中實際打包的 generation 值(預設 24-bit index、8-bit generation)。若使用非預設 `createWorld({ indexBits, generationBits })`,請改用 `EntityRef` + `deref`。 |
37
- | `packEntity` | stable | 0.3.0 | 使用預設 24/8 bit 佈局將 index + generation 打包為 EntityId。若使用非預設 bit 大小,請改用 `EntityRef` + `deref`。 |
38
- | `refOf` | stable | 0.3.0 | entity 不存活時拋出 `EntityNotAliveError`。 |
39
- | `deref` | stable | 0.3.0 | 對過期或跨 world 的 ref 回傳 null;絕不拋出錯誤。 |
40
- | `aliveRef` | stable | 0.3.0 | `deref` 的布林 guard 形式;絕不拋出錯誤。 |
41
- | `EntityRef`(type) | stable | 0.3.0 | 僅限記憶體內使用;不可序列化。 |
42
- | `EntityNotAliveError` | stable | 0.3.0 | 僅由 `refOf` 拋出。 |
43
- | `defineComponent` | stable | 0.1.0 | |
44
- | `defineTag` | stable | 0.1.0 | |
45
- | `defineObjectComponent` | stable | 0.1.0 | AoS 元件僅限主執行緒;不可跨 SAB 共享。 |
46
- | `addComponent` | stable | 0.1.0 | 參數順序 `(world, eid, component, init?)` 為最終定義。 |
47
- | `removeComponent` | stable | 0.1.0 | |
48
- | `hasComponent` | stable | 0.1.0 | |
49
- | `getComponent` | stable | 0.1.0 | |
50
- | `setComponent` | stable | 0.1.0 | |
51
- | `Types` | stable | 0.1.0 | 常數對應表;欄位名稱屬於契約。 |
52
- | `defineQuery` | stable | 0.1.0 | |
53
- | `runQuery` | stable | 0.1.0 | |
54
- | `forEachEntity` | stable | 0.1.0 | |
55
- | `iterQuery` | stable | 0.1.0 | |
56
- | `enterQuery` | stable | 0.1.0 | |
57
- | `exitQuery` | stable | 0.1.0 | |
58
- | `queryArchetypes` | **experimental** | 0.1.0 | `Archetype.id` 為 opaque 內部值;`Archetype` 的形狀可能增加欄位。 |
59
- | `pipe` | stable | 0.1.0 | |
60
- | `VERSION` | stable | 0.1.0 | |
61
- | `IS_SAB_SUPPORTED` | stable | 0.1.0 | |
62
- | `isWorld` | stable | 0.1.0 | |
63
- | `isEntity` | stable | 0.1.0 | |
64
-
65
- ### `aiecsjs/loop`(utility sub-path)
66
-
67
- 定步長累加迴圈。若應用層已自有 frame 更新驅動(PixiJS `Ticker`、requestAnimationFrame、伺服端模擬),可直接略過本 sub-path。
68
-
69
- | 匯出 | 穩定度 | 起始版本 | 備註 |
70
- |---|---|---|---|
71
- | `createLoop` | stable | 0.1.0 | |
72
-
73
- ### `aiecsjs/commands`(utility sub-path)
74
-
75
- 延後的結構性變更,讓系統可在迭代中安全改動 world 結構而不會讓查詢失效。
76
-
77
- | 匯出 | 穩定度 | 起始版本 | 備註 |
78
- |---|---|---|---|
79
- | `createCommandBuffer` | stable | 0.1.0 | |
80
- | `flush` | stable | 0.1.0 | |
81
- | `withCommandBuffer` | stable | 0.1.0 | |
82
-
83
- ### `aiecsjs/observers`(utility sub-path)
84
-
85
- 元件生命週期 hook。Core 不依賴 observers;只在系統需要 add/remove/set callback 時才安裝本 sub-path。
86
-
87
- | 匯出 | 穩定度 | 起始版本 | 備註 |
88
- |---|---|---|---|
89
- | `observe` | stable | 0.1.0 | |
90
- | `onAdd` | stable | 0.1.0 | |
91
- | `onRemove` | stable | 0.1.0 | |
92
- | `onSet` | stable | 0.1.0 | |
93
-
94
- ### `aiecsjs/serialize`(utility sub-path)
95
-
96
- | 匯出 | 穩定度 | 起始版本 | 備註 |
97
- |---|---|---|---|
98
- | `serializeWorld` | stable | 0.1.0 | 二進位格式包含版本戳記。 |
99
- | `deserializeWorld` | stable | 0.1.0 | |
100
- | `toJSON` | stable | 0.1.0 | |
101
- | `fromJSON` | stable | 0.1.0 | |
102
- | `createDeltaSerializer` | **experimental** | 0.1.0 | Wire format 在 1.0 之前可能改變。 |
103
-
104
- ### `aiecsjs/worker`(experimental adapter sub-path)
105
-
106
- 整個 subpath 在 0.x 為 **experimental**。**0.x 的實作為 snapshot-copy 傳輸**——傳送時將 world 序列化進 SAB,接收端反序列化成全新 world,並非真正的共享記憶體欄位 aliasing。API 表面符合文件契約;真正的共享欄位預計 **0.3+** 推出。Snapshot 佈局與能力旗標可能改變。
107
-
108
- | 匯出 | 穩定度 | 起始版本 | 備註 |
109
- |---|---|---|---|
110
- | `transferableSnapshot` | experimental | 0.1.0 | |
111
- | `adoptSnapshot` | experimental | 0.1.0 | |
112
- | `attachWorld` | experimental | 0.1.0 | |
113
- | `detachWorld` | experimental | 0.1.0 | |
114
-
115
- ### `aiecsjs/relations`(stable sub-path,自 0.4.0 起)
116
-
117
- relations sub-path 自 **0.4.0** 起為 **stable**。圖形 API(`defineRelation`、`addRelation`、`removeRelation`、`getRelationTargets`、`getRelationData`)以及內建 `ChildOf` 關係已為 1.x 凍結。
118
-
119
- **原始 slot 鍵值的 ABA 語意:** relation storage 以原始 entity slot index(`entityId & indexMask`)作為 edge 的鍵,而非包含 generation counter 的完整 packed EntityId。若 entity A 被銷毀後,另一個 entity B 在同一個 slot 被建立,B 將繼承 A 的所有進出 edge——除非 destroy cleanup hook 已執行(呼叫 `destroyEntity` 時會自動執行)。一般使用下是安全的;若在 destroy/recreate 循環中持有快取的 EntityId,讀取 relation data 前應以 `entityExists` 確認活躍狀態。
120
-
121
- | 匯出 | 穩定度 | 起始版本 | 備註 |
122
- |---|---|---|---|
123
- | `defineRelation` | stable | 0.1.0 | |
124
- | `addRelation` | stable | 0.1.0 | |
125
- | `removeRelation` | stable | 0.1.0 | |
126
- | `getRelationTargets` | stable | 0.1.0 | |
127
- | `ChildOf`(常數) | stable | 0.1.0 | 內建獨佔關係。 |
128
- | `getRelationData` | stable | 0.4.0 | 回傳透過 `addRelation` 附加的 data payload,或在 edge 不存在 / 未儲存 data 時回傳 `undefined`。受上述原始 slot 鍵值 ABA 語意影響。 |
129
-
130
- ### `aiecsjs/internal/*`
131
-
132
- 此前綴底下的所有內容皆為 **internal**。它存在於實作自用,可能在任何 release 變更。請勿匯入。
133
-
134
- ## Roadmap
135
-
136
- | 版本 | 焦點 | 穩定度變動 |
137
- |---|---|---|
138
- | 0.1.x | 核心表面(world、entity、component、query、system、loop、commands、observers、serialize) | 初次發佈;package 整體標 experimental,但各 export 表中列為 stable 者皆穩定。 |
139
- | 0.2.0 | 安全與生態對齊 | 原型污染強化、observer `{ signal? }`、`disposeWorld` 別名、`getEntityGeneration` / `packEntity` 改 experimental、`verify:llms` gate。詳見 [CHANGELOG.md](./CHANGELOG.md#020---2026-05-28)。 |
140
- | 0.3.x | EntityRef + generation packing | ABA-safe;`getEntityGeneration` / `packEntity` → stable。 |
141
- | 0.4.0 | Relations 穩定化 | `aiecsjs/relations` 升為 stable;新增 `getRelationData`。`aiecsjs/worker` 維持 experimental(真正 SAB 共享記憶體欄位延後)。 |
142
- | 0.6+ | Multi-World snapshot diff transport(佔位) | experimental — 設計待定。 |
143
- | 1.0.0 | API 凍結 | 所有 `stable` 匯出於 1.x 系列凍結。 |
144
-
145
- ## 在執行時檢查穩定度
146
-
147
- ```ts
148
- import { VERSION } from 'aiecsjs'
149
-
150
- if (VERSION.startsWith('0.')) {
151
- console.warn('aiecsjs 處於 1.0 前;API 表面可能調整')
152
- }
153
- ```
154
-
155
- 如需程式化檢視,請解析 [`api.json`](./api.json) — 每筆都有 `stability` 與 `since` 欄位。