Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
sync: keepGrandfatherStamp lives with alignWithStored, which import now shares (module-size)
garrytanc890a13c38e2
diff --git a/src/core/import-file.ts b/src/core/import-file.tsindex 7ec0ce81fa..f81d0b306a 100644--- a/src/core/import-file.ts+++ b/src/core/import-file.ts@@ -11,7 +11,8 @@ import { readFileSync, statSync, lstatSync } from 'fs';import { basename, extname, resolve } from 'path';import { createHash } from 'crypto';import type { BrainEngine, FileSpec } from './engine.ts';-import { classifyImportHold, keepGrandfatherStamp, parseMarkdown, resolveParsedSubtype, type ParseOpts, type ParsedMarkdown } from './markdown.ts';+import { classifyImportHold, parseMarkdown, resolveParsedSubtype, type ParseOpts, type ParsedMarkdown } from './markdown.ts';+import { alignWithStored } from './persistence/align-stored.ts';import { CODE_FILE_MAX_BYTES, isLargePageBytes } from './page-size-policy.ts';import { importSizeLimit, MAX_FILE_SIZE, screenImportContent, settleContentDisposition, stripGateOwnedMarkers, type ContentRefusal, type FenceScreen } from './import-screen.ts';import type { WriteGateAssessment, WriteGateInput } from './write-gate.ts';@@ -477,12 +478,9 @@ export async function importFromContent(// means "preserve the stored type", not "re-infer". Pre-fix, a round-trip// put (get_page → edit body → put_page without `type:`) silently regressed// a curated type to the path-inferred default ('concept' for bare slugs).- // Explicit frontmatter type stays an override; new pages still infer.- if (parsed.typeExplicit !== true && existing) {- parsed.type = existing.type;- }- resolveParsedSubtype(parsed, existing);- keepGrandfatherStamp(parsed.frontmatter, existing);+ // Explicit frontmatter type stays an override; new pages still infer. The stored subtype and grandfather stamp are kept too.+ if (existing) alignWithStored(parsed, existing, false);+ else resolveParsedSubtype(parsed, existing);// Alias-footgun visibility: an explicit frontmatter `type:` that is an// ALIAS of a canonical pack type (or entirely undeclared) is stored// literally and never re-normalized — different agents can silently filediff --git a/src/core/markdown.ts b/src/core/markdown.tsindex 4a5a916e17..e5588d99b0 100644--- a/src/core/markdown.ts+++ b/src/core/markdown.ts@@ -501,16 +501,6 @@ export function resolveParsedSubtype(if (parsed.inferredSubtype?.type === parsed.type) parsed.frontmatter.subtype = parsed.inferredSubtype.name;}-/**- * #6429: the v0.13.1 grandfather stamped `validate: false` into the database; on an unmanaged brain that path never wrote- * the file, so the file lacks a key the database carries. The mechanical stamp authors nothing (grandfather.ts): a file- * without a `validate:` key keeps the stored stamp. GBRA-133: import and sync compare and store it the same way as the- * write guard, so a legacy page carrying the stamp is not a database edit sync cannot place.- */-export function keepGrandfatherStamp(frontmatter: Record<string, unknown>, existing?: { frontmatter?: Record<string, unknown> | null } | null): void {- if (!Object.hasOwn(frontmatter, 'validate') && existing?.frontmatter?.validate === false) frontmatter.validate = false;-}-/*** #5988 hold codes: deterministic content refusals. Ingestion holds the one* file and keeps going instead of failing the whole sync. Defined once here;diff --git a/src/core/persistence/align-stored.ts b/src/core/persistence/align-stored.tsindex 728e4c5eb8..dddc1ddc5b 100644--- a/src/core/persistence/align-stored.ts+++ b/src/core/persistence/align-stored.ts@@ -1,13 +1,23 @@-import { keepGrandfatherStamp, resolveParsedSubtype, type ParsedMarkdown } from '../markdown.ts';+import { resolveParsedSubtype, type ParsedMarkdown } from '../markdown.ts';/*** Aligns a canonical file's parse with what its import over `stored` keeps (#1035, #5521): a file without an explicit* `type:` (or whose type was only inferred from its path, #6605) keeps the stored type, and the subtype is resolved- * against that type, so the stored subtype is kept too, and so is the grandfather stamp (#6429). Import does the same, in this order. The write guard- * (page-prepare.ts) and reconcile (reconcile-state.ts, reconcile-prepare.ts) share it.+ * against that type, so the stored subtype is kept too, and so is the grandfather stamp (#6429). Import over an existing+ * page (import-file.ts), the write guard (page-prepare.ts) and reconcile (reconcile-state.ts, reconcile-prepare.ts) share it.*/export function alignWithStored(parsed: ParsedMarkdown, stored: { type: string; frontmatter?: Record<string, unknown> | null }, inferred: boolean): void {if (inferred || !parsed.typeExplicit) parsed.type = stored.type as ParsedMarkdown['type'];resolveParsedSubtype(parsed, stored);keepGrandfatherStamp(parsed.frontmatter, stored);}++/**+ * #6429: the v0.13.1 grandfather stamped `validate: false` into the database; on an unmanaged brain that path never wrote+ * the file, so the file lacks a key the database carries. The mechanical stamp authors nothing (grandfather.ts): a file+ * without a `validate:` key keeps the stored stamp. GBRA-133: import and sync compare and store it the same way as the+ * write guard, so a legacy page carrying the stamp is not a database edit sync cannot place.+ */+export function keepGrandfatherStamp(frontmatter: Record<string, unknown>, existing?: { frontmatter?: Record<string, unknown> | null } | null): void {+ if (!Object.hasOwn(frontmatter, 'validate') && existing?.frontmatter?.validate === false) frontmatter.validate = false;+}diff --git a/src/core/persistence/sync-prepare.ts b/src/core/persistence/sync-prepare.tsindex c659123979..640f5a7778 100644--- a/src/core/persistence/sync-prepare.ts+++ b/src/core/persistence/sync-prepare.ts@@ -15,7 +15,8 @@ import { matchTrustAllowRule, type TrustAllowRule } from '../trust/allow-rules.timport { importFromContent, importCodeFile, verifyPageReadable } from '../import-file.ts';import { screenImportContent, screenNormalized, type ContentRefusal, type ImportScreenResult, type ImportSanityConfig } from '../import-screen.ts';import { ContentSanityBlockError } from '../content-sanity.ts';-import { keepGrandfatherStamp, parseMarkdown, resolveParsedSubtype, serializePageToMarkdown, type ParseOpts } from '../markdown.ts';+import { parseMarkdown, resolveParsedSubtype, serializePageToMarkdown, type ParseOpts } from '../markdown.ts';+import { keepGrandfatherStamp } from './align-stored.ts';import { resolveSlugForPath, slugifyPath, isCodeFilePath, isImageFilePath } from '../sync.ts';import { prepareManagedSyncImage } from './sync-image.ts';import { SOURCE_CONFIG_OBJECT_SQL } from '../source-config-sql.ts';