@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,124 @@
1
+ import { isPlainObject } from "./plain-data.js";
2
+ /** What a secret value is replaced with wherever a scrubber finds it. */
3
+ export const secretRemoved = "[secret removed]";
4
+ /**
5
+ * The forms one secret commonly takes in text: as it is, URL-encoded (with
6
+ * upper- and lowercase escapes), form-encoded, and JSON-escaped (with `/`
7
+ * as it is and as `\/`). Base64, reversed, split or otherwise transformed
8
+ * copies are not here: those can't be found by matching text.
9
+ *
10
+ * Not covered either: JSON that escapes non-ASCII as `\uXXXX` (Python's
11
+ * default `json.dumps`), form-encoding with lowercase escapes, and
12
+ * URL-encoding that mixes upper- and lowercase escapes (`%2f%2F`).
13
+ *
14
+ * The forms come in the order shown, which stays the same. They can
15
+ * repeat, for example when the value has nothing to encode. An empty value
16
+ * has no forms, because an empty match is everywhere.
17
+ *
18
+ * @example
19
+ * secretTextForms("a b"); // ["a b", "a%20b", "a%20b", "a+b", "a b", "a b"]
20
+ */
21
+ export function secretTextForms(value) {
22
+ if (value === "")
23
+ return [];
24
+ // `encodeURIComponent` throws on a lone surrogate; the URL and form
25
+ // encoders of the web platform write it as U+FFFD, so do the same.
26
+ const urlEncoded = encodeURIComponent(value.toWellFormed());
27
+ const json = JSON.stringify(value).slice(1, -1);
28
+ return [
29
+ value,
30
+ urlEncoded,
31
+ urlEncoded.replace(/%[0-9A-F]{2}/g, (hex) => hex.toLowerCase()),
32
+ formEncoded(urlEncoded),
33
+ json,
34
+ json.replaceAll("/", "\\/"),
35
+ ];
36
+ }
37
+ /**
38
+ * The value as `application/x-www-form-urlencoded` writes it, as
39
+ * `URLSearchParams` does, built from its URL-encoded form: a space becomes
40
+ * `+`, and `!'()~`, which `encodeURIComponent` leaves alone, are escaped.
41
+ */
42
+ function formEncoded(urlEncoded) {
43
+ return urlEncoded
44
+ .replaceAll("%20", "+")
45
+ .replace(/[!'()~]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
46
+ }
47
+ /**
48
+ * Replaces every secret it has been told about with `[secret removed]`, in
49
+ * each form {@link secretTextForms} lists. It finds every copy of every form
50
+ * in the text as given, so copies that touch or overlap become one
51
+ * `[secret removed]` and no part of either secret is left, and a short
52
+ * secret is never found inside a marker the scrubber wrote itself.
53
+ *
54
+ * Every non-empty secret is matched, however short: a one-letter secret
55
+ * mangles the text, but leaking it would be worse. Scrub a whole text
56
+ * before splitting it into lines, so a secret that holds a line break is
57
+ * still found.
58
+ *
59
+ * @example
60
+ * const scrubber = new SecretScrubber();
61
+ * scrubber.remember(apiKey);
62
+ * scrubber.scrub(`GET /v1?key=${apiKey} failed`); // "GET /v1?key=[secret removed] failed"
63
+ */
64
+ export class SecretScrubber {
65
+ #forms = new Set();
66
+ /** Adds a secret to scrub from now on. An empty value is ignored. */
67
+ remember(value) {
68
+ for (const form of secretTextForms(value))
69
+ this.#forms.add(form);
70
+ }
71
+ /** The text with every form of every remembered secret replaced. */
72
+ scrub(text) {
73
+ const hidden = this.#hiddenCharacters(text);
74
+ let scrubbed = "";
75
+ let at = 0;
76
+ while (at < text.length) {
77
+ if (!hidden[at]) {
78
+ scrubbed += text[at];
79
+ at += 1;
80
+ continue;
81
+ }
82
+ scrubbed += secretRemoved;
83
+ while (at < text.length && hidden[at])
84
+ at += 1;
85
+ }
86
+ return scrubbed;
87
+ }
88
+ /**
89
+ * A copy of JSON-shaped data with {@link scrub} applied to every string in
90
+ * it, object keys included, at any depth. Numbers, booleans, `null` and
91
+ * anything that isn't a string, an array or a plain object are kept as
92
+ * they are. The value given is not changed.
93
+ *
94
+ * @example
95
+ * scrubber.scrubValue({ headers: [`Bearer ${token}`] }); // { headers: ["Bearer [secret removed]"] }
96
+ */
97
+ scrubValue(value) {
98
+ if (typeof value === "string")
99
+ return this.scrub(value);
100
+ if (Array.isArray(value))
101
+ return value.map((item) => this.scrubValue(item));
102
+ if (!isPlainObject(value))
103
+ return value;
104
+ const scrubbed = {};
105
+ for (const [key, item] of Object.entries(value)) {
106
+ scrubbed[this.scrub(key)] = this.scrubValue(item);
107
+ }
108
+ return scrubbed;
109
+ }
110
+ /**
111
+ * One flag per UTF-16 code unit of the text, set where any copy of any
112
+ * form covers it. Copies of one form may overlap (`aa` in `aaa`), so the
113
+ * search moves on one code unit at a time, not past the whole copy.
114
+ */
115
+ #hiddenCharacters(text) {
116
+ const hidden = new Uint8Array(text.length);
117
+ for (const form of this.#forms) {
118
+ for (let at = text.indexOf(form); at !== -1; at = text.indexOf(form, at + 1)) {
119
+ hidden.fill(1, at, at + form.length);
120
+ }
121
+ }
122
+ return hidden;
123
+ }
124
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The kinds of secret `findSecretShape` spots. Only the kind leaves the
3
+ * check, never the text that matched, so a caller can't log or keep the key
4
+ * by accident.
5
+ */
6
+ export type SecretShape = "ai-provider-key" | "google-client-secret" | "google-api-key" | "github-token" | "slack-token";
7
+ /**
8
+ * Finds text shaped like an API key or other secret, so Studio can hold a
9
+ * message before it is sent, saved or logged. The Assistant, Try it chats and
10
+ * the Inbox all ask this one check, so they spot the same formats. When the
11
+ * text holds more than one, the kind that comes first in the text wins.
12
+ *
13
+ * The answer is the kind only. When it finds something, never put the text
14
+ * in a log or an error report: the text holds the key.
15
+ *
16
+ * @example
17
+ * findSecretShape(`my key is sk-${"a".repeat(16)}`); // "ai-provider-key"
18
+ * findSecretShape("we use sk-learn for this"); // undefined
19
+ */
20
+ export declare function findSecretShape(text: string): SecretShape | undefined;
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Each pattern is a prefix at the start of a run of key characters (letters,
3
+ * digits, `-` and `_`), so `task-…` or `xGOCSPX-…` never match, followed by
4
+ * at least 16 more key characters, so words such as `sk-learn` or a prefix
5
+ * named in a sentence don't count either.
6
+ *
7
+ * The run after the prefix must also hold a digit or a capital letter.
8
+ * Lowercase slugs such as `sk-learn-tutorial-for-beginners` are long enough
9
+ * to pass the 16-character floor, but real keys are random mixed-case text
10
+ * and almost never lack both. A digit alone would miss about 1 in 140 Google
11
+ * client secrets.
12
+ *
13
+ * `sk-` covers OpenAI and Anthropic keys (`sk-proj-…`, `sk-ant-…`). `GOCSPX-`
14
+ * is a Google OAuth client secret, which Studio sends to the Google setup's
15
+ * secret field instead of the providers page.
16
+ */
17
+ const notAfterKeyCharacter = "(?<![A-Za-z0-9_-])";
18
+ const keyBody = "(?=[a-z_-]*[A-Z0-9])[A-Za-z0-9_-]{16,}";
19
+ function keyPattern(prefix) {
20
+ return new RegExp(notAfterKeyCharacter + prefix + keyBody);
21
+ }
22
+ const patterns = [
23
+ ["ai-provider-key", keyPattern("sk-")],
24
+ ["google-client-secret", keyPattern("GOCSPX-")],
25
+ ["google-api-key", keyPattern("AIza")],
26
+ ["github-token", keyPattern("(?:ghp_|github_pat_)")],
27
+ ["slack-token", keyPattern("xoxb-")],
28
+ ];
29
+ /**
30
+ * Finds text shaped like an API key or other secret, so Studio can hold a
31
+ * message before it is sent, saved or logged. The Assistant, Try it chats and
32
+ * the Inbox all ask this one check, so they spot the same formats. When the
33
+ * text holds more than one, the kind that comes first in the text wins.
34
+ *
35
+ * The answer is the kind only. When it finds something, never put the text
36
+ * in a log or an error report: the text holds the key.
37
+ *
38
+ * @example
39
+ * findSecretShape(`my key is sk-${"a".repeat(16)}`); // "ai-provider-key"
40
+ * findSecretShape("we use sk-learn for this"); // undefined
41
+ */
42
+ export function findSecretShape(text) {
43
+ let found;
44
+ let foundAt = Number.POSITIVE_INFINITY;
45
+ for (const [shape, pattern] of patterns) {
46
+ const match = pattern.exec(text);
47
+ if (match !== null && match.index < foundAt) {
48
+ found = shape;
49
+ foundAt = match.index;
50
+ }
51
+ }
52
+ return found;
53
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Tells work that it should stop, and why. It does what an `AbortSignal`
3
+ * does for code that can't create one: core packages see the Web types but
4
+ * not their values, so they have no `AbortController`.
5
+ */
6
+ export interface StopSignal {
7
+ /** Whether the work was told to stop. */
8
+ readonly stopped: boolean;
9
+ /** Why it was told to stop; `undefined` until then. */
10
+ readonly reason: Error | undefined;
11
+ /** @throws the reason, once the work was told to stop */
12
+ throwIfStopped(): void;
13
+ /**
14
+ * Calls `listener` once, when the work is told to stop, or soon after this
15
+ * returns when it already was. Returns a function that removes it; a
16
+ * listener removed during the stop, by an earlier listener, isn't called.
17
+ *
18
+ * A listener added after the stop runs outside any `stop` call, so if it
19
+ * throws, nothing catches the error: it becomes an unhandled rejection,
20
+ * which ends a Node process by default.
21
+ */
22
+ onStop(listener: () => void): () => void;
23
+ }
24
+ /**
25
+ * Gives out a {@link StopSignal} and tells it to stop.
26
+ *
27
+ * @example
28
+ * const source = new StopSource();
29
+ * void runHarness(source.signal);
30
+ * source.stop(new Error("The engine stopped."));
31
+ */
32
+ export declare class StopSource {
33
+ #private;
34
+ readonly signal: StopSignal;
35
+ constructor();
36
+ /**
37
+ * Tells the signal to stop with `reason`, and each listener once. A second
38
+ * call changes nothing.
39
+ *
40
+ * @throws the error of the one listener that threw, or an `AggregateError`
41
+ * when several did; the other listeners still run
42
+ */
43
+ stop(reason: Error): void;
44
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Gives out a {@link StopSignal} and tells it to stop.
3
+ *
4
+ * @example
5
+ * const source = new StopSource();
6
+ * void runHarness(source.signal);
7
+ * source.stop(new Error("The engine stopped."));
8
+ */
9
+ export class StopSource {
10
+ signal;
11
+ #reason;
12
+ #listeners = new Set();
13
+ constructor() {
14
+ const source = this;
15
+ this.signal = {
16
+ get stopped() {
17
+ return source.#reason !== undefined;
18
+ },
19
+ get reason() {
20
+ return source.#reason;
21
+ },
22
+ throwIfStopped() {
23
+ if (source.#reason !== undefined)
24
+ throw source.#reason;
25
+ },
26
+ onStop: (listener) => this.#onStop(listener),
27
+ };
28
+ }
29
+ /**
30
+ * Tells the signal to stop with `reason`, and each listener once. A second
31
+ * call changes nothing.
32
+ *
33
+ * @throws the error of the one listener that threw, or an `AggregateError`
34
+ * when several did; the other listeners still run
35
+ */
36
+ stop(reason) {
37
+ if (this.#reason !== undefined)
38
+ return;
39
+ this.#reason = reason;
40
+ this.#callListeners();
41
+ }
42
+ #onStop(listener) {
43
+ // Wrapped, so adding the same function twice gives two independent listeners.
44
+ const entry = () => listener();
45
+ this.#listeners.add(entry);
46
+ if (this.#reason !== undefined) {
47
+ // Called later rather than now, so the caller has its remove function
48
+ // first. A listener that throws here is an unhandled rejection.
49
+ void Promise.resolve().then(() => this.#callListeners());
50
+ }
51
+ return () => {
52
+ this.#listeners.delete(entry);
53
+ };
54
+ }
55
+ /** Calls and removes every listener, like `Emitter.emit` does with errors. */
56
+ #callListeners() {
57
+ const listeners = [...this.#listeners];
58
+ const errors = [];
59
+ for (const listener of listeners) {
60
+ // A listener that an earlier one removed is skipped, as `AbortSignal` does.
61
+ if (!this.#listeners.delete(listener))
62
+ continue;
63
+ try {
64
+ listener();
65
+ }
66
+ catch (error) {
67
+ errors.push(error);
68
+ }
69
+ }
70
+ if (errors.length === 1) {
71
+ throw errors[0];
72
+ }
73
+ if (errors.length > 1) {
74
+ throw new AggregateError(errors, `${errors.length} stop listeners failed.`);
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Turns a display name into a file-safe id: lowercase ASCII letters and digits
3
+ * joined by single hyphens. Spaces and underscores both become hyphens
4
+ * ("snake_case" becomes "snake-case"), and accents are dropped ("Café" becomes
5
+ * "cafe"), as in the old Studio. Hyphens at either end are dropped, so the id
6
+ * can't be read as a command-line flag ("_a_" becomes "a"). A name with nothing
7
+ * usable left ("___", "!!! - !!!") becomes "item".
8
+ *
9
+ * @param name - the name a person typed
10
+ * @returns the id
11
+ *
12
+ * @example
13
+ * slugify("Weekly Report"); // "weekly-report"
14
+ * slugify("Café crème!"); // "cafe-creme"
15
+ */
16
+ export declare function slugify(name: string): string;
17
+ /**
18
+ * Returns `base` when no existing name uses it, otherwise the first free
19
+ * `base-2`, `base-3` and so on.
20
+ *
21
+ * @param base - the name to start from, usually a slug
22
+ * @param taken - the names already in use
23
+ * @returns a name that isn't in `taken`
24
+ *
25
+ * @example
26
+ * uniqueName("report", ["report", "report-2"]); // "report-3"
27
+ */
28
+ export declare function uniqueName(base: string, taken: Iterable<string>): string;
@@ -0,0 +1,54 @@
1
+ /** What `slugify` returns when nothing usable is left of the name. */
2
+ const fallbackSlug = "item";
3
+ /**
4
+ * Turns a display name into a file-safe id: lowercase ASCII letters and digits
5
+ * joined by single hyphens. Spaces and underscores both become hyphens
6
+ * ("snake_case" becomes "snake-case"), and accents are dropped ("Café" becomes
7
+ * "cafe"), as in the old Studio. Hyphens at either end are dropped, so the id
8
+ * can't be read as a command-line flag ("_a_" becomes "a"). A name with nothing
9
+ * usable left ("___", "!!! - !!!") becomes "item".
10
+ *
11
+ * @param name - the name a person typed
12
+ * @returns the id
13
+ *
14
+ * @example
15
+ * slugify("Weekly Report"); // "weekly-report"
16
+ * slugify("Café crème!"); // "cafe-creme"
17
+ */
18
+ export function slugify(name) {
19
+ const slug = name
20
+ .toLowerCase()
21
+ // Splits "é" into "e" and a combining accent, which the next step removes.
22
+ .normalize("NFKD")
23
+ .replace(/[^\w\s-]/g, "")
24
+ .trim()
25
+ .replace(/[\s_]+/g, "-")
26
+ .replace(/-+/g, "-")
27
+ .replace(/^-|-$/g, "");
28
+ if (slug === "") {
29
+ return fallbackSlug;
30
+ }
31
+ return slug;
32
+ }
33
+ /**
34
+ * Returns `base` when no existing name uses it, otherwise the first free
35
+ * `base-2`, `base-3` and so on.
36
+ *
37
+ * @param base - the name to start from, usually a slug
38
+ * @param taken - the names already in use
39
+ * @returns a name that isn't in `taken`
40
+ *
41
+ * @example
42
+ * uniqueName("report", ["report", "report-2"]); // "report-3"
43
+ */
44
+ export function uniqueName(base, taken) {
45
+ const used = new Set(taken);
46
+ if (!used.has(base)) {
47
+ return base;
48
+ }
49
+ let suffix = 2;
50
+ while (used.has(`${base}-${suffix}`)) {
51
+ suffix++;
52
+ }
53
+ return `${base}-${suffix}`;
54
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Encodes text as UTF-8. A lone surrogate, which has no UTF-8 form, becomes
3
+ * U+FFFD, as `TextEncoder` does.
4
+ *
5
+ * @param text - the text to encode
6
+ * @returns the UTF-8 bytes
7
+ *
8
+ * @example
9
+ * encodeUtf8("é"); // Uint8Array [0xc3, 0xa9]
10
+ */
11
+ export declare function encodeUtf8(text: string): Uint8Array;
12
+ /**
13
+ * Decodes UTF-8 bytes as text. Each invalid sequence becomes one U+FFFD, the
14
+ * same way `TextDecoder` does it. A byte order mark at the start is dropped,
15
+ * as `TextDecoder` drops it by default.
16
+ *
17
+ * @param bytes - the bytes to decode
18
+ * @returns the text
19
+ *
20
+ * @example
21
+ * decodeUtf8(new Uint8Array([0xc3, 0xa9])); // "é"
22
+ */
23
+ export declare function decodeUtf8(bytes: Uint8Array): string;
@@ -0,0 +1,110 @@
1
+ // The core has no TextEncoder or TextDecoder (they come from the DOM and Node
2
+ // type libraries, which the core doesn't load), so UTF-8 is written here. Both
3
+ // directions follow the WHATWG Encoding Standard, so they give exactly the same
4
+ // bytes and text as TextEncoder and TextDecoder.
5
+ /** U+FFFD, written in place of anything that isn't valid. */
6
+ const replacementCharacter = 0xfffd;
7
+ /**
8
+ * Encodes text as UTF-8. A lone surrogate, which has no UTF-8 form, becomes
9
+ * U+FFFD, as `TextEncoder` does.
10
+ *
11
+ * @param text - the text to encode
12
+ * @returns the UTF-8 bytes
13
+ *
14
+ * @example
15
+ * encodeUtf8("é"); // Uint8Array [0xc3, 0xa9]
16
+ */
17
+ export function encodeUtf8(text) {
18
+ const bytes = [];
19
+ for (const character of text) {
20
+ // for…of walks code points, so a valid surrogate pair arrives as one.
21
+ let codePoint = character.codePointAt(0) ?? replacementCharacter;
22
+ if (codePoint >= 0xd800 && codePoint <= 0xdfff) {
23
+ codePoint = replacementCharacter;
24
+ }
25
+ if (codePoint < 0x80) {
26
+ bytes.push(codePoint);
27
+ }
28
+ else if (codePoint < 0x800) {
29
+ bytes.push(0xc0 | (codePoint >> 6), 0x80 | (codePoint & 0x3f));
30
+ }
31
+ else if (codePoint < 0x10000) {
32
+ bytes.push(0xe0 | (codePoint >> 12), 0x80 | ((codePoint >> 6) & 0x3f), 0x80 | (codePoint & 0x3f));
33
+ }
34
+ else {
35
+ bytes.push(0xf0 | (codePoint >> 18), 0x80 | ((codePoint >> 12) & 0x3f), 0x80 | ((codePoint >> 6) & 0x3f), 0x80 | (codePoint & 0x3f));
36
+ }
37
+ }
38
+ return Uint8Array.from(bytes);
39
+ }
40
+ /**
41
+ * Decodes UTF-8 bytes as text. Each invalid sequence becomes one U+FFFD, the
42
+ * same way `TextDecoder` does it. A byte order mark at the start is dropped,
43
+ * as `TextDecoder` drops it by default.
44
+ *
45
+ * @param bytes - the bytes to decode
46
+ * @returns the text
47
+ *
48
+ * @example
49
+ * decodeUtf8(new Uint8Array([0xc3, 0xa9])); // "é"
50
+ */
51
+ export function decodeUtf8(bytes) {
52
+ const codePoints = [];
53
+ let index = startsWithByteOrderMark(bytes) ? 3 : 0;
54
+ while (index < bytes.length) {
55
+ const sequence = readSequence(bytes, index);
56
+ codePoints.push(sequence.codePoint);
57
+ index += sequence.length;
58
+ }
59
+ let text = "";
60
+ // In chunks, because String.fromCodePoint takes its arguments on the stack.
61
+ const chunkSize = 8192;
62
+ for (let start = 0; start < codePoints.length; start += chunkSize) {
63
+ text += String.fromCodePoint(...codePoints.slice(start, start + chunkSize));
64
+ }
65
+ return text;
66
+ }
67
+ function startsWithByteOrderMark(bytes) {
68
+ return bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf;
69
+ }
70
+ /** Reads the sequence that starts at `start`, following the WHATWG UTF-8 decoder. */
71
+ function readSequence(bytes, start) {
72
+ const lead = bytes[start] ?? 0;
73
+ if (lead < 0x80) {
74
+ return { codePoint: lead, length: 1 };
75
+ }
76
+ const shape = sequenceShape(lead);
77
+ if (shape === undefined) {
78
+ return { codePoint: replacementCharacter, length: 1 };
79
+ }
80
+ let codePoint = lead & shape.leadMask;
81
+ let lower = shape.secondLower;
82
+ let upper = shape.secondUpper;
83
+ for (let offset = 1; offset < shape.length; offset++) {
84
+ const next = bytes[start + offset];
85
+ if (next === undefined || next < lower || next > upper) {
86
+ // The bytes read so far are one invalid sequence; `next` starts a new one.
87
+ return { codePoint: replacementCharacter, length: offset };
88
+ }
89
+ codePoint = (codePoint << 6) | (next & 0x3f);
90
+ lower = 0x80;
91
+ upper = 0xbf;
92
+ }
93
+ return { codePoint, length: shape.length };
94
+ }
95
+ function sequenceShape(lead) {
96
+ if (lead >= 0xc2 && lead <= 0xdf) {
97
+ return { length: 2, leadMask: 0x1f, secondLower: 0x80, secondUpper: 0xbf };
98
+ }
99
+ if (lead >= 0xe0 && lead <= 0xef) {
100
+ const secondLower = lead === 0xe0 ? 0xa0 : 0x80;
101
+ const secondUpper = lead === 0xed ? 0x9f : 0xbf;
102
+ return { length: 3, leadMask: 0x0f, secondLower, secondUpper };
103
+ }
104
+ if (lead >= 0xf0 && lead <= 0xf4) {
105
+ const secondLower = lead === 0xf0 ? 0x90 : 0x80;
106
+ const secondUpper = lead === 0xf4 ? 0x8f : 0xbf;
107
+ return { length: 4, leadMask: 0x07, secondLower, secondUpper };
108
+ }
109
+ return undefined;
110
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * A version in semver's form, such as 0.169.0-alpha.6: three numbers and
3
+ * the pieces of an optional pre-release part. A build part (`+…`) is read
4
+ * but not kept, because it never changes the order.
5
+ */
6
+ export interface Version {
7
+ readonly major: number;
8
+ readonly minor: number;
9
+ readonly patch: number;
10
+ /** The pre-release pieces, such as `["alpha", 6]`; empty for a release. */
11
+ readonly prerelease: readonly (string | number)[];
12
+ }
13
+ /**
14
+ * Reads a version from text that is nothing but the version. Finding it in a
15
+ * program's output, such as "codex-cli 0.167.0", is the caller's part.
16
+ *
17
+ * @param text - the version, such as "0.169.0-alpha.6"
18
+ * @returns the version, or `undefined` when the text is anything else
19
+ *
20
+ * @example
21
+ * readVersion("0.169.0-alpha.6"); // { major: 0, minor: 169, patch: 0, prerelease: ["alpha", 6] }
22
+ * readVersion("v0.169.0"); // undefined
23
+ */
24
+ export declare function readVersion(text: string): Version | undefined;
25
+ /**
26
+ * Writes a version the usual way, such as "0.169.0-alpha.6".
27
+ *
28
+ * @example
29
+ * formatVersion({ major: 2, minor: 1, patch: 321, prerelease: [] }); // "2.1.321"
30
+ */
31
+ export declare function formatVersion(version: Version): string;
32
+ /**
33
+ * Compares two versions in semver's order.
34
+ *
35
+ * @returns a negative number when `a` comes first, a positive one when `b`
36
+ * does, and 0 when they are equal
37
+ *
38
+ * @example
39
+ * compareVersions(readVersion("0.167.0-alpha.6")!, readVersion("0.167.0")!); // negative
40
+ */
41
+ export declare function compareVersions(a: Version, b: Version): number;
42
+ /**
43
+ * Whether `version` is `minimum` or newer.
44
+ *
45
+ * @example
46
+ * isAtLeast(readVersion("0.167.0")!, readVersion("0.166.0")!); // true
47
+ */
48
+ export declare function isAtLeast(version: Version, minimum: Version): boolean;