import type { Rule } from "./types.js"; /** * Collapse rules with identical normalized content, keeping the first. * Needed because some agents expose more than one rule source (e.g. DSH reads * both the project AGENTS.md and the global bot-team state file), and writing * every duplicate back would grow the file on each migration. */ export function dedupeRules(rules: Rule[]): Rule[] { const seen = new Set(); const out: Rule[] = []; for (const rule of rules) { const key = rule.content.replace(/\s+/g, " ").trim(); if (key.length === 0 || seen.has(key)) continue; seen.add(key); out.push(rule); } return out; }