Mad Programmer Manual — Beast
A guide for anyone who has seriously decided to understand the Beast codebase (“Beast creature, comms console”) and keep evolving it. This is not a substitute for sources or a dump of every module — it is a mental map, principles, and where truth lives (in code and about_*.md).
1. Why this document
- The project is large, links are non-obvious, script load order is critical.
- Much state lives in
window/ globals — without a mental model you can break what “happened to work”. PROJECT_STATE_FOR_NEW_CHAT.mdat the repo root is a compressed snapshot for AI and humans; this manual is broader: philosophy, layers, common pitfalls, how to grow features.
If you change architecture, update PROJECT_STATE_FOR_NEW_CHAT.md and the relevant beast/**/about_*.md (including beast/_12_Sleep/about_sleep.md when sleep mode changes).
2. What Beast is, conceptually
Beast is a browser app modeling organism ↔ stimuli ↔ orientation reflex (OR) ↔ comprehension process (consciousness cycles) ↔ episodic memory (EM).
Principles:
- Time is discrete — the “pulse” (
global.cpuls,Cur_puls_val). Almost everything important ties to a pulse or a UI event between pulses. - Body state — vitals, deviation from norm, integral importance, base state Bad / Normal / Well (
BadNormWell). - Contexts — compact emotional-behavioral tags (basic contexts); “emotion” and tree branch are built from them.
- Stimuli — typed (motivation, positive, negative, neutral); global ids do not collide across arrays (see
StimulusGlobalId_*). - OR — stimulus competition by salience, semantics “maturity” threshold (
OR_well_known), exceptions for some scenarios (see OR code). - Consciousness — not one call but a cycle registry (
ConsciousnessCycles), step dispatcher, main vs background cycles,expired, cycle log. - Memory — semantics (importance by condition), episodes (frames with
effect, stimulus, action, operator answer), abstractions and rules for higher levels.
This layout is spread across beast/_1_ … beast/_12_ — the number hints at the layer (from “body” toward “consciousness, memory, and sleep”).
3. beast/ directory map (layers)
| Folder | Role |
|---|---|
_1_Genetic_vitals |
Vitals, scales, shock, death, prep for calculations |
_2_Genetic_basic_styles |
Basic contexts, styles, prepare.js: BadNormWell, GetBadNormWell, SetWellForHolding, holds, getDiffImportance |
_3_perception |
Stimulus lists, stimulus UI, activation, OR link |
_4_actions |
BasicActions, effectors, mirror actions |
_5_Genetic__reflexes |
Reflex tables, genetic_reflexes_engine.js: processGeneticReflexes, runActionImage, startAction |
_5_2_synonyms_reflexes |
Conditioned (synonym) reflexes |
_6_semantic_memory |
FinalImage, semantic index, experience registration |
_7_perception_tree |
Perception tree, terminal node = “branch” for EM and automatisms |
_8_Hippocampus |
Hippocampus, orientation_reflex.js — OR |
_9_Conscience |
Info picture, detectors, consciousness levels 2–4, gestalt, abstractions, attention channel |
_10_Episodic_memory |
EM frames, answer wait, frame close, effect |
_10_actions_image |
Action images (AI), link to goals |
_11_Automatizms |
Branch automatisms, bind to AI |
_12_Sleep |
Sleep mode (“Sleep” context, stimulus limits, auto-sleep by finished-cycle counter), dreams from empty EM frames |
Also: beast/puls.js — tick heart; beast/docs/ — project notes and analysis.
4. Entry point and sacred script order
- Entry: repo root
index.html. - At end of
body,index.htmlscript order is a contract. Reorder files and some globals areundefinedat init.
Rule: dependents load below dependents-on. Examples:
consciousness_dispatcher.jsdefines the cycle registry and dispatch.gestalt.jsmust be beforeepisodic_memory.js(hookGestalt_onEpisodeFeedbackClosedincloseLastFrame).- Consciousness “level” modules depend on info picture and EM.
Practice: before a big refactor, export the <script src=...> list from index.html and verify the chain by hand.
5. Pulse: what happens each tick
beast/puls.js (and related calls) drives:
- pulse counter increment;
- vitals/context updates (
getActiveBasicContexts, etc.); - when sleep is active — stimulus visuals and
SleepDreams_onPulse(dream machine before consciousness dispatcher so the same tick can run sleep main cycleinfo_fantasizming); - genetic and conditioned reflexes;
- consciousness dispatcher (
Consciousness_runOneStep, etc.); - episodic memory (wait ticks, frame closure by scenario).
Principle: if logic “belongs in the pulse”, do not duplicate it only in UI — UI and pulse must agree or you get races (e.g. info picture vs reflex).
6. Global state: discipline
beast/about_global_variables.md— keywindow.*reference. Before adding a global, ask: does it needwindow, or is a module closure enough.- Naming — the project mixes Russian comments and English identifiers; new code should match the file you edit.
- Serialization — vitals, tree, semantics, EM, goals, AI, automatisms partly go to IndexedDB / files. Any new
windowentity must either enter save/load or be explicitly “session-only” (document that).
7. Data flow “textbook style”
Simplified (reality always branches):
Vitals → BadVitalsValue / contexts → BasicContextsActived
→ BadNormWell, emotion (Emotions_*)
→ perception tree path → terminal node (branchId)
Stimuli (UI) → global stimulus ids → FinalImage
→ OR (competition, thresholds) → actual_stimul_ID
→ stimuls_consciousness → consciousness cycles / automatisms
→ EM frame, effect, frame close → semantics / abstractions / gestaltOrientation reflex (orientation_reflex.js) is not trim — it is the hub: consciousness start, reflex block for a couple of pulses, delayed reflex queue, second pass after answer during waiting (see about_episodic_memory_rules.md).
8. Info picture and detectors
informing.js—InfoPicturestructure, view updates.info_detectors.js— computed fields:criticalVital,badState, play/learn modes, etc. Situations insituatioms_tree.jsare built from detector components.
Principle: detectors should be idempotent in their inputs (vitals, BadNormWell, flags). If you layer meaning (e.g. food clears critical under Well), document briefly in code why.
9. Consciousness levels (2–4) — where to look
| Level | File | Note |
|---|---|---|
| Dispatcher, cycle registry, log | consciousness_dispatcher.js |
Consciousness_cycleAppendLog, expired, force |
| Attention channel, consciousness input | conscious_attention_channel.js |
interrupts, “thought silence” |
| Lv.2 | conscience_level_2.js |
survival, goals, operator answer, EM tie-in |
| Lv.3 | conscience_level_3.js |
rule pipeline, EM wait, motor gates |
| Lv.4 / gestalt | conscience_level_4.js, gestalt.js |
see about_gestalt.md |
| Shared helpers | infofunctions.js |
info_automatismWithEpisodeFeedbackAndExpireCycle, EM rule lookup |
Details and current conventions — beast/_9_Conscience/about_conscience.md, about_adaptivity_levels_2_4.md.
10. Episodic memory and action images
episodic_memory.js— frames, waiting,effect, operator link.actions_image.js— AI (actionIds,finalImageId). Life-experience goals ingoals.jsreference AI; when loading state from IndexedDB do not break id consistency.
Principle: if you add a new “single source of truth”, define it once (as with default goal “Cry” and AI with actionIds: [1]).
11. Debugging without going mad
global.cpuls/Cur_puls_val— pulse number in logs.Consciousness_cycleAppendLog— human-readable main cycle log; rememberexpiredand{ force: true }.- EM test mode (
EpisodicMemory_testMode) — OR alerts (seeorientation_reflex.js). - “Beast activity” block — text from genetic/conditioned reflexes and automatisms (
setBeastActivityText).
12. Common pitfalls (Madness Checklist)
| Symptom | Likely cause |
|---|---|
| “Nothing happens” on stimulus | OR below OR_well_known, no terminal tree node, empty candidates |
Duplicate objects in window |
second window.StimulMotivarion_GeneticReflexes = {...} overwrote the first |
| Goal “Cry” but different action | AI desync after IndexedDB load and goal actionImageId |
| Genetic reflex does not fire | automatismRanForBranchIds, OR block, delayed reflex queue |
| Cycle log empty at start | OrientationReflex_anyStimulusReadyForOr and auto-log conditions in dispatcher |
13. How to grow the system safely
New stimulus
- Add to the right array in
stimuls.js. - Wire effects in
genetic_reflexes.js(internal and/or motor tables). - Ensure global id is built via
StimulusGlobalId_toGlobal. - If needed — UI rules (
stimuls_ui.js).
New action
BasicActionsineffectors.js(if not mirror).- Link to AI via
ActionImages_registerReaction/getOrCreateActionImageId.
New consciousness logic branch
- First — where in the pipeline (lv.2 vs 3, before or after EM wait).
- Do not break gate
awaitingAutomatismEpisodeFeedbackwithout readingconscience_level_3.jsandabout_conscience.md.
Persistence
- Find a similar module with
serialize/applyand IndexedDB. - Remember load order — after restoring AI, update dependents (e.g. goals and AI).
14. Sleep mode (beast/_12_Sleep)
- Purpose: when Beast “sleeps”, only basic context “Sleep” is active, almost all stimuli blocked (exceptions — Punishment, Howl, Siren, Growl, Fire); auto-sleep when
ConsciousnessFinCyclesTotal > 100(even with critical vitals — contexts overridden inprepare.js). - Dreams: iterate empty EM frames (stimulus and AI present, no response stimulus and no numeric
effect), new → old; per frame — main cycle inpassiveand the sameinfo_fantasizming/PassiveMode_processUnderstandingModelsas normal passive; then frame realization and reconstruction limit;SleepMode_exit(true)removes background consciousness cycles (Consciousness_deleteAllBackgroundCycles). Manual wake does not touch background. - Docs:
beast/_12_Sleep/about_sleep.md; globals — section inbeast/about_global_variables.md; script order — comment inindex.html(sleep_dream_process.jsafterfantasizming.js).
15. What to read next (order)
PROJECT_STATE_FOR_NEW_CHAT.md— architecture snapshot.beast/about_global_variables.md— globals glossary.beast/_10_Episodic_memory/about_episodic_memory_rules.md— OR, waiting, chains.beast/_8_Hippocampus/about_hippocampus.mdbeast/_9_Conscience/about_conscience.mdbeast/_6_semantic_memory/about_semantic_memory.mdbeast/_11_Automatizms/about_automatizms.mdbeast/_12_Sleep/about_sleep.md— if you touch sleep, sleep stimuli, or dreams.- Other
about_*.mdas needed for the task.
16. “Mad programmer” ethics
- Code is truth — comments and
about_*can lag; on conflict trust code and fix docs. - Small steps — one scenario, one mental test, one commit in spirit.
- Do not multiply globals without need.
- Respect the pulse — if behavior “must be right after click”, check order: UI → vitals/contexts → OR → pulse.
Manual version: 2026-03-21 (sleep mode _12_Sleep section). Beast is a living project; on major architecture changes update this file and PROJECT_STATE_FOR_NEW_CHAT.md.