// src/engine/reflection/revisions.ts
//
// Shared body-revision helper used by both the reflection input loader and the
// applier so their SHA-1 computations cannot drift.
//
// The revision is computed over the *parsed* body string as returned by
// gray-matter — NOT the raw file bytes.  gray-matter's round-trip normalization
// adds a trailing newline, so the parsed body that arrives from
// `listMemoryEntries` / `readMemoryEntry` is the canonical string to hash.

import { createHash } from 'crypto';

/**
 * Returns the SHA-1 hex digest of a memory entry's parsed body string.
 * Both `loadReflectionInputs` (observedRevisions) and `applyReflection`
 * (CAS check) call this function so the hashes are always comparable.
 */
export function bodyRevision(body: string): string {
  return createHash('sha1').update(body).digest('hex');
}
