@its-not-rocket-science/ananke 0.1.69 → 0.5.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 (165) hide show
  1. package/CHANGELOG.md +254 -0
  2. package/README.md +150 -432
  3. package/STABLE_API.md +113 -490
  4. package/conformance/README.md +46 -44
  5. package/conformance/lockstep-sequence.json +395 -395
  6. package/conformance/phase-order.json +21 -0
  7. package/conformance/replay-parity.json +65 -65
  8. package/conformance/state-hash-regression.json +39 -0
  9. package/conformance/state-hash.json +23 -22
  10. package/dist/src/conformance.d.ts +8 -2
  11. package/dist/src/content/index.d.ts +3 -0
  12. package/dist/src/content/index.js +2 -0
  13. package/dist/src/content/injector.d.ts +19 -0
  14. package/dist/src/content/injector.js +61 -0
  15. package/dist/src/content/loader.d.ts +3 -0
  16. package/dist/src/content/loader.js +170 -0
  17. package/dist/src/content/types.d.ts +56 -0
  18. package/dist/src/content/types.js +1 -0
  19. package/dist/src/content/validator.d.ts +6 -0
  20. package/dist/src/content/validator.js +14 -0
  21. package/dist/src/content-pack.d.ts +3 -2
  22. package/dist/src/content-pack.js +205 -10
  23. package/dist/src/data-governance.d.ts +73 -0
  24. package/dist/src/data-governance.js +188 -0
  25. package/dist/src/debug.d.ts +6 -0
  26. package/dist/src/debug.js +9 -0
  27. package/dist/src/determinism.d.ts +12 -0
  28. package/dist/src/determinism.js +93 -0
  29. package/dist/src/dialogue.d.ts +41 -0
  30. package/dist/src/dialogue.js +113 -2
  31. package/dist/src/economy.d.ts +97 -3
  32. package/dist/src/economy.js +191 -37
  33. package/dist/src/history/autosave.d.ts +19 -0
  34. package/dist/src/history/autosave.js +98 -0
  35. package/dist/src/history/timetravel.d.ts +28 -0
  36. package/dist/src/history/timetravel.js +61 -0
  37. package/dist/src/index.d.ts +19 -31
  38. package/dist/src/index.js +20 -38
  39. package/dist/src/model3d.js +63 -2
  40. package/dist/src/narrative/combat-logger.d.ts +25 -0
  41. package/dist/src/narrative/combat-logger.js +97 -0
  42. package/dist/src/narrative/plausibility.d.ts +30 -0
  43. package/dist/src/narrative/plausibility.js +70 -0
  44. package/dist/src/narrative-layer.d.ts +2 -0
  45. package/dist/src/narrative-layer.js +2 -0
  46. package/dist/src/navigation/causal-chain.d.ts +26 -0
  47. package/dist/src/navigation/causal-chain.js +74 -0
  48. package/dist/src/netcode.d.ts +1 -1
  49. package/dist/src/netcode.js +1 -1
  50. package/dist/src/performance/adaptive-tick.d.ts +23 -0
  51. package/dist/src/performance/adaptive-tick.js +50 -0
  52. package/dist/src/plugins/loader.d.ts +23 -0
  53. package/dist/src/plugins/loader.js +86 -0
  54. package/dist/src/plugins/registry.d.ts +11 -0
  55. package/dist/src/plugins/registry.js +28 -0
  56. package/dist/src/plugins/types.d.ts +31 -0
  57. package/dist/src/plugins/types.js +7 -0
  58. package/dist/src/replay.js +5 -2
  59. package/dist/src/scenario.js +2 -1
  60. package/dist/src/serialization/binary.d.ts +5 -0
  61. package/dist/src/serialization/binary.js +193 -0
  62. package/dist/src/session.d.ts +115 -0
  63. package/dist/src/session.js +228 -0
  64. package/dist/src/sim/ai/decide.js +1 -1
  65. package/dist/src/sim/ai/personality.js +2 -2
  66. package/dist/src/sim/bodyplan.d.ts +30 -0
  67. package/dist/src/sim/context.d.ts +2 -0
  68. package/dist/src/sim/kernel.js +80 -1294
  69. package/dist/src/sim/normalization.d.ts +12 -0
  70. package/dist/src/sim/normalization.js +92 -0
  71. package/dist/src/sim/resolvers/attack-resolver.d.ts +30 -0
  72. package/dist/src/sim/resolvers/attack-resolver.js +310 -0
  73. package/dist/src/sim/resolvers/capability-resolver.d.ts +15 -0
  74. package/dist/src/sim/resolvers/capability-resolver.js +270 -0
  75. package/dist/src/sim/resolvers/grapple-resolver.d.ts +28 -0
  76. package/dist/src/sim/resolvers/grapple-resolver.js +70 -0
  77. package/dist/src/sim/resolvers/shoot-resolver.d.ts +27 -0
  78. package/dist/src/sim/resolvers/shoot-resolver.js +212 -0
  79. package/dist/src/sim/resolvers/treat-resolver.d.ts +16 -0
  80. package/dist/src/sim/resolvers/treat-resolver.js +77 -0
  81. package/dist/src/sim/step/apply/intents.d.ts +6 -0
  82. package/dist/src/sim/step/apply/intents.js +83 -0
  83. package/dist/src/sim/step/kernel-pipeline.d.ts +9 -0
  84. package/dist/src/sim/step/kernel-pipeline.js +15 -0
  85. package/dist/src/sim/step/phases/capability-phase.d.ts +8 -0
  86. package/dist/src/sim/step/phases/capability-phase.js +65 -0
  87. package/dist/src/sim/step/phases/cooldowns-phase.d.ts +3 -0
  88. package/dist/src/sim/step/phases/cooldowns-phase.js +37 -0
  89. package/dist/src/sim/step/phases/prepare-phase.d.ts +10 -0
  90. package/dist/src/sim/step/phases/prepare-phase.js +33 -0
  91. package/dist/src/sim/step/pipeline.d.ts +2 -0
  92. package/dist/src/sim/step/pipeline.js +15 -0
  93. package/dist/src/sim/step/resolvers/impact-resolver.d.ts +9 -0
  94. package/dist/src/sim/step/resolvers/impact-resolver.js +55 -0
  95. package/dist/src/sim/step/world-phases.d.ts +7 -0
  96. package/dist/src/sim/step/world-phases.js +15 -0
  97. package/dist/src/sim/step/world-step-context.d.ts +23 -0
  98. package/dist/src/sim/step/world-step-context.js +1 -0
  99. package/dist/src/sim/systemic-toxicology.js +1 -1
  100. package/dist/src/sim/team.js +2 -2
  101. package/dist/src/sim/testing.js +4 -3
  102. package/dist/src/sim/toxicology.d.ts +1 -1
  103. package/dist/src/sim/toxicology.js +1 -1
  104. package/dist/src/sim/world.d.ts +17 -24
  105. package/dist/src/snapshot.js +3 -6
  106. package/dist/src/tier2.d.ts +19 -0
  107. package/dist/src/tier2.js +21 -0
  108. package/dist/src/tier3.d.ts +10 -0
  109. package/dist/src/tier3.js +12 -0
  110. package/dist/src/version.d.ts +6 -0
  111. package/dist/src/version.js +8 -0
  112. package/dist/src/wasm/bridge.d.ts +14 -0
  113. package/dist/src/wasm/bridge.js +84 -0
  114. package/dist/src/wasm-kernel.d.ts +2 -0
  115. package/dist/src/wasm-kernel.js +1 -0
  116. package/dist/src/world-evolution-backend/engine.d.ts +4 -0
  117. package/dist/src/world-evolution-backend/engine.js +347 -0
  118. package/dist/src/world-evolution-backend/host-schema.d.ts +145 -0
  119. package/dist/src/world-evolution-backend/host-schema.js +375 -0
  120. package/dist/src/world-evolution-backend/index.d.ts +1 -0
  121. package/dist/src/world-evolution-backend/index.js +1 -0
  122. package/dist/src/world-evolution-backend/open-world-host-adapter.d.ts +96 -0
  123. package/dist/src/world-evolution-backend/open-world-host-adapter.js +208 -0
  124. package/dist/src/world-evolution-backend/profiles.d.ts +4 -0
  125. package/dist/src/world-evolution-backend/profiles.js +136 -0
  126. package/dist/src/world-evolution-backend/public.d.ts +11 -0
  127. package/dist/src/world-evolution-backend/public.js +7 -0
  128. package/dist/src/world-evolution-backend/reproducibility.d.ts +8 -0
  129. package/dist/src/world-evolution-backend/reproducibility.js +35 -0
  130. package/dist/src/world-evolution-backend/timeline.d.ts +6 -0
  131. package/dist/src/world-evolution-backend/timeline.js +337 -0
  132. package/dist/src/world-evolution-backend/types.d.ts +138 -0
  133. package/dist/src/world-evolution-backend/types.js +1 -0
  134. package/dist/src/world-evolution-host-backend.d.ts +51 -0
  135. package/dist/src/world-evolution-host-backend.js +97 -0
  136. package/dist/src/world-evolution.d.ts +201 -0
  137. package/dist/src/world-evolution.js +543 -0
  138. package/dist/src/world-factory.js +2 -1
  139. package/dist/tools/pack-cli.js +55 -2
  140. package/docs/bridge-contract.md +140 -332
  141. package/docs/completion-evidence-dashboard.md +63 -0
  142. package/docs/host-contract.md +86 -310
  143. package/docs/host-world-evolution-schema.md +155 -0
  144. package/docs/integration-primer.md +29 -22
  145. package/docs/migration-monolith-to-modular.md +102 -120
  146. package/docs/package-architecture.md +116 -323
  147. package/docs/plugins/README.md +42 -0
  148. package/docs/plugins/hooks.md +22 -0
  149. package/docs/plugins/publishing.md +29 -0
  150. package/docs/plugins/security-model.md +273 -0
  151. package/docs/project-overview.md +30 -30
  152. package/docs/release-dashboard.md +47 -0
  153. package/docs/session-api.md +127 -0
  154. package/docs/stable-api-manifest.json +52 -0
  155. package/docs/trust-dashboard.md +37 -0
  156. package/docs/versioning.md +256 -245
  157. package/docs/wire-protocol.md +140 -209
  158. package/docs/world-evolution-backend.md +200 -0
  159. package/docs/world-evolution-engine.md +150 -0
  160. package/docs/world-evolution-host-backend.md +70 -0
  161. package/docs/world-evolution-orchestration.md +248 -0
  162. package/package.json +125 -6
  163. package/schema/content-pack.schema.json +85 -0
  164. package/schema/plugin.schema.json +57 -0
  165. package/schema/world-evolution-input.schema.json +196 -0
package/STABLE_API.md CHANGED
@@ -1,490 +1,113 @@
1
- # Ananke — Stable API Reference
2
-
3
- This document defines the three stability tiers for Ananke's public API surface.
4
- See [`docs/versioning.md`](docs/versioning.md) for the full versioning policy, upgrade
5
- cadence, and commit-hash pinning guide.
6
- See [`docs/core-guarantees.md`](docs/core-guarantees.md) for the full determinism contract,
7
- validation philosophy, benchmark methodology, and known limits.
8
-
9
- ---
10
-
11
- ## Versioning policy (summary)
12
-
13
- Ananke uses **semantic versioning (semver)** as its public contract. Tier 1 exports
14
- will not break without a major version bump and migration guide. See
15
- [`docs/versioning.md`](docs/versioning.md) for the complete policy.
16
-
17
- Every export in `src/index.ts` is annotated with its tier via inline comments.
18
- The tables below list key symbols by tier.
19
-
20
- ---
21
-
22
- ## Tier 1 — Stable host API
23
-
24
- These exports are safe to depend on. They will not change in a breaking way without a major
25
- version bump and a migration guide in `CHANGELOG.md`.
26
-
27
- ### Fixed-point arithmetic (`src/units.ts`)
28
-
29
- | Export | Description |
30
- |--------|-------------|
31
- | `type Q` | Dimensionless fixed-point scalar; `SCALE.Q == 1.0` |
32
- | `type I32` | int32-safe number |
33
- | `SCALE` | Unit scale constants: `SCALE.Q`, `SCALE.kg`, `SCALE.m`, `SCALE.mps`, `SCALE.J`, `SCALE.N`, `SCALE.W`, `SCALE.s` |
34
- | `q(x)` | Convert a float to fixed-point Q |
35
- | `qMul(a, b)` | Fixed-point multiply |
36
- | `qDiv(a, b)` | Fixed-point divide |
37
- | `clampQ(x, lo, hi)` | Clamp a Q value |
38
- | `mulDiv(a, b, div)` | Integer multiply-then-divide with overflow safety |
39
- | `to` | Conversion helpers: `to.kg(x)`, `to.m(x)`, `to.mps(x)`, `to.J(x)`, `to.N(x)`, `to.W(x)`, `to.s(x)` |
40
- | `from` | Reverse converters: `from.kg(x)`, etc. |
41
- | `sqrtQ(x)` | Fixed-point square root |
42
-
43
- ### Core simulation (`src/sim/kernel.ts`, `src/sim/world.ts`)
44
-
45
- | Export | Description |
46
- |--------|-------------|
47
- | `stepWorld(world, cmds, ctx)` | Advance the world by one tick |
48
- | `applyImpactToInjury(world, aId, bId, energy_J, channel)` | Apply kinetic impact |
49
- | `applyFallDamage(entity, height_m)` | Apply fall damage to an entity |
50
- | `applyExplosion(world, x, y, energy_J, radius_m, ctx)` | Blast AoE |
51
- | `applyPayload(world, targetId, payload, ctx)` | Apply a capability payload |
52
- | `applyCapabilityEffect(world, actorId, targetId, effect, ctx)` | Apply a capability effect |
53
- | `WorldState` | World container type (`entities`, `spatialIndex`, `clock`) |
54
- | `KernelContext` | Tick context (`worldSeed`, `techCtx`, `weather`) |
55
- | `CommandMap` | Map of entity ID → command |
56
-
57
- ### Entity and attributes (`src/sim/entity.ts`, `src/types.ts`, `src/archetypes.ts`)
58
-
59
- | Export | Description |
60
- |--------|-------------|
61
- | `Entity` | Core entity shape. **Stable fields:** `id`, `pos`, `mass_kg`, `attributes`, `injuries`, `fatigue`, `fluid`, `consciousness`, `shock`, `fear`, `team`, `dead`. Optional extension fields (mount, age, sleep, etc.) may gain new members in minor versions |
62
- | `IndividualAttributes` | Physical attribute block (`peakForce_N`, `peakPower_W`, `continuousPower_W`, `reserveEnergy_J`, `reactionTime_s`, `controlQuality`, `stability`, `fineControl`, `stature_m`, `mass_kg`, …) |
63
- | `Archetype` | Archetype baseline with variance fields |
64
- | `BodyPlan` | Species body plan descriptor |
65
- | `NarrativeBias` | Story-shaping bias for `generateIndividual` |
66
-
67
- ### Entity generation (`src/generate.ts`)
68
-
69
- | Export | Description |
70
- |--------|-------------|
71
- | `generateIndividual(seed, archetype, bias?)` | Generate a physically plausible entity from an archetype |
72
-
73
- ### Presets and weapons (`src/presets.ts`, `src/weapons.ts`)
74
-
75
- | Export | Description |
76
- |--------|-------------|
77
- | `mkKnight`, `mkBoxer`, `mkWrestler`, `mkOctopus`, `mkScubaDiver` | Named entity factories |
78
- | `AMATEUR_BOXER`, `PRO_BOXER`, `GRECO_WRESTLER`, `KNIGHT_INFANTRY`, `LARGE_PACIFIC_OCTOPUS` | Validated archetypes |
79
- | `ALL_HISTORICAL_MELEE`, `ALL_HISTORICAL_RANGED` | Complete historical weapon arrays |
80
- | `PREHISTORIC_MELEE` … `CONTEMPORARY_RANGED` | Per-era weapon arrays (six eras × melee/ranged) |
81
-
82
- ### Damage channels and traits (`src/channels.ts`, `src/traits.ts`)
83
-
84
- | Export | Description |
85
- |--------|-------------|
86
- | `DamageChannel` | Enum of damage channel types (kinetic, thermal, etc.) |
87
- | `ChannelMask` | Bitmask type for combining channels |
88
- | `channelMask(...channels)` | Build a combined channel mask |
89
- | `hasChannel(mask, ch)` | Test whether a mask includes a channel |
90
- | `TraitId` | Union type of all valid trait identifiers |
91
- | `TRAITS` | Record mapping each `TraitId` to its `TraitEffect` |
92
- | `buildTraitProfile(traits)` | Aggregate trait multipliers from an entity's trait list |
93
- | `applyTraitsToAttributes(attrs, traits)` | Apply trait effects to an attribute block |
94
-
95
- ### Command vocabulary (`src/sim/kinds.ts`)
96
-
97
- | Export | Description |
98
- |--------|-------------|
99
- | `CommandKinds` | Object of command kind string constants (`Move`, `Attack`, `Defend`, …) |
100
- | `MoveModes` | Walk / sprint / crawl constants |
101
- | `DefenceModes` | Parry / dodge / block constants |
102
- | `EngageModes` | Engage / disengage constants |
103
- | `HitArea` | Union of valid hit area identifiers |
104
-
105
- ### Replay and serialization (`src/replay.ts`)
106
-
107
- | Export | Description |
108
- |--------|-------------|
109
- | `ReplayRecorder` | Attach to a world to record all ticks |
110
- | `replayTo(replay, tick, ctx)` | Replay to a target tick deterministically |
111
- | `serializeReplay(replay)` | JSON-stringify a replay |
112
- | `deserializeReplay(json)` | Restore a replay from JSON |
113
- | `Replay`, `ReplayFrame` | Replay types |
114
-
115
- ### 3D integration and renderer bridge (`src/model3d.ts`, `src/bridge/`)
116
-
117
- See [`docs/bridge-contract.md`](docs/bridge-contract.md) for the field-by-field contract
118
- including `AnimationHints`, `GrapplePoseConstraint`, and `InterpolatedState`.
119
-
120
- | Export | Description |
121
- |--------|-------------|
122
- | `extractRigSnapshots(world)` | Per-entity rig data snapshot for renderer use |
123
- | `deriveAnimationHints(entity)` | Animation state hints |
124
- | `derivePoseModifiers(entity)` | Per-region impairment pose weights |
125
- | `deriveGrappleConstraint(entity)` | Grapple pose constraint for paired entities |
126
- | `deriveMassDistribution(entity)` | Mass distribution for physics rigs |
127
- | `deriveInertiaTensor(entity)` | Inertia tensor for physics rigs |
128
- | `AnimationHints`, `PoseModifier`, `GrapplePoseConstraint`, `MassDistribution`, `InertiaTensor` | Types |
129
- | `BridgeEngine` | Double-buffered renderer bridge engine |
130
- | `BridgeConfig`, `BodyPlanMapping`, `InterpolatedState` | Bridge configuration and output types |
131
-
132
- ### Description layer (`src/describe.ts`)
133
-
134
- | Export | Description |
135
- |--------|-------------|
136
- | `describeCharacter(attrs)` | Translate fixed-point attributes into rated descriptions |
137
- | `formatCharacterSheet(desc)` | Multi-line formatted character sheet |
138
- | `formatOneLine(desc)` | One-line summary |
139
- | `CharacterDescription`, `AttributeRating` | Types |
140
-
141
- ### Socio-Economic Campaign Layer (`ananke/polity` subpath — CE-14)
142
-
143
- All of the following are available via `import { … } from "ananke/polity"` as a single
144
- entry point. The frozen interfaces (`Polity`, `PolityRegistry`, `PolityPair`,
145
- `EmotionalWave`) will not gain required fields or lose existing fields without a minor
146
- version bump; renames require a major bump and migration guide.
147
-
148
- #### Polity system (`src/polity.ts`)
149
-
150
- | Export | Description |
151
- |--------|-------------|
152
- | `Polity` _(frozen)_ | Geopolitical entity: city, nation, or empire |
153
- | `PolityRegistry` _(frozen)_ | Container for all polities and active wars/alliances |
154
- | `PolityPair` _(frozen)_ | Trade/proximity link between two polities |
155
- | `createPolity(spec)` | Construct a `Polity` with sensible defaults |
156
- | `createPolityRegistry(polities)` | Construct an empty registry |
157
- | `stepPolityDay(registry, pairs, worldSeed, tick)` | Advance all polities by one simulated day |
158
- | `declareWar(registry, aId, bId)` | Record a war between two polities |
159
- | `makePeace(registry, aId, bId)` | End a war between two polities |
160
- | `areAtWar(registry, aId, bId)` | Query war status |
161
-
162
- #### Technology diffusion (`src/tech-diffusion.ts`)
163
-
164
- | Export | Description |
165
- |--------|-------------|
166
- | `stepTechDiffusion(registry, pairs, worldSeed, tick)` | Spread technology between polities for one day |
167
- | `computeDiffusionPressure(source, target, pair)` | Per-pair pressure score |
168
- | `totalInboundPressure(registry, pairs, targetId)` | Sum of all inbound pressure toward a polity |
169
- | `techEraName(era)` | Human-readable era label |
170
-
171
- #### Emotional contagion (`src/emotional-contagion.ts`)
172
-
173
- | Export | Description |
174
- |--------|-------------|
175
- | `EmotionalWave` _(frozen)_ | Active emotional event propagating across polities |
176
- | `applyEmotionalContagion(registry, waves, worldSeed, tick)` | Apply all active waves to polity morale |
177
- | `stepEmotionalWaves(waves, worldSeed, tick)` | Advance wave intensities by one day |
178
- | `computeEmotionalSpread(source, target, wave, profile)` | Spread probability for one polity pair |
179
- | `triggerMilitaryRout(sourcePolityId)` | Emit a fear wave from a battlefield loss |
180
- | `triggerVictoryRally(sourcePolityId, leaderId?)` | Emit a hope wave from a victory |
181
- | `netEmotionalPressure(registry, waves, polityId)` | Net morale pressure on a polity |
182
-
183
- ---
184
-
185
- ## Tier 2 — Experimental extension API
186
-
187
- These exports are usable and tested but may change across minor versions.
188
- A `CHANGELOG.md` entry will document any breaking change.
189
-
190
- Tier 2 modules are accessible via **named subpath exports** (preferred) or deep imports:
191
-
192
- ```typescript
193
- // Preferred — named subpath (stable grouping, no internal path coupling)
194
- import { stepAging, applyAgingToAttributes } from "@its-not-rocket-science/ananke/character";
195
- import { resolveRangedAttack, stepGrapple } from "@its-not-rocket-science/ananke/combat";
196
- import { stepCampaignDay, createSettlement } from "@its-not-rocket-science/ananke/campaign";
197
- import { dialogueProbability, effectiveStanding } from "@its-not-rocket-science/ananke/social";
198
- import { addChronicleEntry, detectStoryArcs } from "@its-not-rocket-science/ananke/narrative";
199
- import { compileAnatomyDefinition } from "@its-not-rocket-science/ananke/anatomy";
200
- import { craftItem, getAvailableRecipes } from "@its-not-rocket-science/ananke/crafting";
201
- import { resolveCompetence } from "@its-not-rocket-science/ananke/competence";
202
-
203
- // Deep import (fallback — internal paths may change)
204
- import { stepAging } from "@its-not-rocket-science/ananke/dist/src/sim/aging.js";
205
- ```
206
-
207
- ### AI command system
208
-
209
- | Module | Key exports |
210
- |--------|------------|
211
- | `src/sim/ai/system.ts` | `buildAICommands(world, ctx)` — build a `CommandMap` for all AI-controlled entities |
212
-
213
- ### Character lifecycle
214
-
215
- | Module | Key exports |
216
- |--------|------------|
217
- | `src/sim/aging.ts` | `applyAgingToAttributes`, `stepAging`, `deriveAgeMultipliers`, `getAgePhase` |
218
- | `src/sim/sleep.ts` | `applySleepToAttributes`, `stepSleep`, `deriveSleepDeprivationMuls`, `circadianAlertness` |
219
- | `src/sim/disease.ts` | `exposeToDisease`, `stepDiseaseForEntity`, `spreadDisease`, `computeTransmissionRisk` |
220
- | `src/sim/wound-aging.ts` | `stepWoundAging`, `recordTraumaEvent`, `deriveFearThresholdMul`, `deriveSepsisRisk` |
221
- | `src/sim/thermoregulation.ts` | `stepThermoregulation`, `deriveThermalComfort`, `computeMetabolicRate` |
222
- | `src/sim/nutrition.ts` | `stepNutrition`, `computeHungerEffect`, food catalogue constants |
223
- | `src/sim/medical.ts` | `resolveTreatment`, `computeTreatmentEffect`, medical tier definitions |
224
- | `src/sim/toxicology.ts` | `applyVenom`, `stepActiveVenoms`, `resolveIngestedToxin` |
225
- | `src/progression.ts` | `applyXP`, `applyTrainingDrift`, `computeMilestones` |
226
-
227
- ### Combat extensions
228
-
229
- | Module | Key exports |
230
- |--------|------------|
231
- | `src/sim/mount.ts` | `checkMountStep`, `computeChargeBonus`, `deriveRiderHeightBonus` |
232
- | `src/sim/hazard.ts` | `deriveHazardEffect`, `computeHazardExposure`, `stepHazardZone` |
233
- | `src/sim/ranged.ts` | `resolveRangedAttack`, `computeRangedAccuracy`, `computeProjectileEnergy` |
234
- | `src/sim/grapple.ts` | `resolveGrappleContest`, `computeGrappleStrength`, `stepGrapple` |
235
- | `src/sim/formation.ts` | `FormationConfig`, `computeFormationBonus`, `resolveFormationStep` |
236
- | `src/sim/morale.ts` | `computeMoraleEffect`, `stepMorale`, `applyRoutEffect` |
237
- | `src/sim/sensory.ts` | `computeVisibility`, `computeHearingRange`, `stepSensoryState` |
238
- | `src/sim/sensory-extended.ts` | `computeEcholocationRange`, `computeOlfactionRange` — non-human senses |
239
- | `src/sim/weather.ts` | `WeatherState`, `stepWeather`, `computeWeatherEffect` |
240
- | `src/sim/terrain.ts` | `TerrainType`, `TERRAIN_PROFILES`, `computeTerrainTraction` |
241
- | `src/sim/skills.ts` | `SkillId`, `SkillLevel`, `SKILL_LEVEL_MULS`, `buildSkillMap`, `getSkillMul` |
242
- | `src/sim/biome.ts` | `BiomeType`, `BIOME_PROFILES`, `deriveBiomeEnvironment` |
243
-
244
- ### Social and economic systems
245
-
246
- | Module | Key exports |
247
- |--------|------------|
248
- | `src/dialogue.ts` | `resolveIntimidation`, `resolvePersuasion`, `resolveDeception`, `resolveTradeNegotiation` |
249
- | `src/faction.ts` | `FactionRegistry`, `updateStanding`, `getFactionStanding` |
250
- | `src/economy.ts` | `computeItemValue`, `applyWear`, `resolveDrops`, `evaluateTradeOffer` |
251
- | `src/relationships.ts` | `createRelationshipGraph`, `establishRelationship`, `recordEvent`, `getRelationshipAffinity` |
252
- | `src/relationships-effects.ts` | Relationship modifiers applied to dialogue, teaching, morale contexts |
253
- | `src/party.ts` | `createPartyRegistry`, `createParty`, `addPartyMember`, `setPartyStanding` |
254
-
255
- ### Campaign and world management
256
-
257
- | Module | Key exports |
258
- |--------|------------|
259
- | `src/campaign.ts` | `Campaign`, `stepCampaignDay`, `advanceCampaignClock`, `serializeCampaign`, `deserializeCampaign` |
260
- | `src/downtime.ts` | `stepDowntime`, `TreatmentSchedule`, `EntityRecoveryReport` |
261
- | `src/collective-activities.ts` | `createCollectiveProject`, `contributeToCollectiveProject`, `stepRitual`, `planCaravanRoute` |
262
- | `src/inventory.ts` | `createInventory`, `addItemToInventory`, `consumeItemsByTemplateId`, `getEncumbrancePenalty` |
263
- | `src/item-durability.ts` | `stepWear`, `applyWearPenalty` |
264
- | `src/settlement.ts` | `createSettlement`, `upgradeSettlement`, `getServiceBonus` |
265
- | `src/settlement-services.ts` | Service definitions (forge, medical, market, barracks, temple) |
266
- | `src/inheritance.ts` | `transferEquipment`, `transferRelationships`, `transferInventory` — character death succession |
267
- | `src/world-generation.ts` | `generateWorld`, `deriveStartingRelationships`, `deriveStartingConflicts` |
268
-
269
- ### Quest and narrative layer
270
-
271
- | Module | Key exports |
272
- |--------|------------|
273
- | `src/quest.ts` | `questFactory`, `updateQuestState`, `resolveObjective`, `Quest`, `QuestObjective` |
274
- | `src/quest-generators.ts` | `generateBountyQuest`, `generateEscortQuest`, `generateRetrievalQuest` |
275
- | `src/chronicle.ts` | `createChronicle`, `addChronicleEntry`, `getEntriesForEntity`, `ChronicleEntry` |
276
- | `src/story-arcs.ts` | `detectStoryArcs`, `updateDetectedArcs` — pattern detection across chronicle entries |
277
- | `src/narrative-render.ts` | `renderEntry`, `renderArcSummary` — template-based prose from chronicle entries |
278
- | `src/legend.ts` | `createLegendRegistry`, `createLegendFromChronicle`, `applyLegendToDialogueContext` |
279
- | `src/mythology.ts` | `compressMythsFromHistory`, `stepMythologyYear`, `aggregateFactionMythEffect`, `scaledMythEffect` |
280
- | `src/narrative.ts` | `narrateCombatTick`, `narrateInjury` — human-readable combat event strings |
281
- | `src/narrative-stress.ts` | `runNarrativeStressTest`, `scoreNarrativePush` |
282
- | `src/metrics.ts` | `extractCombatMetrics`, `summariseBattle` — analytics from trace events |
283
- | `src/arena.ts` | Arena scenario DSL, `runArenaTrial`, `runArenaScenario` |
284
-
285
- ### Anatomy subsystem
286
-
287
- | Module | Key exports |
288
- |--------|------------|
289
- | `src/anatomy/index.ts` | Re-export barrel for the full anatomy API |
290
- | `src/anatomy/anatomy-contracts.ts` | `CompiledAnatomyModel`, `AnatomyContracts`, `AnatomyCapabilities` — core anatomy types |
291
- | `src/anatomy/anatomy-schema.ts` | `validateExtendedBodyPlan`, `ValidationResult` — validate JSON body plan definitions |
292
- | `src/anatomy/anatomy-compiler.ts` | `compileAnatomyDefinition`, `compileAnatomyDefinitionOrThrow` — compile a body plan to indexed model |
293
- | `src/anatomy/anatomy-helpers.ts` | `createAnatomyHelpers`, `summarizeFunctionalHealth`, `sampleProfile` — query compiled anatomy |
294
-
295
- ### Competence framework
296
-
297
- | Module | Key exports |
298
- |--------|------------|
299
- | `src/competence/index.ts` | Re-export barrel for the full competence API |
300
- | `src/competence/framework.ts` | `resolveCompetence(entity, action, ctx)` — unified competence resolution dispatcher |
301
- | `src/competence/catalogue.ts` | `CompetenceDomain`, `CompetenceTask`, predefined task catalogue entries |
302
-
303
- ### Crafting subsystem
304
-
305
- | Module | Key exports |
306
- |--------|------------|
307
- | `src/crafting/index.ts` | `craftItem`, `startManufacturing`, `advanceManufacturing`, `getAvailableRecipes` — main crafting API |
308
-
309
- ---
310
-
311
- ## Tier 3 — Internal kernel structures
312
-
313
- These are implementation details. Do not import them directly; they may change at any time.
314
-
315
- ### Kernel internals
316
-
317
- | Module | Why internal |
318
- |--------|-------------|
319
- | `src/rng.ts` | `makeRng`, `eventSeed`, `hashString` — RNG contract is internal; seed structure may change |
320
- | `src/sim/seeds.ts` | Seed derivation utilities |
321
- | `src/sim/push.ts` | Pair-based resolution internals |
322
- | `src/sim/kernel.ts` (non-exported functions) | Step sub-phases, internal accumulators |
323
- | `src/sim/tick.ts` | Single-tick orchestration called by `stepWorld` |
324
- | `src/sim/action.ts` | Attack cooldown and swing-momentum state machine |
325
- | `src/sim/intent.ts` | Movement and defence intent processing |
326
- | `src/sim/combat.ts` | Hit resolution and skill-contest internals |
327
- | `src/sim/step/` | All sub-step modules (`push`, `energy`, `injury`, `movement`, etc.) |
328
- | `src/sim/context.ts` | `KernelContext` type definition (re-exported via `sim/world.ts`) |
329
- | `src/sim/events.ts` | Internal event emission — consumed by trace and bridge |
330
- | `src/sim/indexing.ts` | Spatial index internals used by `stepWorld` |
331
- | `src/sim/tuning.ts` | Physics constant tables — may be retuned in patch releases |
332
- | `src/sim/impairment.ts` | Functional damage accumulator — called by the kernel step |
333
- | `src/sim/occlusion.ts` | Internal visibility occlusion used by sensory |
334
- | `src/sim/systemic-toxicology.ts` | Multi-substance pharmacokinetics internals |
335
- | `src/sim/formation-unit.ts` | Squad-level unit structure used by `formation-combat.ts` |
336
- | `src/sim/commandBuilders.ts` | Low-level command construction helpers — prefer `noMove()` from `commands.ts` |
337
- | `src/sim/team.ts` | Team/side definitions used internally by AI and morale |
338
- | `src/derive.ts` | Movement-force and geometry derivations used by the kernel |
339
- | `src/lod.ts` | Level-of-detail helpers for large simulations |
340
- | `src/debug.ts` | Visual debug extraction (motion vectors, hit traces) |
341
-
342
- ### AI decision internals
343
-
344
- | Module | Why internal |
345
- |--------|-------------|
346
- | `src/sim/ai/decide.ts` | Decision-tree evaluation — called by `buildAICommands` |
347
- | `src/sim/ai/perception.ts` | AI sensory processing — called by `buildAICommands` |
348
- | `src/sim/ai/targeting.ts` | Target selection heuristics — called by `buildAICommands` |
349
- | `src/sim/ai/personality.ts` | Personality trait modifiers on AI decisions |
350
- | `src/sim/ai/types.ts` | AI policy and state types used only within `src/sim/ai/` |
351
-
352
- > Use `buildAICommands(world, ctx)` from `src/sim/ai/system.ts` (Tier 2) rather than importing AI sub-modules directly.
353
-
354
- ### Competence domain resolvers
355
-
356
- These are called by `resolveCompetence()` and should not be imported directly.
357
-
358
- | Module | Domain |
359
- |--------|--------|
360
- | `src/competence/crafting.ts` | Crafting and tool use |
361
- | `src/competence/navigation.ts` | Wayfinding and cartography |
362
- | `src/competence/naturalist.ts` | Tracking, foraging, taming |
363
- | `src/competence/interspecies.ts` | Cross-species communication |
364
- | `src/competence/language.ts` | Linguistics and translation |
365
- | `src/competence/teaching.ts` | Knowledge transfer |
366
- | `src/competence/willpower.ts` | Endurance and mental fortitude |
367
- | `src/competence/engineering.ts` | Siege and structural engineering |
368
- | `src/competence/performance.ts` | Entertainment and oratory |
369
- | `src/competence/acoustic.ts` | Formation signalling (drums, horns) |
370
-
371
- ### Crafting internals
372
-
373
- These are called by `craftItem()` / `startManufacturing()` and should not be imported directly.
374
-
375
- | Module | Role |
376
- |--------|------|
377
- | `src/crafting/materials.ts` | Material definitions and property calculations |
378
- | `src/crafting/recipes.ts` | Recipe validation and feasibility |
379
- | `src/crafting/manufacturing.ts` | Batch production mechanics |
380
- | `src/crafting/workshops.ts` | Workshop facility definitions and output bonuses |
381
-
382
- ---
383
-
384
- ## What constitutes a "breaking change"
385
-
386
- | Tier 1 (breaking, requires major bump) | Tier 2 (documented in changelog) |
387
- |---------------------------------------|----------------------------------|
388
- | Removing or renaming a stable export | Removing or renaming an experimental export |
389
- | Changing the signature of a stable function | Changing observable behaviour without a matching test update |
390
- | Removing required fields from stable types | Changing field names in experimental types |
391
- | Changing `stepWorld`'s observable output for identical inputs | Changing RNG consumption order in internal modules |
392
- | Breaking `serializeReplay`/`deserializeReplay` round-trip | Changing undocumented default values |
393
-
394
- Adding new **optional** fields to `Entity` or `IndividualAttributes` is never a breaking change.
395
- Adding new exports is never a breaking change at any tier.
396
-
397
- ---
398
-
399
- ## Entity and WorldState Field Tiers
400
-
401
- Every field on `Entity` and `WorldState` carries a JSDoc annotation that identifies which
402
- subsystem owns it and whether it is required by the kernel. There are three tiers:
403
-
404
- ### `@core` — Required by `stepWorld` every tick
405
-
406
- These fields must always be present. Removing or renaming them is a Tier 1 breaking change.
407
-
408
- **`Entity` core fields:**
409
-
410
- | Field | Type | Description |
411
- |-------|------|-------------|
412
- | `id` | `number` | Unique entity identifier; stable across ticks |
413
- | `teamId` | `number` | Combat team / allegiance for attack resolution and AI targeting |
414
- | `attributes` | `IndividualAttributes` | Physical and cognitive capabilities |
415
- | `energy` | `EnergyState` | Energy reserve and fatigue accumulator |
416
- | `loadout` | `Loadout` | Equipped items: weapons, armour, held objects |
417
- | `traits` | `TraitId[]` | Permanent trait flags |
418
- | `position_m` | `Vec3` | World-space position (fixed-point, `SCALE.m` = 1 m) |
419
- | `velocity_mps` | `Vec3` | Velocity (fixed-point, `SCALE.mps` = 1 m/s) |
420
- | `intent` | `IntentState` | Movement and defence intent derived from the previous tick's commands |
421
- | `action` | `ActionState` | Attack cooldowns, swing momentum, weapon-bind state |
422
- | `condition` | `ConditionState` | Fear, morale, sensory modifiers, fatigue, thermal state |
423
- | `injury` | `InjuryState` | Per-region damage, shock, consciousness, fluid loss, death flag |
424
- | `grapple` | `GrappleState` | Active grapple relationships, grip strength, positional lock |
425
-
426
- **`WorldState` core fields:**
427
-
428
- | Field | Type | Description |
429
- |-------|------|-------------|
430
- | `tick` | `number` | Current tick count; incremented by `stepWorld` |
431
- | `seed` | `number` | Deterministic RNG seed |
432
- | `entities` | `Entity[]` | All live and dead entities |
433
-
434
- ### `@subsystem(name)` — Optional state consumed by a specific module
435
-
436
- These fields are optional `?` properties. Omitting a subsystem field disables that module's
437
- behaviour for the entity; the kernel continues to run correctly without it. Adding new
438
- subsystem fields is never a breaking change.
439
-
440
- **`Entity` subsystem fields:**
441
-
442
- | Field | Module | Description |
443
- |-------|--------|-------------|
444
- | `willpower?` | `willpower` | Cognitive stamina reserve for concentration abilities |
445
- | `skills?` | `skills` | Per-skill proficiency map for skill-contest resolution |
446
- | `bodyPlan?` | `anatomy` | Body plan defining injury segments and mass distribution |
447
- | `substances?` | `pharmacology` | Active pharmacological substances in the bloodstream |
448
- | `foodInventory?` | `nutrition` | Consumable food items and counts |
449
- | `molting?` | `anatomy` | Arthropod molting state (softening segments, repair cycles) |
450
- | `ai?` | `ai` | AI decision state (target selection, threat map) |
451
- | `capabilitySources?` | `capability` | Attached capability sources (mana pools, divine reserves) |
452
- | `armourState?` | `armour` | Mutable resist state for ablative armour items |
453
- | `pendingActivation?` | `capability` | In-flight capability cast |
454
- | `activeConcentration?` | `capability` | Active concentration aura |
455
- | `faction?` | `faction` | Faction membership identifier |
456
- | `party?` | `party` | Adventuring party membership identifier |
457
- | `reputations?` | `faction` | Entity-level faction-standing overrides |
458
- | `physiology?` | `thermoregulation` | Species-level physiological overrides |
459
- | `activeVenoms?` | `toxicology` | Active venom/toxin injections |
460
- | `limbStates?` | `anatomy` | Per-limb state for multi-limb entities |
461
- | `personality?` | `ai` | AI personality traits (aggression, caution, loyalty) |
462
- | `extendedSenses?` | `sensory` | Extended sensory modalities (echolocation, olfaction) |
463
- | `activeIngestedToxins?` | `toxicology` | Active ingested toxins (alcohol, sedatives, heavy metals) |
464
- | `cumulativeExposure?` | `toxicology` | Cumulative lifetime dose records |
465
- | `withdrawal?` | `toxicology` | Active withdrawal states |
466
- | `traumaState?` | `wound-aging` | PTSD-like trauma state from severe shock events |
467
- | `activeDiseases?` | `disease` | Active systemic disease states |
468
- | `immunity?` | `disease` | Post-recovery immunity records |
469
- | `age?` | `aging` | Elapsed life-seconds for aging calculations |
470
- | `sleep?` | `sleep` | Sleep-phase state and debt accumulator |
471
- | `mount?` | `mount` | Rider/mount pair state for mounted combat |
472
- | `compiledAnatomy?` | `anatomy` | Internal anatomy cache — do not set manually |
473
- | `anatomyHelpers?` | `anatomy` | Internal anatomy helper cache — do not set manually |
474
-
475
- **`WorldState` subsystem fields:**
476
-
477
- | Field | Module | Description |
478
- |-------|--------|-------------|
479
- | `activeFieldEffects?` | `capability` | Active suppression zones and field-effect modifiers |
480
- | `__sensoryEnv?` | `sensory` | Ambient lighting and visibility environment |
481
- | `__factionRegistry?` | `faction` | Global faction-standing registry |
482
- | `__partyRegistry?` | `party` | Global party registry |
483
- | `__relationshipGraph?` | `relationships` | Inter-entity relationship graph |
484
- | `__nutritionAccum?` | `nutrition` | Cross-tick nutrition accumulator |
485
-
486
- ### `@extension` — Host-owned data
487
-
488
- No built-in fields carry this tag. Hosts may add their own optional `?` fields to pass
489
- renderer metadata, network session IDs, or other application-specific data alongside entities.
490
- TypeScript's structural typing allows this without modifying `Entity`'s definition.
1
+ # Ananke — Stable API Reference
2
+
3
+ Canonical contract sources:
4
+
5
+ - `src/index.ts`
6
+ - `docs/stable-api-manifest.json`
7
+ - `docs/public-contract.md`
8
+
9
+ For explicit maintainer promises, exclusions, and version-pinning guidance, see `docs/support-boundaries.md`.
10
+
11
+
12
+ ## Stability labels (taxonomy-bound)
13
+
14
+ <!-- CONTRACT:STABILITY_LABELS:start -->
15
+ ```json
16
+ [
17
+ { "kind": "subpath", "subject": ".", "status": "Tier 1 stable", "notes": "Root package entrypoint" },
18
+ { "kind": "symbol-group", "subject": "root:tier1-symbols", "status": "Tier 1 stable", "notes": "Manifest-backed root symbols" }
19
+ ]
20
+ ```
21
+ <!-- CONTRACT:STABILITY_LABELS:end -->
22
+
23
+ ## Tier-1 (root-stable)
24
+
25
+ Only root imports are Tier-1:
26
+
27
+ ```ts
28
+ import { ... } from "@its-not-rocket-science/ananke";
29
+ ```
30
+
31
+ <!-- CONTRACT:TIER1_SYMBOLS:start -->
32
+ ```json
33
+ [
34
+ "AnankeScenario",
35
+ "AnankeScenarioEntity",
36
+ "AnimationHints",
37
+ "Command",
38
+ "CommandMap",
39
+ "Entity",
40
+ "EntitySpec",
41
+ "G_mps2",
42
+ "I32",
43
+ "IndividualAttributes",
44
+ "KernelContext",
45
+ "LoadedPlugin",
46
+ "PluginHookContext",
47
+ "PluginHooks",
48
+ "PluginManifest",
49
+ "PluginModule",
50
+ "PluginPermission",
51
+ "PluginRuntimeApi",
52
+ "Q",
53
+ "Replay",
54
+ "ReplayFrame",
55
+ "ReplayRecorder",
56
+ "RigSnapshot",
57
+ "SCALE",
58
+ "WorldState",
59
+ "clampQ",
60
+ "createWorld",
61
+ "deriveAnimationHints",
62
+ "deserializeReplay",
63
+ "extractRigSnapshots",
64
+ "from",
65
+ "installPluginFromRegistry",
66
+ "loadPlugin",
67
+ "loadScenario",
68
+ "mulDiv",
69
+ "q",
70
+ "qDiv",
71
+ "qMul",
72
+ "replayTo",
73
+ "serializeReplay",
74
+ "sqrtQ",
75
+ "stepWorld",
76
+ "to",
77
+ "validateScenario"
78
+ ]
79
+ ```
80
+ <!-- CONTRACT:TIER1_SYMBOLS:end -->
81
+
82
+ ## Tier-2 stable (subpath imports with explicit stability claims)
83
+
84
+ The following subpaths are **Tier 2 stable**: they are fully implemented, thoroughly tested (>90% coverage), and API-stable within the `@minor` version boundary. Breaking changes require at minimum a minor version bump with a CHANGELOG entry. They are not Tier-1 because they are not re-exported from the root entrypoint.
85
+
86
+ | Subpath | Status | Coverage | Notes |
87
+ |---------|--------|----------|-------|
88
+ | `@its-not-rocket-science/ananke/sim/combat` | **Tier 2 stable** | >95% | `resolveHit`, `computeWeaponEnergy`, `CombatResult` — full pair-based combat resolution |
89
+ | `@its-not-rocket-science/ananke/sim/disease` | **Tier 2 stable** | 100% | `exposeToDisease`, `stepDiseaseForEntity`, `spreadDisease`, all 6 built-in profiles |
90
+ | `@its-not-rocket-science/ananke/sim/hazard` | **Tier 2 stable** | >95% | `computeHazardExposure`, `deriveHazardEffect`, `stepHazardZone`, all 5 built-in zones |
91
+
92
+ ```ts
93
+ // Stable Tier-2 usage:
94
+ import { resolveHit, computeWeaponEnergy } from "@its-not-rocket-science/ananke/sim/combat";
95
+ import { exposeToDisease, spreadDisease } from "@its-not-rocket-science/ananke/sim/disease";
96
+ import { computeHazardExposure, CAMPFIRE } from "@its-not-rocket-science/ananke/sim/hazard";
97
+ ```
98
+
99
+ > **Path to Tier-1**: These subpaths will be promoted to Tier-1 (re-exported from root) when the API has been exercised by ≥2 external integrations with documented use cases. Track `ROADMAP.md` for PM-series milestones.
100
+
101
+ ## Shipped but not Tier-1 (subpath imports)
102
+
103
+ Everything below is public and shipped through `package.json` exports, but must be treated by the taxonomy as **Shipped but undocumented**, **Experimental**, or **Internal** (never Tier 1 stable unless explicitly labeled).
104
+
105
+ - Experimental subpaths: see `docs/module-index.md` for grouped listing.
106
+ - Internal/advanced subpath: `@its-not-rocket-science/ananke/tier3`.
107
+
108
+ ## Rules
109
+
110
+ - Do not import non-listed symbols from root and assume stability.
111
+ - If a symbol is shipped only via subpath, treat it as shipped-but-not-Tier-1 unless a specific subpath-stability claim exists.
112
+ - If you depend on subpaths in production, pin versions conservatively and regression-test every upgrade.
113
+