Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
P1.5b/P1.7 stack hunks land (wave 13 PR2 merged): effects.ts isMetafilePage uses isSyncMetafile(path); reconcile-state.ts refuses a well-formed legacy file whose path derives another slug with source_changed/slug_rule_mismatch naming the frontmatter repair; the todo test is real (fails 1/5 without the hunk, 5/5 with)
garrytanee69bcc0ee61
diff --git a/src/core/persistence/effects.ts b/src/core/persistence/effects.tsindex b75c70ecc2..f5bc0c6dc9 100644--- a/src/core/persistence/effects.ts+++ b/src/core/persistence/effects.ts@@ -2,7 +2,7 @@ import { withAIAttribution } from '../ai/invocation-guard.ts';import { randomUUID } from 'node:crypto';import { targetedWithdrawalEffect, upgradeWithdrawalEffect } from './effect-targets.ts';import { existsSync, statSync } from 'node:fs';-import { basename, join, relative, sep } from 'node:path';+import { join, relative, sep } from 'node:path';import type { BrainEngine } from '../engine.ts';import { PERSISTENCE_PROTOCOL_PREDICATE } from './protocol.ts';import type { GBrainConfig } from '../config.ts';@@ -37,7 +37,7 @@ import { EFFECT_FAULT_POINTS, faultPoint } from './fault-points.ts';import { dispatchFactsBackstopEffect } from './effect-facts.ts';import { runLinksEffect } from './effect-links.ts';import { PARK_AFTER_FAILURES, type EffectRecovery, type GitCommitNote, type PersistenceEffect, type SkippedTarget } from './effect-model.ts';-import { SYNC_SKIP_FILES } from '../sync.ts';+import { isSyncMetafile } from '../sync.ts';import { recoveryStagingFile } from './staging.ts';import { selectEffectRecoveries } from './effect-recovery-scan.ts';import { nativeFileTarget } from './native-file-target.ts';@@ -145,7 +145,7 @@ async function recordSkippedTarget(engine: BrainEngine, effect: PersistenceEffec* so its legacy page and file diverge; a scan never publishes either one to the other.*/function isMetafilePage(snapshot: PageSnapshot): boolean {- return !!snapshot.page.source_path && (SYNC_SKIP_FILES as readonly string[]).includes(basename(snapshot.page.source_path));+ return !!snapshot.page.source_path && isSyncMetafile(snapshot.page.source_path);}function isFileDatabaseDrift(error: unknown): boolean {diff --git a/src/core/persistence/reconcile-state.ts b/src/core/persistence/reconcile-state.tsindex ff3d2345e7..0b056bf932 100644--- a/src/core/persistence/reconcile-state.ts+++ b/src/core/persistence/reconcile-state.ts@@ -192,6 +192,13 @@ export async function readReconcileState(engine: BrainEngine, sourceId: string,// Preserve a terminal .md in the page key while parsing the canonical Markdown.const parsed = parseMarkdown(text, `${slug}.md`, { validate: true, expectedSlug: slug });const errors = parsed.errors?.filter(e => !['MISSING_OPEN', 'MISSING_CLOSE', 'EMPTY_FRONTMATTER'].includes(e.code)) ?? [];+ if (!errors.length && !parsed.errors?.some(e => e.code === 'MISSING_CLOSE') && parsed.slug !== slug) {+ // #5966 (W14 P1.7): a well-formed file whose path derives another slug is a legacy render of a slug the+ // path cannot derive, written before renders stamped `slug:`; the frontmatter repair proposes the stamp.+ throw opError('source_changed', 'The canonical file carries no slug stamp, so its path derives a different slug.',+ `Nothing changed. The file of ${slug} in '${sourceId}' reads as ${parsed.slug} from its path. Preview the stamp with gbrain repair frontmatter --source ${sourceId} --only ${relative(root, path)} (a safe repair), apply it, then preview the page again.`,+ { detail: 'slug_rule_mismatch' });+ }if (errors.length || parsed.errors?.some(e => e.code === 'MISSING_CLOSE') || parsed.slug !== slug) {throw opError('invalid_params', 'Canonical file metadata cannot be parsed losslessly; repair its syntax before previewing.',`Nothing changed. Fix the frontmatter of the canonical file of ${slug} in '${sourceId}' (close the --- block, keep its slug), then preview the page again.`);diff --git a/test/slug-stamp-double-hyphen.test.ts b/test/slug-stamp-double-hyphen.test.tsindex 106fbc25d8..07fa893ff8 100644--- a/test/slug-stamp-double-hyphen.test.ts+++ b/test/slug-stamp-double-hyphen.test.ts@@ -20,6 +20,7 @@ import { PGLiteEngine } from '../src/core/pglite-engine.ts';import type { OperationContext } from '../src/core/ops/contract.ts';import { claimWorktree } from '../src/core/persistence/ownership.ts';import { submitPageMutation } from '../src/core/persistence/page-mutations.ts';+import { readReconcileState } from '../src/core/persistence/reconcile-state.ts';import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';import { resolveRepairScope, type RepairResult } from '../src/core/repair/core.ts';import { repairRunner } from '../src/core/repair/registry.ts';@@ -96,6 +97,8 @@ for (const kind of backends) describe(`repair frontmatter stamps a legacy unstamwriteFileSync(join(root, 'notes', 'a--b.md'), legacy);git(root, 'add', '-A'); git(root, 'commit', '-qm', 'legacy unstamped render');+ // Before the stamp, a reconcile preview of the page names the repair instead of 'cannot be parsed losslessly'.+ await expect(readReconcileState(engine, id, 'notes/a--b')).rejects.toMatchObject({ code: 'source_changed', detail: 'slug_rule_mismatch', suggestion: expect.stringContaining(`gbrain repair frontmatter --source ${id} --only notes/a--b.md`) });const runner = await repairRunner(engine, { apply: false, noEmbed: true, logger: quiet });const preview = await runner.run('frontmatter', await resolveRepairScope(engine, id), { explicit: true, sourceFlag: id });expect(preview).toMatchObject({ mode: 'dry_run', affected: 1 });@@ -118,5 +121,4 @@ for (const kind of backends) describe(`repair frontmatter stamps a legacy unstam}}), 180_000);- test.todo('P1.7 (#5966) stack hunk: sources reconcile --preview of a legacy unstamped -- file refuses with detail slug_rule_mismatch naming the repair command (reconcile-state.ts is wave-13 owned; see ~/.capy/work/w14/pr1/stack-hunks)', () => {});});