Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge remote-tracking branch 'origin/capy/gbra131-overwrite-class' into capy/gbra131-derived
garrytan60e827cd9cf3
diff --cc src/core/facts/file-body-guard.tsindex 6488990e08,772778c859..66225e13a9--- a/src/core/facts/file-body-guard.ts+++ b/src/core/facts/file-body-guard.ts@@@ -13,8 -13,9 +13,9 @@@import { existsSync, readFileSync } from 'node:fs';import type { BrainEngine } from '../engine.ts';import { sanitizeText } from '../batch-rows.ts';-import { parseMarkdown } from '../markdown.ts';+import { parseMarkdown, parseMarkdownHead } from '../markdown.ts';import { contentHash, contentHashFrontmatterAndTags } from '../utils.ts';+ import { stableJson } from '../persistence/digest.ts';export interface StoredBody {compiled_truth: string | null;@@@ -60,28 -70,14 +70,28 @@@ export async function mirrorFileBody(tx/** Page states a checkout file is compared with: the live row, then its newest page_versions rows. */const HISTORY_ROWS = 20;-interface StoredState extends StoredBody { frontmatter: Record<string, unknown> | null }+interface StoredState extends StoredBody {+ frontmatter: Record<string, unknown> | null;+ title: string | null;+ type: string | null;+ tags: unknown;+}-/** Whether the file's body, timeline and every frontmatter key it carries (ephemeral keys aside) equal `state`'s. */+/**+ * Whether the file's body, timeline, every frontmatter key it carries (ephemeral keys aside), its tags, and the title+ * and type its frontmatter declares equal `state`'s.+ */function fileHeldBy(fileBytes: string, slug: string, state: StoredState): boolean {if (!fileBodyMatchesStored(fileBytes, slug, state)) return false;- const file = contentHashFrontmatterAndTags({ frontmatter: parseMarkdown(fileBytes, `${slug}.md`).frontmatter });+ const parsed = parseMarkdown(fileBytes, `${slug}.md`);+ const declared = parseMarkdownHead(fileBytes).frontmatter;+ if (declared.title !== undefined && parsed.title.trim() !== (state.title ?? '').trim()) return false;+ if (parsed.typeExplicit && parsed.type !== state.type) return false;+ const storedTags = Array.isArray(state.tags) ? state.tags.map(String) : [];+ if (JSON.stringify([...new Set(parsed.tags)].sort()) !== JSON.stringify([...new Set(storedTags)].sort())) return false;+ const file = contentHashFrontmatterAndTags({ frontmatter: parsed.frontmatter });const stored = contentHashFrontmatterAndTags({ frontmatter: state.frontmatter ?? {} });- return Object.entries(file.frontmatter).every(([key, value]) => JSON.stringify(value) === JSON.stringify(stored.frontmatter[key]));+ return Object.entries(file.frontmatter).every(([key, value]) => stableJson(value) === stableJson(stored.frontmatter[key]));}/**