effect 4.0.6 → 4.0.7

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 (480) hide show
  1. package/dist/Arbitrary.d.ts +10 -2
  2. package/dist/Arbitrary.d.ts.map +1 -1
  3. package/dist/Arbitrary.js +2 -1
  4. package/dist/Arbitrary.js.map +1 -1
  5. package/dist/Channel.d.ts.map +1 -1
  6. package/dist/Channel.js +21 -6
  7. package/dist/Channel.js.map +1 -1
  8. package/dist/Data.d.ts +54 -235
  9. package/dist/Data.d.ts.map +1 -1
  10. package/dist/Data.js.map +1 -1
  11. package/dist/Effect.d.ts +1 -1
  12. package/dist/Effect.js +1 -1
  13. package/dist/Equal.d.ts.map +1 -1
  14. package/dist/Equal.js +8 -1
  15. package/dist/Equal.js.map +1 -1
  16. package/dist/Exit.d.ts +3 -3
  17. package/dist/Exit.d.ts.map +1 -1
  18. package/dist/Exit.js.map +1 -1
  19. package/dist/Formatter.d.ts.map +1 -1
  20. package/dist/Formatter.js +27 -13
  21. package/dist/Formatter.js.map +1 -1
  22. package/dist/Hash.d.ts.map +1 -1
  23. package/dist/Hash.js +4 -1
  24. package/dist/Hash.js.map +1 -1
  25. package/dist/JsonPatch.js +4 -0
  26. package/dist/JsonPatch.js.map +1 -1
  27. package/dist/JsonSchema.d.ts.map +1 -1
  28. package/dist/JsonSchema.js +13 -40
  29. package/dist/JsonSchema.js.map +1 -1
  30. package/dist/Metric.d.ts +3 -3
  31. package/dist/MutableList.d.ts +5 -2
  32. package/dist/MutableList.d.ts.map +1 -1
  33. package/dist/MutableList.js +7 -5
  34. package/dist/MutableList.js.map +1 -1
  35. package/dist/MutableRef.d.ts.map +1 -1
  36. package/dist/MutableRef.js +7 -0
  37. package/dist/MutableRef.js.map +1 -1
  38. package/dist/PartitionedSemaphore.d.ts +2 -1
  39. package/dist/PartitionedSemaphore.d.ts.map +1 -1
  40. package/dist/PartitionedSemaphore.js +22 -12
  41. package/dist/PartitionedSemaphore.js.map +1 -1
  42. package/dist/Pool.d.ts.map +1 -1
  43. package/dist/Pool.js +77 -27
  44. package/dist/Pool.js.map +1 -1
  45. package/dist/PubSub.d.ts.map +1 -1
  46. package/dist/PubSub.js +5 -6
  47. package/dist/PubSub.js.map +1 -1
  48. package/dist/Ref.d.ts.map +1 -1
  49. package/dist/Ref.js +8 -0
  50. package/dist/Ref.js.map +1 -1
  51. package/dist/Schedule.js +1 -1
  52. package/dist/Schedule.js.map +1 -1
  53. package/dist/Schema.d.ts +24 -8
  54. package/dist/Schema.d.ts.map +1 -1
  55. package/dist/Schema.js +37 -28
  56. package/dist/Schema.js.map +1 -1
  57. package/dist/SchemaAST.d.ts +4 -2
  58. package/dist/SchemaAST.d.ts.map +1 -1
  59. package/dist/SchemaAST.js +14 -17
  60. package/dist/SchemaAST.js.map +1 -1
  61. package/dist/SchemaParser.d.ts.map +1 -1
  62. package/dist/SchemaParser.js +48 -22
  63. package/dist/SchemaParser.js.map +1 -1
  64. package/dist/SchemaRepresentation.d.ts +19 -10
  65. package/dist/SchemaRepresentation.d.ts.map +1 -1
  66. package/dist/SchemaRepresentation.js +23 -13
  67. package/dist/SchemaRepresentation.js.map +1 -1
  68. package/dist/SchemaTransformation.d.ts +4 -1
  69. package/dist/SchemaTransformation.d.ts.map +1 -1
  70. package/dist/SchemaTransformation.js +9 -2
  71. package/dist/SchemaTransformation.js.map +1 -1
  72. package/dist/Semaphore.d.ts.map +1 -1
  73. package/dist/Semaphore.js +54 -35
  74. package/dist/Semaphore.js.map +1 -1
  75. package/dist/Sink.d.ts.map +1 -1
  76. package/dist/Sink.js +7 -2
  77. package/dist/Sink.js.map +1 -1
  78. package/dist/Stream.d.ts.map +1 -1
  79. package/dist/Stream.js +22 -10
  80. package/dist/Stream.js.map +1 -1
  81. package/dist/String.d.ts +3 -0
  82. package/dist/String.d.ts.map +1 -1
  83. package/dist/String.js +3 -0
  84. package/dist/String.js.map +1 -1
  85. package/dist/Tracer.d.ts +11 -1
  86. package/dist/Tracer.d.ts.map +1 -1
  87. package/dist/Tracer.js +6 -1
  88. package/dist/Tracer.js.map +1 -1
  89. package/dist/ai/LanguageModel.d.ts.map +1 -1
  90. package/dist/ai/LanguageModel.js +9 -0
  91. package/dist/ai/LanguageModel.js.map +1 -1
  92. package/dist/ai/McpSchema.d.ts +110 -110
  93. package/dist/ai/McpSchema.d.ts.map +1 -1
  94. package/dist/ai/McpServer.d.ts.map +1 -1
  95. package/dist/ai/McpServer.js +21 -15
  96. package/dist/ai/McpServer.js.map +1 -1
  97. package/dist/ai/Prompt.d.ts +52 -0
  98. package/dist/ai/Prompt.d.ts.map +1 -1
  99. package/dist/ai/Prompt.js +38 -0
  100. package/dist/ai/Prompt.js.map +1 -1
  101. package/dist/ai/Response.d.ts +16 -3
  102. package/dist/ai/Response.d.ts.map +1 -1
  103. package/dist/ai/Response.js +4 -0
  104. package/dist/ai/Response.js.map +1 -1
  105. package/dist/ai/Tool.d.ts +24 -0
  106. package/dist/ai/Tool.d.ts.map +1 -1
  107. package/dist/ai/Tool.js +5 -2
  108. package/dist/ai/Tool.js.map +1 -1
  109. package/dist/ai/Toolkit.d.ts.map +1 -1
  110. package/dist/ai/Toolkit.js +8 -1
  111. package/dist/ai/Toolkit.js.map +1 -1
  112. package/dist/cli/Argument.d.ts +15 -0
  113. package/dist/cli/Argument.d.ts.map +1 -1
  114. package/dist/cli/Argument.js +5 -0
  115. package/dist/cli/Argument.js.map +1 -1
  116. package/dist/cli/CliError.d.ts +78 -0
  117. package/dist/cli/CliError.d.ts.map +1 -1
  118. package/dist/cli/CliError.js +65 -3
  119. package/dist/cli/CliError.js.map +1 -1
  120. package/dist/cli/CliOutput.d.ts +155 -6
  121. package/dist/cli/CliOutput.d.ts.map +1 -1
  122. package/dist/cli/CliOutput.js +62 -6
  123. package/dist/cli/CliOutput.js.map +1 -1
  124. package/dist/cli/Command.d.ts +24 -16
  125. package/dist/cli/Command.d.ts.map +1 -1
  126. package/dist/cli/Command.js +59 -29
  127. package/dist/cli/Command.js.map +1 -1
  128. package/dist/cli/Completions.d.ts +58 -0
  129. package/dist/cli/Completions.d.ts.map +1 -1
  130. package/dist/cli/Completions.js +49 -9
  131. package/dist/cli/Completions.js.map +1 -1
  132. package/dist/cli/Flag.d.ts +15 -0
  133. package/dist/cli/Flag.d.ts.map +1 -1
  134. package/dist/cli/Flag.js +5 -0
  135. package/dist/cli/Flag.js.map +1 -1
  136. package/dist/cli/GlobalFlag.d.ts.map +1 -1
  137. package/dist/cli/GlobalFlag.js +15 -7
  138. package/dist/cli/GlobalFlag.js.map +1 -1
  139. package/dist/cli/Param.d.ts +9 -0
  140. package/dist/cli/Param.d.ts.map +1 -1
  141. package/dist/cli/Param.js +21 -2
  142. package/dist/cli/Param.js.map +1 -1
  143. package/dist/cli/TerminalCapabilities.d.ts +3 -2
  144. package/dist/cli/TerminalCapabilities.d.ts.map +1 -1
  145. package/dist/cli/TerminalCapabilities.js +3 -1
  146. package/dist/cli/TerminalCapabilities.js.map +1 -1
  147. package/dist/cli/internal/completions/bash.js +73 -27
  148. package/dist/cli/internal/completions/bash.js.map +1 -1
  149. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  150. package/dist/cluster/ClusterWorkflowEngine.js +45 -10
  151. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  152. package/dist/cluster/MessageStorage.d.ts +23 -45
  153. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  154. package/dist/cluster/MessageStorage.js +6 -7
  155. package/dist/cluster/MessageStorage.js.map +1 -1
  156. package/dist/cluster/Sharding.d.ts.map +1 -1
  157. package/dist/cluster/Sharding.js +61 -21
  158. package/dist/cluster/Sharding.js.map +1 -1
  159. package/dist/cluster/ShardingConfig.d.ts +10 -0
  160. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  161. package/dist/cluster/ShardingConfig.js.map +1 -1
  162. package/dist/cluster/Snowflake.d.ts.map +1 -1
  163. package/dist/cluster/Snowflake.js +3 -7
  164. package/dist/cluster/Snowflake.js.map +1 -1
  165. package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
  166. package/dist/cluster/SqlRunnerStorage.js +87 -39
  167. package/dist/cluster/SqlRunnerStorage.js.map +1 -1
  168. package/dist/cluster/internal/entityManager.js +54 -20
  169. package/dist/cluster/internal/entityManager.js.map +1 -1
  170. package/dist/devtools/DevToolsClient.d.ts.map +1 -1
  171. package/dist/devtools/DevToolsClient.js +2 -0
  172. package/dist/devtools/DevToolsClient.js.map +1 -1
  173. package/dist/encoding/Base64.js +36 -0
  174. package/dist/encoding/Base64.js.map +1 -1
  175. package/dist/encoding/Sse.d.ts.map +1 -1
  176. package/dist/encoding/Sse.js +3 -3
  177. package/dist/encoding/Sse.js.map +1 -1
  178. package/dist/encoding/Toml.d.ts.map +1 -1
  179. package/dist/encoding/Toml.js +21 -16
  180. package/dist/encoding/Toml.js.map +1 -1
  181. package/dist/eventlog/SqlEventJournal.d.ts.map +1 -1
  182. package/dist/eventlog/SqlEventJournal.js +47 -27
  183. package/dist/eventlog/SqlEventJournal.js.map +1 -1
  184. package/dist/eventlog/internal/conflicts.d.ts +0 -1
  185. package/dist/eventlog/internal/conflicts.d.ts.map +1 -1
  186. package/dist/eventlog/internal/conflicts.js +0 -3
  187. package/dist/eventlog/internal/conflicts.js.map +1 -1
  188. package/dist/http/Cookies.d.ts.map +1 -1
  189. package/dist/http/Cookies.js +10 -9
  190. package/dist/http/Cookies.js.map +1 -1
  191. package/dist/http/HttpClient.d.ts +423 -0
  192. package/dist/http/HttpClient.d.ts.map +1 -1
  193. package/dist/http/HttpClient.js +231 -7
  194. package/dist/http/HttpClient.js.map +1 -1
  195. package/dist/http/HttpClientError.d.ts +8 -1
  196. package/dist/http/HttpClientError.d.ts.map +1 -1
  197. package/dist/http/HttpClientError.js +37 -1
  198. package/dist/http/HttpClientError.js.map +1 -1
  199. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  200. package/dist/http/HttpClientRequest.js +1 -1
  201. package/dist/http/HttpClientRequest.js.map +1 -1
  202. package/dist/http/HttpMiddleware.d.ts +1 -1
  203. package/dist/http/HttpMiddleware.d.ts.map +1 -1
  204. package/dist/http/HttpMiddleware.js +14 -16
  205. package/dist/http/HttpMiddleware.js.map +1 -1
  206. package/dist/http/HttpRouter.d.ts.map +1 -1
  207. package/dist/http/HttpRouter.js +2 -1
  208. package/dist/http/HttpRouter.js.map +1 -1
  209. package/dist/http/HttpServerError.js +2 -2
  210. package/dist/http/HttpServerError.js.map +1 -1
  211. package/dist/http/HttpServerRequest.d.ts +6 -1
  212. package/dist/http/HttpServerRequest.d.ts.map +1 -1
  213. package/dist/http/HttpServerRequest.js +73 -10
  214. package/dist/http/HttpServerRequest.js.map +1 -1
  215. package/dist/http/HttpStaticServer.d.ts.map +1 -1
  216. package/dist/http/HttpStaticServer.js +48 -21
  217. package/dist/http/HttpStaticServer.js.map +1 -1
  218. package/dist/http/MultipartParser/internal/contentType.js +3 -3
  219. package/dist/http/UrlParams.d.ts +3 -1
  220. package/dist/http/UrlParams.d.ts.map +1 -1
  221. package/dist/http/UrlParams.js +4 -2
  222. package/dist/http/UrlParams.js.map +1 -1
  223. package/dist/http/internal/compression.js +4 -5
  224. package/dist/http/internal/compression.js.map +1 -1
  225. package/dist/http/internal/decompression.js +3 -0
  226. package/dist/http/internal/decompression.js.map +1 -1
  227. package/dist/http/internal/httpBody.js +8 -1
  228. package/dist/http/internal/httpBody.js.map +1 -1
  229. package/dist/http/internal/urlParams.js +25 -0
  230. package/dist/http/internal/urlParams.js.map +1 -1
  231. package/dist/http-api/HttpApi.d.ts +3 -6
  232. package/dist/http-api/HttpApi.d.ts.map +1 -1
  233. package/dist/http-api/HttpApi.js +3 -6
  234. package/dist/http-api/HttpApi.js.map +1 -1
  235. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  236. package/dist/http-api/HttpApiBuilder.js +27 -11
  237. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  238. package/dist/http-api/HttpApiClient.d.ts +77 -7
  239. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  240. package/dist/http-api/HttpApiClient.js +142 -44
  241. package/dist/http-api/HttpApiClient.js.map +1 -1
  242. package/dist/http-api/HttpApiEndpoint.d.ts +24 -7
  243. package/dist/http-api/HttpApiEndpoint.d.ts.map +1 -1
  244. package/dist/http-api/HttpApiEndpoint.js +109 -27
  245. package/dist/http-api/HttpApiEndpoint.js.map +1 -1
  246. package/dist/http-api/HttpApiSchema.d.ts +76 -29
  247. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  248. package/dist/http-api/HttpApiSchema.js +70 -59
  249. package/dist/http-api/HttpApiSchema.js.map +1 -1
  250. package/dist/http-api/HttpApiTest.d.ts.map +1 -1
  251. package/dist/http-api/HttpApiTest.js +3 -2
  252. package/dist/http-api/HttpApiTest.js.map +1 -1
  253. package/dist/http-api/OpenApi.d.ts.map +1 -1
  254. package/dist/http-api/OpenApi.js +25 -16
  255. package/dist/http-api/OpenApi.js.map +1 -1
  256. package/dist/http-api/internal/toCodecHttpProperties.d.ts +2 -0
  257. package/dist/http-api/internal/toCodecHttpProperties.d.ts.map +1 -0
  258. package/dist/http-api/internal/toCodecHttpProperties.js +38 -0
  259. package/dist/http-api/internal/toCodecHttpProperties.js.map +1 -0
  260. package/dist/internal/arbitrary/runner.d.ts.map +1 -1
  261. package/dist/internal/arbitrary/runner.js +120 -44
  262. package/dist/internal/arbitrary/runner.js.map +1 -1
  263. package/dist/internal/core.js +2 -0
  264. package/dist/internal/core.js.map +1 -1
  265. package/dist/internal/effect.js +21 -13
  266. package/dist/internal/effect.js.map +1 -1
  267. package/dist/internal/equal.js +14 -0
  268. package/dist/internal/equal.js.map +1 -1
  269. package/dist/internal/jsonSchema.d.ts +2 -0
  270. package/dist/internal/jsonSchema.d.ts.map +1 -0
  271. package/dist/internal/jsonSchema.js +28 -0
  272. package/dist/internal/jsonSchema.js.map +1 -0
  273. package/dist/internal/matcher.js +1 -1
  274. package/dist/internal/matcher.js.map +1 -1
  275. package/dist/internal/schema/compilerRegistry.js +4 -1
  276. package/dist/internal/schema/compilerRegistry.js.map +1 -1
  277. package/dist/internal/schema/content.d.ts +2 -0
  278. package/dist/internal/schema/content.d.ts.map +1 -0
  279. package/dist/internal/schema/content.js +13 -0
  280. package/dist/internal/schema/content.js.map +1 -0
  281. package/dist/internal/schema/fromJsonSchemaDocument.js +173 -185
  282. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  283. package/dist/internal/schema/fromRepresentation.js +2 -1
  284. package/dist/internal/schema/fromRepresentation.js.map +1 -1
  285. package/dist/internal/schema/standardSchema.js +8 -2
  286. package/dist/internal/schema/standardSchema.js.map +1 -1
  287. package/dist/internal/schema/toCodeDocument.js +3 -3
  288. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  289. package/dist/internal/schema/toCodec.js +21 -24
  290. package/dist/internal/schema/toCodec.js.map +1 -1
  291. package/dist/internal/schema/toJsonSchemaDocument.js +205 -140
  292. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
  293. package/dist/internal/schema/toRepresentation.js +107 -129
  294. package/dist/internal/schema/toRepresentation.js.map +1 -1
  295. package/dist/internal/sql.d.ts +2 -0
  296. package/dist/internal/sql.d.ts.map +1 -0
  297. package/dist/internal/sql.js +13 -0
  298. package/dist/internal/sql.js.map +1 -0
  299. package/dist/internal/version.js +1 -1
  300. package/dist/observability/OtlpProxy.d.ts +154 -0
  301. package/dist/observability/OtlpProxy.d.ts.map +1 -0
  302. package/dist/observability/OtlpProxy.js +235 -0
  303. package/dist/observability/OtlpProxy.js.map +1 -0
  304. package/dist/observability/OtlpTracer.d.ts.map +1 -1
  305. package/dist/observability/OtlpTracer.js +4 -0
  306. package/dist/observability/OtlpTracer.js.map +1 -1
  307. package/dist/observability/index.d.ts +5 -0
  308. package/dist/observability/index.d.ts.map +1 -1
  309. package/dist/observability/index.js +5 -0
  310. package/dist/observability/index.js.map +1 -1
  311. package/dist/persistence/CircuitBreaker.d.ts +897 -0
  312. package/dist/persistence/CircuitBreaker.d.ts.map +1 -0
  313. package/dist/persistence/CircuitBreaker.js +1165 -0
  314. package/dist/persistence/CircuitBreaker.js.map +1 -0
  315. package/dist/persistence/Redis.d.ts +78 -2
  316. package/dist/persistence/Redis.d.ts.map +1 -1
  317. package/dist/persistence/Redis.js +62 -7
  318. package/dist/persistence/Redis.js.map +1 -1
  319. package/dist/persistence/index.d.ts +5 -0
  320. package/dist/persistence/index.d.ts.map +1 -1
  321. package/dist/persistence/index.js +5 -0
  322. package/dist/persistence/index.js.map +1 -1
  323. package/dist/process/ChildProcess.d.ts +30 -4
  324. package/dist/process/ChildProcess.d.ts.map +1 -1
  325. package/dist/process/ChildProcess.js.map +1 -1
  326. package/dist/process/ChildProcessSpawner.d.ts +30 -0
  327. package/dist/process/ChildProcessSpawner.d.ts.map +1 -1
  328. package/dist/process/ChildProcessSpawner.js +5 -2
  329. package/dist/process/ChildProcessSpawner.js.map +1 -1
  330. package/dist/reactivity/AsyncResult.d.ts +1 -1
  331. package/dist/reactivity/AsyncResult.d.ts.map +1 -1
  332. package/dist/rpc/RpcClient.d.ts.map +1 -1
  333. package/dist/rpc/RpcClient.js +9 -8
  334. package/dist/rpc/RpcClient.js.map +1 -1
  335. package/dist/rpc/RpcSerialization.d.ts +14 -0
  336. package/dist/rpc/RpcSerialization.d.ts.map +1 -1
  337. package/dist/rpc/RpcSerialization.js +20 -8
  338. package/dist/rpc/RpcSerialization.js.map +1 -1
  339. package/dist/rpc/RpcServer.d.ts.map +1 -1
  340. package/dist/rpc/RpcServer.js +11 -1
  341. package/dist/rpc/RpcServer.js.map +1 -1
  342. package/dist/rpc/RpcTest.d.ts +1 -0
  343. package/dist/rpc/RpcTest.d.ts.map +1 -1
  344. package/dist/rpc/RpcTest.js +1 -0
  345. package/dist/rpc/RpcTest.js.map +1 -1
  346. package/dist/sql/Migrator.d.ts +2 -1
  347. package/dist/sql/Migrator.d.ts.map +1 -1
  348. package/dist/sql/Migrator.js +11 -8
  349. package/dist/sql/Migrator.js.map +1 -1
  350. package/dist/sql/SqlClient.d.ts +9 -4
  351. package/dist/sql/SqlClient.d.ts.map +1 -1
  352. package/dist/sql/SqlClient.js +8 -1
  353. package/dist/sql/SqlClient.js.map +1 -1
  354. package/dist/sql/SqlResolver.d.ts +4 -0
  355. package/dist/sql/SqlResolver.d.ts.map +1 -1
  356. package/dist/sql/SqlResolver.js +18 -4
  357. package/dist/sql/SqlResolver.js.map +1 -1
  358. package/dist/sql/Statement.d.ts +7 -0
  359. package/dist/sql/Statement.d.ts.map +1 -1
  360. package/dist/sql/Statement.js +21 -2
  361. package/dist/sql/Statement.js.map +1 -1
  362. package/dist/workflow/DurableDeferred.d.ts.map +1 -1
  363. package/dist/workflow/DurableDeferred.js +21 -2
  364. package/dist/workflow/DurableDeferred.js.map +1 -1
  365. package/package.json +1 -1
  366. package/src/Arbitrary.ts +10 -2
  367. package/src/Channel.ts +47 -18
  368. package/src/Data.ts +60 -265
  369. package/src/Effect.ts +1 -1
  370. package/src/Equal.ts +8 -1
  371. package/src/Exit.ts +3 -3
  372. package/src/Formatter.ts +28 -13
  373. package/src/Hash.ts +4 -1
  374. package/src/JsonPatch.ts +4 -0
  375. package/src/JsonSchema.ts +12 -40
  376. package/src/Metric.ts +3 -3
  377. package/src/MutableList.ts +7 -5
  378. package/src/MutableRef.ts +8 -1
  379. package/src/PartitionedSemaphore.ts +24 -13
  380. package/src/Pool.ts +109 -37
  381. package/src/PubSub.ts +5 -6
  382. package/src/Ref.ts +8 -0
  383. package/src/Schedule.ts +1 -1
  384. package/src/Schema.ts +48 -25
  385. package/src/SchemaAST.ts +20 -20
  386. package/src/SchemaParser.ts +51 -18
  387. package/src/SchemaRepresentation.ts +31 -34
  388. package/src/SchemaTransformation.ts +9 -2
  389. package/src/Semaphore.ts +67 -40
  390. package/src/Sink.ts +15 -2
  391. package/src/Stream.ts +33 -16
  392. package/src/String.ts +3 -0
  393. package/src/Tracer.ts +15 -1
  394. package/src/ai/LanguageModel.ts +9 -0
  395. package/src/ai/McpServer.ts +14 -13
  396. package/src/ai/Prompt.ts +65 -0
  397. package/src/ai/Response.ts +34 -9
  398. package/src/ai/Tool.ts +38 -2
  399. package/src/ai/Toolkit.ts +4 -1
  400. package/src/cli/Argument.ts +15 -0
  401. package/src/cli/CliError.ts +90 -3
  402. package/src/cli/CliOutput.ts +183 -6
  403. package/src/cli/Command.ts +53 -41
  404. package/src/cli/Completions.ts +51 -0
  405. package/src/cli/Flag.ts +15 -0
  406. package/src/cli/GlobalFlag.ts +6 -7
  407. package/src/cli/Param.ts +29 -6
  408. package/src/cli/TerminalCapabilities.ts +6 -3
  409. package/src/cli/internal/completions/bash.ts +79 -29
  410. package/src/cluster/ClusterWorkflowEngine.ts +46 -16
  411. package/src/cluster/MessageStorage.ts +19 -14
  412. package/src/cluster/Sharding.ts +83 -21
  413. package/src/cluster/ShardingConfig.ts +5 -0
  414. package/src/cluster/Snowflake.ts +3 -7
  415. package/src/cluster/SqlRunnerStorage.ts +110 -47
  416. package/src/cluster/internal/entityManager.ts +75 -22
  417. package/src/devtools/DevToolsClient.ts +2 -0
  418. package/src/encoding/Base64.ts +38 -0
  419. package/src/encoding/Sse.ts +4 -3
  420. package/src/encoding/Toml.ts +33 -16
  421. package/src/eventlog/SqlEventJournal.ts +68 -45
  422. package/src/eventlog/internal/conflicts.ts +0 -4
  423. package/src/http/Cookies.ts +10 -11
  424. package/src/http/HttpClient.ts +547 -7
  425. package/src/http/HttpClientError.ts +35 -1
  426. package/src/http/HttpClientRequest.ts +9 -1
  427. package/src/http/HttpMiddleware.ts +15 -18
  428. package/src/http/HttpRouter.ts +2 -1
  429. package/src/http/HttpServerError.ts +2 -2
  430. package/src/http/HttpServerRequest.ts +102 -16
  431. package/src/http/HttpStaticServer.ts +51 -22
  432. package/src/http/MultipartParser/internal/contentType.ts +3 -3
  433. package/src/http/UrlParams.ts +6 -1
  434. package/src/http/internal/compression.ts +4 -5
  435. package/src/http/internal/decompression.ts +6 -0
  436. package/src/http/internal/httpBody.ts +10 -2
  437. package/src/http/internal/urlParams.ts +29 -0
  438. package/src/http-api/HttpApi.ts +3 -6
  439. package/src/http-api/HttpApiBuilder.ts +45 -15
  440. package/src/http-api/HttpApiClient.ts +218 -72
  441. package/src/http-api/HttpApiEndpoint.ts +121 -30
  442. package/src/http-api/HttpApiSchema.ts +141 -48
  443. package/src/http-api/HttpApiTest.ts +3 -2
  444. package/src/http-api/OpenApi.ts +20 -17
  445. package/src/http-api/internal/toCodecHttpProperties.ts +56 -0
  446. package/src/internal/arbitrary/runner.ts +133 -36
  447. package/src/internal/core.ts +2 -0
  448. package/src/internal/effect.ts +24 -16
  449. package/src/internal/equal.ts +17 -0
  450. package/src/internal/jsonSchema.ts +27 -0
  451. package/src/internal/matcher.ts +1 -1
  452. package/src/internal/schema/compilerRegistry.ts +6 -1
  453. package/src/internal/schema/content.ts +18 -0
  454. package/src/internal/schema/fromJsonSchemaDocument.ts +228 -190
  455. package/src/internal/schema/fromRepresentation.ts +2 -1
  456. package/src/internal/schema/standardSchema.ts +2 -2
  457. package/src/internal/schema/toCodeDocument.ts +4 -4
  458. package/src/internal/schema/toCodec.ts +26 -22
  459. package/src/internal/schema/toJsonSchemaDocument.ts +189 -167
  460. package/src/internal/schema/toRepresentation.ts +122 -140
  461. package/src/internal/sql.ts +14 -0
  462. package/src/internal/version.ts +1 -1
  463. package/src/observability/OtlpProxy.ts +314 -0
  464. package/src/observability/OtlpTracer.ts +4 -0
  465. package/src/observability/index.ts +6 -0
  466. package/src/persistence/CircuitBreaker.ts +1678 -0
  467. package/src/persistence/Redis.ts +129 -8
  468. package/src/persistence/index.ts +6 -0
  469. package/src/process/ChildProcess.ts +30 -4
  470. package/src/process/ChildProcessSpawner.ts +41 -2
  471. package/src/reactivity/AsyncResult.ts +1 -1
  472. package/src/rpc/RpcClient.ts +13 -10
  473. package/src/rpc/RpcSerialization.ts +32 -9
  474. package/src/rpc/RpcServer.ts +16 -1
  475. package/src/rpc/RpcTest.ts +3 -0
  476. package/src/sql/Migrator.ts +12 -7
  477. package/src/sql/SqlClient.ts +11 -4
  478. package/src/sql/SqlResolver.ts +23 -9
  479. package/src/sql/Statement.ts +30 -2
  480. package/src/workflow/DurableDeferred.ts +23 -6
@@ -1,22 +1,24 @@
1
1
  /**
2
- * Formats CLI help and errors as text.
2
+ * Formats and presents CLI help, errors, and version information.
3
3
  *
4
- * This module turns help documents, CLI errors, grouped errors, and version
5
- * information into strings. It does not write those strings to the terminal
6
- * itself. It includes the `Formatter` interface, the formatter service, a layer
7
- * for custom formatters, and the default formatter with configurable color
8
- * support.
4
+ * The `Formatter` service turns help documents, errors, and version
5
+ * information into strings. The `Presenter` service decides where the built-in
6
+ * help, version, and invalid-invocation output of `Command.runWith` is written,
7
+ * and can be replaced to suppress or redirect it.
9
8
  *
10
9
  * @stability unstable
11
10
  * @since 4.0.0
12
11
  */
13
12
 
13
+ import * as Console from "../Console.ts"
14
14
  import * as Context from "../Context.ts"
15
+ import * as Effect from "../Effect.ts"
15
16
  import * as Layer from "../Layer.ts"
16
17
  import * as Option from "../Option.ts"
17
18
  import type * as CliError from "./CliError.ts"
18
19
  import type { HelpDoc } from "./HelpDoc.ts"
19
20
  import * as Ansi from "./internal/ansi.ts"
21
+ import * as TerminalCapabilities from "./TerminalCapabilities.ts"
20
22
 
21
23
  /**
22
24
  * Defines the service interface for formatting CLI output including help, errors, and version info.
@@ -205,6 +207,124 @@ export interface Formatter {
205
207
  readonly formatErrors: (errors: ReadonlyArray<CliError.CliError>) => string
206
208
  }
207
209
 
210
+ /**
211
+ * Presents the built-in help, version, and invalid-invocation output of
212
+ * `Command.runWith`.
213
+ *
214
+ * **When to use**
215
+ *
216
+ * Use to suppress, redirect, or replace that output, for example to keep
217
+ * stdout clean for machine-readable results.
218
+ *
219
+ * **Details**
220
+ *
221
+ * Events carry the help document and errors rather than rendered text, so a
222
+ * presenter can still render them with the `Formatter` service. Presenting an
223
+ * event does not change the result of the run: implicit help and invalid
224
+ * invocations still fail with `CliError.ShowHelp`.
225
+ *
226
+ * **Gotchas**
227
+ *
228
+ * `--completions` scripts, wizard mode output, and handler failures rendered
229
+ * through `CliError.userMessage` do not go through the presenter.
230
+ *
231
+ * **Example** (Writing invalid-invocation output to stderr)
232
+ *
233
+ * ```ts import.meta.vitest
234
+ * import { Console, Effect } from "effect"
235
+ * import { CliOutput } from "effect/cli"
236
+ *
237
+ * const StderrPresenter = CliOutput.layerPresenter({
238
+ * present: (event) =>
239
+ * event._tag === "InvalidInvocation"
240
+ * ? Effect.gen(function*() {
241
+ * const formatter = yield* CliOutput.Formatter
242
+ * yield* Console.error(formatter.formatHelpDoc(event.helpDoc))
243
+ * yield* Console.error(formatter.formatErrors(event.errors))
244
+ * })
245
+ * : CliOutput.defaultPresenter.present(event)
246
+ * })
247
+ * ```
248
+ *
249
+ * @see {@link defaultPresenter} for the default console output
250
+ * @stability unstable
251
+ * @category models
252
+ * @since 4.0.0
253
+ */
254
+ export interface Presenter {
255
+ /**
256
+ * Presents a CLI output event.
257
+ *
258
+ * @stability unstable
259
+ * @since 4.0.0
260
+ */
261
+ readonly present: (event: Presenter.Event) => Effect.Effect<void>
262
+ }
263
+
264
+ /**
265
+ * Types used by the `Presenter` service.
266
+ *
267
+ * @stability unstable
268
+ * @since 4.0.0
269
+ */
270
+ export declare namespace Presenter {
271
+ /**
272
+ * Output events produced while running a CLI command.
273
+ *
274
+ * @stability unstable
275
+ * @category models
276
+ * @since 4.0.0
277
+ */
278
+ export type Event = Help | InvalidInvocation | Version
279
+
280
+ /**
281
+ * Help for a command path.
282
+ *
283
+ * **Details**
284
+ *
285
+ * `reason` is `"Requested"` for `--help`, and `"Implicit"` when the run
286
+ * fails with a `CliError.ShowHelp` that carries no errors, such as selecting
287
+ * a command that has no handler, or when `renderErrors` is `false`.
288
+ *
289
+ * @stability unstable
290
+ * @category models
291
+ * @since 4.0.0
292
+ */
293
+ export interface Help {
294
+ readonly _tag: "Help"
295
+ readonly reason: "Requested" | "Implicit"
296
+ readonly commandPath: ReadonlyArray<string>
297
+ readonly helpDoc: HelpDoc
298
+ }
299
+
300
+ /**
301
+ * Help and parse or validation errors for an invalid invocation.
302
+ *
303
+ * @stability unstable
304
+ * @category models
305
+ * @since 4.0.0
306
+ */
307
+ export interface InvalidInvocation {
308
+ readonly _tag: "InvalidInvocation"
309
+ readonly commandPath: ReadonlyArray<string>
310
+ readonly helpDoc: HelpDoc
311
+ readonly errors: ReadonlyArray<CliError.NonShowHelpErrors>
312
+ }
313
+
314
+ /**
315
+ * Version information requested with `--version`.
316
+ *
317
+ * @stability unstable
318
+ * @category models
319
+ * @since 4.0.0
320
+ */
321
+ export interface Version {
322
+ readonly _tag: "Version"
323
+ readonly name: string
324
+ readonly version: string
325
+ }
326
+ }
327
+
208
328
  /**
209
329
  * Service reference for the CLI output formatter. Provides a default implementation
210
330
  * that can be overridden for custom formatting or testing.
@@ -238,6 +358,53 @@ export const Formatter: Context.Reference<Formatter> = Context.Reference(
238
358
  { defaultValue: () => defaultFormatter() }
239
359
  )
240
360
 
361
+ /**
362
+ * Default presenter that renders events with the current `Formatter` and
363
+ * writes them with `Console`.
364
+ *
365
+ * **Details**
366
+ *
367
+ * Help and version output goes to `Console.log`. Invalid invocations write
368
+ * help to `Console.log` and errors to `Console.error`. When no `Formatter` is
369
+ * installed, the default formatter colors output when `TerminalCapabilities`
370
+ * says it can.
371
+ *
372
+ * @see {@link Presenter} for replacing the default output
373
+ * @stability unstable
374
+ * @category defaults
375
+ * @since 4.0.0
376
+ */
377
+ export const defaultPresenter: Presenter = {
378
+ present: Effect.fnUntraced(function*(event) {
379
+ const context = yield* Effect.context<never>()
380
+ const formatter = Context.getOrUndefined(context, Formatter) ??
381
+ defaultFormatter({ colors: Context.get(context, TerminalCapabilities.TerminalCapabilities).canColor })
382
+ switch (event._tag) {
383
+ case "Help":
384
+ return yield* Console.log(formatter.formatHelpDoc(event.helpDoc))
385
+ case "InvalidInvocation":
386
+ yield* Console.log(formatter.formatHelpDoc(event.helpDoc))
387
+ return yield* Console.error(formatter.formatErrors(event.errors))
388
+ case "Version":
389
+ return yield* Console.log(formatter.formatVersion(event.name, event.version))
390
+ }
391
+ })
392
+ }
393
+
394
+ /**
395
+ * Service reference for the CLI output presenter. Defaults to
396
+ * `defaultPresenter`.
397
+ *
398
+ * @see {@link layerPresenter} for providing a custom presenter
399
+ * @stability unstable
400
+ * @category services
401
+ * @since 4.0.0
402
+ */
403
+ export const Presenter: Context.Reference<Presenter> = Context.Reference(
404
+ "effect/cli/CliOutput/Presenter",
405
+ { defaultValue: () => defaultPresenter }
406
+ )
407
+
241
408
  /**
242
409
  * Creates a Layer that provides a custom Formatter implementation.
243
410
  *
@@ -268,6 +435,16 @@ export const Formatter: Context.Reference<Formatter> = Context.Reference(
268
435
  */
269
436
  export const layer = (formatter: Formatter): Layer.Layer<never> => Layer.succeed(Formatter)(formatter)
270
437
 
438
+ /**
439
+ * Creates a Layer that provides a custom Presenter implementation.
440
+ *
441
+ * @see {@link Presenter} for the events a presenter receives
442
+ * @stability unstable
443
+ * @category layers
444
+ * @since 4.0.0
445
+ */
446
+ export const layerPresenter = (presenter: Presenter): Layer.Layer<never> => Layer.succeed(Presenter)(presenter)
447
+
271
448
  const escapeControlCharacters = (text: string): string =>
272
449
  // oxlint-disable-next-line no-control-regex
273
450
  text.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, (character) =>
@@ -30,6 +30,7 @@ import * as Terminal from "../Terminal.ts"
30
30
  import type { Contravariant, Covariant, NoInfer, Simplify } from "../Types.ts"
31
31
  import * as CliConfig from "./CliConfig.ts"
32
32
  import * as CliError from "./CliError.ts"
33
+ import * as CliOutput from "./CliOutput.ts"
33
34
  import * as GlobalFlag from "./GlobalFlag.ts"
34
35
  import { checkForDuplicateFlags, makeCommand, makeParser, toImpl, TypeId } from "./internal/command.ts"
35
36
  import { mergeConfig, parseConfig } from "./internal/config.ts"
@@ -3062,19 +3063,24 @@ const showHelp = <Name extends string, Input, E, R, ContextInput>(
3062
3063
  ): Effect.Effect<void, CliError.CliError, Environment> =>
3063
3064
  Effect.gen(function*() {
3064
3065
  const { builtIns } = yield* CliConfig.CliConfig
3065
- const formatter = yield* resolveFormatter
3066
- const helpDoc = yield* getHelpForCommandPath(command, error.commandPath, builtIns)
3067
- yield* Console.log(formatter.formatHelpDoc(helpDoc))
3068
- if (renderErrors && error.errors.length > 0) {
3069
- yield* Console.error(formatter.formatErrors(error.errors as any))
3070
- }
3066
+ const presenter = yield* CliOutput.Presenter
3067
+ const { commandPath, errors } = error
3068
+ const helpDoc = yield* getHelpForCommandPath(command, commandPath, builtIns)
3069
+ yield* presenter.present(
3070
+ renderErrors && errors.length > 0
3071
+ ? { _tag: "InvalidInvocation", commandPath, helpDoc, errors }
3072
+ : { _tag: "Help", reason: "Implicit", commandPath, helpDoc }
3073
+ )
3071
3074
  })
3072
3075
 
3073
- const showUserError = (error: CliError.UserError): Effect.Effect<void> =>
3076
+ const showUserError = (error: object, userMessage: string): Effect.Effect<void> =>
3074
3077
  Effect.gen(function*() {
3075
3078
  const formatter = yield* resolveFormatter
3076
- yield* Console.error(formatter.formatError(error))
3077
- error[Runtime.errorReported] = false
3079
+ const rendered = error instanceof CliError.UserError
3080
+ ? error
3081
+ : new CliError.UserError({ cause: error, userMessage })
3082
+ yield* Console.error(formatter.formatError(rendered))
3083
+ Object.assign(error, { [Runtime.errorReported]: false })
3078
3084
  })
3079
3085
 
3080
3086
  /**
@@ -3085,10 +3091,12 @@ const showUserError = (error: CliError.UserError): Effect.Effect<void> =>
3085
3091
  * Use when command-line arguments should come from `Stdio` at the application
3086
3092
  * entry point.
3087
3093
  *
3088
- * Help documents are always rendered. By default, parse error details and
3089
- * `CliError.UserError` failures are also rendered with the installed
3090
- * `CliOutput.Formatter` before the error is rethrown. Set `renderErrors` to
3091
- * `false` when the host application owns error rendering.
3094
+ * Help, version, and parse error output is written through
3095
+ * `CliOutput.Presenter`. Help documents are always presented. By default,
3096
+ * parse error details are also presented, and handler failures annotated with
3097
+ * `CliError.userMessage`, including `CliError.UserError`, are rendered with the
3098
+ * installed `CliOutput.Formatter` before the error is rethrown. Set
3099
+ * `renderErrors` to `false` when the host application owns error rendering.
3092
3100
  *
3093
3101
  * **Example** (Running commands with standard input)
3094
3102
  *
@@ -3148,10 +3156,12 @@ export const run: {
3148
3156
  * Use when command-line arguments should come from `Stdio` at the application
3149
3157
  * entry point.
3150
3158
  *
3151
- * Help documents are always rendered. By default, parse error details and
3152
- * `CliError.UserError` failures are also rendered with the installed
3153
- * `CliOutput.Formatter` before the error is rethrown. Set `renderErrors` to
3154
- * `false` when the host application owns error rendering.
3159
+ * Help, version, and parse error output is written through
3160
+ * `CliOutput.Presenter`. Help documents are always presented. By default,
3161
+ * parse error details are also presented, and handler failures annotated with
3162
+ * `CliError.userMessage`, including `CliError.UserError`, are rendered with the
3163
+ * installed `CliOutput.Formatter` before the error is rethrown. Set
3164
+ * `renderErrors` to `false` when the host application owns error rendering.
3155
3165
  *
3156
3166
  * **Example** (Running commands with standard input)
3157
3167
  *
@@ -3218,10 +3228,12 @@ export const run: {
3218
3228
  * Use when command-line arguments should come from `Stdio` at the application
3219
3229
  * entry point.
3220
3230
  *
3221
- * Help documents are always rendered. By default, parse error details and
3222
- * `CliError.UserError` failures are also rendered with the installed
3223
- * `CliOutput.Formatter` before the error is rethrown. Set `renderErrors` to
3224
- * `false` when the host application owns error rendering.
3231
+ * Help, version, and parse error output is written through
3232
+ * `CliOutput.Presenter`. Help documents are always presented. By default,
3233
+ * parse error details are also presented, and handler failures annotated with
3234
+ * `CliError.userMessage`, including `CliError.UserError`, are rendered with the
3235
+ * installed `CliOutput.Formatter` before the error is rethrown. Set
3236
+ * `renderErrors` to `false` when the host application owns error rendering.
3225
3237
  *
3226
3238
  * **Example** (Running commands with standard input)
3227
3239
  *
@@ -3301,10 +3313,12 @@ export const run: {
3301
3313
  * Use when you need to test CLI applications or programmatically execute
3302
3314
  * commands with specific arguments.
3303
3315
  *
3304
- * Help documents are always rendered. By default, parse error details and
3305
- * `CliError.UserError` failures are also rendered with the installed
3306
- * `CliOutput.Formatter` before the error is rethrown. Set `renderErrors` to
3307
- * `false` when the host application owns error rendering.
3316
+ * Help, version, and parse error output is written through
3317
+ * `CliOutput.Presenter`. Help documents are always presented. By default,
3318
+ * parse error details are also presented, and handler failures annotated with
3319
+ * `CliError.userMessage`, including `CliError.UserError`, are rendered with the
3320
+ * installed `CliOutput.Formatter` before the error is rethrown. Set
3321
+ * `renderErrors` to `false` when the host application owns error rendering.
3308
3322
  *
3309
3323
  * **Example** (Running commands with explicit arguments)
3310
3324
  *
@@ -3387,6 +3401,9 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
3387
3401
  // 3. Parse command arguments from remaining tokens
3388
3402
  const parsedArgs = yield* Parser.parseArgs({ tokens: remainder, trailingOperands }, command)
3389
3403
  const commandPath = [command.name, ...Parser.getCommandPath(parsedArgs)] as const
3404
+ const toShowHelp = Effect.mapError((error: CliError.CliError) =>
3405
+ error._tag === "ShowHelp" ? error : new CliError.ShowHelp({ commandPath, errors: [error] })
3406
+ )
3390
3407
  const handlerCtx: GlobalFlag.HandlerContext = { builtIns, command, commandPath, version: config.version }
3391
3408
  const activeFlags = getGlobalFlagsForCommandPath(command, commandPath, builtIns)
3392
3409
 
@@ -3409,7 +3426,7 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
3409
3426
  return entries !== undefined && entries.length > 0
3410
3427
  })
3411
3428
  if (!hasEntry) continue
3412
- const [, value] = yield* flag.flag.parse(emptyArgs)
3429
+ const [, value] = yield* flag.flag.parse(emptyArgs).pipe(toShowHelp)
3413
3430
  if (flag === GlobalFlag.Wizard) {
3414
3431
  const { colors } = yield* Prompt.Theme
3415
3432
  return yield* Effect.gen(function*() {
@@ -3442,23 +3459,17 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
3442
3459
  if (parsedArgs.errors && parsedArgs.errors.length > 0) {
3443
3460
  return yield* new CliError.ShowHelp({ commandPath, errors: parsedArgs.errors })
3444
3461
  }
3445
- const parseResult = yield* Effect.result(commandImpl.parse(parsedArgs))
3446
- if (parseResult._tag === "Failure") {
3447
- return yield* new CliError.ShowHelp({
3448
- commandPath,
3449
- errors: [parseResult.failure as CliError.NonShowHelpErrors]
3450
- })
3451
- }
3462
+ const input = yield* commandImpl.parse(parsedArgs).pipe(toShowHelp)
3452
3463
 
3453
3464
  // 7. Provide setting values
3454
- let program = commandImpl.handle(parseResult.success, [command.name])
3465
+ let program = commandImpl.handle(input, [command.name])
3455
3466
  const logLevel = activeFlags.includes(GlobalFlag.LogLevel)
3456
- ? (yield* GlobalFlag.LogLevel.flag.parse(emptyArgs))[1]
3467
+ ? (yield* GlobalFlag.LogLevel.flag.parse(emptyArgs).pipe(toShowHelp))[1]
3457
3468
  : Option.none()
3458
3469
  program = Effect.provideService(program, GlobalFlag.LogLevel, logLevel)
3459
3470
  for (const flag of activeFlags) {
3460
3471
  if (flag._tag !== "Setting" || flag === GlobalFlag.LogLevel) continue
3461
- const [, value] = yield* flag.flag.parse(emptyArgs)
3472
+ const [, value] = yield* flag.flag.parse(emptyArgs).pipe(toShowHelp)
3462
3473
  program = Effect.provideService(program, flag, value)
3463
3474
  }
3464
3475
 
@@ -3479,11 +3490,12 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
3479
3490
  (error) => Effect.andThen(showHelp(command, error, config.renderErrors !== false), Effect.fail(error))
3480
3491
  ),
3481
3492
  Effect.catchFilter(
3482
- (error) =>
3483
- config.renderErrors !== false && CliError.isCliError(error) && error._tag === "UserError"
3484
- ? Result.succeed(error)
3485
- : Result.fail(error),
3486
- (error) => Effect.andThen(showUserError(error), Effect.fail(error))
3493
+ (error) => {
3494
+ if (config.renderErrors === false || !Predicate.isObjectKeyword(error)) return Result.fail(error)
3495
+ const userMessage = CliError.getUserMessage(error)
3496
+ return userMessage === undefined ? Result.fail(error) : Result.succeed({ error, userMessage })
3497
+ },
3498
+ ({ error, userMessage }) => Effect.andThen(showUserError(error, userMessage), Effect.fail(error))
3487
3499
  ),
3488
3500
  Effect.catchFilter(
3489
3501
  (e) =>
@@ -7,7 +7,9 @@
7
7
  * @stability unstable
8
8
  * @since 4.0.0
9
9
  */
10
+ import type { Command } from "./Command.ts"
10
11
  import * as Bash from "./internal/completions/bash.ts"
12
+ import * as Descriptor from "./internal/completions/descriptor.ts"
11
13
  import * as Fish from "./internal/completions/fish.ts"
12
14
  import * as PowerShell from "./internal/completions/powershell.ts"
13
15
  import * as Zsh from "./internal/completions/zsh.ts"
@@ -106,6 +108,55 @@ export type ArgumentType =
106
108
  | { readonly _tag: "Choice"; readonly values: ReadonlyArray<string> }
107
109
  | { readonly _tag: "Path"; readonly pathType: "file" | "directory" | "either" }
108
110
 
111
+ /**
112
+ * Converts a command tree into a `CommandDescriptor` for completion script
113
+ * generation.
114
+ *
115
+ * **When to use**
116
+ *
117
+ * Use when you need to generate a completion script from an existing
118
+ * `Command`, for example in a build step, without running the CLI or
119
+ * capturing the output of the built-in `--completions` flag.
120
+ *
121
+ * **Details**
122
+ *
123
+ * Reads the command's flags, arguments, and subcommands, including flags
124
+ * shared with subcommands and aliases. Hidden flags and unlisted subcommands
125
+ * are omitted, matching `--help`. Command handlers are never run.
126
+ *
127
+ * **Example** (Generating a Zsh completion script at build time)
128
+ *
129
+ * ```ts import.meta.vitest
130
+ * import { Effect } from "effect"
131
+ * import { Command, Completions, Flag } from "effect/cli"
132
+ *
133
+ * const start = Command.make(
134
+ * "start",
135
+ * { port: Flag.Int("port") },
136
+ * ({ port }) => Effect.log(`Listening on ${port}`)
137
+ * )
138
+ *
139
+ * const cli = Command.make("server").pipe(
140
+ * Command.withSubcommands([start])
141
+ * )
142
+ *
143
+ * const script = Completions.generate(
144
+ * "server",
145
+ * "zsh",
146
+ * Completions.fromCommand(cli)
147
+ * )
148
+ *
149
+ * script.startsWith("#compdef server") // => true
150
+ * ```
151
+ *
152
+ * @see {@link generate} for turning the descriptor into a shell script
153
+ *
154
+ * @stability unstable
155
+ * @category constructors
156
+ * @since 4.0.7
157
+ */
158
+ export const fromCommand = (command: Command.Any): CommandDescriptor => Descriptor.fromCommand(command)
159
+
109
160
  /**
110
161
  * Generates a shell completion script for a command descriptor.
111
162
  *
package/src/cli/Flag.ts CHANGED
@@ -1155,6 +1155,11 @@ export const withFallbackConfig: {
1155
1155
  /**
1156
1156
  * Adds a fallback prompt that is shown when a required flag is missing.
1157
1157
  *
1158
+ * **Gotchas**
1159
+ *
1160
+ * When `TerminalCapabilities.canPrompt` is `false`, the prompt is skipped and
1161
+ * the original `MissingOption` error is returned.
1162
+ *
1158
1163
  * **Example** (Falling back to prompts)
1159
1164
  *
1160
1165
  * ```ts import.meta.vitest
@@ -1174,6 +1179,11 @@ export const withFallbackPrompt: {
1174
1179
  /**
1175
1180
  * Adds a fallback prompt that is shown when a required flag is missing.
1176
1181
  *
1182
+ * **Gotchas**
1183
+ *
1184
+ * When `TerminalCapabilities.canPrompt` is `false`, the prompt is skipped and
1185
+ * the original `MissingOption` error is returned.
1186
+ *
1177
1187
  * **Example** (Falling back to prompts)
1178
1188
  *
1179
1189
  * ```ts import.meta.vitest
@@ -1193,6 +1203,11 @@ export const withFallbackPrompt: {
1193
1203
  /**
1194
1204
  * Adds a fallback prompt that is shown when a required flag is missing.
1195
1205
  *
1206
+ * **Gotchas**
1207
+ *
1208
+ * When `TerminalCapabilities.canPrompt` is `false`, the prompt is skipped and
1209
+ * the original `MissingOption` error is returned.
1210
+ *
1196
1211
  * **Example** (Falling back to prompts)
1197
1212
  *
1198
1213
  * ```ts import.meta.vitest
@@ -17,11 +17,10 @@ import * as Context from "../Context.ts"
17
17
  import * as Effect from "../Effect.ts"
18
18
  import type { LogLevel as LogLevelType } from "../LogLevel.ts"
19
19
  import * as Option from "../Option.ts"
20
+ import * as CliOutput from "./CliOutput.ts"
20
21
  import type * as Command from "./Command.ts"
21
22
  import * as Completions_ from "./Completions.ts"
22
23
  import * as Flag from "./Flag.ts"
23
- import * as CommandDescriptor from "./internal/completions/descriptor.ts"
24
- import { resolveFormatter } from "./internal/formatter.ts"
25
24
  import * as HelpInternal from "./internal/help.ts"
26
25
 
27
26
  /* ========================================================================== */
@@ -169,9 +168,9 @@ export const Help: Action<boolean> = Action({
169
168
  Flag.withDefault(false)
170
169
  ),
171
170
  run: Effect.fnUntraced(function*(_, { builtIns, command, commandPath }) {
172
- const formatter = yield* resolveFormatter
171
+ const presenter = yield* CliOutput.Presenter
173
172
  const helpDoc = yield* HelpInternal.getHelpForCommandPath(command, commandPath, builtIns)
174
- yield* Console.log(formatter.formatHelpDoc(helpDoc))
173
+ yield* presenter.present({ _tag: "Help", reason: "Requested", commandPath, helpDoc })
175
174
  })
176
175
  })
177
176
 
@@ -193,8 +192,8 @@ export const Version: Action<boolean> = Action({
193
192
  Flag.withDefault(false)
194
193
  ),
195
194
  run: Effect.fnUntraced(function*(_, { command, version }) {
196
- const formatter = yield* resolveFormatter
197
- yield* Console.log(formatter.formatVersion(command.name, version))
195
+ const presenter = yield* CliOutput.Presenter
196
+ yield* presenter.present({ _tag: "Version", name: command.name, version })
198
197
  })
199
198
  })
200
199
 
@@ -249,7 +248,7 @@ export const Completions: Action<Option.Option<Completions_.Shell>> = Action({
249
248
  ),
250
249
  run: Effect.fnUntraced(function*(shell, { command }) {
251
250
  if (Option.isNone(shell)) return
252
- const descriptor = CommandDescriptor.fromCommand(command)
251
+ const descriptor = Completions_.fromCommand(command)
253
252
  yield* Console.log(
254
253
  Completions_.generate(command.name, shell.value, descriptor)
255
254
  )
package/src/cli/Param.ts CHANGED
@@ -25,6 +25,7 @@ import * as CliError from "./CliError.ts"
25
25
  import type { Environment } from "./Command.ts"
26
26
  import * as Primitive from "./Primitive.ts"
27
27
  import * as Prompt from "./Prompt.ts"
28
+ import * as TerminalCapabilities from "./TerminalCapabilities.ts"
28
29
 
29
30
  const TypeId = "~effect/cli/Param"
30
31
 
@@ -1931,6 +1932,9 @@ export const withFallbackConfig: {
1931
1932
  *
1932
1933
  * This only handles missing options and missing arguments. Invalid values do not
1933
1934
  * prompt, and prompt cancellation re-fails with the original missing error.
1935
+ * When `TerminalCapabilities.canPrompt` is `false`, the fallback is skipped
1936
+ * entirely: no prompt is built or shown, and the original missing error is
1937
+ * returned.
1934
1938
  *
1935
1939
  * @see {@link FallbackPrompt} for accepted fallback prompt forms
1936
1940
  * @see {@link withFallbackConfig} for loading a fallback from config
@@ -1958,6 +1962,9 @@ export const withFallbackPrompt: {
1958
1962
  *
1959
1963
  * This only handles missing options and missing arguments. Invalid values do not
1960
1964
  * prompt, and prompt cancellation re-fails with the original missing error.
1965
+ * When `TerminalCapabilities.canPrompt` is `false`, the fallback is skipped
1966
+ * entirely: no prompt is built or shown, and the original missing error is
1967
+ * returned.
1961
1968
  *
1962
1969
  * @see {@link FallbackPrompt} for accepted fallback prompt forms
1963
1970
  * @see {@link withFallbackConfig} for loading a fallback from config
@@ -1985,6 +1992,9 @@ export const withFallbackPrompt: {
1985
1992
  *
1986
1993
  * This only handles missing options and missing arguments. Invalid values do not
1987
1994
  * prompt, and prompt cancellation re-fails with the original missing error.
1995
+ * When `TerminalCapabilities.canPrompt` is `false`, the fallback is skipped
1996
+ * entirely: no prompt is built or shown, and the original missing error is
1997
+ * returned.
1988
1998
  *
1989
1999
  * @see {@link FallbackPrompt} for accepted fallback prompt forms
1990
2000
  * @see {@link withFallbackConfig} for loading a fallback from config
@@ -1999,11 +2009,16 @@ export const withFallbackPrompt: {
1999
2009
  self: Param<Kind, A>,
2000
2010
  prompt: FallbackPrompt<B>
2001
2011
  ): Param<Kind, A | B> => {
2002
- const runPrompt = (error: CliError.MissingOption | CliError.MissingArgument, args: ParsedArgs) =>
2003
- Effect.flatMap(Prompt.isPrompt(prompt) ? Effect.succeed(prompt) : prompt, Prompt.run).pipe(
2004
- Effect.map((value) => [args.arguments, value as A | B] as const),
2005
- Effect.catchTag("QuitError", () => Effect.fail(error))
2006
- )
2012
+ const runPrompt = Effect.fnUntraced(function*(
2013
+ error: CliError.MissingOption | CliError.MissingArgument,
2014
+ args: ParsedArgs
2015
+ ) {
2016
+ const { canPrompt } = yield* TerminalCapabilities.TerminalCapabilities
2017
+ if (!canPrompt) return yield* Effect.fail(error)
2018
+ const built = Prompt.isPrompt(prompt) ? prompt : yield* prompt
2019
+ const value = yield* Effect.catchTag(Prompt.run(built), "QuitError", () => Effect.fail(error))
2020
+ return [args.arguments, value as A | B] as const
2021
+ })
2007
2022
  return transform(
2008
2023
  self,
2009
2024
  (parse) => (args) =>
@@ -3191,7 +3206,15 @@ const parseFlag: <A>(
3191
3206
  return yield* new CliError.MissingOption({ option: name })
3192
3207
  }
3193
3208
 
3194
- // Parse the first value (later we can handle multiple)
3209
+ if (providedValues.length > 1) {
3210
+ return yield* new CliError.InvalidValue({
3211
+ option: name,
3212
+ value: `${providedValues.length} occurrences`,
3213
+ expected: "at most 1 value",
3214
+ kind: "flag"
3215
+ })
3216
+ }
3217
+
3195
3218
  const arg = providedValues[0]
3196
3219
  const value = yield* Effect.mapError(
3197
3220
  primitiveType.parse(arg),
@@ -5,7 +5,9 @@
5
5
  * the current process. The layer reads the same variables through
6
6
  * `ConfigProvider`, plus the TTY state of `Stdio`. Unless a
7
7
  * `CliOutput.Formatter` is provided, the built-in help, version, and error
8
- * output of `Command` follows `canColor`.
8
+ * output of `Command` follows `canColor`. Fallback prompts added with
9
+ * `Flag.withFallbackPrompt` or `Argument.withFallbackPrompt` only run when
10
+ * `canPrompt` is `true`.
9
11
  *
10
12
  * @stability unstable
11
13
  * @since 4.0.0
@@ -25,8 +27,9 @@ import * as Stdio from "../Stdio.ts"
25
27
  * `canColor` says whether styling will be rendered rather than stored as
26
28
  * bytes. `canAnimate` says whether output is being watched, so pacing means
27
29
  * something. `canPrompt` says whether a question can be asked and answered.
28
- * Only `canColor` is read by the built-in `Command` output; the other two are
29
- * for application code that renders its own output.
30
+ * The built-in `Command` output reads `canColor`, and fallback prompts for
31
+ * missing flags and arguments are skipped when `canPrompt` is `false`.
32
+ * `canAnimate` is for application code that renders its own output.
30
33
  *
31
34
  * @stability unstable
32
35
  * @category models