/** * Shared identity, sort, merge, and cap helpers for the optional semantic * declaration/reference plane (P2 MCP audit Phase 3). * * Pure data only — no compiler, filesystem, or repository coupling. Producers, * shard merge, incremental rebuild, and the global reconciler all share these * recipes so fact IDs and order stay generation-stable. */ import type { CrossFileReferenceFact, DeclarationFact, SemanticFactBundle, SemanticFactLimits, SemanticFactProducerCoverage } from './types.js'; /** Build a stable declaration id from normalized identity inputs. */ export declare function makeDeclarationId(input: { readonly package: string; readonly filePath: string; readonly kind: string; readonly name: string; readonly line: number; readonly column: number; }): string; /** Build a stable reference id from source span + kind + target fingerprint. */ export declare function makeReferenceId(input: { readonly filePath: string; readonly kind: string; readonly line: number; readonly column: number; readonly targetDeclarationId?: string; readonly targetName?: string; readonly targetPackage?: string; }): string; /** Deterministic declaration order: package, path, line, column, id. */ export declare function compareDeclarationFacts(a: DeclarationFact, b: DeclarationFact): number; /** Deterministic reference order: path, line, column, kind, id. */ export declare function compareReferenceFacts(a: CrossFileReferenceFact, b: CrossFileReferenceFact): number; /** Sort and de-duplicate reasons for stable coverage payloads. */ export declare function sortReasonCodes(reasons: readonly string[]): readonly string[]; /** * Merge producer coverage conservatively: partial if any input is partial, * sum counters, union reason codes. */ export declare function mergeProducerCoverage(coverages: readonly SemanticFactProducerCoverage[]): SemanticFactProducerCoverage; /** * After retention, re-sync emitted counts with actual arrays and mark partial * when reasons remain (or when caps truncated). */ export declare function finalizeProducerCoverage(coverage: SemanticFactProducerCoverage, declarations: readonly DeclarationFact[], references: readonly CrossFileReferenceFact[]): SemanticFactProducerCoverage; /** * Apply global caps: keep deterministic top-K by stable identity order, then * enforce referential closure — either retain referenced declarations that * would fall outside the declaration cap, or downgrade dangling references * with `target-omitted-by-cap`. Never emit a dangling targetDeclarationId. */ export declare function applySemanticFactCaps(declarations: readonly DeclarationFact[], references: readonly CrossFileReferenceFact[], coverage: SemanticFactProducerCoverage, limits?: SemanticFactLimits): SemanticFactBundle; /** * Union semantic fact bundles by stable identity, sort, merge coverage, and * re-apply caps. Absent inputs are ignored; if every input is absent, returns * `undefined` (unsupported). Present-empty bundles remain present. */ export declare function mergeSemanticFactBundles(bundles: readonly (SemanticFactBundle | undefined)[], limits?: SemanticFactLimits): SemanticFactBundle | undefined; /** * Incremental merge: keep cached facts whose source (and for references, * target declaration) files are outside the re-walked closure; replace with * freshly collected facts for the closure. Absent cached + absent fresh → * absent; present empty preserved. */ export declare function mergeSemanticFactsIncremental(cached: SemanticFactBundle | undefined, fresh: SemanticFactBundle | undefined, closureRel: ReadonlySet, declFileById: ReadonlyMap, limits?: SemanticFactLimits): SemanticFactBundle | undefined; /** Index declarationId → filePath for incremental target-file filtering. */ export declare function declarationFileIndex(declarations: readonly DeclarationFact[]): ReadonlyMap; /** Empty supported bundle (exact mode, no facts). */ export declare function emptySemanticFactBundle(coverage?: Partial): SemanticFactBundle; //# sourceMappingURL=semantic-facts.d.ts.map