@halonicjs/testing 0.0.0 → 0.1.1

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 (438) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +41 -1
  4. package/dist/adapters/http-kit/src/address-checking.d.ts +19 -0
  5. package/dist/adapters/http-kit/src/address-checking.js +1 -0
  6. package/dist/adapters/http-kit/src/address-class.d.ts +34 -0
  7. package/dist/adapters/http-kit/src/address-class.js +109 -0
  8. package/dist/adapters/http-kit/src/index.d.ts +3 -0
  9. package/dist/adapters/http-kit/src/index.js +2 -0
  10. package/dist/adapters/http-kit/src/ip-address.d.ts +23 -0
  11. package/dist/adapters/http-kit/src/ip-address.js +89 -0
  12. package/dist/adapters/integration-kit/src/auth-placement.d.ts +40 -0
  13. package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
  14. package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
  15. package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
  16. package/dist/adapters/integration-kit/src/declaration.d.ts +15 -0
  17. package/dist/adapters/integration-kit/src/declaration.js +78 -0
  18. package/dist/adapters/integration-kit/src/host.d.ts +34 -0
  19. package/dist/adapters/integration-kit/src/host.js +31 -0
  20. package/dist/adapters/integration-kit/src/index.d.ts +16 -0
  21. package/dist/adapters/integration-kit/src/index.js +22 -0
  22. package/dist/adapters/integration-kit/src/leak-attempt.d.ts +16 -0
  23. package/dist/adapters/integration-kit/src/leak-attempt.js +19 -0
  24. package/dist/adapters/integration-kit/src/limited-http.d.ts +55 -0
  25. package/dist/adapters/integration-kit/src/limited-http.js +225 -0
  26. package/dist/adapters/integration-kit/src/load-problem.d.ts +20 -0
  27. package/dist/adapters/integration-kit/src/load-problem.js +1 -0
  28. package/dist/adapters/integration-kit/src/loader.d.ts +131 -0
  29. package/dist/adapters/integration-kit/src/loader.js +251 -0
  30. package/dist/adapters/integration-kit/src/local-address.d.ts +15 -0
  31. package/dist/adapters/integration-kit/src/local-address.js +25 -0
  32. package/dist/adapters/integration-kit/src/own-request.d.ts +33 -0
  33. package/dist/adapters/integration-kit/src/own-request.js +36 -0
  34. package/dist/adapters/integration-kit/src/plugin-load.d.ts +14 -0
  35. package/dist/adapters/integration-kit/src/plugin-load.js +58 -0
  36. package/dist/adapters/integration-kit/src/policy.d.ts +83 -0
  37. package/dist/adapters/integration-kit/src/policy.js +37 -0
  38. package/dist/adapters/integration-kit/src/request-body.d.ts +38 -0
  39. package/dist/adapters/integration-kit/src/request-body.js +68 -0
  40. package/dist/adapters/integration-kit/src/request-log.d.ts +25 -0
  41. package/dist/adapters/integration-kit/src/request-log.js +17 -0
  42. package/dist/adapters/integration-kit/src/response-body.d.ts +27 -0
  43. package/dist/adapters/integration-kit/src/response-body.js +117 -0
  44. package/dist/adapters/integration-kit/src/scoped-tokens.d.ts +14 -0
  45. package/dist/adapters/integration-kit/src/scoped-tokens.js +27 -0
  46. package/dist/adapters/integration-kit/src/secret-filter.d.ts +84 -0
  47. package/dist/adapters/integration-kit/src/secret-filter.js +220 -0
  48. package/dist/adapters/integration-kit/src/secret-in-request.d.ts +62 -0
  49. package/dist/adapters/integration-kit/src/secret-in-request.js +139 -0
  50. package/dist/adapters/integration-kit/src/secret-placement.d.ts +46 -0
  51. package/dist/adapters/integration-kit/src/secret-placement.js +160 -0
  52. package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
  53. package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
  54. package/dist/adapters/integration-kit/src/wait.d.ts +16 -0
  55. package/dist/adapters/integration-kit/src/wait.js +35 -0
  56. package/dist/core/events/src/add-usage.d.ts +10 -0
  57. package/dist/core/events/src/add-usage.js +27 -0
  58. package/dist/core/events/src/agent-resume.d.ts +24 -0
  59. package/dist/core/events/src/agent-resume.js +1 -0
  60. package/dist/core/events/src/blocked-sites.d.ts +57 -0
  61. package/dist/core/events/src/blocked-sites.js +89 -0
  62. package/dist/core/events/src/home-path.d.ts +13 -0
  63. package/dist/core/events/src/home-path.js +26 -0
  64. package/dist/core/events/src/index.d.ts +17 -0
  65. package/dist/core/events/src/index.js +10 -0
  66. package/dist/core/events/src/run-basics.d.ts +228 -0
  67. package/dist/core/events/src/run-basics.js +1 -0
  68. package/dist/core/events/src/run-event.d.ts +478 -0
  69. package/dist/core/events/src/run-event.js +1 -0
  70. package/dist/core/events/src/run-reads.d.ts +25 -0
  71. package/dist/core/events/src/run-reads.js +44 -0
  72. package/dist/core/events/src/run-sends.d.ts +47 -0
  73. package/dist/core/events/src/run-sends.js +68 -0
  74. package/dist/core/events/src/run-summary.d.ts +108 -0
  75. package/dist/core/events/src/run-summary.js +1 -0
  76. package/dist/core/events/src/sandbox-blocked.d.ts +42 -0
  77. package/dist/core/events/src/sandbox-blocked.js +26 -0
  78. package/dist/core/events/src/sandbox-opened-read.d.ts +17 -0
  79. package/dist/core/events/src/sandbox-opened-read.js +63 -0
  80. package/dist/core/events/src/sandbox-opened.d.ts +94 -0
  81. package/dist/core/events/src/sandbox-opened.js +52 -0
  82. package/dist/core/events/src/summarize.d.ts +14 -0
  83. package/dist/core/events/src/summarize.js +192 -0
  84. package/dist/core/events/src/timeline-entry.d.ts +21 -0
  85. package/dist/core/events/src/timeline-entry.js +106 -0
  86. package/dist/core/events/src/upgrade.d.ts +23 -0
  87. package/dist/core/events/src/upgrade.js +49 -0
  88. package/dist/core/format/src/compact.d.ts +30 -0
  89. package/dist/core/format/src/compact.js +72 -0
  90. package/dist/core/format/src/index.d.ts +39 -0
  91. package/dist/core/format/src/index.js +25 -0
  92. package/dist/core/format/src/integration/index.d.ts +7 -0
  93. package/dist/core/format/src/integration/index.js +10 -0
  94. package/dist/core/format/src/json-schema.d.ts +26 -0
  95. package/dist/core/format/src/json-schema.js +48 -0
  96. package/dist/core/format/src/kind.d.ts +65 -0
  97. package/dist/core/format/src/kind.js +1 -0
  98. package/dist/core/format/src/kinds/agent/kind.d.ts +4 -0
  99. package/dist/core/format/src/kinds/agent/kind.js +10 -0
  100. package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +99 -0
  101. package/dist/core/format/src/kinds/agent/sandbox-fields.js +216 -0
  102. package/dist/core/format/src/kinds/agent/schema.d.ts +147 -0
  103. package/dist/core/format/src/kinds/agent/schema.js +107 -0
  104. package/dist/core/format/src/kinds/agent/working-folder-start.d.ts +74 -0
  105. package/dist/core/format/src/kinds/agent/working-folder-start.js +312 -0
  106. package/dist/core/format/src/kinds/collection/kind.d.ts +8 -0
  107. package/dist/core/format/src/kinds/collection/kind.js +14 -0
  108. package/dist/core/format/src/kinds/collection/schema.d.ts +89 -0
  109. package/dist/core/format/src/kinds/collection/schema.js +90 -0
  110. package/dist/core/format/src/kinds/connector/is-local.d.ts +10 -0
  111. package/dist/core/format/src/kinds/connector/is-local.js +43 -0
  112. package/dist/core/format/src/kinds/connector/kind.d.ts +4 -0
  113. package/dist/core/format/src/kinds/connector/kind.js +218 -0
  114. package/dist/core/format/src/kinds/connector/schema.d.ts +74 -0
  115. package/dist/core/format/src/kinds/connector/schema.js +143 -0
  116. package/dist/core/format/src/kinds/deployments/kind.d.ts +4 -0
  117. package/dist/core/format/src/kinds/deployments/kind.js +49 -0
  118. package/dist/core/format/src/kinds/deployments/schema.d.ts +77 -0
  119. package/dist/core/format/src/kinds/deployments/schema.js +94 -0
  120. package/dist/core/format/src/kinds/hub/kind.d.ts +4 -0
  121. package/dist/core/format/src/kinds/hub/kind.js +10 -0
  122. package/dist/core/format/src/kinds/hub/schema.d.ts +54 -0
  123. package/dist/core/format/src/kinds/hub/schema.js +34 -0
  124. package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
  125. package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
  126. package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
  127. package/dist/core/format/src/kinds/integration/host-key.js +8 -0
  128. package/dist/core/format/src/kinds/integration/kind.d.ts +18 -0
  129. package/dist/core/format/src/kinds/integration/kind.js +175 -0
  130. package/dist/core/format/src/kinds/integration/parse-sheet.d.ts +19 -0
  131. package/dist/core/format/src/kinds/integration/parse-sheet.js +24 -0
  132. package/dist/core/format/src/kinds/integration/policy.d.ts +112 -0
  133. package/dist/core/format/src/kinds/integration/policy.js +327 -0
  134. package/dist/core/format/src/kinds/integration/schema.d.ts +410 -0
  135. package/dist/core/format/src/kinds/integration/schema.js +359 -0
  136. package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +13 -0
  137. package/dist/core/format/src/kinds/integration/sign-in-checks.js +120 -0
  138. package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
  139. package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
  140. package/dist/core/format/src/kinds/knowledge/kind.d.ts +4 -0
  141. package/dist/core/format/src/kinds/knowledge/kind.js +13 -0
  142. package/dist/core/format/src/kinds/knowledge/schema.d.ts +18 -0
  143. package/dist/core/format/src/kinds/knowledge/schema.js +25 -0
  144. package/dist/core/format/src/kinds/models/kind.d.ts +4 -0
  145. package/dist/core/format/src/kinds/models/kind.js +10 -0
  146. package/dist/core/format/src/kinds/models/schema.d.ts +92 -0
  147. package/dist/core/format/src/kinds/models/schema.js +38 -0
  148. package/dist/core/format/src/kinds/plugin/backend.d.ts +22 -0
  149. package/dist/core/format/src/kinds/plugin/backend.js +31 -0
  150. package/dist/core/format/src/kinds/plugin/checks.d.ts +13 -0
  151. package/dist/core/format/src/kinds/plugin/checks.js +137 -0
  152. package/dist/core/format/src/kinds/plugin/kind.d.ts +8 -0
  153. package/dist/core/format/src/kinds/plugin/kind.js +16 -0
  154. package/dist/core/format/src/kinds/plugin/problems.d.ts +24 -0
  155. package/dist/core/format/src/kinds/plugin/problems.js +65 -0
  156. package/dist/core/format/src/kinds/plugin/schema.d.ts +672 -0
  157. package/dist/core/format/src/kinds/plugin/schema.js +261 -0
  158. package/dist/core/format/src/kinds/plugin/setting-values.d.ts +17 -0
  159. package/dist/core/format/src/kinds/plugin/setting-values.js +38 -0
  160. package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +8 -0
  161. package/dist/core/format/src/kinds/plugin/ui-checks.js +85 -0
  162. package/dist/core/format/src/kinds/provider/kind.d.ts +4 -0
  163. package/dist/core/format/src/kinds/provider/kind.js +24 -0
  164. package/dist/core/format/src/kinds/provider/schema.d.ts +17 -0
  165. package/dist/core/format/src/kinds/provider/schema.js +22 -0
  166. package/dist/core/format/src/kinds/routine/kind.d.ts +8 -0
  167. package/dist/core/format/src/kinds/routine/kind.js +62 -0
  168. package/dist/core/format/src/kinds/routine/schema.d.ts +94 -0
  169. package/dist/core/format/src/kinds/routine/schema.js +115 -0
  170. package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
  171. package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
  172. package/dist/core/format/src/kinds/runtime/kind.d.ts +4 -0
  173. package/dist/core/format/src/kinds/runtime/kind.js +13 -0
  174. package/dist/core/format/src/kinds/runtime/schema.d.ts +10 -0
  175. package/dist/core/format/src/kinds/runtime/schema.js +12 -0
  176. package/dist/core/format/src/kinds/skill/kind.d.ts +4 -0
  177. package/dist/core/format/src/kinds/skill/kind.js +10 -0
  178. package/dist/core/format/src/kinds/skill/schema.d.ts +17 -0
  179. package/dist/core/format/src/kinds/skill/schema.js +17 -0
  180. package/dist/core/format/src/kinds/skill/scripts-folder.d.ts +27 -0
  181. package/dist/core/format/src/kinds/skill/scripts-folder.js +37 -0
  182. package/dist/core/format/src/kinds/workflow/kind.d.ts +8 -0
  183. package/dist/core/format/src/kinds/workflow/kind.js +14 -0
  184. package/dist/core/format/src/kinds/workflow/schema.d.ts +162 -0
  185. package/dist/core/format/src/kinds/workflow/schema.js +106 -0
  186. package/dist/core/format/src/kinds/workflow-test/kind.d.ts +4 -0
  187. package/dist/core/format/src/kinds/workflow-test/kind.js +14 -0
  188. package/dist/core/format/src/kinds/workflow-test/schema.d.ts +67 -0
  189. package/dist/core/format/src/kinds/workflow-test/schema.js +59 -0
  190. package/dist/core/format/src/kinds/workspace/kind.d.ts +4 -0
  191. package/dist/core/format/src/kinds/workspace/kind.js +10 -0
  192. package/dist/core/format/src/kinds/workspace/schema.d.ts +72 -0
  193. package/dist/core/format/src/kinds/workspace/schema.js +66 -0
  194. package/dist/core/format/src/parse-file.d.ts +69 -0
  195. package/dist/core/format/src/parse-file.js +105 -0
  196. package/dist/core/format/src/recording/format.d.ts +81 -0
  197. package/dist/core/format/src/recording/format.js +102 -0
  198. package/dist/core/format/src/recording/index.d.ts +1 -0
  199. package/dist/core/format/src/recording/index.js +3 -0
  200. package/dist/core/format/src/registry.d.ts +64 -0
  201. package/dist/core/format/src/registry.js +61 -0
  202. package/dist/core/format/src/reserved.d.ts +20 -0
  203. package/dist/core/format/src/reserved.js +30 -0
  204. package/dist/core/format/src/shared/fields.d.ts +34 -0
  205. package/dist/core/format/src/shared/fields.js +74 -0
  206. package/dist/core/format/src/shared/guard.d.ts +32 -0
  207. package/dist/core/format/src/shared/guard.js +16 -0
  208. package/dist/core/format/src/shared/key-in-value.d.ts +28 -0
  209. package/dist/core/format/src/shared/key-in-value.js +82 -0
  210. package/dist/core/format/src/shared/legacy-keys.d.ts +8 -0
  211. package/dist/core/format/src/shared/legacy-keys.js +17 -0
  212. package/dist/core/format/src/shared/program-start.d.ts +60 -0
  213. package/dist/core/format/src/shared/program-start.js +99 -0
  214. package/dist/core/format/src/shared/relative-path.d.ts +29 -0
  215. package/dist/core/format/src/shared/relative-path.js +50 -0
  216. package/dist/core/format/src/shared/secret-name.d.ts +24 -0
  217. package/dist/core/format/src/shared/secret-name.js +107 -0
  218. package/dist/core/format/src/source.d.ts +16 -0
  219. package/dist/core/format/src/source.js +73 -0
  220. package/dist/core/ports/src/agent-placement-store.d.ts +74 -0
  221. package/dist/core/ports/src/agent-placement-store.js +27 -0
  222. package/dist/core/ports/src/agent-runs-not-available.d.ts +21 -0
  223. package/dist/core/ports/src/agent-runs-not-available.js +25 -0
  224. package/dist/core/ports/src/blob-store.d.ts +45 -0
  225. package/dist/core/ports/src/blob-store.js +24 -0
  226. package/dist/core/ports/src/cant-try-error.d.ts +35 -0
  227. package/dist/core/ports/src/cant-try-error.js +44 -0
  228. package/dist/core/ports/src/chat.d.ts +127 -0
  229. package/dist/core/ports/src/chat.js +1 -0
  230. package/dist/core/ports/src/clock.d.ts +7 -0
  231. package/dist/core/ports/src/clock.js +2 -0
  232. package/dist/core/ports/src/connection-settings-store.d.ts +57 -0
  233. package/dist/core/ports/src/connection-settings-store.js +2 -0
  234. package/dist/core/ports/src/connector-client.d.ts +303 -0
  235. package/dist/core/ports/src/connector-client.js +19 -0
  236. package/dist/core/ports/src/coordination.d.ts +84 -0
  237. package/dist/core/ports/src/coordination.js +2 -0
  238. package/dist/core/ports/src/definition-store.d.ts +229 -0
  239. package/dist/core/ports/src/definition-store.js +122 -0
  240. package/dist/core/ports/src/digest.d.ts +14 -0
  241. package/dist/core/ports/src/digest.js +2 -0
  242. package/dist/core/ports/src/folder-reader.d.ts +89 -0
  243. package/dist/core/ports/src/folder-reader.js +2 -0
  244. package/dist/core/ports/src/harness-bridge-server.d.ts +198 -0
  245. package/dist/core/ports/src/harness-bridge-server.js +37 -0
  246. package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
  247. package/dist/core/ports/src/harness-sign-in-command.js +31 -0
  248. package/dist/core/ports/src/harness.d.ts +283 -0
  249. package/dist/core/ports/src/harness.js +45 -0
  250. package/dist/core/ports/src/host-settings-store.d.ts +116 -0
  251. package/dist/core/ports/src/host-settings-store.js +106 -0
  252. package/dist/core/ports/src/http-client.d.ts +27 -0
  253. package/dist/core/ports/src/http-client.js +2 -0
  254. package/dist/core/ports/src/id-generator.d.ts +14 -0
  255. package/dist/core/ports/src/id-generator.js +2 -0
  256. package/dist/core/ports/src/index.d.ts +45 -0
  257. package/dist/core/ports/src/index.js +44 -0
  258. package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
  259. package/dist/core/ports/src/instruction-trust-store.js +43 -0
  260. package/dist/core/ports/src/integration.d.ts +242 -0
  261. package/dist/core/ports/src/integration.js +31 -0
  262. package/dist/core/ports/src/knowledge-provider.d.ts +65 -0
  263. package/dist/core/ports/src/knowledge-provider.js +2 -0
  264. package/dist/core/ports/src/llm-cache.d.ts +13 -0
  265. package/dist/core/ports/src/llm-cache.js +2 -0
  266. package/dist/core/ports/src/llm-provider.d.ts +186 -0
  267. package/dist/core/ports/src/llm-provider.js +139 -0
  268. package/dist/core/ports/src/model-price.d.ts +34 -0
  269. package/dist/core/ports/src/model-price.js +25 -0
  270. package/dist/core/ports/src/password-hasher.d.ts +63 -0
  271. package/dist/core/ports/src/password-hasher.js +2 -0
  272. package/dist/core/ports/src/plugin-folder-writer.d.ts +104 -0
  273. package/dist/core/ports/src/plugin-folder-writer.js +95 -0
  274. package/dist/core/ports/src/port-versions.d.ts +47 -0
  275. package/dist/core/ports/src/port-versions.js +80 -0
  276. package/dist/core/ports/src/program-probe.d.ts +69 -0
  277. package/dist/core/ports/src/program-probe.js +2 -0
  278. package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
  279. package/dist/core/ports/src/provider-default-base-url.js +18 -0
  280. package/dist/core/ports/src/record-store.d.ts +79 -0
  281. package/dist/core/ports/src/record-store.js +108 -0
  282. package/dist/core/ports/src/resource-probe.d.ts +59 -0
  283. package/dist/core/ports/src/resource-probe.js +2 -0
  284. package/dist/core/ports/src/run-executor.d.ts +303 -0
  285. package/dist/core/ports/src/run-executor.js +2 -0
  286. package/dist/core/ports/src/run-failure-error.d.ts +49 -0
  287. package/dist/core/ports/src/run-failure-error.js +47 -0
  288. package/dist/core/ports/src/run-store.d.ts +194 -0
  289. package/dist/core/ports/src/run-store.js +131 -0
  290. package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
  291. package/dist/core/ports/src/run-target-not-found.js +41 -0
  292. package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
  293. package/dist/core/ports/src/sandbox-setting-store.js +33 -0
  294. package/dist/core/ports/src/sandbox.d.ts +364 -0
  295. package/dist/core/ports/src/sandbox.js +70 -0
  296. package/dist/core/ports/src/scheduler.d.ts +85 -0
  297. package/dist/core/ports/src/scheduler.js +2 -0
  298. package/dist/core/ports/src/secrets.d.ts +201 -0
  299. package/dist/core/ports/src/secrets.js +200 -0
  300. package/dist/core/ports/src/token-store.d.ts +19 -0
  301. package/dist/core/ports/src/token-store.js +2 -0
  302. package/dist/core/ports/src/tool-approval-store.d.ts +253 -0
  303. package/dist/core/ports/src/tool-approval-store.js +116 -0
  304. package/dist/core/ports/src/trust-store.d.ts +72 -0
  305. package/dist/core/ports/src/trust-store.js +2 -0
  306. package/dist/core/ports/src/unfenced-run-consent-store.d.ts +43 -0
  307. package/dist/core/ports/src/unfenced-run-consent-store.js +2 -0
  308. package/dist/core/ports/src/vcs-status.d.ts +8 -0
  309. package/dist/core/ports/src/vcs-status.js +90 -0
  310. package/dist/core/ports/src/vcs.d.ts +394 -0
  311. package/dist/core/ports/src/vcs.js +48 -0
  312. package/dist/core/schema-kit/src/builders.d.ts +50 -0
  313. package/dist/core/schema-kit/src/builders.js +72 -0
  314. package/dist/core/schema-kit/src/depth.d.ts +15 -0
  315. package/dist/core/schema-kit/src/depth.js +37 -0
  316. package/dist/core/schema-kit/src/index.d.ts +6 -0
  317. package/dist/core/schema-kit/src/index.js +6 -0
  318. package/dist/core/schema-kit/src/issue.d.ts +22 -0
  319. package/dist/core/schema-kit/src/issue.js +23 -0
  320. package/dist/core/schema-kit/src/json-schema.d.ts +23 -0
  321. package/dist/core/schema-kit/src/json-schema.js +22 -0
  322. package/dist/core/schema-kit/src/parse.d.ts +17 -0
  323. package/dist/core/schema-kit/src/parse.js +25 -0
  324. package/dist/core/schema-kit/src/schema.d.ts +12 -0
  325. package/dist/core/schema-kit/src/schema.js +1 -0
  326. package/dist/core/std/src/amount.d.ts +13 -0
  327. package/dist/core/std/src/amount.js +22 -0
  328. package/dist/core/std/src/ascii-host.d.ts +18 -0
  329. package/dist/core/std/src/ascii-host.js +110 -0
  330. package/dist/core/std/src/assert.d.ts +39 -0
  331. package/dist/core/std/src/assert.js +59 -0
  332. package/dist/core/std/src/base64url.d.ts +23 -0
  333. package/dist/core/std/src/base64url.js +65 -0
  334. package/dist/core/std/src/canonical-json.d.ts +18 -0
  335. package/dist/core/std/src/canonical-json.js +56 -0
  336. package/dist/core/std/src/clock.d.ts +27 -0
  337. package/dist/core/std/src/clock.js +33 -0
  338. package/dist/core/std/src/constant-time.d.ts +16 -0
  339. package/dist/core/std/src/constant-time.js +26 -0
  340. package/dist/core/std/src/content-digest.d.ts +24 -0
  341. package/dist/core/std/src/content-digest.js +28 -0
  342. package/dist/core/std/src/deep-clone.d.ts +15 -0
  343. package/dist/core/std/src/deep-clone.js +59 -0
  344. package/dist/core/std/src/deep-equal.d.ts +23 -0
  345. package/dist/core/std/src/deep-equal.js +64 -0
  346. package/dist/core/std/src/emitter.d.ts +42 -0
  347. package/dist/core/std/src/emitter.js +74 -0
  348. package/dist/core/std/src/error-kind.d.ts +88 -0
  349. package/dist/core/std/src/error-kind.js +98 -0
  350. package/dist/core/std/src/hex.d.ts +10 -0
  351. package/dist/core/std/src/hex.js +16 -0
  352. package/dist/core/std/src/hidden-characters.d.ts +19 -0
  353. package/dist/core/std/src/hidden-characters.js +54 -0
  354. package/dist/core/std/src/ids.d.ts +45 -0
  355. package/dist/core/std/src/ids.js +49 -0
  356. package/dist/core/std/src/index.d.ts +30 -0
  357. package/dist/core/std/src/index.js +31 -0
  358. package/dist/core/std/src/keyed-queue.d.ts +18 -0
  359. package/dist/core/std/src/keyed-queue.js +32 -0
  360. package/dist/core/std/src/line-diff.d.ts +83 -0
  361. package/dist/core/std/src/line-diff.js +179 -0
  362. package/dist/core/std/src/line-merge.d.ts +63 -0
  363. package/dist/core/std/src/line-merge.js +138 -0
  364. package/dist/core/std/src/plain-data.d.ts +32 -0
  365. package/dist/core/std/src/plain-data.js +57 -0
  366. package/dist/core/std/src/posix-path.d.ts +61 -0
  367. package/dist/core/std/src/posix-path.js +121 -0
  368. package/dist/core/std/src/public-suffixes.generated.d.ts +9 -0
  369. package/dist/core/std/src/public-suffixes.generated.js +10429 -0
  370. package/dist/core/std/src/registrable-domain.d.ts +10 -0
  371. package/dist/core/std/src/registrable-domain.js +62 -0
  372. package/dist/core/std/src/result.d.ts +55 -0
  373. package/dist/core/std/src/result.js +52 -0
  374. package/dist/core/std/src/secret-scrubber.d.ts +54 -0
  375. package/dist/core/std/src/secret-scrubber.js +124 -0
  376. package/dist/core/std/src/secret-shape.d.ts +20 -0
  377. package/dist/core/std/src/secret-shape.js +53 -0
  378. package/dist/core/std/src/secret-variable-name.d.ts +12 -0
  379. package/dist/core/std/src/secret-variable-name.js +34 -0
  380. package/dist/core/std/src/site-name.d.ts +35 -0
  381. package/dist/core/std/src/site-name.js +111 -0
  382. package/dist/core/std/src/stop-signal.d.ts +44 -0
  383. package/dist/core/std/src/stop-signal.js +77 -0
  384. package/dist/core/std/src/text.d.ts +28 -0
  385. package/dist/core/std/src/text.js +54 -0
  386. package/dist/core/std/src/url-host.d.ts +35 -0
  387. package/dist/core/std/src/url-host.js +170 -0
  388. package/dist/core/std/src/utf8.d.ts +23 -0
  389. package/dist/core/std/src/utf8.js +110 -0
  390. package/dist/core/std/src/version.d.ts +48 -0
  391. package/dist/core/std/src/version.js +103 -0
  392. package/dist/core/yaml/src/depth.d.ts +14 -0
  393. package/dist/core/yaml/src/depth.js +140 -0
  394. package/dist/core/yaml/src/edit-data.d.ts +47 -0
  395. package/dist/core/yaml/src/edit-data.js +286 -0
  396. package/dist/core/yaml/src/edit-text.d.ts +92 -0
  397. package/dist/core/yaml/src/edit-text.js +267 -0
  398. package/dist/core/yaml/src/edit.d.ts +47 -0
  399. package/dist/core/yaml/src/edit.js +198 -0
  400. package/dist/core/yaml/src/index.d.ts +5 -0
  401. package/dist/core/yaml/src/index.js +4 -0
  402. package/dist/core/yaml/src/problem.d.ts +20 -0
  403. package/dist/core/yaml/src/problem.js +1 -0
  404. package/dist/core/yaml/src/read.d.ts +47 -0
  405. package/dist/core/yaml/src/read.js +130 -0
  406. package/dist/core/yaml/src/splice-node.d.ts +47 -0
  407. package/dist/core/yaml/src/splice-node.js +333 -0
  408. package/dist/core/yaml/src/splice.d.ts +13 -0
  409. package/dist/core/yaml/src/splice.js +174 -0
  410. package/dist/core/yaml/src/unsupported.d.ts +26 -0
  411. package/dist/core/yaml/src/unsupported.js +70 -0
  412. package/dist/core/yaml/src/write.d.ts +35 -0
  413. package/dist/core/yaml/src/write.js +44 -0
  414. package/dist/testing/integration/src/canaries.d.ts +14 -0
  415. package/dist/testing/integration/src/canaries.js +17 -0
  416. package/dist/testing/integration/src/checks.d.ts +37 -0
  417. package/dist/testing/integration/src/checks.js +195 -0
  418. package/dist/testing/integration/src/describe.d.ts +35 -0
  419. package/dist/testing/integration/src/describe.js +74 -0
  420. package/dist/testing/integration/src/failure.d.ts +6 -0
  421. package/dist/testing/integration/src/failure.js +8 -0
  422. package/dist/testing/integration/src/fake-wait.d.ts +18 -0
  423. package/dist/testing/integration/src/fake-wait.js +21 -0
  424. package/dist/testing/integration/src/index.d.ts +10 -0
  425. package/dist/testing/integration/src/index.js +11 -0
  426. package/dist/testing/integration/src/load.d.ts +14 -0
  427. package/dist/testing/integration/src/load.js +47 -0
  428. package/dist/testing/integration/src/plugin-folder.d.ts +23 -0
  429. package/dist/testing/integration/src/plugin-folder.js +59 -0
  430. package/dist/testing/integration/src/plugin.d.ts +32 -0
  431. package/dist/testing/integration/src/plugin.js +57 -0
  432. package/dist/testing/integration/src/recording.d.ts +84 -0
  433. package/dist/testing/integration/src/recording.js +164 -0
  434. package/dist/testing/integration/src/run.d.ts +60 -0
  435. package/dist/testing/integration/src/run.js +81 -0
  436. package/dist/testing/integration/src/source-scan.d.ts +16 -0
  437. package/dist/testing/integration/src/source-scan.js +40 -0
  438. package/package.json +34 -3
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Compares two byte arrays in time that depends only on their length, never
3
+ * on where they first differ. Use it to check password hashes and tokens, so
4
+ * an attacker can't learn a secret from how long a comparison takes.
5
+ *
6
+ * Arrays of different lengths are unequal at once: lengths aren't secret
7
+ * here, because hashes and tokens have a fixed length.
8
+ *
9
+ * @param first - the first bytes
10
+ * @param second - the second bytes
11
+ * @returns true when both hold the same bytes
12
+ *
13
+ * @example
14
+ * constantTimeEqual(storedHash, await hasher.hash(password, salt)); // true or false
15
+ */
16
+ export function constantTimeEqual(first, second) {
17
+ if (first.length !== second.length) {
18
+ return false;
19
+ }
20
+ let difference = 0;
21
+ for (let index = 0; index < first.length; index++) {
22
+ // No early exit: every byte is compared, and differences pile up in one number.
23
+ difference |= (first[index] ?? 0) ^ (second[index] ?? 0);
24
+ }
25
+ return difference === 0;
26
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Anything that hashes bytes with SHA-256, such as the `Digest` port. The
3
+ * core has no hash code of its own, so the caller passes one in.
4
+ */
5
+ export interface Sha256 {
6
+ /** The 32-byte SHA-256 of the bytes. */
7
+ sha256(data: Uint8Array): Promise<Uint8Array>;
8
+ }
9
+ /**
10
+ * The digest of a workspace file's text, as `DefinitionStore.write` expects
11
+ * it: `sha256:` and the 64 lowercase hex characters of the SHA-256 of the
12
+ * text's UTF-8 bytes.
13
+ *
14
+ * @example
15
+ * await contentDigest("hello", digest);
16
+ * // "sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
17
+ */
18
+ export declare function contentDigest(content: string, digest: Sha256): Promise<`sha256:${string}`>;
19
+ /**
20
+ * Whether a file's text, or `null` when there is no file, is what a caller
21
+ * expects: the {@link contentDigest} of the text it last read, or `"absent"`
22
+ * for no file. Every store calls this before a write with `expected`.
23
+ */
24
+ export declare function matchesExpected(current: string | null, expected: string, digest: Sha256): Promise<boolean>;
@@ -0,0 +1,28 @@
1
+ // The digest the `DefinitionStore` port's write-if-unchanged check compares.
2
+ // It lives here, not in `@halonicjs/ports`, because the ports package uses no
3
+ // other package and the core has no `TextEncoder`.
4
+ import { bytesToHex } from "./hex.js";
5
+ import { encodeUtf8 } from "./utf8.js";
6
+ /**
7
+ * The digest of a workspace file's text, as `DefinitionStore.write` expects
8
+ * it: `sha256:` and the 64 lowercase hex characters of the SHA-256 of the
9
+ * text's UTF-8 bytes.
10
+ *
11
+ * @example
12
+ * await contentDigest("hello", digest);
13
+ * // "sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
14
+ */
15
+ export async function contentDigest(content, digest) {
16
+ return `sha256:${bytesToHex(await digest.sha256(encodeUtf8(content)))}`;
17
+ }
18
+ /**
19
+ * Whether a file's text, or `null` when there is no file, is what a caller
20
+ * expects: the {@link contentDigest} of the text it last read, or `"absent"`
21
+ * for no file. Every store calls this before a write with `expected`.
22
+ */
23
+ export async function matchesExpected(current, expected, digest) {
24
+ if (expected === "absent" || current === null) {
25
+ return expected === "absent" && current === null;
26
+ }
27
+ return (await contentDigest(current, digest)) === expected;
28
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copies plain data all the way down: arrays, plain objects, dates and
3
+ * primitives. A value that appears twice, or contains itself, is copied once
4
+ * and shared the same way in the copy, as `structuredClone` does. The core
5
+ * has no `structuredClone`, so this replaces it for run events, records and
6
+ * workflow context.
7
+ *
8
+ * @param value - the data to copy
9
+ * @returns a copy that shares no objects with `value`
10
+ * @throws TypeError for anything that isn't plain data, such as a function, a `Map` or a class instance
11
+ *
12
+ * @example
13
+ * const copy = deepClone({ steps: [{ id: "a" }] });
14
+ */
15
+ export declare function deepClone<T>(value: T): T;
@@ -0,0 +1,59 @@
1
+ import { describeObject, isPlainObject, keyPath } from "./plain-data.js";
2
+ /**
3
+ * Copies plain data all the way down: arrays, plain objects, dates and
4
+ * primitives. A value that appears twice, or contains itself, is copied once
5
+ * and shared the same way in the copy, as `structuredClone` does. The core
6
+ * has no `structuredClone`, so this replaces it for run events, records and
7
+ * workflow context.
8
+ *
9
+ * @param value - the data to copy
10
+ * @returns a copy that shares no objects with `value`
11
+ * @throws TypeError for anything that isn't plain data, such as a function, a `Map` or a class instance
12
+ *
13
+ * @example
14
+ * const copy = deepClone({ steps: [{ id: "a" }] });
15
+ */
16
+ export function deepClone(value) {
17
+ return cloneValue(value, new Map(), "value");
18
+ }
19
+ function cloneValue(value, copies, path) {
20
+ if (typeof value === "function" || typeof value === "symbol") {
21
+ throw new TypeError(`deepClone can't copy the ${typeof value} at ${path}.`);
22
+ }
23
+ if (typeof value !== "object" || value === null) {
24
+ return value;
25
+ }
26
+ const existing = copies.get(value);
27
+ if (existing !== undefined) {
28
+ return existing;
29
+ }
30
+ if (value instanceof Date) {
31
+ const copy = new Date(value.getTime());
32
+ copies.set(value, copy);
33
+ return copy;
34
+ }
35
+ if (Array.isArray(value)) {
36
+ const copy = [];
37
+ copies.set(value, copy);
38
+ for (let index = 0; index < value.length; index++) {
39
+ copy.push(cloneValue(value[index], copies, `${path}[${index}]`));
40
+ }
41
+ return copy;
42
+ }
43
+ if (isPlainObject(value)) {
44
+ const copy = Object.getPrototypeOf(value) === null ? Object.create(null) : {};
45
+ copies.set(value, copy);
46
+ for (const key of Object.keys(value)) {
47
+ // defineProperty, not assignment: a "__proto__" key from JSON.parse
48
+ // stays a plain key instead of changing the copy's prototype.
49
+ Object.defineProperty(copy, key, {
50
+ value: cloneValue(value[key], copies, keyPath(path, key)),
51
+ enumerable: true,
52
+ writable: true,
53
+ configurable: true,
54
+ });
55
+ }
56
+ return copy;
57
+ }
58
+ throw new TypeError(`deepClone copies plain data only, but ${path} is ${describeObject(value)}.`);
59
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Compares two values by content: arrays item by item, plain objects key by
3
+ * key in any order, and dates by time. Numbers compare with `===`, except
4
+ * that `NaN` equals `NaN`. Any other object (a `Map`, a class instance)
5
+ * equals only itself.
6
+ *
7
+ * Unlike comparing `JSON.stringify` output, key order doesn't matter, and a
8
+ * key whose value is `undefined` is still a key: `{ a: undefined }` doesn't
9
+ * equal `{}`.
10
+ *
11
+ * Cyclic data isn't supported: comparing it throws a `RangeError`. JSON can't
12
+ * express cycles, and `@halonicjs/yaml` rejects aliases that refer to
13
+ * themselves. `deepClone` keeps cycles because it mirrors `structuredClone`,
14
+ * while comparing a cycle would need extra bookkeeping on every call.
15
+ *
16
+ * @param first - the first value
17
+ * @param second - the second value
18
+ * @returns true when both have the same content
19
+ *
20
+ * @example
21
+ * deepEqual({ a: [1, 2], b: "x" }, { b: "x", a: [1, 2] }); // true
22
+ */
23
+ export declare function deepEqual(first: unknown, second: unknown): boolean;
@@ -0,0 +1,64 @@
1
+ import { isPlainObject } from "./plain-data.js";
2
+ /**
3
+ * Compares two values by content: arrays item by item, plain objects key by
4
+ * key in any order, and dates by time. Numbers compare with `===`, except
5
+ * that `NaN` equals `NaN`. Any other object (a `Map`, a class instance)
6
+ * equals only itself.
7
+ *
8
+ * Unlike comparing `JSON.stringify` output, key order doesn't matter, and a
9
+ * key whose value is `undefined` is still a key: `{ a: undefined }` doesn't
10
+ * equal `{}`.
11
+ *
12
+ * Cyclic data isn't supported: comparing it throws a `RangeError`. JSON can't
13
+ * express cycles, and `@halonicjs/yaml` rejects aliases that refer to
14
+ * themselves. `deepClone` keeps cycles because it mirrors `structuredClone`,
15
+ * while comparing a cycle would need extra bookkeeping on every call.
16
+ *
17
+ * @param first - the first value
18
+ * @param second - the second value
19
+ * @returns true when both have the same content
20
+ *
21
+ * @example
22
+ * deepEqual({ a: [1, 2], b: "x" }, { b: "x", a: [1, 2] }); // true
23
+ */
24
+ export function deepEqual(first, second) {
25
+ if (first === second) {
26
+ return true;
27
+ }
28
+ if (typeof first === "number" && typeof second === "number") {
29
+ return Number.isNaN(first) && Number.isNaN(second);
30
+ }
31
+ if (Array.isArray(first) && Array.isArray(second)) {
32
+ return arraysEqual(first, second);
33
+ }
34
+ if (first instanceof Date && second instanceof Date) {
35
+ return Object.is(first.getTime(), second.getTime());
36
+ }
37
+ if (isPlainObject(first) && isPlainObject(second)) {
38
+ return objectsEqual(first, second);
39
+ }
40
+ return false;
41
+ }
42
+ function arraysEqual(first, second) {
43
+ if (first.length !== second.length) {
44
+ return false;
45
+ }
46
+ for (let index = 0; index < first.length; index++) {
47
+ if (!deepEqual(first[index], second[index])) {
48
+ return false;
49
+ }
50
+ }
51
+ return true;
52
+ }
53
+ function objectsEqual(first, second) {
54
+ const firstKeys = Object.keys(first);
55
+ if (firstKeys.length !== Object.keys(second).length) {
56
+ return false;
57
+ }
58
+ for (const key of firstKeys) {
59
+ if (!Object.hasOwn(second, key) || !deepEqual(first[key], second[key])) {
60
+ return false;
61
+ }
62
+ }
63
+ return true;
64
+ }
@@ -0,0 +1,42 @@
1
+ /** A function that receives one kind of event. */
2
+ export type Listener<Payload> = (payload: Payload) => void;
3
+ /**
4
+ * A small typed event emitter. `Events` maps each event name to the type of
5
+ * its payload, so `emit` and `on` check both.
6
+ *
7
+ * Listeners run in the order they were added. A listener added or removed
8
+ * while an event is being sent takes effect from the next event. If a
9
+ * listener throws, the others still run, and `emit` then throws the error
10
+ * (or an `AggregateError` with all of them).
11
+ *
12
+ * @example
13
+ * const changes = new Emitter<{ saved: { path: string }; closed: undefined }>();
14
+ * const stop = changes.on("saved", ({ path }) => console.log(path));
15
+ * changes.emit("saved", { path: "hubs/support/hub.yaml" });
16
+ * stop();
17
+ */
18
+ export declare class Emitter<Events extends Record<string, unknown>> {
19
+ private readonly listeners;
20
+ /**
21
+ * Adds a listener for one event.
22
+ *
23
+ * @param name - the event to listen to
24
+ * @param listener - called with each payload
25
+ * @returns a function that removes the listener again; calling it twice is harmless
26
+ */
27
+ on<Name extends keyof Events>(name: Name, listener: Listener<Events[Name]>): () => void;
28
+ /**
29
+ * Sends an event to every listener for it.
30
+ *
31
+ * @param name - the event
32
+ * @param payload - what the listeners receive
33
+ * @throws the error of the one listener that threw, or an `AggregateError` when several did
34
+ */
35
+ emit<Name extends keyof Events>(name: Name, payload: Events[Name]): void;
36
+ /**
37
+ * How many listeners an event has.
38
+ *
39
+ * @param name - the event
40
+ */
41
+ listenerCount(name: keyof Events): number;
42
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * A small typed event emitter. `Events` maps each event name to the type of
3
+ * its payload, so `emit` and `on` check both.
4
+ *
5
+ * Listeners run in the order they were added. A listener added or removed
6
+ * while an event is being sent takes effect from the next event. If a
7
+ * listener throws, the others still run, and `emit` then throws the error
8
+ * (or an `AggregateError` with all of them).
9
+ *
10
+ * @example
11
+ * const changes = new Emitter<{ saved: { path: string }; closed: undefined }>();
12
+ * const stop = changes.on("saved", ({ path }) => console.log(path));
13
+ * changes.emit("saved", { path: "hubs/support/hub.yaml" });
14
+ * stop();
15
+ */
16
+ export class Emitter {
17
+ listeners = new Map();
18
+ /**
19
+ * Adds a listener for one event.
20
+ *
21
+ * @param name - the event to listen to
22
+ * @param listener - called with each payload
23
+ * @returns a function that removes the listener again; calling it twice is harmless
24
+ */
25
+ on(name, listener) {
26
+ let forName = this.listeners.get(name);
27
+ if (forName === undefined) {
28
+ forName = new Set();
29
+ this.listeners.set(name, forName);
30
+ }
31
+ // Wrapped, so adding the same function twice gives two independent listeners.
32
+ const entry = (payload) => listener(payload);
33
+ forName.add(entry);
34
+ return () => {
35
+ forName.delete(entry);
36
+ };
37
+ }
38
+ /**
39
+ * Sends an event to every listener for it.
40
+ *
41
+ * @param name - the event
42
+ * @param payload - what the listeners receive
43
+ * @throws the error of the one listener that threw, or an `AggregateError` when several did
44
+ */
45
+ emit(name, payload) {
46
+ const forName = this.listeners.get(name);
47
+ if (forName === undefined) {
48
+ return;
49
+ }
50
+ const errors = [];
51
+ for (const listener of [...forName]) {
52
+ try {
53
+ listener(payload);
54
+ }
55
+ catch (error) {
56
+ errors.push(error);
57
+ }
58
+ }
59
+ if (errors.length === 1) {
60
+ throw errors[0];
61
+ }
62
+ if (errors.length > 1) {
63
+ throw new AggregateError(errors, `${errors.length} listeners for "${String(name)}" failed.`);
64
+ }
65
+ }
66
+ /**
67
+ * How many listeners an event has.
68
+ *
69
+ * @param name - the event
70
+ */
71
+ listenerCount(name) {
72
+ return this.listeners.get(name)?.size ?? 0;
73
+ }
74
+ }
@@ -0,0 +1,88 @@
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 declare const errorKinds: readonly ["invalid_input", "not_found", "conflict", "unauthenticated", "denied", "limit_reached", "unavailable", "internal"];
19
+ /** One of {@link errorKinds}. */
20
+ export type ErrorKind = (typeof errorKinds)[number];
21
+ /**
22
+ * True when `value` is one of the error kinds. Use it to decode a kind that
23
+ * came over the wire, such as the `kind` in an HTTP error body.
24
+ *
25
+ * @example
26
+ * isErrorKind("not_found"); // true
27
+ * isErrorKind("not-found"); // false
28
+ */
29
+ export declare function isErrorKind(value: unknown): value is ErrorKind;
30
+ /** What a {@link KindedError} can carry besides its kind and message. */
31
+ export type KindedErrorOptions = {
32
+ /**
33
+ * The one next step that fixes it, as a sentence on its own line, such as
34
+ * "Start Ollama, then run again." Leave it out when there is no step to
35
+ * suggest: surfaces then show no fix and never make one up.
36
+ */
37
+ readonly fix?: string;
38
+ /** The error this one wraps, for the log. */
39
+ readonly cause?: unknown;
40
+ };
41
+ /**
42
+ * An error with a kind, for code that fails in a way a person should hear
43
+ * about. Errors that already have their own class don't have to extend this
44
+ * one: a `kind` property is enough for {@link errorKindOf}.
45
+ *
46
+ * The message must be safe to show and to log: no secrets, tokens, internal
47
+ * paths or internal codes. Surfaces show a generic message for `internal`
48
+ * instead of this one, so don't rely on the text of an `internal` error
49
+ * reaching the user; put what helps there in the log. The same rule holds
50
+ * for the optional `fix`, which is kept apart from the message so a surface
51
+ * can show it on its own line or in its own JSON field.
52
+ *
53
+ * @example
54
+ * throw new KindedError("not_found", `There is no routine named "${name}".`);
55
+ * throw new KindedError("unavailable", "Halonic couldn't reach Ollama.", {
56
+ * fix: "Start Ollama, then run again.",
57
+ * });
58
+ */
59
+ export declare class KindedError extends Error {
60
+ readonly name = "KindedError";
61
+ readonly kind: ErrorKind;
62
+ /** The one next step that fixes it; `undefined` when there is none to suggest. */
63
+ readonly fix: string | undefined;
64
+ /**
65
+ * @param kind - how a surface should respond
66
+ * @param message - safe to show and to log
67
+ * @param options - `fix` is the next step, safe to show and to log; `cause`
68
+ * keeps the error this one wraps, for the log
69
+ */
70
+ constructor(kind: ErrorKind, message: string, options?: KindedErrorOptions);
71
+ }
72
+ /**
73
+ * The kind of any thrown value, for the one function per surface that turns
74
+ * errors into responses. A value has a kind when it is an object with a
75
+ * valid `kind` string and a `message` string: a `KindedError`, an error class
76
+ * with a `kind` property, or the `{ kind, message }` shape an error takes over
77
+ * HTTP or IPC. Anything else is `internal`, including objects that only have
78
+ * a `kind`, such as events.
79
+ *
80
+ * It reads only the value itself, never its `cause`: code that wraps an error
81
+ * chooses the kind of the wrapper on purpose.
82
+ *
83
+ * @example
84
+ * errorKindOf(new KindedError("conflict", "The run changed.")); // "conflict"
85
+ * errorKindOf({ kind: "not_found", message: "No such hub." }); // "not_found"
86
+ * errorKindOf(new TypeError("x is undefined")); // "internal"
87
+ */
88
+ export declare function errorKindOf(error: unknown): ErrorKind;
@@ -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,19 @@
1
+ /**
2
+ * Whether a code point is one nobody sees on screen but that can still change
3
+ * the text around it, such as a right-to-left override.
4
+ *
5
+ * @example
6
+ * isHiddenCharacter(0x202e); // true
7
+ * isHiddenCharacter("a".codePointAt(0) ?? 0); // false
8
+ */
9
+ export declare function isHiddenCharacter(codePoint: number): boolean;
10
+ /**
11
+ * JSON text with every hidden character written as a `\uXXXX` escape, so the
12
+ * raw JSON shows it too and stays the same JSON. A character above U+FFFF,
13
+ * such as a tag character, becomes its two UTF-16 escapes. Hidden characters
14
+ * can only stand inside JSON strings, where an escape means the same.
15
+ *
16
+ * @example
17
+ * escapeHidden(JSON.stringify(`Refund${String.fromCodePoint(0x202e)}for Sam`)); // '"Refund\\u202efor Sam"'
18
+ */
19
+ export declare function escapeHidden(json: string): string;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The code point ranges a text can carry without anyone seeing them: control
3
+ * characters other than tab (U+0009) and newline (U+000A), the soft hyphen,
4
+ * zero-width characters, direction marks, overrides and isolates, the word
5
+ * joiner and invisible operators, the byte order mark and Unicode tag
6
+ * characters. Written as numbers, so the source holds no invisible character
7
+ * itself.
8
+ */
9
+ const hiddenRanges = [
10
+ [0x0000, 0x0008],
11
+ [0x000b, 0x001f],
12
+ [0x007f, 0x009f],
13
+ [0x00ad, 0x00ad],
14
+ [0x061c, 0x061c],
15
+ [0x200b, 0x200f],
16
+ [0x202a, 0x202e],
17
+ [0x2060, 0x2064],
18
+ [0x2066, 0x2069],
19
+ [0xfeff, 0xfeff],
20
+ [0xe0000, 0xe007f],
21
+ ];
22
+ /**
23
+ * Whether a code point is one nobody sees on screen but that can still change
24
+ * the text around it, such as a right-to-left override.
25
+ *
26
+ * @example
27
+ * isHiddenCharacter(0x202e); // true
28
+ * isHiddenCharacter("a".codePointAt(0) ?? 0); // false
29
+ */
30
+ export function isHiddenCharacter(codePoint) {
31
+ return hiddenRanges.some(([first, last]) => codePoint >= first && codePoint <= last);
32
+ }
33
+ /**
34
+ * JSON text with every hidden character written as a `\uXXXX` escape, so the
35
+ * raw JSON shows it too and stays the same JSON. A character above U+FFFF,
36
+ * such as a tag character, becomes its two UTF-16 escapes. Hidden characters
37
+ * can only stand inside JSON strings, where an escape means the same.
38
+ *
39
+ * @example
40
+ * escapeHidden(JSON.stringify(`Refund${String.fromCodePoint(0x202e)}for Sam`)); // '"Refund\\u202efor Sam"'
41
+ */
42
+ export function escapeHidden(json) {
43
+ let escaped = "";
44
+ for (const character of json) {
45
+ if (!isHiddenCharacter(character.codePointAt(0) ?? 0)) {
46
+ escaped += character;
47
+ continue;
48
+ }
49
+ for (let index = 0; index < character.length; index++) {
50
+ escaped += `\\u${character.charCodeAt(index).toString(16).padStart(4, "0")}`;
51
+ }
52
+ }
53
+ return escaped;
54
+ }