Skip to content

Appendix C — Module API Reference

Function signatures and hooks for built-in modules.

Creates and returns an engine instance.

Creates an isolated engine instance for testing.

Cognition Core — createCognitionCore(config?)

Section titled “Cognition Core — createCognitionCore(config?)”
FunctionSignatureDescription
getCognition(world, entityId) → CognitionStateGet entity’s cognition state
setBelief(world, entityId, belief) → voidSet a belief
getBelief(world, entityId, subject, key) → BeliefGet a specific belief
getBeliefValue(world, entityId, subject, key) → anyGet belief value directly
believes(world, entityId, subject, key, value) → booleanCheck if entity holds a belief
addMemory(world, entityId, memory) → voidRecord a memory
getMemories(world, entityId) → Memory[]Get all memories
getRecentMemories(world, entityId, count) → Memory[]Get N most recent memories
checkPerception(world, entityId, difficulty, stat?) → PerceptionResultRoll a perception check
selectIntent(world, entityId) → IntentOptionChoose an action from AI profile

Perception Filter — createPerceptionFilter(config?)

Section titled “Perception Filter — createPerceptionFilter(config?)”
FunctionSignatureDescription
getPerceptionLog(world, entityId) → PerceivedEvent[]Full perception history
getRecentPerceptions(world, entityId, count) → PerceivedEvent[]Recent perceptions
didPerceive(world, entityId, eventType) → booleanCheck if entity perceived event type
whoPerceived(world, eventType) → string[]List entities that perceived event

Progression Core — createProgressionCore(config)

Section titled “Progression Core — createProgressionCore(config)”
FunctionSignatureDescription
getCurrency(world, entityId, currency) → numberGet currency balance
addCurrency(world, entityId, currency, amount) → voidAdd currency
spendCurrency(world, entityId, currency, amount) → booleanSpend currency
isNodeUnlocked(world, entityId, nodeId) → booleanCheck if node is unlocked
canUnlock(world, entityId, nodeId) → booleanCheck if node can be unlocked
unlockNode(world, entityId, nodeId) → UnlockResultUnlock a progression node
getAvailableNodes(world, entityId) → TreeNode[]List unlockable nodes
getUnlockedNodes(world, entityId) → string[]List unlocked node IDs

Environment Core — createEnvironmentCore(config?)

Section titled “Environment Core — createEnvironmentCore(config?)”
FunctionSignatureDescription
getZoneProperty(world, zoneId, key) → numberGet dynamic zone property
setZoneProperty(world, zoneId, key, value) → voidSet zone property
modifyZoneProperty(world, zoneId, key, delta) → voidModify property by delta
processEnvironmentDecays(world) → voidProcess all decay timers

Narrative Authority — createNarrativeAuthority(config?)

Section titled “Narrative Authority — createNarrativeAuthority(config?)”
FunctionSignatureDescription
conceal(world, eventId, reason) → voidHide an event from presentation
distort(world, eventId, replacement) → voidReplace event in presentation
getContradictions(world) → Contradiction[]List recorded contradictions
reveal(world, contradictionId) → voidExpose a hidden truth

District Core — createDistrictCore(config)

Section titled “District Core — createDistrictCore(config)”
FunctionSignatureDescription
getDistrictForZone(world, zoneId) → string | undefinedFind which district a zone belongs to
getDistrictState(world, districtId) → DistrictMetrics | undefinedGet district aggregate metrics
getDistrictDefinition(world, districtId) → DistrictDefinition | undefinedGet district config
getAllDistrictIds(world) → string[]List all district IDs
getDistrictMetric(world, districtId, metric) → numberGet a specific metric value
modifyDistrictMetric(world, districtId, metric, delta) → voidModify a metric by delta (clamped 0-100)
isDistrictOnAlert(world, districtId) → booleanCheck if alertPressure > 30
getDistrictThreatLevel(world, districtId) → numberWeighted composite of all metrics

Belief Provenance — createBeliefProvenance()

Section titled “Belief Provenance — createBeliefProvenance()”
FunctionSignatureDescription
traceEntityBelief(world, entityId, subject, key) → BeliefTraceTrace an entity belief’s provenance
traceFactionBelief(world, factionId, subject, key) → BeliefTraceTrace a faction belief through rumor chain
traceSubject(world, subject) → BeliefTrace[]Find all beliefs about a subject
formatBeliefTrace(trace) → stringHuman-readable forensic narrative

Observer Presentation — createObserverPresentation(config?)

Section titled “Observer Presentation — createObserverPresentation(config?)”
FunctionSignatureDescription
presentForObserver(event, observerId, world, rules?) → ObserverPresentedEventPresent event from observer’s perspective
presentForAllObservers(event, world) → ObserverPresentedEvent[]One version per AI entity
getDivergences(world) → DivergenceRecord[]All recorded divergences
getEventDivergences(world, eventId) → DivergenceRecord[]Divergences for a specific event

Simulation Inspector — createSimulationInspector()

Section titled “Simulation Inspector — createSimulationInspector()”
FunctionSignatureDescription
inspectEntity(world, entityId) → EntityInspectionFull entity cognitive state
inspectFaction(world, factionId) → FactionInspectionFaction beliefs and alert level
inspectZone(world, zoneId) → ZoneInspectionZone environment state
inspectDistrict(world, districtId) → DistrictInspectionDistrict aggregate metrics
inspectAllDistricts(world) → Record<string, DistrictInspection>All district inspections
createSnapshot(world) → SimulationSnapshotFull world snapshot
formatEntityInspection(inspection) → stringText format for entity
formatFactionInspection(inspection) → stringText format for faction
formatDistrictInspection(inspection) → stringText format for district