/** * Cross-shard merge & semantic boundary linking (plan #2, Phase 2). * * After the shard workers return per-shard fragments + cross-boundary * call descriptors, this module: * 1. merges the fragments into one unified catalog (union of occurrences, * each keeping its already-resolved intra-shard edges); * 2. LINKS the boundary calls semantically against the export symbol table * ({@link ExportIndex}) + package manifest index ({@link PackageManifestIndex}) * built from the merged catalog and the resolved shard set, then stitches * the recovered edges onto their owner occurrences as * `resolution: 'semantic'`, `crossShard: true`, `confidence: 'high'`. * * The linker emits a cross-package edge ONLY when the import specifier + callee * name resolve to a UNIQUE exported occurrence in the imported package — exactly * what the TypeScript type checker would conclude. On ANY ambiguity (a name with * multiple matching exports the subpath can't disambiguate, a name the package * does not export, a specifier pointing at an external npm package) it DECLINES * and emits an unresolved (`to: []`) edge. A missing edge is safe; a phantom * cross-package edge would fail the gate. This replaces the old name-only * syntactic fallback, which fabricated impossible coupling edges by matching a * globally-unique simple name into a package the caller never imported. * * Intra-shard edges retain their original (semantic, in exact mode) fidelity; * relative imports are still path-pinned (already exact for same-package * imports). Engine-layer and language-agnostic: it operates on plain catalog * data + the descriptors' callee names / import specifiers + each package's * `package.json` — no parser, no TypeScript assumptions. */ import type { PackageManifestIndex } from './export-index.js'; import type { ShardBuildResult } from './shard-model.js'; import type { Catalog, CrossBoundaryCall, ResolutionStats } from '../../types.js'; /** Output of the cross-shard pass: the unified catalog + boundary-resolution stats. */ export interface CrossShardOutput { readonly catalog: Catalog; readonly boundaryStats: ResolutionStats; } /** * Merge per-shard fragments and recover cross-package edges. The single * Phase-2 entry the orchestrator calls. */ export declare function mergeAndResolveShards(fragments: readonly ShardBuildResult[], allFiles: readonly string[], manifestIndex: PackageManifestIndex): CrossShardOutput; /** * Union every fragment's `functions` map into one catalog. Each * occurrence keeps its already-resolved intra-shard `calls`. Shards are * disjoint by construction (distinct files), so occurrences don't * conflict; a defensive dedup by (bodyHash, filePath, line) drops any * accidental duplicate rather than double-counting. */ export declare function mergeShardFragments(fragments: readonly Catalog[], allFiles: readonly string[]): Catalog; /** * Resolve each cross-boundary call against the merged global catalog and * stitch the recovered edge onto its owner. A recovered edge is `'semantic'`, * `crossShard: true`, `confidence: 'high'` — the import specifier + callee name * linked to a UNIQUE target occurrence (relative imports pin by path; bare / * workspace imports pin by the imported package's export symbol table). On any * ambiguity the resolver DECLINES (`to: []`) — a missing edge is safe, a phantom * cross-package edge is not. Declined / external boundary calls stay unresolved * but are counted (attributable). */ export declare function resolveCrossBoundaryCalls(merged: Catalog, boundaryCalls: readonly CrossBoundaryCall[], manifestIndex: PackageManifestIndex): CrossShardOutput; export interface CatalogEdgeDiff { /** Intra-shard edges whose target differs between the two catalogs. MUST be * empty for a correct sharded build vs single-program build. */ readonly intraMismatches: readonly string[]; /** * Cross-package (boundary-linked) edges whose target differs between the two * catalogs. MUST ALSO be empty. * * With semantic linking (Phase 2), the sharded build's cross-package edges * are no longer an approximation of the single-program build's — they are the * SAME edges, recovered by linking each import specifier + callee name to the * UNIQUE exported occurrence the type checker would pick. A non-empty * `crossDifferences` is therefore a correctness REGRESSION (e.g. a name-only * fallback fabricating a phantom edge into a package the caller never * imported, or the linker declining an edge the single program resolves), NOT * an accepted fidelity gap. The Phase 4 equivalence guardrail asserts this * partition empty. */ readonly crossDifferences: readonly string[]; } /** * Diff two catalogs by edge, partitioned into intra-shard mismatches and * cross-package (boundary-linked) differences. An edge is keyed by * `ownerHash@line:col → sorted(to)`; a key is a difference when the two * catalogs disagree on its target set. Both partitions MUST be empty for a * correct sharded build vs single-program build: intra-package edges are exact * in both, and semantic boundary linking reproduces the single-program build's * cross-package edges verbatim (Phase 2). The partition only records WHICH side * a difference falls on (cross when either edge is `crossShard`), so a * regression is attributable to the linker vs a local resolver. The Phase 4 * equivalence guardrail (`__tests__/equivalence.test.ts`) is the live gate. */ export declare function diffCatalogsByEdge(a: Catalog, b: Catalog): CatalogEdgeDiff; //# sourceMappingURL=cross-shard-resolve.d.ts.map