Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Key files: Derived generations
Subsystem index. Read only the entries relevant to your change. Current behavior and load-bearing invariants; history belongs in Git and CHANGELOG.
src/core/generations/{contract,plan,publish,proofs,config,repair,ledger-scrub}.ts+adapters/{page,atoms,index}.ts(GBRA-161) — the generation primitive: one ledger row per derived key generation (derived_generations, items and bounded preimages inderived_generation_items);publishGenerationholds a shrunk, oversize, unproven-empty, valve or segmented result and otherwise writes, completes, rechecks, retires (versioned, stamped) and activates in one transaction.gbrain repair generationsrestores or releases from previews; doctorgeneration_retirements/generation_held. Reference: generations. Tests:test/pathological/g1-generations.test.ts,test/pathological/g1-atom-generations.test.ts.src/core/generations/fence-evidence.ts(#8819) —factsFenceHeld: which positioned fact rows of a page some fence held at the same row number, claim and visibility (a non-retired item of anyfact_fencegeneration of the page, the replaced body's rows frompageFenceRowKeys, which reads a segmented page from its marker segments, or a storedpage_versionsbody, newest first, at most 1000;completeis false past that or when a version has no body, as a segmented snapshot has none). The page projection (projectFactFenceGeneration, which returnsretireIdsandkept) retires only held rows, rows whose claim the incoming fence states, and conversation-extractor rows a fence row displaces; the managedextract_factsreconcile keeps the other unheld stale rows out of its retirements.moveKeptRowsmoves a kept row whose number an incoming fence row claims above every row of the page. The projection's evidence is also whycanonical-projections.tsreads the prior fence before publication. Tests:test/fence-first-generation-8819.test.ts(PGLite and Postgres).src/core/repair/unwithdrawn-facts.ts—gbrain repair unwithdrawn-facts(#8819), explicit-only and preview-bound.classifyUnwithdrawnFacts(read-only; also the doctor check's count) takes each fact afact_fencegeneration retired (aretiredledger item with a fact preimage that was active and positioned) whose row is still as the retirement left it (expired at the generation's instant,row_numNULL, same claim and visibility; conversation-extractor rows excluded), and classes itevidenced(no fence ever held it:generations/fence-evidence.tsover the ledger, the current page and its stored versions),ambiguous(version_history_gap_atset, or versions left unread) orexcluded:<reason>(page missing, superseded, withdrawn, changed since retirement,fence_held, active duplicate at any visibility, duplicate candidate,unmanaged_reconcileon an unmanaged brain, whose reconcile would retire a restored row again). The preview saves one item per page with its revision throughpreview-approval.ts; the apply restores the preimage's lifecycle (expired_at,valid_until,superseded_by, consolidation marks) on the same id at its recorded row number when free, else above the page's rows, after reclassifying under the page key: managed, one database-onlymanaged_maintenance_restore_unwithdrawn_factsrequest per page bound to the previewed revision (prepareUnwithdrawnFactsRestore, refusingrevision_conflict); unmanaged, a page-lockedmaintenanceTransactionthat refuses a changed revision and reclassifies (so restores nothing). Doctorunwithdrawn_facts(commands/doctor/checks/unwithdrawn-facts.ts). Tests:test/repair-unwithdrawn-facts-8819.test.ts(PGLite and Postgres).src/commands/doctor/checks/unwithdrawn-facts.ts— doctorunwithdrawn_facts(#8819): counts those retirements by class throughclassifyUnwithdrawnFacts(excludedreported, never a finding) and names thegbrain repair unwithdrawn-factspreview. Read-only.src/core/generations/adapters/synthesis.ts,src/core/generations/synthesis-coverage.ts,src/core/generations/managed-retire.ts,src/core/cycle/synthesize-generations.ts(GBRA-161 PR 4, #7065) — synthesis on the primitive: each re-synthesized transcript's outputs become itssynthesisgeneration after postprocess; an earlier output retires (versioned,synthesis-resynthesis) only when it is an exact duplicate or the same subject with every claim, quote and citation covered (pure match insynthesis-coverage.ts); others stay live andgbrain repair generations --kind synthesis --mode cleanuplists and, on apply, retires them (synthesis-cleanup). A chunk failure, deferral orgenerations.synthesis.retire_previous=falsemakes the generation partial. Managed brains admit the activation plus onemanaged_generation_retiredelete per retirement (managed-retire.ts). Reference: generations. Tests:test/pathological/g4-synthesis-resynthesis-7065.test.ts.src/core/generations/adapters/single-page.ts(GBRA-161 PR 5) — dream summary,thinkpage and drift report as single-item generations: revision-bound, versioned first, restorable. Reference: generations. Tests:test/pathological/g5-*tog7-*.