@shapeshift-labs/frontier-lang-compiler 0.2.149 → 0.2.151

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. package/README.md +315 -9
  2. package/bench/real-repo-corpus-checkout-identity.mjs +134 -0
  3. package/bench/real-repo-corpus-checkout-proof.mjs +263 -0
  4. package/bench/real-repo-corpus-command-execution.mjs +314 -0
  5. package/bench/real-repo-corpus-evidence.mjs +165 -0
  6. package/bench/real-repo-corpus-suite.mjs +273 -0
  7. package/bench/smoke.mjs +109 -7
  8. package/dist/declarations/import-adapter-core.d.ts +4 -3
  9. package/dist/declarations/import-adapter-options-native.d.ts +21 -0
  10. package/dist/declarations/js-ts-project-merge-admission-routes.d.ts +35 -0
  11. package/dist/declarations/js-ts-project-merge-commonjs-interop.d.ts +29 -0
  12. package/dist/declarations/js-ts-project-merge-confidence.d.ts +64 -0
  13. package/dist/declarations/js-ts-project-merge-declaration-emit-parity.d.ts +37 -0
  14. package/dist/declarations/js-ts-project-merge-declarations.d.ts +65 -0
  15. package/dist/declarations/js-ts-project-merge-diagnostics.d.ts +97 -0
  16. package/dist/declarations/js-ts-project-merge-global-augmentation.d.ts +30 -0
  17. package/dist/declarations/js-ts-project-merge-jsx-render-branch.d.ts +48 -0
  18. package/dist/declarations/js-ts-project-merge-proof-levels.d.ts +109 -0
  19. package/dist/declarations/js-ts-project-merge-quality-gates.d.ts +38 -0
  20. package/dist/declarations/js-ts-project-merge-semantic-equivalence-proof.d.ts +45 -0
  21. package/dist/declarations/js-ts-project-merge-tsconfig.d.ts +43 -0
  22. package/dist/declarations/js-ts-safe-merge.d.ts +47 -0
  23. package/dist/declarations/js-ts-safe-project-merge.d.ts +120 -38
  24. package/dist/declarations/native-project-compiler-assignability-oracle.d.ts +41 -0
  25. package/dist/declarations/native-project-compiler-callable-signatures.d.ts +31 -0
  26. package/dist/declarations/native-project-compiler-class-member-runtime-proof.d.ts +87 -0
  27. package/dist/declarations/native-project-compiler-composite-types.d.ts +23 -0
  28. package/dist/declarations/native-project-compiler-enum-proof.d.ts +58 -0
  29. package/dist/declarations/native-project-compiler-index-signature.d.ts +7 -0
  30. package/dist/declarations/native-project-compiler-public-api-source-binding.d.ts +8 -0
  31. package/dist/declarations/native-project-compiler-scope.d.ts +37 -0
  32. package/dist/declarations/native-project-compiler-type-reference-targets.d.ts +38 -0
  33. package/dist/declarations/native-project-css-modules.d.ts +90 -0
  34. package/dist/declarations/native-project-decorator-metadata.d.ts +126 -0
  35. package/dist/declarations/native-project-jsx-graph.d.ts +313 -0
  36. package/dist/declarations/native-project-module-declarations.d.ts +52 -0
  37. package/dist/declarations/native-project-module-resolution.d.ts +76 -1
  38. package/dist/declarations/native-project-runtime-effect-target.d.ts +29 -0
  39. package/dist/declarations/native-project-runtime-executable-effect-evidence.d.ts +107 -0
  40. package/dist/declarations/native-project-runtime-mutation-target.d.ts +33 -0
  41. package/dist/declarations/native-project-runtime-promise-chain.d.ts +30 -0
  42. package/dist/declarations/native-project-runtime-promise-combinator.d.ts +22 -0
  43. package/dist/declarations/native-project-runtime-reachability.d.ts +30 -0
  44. package/dist/declarations/native-project-runtime-resource-management.d.ts +27 -0
  45. package/dist/declarations/native-project-runtime-yield-delegation.d.ts +10 -0
  46. package/dist/declarations/native-project-scope-template-reference.d.ts +13 -0
  47. package/dist/declarations/native-project-source-evidence.d.ts +8 -0
  48. package/dist/declarations/native-project.d.ts +40 -39
  49. package/dist/declarations/semantic-edit-script.d.ts +10 -8
  50. package/dist/declarations/semantic-graph-layers.d.ts +79 -0
  51. package/dist/declarations/semantic-patch-bundle-composition.d.ts +62 -0
  52. package/dist/declarations/semantic-sidecar.d.ts +3 -2
  53. package/dist/declarations/semantic-structural-diff.d.ts +94 -0
  54. package/dist/declarations/source-preservation.d.ts +32 -1
  55. package/dist/declarations/target-adapters.d.ts +22 -2
  56. package/dist/index.d.ts +32 -0
  57. package/dist/index.js +6 -0
  58. package/dist/internal/index-impl/compileNativeSource.js +53 -5
  59. package/dist/internal/index-impl/createLightweightNativeImport.js +58 -4
  60. package/dist/internal/index-impl/createNativeImportFromSyntaxAst.js +17 -1
  61. package/dist/internal/index-impl/createNativeImportFromTypeScriptAst.js +28 -4
  62. package/dist/internal/index-impl/createNativeProjectImportResult.js +31 -27
  63. package/dist/internal/index-impl/createNativeProjectModuleResolutionFromPackageManifests.js +145 -0
  64. package/dist/internal/index-impl/createNativeSourcePreservation.js +34 -7
  65. package/dist/internal/index-impl/createSemanticImportSidecar.js +27 -1
  66. package/dist/internal/index-impl/createTypeScriptCompilerNativeImporterAdapter.js +16 -5
  67. package/dist/internal/index-impl/dynamicImportExpressionMetadata.js +80 -0
  68. package/dist/internal/index-impl/importMetaUrlDependencyMetadata.js +176 -0
  69. package/dist/internal/index-impl/importNativeSource.js +2 -3
  70. package/dist/internal/index-impl/moduleImportAttributeMetadata.js +232 -0
  71. package/dist/internal/index-impl/projectSemanticEditScriptToSource.js +8 -1
  72. package/dist/internal/index-impl/projectSymbolGraphClassStaticBlocks.js +148 -0
  73. package/dist/internal/index-impl/projectSymbolGraphCompilerAdvancedTypeMetadata.js +45 -0
  74. package/dist/internal/index-impl/projectSymbolGraphCompilerCallableSignatureEquivalence.js +107 -0
  75. package/dist/internal/index-impl/projectSymbolGraphCompilerClassPrivateAccessorRuntimeProof.js +280 -0
  76. package/dist/internal/index-impl/projectSymbolGraphCompilerClassShapeEquivalence.js +103 -0
  77. package/dist/internal/index-impl/projectSymbolGraphCompilerConditionalTypeEquivalence.js +242 -0
  78. package/dist/internal/index-impl/projectSymbolGraphCompilerDecoratorRuntimeProof.js +197 -0
  79. package/dist/internal/index-impl/projectSymbolGraphCompilerEnumEquivalence.js +188 -0
  80. package/dist/internal/index-impl/projectSymbolGraphCompilerFacts.js +244 -0
  81. package/dist/internal/index-impl/projectSymbolGraphCompilerIndexSignatureEquivalence.js +58 -0
  82. package/dist/internal/index-impl/projectSymbolGraphCompilerMetadata.js +168 -0
  83. package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalence.js +199 -0
  84. package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalenceProof.js +204 -0
  85. package/dist/internal/index-impl/projectSymbolGraphCompilerTypeReferenceTargetEquivalence.js +99 -0
  86. package/dist/internal/index-impl/projectSymbolGraphCssModuleRecords.js +264 -0
  87. package/dist/internal/index-impl/projectSymbolGraphCssModuleScanners.js +242 -0
  88. package/dist/internal/index-impl/projectSymbolGraphCssModuleUtils.js +152 -0
  89. package/dist/internal/index-impl/projectSymbolGraphCssModules.js +82 -0
  90. package/dist/internal/index-impl/projectSymbolGraphJsxComponentImports.js +170 -0
  91. package/dist/internal/index-impl/projectSymbolGraphJsxComponentProviderLookup.js +167 -0
  92. package/dist/internal/index-impl/projectSymbolGraphJsxComponentWrappers.js +150 -0
  93. package/dist/internal/index-impl/projectSymbolGraphJsxContextTargets.js +71 -0
  94. package/dist/internal/index-impl/projectSymbolGraphJsxContextValues.js +212 -0
  95. package/dist/internal/index-impl/projectSymbolGraphJsxEventHandlers.js +172 -0
  96. package/dist/internal/index-impl/projectSymbolGraphJsxHookEffects.js +124 -0
  97. package/dist/internal/index-impl/projectSymbolGraphJsxHooks.js +281 -0
  98. package/dist/internal/index-impl/projectSymbolGraphJsxMemberComponents.js +139 -0
  99. package/dist/internal/index-impl/projectSymbolGraphJsxPropFlows.js +320 -0
  100. package/dist/internal/index-impl/projectSymbolGraphJsxPropValues.js +145 -0
  101. package/dist/internal/index-impl/projectSymbolGraphJsxProviderFlows.js +133 -0
  102. package/dist/internal/index-impl/projectSymbolGraphJsxRecords.js +315 -0
  103. package/dist/internal/index-impl/projectSymbolGraphJsxRenderCollections.js +155 -0
  104. package/dist/internal/index-impl/projectSymbolGraphJsxRenderReturns.js +291 -0
  105. package/dist/internal/index-impl/projectSymbolGraphJsxRenderRisk.js +279 -0
  106. package/dist/internal/index-impl/projectSymbolGraphModuleDeclarationShapes.js +138 -0
  107. package/dist/internal/index-impl/projectSymbolGraphModuleResolution.js +89 -87
  108. package/dist/internal/index-impl/projectSymbolGraphPackageConditions.js +314 -0
  109. package/dist/internal/index-impl/projectSymbolGraphReExportImportTargets.js +43 -0
  110. package/dist/internal/index-impl/projectSymbolGraphReExports.js +55 -1
  111. package/dist/internal/index-impl/projectSymbolGraphRuntimeRegions.js +108 -0
  112. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefAliases.js +307 -0
  113. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefLexical.js +320 -0
  114. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefOwners.js +50 -0
  115. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecordBuilders.js +112 -0
  116. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecords.js +238 -0
  117. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructural.js +104 -0
  118. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructuralNormalize.js +242 -0
  119. package/dist/internal/index-impl/projectSymbolGraphScopeUseDefUseHashes.js +107 -0
  120. package/dist/internal/index-impl/projectSymbolGraphSourceMapGeneratedBoundary.js +111 -0
  121. package/dist/internal/index-impl/projectSymbolGraphSourceRecords.js +268 -0
  122. package/dist/internal/index-impl/projectSymbolGraphSourceRecordsOwnership.js +309 -0
  123. package/dist/internal/index-impl/replaySemanticEditProjection.js +53 -39
  124. package/dist/internal/index-impl/runtimeOrderEvidenceBinding.js +151 -0
  125. package/dist/internal/index-impl/runtimeOrderProofSurfaces.js +253 -0
  126. package/dist/internal/index-impl/semanticEditCallsiteArgumentMerge.js +319 -0
  127. package/dist/internal/index-impl/semanticEditExplicitSourceReplacement.js +7 -2
  128. package/dist/internal/index-impl/semanticEditProjectionRecord.js +8 -0
  129. package/dist/internal/index-impl/semanticEditReplayDiagnostics.js +7 -2
  130. package/dist/internal/index-impl/semanticEditReplayOutputBinding.js +61 -0
  131. package/dist/internal/index-impl/semanticEditReplayRerunRoute.js +27 -0
  132. package/dist/internal/index-impl/semanticEditReplaySourceReplacement.js +6 -1
  133. package/dist/internal/index-impl/semanticEditRuntimeOrderReasons.js +320 -0
  134. package/dist/internal/index-impl/semanticEditScriptClassification.js +90 -5
  135. package/dist/internal/index-impl/semanticEditScripts.js +42 -5
  136. package/dist/internal/index-impl/semanticEditTypeSyntaxReasons.js +134 -0
  137. package/dist/internal/index-impl/semanticIndexFromNativeDeclarations.js +11 -5
  138. package/dist/internal/index-impl/semanticPatchBundleComposition.js +166 -0
  139. package/dist/internal/index-impl/semanticStructuralDiffRecords.js +150 -0
  140. package/dist/internal/index-impl/sourceMapGeneratedBoundaryGate.js +185 -0
  141. package/dist/internal/index-impl/staticMemberLiteral.js +31 -0
  142. package/dist/internal/index-impl/staticOptionalMemberReference.js +22 -0
  143. package/dist/internal/index-impl/syntaxAstSourcePreservation.js +273 -0
  144. package/dist/internal/index-impl/syntaxCommonJsModuleDeclarationEntries.js +297 -0
  145. package/dist/internal/index-impl/syntaxModuleDeclarationEntries.js +56 -132
  146. package/dist/internal/index-impl/syntaxModuleEntryRecords.js +160 -0
  147. package/dist/internal/index-impl/typeScriptCompilerAdvancedTypeShapes.js +160 -0
  148. package/dist/internal/index-impl/typeScriptCompilerAssignabilityOracle.js +97 -0
  149. package/dist/internal/index-impl/typeScriptCompilerClassApi.js +238 -0
  150. package/dist/internal/index-impl/typeScriptCompilerDecoratorMetadata.js +290 -0
  151. package/dist/internal/index-impl/typeScriptCompilerEnumShape.js +279 -0
  152. package/dist/internal/index-impl/typeScriptCompilerFacts.js +294 -0
  153. package/dist/internal/index-impl/typeScriptCompilerInferenceSyntax.js +170 -0
  154. package/dist/internal/index-impl/typeScriptCompilerReferenceGraph.js +186 -0
  155. package/dist/internal/index-impl/typeScriptCompilerSymbolIdentity.js +294 -0
  156. package/dist/internal/index-impl/typeScriptCompilerTypeReferenceTargets.js +142 -0
  157. package/dist/internal/index-impl/typeScriptDeclaration.js +10 -38
  158. package/dist/internal/index-impl/typeScriptModuleDeclarationEntries.js +52 -15
  159. package/dist/internal/index-impl/typeScriptSourceFilePreservation.js +296 -0
  160. package/dist/js-ts-safe-member-class-invariants.js +247 -0
  161. package/dist/js-ts-safe-member-merge-result.js +23 -3
  162. package/dist/js-ts-safe-member-merge.js +28 -4
  163. package/dist/js-ts-safe-merge-binding-patterns.js +170 -0
  164. package/dist/js-ts-safe-merge-context.js +1 -0
  165. package/dist/js-ts-safe-merge-jsx-attribute-fallback.js +314 -0
  166. package/dist/js-ts-safe-merge-jsx-attribute-parser.js +277 -0
  167. package/dist/js-ts-safe-merge-jsx-child-expression-fallback.js +161 -0
  168. package/dist/js-ts-safe-merge-jsx-child-expression-merge.js +319 -0
  169. package/dist/js-ts-safe-merge-jsx-child-expression-parser.js +300 -0
  170. package/dist/js-ts-safe-merge-parse-declarations.js +46 -2
  171. package/dist/js-ts-safe-merge-parse-statements.js +8 -0
  172. package/dist/js-ts-safe-merge-plan.js +3 -1
  173. package/dist/js-ts-safe-merge-semantic-edit-fallback.js +49 -0
  174. package/dist/js-ts-safe-merge-source-shape-fallbacks.js +5 -1
  175. package/dist/js-ts-safe-merge-top-level-rename-fallback.js +31 -5
  176. package/dist/js-ts-safe-merge-top-level-rename-result.js +7 -2
  177. package/dist/js-ts-safe-merge-variable-declarator-fallback.js +124 -6
  178. package/dist/js-ts-safe-merge-variable-declarator-parser.js +34 -4
  179. package/dist/js-ts-safe-merge.js +136 -0
  180. package/dist/js-ts-safe-project-merge-admission-routes.js +216 -0
  181. package/dist/js-ts-safe-project-merge-admission.js +161 -0
  182. package/dist/js-ts-safe-project-merge-ambient.js +110 -0
  183. package/dist/js-ts-safe-project-merge-core.js +85 -0
  184. package/dist/js-ts-safe-project-merge-css-module-conflicts.js +60 -0
  185. package/dist/js-ts-safe-project-merge-declaration-emit-parity.js +186 -0
  186. package/dist/js-ts-safe-project-merge-declarations.js +227 -0
  187. package/dist/js-ts-safe-project-merge-diagnostics-metadata.js +42 -0
  188. package/dist/js-ts-safe-project-merge-diagnostics-ts.js +73 -0
  189. package/dist/js-ts-safe-project-merge-diagnostics.js +283 -0
  190. package/dist/js-ts-safe-project-merge-evidence-routing.js +38 -0
  191. package/dist/js-ts-safe-project-merge-files.js +70 -0
  192. package/dist/js-ts-safe-project-merge-global-augmentation-compatibility.js +99 -0
  193. package/dist/js-ts-safe-project-merge-graph-conflicts.js +90 -2
  194. package/dist/js-ts-safe-project-merge-graph-delta-commonjs-interop.js +108 -0
  195. package/dist/js-ts-safe-project-merge-graph-delta-compiler-conflicts.js +179 -0
  196. package/dist/js-ts-safe-project-merge-graph-delta-compiler-details.js +189 -0
  197. package/dist/js-ts-safe-project-merge-graph-delta-conflicts.js +51 -184
  198. package/dist/js-ts-safe-project-merge-graph-delta-identity-conflicts.js +202 -0
  199. package/dist/js-ts-safe-project-merge-graph-delta-inference-syntax.js +80 -0
  200. package/dist/js-ts-safe-project-merge-graph-delta-module-declarations.js +155 -0
  201. package/dist/js-ts-safe-project-merge-graph-limits.js +16 -1
  202. package/dist/js-ts-safe-project-merge-graph.js +37 -5
  203. package/dist/js-ts-safe-project-merge-import-removal.js +292 -0
  204. package/dist/js-ts-safe-project-merge-jsx-graph-conflict-details.js +235 -0
  205. package/dist/js-ts-safe-project-merge-jsx-graph-conflicts.js +173 -0
  206. package/dist/js-ts-safe-project-merge-jsx-prop-contracts.js +86 -0
  207. package/dist/js-ts-safe-project-merge-jsx-render-branch-proof.js +189 -0
  208. package/dist/js-ts-safe-project-merge-missing-evidence.js +310 -0
  209. package/dist/js-ts-safe-project-merge-move-rename.js +209 -0
  210. package/dist/js-ts-safe-project-merge-proof-conflicts.js +44 -0
  211. package/dist/js-ts-safe-project-merge-proof-levels.js +320 -0
  212. package/dist/js-ts-safe-project-merge-quality-gates.js +140 -0
  213. package/dist/js-ts-safe-project-merge-routing-calibration.js +125 -0
  214. package/dist/js-ts-safe-project-merge-runtime-region-conflicts.js +156 -0
  215. package/dist/js-ts-safe-project-merge-scope-use-def-conflicts.js +292 -0
  216. package/dist/js-ts-safe-project-merge-semantic-equivalence-proof.js +175 -0
  217. package/dist/js-ts-safe-project-merge-semantic-replay-proof.js +311 -0
  218. package/dist/js-ts-safe-project-merge-semantic-replay-routes.js +179 -0
  219. package/dist/js-ts-safe-project-merge-source-span-conflicts.js +310 -0
  220. package/dist/js-ts-safe-project-merge-source-span-roundtrip-proof.js +172 -0
  221. package/dist/js-ts-safe-project-merge-split-merge-admission.js +96 -0
  222. package/dist/js-ts-safe-project-merge-split-merge-records.js +320 -0
  223. package/dist/js-ts-safe-project-merge-split-merge-shapes.js +234 -0
  224. package/dist/js-ts-safe-project-merge-split-merge.js +218 -0
  225. package/dist/js-ts-safe-project-merge-summary.js +320 -0
  226. package/dist/js-ts-safe-project-merge-symbol-move-admission.js +63 -0
  227. package/dist/js-ts-safe-project-merge-symbol-move-default-admission.js +143 -0
  228. package/dist/js-ts-safe-project-merge-symbol-move-risks.js +213 -0
  229. package/dist/js-ts-safe-project-merge-symbol-move.js +316 -0
  230. package/dist/js-ts-safe-project-merge-symbol-rename-admission.js +59 -0
  231. package/dist/js-ts-safe-project-merge-symbol-rename-default-admission.js +111 -0
  232. package/dist/js-ts-safe-project-merge-symbol-rename.js +319 -0
  233. package/dist/js-ts-safe-project-merge-ts-options.js +205 -0
  234. package/dist/js-ts-safe-project-merge-ts-program.js +268 -0
  235. package/dist/js-ts-safe-project-merge-typed-property-rename-rebase-utils.js +69 -0
  236. package/dist/js-ts-safe-project-merge-typed-property-rename-rebase.js +317 -0
  237. package/dist/js-ts-safe-project-merge-unsupported-surfaces.js +319 -0
  238. package/dist/js-ts-safe-project-merge.js +171 -172
  239. package/dist/js-ts-semantic-scope-use-def-bindings.js +287 -0
  240. package/dist/js-ts-semantic-scope-use-def-scan.js +241 -0
  241. package/dist/js-ts-semantic-scope-use-def-utils.js +132 -0
  242. package/dist/js-ts-semantic-scope-use-def.js +217 -0
  243. package/dist/lightweight-dependency-effects.js +28 -4
  244. package/dist/lightweight-dependency-relations.js +13 -7
  245. package/dist/lightweight-dependency-top-level.js +63 -0
  246. package/dist/native-import-language-profiles.js +27 -1
  247. package/dist/native-js-ts-importers.js +9 -5
  248. package/dist/native-parser-ast-format-profiles.js +12 -0
  249. package/dist/native-parser-html-css-format-profiles.js +85 -0
  250. package/dist/native-region-scanner-core.js +5 -3
  251. package/dist/native-region-scanner-js-commonjs.js +155 -0
  252. package/dist/native-region-scanner-js-imports.js +51 -13
  253. package/dist/native-region-scanner-js-reexports.js +79 -0
  254. package/dist/native-region-scanner-js-ts-helpers.js +23 -0
  255. package/dist/native-source-ledger-helpers.js +1 -1
  256. package/dist/native-source-ledger.js +24 -10
  257. package/dist/native-source-maps-ecma426.js +316 -0
  258. package/dist/native-source-maps.js +36 -6
  259. package/dist/native-source-preservation-ownership.js +292 -0
  260. package/dist/native-source-preservation-scanner.js +63 -25
  261. package/dist/native-source-preservation-types.d.ts +3 -0
  262. package/dist/semantic-import-effect-occurrences.js +242 -0
  263. package/dist/semantic-import-effect-regions.js +95 -58
  264. package/dist/semantic-import-graph-layers.js +224 -0
  265. package/dist/semantic-import-runtime-conditional-evidence.js +135 -0
  266. package/dist/semantic-import-runtime-effect-target-evidence.js +145 -0
  267. package/dist/semantic-import-runtime-exit-evidence.js +32 -0
  268. package/dist/semantic-import-runtime-import-meta-evidence.js +33 -0
  269. package/dist/semantic-import-runtime-mutation-evidence.js +155 -0
  270. package/dist/semantic-import-runtime-order-evidence.js +318 -0
  271. package/dist/semantic-import-runtime-promise-chain-evidence.js +103 -0
  272. package/dist/semantic-import-runtime-promise-combinator-evidence.js +166 -0
  273. package/dist/semantic-import-runtime-reachability-evidence.js +269 -0
  274. package/dist/semantic-import-runtime-resource-management-evidence.js +293 -0
  275. package/dist/semantic-import-runtime-switch-evidence.js +304 -0
  276. package/dist/semantic-import-runtime-throw-evidence.js +44 -0
  277. package/dist/semantic-import-runtime-try-finally-evidence.js +172 -0
  278. package/dist/semantic-import-sidecar-entry.js +4 -0
  279. package/dist/semantic-import-source-preservation.js +6 -2
  280. package/package.json +1 -1
@@ -12,6 +12,9 @@ import { createJsTsSafeMergeSemanticArtifacts } from './js-ts-safe-merge-semanti
12
12
 
13
13
  export { JsTsSafeMergeConflictCodes, JsTsSafeMergeGateIds, JsTsSafeMergeStatuses };
14
14
 
15
+ const mergedOutputSyntaxDiagnosticCode = 'merged-output-syntax-diagnostic';
16
+ const mergedOutputSyntaxDiagnosticsUnavailableCode = 'merged-output-syntax-diagnostics-unavailable';
17
+
15
18
  export function safeMergeJsTsImportsAndDeclarations(input = {}) {
16
19
  const context = createMergeContext(input);
17
20
  const baseSourceText = input.baseSourceText;
@@ -60,6 +63,7 @@ export function safeMergeJsTsImportsAndDeclarations(input = {}) {
60
63
  const mergedSourceText = applySourceMergePlan(headSourceText, mergePlan);
61
64
  const merged = scanJsTsTopLevelLedger(mergedSourceText, 'merged', context);
62
65
  if (!context.conflicts.length) validateLedgerUniqueness(merged, context);
66
+ if (!context.conflicts.length) validateMergedOutputSyntaxGate(input, context);
63
67
  if (context.conflicts.length) return blockedResult(context, { base, worker, head, merged });
64
68
 
65
69
  const result = {
@@ -179,3 +183,135 @@ function hasLedgerSpan(entry) {
179
183
  const hasLines = Number.isFinite(span.startLine) && Number.isFinite(span.endLine);
180
184
  return hasOffsets || hasLines;
181
185
  }
186
+
187
+ function validateMergedOutputSyntaxGate(input, context) {
188
+ const diagnostics = normalizeMergedOutputSyntaxDiagnostics(input, context.sourcePath);
189
+ if (!diagnostics) {
190
+ if (requiresMergedOutputSyntaxDiagnostics(input)) {
191
+ addConflict(context, {
192
+ code: mergedOutputSyntaxDiagnosticsUnavailableCode,
193
+ gateId: JsTsSafeMergeGateIds.parseLedger,
194
+ side: 'merged',
195
+ message: 'Merged JS/TS output syntax diagnostics are required but were not provided.',
196
+ details: { required: true, diagnosticSource: 'missing' }
197
+ });
198
+ }
199
+ return;
200
+ }
201
+ for (const diagnostic of diagnostics) {
202
+ if (diagnostic.severity !== 'error' || !isSyntaxDiagnostic(diagnostic)) continue;
203
+ addConflict(context, {
204
+ code: mergedOutputSyntaxDiagnosticCode,
205
+ gateId: JsTsSafeMergeGateIds.parseLedger,
206
+ side: 'merged',
207
+ message: `Merged JS/TS output syntax diagnostic ${diagnostic.code}: ${diagnostic.message}`,
208
+ details: { diagnostic }
209
+ });
210
+ }
211
+ }
212
+
213
+ function requiresMergedOutputSyntaxDiagnostics(input) {
214
+ return input.requireMergedOutputSyntaxDiagnostics === true
215
+ || input.requireOutputSyntaxDiagnostics === true
216
+ || input.requireOutputSyntaxGate === true
217
+ || input.requireSyntaxGate === true;
218
+ }
219
+
220
+ function normalizeMergedOutputSyntaxDiagnostics(input, sourcePath) {
221
+ const values = [
222
+ input.mergedOutputSyntaxDiagnostics,
223
+ input.outputSyntaxDiagnostics,
224
+ input.syntaxDiagnostics?.merged,
225
+ input.syntaxDiagnostics?.output,
226
+ input.outputDiagnostics
227
+ ];
228
+ if (!values.some((value) => value !== undefined)) return undefined;
229
+ const expectedPath = normalizeDiagnosticPath(sourcePath);
230
+ const diagnostics = values
231
+ .flatMap((value) => normalizeDiagnosticList(value))
232
+ .filter((diagnostic) => {
233
+ const diagnosticPath = normalizeDiagnosticPath(diagnostic.sourcePath);
234
+ return !expectedPath || !diagnosticPath || expectedPath === diagnosticPath;
235
+ });
236
+ return diagnostics;
237
+ }
238
+
239
+ function normalizeDiagnosticList(value) {
240
+ if (value === undefined) return [];
241
+ const values = Array.isArray(value) ? value : [value].filter(Boolean);
242
+ return values.map((diagnostic, index) => compactRecord({
243
+ id: diagnostic.id ?? `diagnostic_${index + 1}`,
244
+ source: diagnostic.source ?? diagnostic.tool ?? diagnostic.name,
245
+ code: String(diagnostic.code ?? diagnostic.diagnosticCode ?? diagnostic.name ?? 'syntax-diagnostic'),
246
+ severity: normalizeDiagnosticSeverity(diagnostic.severity ?? diagnostic.category),
247
+ message: String(diagnostic.message ?? diagnostic.messageText ?? ''),
248
+ sourcePath: normalizeDiagnosticPath(diagnostic.sourcePath ?? diagnostic.fileName ?? diagnostic.file?.fileName),
249
+ start: numberOrUndefined(diagnostic.start),
250
+ end: numberOrUndefined(diagnostic.end),
251
+ line: numberOrUndefined(diagnostic.line),
252
+ column: numberOrUndefined(diagnostic.column),
253
+ phase: normalizeDiagnosticPhase(diagnostic.phase ?? diagnostic.diagnosticPhase ?? diagnostic.kind ?? diagnostic.type),
254
+ syntax: diagnostic.syntax === true ? true : undefined
255
+ }));
256
+ }
257
+
258
+ function isSyntaxDiagnostic(diagnostic) {
259
+ if (diagnostic.syntax === true) return true;
260
+ const text = [
261
+ diagnostic.phase,
262
+ diagnostic.kind,
263
+ diagnostic.category,
264
+ diagnostic.type,
265
+ diagnostic.source,
266
+ diagnostic.ruleId,
267
+ diagnostic.name,
268
+ diagnostic.code
269
+ ].filter(Boolean).join(' ').toLowerCase();
270
+ return /\bsyntax\b|\bsyntactic\b|\bparse\b|\bparser\b/.test(text) || isTypeScriptSyntaxDiagnosticCode(diagnostic.code);
271
+ }
272
+
273
+ function isTypeScriptSyntaxDiagnosticCode(code) {
274
+ const match = /^TS(\d+)$/.exec(String(code ?? ''));
275
+ if (!match) return false;
276
+ const numeric = Number(match[1]);
277
+ return numeric >= 1000 && numeric < 2000;
278
+ }
279
+
280
+ function normalizeDiagnosticSeverity(value) {
281
+ if (typeof value === 'string') {
282
+ const lowered = value.toLowerCase();
283
+ if (lowered.includes('error')) return 'error';
284
+ if (lowered.includes('warn')) return 'warning';
285
+ if (lowered.includes('suggest')) return 'suggestion';
286
+ if (lowered.includes('message')) return 'message';
287
+ }
288
+ if (value === 1) return 'error';
289
+ if (value === 0) return 'warning';
290
+ if (value === 2) return 'suggestion';
291
+ if (value === 3) return 'message';
292
+ return 'error';
293
+ }
294
+
295
+ function normalizeDiagnosticPhase(value) {
296
+ if (typeof value !== 'string') return undefined;
297
+ const lowered = value.toLowerCase();
298
+ if (lowered.includes('syntax') || lowered.includes('syntactic') || lowered.includes('parse')) return 'syntax';
299
+ if (lowered.includes('semantic') || lowered.includes('type')) return 'semantic';
300
+ return value;
301
+ }
302
+
303
+ function normalizeDiagnosticPath(value) {
304
+ if (value === undefined || value === null) return undefined;
305
+ const raw = String(value).replace(/\\/g, '/').replace(/\/+/g, '/');
306
+ const parts = [];
307
+ for (const part of raw.split('/')) {
308
+ if (!part || part === '.') continue;
309
+ if (part === '..' && parts.length) parts.pop();
310
+ else if (part !== '..') parts.push(part);
311
+ }
312
+ return parts.join('/');
313
+ }
314
+
315
+ function numberOrUndefined(value) {
316
+ return Number.isFinite(value) ? value : undefined;
317
+ }
@@ -0,0 +1,216 @@
1
+ const exactAdmissionRouteSpecs = Object.freeze({
2
+ 'js-ts-project-symbol-rename-admission': routeSpec('apply-cross-file-symbol-rename', 'cross-file-symbol-rename', 'apply-project-symbol-rename'),
3
+ 'js-ts-project-symbol-move-admission': routeSpec('apply-symbol-move-between-files', 'symbol-move-between-files', 'apply-project-symbol-move'),
4
+ 'js-ts-project-split-merge-admission': routeSpec('apply-project-split-merge', 'split-merge-modules-classes', 'apply-project-split-merge')
5
+ });
6
+
7
+ const classificationRouteSpecs = Object.freeze({
8
+ 'cross-file-symbol-rename': routeSpec('review-cross-file-symbol-rename', 'cross-file-symbol-rename', 'supply-import-export-rewrite-diagnostics-and-declarations'),
9
+ 'exported-symbol-move': routeSpec('review-symbol-move-between-files', 'symbol-move-between-files', 'supply-symbol-lineage-rewrite-diagnostics-and-declarations'),
10
+ 'imported-symbol-move': routeSpec('review-symbol-move-between-files', 'symbol-move-between-files', 'supply-symbol-lineage-rewrite-diagnostics-and-declarations'),
11
+ 'file-move-rename': routeSpec('review-file-move-rename', 'file-move-rename', 'supply-path-lineage-rewrite-diagnostics-and-declarations'),
12
+ 'module-split': routeSpec('review-project-split-merge', 'split-merge-modules-classes', 'supply-structural-partition-diagnostics-and-declarations'),
13
+ 'module-merge': routeSpec('review-project-split-merge', 'split-merge-modules-classes', 'supply-structural-partition-diagnostics-and-declarations'),
14
+ 'class-split': routeSpec('review-project-split-merge', 'split-merge-modules-classes', 'supply-structural-partition-diagnostics-and-declarations'),
15
+ 'class-merge': routeSpec('review-project-split-merge', 'split-merge-modules-classes', 'supply-structural-partition-diagnostics-and-declarations')
16
+ });
17
+
18
+ function createProjectAdmissionRoutes(input = {}) {
19
+ return uniqueProjectAdmissionRoutes([
20
+ ...(input.fileResults ?? []).flatMap(fileAdmissionRoutes),
21
+ ...(input.missingEvidence ?? []).map(projectAdmissionRouteFromMissingEvidence),
22
+ ...(input.conflicts ?? []).map(projectAdmissionRouteFromConflict)
23
+ ].filter(Boolean));
24
+ }
25
+
26
+ function projectAdmissionRouteSummary(routes = []) {
27
+ return compactRecord({
28
+ total: routes.length,
29
+ byKind: countField(routes, 'routeKind'),
30
+ byAction: countField(routes, 'action'),
31
+ byLane: countField(routes, 'routeLane'),
32
+ byStatus: countField(routes, 'status'),
33
+ byRoute: countField(routes, 'routeId'),
34
+ nextRoute: routes.find((route) => route.status !== 'passed') ?? routes[0]
35
+ });
36
+ }
37
+
38
+ function projectAdmissionRouteFromExactAdmission(admission, options = {}) {
39
+ const spec = exactAdmissionRouteSpecs[admission?.kind] ?? routeSpec(`apply-${safeToken(admission?.kind ?? 'project-admission')}`, 'project-admission', options.action ?? 'apply-project');
40
+ return routeRecord({
41
+ routeId: spec.routeId,
42
+ routeKind: 'apply',
43
+ routeLane: spec.routeLane,
44
+ routeNext: spec.routeNext,
45
+ action: 'apply',
46
+ status: 'passed',
47
+ source: 'file-admission',
48
+ subjectKind: admission?.kind,
49
+ branch: admission?.branch,
50
+ sourcePath: admission?.sourcePath,
51
+ sourcePaths: admission?.details?.sourcePaths,
52
+ evidenceId: admission?.id,
53
+ conflictKey: admission?.details?.conflictKey,
54
+ reasonCodes: admission?.details?.reasonCode ? [admission.details.reasonCode] : [],
55
+ requiredEvidence: admission?.details?.requiredEvidence,
56
+ presentEvidence: admission?.details?.presentRequiredEvidence,
57
+ details: admission?.details
58
+ });
59
+ }
60
+
61
+ function projectAdmissionRouteFromClassification(classification, options = {}) {
62
+ const details = classification?.details ?? {};
63
+ const spec = classificationRouteSpecs[classification?.kind] ?? routeSpec(`review-${safeToken(classification?.kind ?? classification?.code ?? 'project-admission')}`, 'project-admission', 'review-structural-admission-evidence');
64
+ const explicitRouteId = details.routeId ?? details.proofRouteId;
65
+ const staleRouteId = details.structuralProofRouteId;
66
+ const stale = details.staleStructuralEditProof === true || details.otherBranchChanged === true;
67
+ return routeRecord({
68
+ routeId: options.routeId ?? explicitRouteId ?? staleRouteId ?? spec.routeId,
69
+ routeKind: stale ? 'rebase' : 'review',
70
+ routeLane: stale ? 'split-merge-modules-classes' : details.routeLane ?? spec.routeLane,
71
+ routeNext: stale ? 'prove-current-branch-output-before-admission' : details.routeNext ?? spec.routeNext,
72
+ action: stale ? 'rebase' : 'review',
73
+ status: options.status ?? 'blocked',
74
+ source: options.source ?? 'classification',
75
+ subjectKind: classification?.kind,
76
+ branch: classification?.branch,
77
+ sourcePath: options.sourcePath,
78
+ sourcePaths: classification?.sourcePaths,
79
+ conflictKey: details.conflictKey,
80
+ reasonCodes: uniqueStrings([classification?.code, details.reasonCode, ...(details.missingRequiredEvidence ?? [])]),
81
+ requiredEvidence: details.requiredEvidence,
82
+ missingEvidence: details.missingRequiredEvidence,
83
+ details
84
+ });
85
+ }
86
+
87
+ function projectAdmissionRouteFromConflict(conflict) {
88
+ const details = conflict?.details ?? {};
89
+ const classification = {
90
+ kind: classificationKindFromConflict(conflict, details),
91
+ code: conflict?.code,
92
+ branch: details.branch,
93
+ sourcePaths: uniqueStrings([...(details.sourcePaths ?? []), details.fromSourcePath, details.toSourcePath, details.exportSourcePath, details.importSourcePath, conflict?.sourcePath]),
94
+ details: { ...details, reasonCode: details.reasonCode ?? conflict?.code }
95
+ };
96
+ const route = projectAdmissionRouteFromClassification(classification, {
97
+ source: 'conflict',
98
+ sourcePath: conflict?.sourcePath,
99
+ status: conflict?.severity === 'error' ? 'failed' : 'blocked'
100
+ });
101
+ return route?.subjectKind === 'project-admission' && !structuralConflictCode(conflict?.code) && !details.routeId ? undefined : route;
102
+ }
103
+
104
+ function projectAdmissionRouteFromMissingEvidence(item) {
105
+ const route = item?.route ?? {};
106
+ const routeId = item?.routeId ?? route.id;
107
+ if (!routeId) return undefined;
108
+ const action = normalizedRouteAction(item?.action);
109
+ return routeRecord({
110
+ routeId,
111
+ routeKind: action,
112
+ routeLane: item?.routeLane ?? route.lane,
113
+ routeNext: item?.routeNext ?? route.next,
114
+ action,
115
+ status: item?.status ?? 'missing',
116
+ source: 'missing-evidence',
117
+ subjectKind: item?.kind,
118
+ proofLevel: item?.proofLevel,
119
+ evidenceId: item?.evidenceId,
120
+ reasonCodes: uniqueStrings([item?.code, ...(item?.relatedSignals ?? [])]),
121
+ details: item
122
+ });
123
+ }
124
+
125
+ function fileAdmissionRoutes(file) {
126
+ return [
127
+ ...(file?.admission?.routes ?? []),
128
+ ...fileAdmissionEvidence(file).map((record) => record.admissionRoute)
129
+ ].filter(Boolean);
130
+ }
131
+
132
+ function fileAdmissionEvidence(file) {
133
+ const records = [file?.summary, file?.metadata].filter(isPlainObject);
134
+ return records.flatMap((record) => Object.entries(record)
135
+ .filter(([key, value]) => /Admission(?:Evidence|s)$/.test(key) && Array.isArray(value))
136
+ .flatMap(([, value]) => value));
137
+ }
138
+
139
+ function classificationKindFromConflict(conflict, details) {
140
+ if (details.symbolRenameKind) return 'cross-file-symbol-rename';
141
+ if (details.symbolMoveKind === 'exported') return 'exported-symbol-move';
142
+ if (details.symbolMoveKind === 'imported') return 'imported-symbol-move';
143
+ if (details.movementKind && String(conflict?.code).includes('file-move-rename')) return 'file-move-rename';
144
+ for (const kind of ['module-split', 'module-merge', 'class-split', 'class-merge']) {
145
+ if (String(conflict?.code).includes(kind)) return kind;
146
+ }
147
+ return structuralConflictCode(conflict?.code) ? 'project-admission' : undefined;
148
+ }
149
+
150
+ function structuralConflictCode(code) {
151
+ return /^project-(worker|head)-/.test(String(code ?? ''))
152
+ || ['project-typescript-refactor-evidence-missing', 'project-source-span-roundtrip-proof-failed'].includes(String(code ?? ''));
153
+ }
154
+
155
+ function routeRecord(input) {
156
+ if (!input.routeId) return undefined;
157
+ return compactRecord({
158
+ kind: 'frontier.lang.jsTsProjectMergeAdmissionRoute',
159
+ version: 1,
160
+ routeId: input.routeId,
161
+ routeKind: input.routeKind,
162
+ routeLane: input.routeLane,
163
+ routeNext: input.routeNext,
164
+ action: input.action,
165
+ status: input.status,
166
+ source: input.source,
167
+ subjectKind: input.subjectKind,
168
+ branch: input.branch,
169
+ sourcePath: input.sourcePath,
170
+ sourcePaths: input.sourcePaths?.length ? uniqueStrings(input.sourcePaths) : undefined,
171
+ proofLevel: input.proofLevel,
172
+ evidenceId: input.evidenceId,
173
+ conflictKey: input.conflictKey,
174
+ reasonCodes: input.reasonCodes?.length ? uniqueStrings(input.reasonCodes) : undefined,
175
+ requiredEvidence: input.requiredEvidence,
176
+ presentEvidence: input.presentEvidence,
177
+ missingEvidence: input.missingEvidence,
178
+ details: input.details,
179
+ autoMergeClaim: false,
180
+ semanticEquivalenceClaim: false
181
+ });
182
+ }
183
+
184
+ function uniqueProjectAdmissionRoutes(routes) {
185
+ const seen = new Set();
186
+ return routes.filter((route) => {
187
+ const key = [route.routeId, route.source, route.sourcePath, route.conflictKey, route.evidenceId, route.status].filter(Boolean).join('#');
188
+ if (!key || seen.has(key)) return false;
189
+ seen.add(key);
190
+ return true;
191
+ });
192
+ }
193
+
194
+ function normalizedRouteAction(action) {
195
+ if (action === 'rerun' || action === 'rerun-gate') return 'rerun';
196
+ if (action === 'reject-proof' || action === 'reject') return 'reject';
197
+ if (action === 'block') return 'block';
198
+ if (action === 'apply') return 'apply';
199
+ if (action === 'rebase') return 'rebase';
200
+ return 'review';
201
+ }
202
+
203
+ function routeSpec(routeId, routeLane, routeNext) { return Object.freeze({ routeId, routeLane, routeNext }); }
204
+ function countField(values, field) { const result = {}; for (const value of values) if (value?.[field]) result[value[field]] = (result[value[field]] ?? 0) + 1; return result; }
205
+ function uniqueStrings(values) { return [...new Set((values ?? []).filter((value) => typeof value === 'string' && value.length > 0))]; }
206
+ function safeToken(value) { return String(value ?? 'project-admission').replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-+|-+$/g, '') || 'project-admission'; }
207
+ function isPlainObject(value) { return Boolean(value && typeof value === 'object' && !Array.isArray(value)); }
208
+ function compactRecord(record) { return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined && (!Array.isArray(value) || value.length > 0))); }
209
+
210
+ export {
211
+ createProjectAdmissionRoutes,
212
+ projectAdmissionRouteFromClassification,
213
+ projectAdmissionRouteFromExactAdmission,
214
+ projectAdmissionRouteFromMissingEvidence,
215
+ projectAdmissionRouteSummary
216
+ };
@@ -0,0 +1,161 @@
1
+ import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
2
+ import { compactRecord } from './js-ts-safe-merge-context.js';
3
+ import { projectAdmissionRouteFromExactAdmission } from './js-ts-safe-project-merge-admission-routes.js';
4
+
5
+ function createExactBranchProjectSemanticEditAdmissionFile(options) {
6
+ const {
7
+ fileResult,
8
+ file,
9
+ classifications = [],
10
+ admissionKind,
11
+ action,
12
+ operation,
13
+ summaryKey,
14
+ evidenceKey,
15
+ metadataKey,
16
+ requireOtherBranchUnchanged = true,
17
+ requireBaseForOtherBranchUnchanged = true,
18
+ allowDeletedBranchOutput = false,
19
+ allowExistingExactOutput = false,
20
+ classificationFilter = () => true,
21
+ admissionFields = () => ({}),
22
+ details = (classification) => classification.details
23
+ } = options;
24
+ if (!classifications.length || !classifications.every(classificationFilter)) return undefined;
25
+ const branches = uniqueStrings(classifications.map((classification) => classification.branch));
26
+ if (branches.length !== 1) return undefined;
27
+ const branch = branches[0];
28
+ const admissions = classifications
29
+ .map((classification) => exactBranchProjectSemanticEditAdmission({
30
+ fileResult,
31
+ file,
32
+ classification,
33
+ admissionKind,
34
+ requireOtherBranchUnchanged,
35
+ requireBaseForOtherBranchUnchanged,
36
+ allowDeletedBranchOutput,
37
+ allowExistingExactOutput,
38
+ admissionFields,
39
+ details
40
+ }))
41
+ .filter(Boolean);
42
+ if (admissions.length !== classifications.length) return undefined;
43
+ const branchText = branchSourceText(file, branch);
44
+ const outputHash = hashProjectSourceText(branchText);
45
+ return {
46
+ admissions,
47
+ fileResult: compactRecord({
48
+ ...fileResult,
49
+ status: 'merged',
50
+ operation: typeof operation === 'function' ? operation(fileResult) : operation,
51
+ outputSourceText: branchText,
52
+ outputHash,
53
+ baseHash: hashProjectSourceText(file.baseSourceText),
54
+ workerHash: hashProjectSourceText(branchSourceText(file, 'worker')),
55
+ headHash: hashProjectSourceText(branchSourceText(file, 'head')),
56
+ result: fileResult.status === 'merged' ? fileResult.result : undefined,
57
+ semanticArtifacts: fileResult.status === 'merged' ? fileResult.semanticArtifacts : undefined,
58
+ conflicts: [],
59
+ admission: exactBranchProjectSemanticEditFileAdmission(action),
60
+ summary: compactRecord({
61
+ ...(isPlainObject(fileResult.summary) ? fileResult.summary : {}),
62
+ conflicts: 0,
63
+ [summaryKey]: admissions.length,
64
+ [evidenceKey]: admissions
65
+ }),
66
+ metadata: metadataKey ? compactRecord({
67
+ ...(isPlainObject(fileResult.metadata) ? fileResult.metadata : {}),
68
+ [metadataKey]: admissions
69
+ }) : fileResult.metadata
70
+ })
71
+ };
72
+ }
73
+
74
+ function exactBranchProjectSemanticEditAdmission(options) {
75
+ const { fileResult, file, classification, admissionKind, requireOtherBranchUnchanged, requireBaseForOtherBranchUnchanged, allowDeletedBranchOutput, allowExistingExactOutput, admissionFields, details } = options;
76
+ const branchText = branchSourceText(file, classification.branch);
77
+ if (typeof branchText !== 'string' && !allowDeletedBranchOutput) return undefined;
78
+ const exactMergedOutput = fileResult.status === 'merged' && fileResult.outputSourceText === branchText;
79
+ if (!exactMergedOutput || !allowExistingExactOutput) {
80
+ if (requireOtherBranchUnchanged && !otherProjectBranchUnchanged(file, classification.branch, { requireBase: requireBaseForOtherBranchUnchanged })) return undefined;
81
+ }
82
+ const outputHash = hashProjectSourceText(branchText);
83
+ const admission = {
84
+ id: safeProjectEvidenceId(`${classification.details?.conflictKey ?? classification.code}_${file.sourcePath}`),
85
+ kind: admissionKind,
86
+ status: 'passed',
87
+ branch: classification.branch,
88
+ ...(admissionFields(classification) ?? {}),
89
+ sourcePath: file.sourcePath,
90
+ outputHash,
91
+ sourceHash: outputHash,
92
+ summary: `Project ${classification.branch} semantic edit output matched branch ${typeof branchText === 'string' ? 'source' : 'deletion'} for ${file.sourcePath}.`,
93
+ details: compactRecord({
94
+ ...(details(classification) ?? {}),
95
+ sourcePath: file.sourcePath,
96
+ outputHash,
97
+ exactBranchOutput: true,
98
+ deletedOutput: typeof branchText !== 'string' || undefined,
99
+ autoMergeClaim: false,
100
+ semanticEquivalenceClaim: false
101
+ })
102
+ };
103
+ return { ...admission, admissionRoute: projectAdmissionRouteFromExactAdmission(admission, { action: options.action }) };
104
+ }
105
+
106
+ function exactBranchProjectSemanticEditFileAdmission(action) {
107
+ return {
108
+ status: 'auto-merge-candidate',
109
+ action,
110
+ reviewRequired: false,
111
+ autoApplyCandidate: true,
112
+ autoMergeClaim: false,
113
+ semanticEquivalenceClaim: false,
114
+ reasonCodes: []
115
+ };
116
+ }
117
+
118
+ function summarizeProjectSemanticEditAdmissions(admissions = [], fields = {}) {
119
+ const unique = uniqueProjectSemanticEditAdmissions(admissions);
120
+ const summary = { [fields.totalKey ?? 'admissions']: unique.length };
121
+ for (const field of fields.byKind ?? []) {
122
+ summary[field.key] = unique.filter((admission) => admission[field.property] === field.value).length;
123
+ }
124
+ if (fields.evidenceIdsKey) summary[fields.evidenceIdsKey] = unique.map((admission) => admission.id);
125
+ return summary;
126
+ }
127
+
128
+ function uniqueProjectSemanticEditAdmissions(admissions) {
129
+ const seen = new Set();
130
+ return admissions.filter((admission) => {
131
+ const key = admission.details?.conflictKey ?? admission.id;
132
+ if (!key || seen.has(key)) return false;
133
+ seen.add(key);
134
+ return true;
135
+ });
136
+ }
137
+
138
+ function branchSourceText(file, branch) {
139
+ if (branch === 'worker') return file.workerDeleted ? undefined : file.workerSourceText ?? file.baseSourceText;
140
+ return file.headDeleted ? undefined : file.headSourceText ?? file.baseSourceText;
141
+ }
142
+
143
+ function otherProjectBranchUnchanged(file, branch, options = {}) {
144
+ const other = branch === 'worker' ? branchSourceText(file, 'head') : branchSourceText(file, 'worker');
145
+ return (options.requireBase === false || typeof file.baseSourceText === 'string') && other === file.baseSourceText;
146
+ }
147
+
148
+ function hashProjectSourceText(text) { return typeof text === 'string' ? hashSemanticValue(text) : undefined; }
149
+ function uniqueStrings(values) { return [...new Set(values.filter((value) => typeof value === 'string' && value.length > 0))]; }
150
+ function isPlainObject(value) { return Boolean(value && typeof value === 'object' && !Array.isArray(value)); }
151
+ function safeProjectEvidenceId(value) { return String(value ?? 'unknown').replace(/[^a-zA-Z0-9]+/g, '_').replace(/^_+|_+$/g, '') || 'evidence'; }
152
+
153
+ export {
154
+ branchSourceText,
155
+ createExactBranchProjectSemanticEditAdmissionFile,
156
+ hashProjectSourceText,
157
+ otherProjectBranchUnchanged,
158
+ safeProjectEvidenceId,
159
+ summarizeProjectSemanticEditAdmissions,
160
+ uniqueProjectSemanticEditAdmissions
161
+ };
@@ -0,0 +1,110 @@
1
+ import { hashSemanticValue } from '@shapeshift-labs/frontier-lang-kernel';
2
+ import { compactRecord } from './js-ts-safe-merge-context.js';
3
+ import { globalAugmentationCompatibilityAssessment } from './js-ts-safe-project-merge-global-augmentation-compatibility.js';
4
+
5
+ const ambientRequiredEvidence = [
6
+ 'typescript-program-symbol-evidence',
7
+ 'declaration-output-gate',
8
+ 'consumer-diagnostics-gate',
9
+ 'global-augmentation-compatibility-evidence'
10
+ ];
11
+
12
+ function maybeBlockAmbientProjectFile(file, context, input = {}) {
13
+ const changed = changedProjectTexts(file);
14
+ if (!changed.length) return undefined;
15
+ const sourceText = changed.map((entry) => entry.sourceText).join('\n');
16
+ const ambient = ambientReason(file.sourcePath, sourceText);
17
+ if (!ambient) return undefined;
18
+ const compatibility = ambient.surface === 'global-augmentation'
19
+ ? globalAugmentationCompatibilityAssessment({
20
+ sourcePath: file.sourcePath,
21
+ sourceHashes: uniqueStrings(changed.map((entry) => hashText(entry.sourceText))),
22
+ moduleName: 'global',
23
+ surfaceKind: 'global-augmentation'
24
+ }, input)
25
+ : undefined;
26
+ if (compatibility?.status === 'passed') return undefined;
27
+ return blockedAmbientFile(file, context, ambient, compatibility);
28
+ }
29
+
30
+ function changedProjectTexts(file) {
31
+ const entries = [];
32
+ if (typeof file.workerSourceText === 'string' && file.workerSourceText !== file.baseSourceText) {
33
+ entries.push({ branch: 'worker', sourceText: file.workerSourceText });
34
+ }
35
+ if (typeof file.headSourceText === 'string' && file.headSourceText !== file.baseSourceText) {
36
+ entries.push({ branch: 'head', sourceText: file.headSourceText });
37
+ }
38
+ if (file.workerDeleted || file.headDeleted) entries.push({ branch: file.workerDeleted ? 'worker' : 'head', sourceText: file.baseSourceText ?? '' });
39
+ return entries;
40
+ }
41
+
42
+ function ambientReason(sourcePath, sourceText) {
43
+ if (/\.d\.[cm]?ts$/i.test(String(sourcePath ?? ''))) {
44
+ return { code: 'project-ambient-declaration-merge-blocked', operation: 'blocked-ambient-declaration', surface: 'declaration-file' };
45
+ }
46
+ if (/\bdeclare\s+global\b|\bdeclare\s+module\s+['"]|\bglobalThis\b/.test(String(sourceText ?? ''))) {
47
+ return { code: 'project-global-augmentation-merge-blocked', operation: 'blocked-global-augmentation', surface: 'global-augmentation' };
48
+ }
49
+ return undefined;
50
+ }
51
+
52
+ function blockedAmbientFile(file, context, ambient, compatibility = undefined) {
53
+ const conflict = {
54
+ code: ambient.code,
55
+ gateId: 'project-ambient-declaration-classifier',
56
+ message: `Project ${ambient.surface} changes require TypeScript program, declaration, and consumer diagnostics evidence.`,
57
+ sourcePath: file.sourcePath,
58
+ details: compactRecord({
59
+ reasonCode: ambient.code,
60
+ conflictKey: `project-ambient#${ambient.surface}#${file.sourcePath}`,
61
+ sourcePath: file.sourcePath,
62
+ surface: ambient.surface,
63
+ baseHash: hashText(file.baseSourceText),
64
+ workerHash: hashText(file.workerSourceText),
65
+ headHash: hashText(file.headSourceText),
66
+ requiredEvidence: ambientRequiredEvidence,
67
+ routeId: compatibility?.routeId,
68
+ routeLane: compatibility?.routeLane,
69
+ routeNext: compatibility?.routeNext,
70
+ reasonCodes: compatibility?.reasonCodes,
71
+ globalAugmentationCompatibilityProof: compatibility?.record,
72
+ autoMergeClaim: false,
73
+ semanticEquivalenceClaim: false
74
+ })
75
+ };
76
+ return compactRecord({
77
+ kind: 'frontier.lang.jsTsProjectSafeMergeFile',
78
+ version: 1,
79
+ sourcePath: file.sourcePath,
80
+ language: context.language,
81
+ status: 'blocked',
82
+ operation: ambient.operation,
83
+ baseHash: hashText(file.baseSourceText),
84
+ workerHash: hashText(file.workerSourceText),
85
+ headHash: hashText(file.headSourceText),
86
+ conflicts: [conflict],
87
+ admission: {
88
+ status: 'blocked',
89
+ action: 'human-review',
90
+ reviewRequired: true,
91
+ autoApplyCandidate: false,
92
+ autoMergeClaim: false,
93
+ semanticEquivalenceClaim: false,
94
+ reasonCodes: [ambient.code],
95
+ conflictKeys: [conflict.details.conflictKey]
96
+ },
97
+ summary: { conflicts: 1, projectAmbientDeclarationClassification: true },
98
+ conflictKeys: [conflict.details.conflictKey]
99
+ });
100
+ }
101
+
102
+ function hashText(text) {
103
+ return typeof text === 'string' ? hashSemanticValue(text) : undefined;
104
+ }
105
+
106
+ function uniqueStrings(values) {
107
+ return [...new Set(values.filter((value) => typeof value === 'string' && value.length > 0))];
108
+ }
109
+
110
+ export { maybeBlockAmbientProjectFile };