// src/layer/Elision.ts
import type { FileHash } from "./types.ts";

export interface ElisionSigil {
  hash: FileHash;
  firstSeenTurn: number;
  path: string;
}

export const ELISION_RE = /§READ:([a-f0-9]{12})@T(\d+)/g;

export function formatElision(s: ElisionSigil): string {
  return `§READ:${s.hash}@T${s.firstSeenTurn}`;
}

export function parseElision(token: string): { hash: FileHash; firstSeenTurn: number } | null {
  // Use matchAll to avoid exec
  const matches = [...token.matchAll(/§READ:([a-f0-9]{12})@T(\d+)/g)];
  const m = matches[0];
  if (!m) return null;
  return {
    hash: m[1]! as FileHash,
    firstSeenTurn: parseInt(m[2]!, 10),
  };
}
