@halonicjs/testing 0.0.0 → 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 +41 -1
  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 +34 -3
@@ -0,0 +1,259 @@
1
+ import type { HttpClient } from "./http-client.js";
2
+ import type { SandboxSession } from "./sandbox.js";
3
+ import type { Secrets } from "./secrets.js";
4
+ import type { TokenStore } from "./token-store.js";
5
+ /** Version of the {@link ConnectorClient} and {@link ConnectorFactory} ports. A breaking change bumps it and comes with an ADR. */
6
+ export declare const connectorClientVersion = 1;
7
+ /**
8
+ * What calling a tool can do. `read` changes nothing; `write` changes data,
9
+ * such as mail, files or records; `send` reaches people outside, such as
10
+ * sending a mail. Approvals use it.
11
+ */
12
+ export type ToolRisk = "read" | "write" | "send";
13
+ /** A tool a connector offers. */
14
+ export interface ConnectorTool {
15
+ /** The tool's name, unique within its connector. */
16
+ name: string;
17
+ /** What the tool does, written for the model. */
18
+ description: string;
19
+ /** JSON Schema of the arguments object. */
20
+ parameters: Record<string, unknown>;
21
+ /**
22
+ * What calling it can do. Absent means unknown: treat it as `write`. The
23
+ * host ignores it for a tool an `http` or `stdio` connector lists (see
24
+ * {@link ConnectorClient.listTools}).
25
+ */
26
+ risk?: ToolRisk;
27
+ /**
28
+ * Whether its result carries outside content (mail, web pages), which the
29
+ * engine fences off. It covers the result only. For a tool an `http` or
30
+ * `stdio` connector lists, the host fences everything anyway (see
31
+ * {@link ConnectorClient.listTools}).
32
+ */
33
+ untrusted?: boolean;
34
+ }
35
+ /**
36
+ * Hints for one tool call. Each is optional, and an adapter may ignore any
37
+ * of them: no caller's correctness depends on an adapter using one (port
38
+ * list ADR, "Additive after the freeze: optional hints").
39
+ */
40
+ export interface ConnectorCallOptions {
41
+ /**
42
+ * The same for every attempt at one call, such as `<runId>:<callId>`
43
+ * when a person has a run try a call again. An adapter may pass it on,
44
+ * so a server that knows it can drop a duplicate, and may ignore it.
45
+ */
46
+ readonly idempotencyKey?: string;
47
+ }
48
+ /** A connection to one connector: an MCP server over HTTP or a local process, or a built-in one. */
49
+ export interface ConnectorClient {
50
+ /** The connector's id in the workspace. */
51
+ readonly id: string;
52
+ /**
53
+ * The tools the connector offers now. Connects on the first call.
54
+ *
55
+ * For an `http` or `stdio` connector, a server the workspace chose wrote
56
+ * these tools. The host rebuilds their parameters from an allow-list,
57
+ * fences off their descriptions and results as untrusted text, treats
58
+ * their `risk` as `write` unless the workspace sets a lower one, and
59
+ * refuses tools that are too large or whose names it can't check
60
+ * (requirement `ports.untrusted-tool-listings`).
61
+ * Don't fence them here, and don't mark them trusted.
62
+ *
63
+ * @throws when the connector can't be reached or started
64
+ */
65
+ listTools(): Promise<ConnectorTool[]>;
66
+ /**
67
+ * Calls a tool and returns its text result. Throws on transport errors and tool errors.
68
+ *
69
+ * `options` holds hints (`ports.connector-call-hints`): an adapter may
70
+ * use them and may ignore them, and the call must work either way.
71
+ */
72
+ callTool(name: string, args: Record<string, unknown>, options?: ConnectorCallOptions): Promise<string>;
73
+ /** Release the connection (stop a local process). Safe to call twice. */
74
+ close(): Promise<void>;
75
+ }
76
+ /**
77
+ * The exact package version a package-runner connector (`npx`, `uvx` and the
78
+ * others listed on the stdio transport) starts, and the registry it comes
79
+ * from. It is stored in the trust record when a person trusts the workspace,
80
+ * so it is per machine and never in a workspace file.
81
+ *
82
+ * It has no integrity hash, on purpose: the person already trusts the
83
+ * registry, and a Python package has a different file, so a different hash,
84
+ * per platform. See the port list ADR. For a workspace connector,
85
+ * `registryUrl` comes from the user's profile. For a plugin's local tool it
86
+ * comes from the plugin's manifest, or is the runner's public registry, and
87
+ * the person sees it in the trust prompt before trusting the plugin (plugins
88
+ * ADR, section 1.2).
89
+ *
90
+ * @example
91
+ * const pin: ConnectorPin = {
92
+ * registry: "npm",
93
+ * registryUrl: "https://registry.npmjs.org",
94
+ * package: "@acme/mail-mcp",
95
+ * version: "2.3.1",
96
+ * };
97
+ */
98
+ export interface ConnectorPin {
99
+ /** `npm` for the npm runners (`npx`, `pnpm dlx`, `bunx` and so on), `pypi` for the Python ones (`uvx`, `pipx run`, `uv tool run`). */
100
+ registry: "npm" | "pypi";
101
+ /**
102
+ * The registry's base address, such as "https://pypi.org", never its index
103
+ * (the launcher adds `/simple` itself). Never from a workspace: from the
104
+ * user's profile, or for a plugin from its trusted manifest.
105
+ */
106
+ registryUrl: string;
107
+ /** The package name, such as "@acme/mail-mcp". */
108
+ package: string;
109
+ /**
110
+ * An exact version, such as "2.3.1". The adapter refuses to start on a tag
111
+ * or a range (`latest`, `^2.3.1`, `>=2`) instead of resolving it.
112
+ */
113
+ version: string;
114
+ }
115
+ /** How to reach a connector. */
116
+ export type ConnectorTransport = {
117
+ kind: "http";
118
+ url: string;
119
+ headers: Record<string, string>;
120
+ } | {
121
+ kind: "stdio";
122
+ command: string;
123
+ args: string[];
124
+ env: Record<string, string>;
125
+ cwd?: string;
126
+ /**
127
+ * The version to start, for package-runner connectors. The app fills it
128
+ * from the trust record, **never from workspace YAML**, so a workspace
129
+ * edit can't choose the version or the registry.
130
+ *
131
+ * A package runner is a `command` whose program name, without its
132
+ * folder, any case and any `.cmd`, `.exe`, `.bat` or `.ps1` ending, is
133
+ * `npx`, `bunx` or `uvx`, or one of `npm exec`, `pnpm dlx`,
134
+ * `yarn dlx`, `pipx run` and `uv tool run`. Without a `pin`, a package
135
+ * runner starts only with a trust grant, like every stdio program, and
136
+ * its `command` and `args` are in the fingerprint the person confirmed.
137
+ * The version it runs is not fixed: the runner may start whatever
138
+ * version is newest. Pinning at trust comes later.
139
+ *
140
+ * When it is set, the adapter starts exactly `package` at `version`,
141
+ * looks it up only at `registryUrl`, starts in an empty folder of its
142
+ * own instead of `cwd`, ignores the workspace's package-manager
143
+ * settings (`.npmrc`, `node_modules`, `uv.toml`, `pyproject.toml`), and
144
+ * refuses to start when the command names any other version.
145
+ *
146
+ * It also refuses to start when `env` sets a variable, in any case,
147
+ * that can move the registry or run code before the package:
148
+ * `NODE_OPTIONS`, `NODE_PATH`, `PYTHONPATH`, `PYTHONSTARTUP`,
149
+ * `PYTHONHOME`, or any name starting with `npm_config_`, `YARN_`,
150
+ * `PNPM_`, `BUN_`, `COREPACK_`, `UV_`, `PIP_` or `PIPX_`; a proxy,
151
+ * `HTTPS_PROXY`, `HTTP_PROXY` or `ALL_PROXY`; a certificate setting,
152
+ * `NODE_EXTRA_CA_CERTS`, `NODE_TLS_REJECT_UNAUTHORIZED`,
153
+ * `SSL_CERT_FILE`, `SSL_CERT_DIR`, `REQUESTS_CA_BUNDLE` or
154
+ * `CURL_CA_BUNDLE`; or a preload, `LD_PRELOAD`, `LD_LIBRARY_PATH`,
155
+ * `DYLD_INSERT_LIBRARIES` or `DYLD_LIBRARY_PATH`. It drops the
156
+ * package-manager and language variables it inherits from its own
157
+ * process and sets the registry from `registryUrl` itself. It keeps an
158
+ * inherited proxy, certificate or preload: those are the person's own
159
+ * machine settings, such as a company proxy, not the workspace's.
160
+ *
161
+ * And it refuses to start when an argument is a runner option that
162
+ * fetches from somewhere else: `--registry`, an npm scope's
163
+ * `--@<scope>:registry`, `--userconfig`, `--globalconfig`, `--cache`,
164
+ * `--index-url` (`-i`), `--extra-index-url`, `--index`,
165
+ * `--default-index`, `--find-links` (`-f`), `--config-file`,
166
+ * `--cache-dir` or `--pip-args`.
167
+ *
168
+ * Every stdio launcher checks these rules with `@halonicjs/app`'s
169
+ * `checkPackageRunnerLaunch`, so they live in one place.
170
+ */
171
+ pin?: ConnectorPin;
172
+ }
173
+ /** Built-in Gmail and Drive for one account; `client` names no secret. */
174
+ | {
175
+ kind: "google";
176
+ account: string;
177
+ client: string;
178
+ };
179
+ /** A connector as the workspace configures it. */
180
+ export interface ConnectorConfig {
181
+ id: string;
182
+ transport: ConnectorTransport;
183
+ /** HTTP bearer token secret name. */
184
+ secret?: string;
185
+ /** stdio: environment variable -> secret name. */
186
+ secretEnv: Record<string, string>;
187
+ }
188
+ /**
189
+ * Proof that a person trusted the workspace a connector comes from.
190
+ * `TrustService` in `core/app` checks the trust record against the
191
+ * workspace's current fingerprint and hands out a grant only when they
192
+ * match; adapters don't compute or compare fingerprints themselves.
193
+ */
194
+ export interface TrustGrant {
195
+ /** The trusted workspace's location: its resolved real path. */
196
+ location: string;
197
+ /** The fingerprint the person trusted, such as "hfp1:9f86d0…". */
198
+ fingerprint: string;
199
+ }
200
+ /** What a factory may use to build a connector client. */
201
+ export interface ConnectorFactoryContext {
202
+ secrets: Secrets;
203
+ /** Where sign-ins keep their tokens, such as Google refresh tokens. */
204
+ tokens: TokenStore;
205
+ http: HttpClient;
206
+ /** The workspace folder, for stdio connectors that run in it. Absent where programs can't start. */
207
+ workspaceRoot?: string;
208
+ /**
209
+ * The absolute working folder of every harness agent in the workspace,
210
+ * resolved to real paths by the caller. A harness agent writes there from
211
+ * inside its sandbox, so a `stdio` connector refuses, right before its
212
+ * program starts, a start that would run or load a file from one of them
213
+ * (requirement `format.working-folder-start`).
214
+ *
215
+ * Absent, or empty, when the workspace has no harness agent with a
216
+ * working folder: there is nothing to protect.
217
+ */
218
+ workingFolders?: readonly string[];
219
+ /**
220
+ * The trust grant for the connector's workspace, or `null` when it isn't
221
+ * trusted. Required, so a caller can't forget it.
222
+ *
223
+ * Without a grant:
224
+ * - a `stdio` connector never starts its program (`listTools` and
225
+ * `callTool` throw);
226
+ * - an `http` connector's `callTool` always throws, because the only
227
+ * `risk` it sees is the one the server wrote;
228
+ * - the built-in `google` connector's `callTool` throws for every tool
229
+ * whose own `risk` isn't `read`;
230
+ * - the host ignores any `risk` the workspace sets, so every tool an
231
+ * `http` or `stdio` connector lists counts as `write`, and it refuses
232
+ * to call a tool whose risk isn't `read`.
233
+ *
234
+ * Both checks hold on their own, so a mistake in one doesn't open the gate
235
+ * (requirement `ports.connector-trust-enforcement`).
236
+ */
237
+ trust: TrustGrant | null;
238
+ /**
239
+ * The sandbox session a `stdio` connector starts its program in, for a
240
+ * plugin's local tool (plugins ADR, sections 3 and 4). Halonic opens it
241
+ * with a profile it builds itself, never the plugin.
242
+ *
243
+ * When it is set, the program starts in this session and nowhere else:
244
+ * - only a factory that starts programs through a session takes it; a
245
+ * factory that starts programs on this computer refuses the context, so
246
+ * a wiring mistake can't run a plugin's program outside the fence;
247
+ * - a session whose fence proof isn't `fenced` starts nothing, and there
248
+ * is no fallback to this computer. A person's yes to run without the
249
+ * sandbox doesn't cover programs.
250
+ *
251
+ * Absent for a workspace's own connectors, which start as before.
252
+ */
253
+ sandbox?: SandboxSession;
254
+ }
255
+ /** Creates connector clients for one transport kind. */
256
+ export interface ConnectorFactory {
257
+ readonly transport: ConnectorTransport["kind"];
258
+ create(config: ConnectorConfig, context: ConnectorFactoryContext): ConnectorClient;
259
+ }
@@ -0,0 +1,2 @@
1
+ /** Version of the {@link ConnectorClient} and {@link ConnectorFactory} ports. A breaking change bumps it and comes with an ADR. */
2
+ export const connectorClientVersion = 1;
@@ -0,0 +1,84 @@
1
+ /** Version of the {@link Coordination} port. A breaking change bumps it and comes with an ADR. */
2
+ export declare const coordinationVersion = 1;
3
+ /** The right to do something alone until `expiresAt`. A lease is never held across a crash for good. */
4
+ export interface Lease {
5
+ /** The key the lease was taken on. */
6
+ key: string;
7
+ /** Proves who holds the lease; renewing or releasing with an old token does nothing. Renewing keeps it. */
8
+ token: string;
9
+ /**
10
+ * ISO time the lease ends unless it is renewed, by the adapter's clock.
11
+ * For display and logs only: callers don't compare it with their own clock
12
+ * to decide whether they still hold the lease; they renew and check the result.
13
+ */
14
+ expiresAt: string;
15
+ }
16
+ /** What {@link Coordination.increment} did, and the counter's value afterwards. */
17
+ export interface CounterResult {
18
+ /** Whether `by` was added; `false` when it would have gone above the limit. */
19
+ applied: boolean;
20
+ /** The counter's value after the call, whether or not `by` was added. */
21
+ value: number;
22
+ }
23
+ /** What {@link Coordination.countInWindow} decided. */
24
+ export interface WindowCount {
25
+ /** Whether this attempt was within the limit; only allowed attempts are counted. */
26
+ allowed: boolean;
27
+ /** Attempts counted in the current window, this one included when allowed; `limit` when refused. */
28
+ count: number;
29
+ /** ISO time the current window ends and counting starts again. A refused attempt doesn't move it. */
30
+ resetAt: string;
31
+ }
32
+ /**
33
+ * Leases, values and counters shared by every instance of a deployment: a
34
+ * routine fires once, a run advances in one place, login limits and the
35
+ * budget hold. Nothing can hold a lock across an
36
+ * `await`, so locks are leases with a time limit.
37
+ *
38
+ * Leases, values, counters and windows each have their own keys: the same key
39
+ * in two of them names two different things. Every operation is atomic.
40
+ *
41
+ * **Input rules**, the same on every adapter:
42
+ * - Keys are 1 to 256 UTF-8 bytes. Core hashes user input (an email
43
+ * address, a file name) before putting it in a key.
44
+ * - A value set with `compareAndSet` is at most 64 KiB of UTF-8, below
45
+ * the per-value limit of Durable Objects storage.
46
+ * - `ttlMs`, `windowMs`, `limit` and `by` are positive safe whole numbers.
47
+ * Amounts that have fractions, such as the budget, are counted in whole
48
+ * micro-units (1 = 0.000001), so every store adds them up the same way.
49
+ * - Breaking a rule throws a `RangeError` and changes nothing.
50
+ */
51
+ export interface Coordination {
52
+ /**
53
+ * Takes the lease for `ttlMs` milliseconds, or returns `null` while anyone
54
+ * holds it, the caller included.
55
+ */
56
+ tryAcquire(key: string, ttlMs: number): Promise<Lease | null>;
57
+ /**
58
+ * Extends a lease still held to `ttlMs` milliseconds from now, keeping its
59
+ * token, or returns `null` when it ran out or was taken over.
60
+ */
61
+ renew(lease: Lease, ttlMs: number): Promise<Lease | null>;
62
+ /** Gives a lease back. Releasing one that ran out or was taken over does nothing. */
63
+ release(lease: Lease): Promise<void>;
64
+ /** A value, or `null` when it isn't set. */
65
+ read(key: string): Promise<string | null>;
66
+ /**
67
+ * Sets the value only if it is still `expected` (`null`: not set). A `next`
68
+ * of `null` deletes it. Returns whether it changed.
69
+ */
70
+ compareAndSet(key: string, expected: string | null, next: string | null): Promise<boolean>;
71
+ /**
72
+ * Adds `by` to a counter that starts at 0, unless the result would go above
73
+ * `limit`; then it leaves the counter as it is. Counters only go up.
74
+ */
75
+ increment(key: string, by: number, limit?: number): Promise<CounterResult>;
76
+ /**
77
+ * Counts one attempt in a fixed window of `windowMs` milliseconds that
78
+ * starts with its first attempt, if fewer than `limit` were counted in it.
79
+ * The window covers `start` up to but not including `start + windowMs`; an
80
+ * attempt at that moment opens a new window. Parallel attempts never let
81
+ * more than `limit` through.
82
+ */
83
+ countInWindow(key: string, windowMs: number, limit: number): Promise<WindowCount>;
84
+ }
@@ -0,0 +1,2 @@
1
+ /** Version of the {@link Coordination} port. A breaking change bumps it and comes with an ADR. */
2
+ export const coordinationVersion = 1;
@@ -0,0 +1,208 @@
1
+ /** Version of the {@link DefinitionStore} and {@link DefinitionSource} ports. A breaking change bumps it and comes with an ADR. */
2
+ export declare const definitionStoreVersion = 2;
3
+ /**
4
+ * Read access to the workspace files (agents, workflows, hubs …), wherever
5
+ * they live: a folder, git, memory or a deployed snapshot. Paths are
6
+ * relative and "/" separated.
7
+ *
8
+ * **Every method refuses an unsafe path** with a `RangeError` before it
9
+ * touches storage: one that is absolute, has a `.`, `..` or empty segment, or
10
+ * contains a backslash or NUL. The port says so, not each adapter, because
11
+ * in the old repo only the Node adapter checked. Refusing `.` keeps `a/./b`
12
+ * from meaning `a/b` in a folder but another key in a key-value store.
13
+ *
14
+ * **Every method also refuses a private entry** with a `RangeError`, and
15
+ * `list()` leaves such entries out instead of throwing. A private entry is
16
+ * a path with a segment that, after the clean-up below, is `.git`,
17
+ * `.studio`, `.env` or `.envrc`, or starts with `.env.` (such as
18
+ * `.env.local`). The clean-up matches segments the way Windows and macOS
19
+ * would open them: it removes the code points HFS+ ignores (as git's
20
+ * `is_hfs_dotgit` does, so `.g\u200Cit` is `.git`), ignores case and
21
+ * removes trailing dots and spaces. Two more kinds of segment are private
22
+ * whatever their name: one that holds a `:`, because NTFS opens
23
+ * `.env::$DATA` as `.env`, and one that holds `~` followed by a digit,
24
+ * because that is how 8.3 short names look (`GIT~1`, `ENV~1.LOC`,
25
+ * `GI3F2A~1`), as git refuses for its own paths.
26
+ *
27
+ * **Any symbolic link** counts as private too, wherever it points, inside
28
+ * the root or not, and so do Windows junctions and other reparse points. A
29
+ * link in any segment counts, not only the last: a store that has links
30
+ * refuses to read, write or remove through one and doesn't list it or
31
+ * anything under it. This keeps the served Studio and agents away from git
32
+ * internals, Halonic's own data and secrets files.
33
+ *
34
+ * A cloud deployment hands out only this read side, so a stolen session can't
35
+ * change what runs.
36
+ */
37
+ export interface DefinitionSource {
38
+ /** Human-readable location, such as "~/workspaces/acme" or "memory:demo". */
39
+ readonly location: string;
40
+ /**
41
+ * Lists the file paths under a directory, recursively and sorted. The
42
+ * paths are relative to the store root, not to `dir`, as in the old
43
+ * adapter. Omit `dir` for the whole store; `""` is an empty path and is
44
+ * refused like any other unsafe path. A directory that doesn't exist
45
+ * gives `[]`. A folder under the root that the account may not read
46
+ * throws an `UnreadableWorkspaceFolderError` naming it, rather than being
47
+ * left out.
48
+ */
49
+ list(dir?: string): Promise<string[]>;
50
+ /** The file's text, or `null` when there is no such file. */
51
+ read(path: string): Promise<string | null>;
52
+ /**
53
+ * Identifier of the current version of the definitions (git commit, content
54
+ * hash). Runs record it so they can be explained and replayed later.
55
+ */
56
+ version(): Promise<string>;
57
+ }
58
+ /**
59
+ * What a caller expects a file to hold before it writes: the digest of the
60
+ * text it last read, or `"absent"` for a file that should not exist yet. The
61
+ * digest is `sha256:` and the 64 lowercase hex characters of the SHA-256 of
62
+ * the text's UTF-8 bytes: a fixed format, not one each store picks, so a
63
+ * caller can work it out from text it got elsewhere (a proposal's snapshot)
64
+ * and a watcher can recognise its own write. `contentDigest` and
65
+ * `matchesExpected` in `@halonicjs/std` work it out and compare it, so every
66
+ * store does both the same way.
67
+ */
68
+ export type ExpectedContent = `sha256:${string}` | "absent";
69
+ /** Options for {@link DefinitionStore.write}. */
70
+ export interface WriteOptions {
71
+ /**
72
+ * Write only if the file still holds this (save model 1.7). Leave it out
73
+ * to replace the file whatever it holds, as setting up a new workspace or
74
+ * checking out a version does. The Studio's saves always pass it.
75
+ */
76
+ readonly expected?: ExpectedContent;
77
+ }
78
+ /**
79
+ * What {@link DefinitionStore.write} did. `changed-on-disk` means the file
80
+ * no longer held what the caller expected, so nothing was written; `current`
81
+ * is its text now, or `null` when it is gone, so the Studio can show
82
+ * Compare without reading it again.
83
+ */
84
+ export type WriteResult = {
85
+ readonly status: "written";
86
+ } | {
87
+ readonly status: "changed-on-disk";
88
+ readonly current: string | null;
89
+ };
90
+ /**
91
+ * One workspace file that changed outside Halonic. `removed` means it is gone
92
+ * at the end of the batch; a file removed and created again, as many editors
93
+ * save, is `changed`. A folder that went away gives one `removed` per file
94
+ * that was in it.
95
+ */
96
+ export interface WorkspaceFileChange {
97
+ readonly path: string;
98
+ readonly kind: "changed" | "removed";
99
+ }
100
+ /** Who hears about changes from outside Halonic while a watch is open. */
101
+ export interface DefinitionWatchListener {
102
+ /**
103
+ * One batch of changes, each path at most once, sorted by path. Many
104
+ * changes close together (a checkout touching 50 files) come as one batch.
105
+ */
106
+ changed(changes: readonly WorkspaceFileChange[]): void;
107
+ /** The watch broke (the folder went away, say) and reports nothing more. */
108
+ failed(error: Error): void;
109
+ }
110
+ /** An open watch; see {@link DefinitionStore.watch}. */
111
+ export interface DefinitionWatch {
112
+ /** Stops the watch. No batch is reported after it resolves. */
113
+ close(): Promise<void>;
114
+ }
115
+ /** A {@link DefinitionSource} that can also change the files: the Studio's editors and `halonic serve` use it. */
116
+ export interface DefinitionStore extends DefinitionSource {
117
+ /**
118
+ * Creates or replaces a file, creating folders as needed. With
119
+ * `expected`, it first checks the file still holds what the caller last
120
+ * read and, if not, writes nothing and returns `changed-on-disk`.
121
+ */
122
+ write(path: string, content: string, options?: WriteOptions): Promise<WriteResult>;
123
+ /** Deletes a file. Deleting a file that isn't there is not an error. */
124
+ remove(path: string): Promise<void>;
125
+ /**
126
+ * Reports the files that change from outside Halonic (save model 6):
127
+ * another editor, a sync tool, `git pull`. A change is one whose text
128
+ * differs from what the store last saw, so the store's own writes and
129
+ * removes, and a file saved again with the same text, are not reported.
130
+ * Private entries are left out, as in `list()`. A store nothing else can
131
+ * change, such as one in memory, reports nothing.
132
+ */
133
+ watch(listener: DefinitionWatchListener): Promise<DefinitionWatch>;
134
+ }
135
+ /**
136
+ * What a {@link DefinitionSource}'s `list()` throws when the account may not
137
+ * read a folder under the store's root (requirement
138
+ * `ports.unreadable-workspace-folder`). Leaving the folder out instead would
139
+ * hide the agents in it without a word, which is worse than an error.
140
+ *
141
+ * `path` is the folder's workspace path, so a caller can name it without
142
+ * knowing where the store keeps its files. The message is for the log; keep
143
+ * the store's own error in `cause`.
144
+ *
145
+ * Check for it with {@link isUnreadableWorkspaceFolderError}, not
146
+ * `instanceof`: an adapter may be built against its own copy of this package.
147
+ *
148
+ * @example
149
+ * throw new UnreadableWorkspaceFolderError("hubs/support", "The folder can't be read.", { cause });
150
+ */
151
+ export declare class UnreadableWorkspaceFolderError extends Error {
152
+ readonly name = "UnreadableWorkspaceFolderError";
153
+ /** The folder's workspace path: relative and "/" separated, as the port's paths are. */
154
+ readonly path: string;
155
+ /**
156
+ * @param path - the folder's workspace path
157
+ * @param message - for the log
158
+ * @param options - `cause` keeps the error this one wraps
159
+ */
160
+ constructor(path: string, message: string, options?: {
161
+ cause?: unknown;
162
+ });
163
+ }
164
+ /**
165
+ * Whether `value` is an {@link UnreadableWorkspaceFolderError}: an `Error`
166
+ * named "UnreadableWorkspaceFolderError" with a `path`. It works across
167
+ * copies of this package, where `instanceof` doesn't.
168
+ *
169
+ * @example
170
+ * const folder = isUnreadableWorkspaceFolderError(error) ? error.path : null;
171
+ */
172
+ export declare function isUnreadableWorkspaceFolderError(value: unknown): value is UnreadableWorkspaceFolderError;
173
+ /**
174
+ * Refuses a workspace path the `DefinitionSource` port calls unsafe: one that
175
+ * is absolute, has a `.`, `..` or empty segment, or contains a backslash or
176
+ * NUL. Checked before the store is touched, so `a/./b` can never mean `a/b`.
177
+ *
178
+ * @throws RangeError naming the path and what is wrong with it
179
+ */
180
+ export declare function checkWorkspacePath(path: string): void;
181
+ /**
182
+ * Refuses an unsafe path, as {@link checkWorkspacePath} does, and also a
183
+ * private one (see {@link isPrivateWorkspacePath}). Every method that takes a path
184
+ * calls this.
185
+ *
186
+ * @throws RangeError naming the path and what is wrong with it
187
+ */
188
+ export declare function checkPublicWorkspacePath(path: string): void;
189
+ /**
190
+ * Whether a safe path has a private segment, as the port defines it: after
191
+ * removing the code points HFS+ ignores, ignoring case and removing trailing
192
+ * dots and spaces, `.git`, `.studio`, `.env`, `.envrc` or `.env.` and more;
193
+ * or, whatever its name, a segment with a `:` (an NTFS stream) or a `~`
194
+ * followed by a digit (an 8.3 short name).
195
+ */
196
+ export declare function isPrivateWorkspacePath(path: string): boolean;
197
+ /**
198
+ * A path segment the way Windows and macOS would open it, as the private
199
+ * rule above compares names: without the code points HFS+ ignores, with
200
+ * case folded as any file system might fold it, and without trailing dots
201
+ * and spaces. Another folder a store or decorator keeps to itself compares
202
+ * names the same way, so `.Halonic./x` can't get round a check for
203
+ * `.halonic/x`.
204
+ *
205
+ * @example
206
+ * segmentAsOpened(".G\u200CIT. "); // ".git"
207
+ */
208
+ export declare function segmentAsOpened(segment: string): string;
@@ -0,0 +1,122 @@
1
+ /** Version of the {@link DefinitionStore} and {@link DefinitionSource} ports. A breaking change bumps it and comes with an ADR. */
2
+ export const definitionStoreVersion = 2;
3
+ /**
4
+ * What a {@link DefinitionSource}'s `list()` throws when the account may not
5
+ * read a folder under the store's root (requirement
6
+ * `ports.unreadable-workspace-folder`). Leaving the folder out instead would
7
+ * hide the agents in it without a word, which is worse than an error.
8
+ *
9
+ * `path` is the folder's workspace path, so a caller can name it without
10
+ * knowing where the store keeps its files. The message is for the log; keep
11
+ * the store's own error in `cause`.
12
+ *
13
+ * Check for it with {@link isUnreadableWorkspaceFolderError}, not
14
+ * `instanceof`: an adapter may be built against its own copy of this package.
15
+ *
16
+ * @example
17
+ * throw new UnreadableWorkspaceFolderError("hubs/support", "The folder can't be read.", { cause });
18
+ */
19
+ export class UnreadableWorkspaceFolderError extends Error {
20
+ name = "UnreadableWorkspaceFolderError";
21
+ /** The folder's workspace path: relative and "/" separated, as the port's paths are. */
22
+ path;
23
+ /**
24
+ * @param path - the folder's workspace path
25
+ * @param message - for the log
26
+ * @param options - `cause` keeps the error this one wraps
27
+ */
28
+ constructor(path, message, options) {
29
+ super(message, options);
30
+ this.path = path;
31
+ }
32
+ }
33
+ /**
34
+ * Whether `value` is an {@link UnreadableWorkspaceFolderError}: an `Error`
35
+ * named "UnreadableWorkspaceFolderError" with a `path`. It works across
36
+ * copies of this package, where `instanceof` doesn't.
37
+ *
38
+ * @example
39
+ * const folder = isUnreadableWorkspaceFolderError(error) ? error.path : null;
40
+ */
41
+ export function isUnreadableWorkspaceFolderError(value) {
42
+ if (!(value instanceof Error) || value.name !== "UnreadableWorkspaceFolderError")
43
+ return false;
44
+ return typeof value.path === "string";
45
+ }
46
+ // The path rules above, as code, so every adapter refuses exactly the same paths.
47
+ /**
48
+ * Refuses a workspace path the `DefinitionSource` port calls unsafe: one that
49
+ * is absolute, has a `.`, `..` or empty segment, or contains a backslash or
50
+ * NUL. Checked before the store is touched, so `a/./b` can never mean `a/b`.
51
+ *
52
+ * @throws RangeError naming the path and what is wrong with it
53
+ */
54
+ export function checkWorkspacePath(path) {
55
+ if (path.includes("\\") || path.includes("\u0000")) {
56
+ throw new RangeError(`Unsafe workspace path ${JSON.stringify(path)}: no backslash or NUL.`);
57
+ }
58
+ if (path.startsWith("/")) {
59
+ throw new RangeError(`Unsafe workspace path ${JSON.stringify(path)}: it must be relative.`);
60
+ }
61
+ for (const segment of path.split("/")) {
62
+ if (segment === "" || segment === "." || segment === "..") {
63
+ throw new RangeError(`Unsafe workspace path ${JSON.stringify(path)}: no empty, "." or ".." segment.`);
64
+ }
65
+ }
66
+ }
67
+ /**
68
+ * Refuses an unsafe path, as {@link checkWorkspacePath} does, and also a
69
+ * private one (see {@link isPrivateWorkspacePath}). Every method that takes a path
70
+ * calls this.
71
+ *
72
+ * @throws RangeError naming the path and what is wrong with it
73
+ */
74
+ export function checkPublicWorkspacePath(path) {
75
+ checkWorkspacePath(path);
76
+ if (isPrivateWorkspacePath(path)) {
77
+ throw new RangeError(`Private workspace path ${JSON.stringify(path)}: the store doesn't serve it.`);
78
+ }
79
+ }
80
+ /** Code points HFS+ ignores in a name, as in git's `next_hfs_char`. */
81
+ const hfsIgnored = /[\u200C-\u200F\u202A-\u202E\u206A-\u206F\uFEFF]/gu;
82
+ /**
83
+ * Whether a safe path has a private segment, as the port defines it: after
84
+ * removing the code points HFS+ ignores, ignoring case and removing trailing
85
+ * dots and spaces, `.git`, `.studio`, `.env`, `.envrc` or `.env.` and more;
86
+ * or, whatever its name, a segment with a `:` (an NTFS stream) or a `~`
87
+ * followed by a digit (an 8.3 short name).
88
+ */
89
+ export function isPrivateWorkspacePath(path) {
90
+ return path.split("/").some(isPrivateSegment);
91
+ }
92
+ /**
93
+ * A path segment the way Windows and macOS would open it, as the private
94
+ * rule above compares names: without the code points HFS+ ignores, with
95
+ * case folded as any file system might fold it, and without trailing dots
96
+ * and spaces. Another folder a store or decorator keeps to itself compares
97
+ * names the same way, so `.Halonic./x` can't get round a check for
98
+ * `.halonic/x`.
99
+ *
100
+ * @example
101
+ * segmentAsOpened(".G\u200CIT. "); // ".git"
102
+ */
103
+ export function segmentAsOpened(segment) {
104
+ return (segment
105
+ .replace(hfsIgnored, "")
106
+ // Upper case first, so letters that fold to ASCII on some file system match
107
+ // too: a long s to `s`, an `st` ligature to `st`, a dotless i to `i`.
108
+ .toUpperCase()
109
+ .toLowerCase()
110
+ .replace(/[. ]+$/u, ""));
111
+ }
112
+ function isPrivateSegment(segment) {
113
+ if (segment.includes(":") || /~\d/u.test(segment)) {
114
+ return true;
115
+ }
116
+ const name = segmentAsOpened(segment);
117
+ return (name === ".git" ||
118
+ name === ".studio" ||
119
+ name === ".env" ||
120
+ name === ".envrc" ||
121
+ name.startsWith(".env."));
122
+ }