File size: 655 Bytes
0fc6e34 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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<string>();
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;
}
|