@halonicjs/testing 0.0.0-stage → 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 (384) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +1 -0
  3. package/README.md +40 -2
  4. package/dist/adapters/http-kit/src/address-class.d.ts +34 -0
  5. package/dist/adapters/http-kit/src/address-class.js +109 -0
  6. package/dist/adapters/http-kit/src/index.d.ts +2 -0
  7. package/dist/adapters/http-kit/src/index.js +2 -0
  8. package/dist/adapters/http-kit/src/ip-address.d.ts +23 -0
  9. package/dist/adapters/http-kit/src/ip-address.js +89 -0
  10. package/dist/adapters/integration-kit/src/declaration.d.ts +14 -0
  11. package/dist/adapters/integration-kit/src/declaration.js +77 -0
  12. package/dist/adapters/integration-kit/src/host.d.ts +28 -0
  13. package/dist/adapters/integration-kit/src/host.js +30 -0
  14. package/dist/adapters/integration-kit/src/index.d.ts +14 -0
  15. package/dist/adapters/integration-kit/src/index.js +21 -0
  16. package/dist/adapters/integration-kit/src/leak-attempt.d.ts +14 -0
  17. package/dist/adapters/integration-kit/src/leak-attempt.js +16 -0
  18. package/dist/adapters/integration-kit/src/limited-http.d.ts +49 -0
  19. package/dist/adapters/integration-kit/src/limited-http.js +182 -0
  20. package/dist/adapters/integration-kit/src/load-problem.d.ts +20 -0
  21. package/dist/adapters/integration-kit/src/load-problem.js +1 -0
  22. package/dist/adapters/integration-kit/src/loader.d.ts +104 -0
  23. package/dist/adapters/integration-kit/src/loader.js +219 -0
  24. package/dist/adapters/integration-kit/src/local-address.d.ts +15 -0
  25. package/dist/adapters/integration-kit/src/local-address.js +25 -0
  26. package/dist/adapters/integration-kit/src/own-request.d.ts +33 -0
  27. package/dist/adapters/integration-kit/src/own-request.js +36 -0
  28. package/dist/adapters/integration-kit/src/plugin-load.d.ts +14 -0
  29. package/dist/adapters/integration-kit/src/plugin-load.js +58 -0
  30. package/dist/adapters/integration-kit/src/policy.d.ts +55 -0
  31. package/dist/adapters/integration-kit/src/policy.js +37 -0
  32. package/dist/adapters/integration-kit/src/request-body.d.ts +38 -0
  33. package/dist/adapters/integration-kit/src/request-body.js +68 -0
  34. package/dist/adapters/integration-kit/src/request-log.d.ts +25 -0
  35. package/dist/adapters/integration-kit/src/request-log.js +17 -0
  36. package/dist/adapters/integration-kit/src/response-body.d.ts +23 -0
  37. package/dist/adapters/integration-kit/src/response-body.js +117 -0
  38. package/dist/adapters/integration-kit/src/scoped-tokens.d.ts +14 -0
  39. package/dist/adapters/integration-kit/src/scoped-tokens.js +27 -0
  40. package/dist/adapters/integration-kit/src/secret-filter.d.ts +84 -0
  41. package/dist/adapters/integration-kit/src/secret-filter.js +205 -0
  42. package/dist/adapters/integration-kit/src/secret-in-request.d.ts +59 -0
  43. package/dist/adapters/integration-kit/src/secret-in-request.js +133 -0
  44. package/dist/adapters/integration-kit/src/secret-placement.d.ts +36 -0
  45. package/dist/adapters/integration-kit/src/secret-placement.js +190 -0
  46. package/dist/adapters/integration-kit/src/wait.d.ts +16 -0
  47. package/dist/adapters/integration-kit/src/wait.js +35 -0
  48. package/dist/core/events/src/add-usage.d.ts +10 -0
  49. package/dist/core/events/src/add-usage.js +27 -0
  50. package/dist/core/events/src/agent-resume.d.ts +24 -0
  51. package/dist/core/events/src/agent-resume.js +1 -0
  52. package/dist/core/events/src/home-path.d.ts +13 -0
  53. package/dist/core/events/src/home-path.js +26 -0
  54. package/dist/core/events/src/index.d.ts +13 -0
  55. package/dist/core/events/src/index.js +7 -0
  56. package/dist/core/events/src/run-basics.d.ts +205 -0
  57. package/dist/core/events/src/run-basics.js +1 -0
  58. package/dist/core/events/src/run-event.d.ts +434 -0
  59. package/dist/core/events/src/run-event.js +1 -0
  60. package/dist/core/events/src/run-summary.d.ts +108 -0
  61. package/dist/core/events/src/run-summary.js +1 -0
  62. package/dist/core/events/src/sandbox-blocked.d.ts +42 -0
  63. package/dist/core/events/src/sandbox-blocked.js +26 -0
  64. package/dist/core/events/src/sandbox-opened-read.d.ts +17 -0
  65. package/dist/core/events/src/sandbox-opened-read.js +63 -0
  66. package/dist/core/events/src/sandbox-opened.d.ts +94 -0
  67. package/dist/core/events/src/sandbox-opened.js +52 -0
  68. package/dist/core/events/src/summarize.d.ts +14 -0
  69. package/dist/core/events/src/summarize.js +188 -0
  70. package/dist/core/events/src/timeline-entry.d.ts +21 -0
  71. package/dist/core/events/src/timeline-entry.js +105 -0
  72. package/dist/core/events/src/upgrade.d.ts +23 -0
  73. package/dist/core/events/src/upgrade.js +49 -0
  74. package/dist/core/format/src/compact.d.ts +30 -0
  75. package/dist/core/format/src/compact.js +72 -0
  76. package/dist/core/format/src/index.d.ts +37 -0
  77. package/dist/core/format/src/index.js +23 -0
  78. package/dist/core/format/src/integration/index.d.ts +6 -0
  79. package/dist/core/format/src/integration/index.js +9 -0
  80. package/dist/core/format/src/json-schema.d.ts +26 -0
  81. package/dist/core/format/src/json-schema.js +48 -0
  82. package/dist/core/format/src/kind.d.ts +65 -0
  83. package/dist/core/format/src/kind.js +1 -0
  84. package/dist/core/format/src/kinds/agent/kind.d.ts +4 -0
  85. package/dist/core/format/src/kinds/agent/kind.js +10 -0
  86. package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +89 -0
  87. package/dist/core/format/src/kinds/agent/sandbox-fields.js +197 -0
  88. package/dist/core/format/src/kinds/agent/schema.d.ts +147 -0
  89. package/dist/core/format/src/kinds/agent/schema.js +107 -0
  90. package/dist/core/format/src/kinds/agent/working-folder-start.d.ts +74 -0
  91. package/dist/core/format/src/kinds/agent/working-folder-start.js +312 -0
  92. package/dist/core/format/src/kinds/collection/kind.d.ts +8 -0
  93. package/dist/core/format/src/kinds/collection/kind.js +14 -0
  94. package/dist/core/format/src/kinds/collection/schema.d.ts +89 -0
  95. package/dist/core/format/src/kinds/collection/schema.js +90 -0
  96. package/dist/core/format/src/kinds/connector/is-local.d.ts +10 -0
  97. package/dist/core/format/src/kinds/connector/is-local.js +43 -0
  98. package/dist/core/format/src/kinds/connector/kind.d.ts +4 -0
  99. package/dist/core/format/src/kinds/connector/kind.js +119 -0
  100. package/dist/core/format/src/kinds/connector/schema.d.ts +50 -0
  101. package/dist/core/format/src/kinds/connector/schema.js +92 -0
  102. package/dist/core/format/src/kinds/deployments/kind.d.ts +4 -0
  103. package/dist/core/format/src/kinds/deployments/kind.js +25 -0
  104. package/dist/core/format/src/kinds/deployments/schema.d.ts +37 -0
  105. package/dist/core/format/src/kinds/deployments/schema.js +42 -0
  106. package/dist/core/format/src/kinds/hub/kind.d.ts +4 -0
  107. package/dist/core/format/src/kinds/hub/kind.js +10 -0
  108. package/dist/core/format/src/kinds/hub/schema.d.ts +54 -0
  109. package/dist/core/format/src/kinds/hub/schema.js +34 -0
  110. package/dist/core/format/src/kinds/integration/kind.d.ts +16 -0
  111. package/dist/core/format/src/kinds/integration/kind.js +138 -0
  112. package/dist/core/format/src/kinds/integration/parse-sheet.d.ts +19 -0
  113. package/dist/core/format/src/kinds/integration/parse-sheet.js +24 -0
  114. package/dist/core/format/src/kinds/integration/policy.d.ts +67 -0
  115. package/dist/core/format/src/kinds/integration/policy.js +268 -0
  116. package/dist/core/format/src/kinds/integration/schema.d.ts +233 -0
  117. package/dist/core/format/src/kinds/integration/schema.js +233 -0
  118. package/dist/core/format/src/kinds/knowledge/kind.d.ts +4 -0
  119. package/dist/core/format/src/kinds/knowledge/kind.js +13 -0
  120. package/dist/core/format/src/kinds/knowledge/schema.d.ts +18 -0
  121. package/dist/core/format/src/kinds/knowledge/schema.js +25 -0
  122. package/dist/core/format/src/kinds/models/kind.d.ts +4 -0
  123. package/dist/core/format/src/kinds/models/kind.js +10 -0
  124. package/dist/core/format/src/kinds/models/schema.d.ts +92 -0
  125. package/dist/core/format/src/kinds/models/schema.js +38 -0
  126. package/dist/core/format/src/kinds/plugin/backend.d.ts +22 -0
  127. package/dist/core/format/src/kinds/plugin/backend.js +31 -0
  128. package/dist/core/format/src/kinds/plugin/checks.d.ts +13 -0
  129. package/dist/core/format/src/kinds/plugin/checks.js +131 -0
  130. package/dist/core/format/src/kinds/plugin/kind.d.ts +8 -0
  131. package/dist/core/format/src/kinds/plugin/kind.js +16 -0
  132. package/dist/core/format/src/kinds/plugin/problems.d.ts +24 -0
  133. package/dist/core/format/src/kinds/plugin/problems.js +65 -0
  134. package/dist/core/format/src/kinds/plugin/schema.d.ts +542 -0
  135. package/dist/core/format/src/kinds/plugin/schema.js +261 -0
  136. package/dist/core/format/src/kinds/plugin/setting-values.d.ts +17 -0
  137. package/dist/core/format/src/kinds/plugin/setting-values.js +38 -0
  138. package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +8 -0
  139. package/dist/core/format/src/kinds/plugin/ui-checks.js +94 -0
  140. package/dist/core/format/src/kinds/provider/kind.d.ts +4 -0
  141. package/dist/core/format/src/kinds/provider/kind.js +24 -0
  142. package/dist/core/format/src/kinds/provider/schema.d.ts +17 -0
  143. package/dist/core/format/src/kinds/provider/schema.js +22 -0
  144. package/dist/core/format/src/kinds/routine/kind.d.ts +8 -0
  145. package/dist/core/format/src/kinds/routine/kind.js +25 -0
  146. package/dist/core/format/src/kinds/routine/schema.d.ts +84 -0
  147. package/dist/core/format/src/kinds/routine/schema.js +93 -0
  148. package/dist/core/format/src/kinds/runtime/kind.d.ts +4 -0
  149. package/dist/core/format/src/kinds/runtime/kind.js +13 -0
  150. package/dist/core/format/src/kinds/runtime/schema.d.ts +10 -0
  151. package/dist/core/format/src/kinds/runtime/schema.js +12 -0
  152. package/dist/core/format/src/kinds/skill/kind.d.ts +4 -0
  153. package/dist/core/format/src/kinds/skill/kind.js +10 -0
  154. package/dist/core/format/src/kinds/skill/schema.d.ts +17 -0
  155. package/dist/core/format/src/kinds/skill/schema.js +17 -0
  156. package/dist/core/format/src/kinds/skill/scripts-folder.d.ts +27 -0
  157. package/dist/core/format/src/kinds/skill/scripts-folder.js +37 -0
  158. package/dist/core/format/src/kinds/workflow/kind.d.ts +8 -0
  159. package/dist/core/format/src/kinds/workflow/kind.js +14 -0
  160. package/dist/core/format/src/kinds/workflow/schema.d.ts +162 -0
  161. package/dist/core/format/src/kinds/workflow/schema.js +106 -0
  162. package/dist/core/format/src/kinds/workflow-test/kind.d.ts +4 -0
  163. package/dist/core/format/src/kinds/workflow-test/kind.js +14 -0
  164. package/dist/core/format/src/kinds/workflow-test/schema.d.ts +67 -0
  165. package/dist/core/format/src/kinds/workflow-test/schema.js +59 -0
  166. package/dist/core/format/src/kinds/workspace/kind.d.ts +4 -0
  167. package/dist/core/format/src/kinds/workspace/kind.js +10 -0
  168. package/dist/core/format/src/kinds/workspace/schema.d.ts +72 -0
  169. package/dist/core/format/src/kinds/workspace/schema.js +66 -0
  170. package/dist/core/format/src/parse-file.d.ts +69 -0
  171. package/dist/core/format/src/parse-file.js +105 -0
  172. package/dist/core/format/src/recording/format.d.ts +81 -0
  173. package/dist/core/format/src/recording/format.js +102 -0
  174. package/dist/core/format/src/recording/index.d.ts +1 -0
  175. package/dist/core/format/src/recording/index.js +3 -0
  176. package/dist/core/format/src/registry.d.ts +64 -0
  177. package/dist/core/format/src/registry.js +61 -0
  178. package/dist/core/format/src/reserved.d.ts +20 -0
  179. package/dist/core/format/src/reserved.js +30 -0
  180. package/dist/core/format/src/shared/fields.d.ts +37 -0
  181. package/dist/core/format/src/shared/fields.js +54 -0
  182. package/dist/core/format/src/shared/guard.d.ts +32 -0
  183. package/dist/core/format/src/shared/guard.js +16 -0
  184. package/dist/core/format/src/shared/key-in-value.d.ts +28 -0
  185. package/dist/core/format/src/shared/key-in-value.js +82 -0
  186. package/dist/core/format/src/shared/legacy-keys.d.ts +8 -0
  187. package/dist/core/format/src/shared/legacy-keys.js +17 -0
  188. package/dist/core/format/src/shared/program-start.d.ts +60 -0
  189. package/dist/core/format/src/shared/program-start.js +99 -0
  190. package/dist/core/format/src/shared/relative-path.d.ts +29 -0
  191. package/dist/core/format/src/shared/relative-path.js +50 -0
  192. package/dist/core/format/src/shared/secret-name.d.ts +24 -0
  193. package/dist/core/format/src/shared/secret-name.js +107 -0
  194. package/dist/core/format/src/source.d.ts +16 -0
  195. package/dist/core/format/src/source.js +73 -0
  196. package/dist/core/ports/src/agent-placement-store.d.ts +74 -0
  197. package/dist/core/ports/src/agent-placement-store.js +27 -0
  198. package/dist/core/ports/src/blob-store.d.ts +33 -0
  199. package/dist/core/ports/src/blob-store.js +2 -0
  200. package/dist/core/ports/src/cant-try-error.d.ts +35 -0
  201. package/dist/core/ports/src/cant-try-error.js +44 -0
  202. package/dist/core/ports/src/chat.d.ts +127 -0
  203. package/dist/core/ports/src/chat.js +1 -0
  204. package/dist/core/ports/src/clock.d.ts +7 -0
  205. package/dist/core/ports/src/clock.js +2 -0
  206. package/dist/core/ports/src/connection-settings-store.d.ts +57 -0
  207. package/dist/core/ports/src/connection-settings-store.js +2 -0
  208. package/dist/core/ports/src/connector-client.d.ts +259 -0
  209. package/dist/core/ports/src/connector-client.js +2 -0
  210. package/dist/core/ports/src/coordination.d.ts +84 -0
  211. package/dist/core/ports/src/coordination.js +2 -0
  212. package/dist/core/ports/src/definition-store.d.ts +208 -0
  213. package/dist/core/ports/src/definition-store.js +122 -0
  214. package/dist/core/ports/src/digest.d.ts +14 -0
  215. package/dist/core/ports/src/digest.js +2 -0
  216. package/dist/core/ports/src/folder-reader.d.ts +89 -0
  217. package/dist/core/ports/src/folder-reader.js +2 -0
  218. package/dist/core/ports/src/harness-bridge-server.d.ts +189 -0
  219. package/dist/core/ports/src/harness-bridge-server.js +37 -0
  220. package/dist/core/ports/src/harness.d.ts +250 -0
  221. package/dist/core/ports/src/harness.js +45 -0
  222. package/dist/core/ports/src/http-client.d.ts +27 -0
  223. package/dist/core/ports/src/http-client.js +2 -0
  224. package/dist/core/ports/src/id-generator.d.ts +14 -0
  225. package/dist/core/ports/src/id-generator.js +2 -0
  226. package/dist/core/ports/src/index.d.ts +37 -0
  227. package/dist/core/ports/src/index.js +36 -0
  228. package/dist/core/ports/src/integration.d.ts +178 -0
  229. package/dist/core/ports/src/integration.js +13 -0
  230. package/dist/core/ports/src/knowledge-provider.d.ts +65 -0
  231. package/dist/core/ports/src/knowledge-provider.js +2 -0
  232. package/dist/core/ports/src/llm-cache.d.ts +13 -0
  233. package/dist/core/ports/src/llm-cache.js +2 -0
  234. package/dist/core/ports/src/llm-provider.d.ts +184 -0
  235. package/dist/core/ports/src/llm-provider.js +136 -0
  236. package/dist/core/ports/src/model-price.d.ts +34 -0
  237. package/dist/core/ports/src/model-price.js +25 -0
  238. package/dist/core/ports/src/password-hasher.d.ts +47 -0
  239. package/dist/core/ports/src/password-hasher.js +2 -0
  240. package/dist/core/ports/src/plugin-folder-writer.d.ts +104 -0
  241. package/dist/core/ports/src/plugin-folder-writer.js +95 -0
  242. package/dist/core/ports/src/port-versions.d.ts +44 -0
  243. package/dist/core/ports/src/port-versions.js +74 -0
  244. package/dist/core/ports/src/program-probe.d.ts +46 -0
  245. package/dist/core/ports/src/program-probe.js +2 -0
  246. package/dist/core/ports/src/record-store.d.ts +62 -0
  247. package/dist/core/ports/src/record-store.js +38 -0
  248. package/dist/core/ports/src/resource-probe.d.ts +59 -0
  249. package/dist/core/ports/src/resource-probe.js +2 -0
  250. package/dist/core/ports/src/run-executor.d.ts +302 -0
  251. package/dist/core/ports/src/run-executor.js +2 -0
  252. package/dist/core/ports/src/run-failure-error.d.ts +49 -0
  253. package/dist/core/ports/src/run-failure-error.js +47 -0
  254. package/dist/core/ports/src/run-store.d.ts +194 -0
  255. package/dist/core/ports/src/run-store.js +131 -0
  256. package/dist/core/ports/src/sandbox.d.ts +247 -0
  257. package/dist/core/ports/src/sandbox.js +34 -0
  258. package/dist/core/ports/src/scheduler.d.ts +85 -0
  259. package/dist/core/ports/src/scheduler.js +2 -0
  260. package/dist/core/ports/src/secrets.d.ts +128 -0
  261. package/dist/core/ports/src/secrets.js +144 -0
  262. package/dist/core/ports/src/token-store.d.ts +19 -0
  263. package/dist/core/ports/src/token-store.js +2 -0
  264. package/dist/core/ports/src/tool-approval-store.d.ts +211 -0
  265. package/dist/core/ports/src/tool-approval-store.js +57 -0
  266. package/dist/core/ports/src/trust-store.d.ts +72 -0
  267. package/dist/core/ports/src/trust-store.js +2 -0
  268. package/dist/core/ports/src/unfenced-run-consent-store.d.ts +43 -0
  269. package/dist/core/ports/src/unfenced-run-consent-store.js +2 -0
  270. package/dist/core/ports/src/vcs.d.ts +394 -0
  271. package/dist/core/ports/src/vcs.js +48 -0
  272. package/dist/core/schema-kit/src/builders.d.ts +50 -0
  273. package/dist/core/schema-kit/src/builders.js +72 -0
  274. package/dist/core/schema-kit/src/depth.d.ts +15 -0
  275. package/dist/core/schema-kit/src/depth.js +37 -0
  276. package/dist/core/schema-kit/src/index.d.ts +6 -0
  277. package/dist/core/schema-kit/src/index.js +6 -0
  278. package/dist/core/schema-kit/src/issue.d.ts +22 -0
  279. package/dist/core/schema-kit/src/issue.js +23 -0
  280. package/dist/core/schema-kit/src/json-schema.d.ts +23 -0
  281. package/dist/core/schema-kit/src/json-schema.js +22 -0
  282. package/dist/core/schema-kit/src/parse.d.ts +17 -0
  283. package/dist/core/schema-kit/src/parse.js +25 -0
  284. package/dist/core/schema-kit/src/schema.d.ts +12 -0
  285. package/dist/core/schema-kit/src/schema.js +1 -0
  286. package/dist/core/std/src/ascii-host.d.ts +18 -0
  287. package/dist/core/std/src/ascii-host.js +110 -0
  288. package/dist/core/std/src/assert.d.ts +39 -0
  289. package/dist/core/std/src/assert.js +59 -0
  290. package/dist/core/std/src/base64url.d.ts +23 -0
  291. package/dist/core/std/src/base64url.js +65 -0
  292. package/dist/core/std/src/canonical-json.d.ts +18 -0
  293. package/dist/core/std/src/canonical-json.js +56 -0
  294. package/dist/core/std/src/clock.d.ts +27 -0
  295. package/dist/core/std/src/clock.js +33 -0
  296. package/dist/core/std/src/constant-time.d.ts +16 -0
  297. package/dist/core/std/src/constant-time.js +26 -0
  298. package/dist/core/std/src/content-digest.d.ts +24 -0
  299. package/dist/core/std/src/content-digest.js +28 -0
  300. package/dist/core/std/src/deep-clone.d.ts +15 -0
  301. package/dist/core/std/src/deep-clone.js +59 -0
  302. package/dist/core/std/src/deep-equal.d.ts +23 -0
  303. package/dist/core/std/src/deep-equal.js +64 -0
  304. package/dist/core/std/src/emitter.d.ts +42 -0
  305. package/dist/core/std/src/emitter.js +74 -0
  306. package/dist/core/std/src/error-kind.d.ts +88 -0
  307. package/dist/core/std/src/error-kind.js +98 -0
  308. package/dist/core/std/src/hex.d.ts +10 -0
  309. package/dist/core/std/src/hex.js +16 -0
  310. package/dist/core/std/src/ids.d.ts +45 -0
  311. package/dist/core/std/src/ids.js +49 -0
  312. package/dist/core/std/src/index.d.ts +25 -0
  313. package/dist/core/std/src/index.js +26 -0
  314. package/dist/core/std/src/keyed-queue.d.ts +18 -0
  315. package/dist/core/std/src/keyed-queue.js +32 -0
  316. package/dist/core/std/src/line-diff.d.ts +83 -0
  317. package/dist/core/std/src/line-diff.js +179 -0
  318. package/dist/core/std/src/line-merge.d.ts +63 -0
  319. package/dist/core/std/src/line-merge.js +138 -0
  320. package/dist/core/std/src/plain-data.d.ts +32 -0
  321. package/dist/core/std/src/plain-data.js +57 -0
  322. package/dist/core/std/src/posix-path.d.ts +61 -0
  323. package/dist/core/std/src/posix-path.js +121 -0
  324. package/dist/core/std/src/result.d.ts +55 -0
  325. package/dist/core/std/src/result.js +52 -0
  326. package/dist/core/std/src/secret-scrubber.d.ts +54 -0
  327. package/dist/core/std/src/secret-scrubber.js +124 -0
  328. package/dist/core/std/src/secret-shape.d.ts +20 -0
  329. package/dist/core/std/src/secret-shape.js +53 -0
  330. package/dist/core/std/src/stop-signal.d.ts +44 -0
  331. package/dist/core/std/src/stop-signal.js +77 -0
  332. package/dist/core/std/src/text.d.ts +28 -0
  333. package/dist/core/std/src/text.js +54 -0
  334. package/dist/core/std/src/utf8.d.ts +23 -0
  335. package/dist/core/std/src/utf8.js +110 -0
  336. package/dist/core/std/src/version.d.ts +48 -0
  337. package/dist/core/std/src/version.js +103 -0
  338. package/dist/core/yaml/src/depth.d.ts +14 -0
  339. package/dist/core/yaml/src/depth.js +140 -0
  340. package/dist/core/yaml/src/edit-data.d.ts +47 -0
  341. package/dist/core/yaml/src/edit-data.js +286 -0
  342. package/dist/core/yaml/src/edit-text.d.ts +92 -0
  343. package/dist/core/yaml/src/edit-text.js +267 -0
  344. package/dist/core/yaml/src/edit.d.ts +47 -0
  345. package/dist/core/yaml/src/edit.js +198 -0
  346. package/dist/core/yaml/src/index.d.ts +5 -0
  347. package/dist/core/yaml/src/index.js +4 -0
  348. package/dist/core/yaml/src/problem.d.ts +20 -0
  349. package/dist/core/yaml/src/problem.js +1 -0
  350. package/dist/core/yaml/src/read.d.ts +47 -0
  351. package/dist/core/yaml/src/read.js +130 -0
  352. package/dist/core/yaml/src/splice-node.d.ts +47 -0
  353. package/dist/core/yaml/src/splice-node.js +333 -0
  354. package/dist/core/yaml/src/splice.d.ts +13 -0
  355. package/dist/core/yaml/src/splice.js +174 -0
  356. package/dist/core/yaml/src/unsupported.d.ts +26 -0
  357. package/dist/core/yaml/src/unsupported.js +70 -0
  358. package/dist/core/yaml/src/write.d.ts +35 -0
  359. package/dist/core/yaml/src/write.js +44 -0
  360. package/dist/testing/integration/src/canaries.d.ts +14 -0
  361. package/dist/testing/integration/src/canaries.js +17 -0
  362. package/dist/testing/integration/src/checks.d.ts +37 -0
  363. package/dist/testing/integration/src/checks.js +195 -0
  364. package/dist/testing/integration/src/describe.d.ts +35 -0
  365. package/dist/testing/integration/src/describe.js +74 -0
  366. package/dist/testing/integration/src/failure.d.ts +6 -0
  367. package/dist/testing/integration/src/failure.js +8 -0
  368. package/dist/testing/integration/src/fake-wait.d.ts +18 -0
  369. package/dist/testing/integration/src/fake-wait.js +21 -0
  370. package/dist/testing/integration/src/index.d.ts +10 -0
  371. package/dist/testing/integration/src/index.js +11 -0
  372. package/dist/testing/integration/src/load.d.ts +14 -0
  373. package/dist/testing/integration/src/load.js +45 -0
  374. package/dist/testing/integration/src/plugin-folder.d.ts +23 -0
  375. package/dist/testing/integration/src/plugin-folder.js +59 -0
  376. package/dist/testing/integration/src/plugin.d.ts +32 -0
  377. package/dist/testing/integration/src/plugin.js +57 -0
  378. package/dist/testing/integration/src/recording.d.ts +84 -0
  379. package/dist/testing/integration/src/recording.js +164 -0
  380. package/dist/testing/integration/src/run.d.ts +60 -0
  381. package/dist/testing/integration/src/run.js +81 -0
  382. package/dist/testing/integration/src/source-scan.d.ts +16 -0
  383. package/dist/testing/integration/src/source-scan.js +40 -0
  384. package/package.json +35 -4
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Every kind of error a surface (HTTP, CLI, Studio, MCP) can respond to, in a
3
+ * fixed order for exhaustive tests and docs. Each surface turns a kind into
4
+ * its response in one `switch` that ends in
5
+ * `assertNever(kind, "error kind")`, so a new kind fails the typecheck until
6
+ * every surface handles it.
7
+ *
8
+ * - `invalid_input`: the request or file is wrong; the caller fixes the input.
9
+ * - `not_found`: the thing asked for doesn't exist.
10
+ * - `conflict`: it exists, but its state doesn't allow this now: it already
11
+ * exists, someone else changed it first, or another step must come first.
12
+ * - `unauthenticated`: we don't know who is asking, or their sign-in expired.
13
+ * - `denied`: we know who is asking, but a rule says no.
14
+ * - `limit_reached`: a rate limit, quota or spend budget is used up.
15
+ * - `unavailable`: something we depend on is down or timed out; a retry may work.
16
+ * - `internal`: a bug on our side. Anything without a kind is `internal`.
17
+ */
18
+ export const errorKinds = [
19
+ "invalid_input",
20
+ "not_found",
21
+ "conflict",
22
+ "unauthenticated",
23
+ "denied",
24
+ "limit_reached",
25
+ "unavailable",
26
+ "internal",
27
+ ];
28
+ /**
29
+ * True when `value` is one of the error kinds. Use it to decode a kind that
30
+ * came over the wire, such as the `kind` in an HTTP error body.
31
+ *
32
+ * @example
33
+ * isErrorKind("not_found"); // true
34
+ * isErrorKind("not-found"); // false
35
+ */
36
+ export function isErrorKind(value) {
37
+ return errorKinds.some((kind) => kind === value);
38
+ }
39
+ /**
40
+ * An error with a kind, for code that fails in a way a person should hear
41
+ * about. Errors that already have their own class don't have to extend this
42
+ * one: a `kind` property is enough for {@link errorKindOf}.
43
+ *
44
+ * The message must be safe to show and to log: no secrets, tokens, internal
45
+ * paths or internal codes. Surfaces show a generic message for `internal`
46
+ * instead of this one, so don't rely on the text of an `internal` error
47
+ * reaching the user; put what helps there in the log. The same rule holds
48
+ * for the optional `fix`, which is kept apart from the message so a surface
49
+ * can show it on its own line or in its own JSON field.
50
+ *
51
+ * @example
52
+ * throw new KindedError("not_found", `There is no routine named "${name}".`);
53
+ * throw new KindedError("unavailable", "Halonic couldn't reach Ollama.", {
54
+ * fix: "Start Ollama, then run again.",
55
+ * });
56
+ */
57
+ export class KindedError extends Error {
58
+ name = "KindedError";
59
+ kind;
60
+ /** The one next step that fixes it; `undefined` when there is none to suggest. */
61
+ fix;
62
+ /**
63
+ * @param kind - how a surface should respond
64
+ * @param message - safe to show and to log
65
+ * @param options - `fix` is the next step, safe to show and to log; `cause`
66
+ * keeps the error this one wraps, for the log
67
+ */
68
+ constructor(kind, message, options = {}) {
69
+ super(message, "cause" in options ? { cause: options.cause } : undefined);
70
+ this.kind = kind;
71
+ this.fix = options.fix;
72
+ }
73
+ }
74
+ /**
75
+ * The kind of any thrown value, for the one function per surface that turns
76
+ * errors into responses. A value has a kind when it is an object with a
77
+ * valid `kind` string and a `message` string: a `KindedError`, an error class
78
+ * with a `kind` property, or the `{ kind, message }` shape an error takes over
79
+ * HTTP or IPC. Anything else is `internal`, including objects that only have
80
+ * a `kind`, such as events.
81
+ *
82
+ * It reads only the value itself, never its `cause`: code that wraps an error
83
+ * chooses the kind of the wrapper on purpose.
84
+ *
85
+ * @example
86
+ * errorKindOf(new KindedError("conflict", "The run changed.")); // "conflict"
87
+ * errorKindOf({ kind: "not_found", message: "No such hub." }); // "not_found"
88
+ * errorKindOf(new TypeError("x is undefined")); // "internal"
89
+ */
90
+ export function errorKindOf(error) {
91
+ if (typeof error !== "object" || error === null || !("kind" in error) || !("message" in error)) {
92
+ return "internal";
93
+ }
94
+ if (isErrorKind(error.kind) && typeof error.message === "string") {
95
+ return error.kind;
96
+ }
97
+ return "internal";
98
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Writes bytes as lowercase hexadecimal text, two characters per byte.
3
+ *
4
+ * @param bytes - the bytes to write
5
+ * @returns the hex text, empty for no bytes
6
+ *
7
+ * @example
8
+ * bytesToHex(new Uint8Array([0, 171, 255])); // "00abff"
9
+ */
10
+ export declare function bytesToHex(bytes: Uint8Array): string;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Writes bytes as lowercase hexadecimal text, two characters per byte.
3
+ *
4
+ * @param bytes - the bytes to write
5
+ * @returns the hex text, empty for no bytes
6
+ *
7
+ * @example
8
+ * bytesToHex(new Uint8Array([0, 171, 255])); // "00abff"
9
+ */
10
+ export function bytesToHex(bytes) {
11
+ let text = "";
12
+ for (const byte of bytes) {
13
+ text += byte.toString(16).padStart(2, "0");
14
+ }
15
+ return text;
16
+ }
@@ -0,0 +1,45 @@
1
+ import type { Clock } from "./clock.js";
2
+ /** Makes new ids. Code that creates ids takes one, so tests can pass `fixedIds()`. */
3
+ export interface IdGenerator {
4
+ /**
5
+ * A new id that starts with `prefix` and an underscore.
6
+ *
7
+ * @param prefix - says what the id is for, such as `"run"`
8
+ */
9
+ next(prefix: string): string;
10
+ }
11
+ /**
12
+ * Fills a new array with `byteCount` random bytes. The core has no access to
13
+ * the platform's randomness, so the caller passes this in. On every target it
14
+ * should be cryptographically secure, such as
15
+ * `(n) => crypto.getRandomValues(new Uint8Array(n))`.
16
+ */
17
+ export type RandomBytes = (byteCount: number) => Uint8Array;
18
+ /**
19
+ * Ids made of a prefix, the time in base 36 and 4 random bytes in hex, such as
20
+ * `run_mfx3k2a1_a1b2c3d4`. Ids made later sort later as long as the time keeps
21
+ * the same number of digits (until the year 2059).
22
+ *
23
+ * @param randomBytes - where the random part comes from
24
+ * @param clock - where the time part comes from
25
+ * @returns the generator
26
+ * @throws AssertionError from `next` when `randomBytes` returns the wrong number of bytes
27
+ *
28
+ * @example
29
+ * const ids = randomIds((n) => crypto.getRandomValues(new Uint8Array(n)), systemClock);
30
+ * ids.next("run"); // "run_mfx3k2a1_a1b2c3d4"
31
+ */
32
+ export declare function randomIds(randomBytes: RandomBytes, clock: Clock): IdGenerator;
33
+ /**
34
+ * Ids for tests: each prefix counts up on its own from 1, so `run_1`, `run_2`
35
+ * and `event_1` are the first three ids of a run.
36
+ *
37
+ * @returns a new generator whose counters all start at zero
38
+ *
39
+ * @example
40
+ * const ids = fixedIds();
41
+ * ids.next("run"); // "run_1"
42
+ * ids.next("run"); // "run_2"
43
+ * ids.next("event"); // "event_1"
44
+ */
45
+ export declare function fixedIds(): IdGenerator;
@@ -0,0 +1,49 @@
1
+ import { assert } from "./assert.js";
2
+ import { bytesToHex } from "./hex.js";
3
+ /** How many random bytes `randomIds` puts in each id. */
4
+ const randomByteCount = 4;
5
+ /**
6
+ * Ids made of a prefix, the time in base 36 and 4 random bytes in hex, such as
7
+ * `run_mfx3k2a1_a1b2c3d4`. Ids made later sort later as long as the time keeps
8
+ * the same number of digits (until the year 2059).
9
+ *
10
+ * @param randomBytes - where the random part comes from
11
+ * @param clock - where the time part comes from
12
+ * @returns the generator
13
+ * @throws AssertionError from `next` when `randomBytes` returns the wrong number of bytes
14
+ *
15
+ * @example
16
+ * const ids = randomIds((n) => crypto.getRandomValues(new Uint8Array(n)), systemClock);
17
+ * ids.next("run"); // "run_mfx3k2a1_a1b2c3d4"
18
+ */
19
+ export function randomIds(randomBytes, clock) {
20
+ return {
21
+ next(prefix) {
22
+ const random = randomBytes(randomByteCount);
23
+ assert(random.length === randomByteCount, `randomIds asked for ${randomByteCount} random bytes but got ${random.length}.`);
24
+ return `${prefix}_${clock.now().getTime().toString(36)}_${bytesToHex(random)}`;
25
+ },
26
+ };
27
+ }
28
+ /**
29
+ * Ids for tests: each prefix counts up on its own from 1, so `run_1`, `run_2`
30
+ * and `event_1` are the first three ids of a run.
31
+ *
32
+ * @returns a new generator whose counters all start at zero
33
+ *
34
+ * @example
35
+ * const ids = fixedIds();
36
+ * ids.next("run"); // "run_1"
37
+ * ids.next("run"); // "run_2"
38
+ * ids.next("event"); // "event_1"
39
+ */
40
+ export function fixedIds() {
41
+ const counters = new Map();
42
+ return {
43
+ next(prefix) {
44
+ const count = (counters.get(prefix) ?? 0) + 1;
45
+ counters.set(prefix, count);
46
+ return `${prefix}_${count}`;
47
+ },
48
+ };
49
+ }
@@ -0,0 +1,25 @@
1
+ export { asciiHost } from "./ascii-host.js";
2
+ export { AssertionError, assert, assertDefined, assertNever } from "./assert.js";
3
+ export { decodeBase64url, encodeBase64url } from "./base64url.js";
4
+ export { canonicalJson } from "./canonical-json.js";
5
+ export { type Clock, fixedClock, fixedClockStart, systemClock } from "./clock.js";
6
+ export { constantTimeEqual } from "./constant-time.js";
7
+ export { contentDigest, matchesExpected, type Sha256 } from "./content-digest.js";
8
+ export { deepClone } from "./deep-clone.js";
9
+ export { deepEqual } from "./deep-equal.js";
10
+ export { Emitter, type Listener } from "./emitter.js";
11
+ export { type ErrorKind, errorKindOf, errorKinds, isErrorKind, KindedError, } from "./error-kind.js";
12
+ export { bytesToHex } from "./hex.js";
13
+ export { fixedIds, type IdGenerator, type RandomBytes, randomIds } from "./ids.js";
14
+ export { KeyedQueue } from "./keyed-queue.js";
15
+ export { applyLineChanges, type DiffLinesOptions, diffLines, type LineChange, MAX_COMPARED_LINE_PAIRS, splitLines, } from "./line-diff.js";
16
+ export { hasConflicts, type MergeLinesOptions, type MergeRegion, mergedText, mergeLines, } from "./line-merge.js";
17
+ export { describeObject, isPlainObject, keyPath } from "./plain-data.js";
18
+ export { posixPath } from "./posix-path.js";
19
+ export { type Err, err, mapResult, type Ok, ok, type Result, unwrap } from "./result.js";
20
+ export { SecretScrubber, secretRemoved, secretTextForms } from "./secret-scrubber.js";
21
+ export { findSecretShape, type SecretShape } from "./secret-shape.js";
22
+ export { type StopSignal, StopSource } from "./stop-signal.js";
23
+ export { slugify, uniqueName } from "./text.js";
24
+ export { decodeUtf8, encodeUtf8 } from "./utf8.js";
25
+ export { compareVersions, formatVersion, isAtLeast, readVersion, type Version } from "./version.js";
@@ -0,0 +1,26 @@
1
+ // The public API of @halonicjs/std. Everything else in src/ is internal.
2
+ export { asciiHost } from "./ascii-host.js";
3
+ export { AssertionError, assert, assertDefined, assertNever } from "./assert.js";
4
+ export { decodeBase64url, encodeBase64url } from "./base64url.js";
5
+ export { canonicalJson } from "./canonical-json.js";
6
+ export { fixedClock, fixedClockStart, systemClock } from "./clock.js";
7
+ export { constantTimeEqual } from "./constant-time.js";
8
+ export { contentDigest, matchesExpected } from "./content-digest.js";
9
+ export { deepClone } from "./deep-clone.js";
10
+ export { deepEqual } from "./deep-equal.js";
11
+ export { Emitter } from "./emitter.js";
12
+ export { errorKindOf, errorKinds, isErrorKind, KindedError, } from "./error-kind.js";
13
+ export { bytesToHex } from "./hex.js";
14
+ export { fixedIds, randomIds } from "./ids.js";
15
+ export { KeyedQueue } from "./keyed-queue.js";
16
+ export { applyLineChanges, diffLines, MAX_COMPARED_LINE_PAIRS, splitLines, } from "./line-diff.js";
17
+ export { hasConflicts, mergedText, mergeLines, } from "./line-merge.js";
18
+ export { describeObject, isPlainObject, keyPath } from "./plain-data.js";
19
+ export { posixPath } from "./posix-path.js";
20
+ export { err, mapResult, ok, unwrap } from "./result.js";
21
+ export { SecretScrubber, secretRemoved, secretTextForms } from "./secret-scrubber.js";
22
+ export { findSecretShape } from "./secret-shape.js";
23
+ export { StopSource } from "./stop-signal.js";
24
+ export { slugify, uniqueName } from "./text.js";
25
+ export { decodeUtf8, encodeUtf8 } from "./utf8.js";
26
+ export { compareVersions, formatVersion, isAtLeast, readVersion } from "./version.js";
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Runs async work one at a time per key: work for a key starts only once
3
+ * the work queued before it for the same key has settled. Work for different
4
+ * keys runs side by side. A failure goes to its own caller and doesn't stop
5
+ * the work queued after it.
6
+ *
7
+ * @example
8
+ * const queue = new KeyedQueue();
9
+ * void queue.run("run-1", () => appendToLog("a"));
10
+ * void queue.run("run-1", () => appendToLog("b")); // starts after "a" is written
11
+ */
12
+ export declare class KeyedQueue {
13
+ #private;
14
+ /** Queues `work` for `key` and gives what it returns or throws. */
15
+ run<T>(key: string, work: () => Promise<T>): Promise<T>;
16
+ /** How many keys have work queued or running. */
17
+ get busyKeys(): number;
18
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Runs async work one at a time per key: work for a key starts only once
3
+ * the work queued before it for the same key has settled. Work for different
4
+ * keys runs side by side. A failure goes to its own caller and doesn't stop
5
+ * the work queued after it.
6
+ *
7
+ * @example
8
+ * const queue = new KeyedQueue();
9
+ * void queue.run("run-1", () => appendToLog("a"));
10
+ * void queue.run("run-1", () => appendToLog("b")); // starts after "a" is written
11
+ */
12
+ export class KeyedQueue {
13
+ /** The last work queued for each key, settled or not. A key is left out once its work is done. */
14
+ #lastWork = new Map();
15
+ /** Queues `work` for `key` and gives what it returns or throws. */
16
+ run(key, work) {
17
+ const result = (this.#lastWork.get(key) ?? Promise.resolve()).then(work);
18
+ const settled = result.then(ignore, ignore);
19
+ this.#lastWork.set(key, settled);
20
+ void settled.then(() => {
21
+ if (this.#lastWork.get(key) === settled) {
22
+ this.#lastWork.delete(key);
23
+ }
24
+ });
25
+ return result;
26
+ }
27
+ /** How many keys have work queued or running. */
28
+ get busyKeys() {
29
+ return this.#lastWork.size;
30
+ }
31
+ }
32
+ function ignore() { }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * One run of changed lines between two texts: the lines `removed` from the
3
+ * text before, at `beforeStart` up to `beforeEnd`, and the lines `added` in
4
+ * their place. Line numbers count from 0. An insertion has
5
+ * `beforeStart === beforeEnd`; a deletion has no `added` lines.
6
+ *
7
+ * Each line keeps its newline, so a last line without one differs from the
8
+ * same line with one, as it does for git.
9
+ */
10
+ export interface LineChange {
11
+ /** The first line of the text before that this change replaces. */
12
+ readonly beforeStart: number;
13
+ /** The line after the last one it replaces; equals `beforeStart` for an insertion. */
14
+ readonly beforeEnd: number;
15
+ /** Where the `added` lines start in the text after. */
16
+ readonly afterStart: number;
17
+ readonly removed: readonly string[];
18
+ readonly added: readonly string[];
19
+ }
20
+ /**
21
+ * The lines of `text`, each with its newline (`\n`), so joining them gives
22
+ * the text back. A last line without a newline is kept as it is; an empty
23
+ * text has no lines.
24
+ *
25
+ * @example
26
+ * splitLines("a\nb"); // ["a\n", "b"]
27
+ */
28
+ export declare function splitLines(text: string): string[];
29
+ /**
30
+ * The most lines `diffLines` compares pair by pair: the changed lines before
31
+ * times the changed lines after. Its table takes 4 bytes a pair, so this is
32
+ * about 16 MB. Above it, the changed middle is one change.
33
+ */
34
+ export declare const MAX_COMPARED_LINE_PAIRS = 4000000;
35
+ /** Options for `diffLines`. */
36
+ export interface DiffLinesOptions {
37
+ /** The most line pairs to compare; `MAX_COMPARED_LINE_PAIRS` when left out. */
38
+ readonly maxComparedLinePairs?: number;
39
+ }
40
+ /**
41
+ * The changes that turn `before` into `after`, line by line, in order and
42
+ * never touching each other: two changes always have at least one unchanged
43
+ * line between them.
44
+ *
45
+ * The diff keeps the longest run of common lines (a longest common
46
+ * subsequence). It skips the lines both texts start and end with first, so
47
+ * the usual edit of a few lines in a long file stays cheap. The changed
48
+ * middles are then compared pair by pair, which takes time and memory in
49
+ * proportion to their line counts multiplied. When that is more than
50
+ * `MAX_COMPARED_LINE_PAIRS` (a rewrite of a generated file or a lockfile),
51
+ * the whole middle is one change instead: still a correct diff, just a
52
+ * coarse one, which shows a big rewrite as one part to take or drop.
53
+ *
54
+ * @param before - the text as it was
55
+ * @param after - the text as it is now
56
+ * @param options - the limit on pairs compared, for tests
57
+ * @returns the changes, empty when the texts are the same
58
+ *
59
+ * @example
60
+ * diffLines("a\nb\nc\n", "a\nB\nc\n");
61
+ * // [{ beforeStart: 1, beforeEnd: 2, afterStart: 1, removed: ["b\n"], added: ["B\n"] }]
62
+ */
63
+ export declare function diffLines(before: string, after: string, options?: DiffLinesOptions): LineChange[];
64
+ /**
65
+ * Applies some of the changes `diffLines(before, …)` gave back to `before`.
66
+ * The changes not passed are left out, so the text keeps its `before` lines
67
+ * there. Passing all of them gives the text after; passing none gives
68
+ * `before`.
69
+ *
70
+ * This is how one part of a diff is taken or dropped: to take only the
71
+ * second change, apply `[changes[1]]`; to drop only the second, apply every
72
+ * change but that one.
73
+ *
74
+ * @param before - the same text the changes were worked out from
75
+ * @param changes - some of those changes, in any order
76
+ * @returns the text with those changes applied
77
+ * @throws Error when two changes overlap, or a change's `removed` lines aren't
78
+ * the lines of `before` at its place (it comes from another text, or the
79
+ * text changed since)
80
+ */
81
+ export declare function applyLineChanges(before: string, changes: readonly LineChange[]): string;
82
+ /** Whether two lists have the same lines in the same order. */
83
+ export declare function sameLines(first: readonly string[], second: readonly string[]): boolean;
@@ -0,0 +1,179 @@
1
+ /**
2
+ * The lines of `text`, each with its newline (`\n`), so joining them gives
3
+ * the text back. A last line without a newline is kept as it is; an empty
4
+ * text has no lines.
5
+ *
6
+ * @example
7
+ * splitLines("a\nb"); // ["a\n", "b"]
8
+ */
9
+ export function splitLines(text) {
10
+ return text.match(/[^\n]*\n|[^\n]+$/gu) ?? [];
11
+ }
12
+ /**
13
+ * The most lines `diffLines` compares pair by pair: the changed lines before
14
+ * times the changed lines after. Its table takes 4 bytes a pair, so this is
15
+ * about 16 MB. Above it, the changed middle is one change.
16
+ */
17
+ export const MAX_COMPARED_LINE_PAIRS = 4_000_000;
18
+ /**
19
+ * The changes that turn `before` into `after`, line by line, in order and
20
+ * never touching each other: two changes always have at least one unchanged
21
+ * line between them.
22
+ *
23
+ * The diff keeps the longest run of common lines (a longest common
24
+ * subsequence). It skips the lines both texts start and end with first, so
25
+ * the usual edit of a few lines in a long file stays cheap. The changed
26
+ * middles are then compared pair by pair, which takes time and memory in
27
+ * proportion to their line counts multiplied. When that is more than
28
+ * `MAX_COMPARED_LINE_PAIRS` (a rewrite of a generated file or a lockfile),
29
+ * the whole middle is one change instead: still a correct diff, just a
30
+ * coarse one, which shows a big rewrite as one part to take or drop.
31
+ *
32
+ * @param before - the text as it was
33
+ * @param after - the text as it is now
34
+ * @param options - the limit on pairs compared, for tests
35
+ * @returns the changes, empty when the texts are the same
36
+ *
37
+ * @example
38
+ * diffLines("a\nb\nc\n", "a\nB\nc\n");
39
+ * // [{ beforeStart: 1, beforeEnd: 2, afterStart: 1, removed: ["b\n"], added: ["B\n"] }]
40
+ */
41
+ export function diffLines(before, after, options = {}) {
42
+ const beforeLines = splitLines(before);
43
+ const afterLines = splitLines(after);
44
+ const prefix = commonPrefixLength(beforeLines, afterLines);
45
+ const suffix = commonSuffixLength(beforeLines, afterLines, prefix);
46
+ const middleBefore = beforeLines.slice(prefix, beforeLines.length - suffix);
47
+ const middleAfter = afterLines.slice(prefix, afterLines.length - suffix);
48
+ const maxPairs = options.maxComparedLinePairs ?? MAX_COMPARED_LINE_PAIRS;
49
+ // No matches makes the whole middle one change.
50
+ const middle = middleBefore.length * middleAfter.length > maxPairs
51
+ ? []
52
+ : matchLines(middleBefore, middleAfter);
53
+ return collectChanges(middle, beforeLines, afterLines, prefix, suffix);
54
+ }
55
+ /**
56
+ * Applies some of the changes `diffLines(before, …)` gave back to `before`.
57
+ * The changes not passed are left out, so the text keeps its `before` lines
58
+ * there. Passing all of them gives the text after; passing none gives
59
+ * `before`.
60
+ *
61
+ * This is how one part of a diff is taken or dropped: to take only the
62
+ * second change, apply `[changes[1]]`; to drop only the second, apply every
63
+ * change but that one.
64
+ *
65
+ * @param before - the same text the changes were worked out from
66
+ * @param changes - some of those changes, in any order
67
+ * @returns the text with those changes applied
68
+ * @throws Error when two changes overlap, or a change's `removed` lines aren't
69
+ * the lines of `before` at its place (it comes from another text, or the
70
+ * text changed since)
71
+ */
72
+ export function applyLineChanges(before, changes) {
73
+ const beforeLines = splitLines(before);
74
+ const ordered = [...changes].sort((first, second) => first.beforeStart - second.beforeStart);
75
+ const out = [];
76
+ let next = 0;
77
+ for (const change of ordered) {
78
+ if (change.beforeStart < next) {
79
+ throw new Error(`applyLineChanges: the change at line ${change.beforeStart + 1} overlaps another.`);
80
+ }
81
+ if (change.beforeEnd > beforeLines.length ||
82
+ !sameLines(beforeLines.slice(change.beforeStart, change.beforeEnd), change.removed)) {
83
+ throw new Error(`applyLineChanges: the change at line ${change.beforeStart + 1} isn't from this text.`);
84
+ }
85
+ out.push(...beforeLines.slice(next, change.beforeStart), ...change.added);
86
+ next = change.beforeEnd;
87
+ }
88
+ out.push(...beforeLines.slice(next));
89
+ return out.join("");
90
+ }
91
+ /** Whether two lists have the same lines in the same order. */
92
+ export function sameLines(first, second) {
93
+ return first.length === second.length && first.every((line, index) => line === second[index]);
94
+ }
95
+ /** How many lines both lists start with. */
96
+ function commonPrefixLength(first, second) {
97
+ let length = 0;
98
+ while (length < first.length && length < second.length && first[length] === second[length]) {
99
+ length++;
100
+ }
101
+ return length;
102
+ }
103
+ /** How many lines both lists end with, not counting the first `skip` lines of either. */
104
+ function commonSuffixLength(first, second, skip) {
105
+ let length = 0;
106
+ while (length < first.length - skip &&
107
+ length < second.length - skip &&
108
+ first[first.length - 1 - length] === second[second.length - 1 - length]) {
109
+ length++;
110
+ }
111
+ return length;
112
+ }
113
+ /**
114
+ * The lines both lists keep, in order, as a longest common subsequence.
115
+ * `common(i, j)` is the length of the longest one for `first[i..]` and
116
+ * `second[j..]`, read from a table filled from the end.
117
+ */
118
+ function matchLines(first, second) {
119
+ const width = second.length + 1;
120
+ const table = new Uint32Array((first.length + 1) * width);
121
+ // Every cell read is inside the table, which starts filled with 0.
122
+ const common = (i, j) => table[i * width + j];
123
+ for (let i = first.length - 1; i >= 0; i--) {
124
+ for (let j = second.length - 1; j >= 0; j--) {
125
+ table[i * width + j] =
126
+ first[i] === second[j]
127
+ ? common(i + 1, j + 1) + 1
128
+ : Math.max(common(i + 1, j), common(i, j + 1));
129
+ }
130
+ }
131
+ const matches = [];
132
+ let i = 0;
133
+ let j = 0;
134
+ while (i < first.length && j < second.length) {
135
+ if (first[i] === second[j]) {
136
+ matches.push({ before: i, after: j });
137
+ i++;
138
+ j++;
139
+ }
140
+ else if (common(i + 1, j) >= common(i, j + 1)) {
141
+ i++;
142
+ }
143
+ else {
144
+ j++;
145
+ }
146
+ }
147
+ return matches;
148
+ }
149
+ /**
150
+ * Turns the lines the middle part keeps into changes over the whole texts.
151
+ * Every gap between two kept lines, or before the first or after the last,
152
+ * that isn't empty on both sides is one change. The middle starts at line
153
+ * `prefix` in both texts and ends where their common last lines start.
154
+ */
155
+ function collectChanges(middleMatches, beforeLines, afterLines, prefix, suffix) {
156
+ const kept = middleMatches.map((match) => ({
157
+ before: match.before + prefix,
158
+ after: match.after + prefix,
159
+ }));
160
+ // The first common last line closes the final gap; it's past the end when there is none.
161
+ kept.push({ before: beforeLines.length - suffix, after: afterLines.length - suffix });
162
+ const changes = [];
163
+ let beforeAt = prefix;
164
+ let afterAt = prefix;
165
+ for (const match of kept) {
166
+ if (match.before > beforeAt || match.after > afterAt) {
167
+ changes.push({
168
+ beforeStart: beforeAt,
169
+ beforeEnd: match.before,
170
+ afterStart: afterAt,
171
+ removed: beforeLines.slice(beforeAt, match.before),
172
+ added: afterLines.slice(afterAt, match.after),
173
+ });
174
+ }
175
+ beforeAt = match.before + 1;
176
+ afterAt = match.after + 1;
177
+ }
178
+ return changes;
179
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * One stretch of a three-way merge. `resolved` lines are settled: both sides
3
+ * kept them, or only one side changed them. A `conflict` is where both sides
4
+ * changed the same lines, or lines next to each other, differently. It holds
5
+ * those lines as they were in the base and as each side has them.
6
+ */
7
+ export type MergeRegion = {
8
+ readonly kind: "resolved";
9
+ readonly lines: readonly string[];
10
+ } | {
11
+ readonly kind: "conflict";
12
+ readonly base: readonly string[];
13
+ readonly ours: readonly string[];
14
+ readonly theirs: readonly string[];
15
+ };
16
+ /** Options for `mergeLines`. */
17
+ export interface MergeLinesOptions {
18
+ /** Whether changes that touch but don't overlap are a conflict; `true` when left out, as git. */
19
+ readonly touchingConflicts?: boolean;
20
+ }
21
+ /**
22
+ * Merges two texts that each started from `base`, line by line, as git's
23
+ * merge does. A change only one side made is taken. The same change on both
24
+ * sides is taken once. Where both sides changed the same lines differently,
25
+ * or changed lines that touch (one ends where the other starts, or both add
26
+ * lines at the same place), the result has a conflict for the caller to
27
+ * settle, with `mergedText` or by asking the person.
28
+ *
29
+ * With `touchingConflicts: false`, changes that only touch are both taken,
30
+ * because there is just one way to put them together. Only changes that
31
+ * overlap, or lines both sides add at the same place (where their order is
32
+ * unclear), are a conflict. The assistant's baseline uses this, so typing on
33
+ * the line after one of the assistant's changes keeps that change to review.
34
+ *
35
+ * @param base - the text both sides started from
36
+ * @param ours - our side
37
+ * @param theirs - their side
38
+ * @param options - whether changes that touch are a conflict (`true`, as git, when left out)
39
+ * @returns the merged text as regions in order, with resolved lines next to each other joined
40
+ *
41
+ * @example
42
+ * mergeLines("a\nb\nc\n", "A\nb\nc\n", "a\nb\nC\n");
43
+ * // [{ kind: "resolved", lines: ["A\n", "b\n", "C\n"] }]
44
+ */
45
+ export declare function mergeLines(base: string, ours: string, theirs: string, options?: MergeLinesOptions): MergeRegion[];
46
+ /**
47
+ * The text of a merge, settling each conflict by taking one side whole.
48
+ *
49
+ * @param regions - what `mergeLines` gave back
50
+ * @param onConflict - which side wins a conflict
51
+ * @returns the merged text
52
+ *
53
+ * @example
54
+ * // A person's edit inside a change the assistant made: the person's text wins.
55
+ * mergedText(mergeLines(before, baseline, after), "theirs");
56
+ */
57
+ export declare function mergedText(regions: readonly MergeRegion[], onConflict: "ours" | "theirs"): string;
58
+ /**
59
+ * Whether a merge has a conflict.
60
+ *
61
+ * @param regions - what `mergeLines` gave back
62
+ */
63
+ export declare function hasConflicts(regions: readonly MergeRegion[]): boolean;