// engine/frontmatter-sha/canonicalize.ts — SPEC-723: Stable canonical form of frozen fields
import { FROZEN_FIELDS } from './frozen-fields.js';
/**
 * Extract only frozen fields from a metadata object and produce a deterministic
 * JSON string with keys sorted alphabetically.
 *
 * Only FROZEN_FIELDS are included — other frontmatter fields (title, tags, etc.)
 * are intentionally excluded so that non-frozen edits do not affect the SHA.
 */
export function canonicalizeFrozenFields(metadata) {
    const extracted = {};
    for (const field of [...FROZEN_FIELDS].sort()) {
        // Include the field even if undefined so callers have a stable key set.
        extracted[field] = Object.prototype.hasOwnProperty.call(metadata, field)
            ? metadata[field]
            : null;
    }
    return JSON.stringify(extracted);
}
//# sourceMappingURL=canonicalize.js.map