[{"data":1,"prerenderedAt":711},["ShallowReactive",2],{"docs-\u002Fdocs\u002Fv2\u002Fcognets\u002Fengine\u002Fworld":3},{"id":4,"title":5,"body":6,"description":704,"extension":705,"meta":706,"navigation":187,"path":707,"seo":708,"stem":709,"__hash__":710},"docs\u002Fdocs\u002Fv2\u002Fcognets\u002Fengine\u002Fworld.md","The World",{"type":7,"value":8,"toc":696},"minimark",[9,13,17,29,34,37,46,49,65,74,77,81,84,294,307,319,327,331,334,463,466,477,480,540,543,547,550,586,589,597,601,604,615,624,627,631,683,686,692],[10,11,5],"h1",{"id":12},"the-world",[14,15,16],"p",{},"Every wake constructs a world: a set of entities, the components attached to them, queries\nover both, and the tick\u002Fphase clock. It is built fresh when the wake starts and dies when\nthe loop stops.",[14,18,19,20,24,25,28],{},"Today a cognet touches one part of it directly — the clock, through ",[21,22,23],"code",{},"phase()"," and\n",[21,26,27],{},"system()",". The entity-component surface is live in the engine and drives telemetry, but\nit is not yet exposed as an authoring API. This page describes the model, why it exists,\nand what is reachable now.",[30,31,33],"h2",{"id":32},"why-cognition-is-shaped-this-way","Why cognition is shaped this way",[14,35,36],{},"The honest reason isn't the game-dev pedigree. It's this:",[38,39,40],"blockquote",{},[14,41,42],{},[43,44,45],"strong",{},"A mind that must be rebuildable from a log cannot hold state that isn't serializable.",[14,47,48],{},"That's a hard constraint, and most data models fail it quietly. Objects with methods,\nclass hierarchies, closures capturing other closures, cyclic references between live\nhandles — all easy to write, and impossible to reconstruct faithfully from a replay.",[14,50,51,52,56,57,60,61,64],{},"Entity-component storage fails it ",[53,54,55],"em",{},"loudly"," instead, because it cannot represent those\nshapes at all. An ",[43,58,59],{},"entity"," is an id. A ",[43,62,63],{},"component"," is a typed record attached to that\nid. Storage is flat maps. There is nowhere to hide a function, nowhere to build a cycle,\nand nothing that means something different after a restart than it did before.",[14,66,67,68,73],{},"So the property ",[69,70,72],"a",{"href":71},"\u002Fdocs\u002Fv2\u002Fcognets\u002Fengine\u002Fmemory","Memory"," depends on — resident state is a\nprojection of the log, lose it freely — stops being a discipline you maintain and becomes\na shape you can't escape.",[14,75,76],{},"Game engines converged on ECS for cache locality and composition over inheritance. Those\nbenefits are real. But they're corroboration, not the reason. The reason is that a\nserializable world is a rebuildable one.",[30,78,80],{"id":79},"the-clock","The clock",[14,82,83],{},"This is the part a cognet drives today.",[85,86,91],"pre",{"className":87,"code":88,"language":89,"meta":90,"style":90},"language-ts shiki shiki-themes dark-plus","loop(async ({ stop }) => {\n    const observations = await phase(\"sense\", async () => {\n        return readEverythingNew()\n    })\n\n    await phase(\"think\", async () => {\n        await system(\"score-candidates\", async () => { \u002F* ... *\u002F })\n        await system(\"pick-action\", async () => { \u002F* ... *\u002F })\n    })\n\n    stop()\n})\n","ts","",[21,92,93,126,164,176,182,189,212,244,270,275,280,288],{"__ignoreMap":90},[94,95,98,102,106,110,113,117,120,123],"span",{"class":96,"line":97},"line",1,[94,99,101],{"class":100},"sCudf","loop",[94,103,105],{"class":104},"sTNBD","(",[94,107,109],{"class":108},"scz_3","async",[94,111,112],{"class":104}," ({ ",[94,114,116],{"class":115},"s3F5K","stop",[94,118,119],{"class":104}," }) ",[94,121,122],{"class":108},"=>",[94,124,125],{"class":104}," {\n",[94,127,129,132,136,139,143,146,148,152,155,157,160,162],{"class":96,"line":128},2,[94,130,131],{"class":108},"    const",[94,133,135],{"class":134},"s9McN"," observations",[94,137,138],{"class":104}," = ",[94,140,142],{"class":141},"sYbnZ","await",[94,144,145],{"class":100}," phase",[94,147,105],{"class":104},[94,149,151],{"class":150},"sKc5r","\"sense\"",[94,153,154],{"class":104},", ",[94,156,109],{"class":108},[94,158,159],{"class":104}," () ",[94,161,122],{"class":108},[94,163,125],{"class":104},[94,165,167,170,173],{"class":96,"line":166},3,[94,168,169],{"class":141},"        return",[94,171,172],{"class":100}," readEverythingNew",[94,174,175],{"class":104},"()\n",[94,177,179],{"class":96,"line":178},4,[94,180,181],{"class":104},"    })\n",[94,183,185],{"class":96,"line":184},5,[94,186,188],{"emptyLinePlaceholder":187},true,"\n",[94,190,192,195,197,199,202,204,206,208,210],{"class":96,"line":191},6,[94,193,194],{"class":141},"    await",[94,196,145],{"class":100},[94,198,105],{"class":104},[94,200,201],{"class":150},"\"think\"",[94,203,154],{"class":104},[94,205,109],{"class":108},[94,207,159],{"class":104},[94,209,122],{"class":108},[94,211,125],{"class":104},[94,213,215,218,221,223,226,228,230,232,234,237,241],{"class":96,"line":214},7,[94,216,217],{"class":141},"        await",[94,219,220],{"class":100}," system",[94,222,105],{"class":104},[94,224,225],{"class":150},"\"score-candidates\"",[94,227,154],{"class":104},[94,229,109],{"class":108},[94,231,159],{"class":104},[94,233,122],{"class":108},[94,235,236],{"class":104}," { ",[94,238,240],{"class":239},"sOLPB","\u002F* ... *\u002F",[94,242,243],{"class":104}," })\n",[94,245,247,249,251,253,256,258,260,262,264,266,268],{"class":96,"line":246},8,[94,248,217],{"class":141},[94,250,220],{"class":100},[94,252,105],{"class":104},[94,254,255],{"class":150},"\"pick-action\"",[94,257,154],{"class":104},[94,259,109],{"class":108},[94,261,159],{"class":104},[94,263,122],{"class":108},[94,265,236],{"class":104},[94,267,240],{"class":239},[94,269,243],{"class":104},[94,271,273],{"class":96,"line":272},9,[94,274,181],{"class":104},[94,276,278],{"class":96,"line":277},10,[94,279,188],{"emptyLinePlaceholder":187},[94,281,283,286],{"class":96,"line":282},11,[94,284,285],{"class":100},"    stop",[94,287,175],{"class":104},[94,289,291],{"class":96,"line":290},12,[94,292,293],{"class":104},"})\n",[14,295,296,154,299,302,303,306],{},[21,297,298],{},"tick",[21,300,301],{},"phase",", and ",[21,304,305],{},"system"," are the only writers of the world clock. Every component\nand entity mutation the engine performs is stamped with the tick and phase it happened\nin, which is what makes the mutation history replayable against the clock rather than\njust a flat log of writes.",[14,308,309,311,312,315,316,318],{},[21,310,23],{}," names a stage and sets ",[21,313,314],{},"state.phase"," for its duration. ",[21,317,27],{}," names a unit\nof work inside a phase and times it. The naming is ECS naming on purpose: a system is\nwork that runs against the world.",[14,320,321,322,326],{},"See ",[69,323,325],{"href":324},"\u002Fdocs\u002Fv2\u002Fcognets\u002Fengine\u002Floop","The Loop"," for the full semantics.",[30,328,330],{"id":329},"the-component-model","The component model",[14,332,333],{},"Components are typed through a registry extended by declaration merging:",[85,335,337],{"className":87,"code":336,"language":89,"meta":90,"style":90},"declare module \"@axon\u002Fcore\" {\n    interface ComponentRegistry {\n        position: { x: number; y: number; z: number }\n        velocity: { dx: number; dy: number; dz: number }\n        goal: { text: string }\n    }\n}\n",[21,338,339,352,363,402,436,453,458],{"__ignoreMap":90},[94,340,341,344,347,350],{"class":96,"line":97},[94,342,343],{"class":108},"declare",[94,345,346],{"class":108}," module",[94,348,349],{"class":150}," \"@axon\u002Fcore\"",[94,351,125],{"class":104},[94,353,354,357,361],{"class":96,"line":128},[94,355,356],{"class":108},"    interface",[94,358,360],{"class":359},"sNl3T"," ComponentRegistry",[94,362,125],{"class":104},[94,364,365,368,371,374,377,380,383,386,388,390,392,395,397,399],{"class":96,"line":166},[94,366,367],{"class":115},"        position",[94,369,370],{"class":104},": { ",[94,372,373],{"class":115},"x",[94,375,376],{"class":104},": ",[94,378,379],{"class":359},"number",[94,381,382],{"class":104},"; ",[94,384,385],{"class":115},"y",[94,387,376],{"class":104},[94,389,379],{"class":359},[94,391,382],{"class":104},[94,393,394],{"class":115},"z",[94,396,376],{"class":104},[94,398,379],{"class":359},[94,400,401],{"class":104}," }\n",[94,403,404,407,409,412,414,416,418,421,423,425,427,430,432,434],{"class":96,"line":178},[94,405,406],{"class":115},"        velocity",[94,408,370],{"class":104},[94,410,411],{"class":115},"dx",[94,413,376],{"class":104},[94,415,379],{"class":359},[94,417,382],{"class":104},[94,419,420],{"class":115},"dy",[94,422,376],{"class":104},[94,424,379],{"class":359},[94,426,382],{"class":104},[94,428,429],{"class":115},"dz",[94,431,376],{"class":104},[94,433,379],{"class":359},[94,435,401],{"class":104},[94,437,438,441,443,446,448,451],{"class":96,"line":184},[94,439,440],{"class":115},"        goal",[94,442,370],{"class":104},[94,444,445],{"class":115},"text",[94,447,376],{"class":104},[94,449,450],{"class":359},"string",[94,452,401],{"class":104},[94,454,455],{"class":96,"line":191},[94,456,457],{"class":104},"    }\n",[94,459,460],{"class":96,"line":214},[94,461,462],{"class":104},"}\n",[14,464,465],{},"The registry is empty by default — a cognet declares the vocabulary of its own world, and\nevery query is typed against it.",[14,467,468,469,472,473,476],{},"Writes go through a single path. ",[21,470,471],{},"Entity.add()"," delegates to ",[21,474,475],{},"Component.add()"," rather\nthan touching storage, so there is exactly one place a component can change. That is what\nmakes telemetry and watchers reliable rather than best-effort, and it is why watchers can\nfire synchronously inside the write.",[14,478,479],{},"Queries narrow in four steps:",[481,482,483,496],"table",{},[484,485,486],"thead",{},[487,488,489,493],"tr",{},[490,491,492],"th",{},"Field",[490,494,495],{},"Effect",[497,498,499,510,520,530],"tbody",{},[487,500,501,507],{},[502,503,504],"td",{},[21,505,506],{},"with",[502,508,509],{},"entity must hold every listed component; they arrive typed in the result",[487,511,512,517],{},[502,513,514],{},[21,515,516],{},"without",[502,518,519],{},"entity must hold none of the listed components",[487,521,522,527],{},[502,523,524],{},[21,525,526],{},"where",[502,528,529],{},"exact-match on component values",[487,531,532,537],{},[502,533,534],{},[21,535,536],{},"filter",[502,538,539],{},"arbitrary predicate over the typed result",[14,541,542],{},"Intersection starts from the smallest matching store, so a query joining a rare component\nagainst a common one costs the size of the rare one.",[30,544,546],{"id":545},"every-mutation-is-telemetry","Every mutation is telemetry",[14,548,549],{},"World writes emit as cognet telemetry, stamped with tick and phase:",[85,551,553],{"className":87,"code":552,"language":89,"meta":90,"style":90},"\"cognet:entity:add\"       \u002F\u002F { tick, phase, entity }\n\"cognet:entity:remove\"\n\"cognet:component:add\"    \u002F\u002F { tick, phase, entity, component }\n\"cognet:component:update\"\n\"cognet:component:remove\"\n",[21,554,555,563,568,576,581],{"__ignoreMap":90},[94,556,557,560],{"class":96,"line":97},[94,558,559],{"class":150},"\"cognet:entity:add\"",[94,561,562],{"class":239},"       \u002F\u002F { tick, phase, entity }\n",[94,564,565],{"class":96,"line":128},[94,566,567],{"class":150},"\"cognet:entity:remove\"\n",[94,569,570,573],{"class":96,"line":166},[94,571,572],{"class":150},"\"cognet:component:add\"",[94,574,575],{"class":239},"    \u002F\u002F { tick, phase, entity, component }\n",[94,577,578],{"class":96,"line":178},[94,579,580],{"class":150},"\"cognet:component:update\"\n",[94,582,583],{"class":96,"line":184},[94,584,585],{"class":150},"\"cognet:component:remove\"\n",[14,587,588],{},"The world isn't only queryable at runtime — its entire mutation history is recorded\nagainst the clock, so you can replay exactly which phase of which tick added, changed, or\nremoved anything.",[14,590,591,592,596],{},"These land in the log's telemetry view and forward to the runtime bus — debugging record,\nnever rendered to the user as part of the conversation. See\n",[69,593,595],{"href":594},"\u002Fdocs\u002Fv2\u002Fcognets\u002Fengine\u002Fobservability","Observability",".",[30,598,600],{"id":599},"the-world-is-per-wake","The world is per-wake",[14,602,603],{},"The world dies when the wake ends, and that is deliberate.",[14,605,606,607,610,611,614],{},"It is a ",[43,608,609],{},"working set"," — the structured view a wake builds in order to think. It is not\nmemory. Persistence lives in the session log; durable cognitive state lives in\n",[21,612,613],{},"kernel.store",". If an entity matters beyond this wake, it was derived from something in\nthe log, and the next wake derives it again.",[14,616,617,620,621,623],{},[21,618,619],{},"zero"," sits at one extreme: it holds no entities at all. Its resident model is the folded\nlog, and it uses the world purely for ",[21,622,23],{}," timing. That is a legitimate way to use\nthe engine — the world is available, not mandatory.",[14,625,626],{},"A perception stack sits at the other: hundreds of entities rebuilt from sensor stimuli\nevery tick, queried, acted on, discarded. Same machinery, opposite fill rate.",[30,628,630],{"id":629},"whats-reachable-today","What's reachable today",[481,632,633,643],{},[484,634,635],{},[487,636,637,640],{},[490,638,639],{},"Surface",[490,641,642],{},"Status",[497,644,645,657,665,673],{},[487,646,647,654],{},[502,648,649,651,652],{},[21,650,23],{}," \u002F ",[21,653,27],{},[502,655,656],{},"ambient globals, available now",[487,658,659,662],{},[502,660,661],{},"tick clock and its telemetry",[502,663,664],{},"driven by the host, emitted automatically",[487,666,667,670],{},[502,668,669],{},"entity \u002F component \u002F query \u002F watch",[502,671,672],{},"live in the engine, not yet exposed to cognet source",[487,674,675,680],{},[502,676,677],{},[21,678,679],{},"ComponentRegistry",[502,681,682],{},"declared and typed, ready for the authoring surface",[14,684,685],{},"The engine builds a world for every wake regardless, because the clock and its telemetry\ndepend on it. Exposing the entity-component surface to authors is a deliberate next step\nrather than an oversight: it wants a real workload — most likely the first continuous\ncognet — to settle what the ambient API should look like before it becomes contract.",[14,687,688,689,691],{},"Until then, a cognet's world model is whatever it holds in module scope, and ",[21,690,619],{},"'s\nlog-shaped approach is the reference pattern.",[693,694,695],"style",{},"html pre.shiki code .sCudf, html code.shiki .sCudf{--shiki-default:#DCDCAA}html pre.shiki code .sTNBD, html code.shiki .sTNBD{--shiki-default:#D4D4D4}html pre.shiki code .scz_3, html code.shiki .scz_3{--shiki-default:#569CD6}html pre.shiki code .s3F5K, html code.shiki .s3F5K{--shiki-default:#9CDCFE}html pre.shiki code .s9McN, html code.shiki .s9McN{--shiki-default:#4FC1FF}html pre.shiki code .sYbnZ, html code.shiki .sYbnZ{--shiki-default:#C586C0}html pre.shiki code .sKc5r, html code.shiki .sKc5r{--shiki-default:#CE9178}html pre.shiki code .sOLPB, html code.shiki .sOLPB{--shiki-default:#6A9955}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sNl3T, html code.shiki .sNl3T{--shiki-default:#4EC9B0}",{"title":90,"searchDepth":128,"depth":128,"links":697},[698,699,700,701,702,703],{"id":32,"depth":128,"text":33},{"id":79,"depth":128,"text":80},{"id":329,"depth":128,"text":330},{"id":545,"depth":128,"text":546},{"id":599,"depth":128,"text":600},{"id":629,"depth":128,"text":630},"The entity-component model behind the clock, and why cognition is shaped like a game world.","md",{},"\u002Fdocs\u002Fv2\u002Fcognets\u002Fengine\u002Fworld",{"title":5,"description":704},"docs\u002Fv2\u002Fcognets\u002Fengine\u002Fworld","a0Yd0RWSTN4xW0d5k_xwyjiqGQ7REkG-3-QGqdl4_JE",1785156432053]