[{"data":1,"prerenderedAt":620},["ShallowReactive",2],{"docs-\u002Fdocs\u002Fv2\u002Fcognets\u002Ffolder\u002Fstate":3},{"id":4,"title":5,"body":6,"description":613,"extension":614,"meta":615,"navigation":79,"path":616,"seo":617,"stem":618,"__hash__":619},"docs\u002Fdocs\u002Fv2\u002Fcognets\u002Ffolder\u002Fstate.md","src\u002Fstate.ts",{"type":7,"value":8,"toc":607},"minimark",[9,13,26,35,334,341,346,360,414,417,421,432,435,482,485,489,498,505,512,515,519,525,586,592,603],[10,11,5],"h1",{"id":12},"srcstatets",[14,15,16,17,21,22,25],"p",{},"There is no required file here. ",[18,19,20],"code",{},"state.ts"," is a convention, not a contract: the engine\nnever reads it, and a cognet that keeps everything in ",[18,23,24],{},"main.ts"," is perfectly valid.",[14,27,28,29,31,32,34],{},"The convention exists because resident memory is worth isolating. ",[18,30,24],{}," is the\npipeline; ",[18,33,20],{}," is what the pipeline operates on, shared by plain import with\nwhatever else needs it.",[36,37,42],"pre",{"className":38,"code":39,"language":40,"meta":41,"style":41},"language-ts shiki shiki-themes dark-plus","import type { AxonEntry } from \"@arcforge\u002Ftypes\"\n\nexport type ZeroState = {\n    \u002F** the folded episodic log, in seq order — what render() sees *\u002F\n    entries: AxonEntry[]\n    \u002F** high-water mark: the last seq folded. -1 = nothing yet. *\u002F\n    seq: number\n}\n\nexport const state: ZeroState = {\n    entries: [],\n    seq: -1,\n}\n\nexport function sync(): void {\n    for (const entry of kernel.store.session.get({ after: state.seq })) {\n        state.entries.push(entry)\n        state.seq = entry.time.seq\n    }\n}\n","ts","",[18,43,44,74,81,97,104,118,124,135,141,146,165,174,190,195,200,221,274,299,323,329],{"__ignoreMap":41},[45,46,49,53,56,60,64,67,70],"span",{"class":47,"line":48},"line",1,[45,50,52],{"class":51},"sYbnZ","import",[45,54,55],{"class":51}," type",[45,57,59],{"class":58},"sTNBD"," { ",[45,61,63],{"class":62},"s3F5K","AxonEntry",[45,65,66],{"class":58}," } ",[45,68,69],{"class":51},"from",[45,71,73],{"class":72},"sKc5r"," \"@arcforge\u002Ftypes\"\n",[45,75,77],{"class":47,"line":76},2,[45,78,80],{"emptyLinePlaceholder":79},true,"\n",[45,82,84,87,90,94],{"class":47,"line":83},3,[45,85,86],{"class":51},"export",[45,88,55],{"class":89},"scz_3",[45,91,93],{"class":92},"sNl3T"," ZeroState",[45,95,96],{"class":58}," = {\n",[45,98,100],{"class":47,"line":99},4,[45,101,103],{"class":102},"sOLPB","    \u002F** the folded episodic log, in seq order — what render() sees *\u002F\n",[45,105,107,110,113,115],{"class":47,"line":106},5,[45,108,109],{"class":62},"    entries",[45,111,112],{"class":58},": ",[45,114,63],{"class":92},[45,116,117],{"class":58},"[]\n",[45,119,121],{"class":47,"line":120},6,[45,122,123],{"class":102},"    \u002F** high-water mark: the last seq folded. -1 = nothing yet. *\u002F\n",[45,125,127,130,132],{"class":47,"line":126},7,[45,128,129],{"class":62},"    seq",[45,131,112],{"class":58},[45,133,134],{"class":92},"number\n",[45,136,138],{"class":47,"line":137},8,[45,139,140],{"class":58},"}\n",[45,142,144],{"class":47,"line":143},9,[45,145,80],{"emptyLinePlaceholder":79},[45,147,149,151,154,158,160,163],{"class":47,"line":148},10,[45,150,86],{"class":51},[45,152,153],{"class":89}," const",[45,155,157],{"class":156},"s9McN"," state",[45,159,112],{"class":58},[45,161,162],{"class":92},"ZeroState",[45,164,96],{"class":58},[45,166,168,171],{"class":47,"line":167},11,[45,169,170],{"class":62},"    entries:",[45,172,173],{"class":58}," [],\n",[45,175,177,180,183,187],{"class":47,"line":176},12,[45,178,179],{"class":62},"    seq:",[45,181,182],{"class":58}," -",[45,184,186],{"class":185},"sDGX8","1",[45,188,189],{"class":58},",\n",[45,191,193],{"class":47,"line":192},13,[45,194,140],{"class":58},[45,196,198],{"class":47,"line":197},14,[45,199,80],{"emptyLinePlaceholder":79},[45,201,203,205,208,212,215,218],{"class":47,"line":202},15,[45,204,86],{"class":51},[45,206,207],{"class":89}," function",[45,209,211],{"class":210},"sCudf"," sync",[45,213,214],{"class":58},"(): ",[45,216,217],{"class":92},"void",[45,219,220],{"class":58}," {\n",[45,222,224,227,230,233,236,239,242,245,248,250,253,255,258,261,264,266,268,271],{"class":47,"line":223},16,[45,225,226],{"class":51},"    for",[45,228,229],{"class":58}," (",[45,231,232],{"class":89},"const",[45,234,235],{"class":156}," entry",[45,237,238],{"class":89}," of",[45,240,241],{"class":62}," kernel",[45,243,244],{"class":58},".",[45,246,247],{"class":62},"store",[45,249,244],{"class":58},[45,251,252],{"class":62},"session",[45,254,244],{"class":58},[45,256,257],{"class":210},"get",[45,259,260],{"class":58},"({ ",[45,262,263],{"class":62},"after:",[45,265,157],{"class":62},[45,267,244],{"class":58},[45,269,270],{"class":62},"seq",[45,272,273],{"class":58}," })) {\n",[45,275,277,280,282,285,287,290,293,296],{"class":47,"line":276},17,[45,278,279],{"class":62},"        state",[45,281,244],{"class":58},[45,283,284],{"class":62},"entries",[45,286,244],{"class":58},[45,288,289],{"class":210},"push",[45,291,292],{"class":58},"(",[45,294,295],{"class":62},"entry",[45,297,298],{"class":58},")\n",[45,300,302,304,306,308,311,313,315,318,320],{"class":47,"line":301},18,[45,303,279],{"class":62},[45,305,244],{"class":58},[45,307,270],{"class":62},[45,309,310],{"class":58}," = ",[45,312,295],{"class":62},[45,314,244],{"class":58},[45,316,317],{"class":62},"time",[45,319,244],{"class":58},[45,321,322],{"class":62},"seq\n",[45,324,326],{"class":47,"line":325},19,[45,327,328],{"class":58},"    }\n",[45,330,332],{"class":47,"line":331},20,[45,333,140],{"class":58},[14,335,336,337,340],{},"That's ",[18,338,339],{},"zero","'s entire memory system.",[342,343,345],"h2",{"id":344},"one-copy-per-brain","One copy per brain",[14,347,348,349,351,352,355,356,359],{},"The compile step bundles ",[18,350,24],{},", ",[18,353,354],{},"plugins\u002F",", and everything they import into a single\nartifact. So a plain ",[18,357,358],{},"import { state } from \".\u002Fstate\""," from two places gives you the same\nobject — module scope is the sharing mechanism, and there is exactly one copy per brain.",[36,361,363],{"className":38,"code":362,"language":40,"meta":41,"style":41},"\u002F\u002F main.ts\nimport { state, sync } from \".\u002Fstate\"\n\n\u002F\u002F plugins\u002Fsetup.ts\nimport { state } from \".\u002Fstate\"\n",[18,364,365,370,391,395,400],{"__ignoreMap":41},[45,366,367],{"class":47,"line":48},[45,368,369],{"class":102},"\u002F\u002F main.ts\n",[45,371,372,374,376,379,381,384,386,388],{"class":47,"line":76},[45,373,52],{"class":51},[45,375,59],{"class":58},[45,377,378],{"class":62},"state",[45,380,351],{"class":58},[45,382,383],{"class":62},"sync",[45,385,66],{"class":58},[45,387,69],{"class":51},[45,389,390],{"class":72}," \".\u002Fstate\"\n",[45,392,393],{"class":47,"line":83},[45,394,80],{"emptyLinePlaceholder":79},[45,396,397],{"class":47,"line":99},[45,398,399],{"class":102},"\u002F\u002F plugins\u002Fsetup.ts\n",[45,401,402,404,406,408,410,412],{"class":47,"line":106},[45,403,52],{"class":51},[45,405,59],{"class":58},[45,407,378],{"class":62},[45,409,66],{"class":58},[45,411,69],{"class":51},[45,413,390],{"class":72},[14,415,416],{},"No registry, no injection, no singleton ceremony. Ordinary module semantics.",[342,418,420],{"id":419},"shape-it-however-you-like","Shape it however you like",[14,422,423,425,426,431],{},[18,424,339],{}," holds the folded log and nothing else. That's a deliberate reference pattern — see\n",[427,428,430],"a",{"href":429},"\u002Fdocs\u002Fv2\u002Fcognets\u002Fengine\u002Fmemory","Memory"," for why a log-shaped model is trivially\nrebuildable and verifiable — but it is not the only shape.",[14,433,434],{},"A perception cognet might hold a spatial index. A planner might hold a task tree. A\ncontroller might hold three floats:",[36,436,438],{"className":38,"code":437,"language":40,"meta":41,"style":41},"export const state = {\n    integral: 0,\n    previous: 0,\n    lastCommand: 0,\n}\n",[18,439,440,450,460,469,478],{"__ignoreMap":41},[45,441,442,444,446,448],{"class":47,"line":48},[45,443,86],{"class":51},[45,445,153],{"class":89},[45,447,157],{"class":156},[45,449,96],{"class":58},[45,451,452,455,458],{"class":47,"line":76},[45,453,454],{"class":62},"    integral:",[45,456,457],{"class":185}," 0",[45,459,189],{"class":58},[45,461,462,465,467],{"class":47,"line":83},[45,463,464],{"class":62},"    previous:",[45,466,457],{"class":185},[45,468,189],{"class":58},[45,470,471,474,476],{"class":47,"line":99},[45,472,473],{"class":62},"    lastCommand:",[45,475,457],{"class":185},[45,477,189],{"class":58},[45,479,480],{"class":47,"line":106},[45,481,140],{"class":58},[14,483,484],{},"The engine has no opinion. It never reads your state, never serializes it, and never\nrestores it.",[342,486,488],{"id":487},"the-one-rule","The one rule",[490,491,492],"blockquote",{},[14,493,494],{},[495,496,497],"strong",{},"Nothing here is authoritative.",[14,499,500,501,504],{},"Resident memory must be reconstructible from the durable record. If losing this object on\na restart would lose information the cognet needs, it belonged in the session log or in\n",[18,502,503],{},"kernel.store"," — not here.",[14,506,507,508,511],{},"That constraint is what makes ",[18,509,510],{},"kill -9"," free. Kill the process at any point, restart, and\nthe brain rebuilds from the log with nothing missing. There is no shutdown hook that must\nrun and no flush that must complete, because nothing in RAM was the source of truth.",[14,513,514],{},"Get this wrong and you've built a mind that can only survive a graceful shutdown. For a\nlong-running agent that's an inconvenience. For an embodied system that can lose power\nmid-decision, it's a design failure.",[342,516,518],{"id":517},"typing-the-private-store","Typing the private store",[14,520,521,522,524],{},"If your cognet uses ",[18,523,503],{},", declare its schema here by declaration merging:",[36,526,528],{"className":38,"code":527,"language":40,"meta":41,"style":41},"declare global {\n    interface CognetStoreSchema {\n        checkpoint: { seq: number; savedAt: number }\n    }\n}\n",[18,529,530,540,550,578,582],{"__ignoreMap":41},[45,531,532,535,538],{"class":47,"line":48},[45,533,534],{"class":89},"declare",[45,536,537],{"class":62}," global",[45,539,220],{"class":58},[45,541,542,545,548],{"class":47,"line":76},[45,543,544],{"class":89},"    interface",[45,546,547],{"class":92}," CognetStoreSchema",[45,549,220],{"class":58},[45,551,552,555,558,560,562,565,568,571,573,575],{"class":47,"line":83},[45,553,554],{"class":62},"        checkpoint",[45,556,557],{"class":58},": { ",[45,559,270],{"class":62},[45,561,112],{"class":58},[45,563,564],{"class":92},"number",[45,566,567],{"class":58},"; ",[45,569,570],{"class":62},"savedAt",[45,572,112],{"class":58},[45,574,564],{"class":92},[45,576,577],{"class":58}," }\n",[45,579,580],{"class":47,"line":99},[45,581,328],{"class":58},[45,583,584],{"class":47,"line":106},[45,585,140],{"class":58},[14,587,588,591],{},[18,589,590],{},"kernel.store.get(\"checkpoint\")"," is then typed, and a key you never declared is a compile\nerror rather than a runtime surprise.",[14,593,594,595,598,599,602],{},"Keep what goes in there small. Reads return ",[18,596,597],{},"null"," when absent ",[495,600,601],{},"or unreadable"," — cache\ndoctrine: rebuild, don't crash. If losing a key can break your cognet, it belonged in the\nlog.",[604,605,606],"style",{},"html pre.shiki code .sYbnZ, html code.shiki .sYbnZ{--shiki-default:#C586C0}html pre.shiki code .sTNBD, html code.shiki .sTNBD{--shiki-default:#D4D4D4}html pre.shiki code .s3F5K, html code.shiki .s3F5K{--shiki-default:#9CDCFE}html pre.shiki code .sKc5r, html code.shiki .sKc5r{--shiki-default:#CE9178}html pre.shiki code .scz_3, html code.shiki .scz_3{--shiki-default:#569CD6}html pre.shiki code .sNl3T, html code.shiki .sNl3T{--shiki-default:#4EC9B0}html pre.shiki code .sOLPB, html code.shiki .sOLPB{--shiki-default:#6A9955}html pre.shiki code .s9McN, html code.shiki .s9McN{--shiki-default:#4FC1FF}html pre.shiki code .sDGX8, html code.shiki .sDGX8{--shiki-default:#B5CEA8}html pre.shiki code .sCudf, html code.shiki .sCudf{--shiki-default:#DCDCAA}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);}",{"title":41,"searchDepth":76,"depth":76,"links":608},[609,610,611,612],{"id":344,"depth":76,"text":345},{"id":419,"depth":76,"text":420},{"id":487,"depth":76,"text":488},{"id":517,"depth":76,"text":518},"The resident model — module scope as the brain's RAM.","md",{},"\u002Fdocs\u002Fv2\u002Fcognets\u002Ffolder\u002Fstate",{"title":5,"description":613},"docs\u002Fv2\u002Fcognets\u002Ffolder\u002Fstate","AT3olMEBLkEnUeDIclhMrlLSynmE7GSCV163Eo1oA6I",1785156432113]