// Identity hash for a UniversalComponentFact.
//
// SHA-256 over a canonical key string, hex-encoded, truncated to 16 chars.
// The same (filePath, componentName, framework, sourceCommit) tuple must
// always yield the same id — that idempotence is what makes the per-UCF
// cache and signal pipeline safe to re-run on unchanged source.

import { createHash } from 'node:crypto';

import type { Framework } from './types.js';

const HASH_LENGTH = 16;

export function ucfId(
  filePath: string,
  componentName: string,
  framework: Framework,
  sourceCommit: string,
): string {
  const key = `${framework}|${filePath}|${componentName}|${sourceCommit}`;
  return createHash('sha256').update(key).digest('hex').slice(0, HASH_LENGTH);
}
