@cleanslate/sdk 0.1.0

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 (581) hide show
  1. package/LICENSE +22 -0
  2. package/NOTICE +48 -0
  3. package/README.md +103 -0
  4. package/VENDOR.md +60 -0
  5. package/dist/agent/cleanSlateAgentExecutionPhase.d.ts +55 -0
  6. package/dist/agent/cleanSlateAgentExecutionPhase.d.ts.map +1 -0
  7. package/dist/agent/cleanSlateAgentExecutionPhase.js +474 -0
  8. package/dist/agent/cleanSlateAgentExecutionPhase.js.map +1 -0
  9. package/dist/agent/cleanSlateAgentExecutionSupport.d.ts +22 -0
  10. package/dist/agent/cleanSlateAgentExecutionSupport.d.ts.map +1 -0
  11. package/dist/agent/cleanSlateAgentExecutionSupport.js +205 -0
  12. package/dist/agent/cleanSlateAgentExecutionSupport.js.map +1 -0
  13. package/dist/agent/cleanSlateAgentParsing.d.ts +21 -0
  14. package/dist/agent/cleanSlateAgentParsing.d.ts.map +1 -0
  15. package/dist/agent/cleanSlateAgentParsing.js +106 -0
  16. package/dist/agent/cleanSlateAgentParsing.js.map +1 -0
  17. package/dist/agent/cleanSlateAgentSession.d.ts +44 -0
  18. package/dist/agent/cleanSlateAgentSession.d.ts.map +1 -0
  19. package/dist/agent/cleanSlateAgentSession.js +205 -0
  20. package/dist/agent/cleanSlateAgentSession.js.map +1 -0
  21. package/dist/agent/cleanSlateAgentTypes.d.ts +91 -0
  22. package/dist/agent/cleanSlateAgentTypes.d.ts.map +1 -0
  23. package/dist/agent/cleanSlateAgentTypes.js +27 -0
  24. package/dist/agent/cleanSlateAgentTypes.js.map +1 -0
  25. package/dist/agent/cleanSlateCommandPolicy.d.ts +12 -0
  26. package/dist/agent/cleanSlateCommandPolicy.d.ts.map +1 -0
  27. package/dist/agent/cleanSlateCommandPolicy.js +30 -0
  28. package/dist/agent/cleanSlateCommandPolicy.js.map +1 -0
  29. package/dist/agent/cleanSlateContextBudgetManager.d.ts +82 -0
  30. package/dist/agent/cleanSlateContextBudgetManager.d.ts.map +1 -0
  31. package/dist/agent/cleanSlateContextBudgetManager.js +419 -0
  32. package/dist/agent/cleanSlateContextBudgetManager.js.map +1 -0
  33. package/dist/agent/cleanSlateDomainProfile.d.ts +71 -0
  34. package/dist/agent/cleanSlateDomainProfile.d.ts.map +1 -0
  35. package/dist/agent/cleanSlateDomainProfile.js +124 -0
  36. package/dist/agent/cleanSlateDomainProfile.js.map +1 -0
  37. package/dist/agent/cleanSlateExecutionBudget.d.ts +19 -0
  38. package/dist/agent/cleanSlateExecutionBudget.d.ts.map +1 -0
  39. package/dist/agent/cleanSlateExecutionBudget.js +28 -0
  40. package/dist/agent/cleanSlateExecutionBudget.js.map +1 -0
  41. package/dist/agent/cleanSlateExecutionEditPolicy.d.ts +15 -0
  42. package/dist/agent/cleanSlateExecutionEditPolicy.d.ts.map +1 -0
  43. package/dist/agent/cleanSlateExecutionEditPolicy.js +148 -0
  44. package/dist/agent/cleanSlateExecutionEditPolicy.js.map +1 -0
  45. package/dist/agent/cleanSlateExecutionEvidenceLedger.d.ts +23 -0
  46. package/dist/agent/cleanSlateExecutionEvidenceLedger.d.ts.map +1 -0
  47. package/dist/agent/cleanSlateExecutionEvidenceLedger.js +121 -0
  48. package/dist/agent/cleanSlateExecutionEvidenceLedger.js.map +1 -0
  49. package/dist/agent/cleanSlateExecutionLoopPrompts.d.ts +5 -0
  50. package/dist/agent/cleanSlateExecutionLoopPrompts.d.ts.map +1 -0
  51. package/dist/agent/cleanSlateExecutionLoopPrompts.js +41 -0
  52. package/dist/agent/cleanSlateExecutionLoopPrompts.js.map +1 -0
  53. package/dist/agent/cleanSlateExecutionQuery.d.ts +162 -0
  54. package/dist/agent/cleanSlateExecutionQuery.d.ts.map +1 -0
  55. package/dist/agent/cleanSlateExecutionQuery.js +1448 -0
  56. package/dist/agent/cleanSlateExecutionQuery.js.map +1 -0
  57. package/dist/agent/cleanSlateFilesModifiedService.d.ts +96 -0
  58. package/dist/agent/cleanSlateFilesModifiedService.d.ts.map +1 -0
  59. package/dist/agent/cleanSlateFilesModifiedService.js +581 -0
  60. package/dist/agent/cleanSlateFilesModifiedService.js.map +1 -0
  61. package/dist/agent/cleanSlateNativeToolTranscript.d.ts +22 -0
  62. package/dist/agent/cleanSlateNativeToolTranscript.d.ts.map +1 -0
  63. package/dist/agent/cleanSlateNativeToolTranscript.js +77 -0
  64. package/dist/agent/cleanSlateNativeToolTranscript.js.map +1 -0
  65. package/dist/agent/cleanSlatePrompts.d.ts +30 -0
  66. package/dist/agent/cleanSlatePrompts.d.ts.map +1 -0
  67. package/dist/agent/cleanSlatePrompts.js +65 -0
  68. package/dist/agent/cleanSlatePrompts.js.map +1 -0
  69. package/dist/agent/cleanSlateQueryRunner.d.ts +56 -0
  70. package/dist/agent/cleanSlateQueryRunner.d.ts.map +1 -0
  71. package/dist/agent/cleanSlateQueryRunner.js +69 -0
  72. package/dist/agent/cleanSlateQueryRunner.js.map +1 -0
  73. package/dist/agent/cleanSlateRuntimePromptBuilder.d.ts +30 -0
  74. package/dist/agent/cleanSlateRuntimePromptBuilder.d.ts.map +1 -0
  75. package/dist/agent/cleanSlateRuntimePromptBuilder.js +99 -0
  76. package/dist/agent/cleanSlateRuntimePromptBuilder.js.map +1 -0
  77. package/dist/agent/cleanSlateStreamingToolExecutor.d.ts +55 -0
  78. package/dist/agent/cleanSlateStreamingToolExecutor.d.ts.map +1 -0
  79. package/dist/agent/cleanSlateStreamingToolExecutor.js +214 -0
  80. package/dist/agent/cleanSlateStreamingToolExecutor.js.map +1 -0
  81. package/dist/agent/cleanSlateToolCallLedger.d.ts +32 -0
  82. package/dist/agent/cleanSlateToolCallLedger.d.ts.map +1 -0
  83. package/dist/agent/cleanSlateToolCallLedger.js +164 -0
  84. package/dist/agent/cleanSlateToolCallLedger.js.map +1 -0
  85. package/dist/agent/cleanSlateToolResultPromptSerializer.d.ts +9 -0
  86. package/dist/agent/cleanSlateToolResultPromptSerializer.d.ts.map +1 -0
  87. package/dist/agent/cleanSlateToolResultPromptSerializer.js +184 -0
  88. package/dist/agent/cleanSlateToolResultPromptSerializer.js.map +1 -0
  89. package/dist/composer/commands/slashCommands.d.ts +8 -0
  90. package/dist/composer/commands/slashCommands.d.ts.map +1 -0
  91. package/dist/composer/commands/slashCommands.js +46 -0
  92. package/dist/composer/commands/slashCommands.js.map +1 -0
  93. package/dist/composer/instructions/baseInstructions.d.ts +3 -0
  94. package/dist/composer/instructions/baseInstructions.d.ts.map +1 -0
  95. package/dist/composer/instructions/baseInstructions.js +35 -0
  96. package/dist/composer/instructions/baseInstructions.js.map +1 -0
  97. package/dist/composer/instructions/runtimeInstructions.d.ts +11 -0
  98. package/dist/composer/instructions/runtimeInstructions.d.ts.map +1 -0
  99. package/dist/composer/instructions/runtimeInstructions.js +31 -0
  100. package/dist/composer/instructions/runtimeInstructions.js.map +1 -0
  101. package/dist/composer/kernel/coreKernel.d.ts +3 -0
  102. package/dist/composer/kernel/coreKernel.d.ts.map +1 -0
  103. package/dist/composer/kernel/coreKernel.js +11 -0
  104. package/dist/composer/kernel/coreKernel.js.map +1 -0
  105. package/dist/composer/kernel/editingRules.d.ts +3 -0
  106. package/dist/composer/kernel/editingRules.d.ts.map +1 -0
  107. package/dist/composer/kernel/editingRules.js +24 -0
  108. package/dist/composer/kernel/editingRules.js.map +1 -0
  109. package/dist/composer/kernel/toolProtocols.d.ts +2 -0
  110. package/dist/composer/kernel/toolProtocols.d.ts.map +1 -0
  111. package/dist/composer/kernel/toolProtocols.js +32 -0
  112. package/dist/composer/kernel/toolProtocols.js.map +1 -0
  113. package/dist/composer/modes/execution.mode.d.ts +2 -0
  114. package/dist/composer/modes/execution.mode.d.ts.map +1 -0
  115. package/dist/composer/modes/execution.mode.js +21 -0
  116. package/dist/composer/modes/execution.mode.js.map +1 -0
  117. package/dist/composer/modes/planning.mode.d.ts +2 -0
  118. package/dist/composer/modes/planning.mode.d.ts.map +1 -0
  119. package/dist/composer/modes/planning.mode.js +23 -0
  120. package/dist/composer/modes/planning.mode.js.map +1 -0
  121. package/dist/composer/promptComposer.d.ts +22 -0
  122. package/dist/composer/promptComposer.d.ts.map +1 -0
  123. package/dist/composer/promptComposer.js +62 -0
  124. package/dist/composer/promptComposer.js.map +1 -0
  125. package/dist/composer/registry/agentSchema.d.ts +16 -0
  126. package/dist/composer/registry/agentSchema.d.ts.map +1 -0
  127. package/dist/composer/registry/agentSchema.js +6 -0
  128. package/dist/composer/registry/agentSchema.js.map +1 -0
  129. package/dist/core/arrays.d.ts +311 -0
  130. package/dist/core/arrays.d.ts.map +1 -0
  131. package/dist/core/arrays.js +811 -0
  132. package/dist/core/arrays.js.map +1 -0
  133. package/dist/core/arraysFind.d.ts +72 -0
  134. package/dist/core/arraysFind.d.ts.map +1 -0
  135. package/dist/core/arraysFind.js +200 -0
  136. package/dist/core/arraysFind.js.map +1 -0
  137. package/dist/core/assert.d.ts +36 -0
  138. package/dist/core/assert.d.ts.map +1 -0
  139. package/dist/core/assert.js +84 -0
  140. package/dist/core/assert.js.map +1 -0
  141. package/dist/core/async.d.ts +11 -0
  142. package/dist/core/async.d.ts.map +1 -0
  143. package/dist/core/async.js +6 -0
  144. package/dist/core/async.js.map +1 -0
  145. package/dist/core/buffer.d.ts +23 -0
  146. package/dist/core/buffer.d.ts.map +1 -0
  147. package/dist/core/buffer.js +40 -0
  148. package/dist/core/buffer.js.map +1 -0
  149. package/dist/core/cancellation.d.ts +52 -0
  150. package/dist/core/cancellation.d.ts.map +1 -0
  151. package/dist/core/cancellation.js +169 -0
  152. package/dist/core/cancellation.js.map +1 -0
  153. package/dist/core/charCode.d.ts +428 -0
  154. package/dist/core/charCode.d.ts.map +1 -0
  155. package/dist/core/charCode.js +439 -0
  156. package/dist/core/charCode.js.map +1 -0
  157. package/dist/core/collections.d.ts +49 -0
  158. package/dist/core/collections.d.ts.map +1 -0
  159. package/dist/core/collections.js +132 -0
  160. package/dist/core/collections.js.map +1 -0
  161. package/dist/core/diff/diff.d.ts +151 -0
  162. package/dist/core/diff/diff.d.ts.map +1 -0
  163. package/dist/core/diff/diff.js +1076 -0
  164. package/dist/core/diff/diff.js.map +1 -0
  165. package/dist/core/diff/diffChange.d.ts +39 -0
  166. package/dist/core/diff/diffChange.d.ts.map +1 -0
  167. package/dist/core/diff/diffChange.js +37 -0
  168. package/dist/core/diff/diffChange.js.map +1 -0
  169. package/dist/core/errors.d.ts +114 -0
  170. package/dist/core/errors.d.ts.map +1 -0
  171. package/dist/core/errors.js +258 -0
  172. package/dist/core/errors.js.map +1 -0
  173. package/dist/core/event.d.ts +595 -0
  174. package/dist/core/event.d.ts.map +1 -0
  175. package/dist/core/event.js +1479 -0
  176. package/dist/core/event.js.map +1 -0
  177. package/dist/core/functional.d.ts +5 -0
  178. package/dist/core/functional.d.ts.map +1 -0
  179. package/dist/core/functional.js +35 -0
  180. package/dist/core/functional.js.map +1 -0
  181. package/dist/core/hash.d.ts +15 -0
  182. package/dist/core/hash.d.ts.map +1 -0
  183. package/dist/core/hash.js +27 -0
  184. package/dist/core/hash.js.map +1 -0
  185. package/dist/core/iterator.d.ts +33 -0
  186. package/dist/core/iterator.d.ts.map +1 -0
  187. package/dist/core/iterator.js +188 -0
  188. package/dist/core/iterator.js.map +1 -0
  189. package/dist/core/lifecycle.d.ts +313 -0
  190. package/dist/core/lifecycle.d.ts.map +1 -0
  191. package/dist/core/lifecycle.js +789 -0
  192. package/dist/core/lifecycle.js.map +1 -0
  193. package/dist/core/linkedList.d.ts +17 -0
  194. package/dist/core/linkedList.d.ts.map +1 -0
  195. package/dist/core/linkedList.js +138 -0
  196. package/dist/core/linkedList.js.map +1 -0
  197. package/dist/core/map.d.ts +175 -0
  198. package/dist/core/map.d.ts.map +1 -0
  199. package/dist/core/map.js +796 -0
  200. package/dist/core/map.js.map +1 -0
  201. package/dist/core/marshallingIds.d.ts +29 -0
  202. package/dist/core/marshallingIds.d.ts.map +1 -0
  203. package/dist/core/marshallingIds.js +38 -0
  204. package/dist/core/marshallingIds.js.map +1 -0
  205. package/dist/core/observable.d.ts +28 -0
  206. package/dist/core/observable.d.ts.map +1 -0
  207. package/dist/core/observable.js +6 -0
  208. package/dist/core/observable.js.map +1 -0
  209. package/dist/core/platform.d.ts +4 -0
  210. package/dist/core/platform.d.ts.map +1 -0
  211. package/dist/core/platform.js +17 -0
  212. package/dist/core/platform.js.map +1 -0
  213. package/dist/core/position.d.ts +91 -0
  214. package/dist/core/position.d.ts.map +1 -0
  215. package/dist/core/position.js +145 -0
  216. package/dist/core/position.js.map +1 -0
  217. package/dist/core/range.d.ts +198 -0
  218. package/dist/core/range.d.ts.map +1 -0
  219. package/dist/core/range.js +426 -0
  220. package/dist/core/range.js.map +1 -0
  221. package/dist/core/resources.d.ts +10 -0
  222. package/dist/core/resources.d.ts.map +1 -0
  223. package/dist/core/resources.js +126 -0
  224. package/dist/core/resources.js.map +1 -0
  225. package/dist/core/sequence.d.ts +20 -0
  226. package/dist/core/sequence.d.ts.map +1 -0
  227. package/dist/core/sequence.js +21 -0
  228. package/dist/core/sequence.js.map +1 -0
  229. package/dist/core/stopwatch.d.ts +11 -0
  230. package/dist/core/stopwatch.d.ts.map +1 -0
  231. package/dist/core/stopwatch.js +33 -0
  232. package/dist/core/stopwatch.js.map +1 -0
  233. package/dist/core/symbols.d.ts +5 -0
  234. package/dist/core/symbols.d.ts.map +1 -0
  235. package/dist/core/symbols.js +13 -0
  236. package/dist/core/symbols.js.map +1 -0
  237. package/dist/core/types.d.ts +229 -0
  238. package/dist/core/types.d.ts.map +1 -0
  239. package/dist/core/types.js +278 -0
  240. package/dist/core/types.js.map +1 -0
  241. package/dist/core/uint.d.ts +32 -0
  242. package/dist/core/uint.d.ts.map +1 -0
  243. package/dist/core/uint.js +57 -0
  244. package/dist/core/uint.js.map +1 -0
  245. package/dist/core/uri.d.ts +172 -0
  246. package/dist/core/uri.d.ts.map +1 -0
  247. package/dist/core/uri.js +623 -0
  248. package/dist/core/uri.js.map +1 -0
  249. package/dist/host/browserAutomation.d.ts +276 -0
  250. package/dist/host/browserAutomation.d.ts.map +1 -0
  251. package/dist/host/browserAutomation.js +6 -0
  252. package/dist/host/browserAutomation.js.map +1 -0
  253. package/dist/host/diagnostics.d.ts +68 -0
  254. package/dist/host/diagnostics.d.ts.map +1 -0
  255. package/dist/host/diagnostics.js +41 -0
  256. package/dist/host/diagnostics.js.map +1 -0
  257. package/dist/host/files.d.ts +70 -0
  258. package/dist/host/files.d.ts.map +1 -0
  259. package/dist/host/files.js +54 -0
  260. package/dist/host/files.js.map +1 -0
  261. package/dist/host/services.d.ts +106 -0
  262. package/dist/host/services.d.ts.map +1 -0
  263. package/dist/host/services.js +6 -0
  264. package/dist/host/services.js.map +1 -0
  265. package/dist/host/symbols.d.ts +45 -0
  266. package/dist/host/symbols.d.ts.map +1 -0
  267. package/dist/host/symbols.js +43 -0
  268. package/dist/host/symbols.js.map +1 -0
  269. package/dist/host/textModel.d.ts +83 -0
  270. package/dist/host/textModel.d.ts.map +1 -0
  271. package/dist/host/textModel.js +6 -0
  272. package/dist/host/textModel.js.map +1 -0
  273. package/dist/host/workspace.d.ts +123 -0
  274. package/dist/host/workspace.d.ts.map +1 -0
  275. package/dist/host/workspace.js +32 -0
  276. package/dist/host/workspace.js.map +1 -0
  277. package/dist/index.d.ts +40 -0
  278. package/dist/index.d.ts.map +1 -0
  279. package/dist/index.js +26 -0
  280. package/dist/index.js.map +1 -0
  281. package/dist/node/cleanSlateAnthropicMessageAdapter.d.ts +12 -0
  282. package/dist/node/cleanSlateAnthropicMessageAdapter.d.ts.map +1 -0
  283. package/dist/node/cleanSlateAnthropicMessageAdapter.js +130 -0
  284. package/dist/node/cleanSlateAnthropicMessageAdapter.js.map +1 -0
  285. package/dist/node/cleanSlateHeadlessRunner.d.ts +63 -0
  286. package/dist/node/cleanSlateHeadlessRunner.d.ts.map +1 -0
  287. package/dist/node/cleanSlateHeadlessRunner.js +84 -0
  288. package/dist/node/cleanSlateHeadlessRunner.js.map +1 -0
  289. package/dist/node/cleanSlateNodeAgentRuntime.d.ts +94 -0
  290. package/dist/node/cleanSlateNodeAgentRuntime.d.ts.map +1 -0
  291. package/dist/node/cleanSlateNodeAgentRuntime.js +339 -0
  292. package/dist/node/cleanSlateNodeAgentRuntime.js.map +1 -0
  293. package/dist/node/cleanSlateNodeBrowserAutomation.d.ts +279 -0
  294. package/dist/node/cleanSlateNodeBrowserAutomation.d.ts.map +1 -0
  295. package/dist/node/cleanSlateNodeBrowserAutomation.js +470 -0
  296. package/dist/node/cleanSlateNodeBrowserAutomation.js.map +1 -0
  297. package/dist/node/cleanSlateNodeCommandService.d.ts +40 -0
  298. package/dist/node/cleanSlateNodeCommandService.d.ts.map +1 -0
  299. package/dist/node/cleanSlateNodeCommandService.js +435 -0
  300. package/dist/node/cleanSlateNodeCommandService.js.map +1 -0
  301. package/dist/node/cleanSlateNodeFileServices.d.ts +68 -0
  302. package/dist/node/cleanSlateNodeFileServices.d.ts.map +1 -0
  303. package/dist/node/cleanSlateNodeFileServices.js +138 -0
  304. package/dist/node/cleanSlateNodeFileServices.js.map +1 -0
  305. package/dist/node/cleanSlateNodeIndexService.d.ts +17 -0
  306. package/dist/node/cleanSlateNodeIndexService.d.ts.map +1 -0
  307. package/dist/node/cleanSlateNodeIndexService.js +128 -0
  308. package/dist/node/cleanSlateNodeIndexService.js.map +1 -0
  309. package/dist/node/cleanSlateNodeLanguageCommands.d.ts +11 -0
  310. package/dist/node/cleanSlateNodeLanguageCommands.d.ts.map +1 -0
  311. package/dist/node/cleanSlateNodeLanguageCommands.js +146 -0
  312. package/dist/node/cleanSlateNodeLanguageCommands.js.map +1 -0
  313. package/dist/node/cleanSlateNodeMainService.d.ts +87 -0
  314. package/dist/node/cleanSlateNodeMainService.d.ts.map +1 -0
  315. package/dist/node/cleanSlateNodeMainService.js +1304 -0
  316. package/dist/node/cleanSlateNodeMainService.js.map +1 -0
  317. package/dist/node/cleanSlateNodeMcpClient.d.ts +20 -0
  318. package/dist/node/cleanSlateNodeMcpClient.d.ts.map +1 -0
  319. package/dist/node/cleanSlateNodeMcpClient.js +184 -0
  320. package/dist/node/cleanSlateNodeMcpClient.js.map +1 -0
  321. package/dist/node/cleanSlateNodeSearchService.d.ts +14 -0
  322. package/dist/node/cleanSlateNodeSearchService.d.ts.map +1 -0
  323. package/dist/node/cleanSlateNodeSearchService.js +180 -0
  324. package/dist/node/cleanSlateNodeSearchService.js.map +1 -0
  325. package/dist/node/cleanSlateNodeTextModel.d.ts +56 -0
  326. package/dist/node/cleanSlateNodeTextModel.d.ts.map +1 -0
  327. package/dist/node/cleanSlateNodeTextModel.js +127 -0
  328. package/dist/node/cleanSlateNodeTextModel.js.map +1 -0
  329. package/dist/node/cleanSlateNodeToolContext.d.ts +50 -0
  330. package/dist/node/cleanSlateNodeToolContext.d.ts.map +1 -0
  331. package/dist/node/cleanSlateNodeToolContext.js +134 -0
  332. package/dist/node/cleanSlateNodeToolContext.js.map +1 -0
  333. package/dist/node/cleanSlateNodeWebRetrieval.d.ts +20 -0
  334. package/dist/node/cleanSlateNodeWebRetrieval.d.ts.map +1 -0
  335. package/dist/node/cleanSlateNodeWebRetrieval.js +379 -0
  336. package/dist/node/cleanSlateNodeWebRetrieval.js.map +1 -0
  337. package/dist/node/cleanSlateOpenAIMessageAdapter.d.ts +8 -0
  338. package/dist/node/cleanSlateOpenAIMessageAdapter.d.ts.map +1 -0
  339. package/dist/node/cleanSlateOpenAIMessageAdapter.js +111 -0
  340. package/dist/node/cleanSlateOpenAIMessageAdapter.js.map +1 -0
  341. package/dist/node/cleanSlateProviderSchemaNormalizer.d.ts +18 -0
  342. package/dist/node/cleanSlateProviderSchemaNormalizer.d.ts.map +1 -0
  343. package/dist/node/cleanSlateProviderSchemaNormalizer.js +175 -0
  344. package/dist/node/cleanSlateProviderSchemaNormalizer.js.map +1 -0
  345. package/dist/node/index.d.ts +25 -0
  346. package/dist/node/index.d.ts.map +1 -0
  347. package/dist/node/index.js +28 -0
  348. package/dist/node/index.js.map +1 -0
  349. package/dist/protocol/cleanSlateAI.d.ts +964 -0
  350. package/dist/protocol/cleanSlateAI.d.ts.map +1 -0
  351. package/dist/protocol/cleanSlateAI.js +35 -0
  352. package/dist/protocol/cleanSlateAI.js.map +1 -0
  353. package/dist/protocol/cleanSlateModelCapabilities.d.ts +86 -0
  354. package/dist/protocol/cleanSlateModelCapabilities.d.ts.map +1 -0
  355. package/dist/protocol/cleanSlateModelCapabilities.js +1104 -0
  356. package/dist/protocol/cleanSlateModelCapabilities.js.map +1 -0
  357. package/dist/protocol/cleanSlateProviderMessageTransforms.d.ts +11 -0
  358. package/dist/protocol/cleanSlateProviderMessageTransforms.d.ts.map +1 -0
  359. package/dist/protocol/cleanSlateProviderMessageTransforms.js +178 -0
  360. package/dist/protocol/cleanSlateProviderMessageTransforms.js.map +1 -0
  361. package/dist/protocol/cleanSlateService.d.ts +68 -0
  362. package/dist/protocol/cleanSlateService.d.ts.map +1 -0
  363. package/dist/protocol/cleanSlateService.js +1149 -0
  364. package/dist/protocol/cleanSlateService.js.map +1 -0
  365. package/dist/services/cleanSlateCancellation.d.ts +7 -0
  366. package/dist/services/cleanSlateCancellation.d.ts.map +1 -0
  367. package/dist/services/cleanSlateCancellation.js +56 -0
  368. package/dist/services/cleanSlateCancellation.js.map +1 -0
  369. package/dist/services/cleanSlateCommandExecutionService.d.ts +25 -0
  370. package/dist/services/cleanSlateCommandExecutionService.d.ts.map +1 -0
  371. package/dist/services/cleanSlateCommandExecutionService.js +31 -0
  372. package/dist/services/cleanSlateCommandExecutionService.js.map +1 -0
  373. package/dist/services/cleanSlateDiffService.d.ts +62 -0
  374. package/dist/services/cleanSlateDiffService.d.ts.map +1 -0
  375. package/dist/services/cleanSlateDiffService.js +428 -0
  376. package/dist/services/cleanSlateDiffService.js.map +1 -0
  377. package/dist/services/cleanSlateEditMatchValidator.d.ts +63 -0
  378. package/dist/services/cleanSlateEditMatchValidator.d.ts.map +1 -0
  379. package/dist/services/cleanSlateEditMatchValidator.js +341 -0
  380. package/dist/services/cleanSlateEditMatchValidator.js.map +1 -0
  381. package/dist/services/cleanSlateEditService.d.ts +155 -0
  382. package/dist/services/cleanSlateEditService.d.ts.map +1 -0
  383. package/dist/services/cleanSlateEditService.js +848 -0
  384. package/dist/services/cleanSlateEditService.js.map +1 -0
  385. package/dist/services/cleanSlateFileHistory.d.ts +56 -0
  386. package/dist/services/cleanSlateFileHistory.d.ts.map +1 -0
  387. package/dist/services/cleanSlateFileHistory.js +157 -0
  388. package/dist/services/cleanSlateFileHistory.js.map +1 -0
  389. package/dist/services/cleanSlateTaskEvidenceCodec.d.ts +15 -0
  390. package/dist/services/cleanSlateTaskEvidenceCodec.d.ts.map +1 -0
  391. package/dist/services/cleanSlateTaskEvidenceCodec.js +151 -0
  392. package/dist/services/cleanSlateTaskEvidenceCodec.js.map +1 -0
  393. package/dist/services/cleanSlateTaskSessionService.d.ts +258 -0
  394. package/dist/services/cleanSlateTaskSessionService.d.ts.map +1 -0
  395. package/dist/services/cleanSlateTaskSessionService.js +1079 -0
  396. package/dist/services/cleanSlateTaskSessionService.js.map +1 -0
  397. package/dist/services/cleanSlateTaskState.d.ts +32 -0
  398. package/dist/services/cleanSlateTaskState.d.ts.map +1 -0
  399. package/dist/services/cleanSlateTaskState.js +40 -0
  400. package/dist/services/cleanSlateTaskState.js.map +1 -0
  401. package/dist/services/cleanSlateThreadService.d.ts +64 -0
  402. package/dist/services/cleanSlateThreadService.d.ts.map +1 -0
  403. package/dist/services/cleanSlateThreadService.js +188 -0
  404. package/dist/services/cleanSlateThreadService.js.map +1 -0
  405. package/dist/services/cleanSlateTools.d.ts +29 -0
  406. package/dist/services/cleanSlateTools.d.ts.map +1 -0
  407. package/dist/services/cleanSlateTools.js +38 -0
  408. package/dist/services/cleanSlateTools.js.map +1 -0
  409. package/dist/services/cleanSlateVerificationTargetTracker.d.ts +23 -0
  410. package/dist/services/cleanSlateVerificationTargetTracker.d.ts.map +1 -0
  411. package/dist/services/cleanSlateVerificationTargetTracker.js +214 -0
  412. package/dist/services/cleanSlateVerificationTargetTracker.js.map +1 -0
  413. package/dist/skills/cleanSlateSkillCatalog.d.ts +29 -0
  414. package/dist/skills/cleanSlateSkillCatalog.d.ts.map +1 -0
  415. package/dist/skills/cleanSlateSkillCatalog.js +225 -0
  416. package/dist/skills/cleanSlateSkillCatalog.js.map +1 -0
  417. package/dist/tools/ApplyEditTool.d.ts +73 -0
  418. package/dist/tools/ApplyEditTool.d.ts.map +1 -0
  419. package/dist/tools/ApplyEditTool.js +741 -0
  420. package/dist/tools/ApplyEditTool.js.map +1 -0
  421. package/dist/tools/AskQuestionTool.d.ts +3 -0
  422. package/dist/tools/AskQuestionTool.d.ts.map +1 -0
  423. package/dist/tools/AskQuestionTool.js +113 -0
  424. package/dist/tools/AskQuestionTool.js.map +1 -0
  425. package/dist/tools/BrowserAutomationTools.d.ts +28 -0
  426. package/dist/tools/BrowserAutomationTools.d.ts.map +1 -0
  427. package/dist/tools/BrowserAutomationTools.js +639 -0
  428. package/dist/tools/BrowserAutomationTools.js.map +1 -0
  429. package/dist/tools/CreateMultipleFilesTool.d.ts +6 -0
  430. package/dist/tools/CreateMultipleFilesTool.d.ts.map +1 -0
  431. package/dist/tools/CreateMultipleFilesTool.js +115 -0
  432. package/dist/tools/CreateMultipleFilesTool.js.map +1 -0
  433. package/dist/tools/ExecuteCommandTool.d.ts +12 -0
  434. package/dist/tools/ExecuteCommandTool.d.ts.map +1 -0
  435. package/dist/tools/ExecuteCommandTool.js +378 -0
  436. package/dist/tools/ExecuteCommandTool.js.map +1 -0
  437. package/dist/tools/FileHistoryRewindTool.d.ts +3 -0
  438. package/dist/tools/FileHistoryRewindTool.d.ts.map +1 -0
  439. package/dist/tools/FileHistoryRewindTool.js +45 -0
  440. package/dist/tools/FileHistoryRewindTool.js.map +1 -0
  441. package/dist/tools/FindByNameTool.d.ts +6 -0
  442. package/dist/tools/FindByNameTool.d.ts.map +1 -0
  443. package/dist/tools/FindByNameTool.js +80 -0
  444. package/dist/tools/FindByNameTool.js.map +1 -0
  445. package/dist/tools/FindReferencesTool.d.ts +3 -0
  446. package/dist/tools/FindReferencesTool.d.ts.map +1 -0
  447. package/dist/tools/FindReferencesTool.js +128 -0
  448. package/dist/tools/FindReferencesTool.js.map +1 -0
  449. package/dist/tools/GetDefinitionsTool.d.ts +3 -0
  450. package/dist/tools/GetDefinitionsTool.d.ts.map +1 -0
  451. package/dist/tools/GetDefinitionsTool.js +136 -0
  452. package/dist/tools/GetDefinitionsTool.js.map +1 -0
  453. package/dist/tools/GetOpenFilesTool.d.ts +6 -0
  454. package/dist/tools/GetOpenFilesTool.d.ts.map +1 -0
  455. package/dist/tools/GetOpenFilesTool.js +21 -0
  456. package/dist/tools/GetOpenFilesTool.js.map +1 -0
  457. package/dist/tools/GrepSearchTool.d.ts +7 -0
  458. package/dist/tools/GrepSearchTool.d.ts.map +1 -0
  459. package/dist/tools/GrepSearchTool.js +95 -0
  460. package/dist/tools/GrepSearchTool.js.map +1 -0
  461. package/dist/tools/ListDirTool.d.ts +6 -0
  462. package/dist/tools/ListDirTool.d.ts.map +1 -0
  463. package/dist/tools/ListDirTool.js +39 -0
  464. package/dist/tools/ListDirTool.js.map +1 -0
  465. package/dist/tools/MCPTools.d.ts +6 -0
  466. package/dist/tools/MCPTools.d.ts.map +1 -0
  467. package/dist/tools/MCPTools.js +103 -0
  468. package/dist/tools/MCPTools.js.map +1 -0
  469. package/dist/tools/MultiFileReplaceTool.d.ts +6 -0
  470. package/dist/tools/MultiFileReplaceTool.d.ts.map +1 -0
  471. package/dist/tools/MultiFileReplaceTool.js +345 -0
  472. package/dist/tools/MultiFileReplaceTool.js.map +1 -0
  473. package/dist/tools/ReadFileRangeTool.d.ts +6 -0
  474. package/dist/tools/ReadFileRangeTool.d.ts.map +1 -0
  475. package/dist/tools/ReadFileRangeTool.js +150 -0
  476. package/dist/tools/ReadFileRangeTool.js.map +1 -0
  477. package/dist/tools/ReadFileTool.d.ts +6 -0
  478. package/dist/tools/ReadFileTool.d.ts.map +1 -0
  479. package/dist/tools/ReadFileTool.js +183 -0
  480. package/dist/tools/ReadFileTool.js.map +1 -0
  481. package/dist/tools/ReadLintsTool.d.ts +6 -0
  482. package/dist/tools/ReadLintsTool.d.ts.map +1 -0
  483. package/dist/tools/ReadLintsTool.js +83 -0
  484. package/dist/tools/ReadLintsTool.js.map +1 -0
  485. package/dist/tools/ReadReferenceTool.d.ts +6 -0
  486. package/dist/tools/ReadReferenceTool.d.ts.map +1 -0
  487. package/dist/tools/ReadReferenceTool.js +24 -0
  488. package/dist/tools/ReadReferenceTool.js.map +1 -0
  489. package/dist/tools/ReadSymbolsTool.d.ts +3 -0
  490. package/dist/tools/ReadSymbolsTool.d.ts.map +1 -0
  491. package/dist/tools/ReadSymbolsTool.js +100 -0
  492. package/dist/tools/ReadSymbolsTool.js.map +1 -0
  493. package/dist/tools/SearchCodebaseTool.d.ts +6 -0
  494. package/dist/tools/SearchCodebaseTool.d.ts.map +1 -0
  495. package/dist/tools/SearchCodebaseTool.js +30 -0
  496. package/dist/tools/SearchCodebaseTool.js.map +1 -0
  497. package/dist/tools/SearchWorkspaceTool.d.ts +7 -0
  498. package/dist/tools/SearchWorkspaceTool.d.ts.map +1 -0
  499. package/dist/tools/SearchWorkspaceTool.js +21 -0
  500. package/dist/tools/SearchWorkspaceTool.js.map +1 -0
  501. package/dist/tools/SemanticSearchTool.d.ts +12 -0
  502. package/dist/tools/SemanticSearchTool.d.ts.map +1 -0
  503. package/dist/tools/SemanticSearchTool.js +46 -0
  504. package/dist/tools/SemanticSearchTool.js.map +1 -0
  505. package/dist/tools/SkillTools.d.ts +3 -0
  506. package/dist/tools/SkillTools.d.ts.map +1 -0
  507. package/dist/tools/SkillTools.js +108 -0
  508. package/dist/tools/SkillTools.js.map +1 -0
  509. package/dist/tools/SpawnWorkerTool.d.ts +6 -0
  510. package/dist/tools/SpawnWorkerTool.d.ts.map +1 -0
  511. package/dist/tools/SpawnWorkerTool.js +28 -0
  512. package/dist/tools/SpawnWorkerTool.js.map +1 -0
  513. package/dist/tools/SubmitArtifactTool.d.ts +3 -0
  514. package/dist/tools/SubmitArtifactTool.d.ts.map +1 -0
  515. package/dist/tools/SubmitArtifactTool.js +121 -0
  516. package/dist/tools/SubmitArtifactTool.js.map +1 -0
  517. package/dist/tools/UndoEditTool.d.ts +3 -0
  518. package/dist/tools/UndoEditTool.d.ts.map +1 -0
  519. package/dist/tools/UndoEditTool.js +66 -0
  520. package/dist/tools/UndoEditTool.js.map +1 -0
  521. package/dist/tools/UpdateTodoTool.d.ts +6 -0
  522. package/dist/tools/UpdateTodoTool.d.ts.map +1 -0
  523. package/dist/tools/UpdateTodoTool.js +116 -0
  524. package/dist/tools/UpdateTodoTool.js.map +1 -0
  525. package/dist/tools/WebRetrievalTools.d.ts +4 -0
  526. package/dist/tools/WebRetrievalTools.d.ts.map +1 -0
  527. package/dist/tools/WebRetrievalTools.js +169 -0
  528. package/dist/tools/WebRetrievalTools.js.map +1 -0
  529. package/dist/tools/WriteFileTool.d.ts +6 -0
  530. package/dist/tools/WriteFileTool.d.ts.map +1 -0
  531. package/dist/tools/WriteFileTool.js +145 -0
  532. package/dist/tools/WriteFileTool.js.map +1 -0
  533. package/dist/tools/cleanSlateFileReadPolicy.d.ts +33 -0
  534. package/dist/tools/cleanSlateFileReadPolicy.d.ts.map +1 -0
  535. package/dist/tools/cleanSlateFileReadPolicy.js +84 -0
  536. package/dist/tools/cleanSlateFileReadPolicy.js.map +1 -0
  537. package/dist/tools/cleanSlateHostTypes.d.ts +100 -0
  538. package/dist/tools/cleanSlateHostTypes.d.ts.map +1 -0
  539. package/dist/tools/cleanSlateHostTypes.js +6 -0
  540. package/dist/tools/cleanSlateHostTypes.js.map +1 -0
  541. package/dist/tools/cleanSlatePlanArtifactPolicy.d.ts +47 -0
  542. package/dist/tools/cleanSlatePlanArtifactPolicy.d.ts.map +1 -0
  543. package/dist/tools/cleanSlatePlanArtifactPolicy.js +126 -0
  544. package/dist/tools/cleanSlatePlanArtifactPolicy.js.map +1 -0
  545. package/dist/tools/cleanSlateStaleDiagnosticPolicy.d.ts +3 -0
  546. package/dist/tools/cleanSlateStaleDiagnosticPolicy.d.ts.map +1 -0
  547. package/dist/tools/cleanSlateStaleDiagnosticPolicy.js +13 -0
  548. package/dist/tools/cleanSlateStaleDiagnosticPolicy.js.map +1 -0
  549. package/dist/tools/languageFeatureActivation.d.ts +13 -0
  550. package/dist/tools/languageFeatureActivation.d.ts.map +1 -0
  551. package/dist/tools/languageFeatureActivation.js +95 -0
  552. package/dist/tools/languageFeatureActivation.js.map +1 -0
  553. package/dist/tools/registry.d.ts +5 -0
  554. package/dist/tools/registry.d.ts.map +1 -0
  555. package/dist/tools/registry.js +104 -0
  556. package/dist/tools/registry.js.map +1 -0
  557. package/dist/tools/structuredEditCanonicalizer.d.ts +11 -0
  558. package/dist/tools/structuredEditCanonicalizer.d.ts.map +1 -0
  559. package/dist/tools/structuredEditCanonicalizer.js +44 -0
  560. package/dist/tools/structuredEditCanonicalizer.js.map +1 -0
  561. package/dist/tools/symbolContext.d.ts +36 -0
  562. package/dist/tools/symbolContext.d.ts.map +1 -0
  563. package/dist/tools/symbolContext.js +146 -0
  564. package/dist/tools/symbolContext.js.map +1 -0
  565. package/dist/tools/symbolEditResolver.d.ts +11 -0
  566. package/dist/tools/symbolEditResolver.d.ts.map +1 -0
  567. package/dist/tools/symbolEditResolver.js +259 -0
  568. package/dist/tools/symbolEditResolver.js.map +1 -0
  569. package/dist/tools/symbolIndex.d.ts +18 -0
  570. package/dist/tools/symbolIndex.d.ts.map +1 -0
  571. package/dist/tools/symbolIndex.js +235 -0
  572. package/dist/tools/symbolIndex.js.map +1 -0
  573. package/dist/tools/types.d.ts +108 -0
  574. package/dist/tools/types.d.ts.map +1 -0
  575. package/dist/tools/types.js +6 -0
  576. package/dist/tools/types.js.map +1 -0
  577. package/dist/tools/utils.d.ts +56 -0
  578. package/dist/tools/utils.d.ts.map +1 -0
  579. package/dist/tools/utils.js +205 -0
  580. package/dist/tools/utils.js.map +1 -0
  581. package/package.json +71 -0
@@ -0,0 +1,1076 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /*
6
+ * Vendored from microsoft/vscode (vs/base/common/diff/diff.ts) for @cleanslate/sdk.
7
+ * Changes: see packages/cleanslate-sdk/VENDOR.md.
8
+ */
9
+ import { DiffChange } from './diffChange.js';
10
+ import { stringHash } from '../hash.js';
11
+ import { Constants } from '../uint.js';
12
+ export class StringDiffSequence {
13
+ constructor(source) {
14
+ this.source = source;
15
+ }
16
+ getElements() {
17
+ const source = this.source;
18
+ const characters = new Int32Array(source.length);
19
+ for (let i = 0, len = source.length; i < len; i++) {
20
+ characters[i] = source.charCodeAt(i);
21
+ }
22
+ return characters;
23
+ }
24
+ }
25
+ export function stringDiff(original, modified, pretty) {
26
+ return new LcsDiff(new StringDiffSequence(original), new StringDiffSequence(modified)).ComputeDiff(pretty).changes;
27
+ }
28
+ //
29
+ // The code below has been ported from a C# implementation in VS
30
+ //
31
+ class Debug {
32
+ static Assert(condition, message) {
33
+ if (!condition) {
34
+ throw new Error(message);
35
+ }
36
+ }
37
+ }
38
+ class MyArray {
39
+ /**
40
+ * Copies a range of elements from an Array starting at the specified source index and pastes
41
+ * them to another Array starting at the specified destination index. The length and the indexes
42
+ * are specified as 64-bit integers.
43
+ * sourceArray:
44
+ * The Array that contains the data to copy.
45
+ * sourceIndex:
46
+ * A 64-bit integer that represents the index in the sourceArray at which copying begins.
47
+ * destinationArray:
48
+ * The Array that receives the data.
49
+ * destinationIndex:
50
+ * A 64-bit integer that represents the index in the destinationArray at which storing begins.
51
+ * length:
52
+ * A 64-bit integer that represents the number of elements to copy.
53
+ */
54
+ static Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length) {
55
+ for (let i = 0; i < length; i++) {
56
+ destinationArray[destinationIndex + i] = sourceArray[sourceIndex + i];
57
+ }
58
+ }
59
+ static Copy2(sourceArray, sourceIndex, destinationArray, destinationIndex, length) {
60
+ for (let i = 0; i < length; i++) {
61
+ destinationArray[destinationIndex + i] = sourceArray[sourceIndex + i];
62
+ }
63
+ }
64
+ }
65
+ //*****************************************************************************
66
+ // LcsDiff.cs
67
+ //
68
+ // An implementation of the difference algorithm described in
69
+ // "An O(ND) Difference Algorithm and its variations" by Eugene W. Myers
70
+ //
71
+ // Copyright (C) 2008 Microsoft Corporation @minifier_do_not_preserve
72
+ //*****************************************************************************
73
+ // Our total memory usage for storing history is (worst-case):
74
+ // 2 * [(MaxDifferencesHistory + 1) * (MaxDifferencesHistory + 1) - 1] * sizeof(int)
75
+ // 2 * [1448*1448 - 1] * 4 = 16773624 = 16MB
76
+ var LocalConstants;
77
+ (function (LocalConstants) {
78
+ LocalConstants[LocalConstants["MaxDifferencesHistory"] = 1447] = "MaxDifferencesHistory";
79
+ })(LocalConstants || (LocalConstants = {}));
80
+ /**
81
+ * A utility class which helps to create the set of DiffChanges from
82
+ * a difference operation. This class accepts original DiffElements and
83
+ * modified DiffElements that are involved in a particular change. The
84
+ * MarkNextChange() method can be called to mark the separation between
85
+ * distinct changes. At the end, the Changes property can be called to retrieve
86
+ * the constructed changes.
87
+ */
88
+ class DiffChangeHelper {
89
+ /**
90
+ * Constructs a new DiffChangeHelper for the given DiffSequences.
91
+ */
92
+ constructor() {
93
+ this.m_changes = [];
94
+ this.m_originalStart = Constants.MAX_SAFE_SMALL_INTEGER;
95
+ this.m_modifiedStart = Constants.MAX_SAFE_SMALL_INTEGER;
96
+ this.m_originalCount = 0;
97
+ this.m_modifiedCount = 0;
98
+ }
99
+ /**
100
+ * Marks the beginning of the next change in the set of differences.
101
+ */
102
+ MarkNextChange() {
103
+ // Only add to the list if there is something to add
104
+ if (this.m_originalCount > 0 || this.m_modifiedCount > 0) {
105
+ // Add the new change to our list
106
+ this.m_changes.push(new DiffChange(this.m_originalStart, this.m_originalCount, this.m_modifiedStart, this.m_modifiedCount));
107
+ }
108
+ // Reset for the next change
109
+ this.m_originalCount = 0;
110
+ this.m_modifiedCount = 0;
111
+ this.m_originalStart = Constants.MAX_SAFE_SMALL_INTEGER;
112
+ this.m_modifiedStart = Constants.MAX_SAFE_SMALL_INTEGER;
113
+ }
114
+ /**
115
+ * Adds the original element at the given position to the elements
116
+ * affected by the current change. The modified index gives context
117
+ * to the change position with respect to the original sequence.
118
+ * @param originalIndex The index of the original element to add.
119
+ * @param modifiedIndex The index of the modified element that provides corresponding position in the modified sequence.
120
+ */
121
+ AddOriginalElement(originalIndex, modifiedIndex) {
122
+ // The 'true' start index is the smallest of the ones we've seen
123
+ this.m_originalStart = Math.min(this.m_originalStart, originalIndex);
124
+ this.m_modifiedStart = Math.min(this.m_modifiedStart, modifiedIndex);
125
+ this.m_originalCount++;
126
+ }
127
+ /**
128
+ * Adds the modified element at the given position to the elements
129
+ * affected by the current change. The original index gives context
130
+ * to the change position with respect to the modified sequence.
131
+ * @param originalIndex The index of the original element that provides corresponding position in the original sequence.
132
+ * @param modifiedIndex The index of the modified element to add.
133
+ */
134
+ AddModifiedElement(originalIndex, modifiedIndex) {
135
+ // The 'true' start index is the smallest of the ones we've seen
136
+ this.m_originalStart = Math.min(this.m_originalStart, originalIndex);
137
+ this.m_modifiedStart = Math.min(this.m_modifiedStart, modifiedIndex);
138
+ this.m_modifiedCount++;
139
+ }
140
+ /**
141
+ * Retrieves all of the changes marked by the class.
142
+ */
143
+ getChanges() {
144
+ if (this.m_originalCount > 0 || this.m_modifiedCount > 0) {
145
+ // Finish up on whatever is left
146
+ this.MarkNextChange();
147
+ }
148
+ return this.m_changes;
149
+ }
150
+ /**
151
+ * Retrieves all of the changes marked by the class in the reverse order
152
+ */
153
+ getReverseChanges() {
154
+ if (this.m_originalCount > 0 || this.m_modifiedCount > 0) {
155
+ // Finish up on whatever is left
156
+ this.MarkNextChange();
157
+ }
158
+ this.m_changes.reverse();
159
+ return this.m_changes;
160
+ }
161
+ }
162
+ /**
163
+ * An implementation of the difference algorithm described in
164
+ * "An O(ND) Difference Algorithm and its variations" by Eugene W. Myers
165
+ */
166
+ export class LcsDiff {
167
+ /**
168
+ * Constructs the DiffFinder
169
+ */
170
+ constructor(originalSequence, modifiedSequence, continueProcessingPredicate = null) {
171
+ this.ContinueProcessingPredicate = continueProcessingPredicate;
172
+ this._originalSequence = originalSequence;
173
+ this._modifiedSequence = modifiedSequence;
174
+ const [originalStringElements, originalElementsOrHash, originalHasStrings] = LcsDiff._getElements(originalSequence);
175
+ const [modifiedStringElements, modifiedElementsOrHash, modifiedHasStrings] = LcsDiff._getElements(modifiedSequence);
176
+ this._hasStrings = (originalHasStrings && modifiedHasStrings);
177
+ this._originalStringElements = originalStringElements;
178
+ this._originalElementsOrHash = originalElementsOrHash;
179
+ this._modifiedStringElements = modifiedStringElements;
180
+ this._modifiedElementsOrHash = modifiedElementsOrHash;
181
+ this.m_forwardHistory = [];
182
+ this.m_reverseHistory = [];
183
+ }
184
+ static _isStringArray(arr) {
185
+ return (arr.length > 0 && typeof arr[0] === 'string');
186
+ }
187
+ static _getElements(sequence) {
188
+ const elements = sequence.getElements();
189
+ if (LcsDiff._isStringArray(elements)) {
190
+ const hashes = new Int32Array(elements.length);
191
+ for (let i = 0, len = elements.length; i < len; i++) {
192
+ hashes[i] = stringHash(elements[i], 0);
193
+ }
194
+ return [elements, hashes, true];
195
+ }
196
+ if (elements instanceof Int32Array) {
197
+ return [[], elements, false];
198
+ }
199
+ return [[], new Int32Array(elements), false];
200
+ }
201
+ ElementsAreEqual(originalIndex, newIndex) {
202
+ if (this._originalElementsOrHash[originalIndex] !== this._modifiedElementsOrHash[newIndex]) {
203
+ return false;
204
+ }
205
+ return (this._hasStrings ? this._originalStringElements[originalIndex] === this._modifiedStringElements[newIndex] : true);
206
+ }
207
+ ElementsAreStrictEqual(originalIndex, newIndex) {
208
+ if (!this.ElementsAreEqual(originalIndex, newIndex)) {
209
+ return false;
210
+ }
211
+ const originalElement = LcsDiff._getStrictElement(this._originalSequence, originalIndex);
212
+ const modifiedElement = LcsDiff._getStrictElement(this._modifiedSequence, newIndex);
213
+ return (originalElement === modifiedElement);
214
+ }
215
+ static _getStrictElement(sequence, index) {
216
+ if (typeof sequence.getStrictElement === 'function') {
217
+ return sequence.getStrictElement(index);
218
+ }
219
+ return null;
220
+ }
221
+ OriginalElementsAreEqual(index1, index2) {
222
+ if (this._originalElementsOrHash[index1] !== this._originalElementsOrHash[index2]) {
223
+ return false;
224
+ }
225
+ return (this._hasStrings ? this._originalStringElements[index1] === this._originalStringElements[index2] : true);
226
+ }
227
+ ModifiedElementsAreEqual(index1, index2) {
228
+ if (this._modifiedElementsOrHash[index1] !== this._modifiedElementsOrHash[index2]) {
229
+ return false;
230
+ }
231
+ return (this._hasStrings ? this._modifiedStringElements[index1] === this._modifiedStringElements[index2] : true);
232
+ }
233
+ ComputeDiff(pretty) {
234
+ return this._ComputeDiff(0, this._originalElementsOrHash.length - 1, 0, this._modifiedElementsOrHash.length - 1, pretty);
235
+ }
236
+ /**
237
+ * Computes the differences between the original and modified input
238
+ * sequences on the bounded range.
239
+ * @returns An array of the differences between the two input sequences.
240
+ */
241
+ _ComputeDiff(originalStart, originalEnd, modifiedStart, modifiedEnd, pretty) {
242
+ const quitEarlyArr = [false];
243
+ let changes = this.ComputeDiffRecursive(originalStart, originalEnd, modifiedStart, modifiedEnd, quitEarlyArr);
244
+ if (pretty) {
245
+ // We have to clean up the computed diff to be more intuitive
246
+ // but it turns out this cannot be done correctly until the entire set
247
+ // of diffs have been computed
248
+ changes = this.PrettifyChanges(changes);
249
+ }
250
+ return {
251
+ quitEarly: quitEarlyArr[0],
252
+ changes: changes
253
+ };
254
+ }
255
+ /**
256
+ * Private helper method which computes the differences on the bounded range
257
+ * recursively.
258
+ * @returns An array of the differences between the two input sequences.
259
+ */
260
+ ComputeDiffRecursive(originalStart, originalEnd, modifiedStart, modifiedEnd, quitEarlyArr) {
261
+ quitEarlyArr[0] = false;
262
+ // Find the start of the differences
263
+ while (originalStart <= originalEnd && modifiedStart <= modifiedEnd && this.ElementsAreEqual(originalStart, modifiedStart)) {
264
+ originalStart++;
265
+ modifiedStart++;
266
+ }
267
+ // Find the end of the differences
268
+ while (originalEnd >= originalStart && modifiedEnd >= modifiedStart && this.ElementsAreEqual(originalEnd, modifiedEnd)) {
269
+ originalEnd--;
270
+ modifiedEnd--;
271
+ }
272
+ // In the special case where we either have all insertions or all deletions or the sequences are identical
273
+ if (originalStart > originalEnd || modifiedStart > modifiedEnd) {
274
+ let changes;
275
+ if (modifiedStart <= modifiedEnd) {
276
+ Debug.Assert(originalStart === originalEnd + 1, 'originalStart should only be one more than originalEnd');
277
+ // All insertions
278
+ changes = [
279
+ new DiffChange(originalStart, 0, modifiedStart, modifiedEnd - modifiedStart + 1)
280
+ ];
281
+ }
282
+ else if (originalStart <= originalEnd) {
283
+ Debug.Assert(modifiedStart === modifiedEnd + 1, 'modifiedStart should only be one more than modifiedEnd');
284
+ // All deletions
285
+ changes = [
286
+ new DiffChange(originalStart, originalEnd - originalStart + 1, modifiedStart, 0)
287
+ ];
288
+ }
289
+ else {
290
+ Debug.Assert(originalStart === originalEnd + 1, 'originalStart should only be one more than originalEnd');
291
+ Debug.Assert(modifiedStart === modifiedEnd + 1, 'modifiedStart should only be one more than modifiedEnd');
292
+ // Identical sequences - No differences
293
+ changes = [];
294
+ }
295
+ return changes;
296
+ }
297
+ // This problem can be solved using the Divide-And-Conquer technique.
298
+ const midOriginalArr = [0];
299
+ const midModifiedArr = [0];
300
+ const result = this.ComputeRecursionPoint(originalStart, originalEnd, modifiedStart, modifiedEnd, midOriginalArr, midModifiedArr, quitEarlyArr);
301
+ const midOriginal = midOriginalArr[0];
302
+ const midModified = midModifiedArr[0];
303
+ if (result !== null) {
304
+ // Result is not-null when there was enough memory to compute the changes while
305
+ // searching for the recursion point
306
+ return result;
307
+ }
308
+ else if (!quitEarlyArr[0]) {
309
+ // We can break the problem down recursively by finding the changes in the
310
+ // First Half: (originalStart, modifiedStart) to (midOriginal, midModified)
311
+ // Second Half: (midOriginal + 1, minModified + 1) to (originalEnd, modifiedEnd)
312
+ // NOTE: ComputeDiff() is inclusive, therefore the second range starts on the next point
313
+ const leftChanges = this.ComputeDiffRecursive(originalStart, midOriginal, modifiedStart, midModified, quitEarlyArr);
314
+ let rightChanges = [];
315
+ if (!quitEarlyArr[0]) {
316
+ rightChanges = this.ComputeDiffRecursive(midOriginal + 1, originalEnd, midModified + 1, modifiedEnd, quitEarlyArr);
317
+ }
318
+ else {
319
+ // We didn't have time to finish the first half, so we don't have time to compute this half.
320
+ // Consider the entire rest of the sequence different.
321
+ rightChanges = [
322
+ new DiffChange(midOriginal + 1, originalEnd - (midOriginal + 1) + 1, midModified + 1, modifiedEnd - (midModified + 1) + 1)
323
+ ];
324
+ }
325
+ return this.ConcatenateChanges(leftChanges, rightChanges);
326
+ }
327
+ // If we hit here, we quit early, and so can't return anything meaningful
328
+ return [
329
+ new DiffChange(originalStart, originalEnd - originalStart + 1, modifiedStart, modifiedEnd - modifiedStart + 1)
330
+ ];
331
+ }
332
+ WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr) {
333
+ let forwardChanges = null;
334
+ let reverseChanges = null;
335
+ // First, walk backward through the forward diagonals history
336
+ let changeHelper = new DiffChangeHelper();
337
+ let diagonalMin = diagonalForwardStart;
338
+ let diagonalMax = diagonalForwardEnd;
339
+ let diagonalRelative = (midOriginalArr[0] - midModifiedArr[0]) - diagonalForwardOffset;
340
+ let lastOriginalIndex = Constants.MIN_SAFE_SMALL_INTEGER;
341
+ let historyIndex = this.m_forwardHistory.length - 1;
342
+ do {
343
+ // Get the diagonal index from the relative diagonal number
344
+ const diagonal = diagonalRelative + diagonalForwardBase;
345
+ // Figure out where we came from
346
+ if (diagonal === diagonalMin || (diagonal < diagonalMax && forwardPoints[diagonal - 1] < forwardPoints[diagonal + 1])) {
347
+ // Vertical line (the element is an insert)
348
+ originalIndex = forwardPoints[diagonal + 1];
349
+ modifiedIndex = originalIndex - diagonalRelative - diagonalForwardOffset;
350
+ if (originalIndex < lastOriginalIndex) {
351
+ changeHelper.MarkNextChange();
352
+ }
353
+ lastOriginalIndex = originalIndex;
354
+ changeHelper.AddModifiedElement(originalIndex + 1, modifiedIndex);
355
+ diagonalRelative = (diagonal + 1) - diagonalForwardBase; //Setup for the next iteration
356
+ }
357
+ else {
358
+ // Horizontal line (the element is a deletion)
359
+ originalIndex = forwardPoints[diagonal - 1] + 1;
360
+ modifiedIndex = originalIndex - diagonalRelative - diagonalForwardOffset;
361
+ if (originalIndex < lastOriginalIndex) {
362
+ changeHelper.MarkNextChange();
363
+ }
364
+ lastOriginalIndex = originalIndex - 1;
365
+ changeHelper.AddOriginalElement(originalIndex, modifiedIndex + 1);
366
+ diagonalRelative = (diagonal - 1) - diagonalForwardBase; //Setup for the next iteration
367
+ }
368
+ if (historyIndex >= 0) {
369
+ forwardPoints = this.m_forwardHistory[historyIndex];
370
+ diagonalForwardBase = forwardPoints[0]; //We stored this in the first spot
371
+ diagonalMin = 1;
372
+ diagonalMax = forwardPoints.length - 1;
373
+ }
374
+ } while (--historyIndex >= -1);
375
+ // Ironically, we get the forward changes as the reverse of the
376
+ // order we added them since we technically added them backwards
377
+ forwardChanges = changeHelper.getReverseChanges();
378
+ if (quitEarlyArr[0]) {
379
+ // TODO: Calculate a partial from the reverse diagonals.
380
+ // For now, just assume everything after the midOriginal/midModified point is a diff
381
+ let originalStartPoint = midOriginalArr[0] + 1;
382
+ let modifiedStartPoint = midModifiedArr[0] + 1;
383
+ if (forwardChanges !== null && forwardChanges.length > 0) {
384
+ const lastForwardChange = forwardChanges[forwardChanges.length - 1];
385
+ originalStartPoint = Math.max(originalStartPoint, lastForwardChange.getOriginalEnd());
386
+ modifiedStartPoint = Math.max(modifiedStartPoint, lastForwardChange.getModifiedEnd());
387
+ }
388
+ reverseChanges = [
389
+ new DiffChange(originalStartPoint, originalEnd - originalStartPoint + 1, modifiedStartPoint, modifiedEnd - modifiedStartPoint + 1)
390
+ ];
391
+ }
392
+ else {
393
+ // Now walk backward through the reverse diagonals history
394
+ changeHelper = new DiffChangeHelper();
395
+ diagonalMin = diagonalReverseStart;
396
+ diagonalMax = diagonalReverseEnd;
397
+ diagonalRelative = (midOriginalArr[0] - midModifiedArr[0]) - diagonalReverseOffset;
398
+ lastOriginalIndex = Constants.MAX_SAFE_SMALL_INTEGER;
399
+ historyIndex = (deltaIsEven) ? this.m_reverseHistory.length - 1 : this.m_reverseHistory.length - 2;
400
+ do {
401
+ // Get the diagonal index from the relative diagonal number
402
+ const diagonal = diagonalRelative + diagonalReverseBase;
403
+ // Figure out where we came from
404
+ if (diagonal === diagonalMin || (diagonal < diagonalMax && reversePoints[diagonal - 1] >= reversePoints[diagonal + 1])) {
405
+ // Horizontal line (the element is a deletion))
406
+ originalIndex = reversePoints[diagonal + 1] - 1;
407
+ modifiedIndex = originalIndex - diagonalRelative - diagonalReverseOffset;
408
+ if (originalIndex > lastOriginalIndex) {
409
+ changeHelper.MarkNextChange();
410
+ }
411
+ lastOriginalIndex = originalIndex + 1;
412
+ changeHelper.AddOriginalElement(originalIndex + 1, modifiedIndex + 1);
413
+ diagonalRelative = (diagonal + 1) - diagonalReverseBase; //Setup for the next iteration
414
+ }
415
+ else {
416
+ // Vertical line (the element is an insertion)
417
+ originalIndex = reversePoints[diagonal - 1];
418
+ modifiedIndex = originalIndex - diagonalRelative - diagonalReverseOffset;
419
+ if (originalIndex > lastOriginalIndex) {
420
+ changeHelper.MarkNextChange();
421
+ }
422
+ lastOriginalIndex = originalIndex;
423
+ changeHelper.AddModifiedElement(originalIndex + 1, modifiedIndex + 1);
424
+ diagonalRelative = (diagonal - 1) - diagonalReverseBase; //Setup for the next iteration
425
+ }
426
+ if (historyIndex >= 0) {
427
+ reversePoints = this.m_reverseHistory[historyIndex];
428
+ diagonalReverseBase = reversePoints[0]; //We stored this in the first spot
429
+ diagonalMin = 1;
430
+ diagonalMax = reversePoints.length - 1;
431
+ }
432
+ } while (--historyIndex >= -1);
433
+ // There are cases where the reverse history will find diffs that
434
+ // are correct, but not intuitive, so we need shift them.
435
+ reverseChanges = changeHelper.getChanges();
436
+ }
437
+ return this.ConcatenateChanges(forwardChanges, reverseChanges);
438
+ }
439
+ /**
440
+ * Given the range to compute the diff on, this method finds the point:
441
+ * (midOriginal, midModified)
442
+ * that exists in the middle of the LCS of the two sequences and
443
+ * is the point at which the LCS problem may be broken down recursively.
444
+ * This method will try to keep the LCS trace in memory. If the LCS recursion
445
+ * point is calculated and the full trace is available in memory, then this method
446
+ * will return the change list.
447
+ * @param originalStart The start bound of the original sequence range
448
+ * @param originalEnd The end bound of the original sequence range
449
+ * @param modifiedStart The start bound of the modified sequence range
450
+ * @param modifiedEnd The end bound of the modified sequence range
451
+ * @param midOriginal The middle point of the original sequence range
452
+ * @param midModified The middle point of the modified sequence range
453
+ * @returns The diff changes, if available, otherwise null
454
+ */
455
+ ComputeRecursionPoint(originalStart, originalEnd, modifiedStart, modifiedEnd, midOriginalArr, midModifiedArr, quitEarlyArr) {
456
+ let originalIndex = 0, modifiedIndex = 0;
457
+ let diagonalForwardStart = 0, diagonalForwardEnd = 0;
458
+ let diagonalReverseStart = 0, diagonalReverseEnd = 0;
459
+ // To traverse the edit graph and produce the proper LCS, our actual
460
+ // start position is just outside the given boundary
461
+ originalStart--;
462
+ modifiedStart--;
463
+ // We set these up to make the compiler happy, but they will
464
+ // be replaced before we return with the actual recursion point
465
+ midOriginalArr[0] = 0;
466
+ midModifiedArr[0] = 0;
467
+ // Clear out the history
468
+ this.m_forwardHistory = [];
469
+ this.m_reverseHistory = [];
470
+ // Each cell in the two arrays corresponds to a diagonal in the edit graph.
471
+ // The integer value in the cell represents the originalIndex of the furthest
472
+ // reaching point found so far that ends in that diagonal.
473
+ // The modifiedIndex can be computed mathematically from the originalIndex and the diagonal number.
474
+ const maxDifferences = (originalEnd - originalStart) + (modifiedEnd - modifiedStart);
475
+ const numDiagonals = maxDifferences + 1;
476
+ const forwardPoints = new Int32Array(numDiagonals);
477
+ const reversePoints = new Int32Array(numDiagonals);
478
+ // diagonalForwardBase: Index into forwardPoints of the diagonal which passes through (originalStart, modifiedStart)
479
+ // diagonalReverseBase: Index into reversePoints of the diagonal which passes through (originalEnd, modifiedEnd)
480
+ const diagonalForwardBase = (modifiedEnd - modifiedStart);
481
+ const diagonalReverseBase = (originalEnd - originalStart);
482
+ // diagonalForwardOffset: Geometric offset which allows modifiedIndex to be computed from originalIndex and the
483
+ // diagonal number (relative to diagonalForwardBase)
484
+ // diagonalReverseOffset: Geometric offset which allows modifiedIndex to be computed from originalIndex and the
485
+ // diagonal number (relative to diagonalReverseBase)
486
+ const diagonalForwardOffset = (originalStart - modifiedStart);
487
+ const diagonalReverseOffset = (originalEnd - modifiedEnd);
488
+ // delta: The difference between the end diagonal and the start diagonal. This is used to relate diagonal numbers
489
+ // relative to the start diagonal with diagonal numbers relative to the end diagonal.
490
+ // The Even/Oddn-ness of this delta is important for determining when we should check for overlap
491
+ const delta = diagonalReverseBase - diagonalForwardBase;
492
+ const deltaIsEven = (delta % 2 === 0);
493
+ // Here we set up the start and end points as the furthest points found so far
494
+ // in both the forward and reverse directions, respectively
495
+ forwardPoints[diagonalForwardBase] = originalStart;
496
+ reversePoints[diagonalReverseBase] = originalEnd;
497
+ // Remember if we quit early, and thus need to do a best-effort result instead of a real result.
498
+ quitEarlyArr[0] = false;
499
+ // A couple of points:
500
+ // --With this method, we iterate on the number of differences between the two sequences.
501
+ // The more differences there actually are, the longer this will take.
502
+ // --Also, as the number of differences increases, we have to search on diagonals further
503
+ // away from the reference diagonal (which is diagonalForwardBase for forward, diagonalReverseBase for reverse).
504
+ // --We extend on even diagonals (relative to the reference diagonal) only when numDifferences
505
+ // is even and odd diagonals only when numDifferences is odd.
506
+ for (let numDifferences = 1; numDifferences <= (maxDifferences / 2) + 1; numDifferences++) {
507
+ let furthestOriginalIndex = 0;
508
+ let furthestModifiedIndex = 0;
509
+ // Run the algorithm in the forward direction
510
+ diagonalForwardStart = this.ClipDiagonalBound(diagonalForwardBase - numDifferences, numDifferences, diagonalForwardBase, numDiagonals);
511
+ diagonalForwardEnd = this.ClipDiagonalBound(diagonalForwardBase + numDifferences, numDifferences, diagonalForwardBase, numDiagonals);
512
+ for (let diagonal = diagonalForwardStart; diagonal <= diagonalForwardEnd; diagonal += 2) {
513
+ // STEP 1: We extend the furthest reaching point in the present diagonal
514
+ // by looking at the diagonals above and below and picking the one whose point
515
+ // is further away from the start point (originalStart, modifiedStart)
516
+ if (diagonal === diagonalForwardStart || (diagonal < diagonalForwardEnd && forwardPoints[diagonal - 1] < forwardPoints[diagonal + 1])) {
517
+ originalIndex = forwardPoints[diagonal + 1];
518
+ }
519
+ else {
520
+ originalIndex = forwardPoints[diagonal - 1] + 1;
521
+ }
522
+ modifiedIndex = originalIndex - (diagonal - diagonalForwardBase) - diagonalForwardOffset;
523
+ // Save the current originalIndex so we can test for false overlap in step 3
524
+ const tempOriginalIndex = originalIndex;
525
+ // STEP 2: We can continue to extend the furthest reaching point in the present diagonal
526
+ // so long as the elements are equal.
527
+ while (originalIndex < originalEnd && modifiedIndex < modifiedEnd && this.ElementsAreEqual(originalIndex + 1, modifiedIndex + 1)) {
528
+ originalIndex++;
529
+ modifiedIndex++;
530
+ }
531
+ forwardPoints[diagonal] = originalIndex;
532
+ if (originalIndex + modifiedIndex > furthestOriginalIndex + furthestModifiedIndex) {
533
+ furthestOriginalIndex = originalIndex;
534
+ furthestModifiedIndex = modifiedIndex;
535
+ }
536
+ // STEP 3: If delta is odd (overlap first happens on forward when delta is odd)
537
+ // and diagonal is in the range of reverse diagonals computed for numDifferences-1
538
+ // (the previous iteration; we haven't computed reverse diagonals for numDifferences yet)
539
+ // then check for overlap.
540
+ if (!deltaIsEven && Math.abs(diagonal - diagonalReverseBase) <= (numDifferences - 1)) {
541
+ if (originalIndex >= reversePoints[diagonal]) {
542
+ midOriginalArr[0] = originalIndex;
543
+ midModifiedArr[0] = modifiedIndex;
544
+ if (tempOriginalIndex <= reversePoints[diagonal] && LocalConstants.MaxDifferencesHistory > 0 && numDifferences <= (LocalConstants.MaxDifferencesHistory + 1)) {
545
+ // BINGO! We overlapped, and we have the full trace in memory!
546
+ return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr);
547
+ }
548
+ else {
549
+ // Either false overlap, or we didn't have enough memory for the full trace
550
+ // Just return the recursion point
551
+ return null;
552
+ }
553
+ }
554
+ }
555
+ }
556
+ // Check to see if we should be quitting early, before moving on to the next iteration.
557
+ const matchLengthOfLongest = ((furthestOriginalIndex - originalStart) + (furthestModifiedIndex - modifiedStart) - numDifferences) / 2;
558
+ if (this.ContinueProcessingPredicate !== null && !this.ContinueProcessingPredicate(furthestOriginalIndex, matchLengthOfLongest)) {
559
+ // We can't finish, so skip ahead to generating a result from what we have.
560
+ quitEarlyArr[0] = true;
561
+ // Use the furthest distance we got in the forward direction.
562
+ midOriginalArr[0] = furthestOriginalIndex;
563
+ midModifiedArr[0] = furthestModifiedIndex;
564
+ if (matchLengthOfLongest > 0 && LocalConstants.MaxDifferencesHistory > 0 && numDifferences <= (LocalConstants.MaxDifferencesHistory + 1)) {
565
+ // Enough of the history is in memory to walk it backwards
566
+ return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr);
567
+ }
568
+ else {
569
+ // We didn't actually remember enough of the history.
570
+ //Since we are quitting the diff early, we need to shift back the originalStart and modified start
571
+ //back into the boundary limits since we decremented their value above beyond the boundary limit.
572
+ originalStart++;
573
+ modifiedStart++;
574
+ return [
575
+ new DiffChange(originalStart, originalEnd - originalStart + 1, modifiedStart, modifiedEnd - modifiedStart + 1)
576
+ ];
577
+ }
578
+ }
579
+ // Run the algorithm in the reverse direction
580
+ diagonalReverseStart = this.ClipDiagonalBound(diagonalReverseBase - numDifferences, numDifferences, diagonalReverseBase, numDiagonals);
581
+ diagonalReverseEnd = this.ClipDiagonalBound(diagonalReverseBase + numDifferences, numDifferences, diagonalReverseBase, numDiagonals);
582
+ for (let diagonal = diagonalReverseStart; diagonal <= diagonalReverseEnd; diagonal += 2) {
583
+ // STEP 1: We extend the furthest reaching point in the present diagonal
584
+ // by looking at the diagonals above and below and picking the one whose point
585
+ // is further away from the start point (originalEnd, modifiedEnd)
586
+ if (diagonal === diagonalReverseStart || (diagonal < diagonalReverseEnd && reversePoints[diagonal - 1] >= reversePoints[diagonal + 1])) {
587
+ originalIndex = reversePoints[diagonal + 1] - 1;
588
+ }
589
+ else {
590
+ originalIndex = reversePoints[diagonal - 1];
591
+ }
592
+ modifiedIndex = originalIndex - (diagonal - diagonalReverseBase) - diagonalReverseOffset;
593
+ // Save the current originalIndex so we can test for false overlap
594
+ const tempOriginalIndex = originalIndex;
595
+ // STEP 2: We can continue to extend the furthest reaching point in the present diagonal
596
+ // as long as the elements are equal.
597
+ while (originalIndex > originalStart && modifiedIndex > modifiedStart && this.ElementsAreEqual(originalIndex, modifiedIndex)) {
598
+ originalIndex--;
599
+ modifiedIndex--;
600
+ }
601
+ reversePoints[diagonal] = originalIndex;
602
+ // STEP 4: If delta is even (overlap first happens on reverse when delta is even)
603
+ // and diagonal is in the range of forward diagonals computed for numDifferences
604
+ // then check for overlap.
605
+ if (deltaIsEven && Math.abs(diagonal - diagonalForwardBase) <= numDifferences) {
606
+ if (originalIndex <= forwardPoints[diagonal]) {
607
+ midOriginalArr[0] = originalIndex;
608
+ midModifiedArr[0] = modifiedIndex;
609
+ if (tempOriginalIndex >= forwardPoints[diagonal] && LocalConstants.MaxDifferencesHistory > 0 && numDifferences <= (LocalConstants.MaxDifferencesHistory + 1)) {
610
+ // BINGO! We overlapped, and we have the full trace in memory!
611
+ return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr);
612
+ }
613
+ else {
614
+ // Either false overlap, or we didn't have enough memory for the full trace
615
+ // Just return the recursion point
616
+ return null;
617
+ }
618
+ }
619
+ }
620
+ }
621
+ // Save current vectors to history before the next iteration
622
+ if (numDifferences <= LocalConstants.MaxDifferencesHistory) {
623
+ // We are allocating space for one extra int, which we fill with
624
+ // the index of the diagonal base index
625
+ let temp = new Int32Array(diagonalForwardEnd - diagonalForwardStart + 2);
626
+ temp[0] = diagonalForwardBase - diagonalForwardStart + 1;
627
+ MyArray.Copy2(forwardPoints, diagonalForwardStart, temp, 1, diagonalForwardEnd - diagonalForwardStart + 1);
628
+ this.m_forwardHistory.push(temp);
629
+ temp = new Int32Array(diagonalReverseEnd - diagonalReverseStart + 2);
630
+ temp[0] = diagonalReverseBase - diagonalReverseStart + 1;
631
+ MyArray.Copy2(reversePoints, diagonalReverseStart, temp, 1, diagonalReverseEnd - diagonalReverseStart + 1);
632
+ this.m_reverseHistory.push(temp);
633
+ }
634
+ }
635
+ // If we got here, then we have the full trace in history. We just have to convert it to a change list
636
+ // NOTE: This part is a bit messy
637
+ return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset, diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset, forwardPoints, reversePoints, originalIndex, originalEnd, midOriginalArr, modifiedIndex, modifiedEnd, midModifiedArr, deltaIsEven, quitEarlyArr);
638
+ }
639
+ /**
640
+ * Shifts the given changes to provide a more intuitive diff.
641
+ * While the first element in a diff matches the first element after the diff,
642
+ * we shift the diff down.
643
+ *
644
+ * @param changes The list of changes to shift
645
+ * @returns The shifted changes
646
+ */
647
+ PrettifyChanges(changes) {
648
+ // Shift all the changes down first
649
+ for (let i = 0; i < changes.length; i++) {
650
+ const change = changes[i];
651
+ const originalStop = (i < changes.length - 1) ? changes[i + 1].originalStart : this._originalElementsOrHash.length;
652
+ const modifiedStop = (i < changes.length - 1) ? changes[i + 1].modifiedStart : this._modifiedElementsOrHash.length;
653
+ const checkOriginal = change.originalLength > 0;
654
+ const checkModified = change.modifiedLength > 0;
655
+ while (change.originalStart + change.originalLength < originalStop
656
+ && change.modifiedStart + change.modifiedLength < modifiedStop
657
+ && (!checkOriginal || this.OriginalElementsAreEqual(change.originalStart, change.originalStart + change.originalLength))
658
+ && (!checkModified || this.ModifiedElementsAreEqual(change.modifiedStart, change.modifiedStart + change.modifiedLength))) {
659
+ const startStrictEqual = this.ElementsAreStrictEqual(change.originalStart, change.modifiedStart);
660
+ const endStrictEqual = this.ElementsAreStrictEqual(change.originalStart + change.originalLength, change.modifiedStart + change.modifiedLength);
661
+ if (endStrictEqual && !startStrictEqual) {
662
+ // moving the change down would create an equal change, but the elements are not strict equal
663
+ break;
664
+ }
665
+ change.originalStart++;
666
+ change.modifiedStart++;
667
+ }
668
+ const mergedChangeArr = [null];
669
+ if (i < changes.length - 1 && this.ChangesOverlap(changes[i], changes[i + 1], mergedChangeArr)) {
670
+ changes[i] = mergedChangeArr[0];
671
+ changes.splice(i + 1, 1);
672
+ i--;
673
+ continue;
674
+ }
675
+ }
676
+ // Shift changes back up until we hit empty or whitespace-only lines
677
+ for (let i = changes.length - 1; i >= 0; i--) {
678
+ const change = changes[i];
679
+ let originalStop = 0;
680
+ let modifiedStop = 0;
681
+ if (i > 0) {
682
+ const prevChange = changes[i - 1];
683
+ originalStop = prevChange.originalStart + prevChange.originalLength;
684
+ modifiedStop = prevChange.modifiedStart + prevChange.modifiedLength;
685
+ }
686
+ const checkOriginal = change.originalLength > 0;
687
+ const checkModified = change.modifiedLength > 0;
688
+ let bestDelta = 0;
689
+ let bestScore = this._boundaryScore(change.originalStart, change.originalLength, change.modifiedStart, change.modifiedLength);
690
+ for (let delta = 1;; delta++) {
691
+ const originalStart = change.originalStart - delta;
692
+ const modifiedStart = change.modifiedStart - delta;
693
+ if (originalStart < originalStop || modifiedStart < modifiedStop) {
694
+ break;
695
+ }
696
+ if (checkOriginal && !this.OriginalElementsAreEqual(originalStart, originalStart + change.originalLength)) {
697
+ break;
698
+ }
699
+ if (checkModified && !this.ModifiedElementsAreEqual(modifiedStart, modifiedStart + change.modifiedLength)) {
700
+ break;
701
+ }
702
+ const touchingPreviousChange = (originalStart === originalStop && modifiedStart === modifiedStop);
703
+ const score = ((touchingPreviousChange ? 5 : 0)
704
+ + this._boundaryScore(originalStart, change.originalLength, modifiedStart, change.modifiedLength));
705
+ if (score > bestScore) {
706
+ bestScore = score;
707
+ bestDelta = delta;
708
+ }
709
+ }
710
+ change.originalStart -= bestDelta;
711
+ change.modifiedStart -= bestDelta;
712
+ const mergedChangeArr = [null];
713
+ if (i > 0 && this.ChangesOverlap(changes[i - 1], changes[i], mergedChangeArr)) {
714
+ changes[i - 1] = mergedChangeArr[0];
715
+ changes.splice(i, 1);
716
+ i++;
717
+ continue;
718
+ }
719
+ }
720
+ // There could be multiple longest common substrings.
721
+ // Give preference to the ones containing longer lines
722
+ if (this._hasStrings) {
723
+ for (let i = 1, len = changes.length; i < len; i++) {
724
+ const aChange = changes[i - 1];
725
+ const bChange = changes[i];
726
+ const matchedLength = bChange.originalStart - aChange.originalStart - aChange.originalLength;
727
+ const aOriginalStart = aChange.originalStart;
728
+ const bOriginalEnd = bChange.originalStart + bChange.originalLength;
729
+ const abOriginalLength = bOriginalEnd - aOriginalStart;
730
+ const aModifiedStart = aChange.modifiedStart;
731
+ const bModifiedEnd = bChange.modifiedStart + bChange.modifiedLength;
732
+ const abModifiedLength = bModifiedEnd - aModifiedStart;
733
+ // Avoid wasting a lot of time with these searches
734
+ if (matchedLength < 5 && abOriginalLength < 20 && abModifiedLength < 20) {
735
+ const t = this._findBetterContiguousSequence(aOriginalStart, abOriginalLength, aModifiedStart, abModifiedLength, matchedLength);
736
+ if (t) {
737
+ const [originalMatchStart, modifiedMatchStart] = t;
738
+ if (originalMatchStart !== aChange.originalStart + aChange.originalLength || modifiedMatchStart !== aChange.modifiedStart + aChange.modifiedLength) {
739
+ // switch to another sequence that has a better score
740
+ aChange.originalLength = originalMatchStart - aChange.originalStart;
741
+ aChange.modifiedLength = modifiedMatchStart - aChange.modifiedStart;
742
+ bChange.originalStart = originalMatchStart + matchedLength;
743
+ bChange.modifiedStart = modifiedMatchStart + matchedLength;
744
+ bChange.originalLength = bOriginalEnd - bChange.originalStart;
745
+ bChange.modifiedLength = bModifiedEnd - bChange.modifiedStart;
746
+ }
747
+ }
748
+ }
749
+ }
750
+ }
751
+ return changes;
752
+ }
753
+ _findBetterContiguousSequence(originalStart, originalLength, modifiedStart, modifiedLength, desiredLength) {
754
+ if (originalLength < desiredLength || modifiedLength < desiredLength) {
755
+ return null;
756
+ }
757
+ const originalMax = originalStart + originalLength - desiredLength + 1;
758
+ const modifiedMax = modifiedStart + modifiedLength - desiredLength + 1;
759
+ let bestScore = 0;
760
+ let bestOriginalStart = 0;
761
+ let bestModifiedStart = 0;
762
+ for (let i = originalStart; i < originalMax; i++) {
763
+ for (let j = modifiedStart; j < modifiedMax; j++) {
764
+ const score = this._contiguousSequenceScore(i, j, desiredLength);
765
+ if (score > 0 && score > bestScore) {
766
+ bestScore = score;
767
+ bestOriginalStart = i;
768
+ bestModifiedStart = j;
769
+ }
770
+ }
771
+ }
772
+ if (bestScore > 0) {
773
+ return [bestOriginalStart, bestModifiedStart];
774
+ }
775
+ return null;
776
+ }
777
+ _contiguousSequenceScore(originalStart, modifiedStart, length) {
778
+ let score = 0;
779
+ for (let l = 0; l < length; l++) {
780
+ if (!this.ElementsAreEqual(originalStart + l, modifiedStart + l)) {
781
+ return 0;
782
+ }
783
+ score += this._originalStringElements[originalStart + l].length;
784
+ }
785
+ return score;
786
+ }
787
+ _OriginalIsBoundary(index) {
788
+ if (index <= 0 || index >= this._originalElementsOrHash.length - 1) {
789
+ return true;
790
+ }
791
+ return (this._hasStrings && /^\s*$/.test(this._originalStringElements[index]));
792
+ }
793
+ _OriginalRegionIsBoundary(originalStart, originalLength) {
794
+ if (this._OriginalIsBoundary(originalStart) || this._OriginalIsBoundary(originalStart - 1)) {
795
+ return true;
796
+ }
797
+ if (originalLength > 0) {
798
+ const originalEnd = originalStart + originalLength;
799
+ if (this._OriginalIsBoundary(originalEnd - 1) || this._OriginalIsBoundary(originalEnd)) {
800
+ return true;
801
+ }
802
+ }
803
+ return false;
804
+ }
805
+ _ModifiedIsBoundary(index) {
806
+ if (index <= 0 || index >= this._modifiedElementsOrHash.length - 1) {
807
+ return true;
808
+ }
809
+ return (this._hasStrings && /^\s*$/.test(this._modifiedStringElements[index]));
810
+ }
811
+ _ModifiedRegionIsBoundary(modifiedStart, modifiedLength) {
812
+ if (this._ModifiedIsBoundary(modifiedStart) || this._ModifiedIsBoundary(modifiedStart - 1)) {
813
+ return true;
814
+ }
815
+ if (modifiedLength > 0) {
816
+ const modifiedEnd = modifiedStart + modifiedLength;
817
+ if (this._ModifiedIsBoundary(modifiedEnd - 1) || this._ModifiedIsBoundary(modifiedEnd)) {
818
+ return true;
819
+ }
820
+ }
821
+ return false;
822
+ }
823
+ _boundaryScore(originalStart, originalLength, modifiedStart, modifiedLength) {
824
+ const originalScore = (this._OriginalRegionIsBoundary(originalStart, originalLength) ? 1 : 0);
825
+ const modifiedScore = (this._ModifiedRegionIsBoundary(modifiedStart, modifiedLength) ? 1 : 0);
826
+ return (originalScore + modifiedScore);
827
+ }
828
+ /**
829
+ * Concatenates the two input DiffChange lists and returns the resulting
830
+ * list.
831
+ * @param The left changes
832
+ * @param The right changes
833
+ * @returns The concatenated list
834
+ */
835
+ ConcatenateChanges(left, right) {
836
+ const mergedChangeArr = [];
837
+ if (left.length === 0 || right.length === 0) {
838
+ return (right.length > 0) ? right : left;
839
+ }
840
+ else if (this.ChangesOverlap(left[left.length - 1], right[0], mergedChangeArr)) {
841
+ // Since we break the problem down recursively, it is possible that we
842
+ // might recurse in the middle of a change thereby splitting it into
843
+ // two changes. Here in the combining stage, we detect and fuse those
844
+ // changes back together
845
+ const result = new Array(left.length + right.length - 1);
846
+ MyArray.Copy(left, 0, result, 0, left.length - 1);
847
+ result[left.length - 1] = mergedChangeArr[0];
848
+ MyArray.Copy(right, 1, result, left.length, right.length - 1);
849
+ return result;
850
+ }
851
+ else {
852
+ const result = new Array(left.length + right.length);
853
+ MyArray.Copy(left, 0, result, 0, left.length);
854
+ MyArray.Copy(right, 0, result, left.length, right.length);
855
+ return result;
856
+ }
857
+ }
858
+ /**
859
+ * Returns true if the two changes overlap and can be merged into a single
860
+ * change
861
+ * @param left The left change
862
+ * @param right The right change
863
+ * @param mergedChange The merged change if the two overlap, null otherwise
864
+ * @returns True if the two changes overlap
865
+ */
866
+ ChangesOverlap(left, right, mergedChangeArr) {
867
+ Debug.Assert(left.originalStart <= right.originalStart, 'Left change is not less than or equal to right change');
868
+ Debug.Assert(left.modifiedStart <= right.modifiedStart, 'Left change is not less than or equal to right change');
869
+ if (left.originalStart + left.originalLength >= right.originalStart || left.modifiedStart + left.modifiedLength >= right.modifiedStart) {
870
+ const originalStart = left.originalStart;
871
+ let originalLength = left.originalLength;
872
+ const modifiedStart = left.modifiedStart;
873
+ let modifiedLength = left.modifiedLength;
874
+ if (left.originalStart + left.originalLength >= right.originalStart) {
875
+ originalLength = right.originalStart + right.originalLength - left.originalStart;
876
+ }
877
+ if (left.modifiedStart + left.modifiedLength >= right.modifiedStart) {
878
+ modifiedLength = right.modifiedStart + right.modifiedLength - left.modifiedStart;
879
+ }
880
+ mergedChangeArr[0] = new DiffChange(originalStart, originalLength, modifiedStart, modifiedLength);
881
+ return true;
882
+ }
883
+ else {
884
+ mergedChangeArr[0] = null;
885
+ return false;
886
+ }
887
+ }
888
+ /**
889
+ * Helper method used to clip a diagonal index to the range of valid
890
+ * diagonals. This also decides whether or not the diagonal index,
891
+ * if it exceeds the boundary, should be clipped to the boundary or clipped
892
+ * one inside the boundary depending on the Even/Odd status of the boundary
893
+ * and numDifferences.
894
+ * @param diagonal The index of the diagonal to clip.
895
+ * @param numDifferences The current number of differences being iterated upon.
896
+ * @param diagonalBaseIndex The base reference diagonal.
897
+ * @param numDiagonals The total number of diagonals.
898
+ * @returns The clipped diagonal index.
899
+ */
900
+ ClipDiagonalBound(diagonal, numDifferences, diagonalBaseIndex, numDiagonals) {
901
+ if (diagonal >= 0 && diagonal < numDiagonals) {
902
+ // Nothing to clip, its in range
903
+ return diagonal;
904
+ }
905
+ // diagonalsBelow: The number of diagonals below the reference diagonal
906
+ // diagonalsAbove: The number of diagonals above the reference diagonal
907
+ const diagonalsBelow = diagonalBaseIndex;
908
+ const diagonalsAbove = numDiagonals - diagonalBaseIndex - 1;
909
+ const diffEven = (numDifferences % 2 === 0);
910
+ if (diagonal < 0) {
911
+ const lowerBoundEven = (diagonalsBelow % 2 === 0);
912
+ return (diffEven === lowerBoundEven) ? 0 : 1;
913
+ }
914
+ else {
915
+ const upperBoundEven = (diagonalsAbove % 2 === 0);
916
+ return (diffEven === upperBoundEven) ? numDiagonals - 1 : numDiagonals - 2;
917
+ }
918
+ }
919
+ }
920
+ /**
921
+ * Precomputed equality array for character codes.
922
+ */
923
+ const precomputedEqualityArray = new Uint32Array(0x10000);
924
+ /**
925
+ * Computes the Levenshtein distance for strings of length <= 32.
926
+ * @param firstString - The first string.
927
+ * @param secondString - The second string.
928
+ * @returns The Levenshtein distance.
929
+ */
930
+ const computeLevenshteinDistanceForShortStrings = (firstString, secondString) => {
931
+ const firstStringLength = firstString.length;
932
+ const secondStringLength = secondString.length;
933
+ const lastBitMask = 1 << (firstStringLength - 1);
934
+ let positiveVector = -1;
935
+ let negativeVector = 0;
936
+ let distance = firstStringLength;
937
+ let index = firstStringLength;
938
+ // Initialize precomputedEqualityArray for firstString
939
+ while (index--) {
940
+ precomputedEqualityArray[firstString.charCodeAt(index)] |= 1 << index;
941
+ }
942
+ // Process each character of secondString
943
+ for (index = 0; index < secondStringLength; index++) {
944
+ let equalityMask = precomputedEqualityArray[secondString.charCodeAt(index)];
945
+ const combinedVector = equalityMask | negativeVector;
946
+ equalityMask |= ((equalityMask & positiveVector) + positiveVector) ^ positiveVector;
947
+ negativeVector |= ~(equalityMask | positiveVector);
948
+ positiveVector &= equalityMask;
949
+ if (negativeVector & lastBitMask) {
950
+ distance++;
951
+ }
952
+ if (positiveVector & lastBitMask) {
953
+ distance--;
954
+ }
955
+ negativeVector = (negativeVector << 1) | 1;
956
+ positiveVector = (positiveVector << 1) | ~(combinedVector | negativeVector);
957
+ negativeVector &= combinedVector;
958
+ }
959
+ // Reset precomputedEqualityArray
960
+ index = firstStringLength;
961
+ while (index--) {
962
+ precomputedEqualityArray[firstString.charCodeAt(index)] = 0;
963
+ }
964
+ return distance;
965
+ };
966
+ /**
967
+ * Computes the Levenshtein distance for strings of length > 32.
968
+ * @param firstString - The first string.
969
+ * @param secondString - The second string.
970
+ * @returns The Levenshtein distance.
971
+ */
972
+ function computeLevenshteinDistanceForLongStrings(firstString, secondString) {
973
+ const firstStringLength = firstString.length;
974
+ const secondStringLength = secondString.length;
975
+ const horizontalBitArray = [];
976
+ const verticalBitArray = [];
977
+ const horizontalSize = Math.ceil(firstStringLength / 32);
978
+ const verticalSize = Math.ceil(secondStringLength / 32);
979
+ // Initialize horizontal and vertical bit arrays
980
+ for (let i = 0; i < horizontalSize; i++) {
981
+ horizontalBitArray[i] = -1;
982
+ verticalBitArray[i] = 0;
983
+ }
984
+ let verticalIndex = 0;
985
+ for (; verticalIndex < verticalSize - 1; verticalIndex++) {
986
+ let negativeVector = 0;
987
+ let positiveVector = -1;
988
+ const start = verticalIndex * 32;
989
+ const verticalLength = Math.min(32, secondStringLength) + start;
990
+ // Initialize precomputedEqualityArray for secondString
991
+ for (let k = start; k < verticalLength; k++) {
992
+ precomputedEqualityArray[secondString.charCodeAt(k)] |= 1 << k;
993
+ }
994
+ // Process each character of firstString
995
+ for (let i = 0; i < firstStringLength; i++) {
996
+ const equalityMask = precomputedEqualityArray[firstString.charCodeAt(i)];
997
+ const previousBit = (horizontalBitArray[(i / 32) | 0] >>> i) & 1;
998
+ const matchBit = (verticalBitArray[(i / 32) | 0] >>> i) & 1;
999
+ const combinedVector = equalityMask | negativeVector;
1000
+ const combinedHorizontalVector = ((((equalityMask | matchBit) & positiveVector) + positiveVector) ^ positiveVector) | equalityMask | matchBit;
1001
+ let positiveHorizontalVector = negativeVector | ~(combinedHorizontalVector | positiveVector);
1002
+ let negativeHorizontalVector = positiveVector & combinedHorizontalVector;
1003
+ if ((positiveHorizontalVector >>> 31) ^ previousBit) {
1004
+ horizontalBitArray[(i / 32) | 0] ^= 1 << i;
1005
+ }
1006
+ if ((negativeHorizontalVector >>> 31) ^ matchBit) {
1007
+ verticalBitArray[(i / 32) | 0] ^= 1 << i;
1008
+ }
1009
+ positiveHorizontalVector = (positiveHorizontalVector << 1) | previousBit;
1010
+ negativeHorizontalVector = (negativeHorizontalVector << 1) | matchBit;
1011
+ positiveVector = negativeHorizontalVector | ~(combinedVector | positiveHorizontalVector);
1012
+ negativeVector = positiveHorizontalVector & combinedVector;
1013
+ }
1014
+ // Reset precomputedEqualityArray
1015
+ for (let k = start; k < verticalLength; k++) {
1016
+ precomputedEqualityArray[secondString.charCodeAt(k)] = 0;
1017
+ }
1018
+ }
1019
+ let negativeVector = 0;
1020
+ let positiveVector = -1;
1021
+ const start = verticalIndex * 32;
1022
+ const verticalLength = Math.min(32, secondStringLength - start) + start;
1023
+ // Initialize precomputedEqualityArray for secondString
1024
+ for (let k = start; k < verticalLength; k++) {
1025
+ precomputedEqualityArray[secondString.charCodeAt(k)] |= 1 << k;
1026
+ }
1027
+ let distance = secondStringLength;
1028
+ // Process each character of firstString
1029
+ for (let i = 0; i < firstStringLength; i++) {
1030
+ const equalityMask = precomputedEqualityArray[firstString.charCodeAt(i)];
1031
+ const previousBit = (horizontalBitArray[(i / 32) | 0] >>> i) & 1;
1032
+ const matchBit = (verticalBitArray[(i / 32) | 0] >>> i) & 1;
1033
+ const combinedVector = equalityMask | negativeVector;
1034
+ const combinedHorizontalVector = ((((equalityMask | matchBit) & positiveVector) + positiveVector) ^ positiveVector) | equalityMask | matchBit;
1035
+ let positiveHorizontalVector = negativeVector | ~(combinedHorizontalVector | positiveVector);
1036
+ let negativeHorizontalVector = positiveVector & combinedHorizontalVector;
1037
+ distance += (positiveHorizontalVector >>> (secondStringLength - 1)) & 1;
1038
+ distance -= (negativeHorizontalVector >>> (secondStringLength - 1)) & 1;
1039
+ if ((positiveHorizontalVector >>> 31) ^ previousBit) {
1040
+ horizontalBitArray[(i / 32) | 0] ^= 1 << i;
1041
+ }
1042
+ if ((negativeHorizontalVector >>> 31) ^ matchBit) {
1043
+ verticalBitArray[(i / 32) | 0] ^= 1 << i;
1044
+ }
1045
+ positiveHorizontalVector = (positiveHorizontalVector << 1) | previousBit;
1046
+ negativeHorizontalVector = (negativeHorizontalVector << 1) | matchBit;
1047
+ positiveVector = negativeHorizontalVector | ~(combinedVector | positiveHorizontalVector);
1048
+ negativeVector = positiveHorizontalVector & combinedVector;
1049
+ }
1050
+ // Reset precomputedEqualityArray
1051
+ for (let k = start; k < verticalLength; k++) {
1052
+ precomputedEqualityArray[secondString.charCodeAt(k)] = 0;
1053
+ }
1054
+ return distance;
1055
+ }
1056
+ /**
1057
+ * Computes the Levenshtein distance between two strings.
1058
+ * @param firstString - The first string.
1059
+ * @param secondString - The second string.
1060
+ * @returns The Levenshtein distance.
1061
+ */
1062
+ export function computeLevenshteinDistance(firstString, secondString) {
1063
+ if (firstString.length < secondString.length) {
1064
+ const temp = secondString;
1065
+ secondString = firstString;
1066
+ firstString = temp;
1067
+ }
1068
+ if (secondString.length === 0) {
1069
+ return firstString.length;
1070
+ }
1071
+ if (firstString.length <= 32) {
1072
+ return computeLevenshteinDistanceForShortStrings(firstString, secondString);
1073
+ }
1074
+ return computeLevenshteinDistanceForLongStrings(firstString, secondString);
1075
+ }
1076
+ //# sourceMappingURL=diff.js.map