Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Always-loaded core memory (key files cluster)
Owner-designated pages (always_load: true) rendered into every session,
held to a brain-wide character budget on the write path, plus the
save-before-compaction path (remember with items, the context-pressure
notice). User guide: core memory.
src/core/core-memory.ts: marking and priority normalization, settings (memory.core.*), page rendering and budget accounting,listCorePages(withdrawal-aware; a page stored in segments is read back whole up to 24 MiB, throughmaterializedSnapshotwhen withdrawn, and a larger one is left out unread and counted by doctorcore_memoryasskipped_segmented,test/large-pages/segmented-core-list.test.ts),renderCoreBlock(whole-page truncation, notice lines, withheld lines),coreRevision, the delivery sensitivity policy (applyCoreSensitivity: credential-like hits withhold, contact details and private paths redact) andloadCoreBlock, which every delivery lane uses.src/core/persistence/core-guard.ts: the write-path guard run frompreparePageMutation: owner-only marking (core_mark_owner_only,core_delete_owner_only), the budget (core_budget_exceeded, re-checked in the publish transaction), the remote-edit policy andcore_edit_noticesrows, andlockCoreSources.- Lock order for a core-touching publish (
coordinator.ts): worktree native lock, then the protocol declaration takes the brain row first (declareDurablePersistenceinprotocol.ts,persistence_brainFOR SHARE), thenguardOwnership(persistence_worktreesFOR SHARE), thenlockCoreSources(sourcesrows FOR UPDATE,ORDER BY id, own source plusdefault) in the source-exclusive slot, thenauthorizeStoredRequest(sourcesFOR SHARE), thenlockCounters: the global orderprotocol.tsdocuments.put_pagesbatch groups skip the per-request source lock, sogroupable()excludes core-locked writes.test/e2e/core-memory-locks-postgres.test.tsraces core writes against topology changes and a claim-shaped transaction on Postgres. scripts/check-core-guard-coverage.mjs(bun run check:core-guard-coverage, inverify): every PreparedMutation builder routes through the guard or is on its reviewed exemption list, and wrappers forwardexclusiveSources.- Delivery:
src/commands/hook.tssession-start (core first viasrc/core/context/session-start-output.ts),context_pack(src/core/ops/facts.ts,src/mcp/context-pack-handler.ts, including the read-onlycoreOnlyIPC arm), OpenClawassemble()insrc/core/context-engine.tsthroughsrc/core/context/openclaw-core.ts(60 s memo keyed on the trust cache identity fromsrc/core/eligibility/generation.ts, revalidated on every delivery: thecoreOnlyarm answerscoreTrust.unchangedfor a matchingcoreIdentity; a failed or timed-out refresh delivers no core block, never the memo), andgbrain compile-context --include-core(src/core/context/compile-view.ts,src/core/context/compiled-core.tsfor git safety and the record doctor reads). - Pressure notice:
src/core/context/pressure.ts(gate read by serve, transcript scan, window detection, once-per-segment state); wired in the user-prompt hook and OpenClawassemble(). src/core/remember-batch.ts:rememberwithitems[](all-or-none validation, deterministic child request ids, per-item status; #7248: an item still publishing ispendingwith itstarget, notfailed; #7432: every item field butfactandreplaces,entity,content_originandvalid_fromincluded, is also a top-level default an item's own value overrides).src/commands/core.ts(gbrain core),src/commands/doctor/checks/core-memory.ts(core_memory), schemasrc/core/core-memory-schema.ts+ migration v213.- Tests:
test/core-memory.test.ts,test/core-guard.test.ts,test/core-cli.test.ts,test/compile-context-core.serial.test.ts,test/context-pressure.test.ts,test/remember-batch.test.ts,test/remember-batch-entity-7432.test.ts,test/trust-cache-invalidation.test.ts(core lane after trust transitions),test/e2e/core-memory-locks-postgres.test.ts.