refactor(packages): rename rules-core to rules-engine

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-21 11:10:51 +09:00
parent 7c7aa28160
commit 4bbf1d9388
32 changed files with 28 additions and 28 deletions
+26
View File
@@ -0,0 +1,26 @@
import { SOURCE_PRIORITY } from "./constants";
import type { RuleFileCandidate } from "./types";
export function sortCandidates<T extends RuleFileCandidate>(candidates: readonly T[]): T[] {
return candidates
.map((candidate, index) => ({ candidate, index }))
.sort((left, right) => compareCandidates(left.candidate, right.candidate) || left.index - right.index)
.map(({ candidate }) => candidate);
}
function compareCandidates(left: RuleFileCandidate, right: RuleFileCandidate): number {
return (
Number(left.isGlobal) - Number(right.isGlobal) ||
left.distance - right.distance ||
(SOURCE_PRIORITY.get(left.source) ?? Number.POSITIVE_INFINITY) -
(SOURCE_PRIORITY.get(right.source) ?? Number.POSITIVE_INFINITY) ||
compareString(left.relativePath, right.relativePath) ||
compareString(left.realPath, right.realPath)
);
}
function compareString(left: string, right: string): number {
if (left < right) return -1;
if (left > right) return 1;
return 0;
}