@asterxsk/kiln 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 (263) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +170 -0
  3. package/agent/AGENTS.md +67 -0
  4. package/agent/README.md +5 -0
  5. package/agent/extensions/AGENTS.md +68 -0
  6. package/agent/extensions/ask-user/index.ts +418 -0
  7. package/agent/extensions/ask-user/install.ps1 +23 -0
  8. package/agent/extensions/ask-user/install.sh +21 -0
  9. package/agent/extensions/ask-user/package-lock.json +769 -0
  10. package/agent/extensions/ask-user/package.json +19 -0
  11. package/agent/extensions/ask-user/prompt.ts +45 -0
  12. package/agent/extensions/ask-user/tsconfig.json +7 -0
  13. package/agent/extensions/background-terminals/docs/implementation-guide.md +942 -0
  14. package/agent/extensions/background-terminals/index.ts +627 -0
  15. package/agent/extensions/background-terminals/install.ps1 +23 -0
  16. package/agent/extensions/background-terminals/install.sh +21 -0
  17. package/agent/extensions/background-terminals/manager.test.ts +735 -0
  18. package/agent/extensions/background-terminals/output.test.ts +109 -0
  19. package/agent/extensions/background-terminals/package-lock.json +769 -0
  20. package/agent/extensions/background-terminals/package.json +17 -0
  21. package/agent/extensions/background-terminals/prompt.test.ts +125 -0
  22. package/agent/extensions/background-terminals/ps.test.ts +82 -0
  23. package/agent/extensions/background-terminals/result-delivery.test.ts +44 -0
  24. package/agent/extensions/background-terminals/src/domain.ts +87 -0
  25. package/agent/extensions/background-terminals/src/manager.ts +907 -0
  26. package/agent/extensions/background-terminals/src/output.ts +84 -0
  27. package/agent/extensions/background-terminals/src/prompt.ts +142 -0
  28. package/agent/extensions/background-terminals/src/result-delivery.ts +27 -0
  29. package/agent/extensions/background-terminals/src/runtime.ts +36 -0
  30. package/agent/extensions/background-terminals/src/ui/output-view.ts +79 -0
  31. package/agent/extensions/background-terminals/src/ui/ps.ts +621 -0
  32. package/agent/extensions/background-terminals/tsconfig.json +7 -0
  33. package/agent/extensions/destructive/README.md +31 -0
  34. package/agent/extensions/destructive/index.ts +88 -0
  35. package/agent/extensions/destructive/install.ps1 +23 -0
  36. package/agent/extensions/destructive/install.sh +21 -0
  37. package/agent/extensions/file-search/index.spec.ts +443 -0
  38. package/agent/extensions/file-search/index.ts +459 -0
  39. package/agent/extensions/file-search/install.ps1 +23 -0
  40. package/agent/extensions/file-search/install.sh +21 -0
  41. package/agent/extensions/file-search/package-lock.json +2253 -0
  42. package/agent/extensions/file-search/package.json +23 -0
  43. package/agent/extensions/file-search/src/args.ts +122 -0
  44. package/agent/extensions/file-search/src/binaries.ts +422 -0
  45. package/agent/extensions/file-search/src/output.ts +126 -0
  46. package/agent/extensions/file-search/src/process.ts +146 -0
  47. package/agent/extensions/file-search/src/prompt.ts +52 -0
  48. package/agent/extensions/file-search/tsconfig.json +7 -0
  49. package/agent/extensions/goal/README.md +50 -0
  50. package/agent/extensions/goal/index.ts +155 -0
  51. package/agent/extensions/goal/install.ps1 +23 -0
  52. package/agent/extensions/goal/install.sh +21 -0
  53. package/agent/extensions/modelconf/PLAN.md +915 -0
  54. package/agent/extensions/modelconf/README.md +66 -0
  55. package/agent/extensions/modelconf/index.ts +296 -0
  56. package/agent/extensions/modelconf/install.ps1 +23 -0
  57. package/agent/extensions/modelconf/install.sh +21 -0
  58. package/agent/extensions/modelconf/package-lock.json +1809 -0
  59. package/agent/extensions/modelconf/package.json +13 -0
  60. package/agent/extensions/modelconf/src/fuzzy.ts +26 -0
  61. package/agent/extensions/modelconf/src/glob.ts +13 -0
  62. package/agent/extensions/modelconf/src/persistence.test.ts +46 -0
  63. package/agent/extensions/modelconf/src/persistence.ts +164 -0
  64. package/agent/extensions/modelconf/src/ui/ModelConfView.test.ts +75 -0
  65. package/agent/extensions/modelconf/src/ui/ModelConfView.ts +1101 -0
  66. package/agent/extensions/modelconf/tsconfig.json +15 -0
  67. package/agent/extensions/pi-web-access/CHANGELOG.md +690 -0
  68. package/agent/extensions/pi-web-access/LICENSE +21 -0
  69. package/agent/extensions/pi-web-access/README.md +470 -0
  70. package/agent/extensions/pi-web-access/SECURITY.md +5 -0
  71. package/agent/extensions/pi-web-access/activity.ts +101 -0
  72. package/agent/extensions/pi-web-access/auth-fetch.ts +148 -0
  73. package/agent/extensions/pi-web-access/banner.png +0 -0
  74. package/agent/extensions/pi-web-access/brightdata-unlocker.ts +272 -0
  75. package/agent/extensions/pi-web-access/chrome-cookies.ts +669 -0
  76. package/agent/extensions/pi-web-access/content-find.ts +139 -0
  77. package/agent/extensions/pi-web-access/credential-source.ts +191 -0
  78. package/agent/extensions/pi-web-access/data-uri-sanitize.ts +406 -0
  79. package/agent/extensions/pi-web-access/datalab-pdf-extract.ts +568 -0
  80. package/agent/extensions/pi-web-access/declared-web-links.ts +173 -0
  81. package/agent/extensions/pi-web-access/evidence/CONTRACT-EVIDENCE.md +496 -0
  82. package/agent/extensions/pi-web-access/evidence/contract-probe.mjs +140 -0
  83. package/agent/extensions/pi-web-access/exa.ts +526 -0
  84. package/agent/extensions/pi-web-access/extract.ts +1196 -0
  85. package/agent/extensions/pi-web-access/feature-config.ts +29 -0
  86. package/agent/extensions/pi-web-access/fetch-params.ts +111 -0
  87. package/agent/extensions/pi-web-access/gemini-adc.ts +298 -0
  88. package/agent/extensions/pi-web-access/gemini-api.ts +353 -0
  89. package/agent/extensions/pi-web-access/gemini-pdf-extract.ts +108 -0
  90. package/agent/extensions/pi-web-access/gemini-search.ts +21 -0
  91. package/agent/extensions/pi-web-access/gemini-url-context.ts +128 -0
  92. package/agent/extensions/pi-web-access/gemini-web-config.ts +101 -0
  93. package/agent/extensions/pi-web-access/gemini-web.ts +487 -0
  94. package/agent/extensions/pi-web-access/github-api.ts +197 -0
  95. package/agent/extensions/pi-web-access/github-extract.ts +746 -0
  96. package/agent/extensions/pi-web-access/github-issue-pr.ts +700 -0
  97. package/agent/extensions/pi-web-access/index.ts +1737 -0
  98. package/agent/extensions/pi-web-access/package-lock.json +5808 -0
  99. package/agent/extensions/pi-web-access/package.json +64 -0
  100. package/agent/extensions/pi-web-access/page-query.ts +96 -0
  101. package/agent/extensions/pi-web-access/pdf-extract.ts +409 -0
  102. package/agent/extensions/pi-web-access/pi-web-fetch-demo.mp4 +0 -0
  103. package/agent/extensions/pi-web-access/promise-try.d.ts +7 -0
  104. package/agent/extensions/pi-web-access/query-rewrite.ts +51 -0
  105. package/agent/extensions/pi-web-access/render-search-error.ts +170 -0
  106. package/agent/extensions/pi-web-access/rsc-extract.ts +338 -0
  107. package/agent/extensions/pi-web-access/search-types.ts +20 -0
  108. package/agent/extensions/pi-web-access/source-check.ts +282 -0
  109. package/agent/extensions/pi-web-access/ssrf-protection.ts +526 -0
  110. package/agent/extensions/pi-web-access/storage.ts +521 -0
  111. package/agent/extensions/pi-web-access/summary-model-scope.ts +125 -0
  112. package/agent/extensions/pi-web-access/test/auth-fetch.test.mjs +208 -0
  113. package/agent/extensions/pi-web-access/test/brightdata-unlocker.test.mjs +840 -0
  114. package/agent/extensions/pi-web-access/test/chrome-cookie-extraction.test.mjs +441 -0
  115. package/agent/extensions/pi-web-access/test/config-path.test.mjs +283 -0
  116. package/agent/extensions/pi-web-access/test/content-find.test.mjs +25 -0
  117. package/agent/extensions/pi-web-access/test/credential-source.test.mjs +118 -0
  118. package/agent/extensions/pi-web-access/test/data-uri-sanitize.test.mjs +210 -0
  119. package/agent/extensions/pi-web-access/test/datalab-pdf-extract.test.mjs +552 -0
  120. package/agent/extensions/pi-web-access/test/declared-web-links.test.mjs +212 -0
  121. package/agent/extensions/pi-web-access/test/fetch-answer-storage.test.mjs +40 -0
  122. package/agent/extensions/pi-web-access/test/fetch-cache-storage.test.mjs +334 -0
  123. package/agent/extensions/pi-web-access/test/fetch-content-domain-policy.test.mjs +95 -0
  124. package/agent/extensions/pi-web-access/test/fetch-modes.test.mjs +53 -0
  125. package/agent/extensions/pi-web-access/test/fetch-not-found-guidance.test.mjs +92 -0
  126. package/agent/extensions/pi-web-access/test/fetch-params.test.mjs +86 -0
  127. package/agent/extensions/pi-web-access/test/fetch-render-call.test.mjs +34 -0
  128. package/agent/extensions/pi-web-access/test/fetch-routing.test.mjs +173 -0
  129. package/agent/extensions/pi-web-access/test/gemini-adc-auth.test.mjs +257 -0
  130. package/agent/extensions/pi-web-access/test/gemini-api-transport.test.mjs +170 -0
  131. package/agent/extensions/pi-web-access/test/gemini-pdf-extract.test.mjs +133 -0
  132. package/agent/extensions/pi-web-access/test/gemini-web-cookie-opt-in.test.mjs +178 -0
  133. package/agent/extensions/pi-web-access/test/gemini-web-header-overflow.test.mjs +148 -0
  134. package/agent/extensions/pi-web-access/test/get-search-content.test.mjs +223 -0
  135. package/agent/extensions/pi-web-access/test/github-extract.test.mjs +378 -0
  136. package/agent/extensions/pi-web-access/test/github-issue-pr.test.mjs +565 -0
  137. package/agent/extensions/pi-web-access/test/inline-content-config.test.mjs +99 -0
  138. package/agent/extensions/pi-web-access/test/lazy-extract-load.test.mjs +118 -0
  139. package/agent/extensions/pi-web-access/test/local-video-oversize.test.mjs +52 -0
  140. package/agent/extensions/pi-web-access/test/package-typebox-dependency.test.mjs +50 -0
  141. package/agent/extensions/pi-web-access/test/page-query.test.mjs +51 -0
  142. package/agent/extensions/pi-web-access/test/pdf-config.test.mjs +140 -0
  143. package/agent/extensions/pi-web-access/test/pdf-extract.test.mjs +500 -0
  144. package/agent/extensions/pi-web-access/test/proxy-transport.test.mjs +286 -0
  145. package/agent/extensions/pi-web-access/test/query-rewrite.test.mjs +52 -0
  146. package/agent/extensions/pi-web-access/test/rsc-fallback.test.mjs +102 -0
  147. package/agent/extensions/pi-web-access/test/search-error-render.test.mjs +152 -0
  148. package/agent/extensions/pi-web-access/test/search-providers.test.mjs +274 -0
  149. package/agent/extensions/pi-web-access/test/source-check.test.mjs +179 -0
  150. package/agent/extensions/pi-web-access/test/ssrf-allow-ranges-config.test.mjs +205 -0
  151. package/agent/extensions/pi-web-access/test/ssrf-protection.test.mjs +456 -0
  152. package/agent/extensions/pi-web-access/test/summary-model-scope.test.mjs +106 -0
  153. package/agent/extensions/pi-web-access/test/tool-registration-config.test.mjs +182 -0
  154. package/agent/extensions/pi-web-access/test/web-search-answer-render.test.mjs +66 -0
  155. package/agent/extensions/pi-web-access/test/youtube-extract-errors.test.mjs +64 -0
  156. package/agent/extensions/pi-web-access/tsconfig.json +11 -0
  157. package/agent/extensions/pi-web-access/utils.ts +451 -0
  158. package/agent/extensions/pi-web-access/video-extract.ts +392 -0
  159. package/agent/extensions/pi-web-access/youtube-extract.ts +328 -0
  160. package/agent/extensions/shared/activity-status.ts +31 -0
  161. package/agent/extensions/shared/child-session.test.ts +270 -0
  162. package/agent/extensions/shared/child-session.ts +148 -0
  163. package/agent/extensions/shared/context-utilization.test.ts +48 -0
  164. package/agent/extensions/shared/context-utilization.ts +47 -0
  165. package/agent/extensions/shared/dashboard-state.ts +99 -0
  166. package/agent/extensions/shared/install.ps1 +23 -0
  167. package/agent/extensions/shared/install.sh +21 -0
  168. package/agent/extensions/shared/tool-call-timeout.test.ts +117 -0
  169. package/agent/extensions/shared/tool-call-timeout.ts +104 -0
  170. package/agent/extensions/skillsconf/README.md +74 -0
  171. package/agent/extensions/skillsconf/index.ts +92 -0
  172. package/agent/extensions/skillsconf/install.ps1 +23 -0
  173. package/agent/extensions/skillsconf/install.sh +21 -0
  174. package/agent/extensions/skillsconf/package-lock.json +1809 -0
  175. package/agent/extensions/skillsconf/package.json +18 -0
  176. package/agent/extensions/skillsconf/src/delete-skill.test.ts +64 -0
  177. package/agent/extensions/skillsconf/src/delete-skill.ts +45 -0
  178. package/agent/extensions/skillsconf/src/filter.test.ts +80 -0
  179. package/agent/extensions/skillsconf/src/filter.ts +74 -0
  180. package/agent/extensions/skillsconf/src/fuzzy.ts +26 -0
  181. package/agent/extensions/skillsconf/src/persistence.test.ts +72 -0
  182. package/agent/extensions/skillsconf/src/persistence.ts +169 -0
  183. package/agent/extensions/skillsconf/src/ui/SkillConfView.test.ts +337 -0
  184. package/agent/extensions/skillsconf/src/ui/SkillConfView.ts +758 -0
  185. package/agent/extensions/skillsconf/src/ui/text-input.ts +91 -0
  186. package/agent/extensions/skillsconf/src/ui/tui-helpers.ts +144 -0
  187. package/agent/extensions/skillsconf/tsconfig.json +15 -0
  188. package/agent/extensions/status line/index.ts +282 -0
  189. package/agent/extensions/status line/install.ps1 +23 -0
  190. package/agent/extensions/status line/install.sh +21 -0
  191. package/agent/extensions/subagents/by-the-way.test.ts +29 -0
  192. package/agent/extensions/subagents/claude.test.ts +119 -0
  193. package/agent/extensions/subagents/codex.test.ts +102 -0
  194. package/agent/extensions/subagents/context-usage.test.ts +107 -0
  195. package/agent/extensions/subagents/docs/design-plan.md +568 -0
  196. package/agent/extensions/subagents/docs/effect-v4-extension-guide.md +354 -0
  197. package/agent/extensions/subagents/docs/effect-v4-notes.md +571 -0
  198. package/agent/extensions/subagents/index.ts +779 -0
  199. package/agent/extensions/subagents/install.ps1 +23 -0
  200. package/agent/extensions/subagents/install.sh +21 -0
  201. package/agent/extensions/subagents/manager.test.ts +276 -0
  202. package/agent/extensions/subagents/package-lock.json +2244 -0
  203. package/agent/extensions/subagents/package.json +19 -0
  204. package/agent/extensions/subagents/result-delivery.test.ts +27 -0
  205. package/agent/extensions/subagents/src/backend.ts +73 -0
  206. package/agent/extensions/subagents/src/backends/claude.ts +701 -0
  207. package/agent/extensions/subagents/src/backends/codex.ts +1060 -0
  208. package/agent/extensions/subagents/src/backends/pi.ts +575 -0
  209. package/agent/extensions/subagents/src/backends/stub.ts +300 -0
  210. package/agent/extensions/subagents/src/by-the-way.ts +21 -0
  211. package/agent/extensions/subagents/src/domain.ts +253 -0
  212. package/agent/extensions/subagents/src/format.ts +74 -0
  213. package/agent/extensions/subagents/src/manager.ts +736 -0
  214. package/agent/extensions/subagents/src/prompt.ts +92 -0
  215. package/agent/extensions/subagents/src/result-delivery.ts +20 -0
  216. package/agent/extensions/subagents/src/runtime.ts +53 -0
  217. package/agent/extensions/subagents/src/ui/takeover.ts +583 -0
  218. package/agent/extensions/subagents/src/ui/transcript.ts +201 -0
  219. package/agent/extensions/subagents/takeover.test.ts +29 -0
  220. package/agent/extensions/subagents/tsconfig.json +7 -0
  221. package/agent/extensions/taste/index.ts +443 -0
  222. package/agent/extensions/taste/install.ps1 +23 -0
  223. package/agent/extensions/taste/install.sh +21 -0
  224. package/agent/extensions/todo/AGENTS.md +38 -0
  225. package/agent/extensions/todo/LICENSE +21 -0
  226. package/agent/extensions/todo/config.ts +55 -0
  227. package/agent/extensions/todo/index.ts +151 -0
  228. package/agent/extensions/todo/install.ps1 +23 -0
  229. package/agent/extensions/todo/install.sh +21 -0
  230. package/agent/extensions/todo/locales/de.json +17 -0
  231. package/agent/extensions/todo/locales/en.json +15 -0
  232. package/agent/extensions/todo/locales/es.json +17 -0
  233. package/agent/extensions/todo/locales/fr.json +17 -0
  234. package/agent/extensions/todo/locales/pt-BR.json +17 -0
  235. package/agent/extensions/todo/locales/pt.json +17 -0
  236. package/agent/extensions/todo/locales/ru.json +17 -0
  237. package/agent/extensions/todo/locales/uk.json +17 -0
  238. package/agent/extensions/todo/locales/zh.json +17 -0
  239. package/agent/extensions/todo/package-lock.json +3358 -0
  240. package/agent/extensions/todo/package.json +67 -0
  241. package/agent/extensions/todo/state/i18n-bridge.ts +64 -0
  242. package/agent/extensions/todo/state/invariants.ts +20 -0
  243. package/agent/extensions/todo/state/replay.ts +38 -0
  244. package/agent/extensions/todo/state/selectors.ts +107 -0
  245. package/agent/extensions/todo/state/state-reducer.ts +326 -0
  246. package/agent/extensions/todo/state/state.ts +18 -0
  247. package/agent/extensions/todo/state/store.ts +82 -0
  248. package/agent/extensions/todo/state/task-graph.ts +57 -0
  249. package/agent/extensions/todo/todo-overlay.ts +200 -0
  250. package/agent/extensions/todo/todo.ts +155 -0
  251. package/agent/extensions/todo/tool/response-envelope.ts +109 -0
  252. package/agent/extensions/todo/tool/types.ts +206 -0
  253. package/agent/extensions/todo/verify-ref-system.js +0 -0
  254. package/agent/extensions/todo/view/format.ts +177 -0
  255. package/agent/extensions/trim-context/README.md +54 -0
  256. package/agent/extensions/trim-context/index.ts +487 -0
  257. package/agent/extensions/trim-context/install.ps1 +23 -0
  258. package/agent/extensions/trim-context/install.sh +21 -0
  259. package/agent/install.ps1 +527 -0
  260. package/agent/install.sh +511 -0
  261. package/agent/keybindings.json +7 -0
  262. package/bin/kiln.js +359 -0
  263. package/package.json +21 -0
@@ -0,0 +1,571 @@
1
+ # Effect v4 — Practical Notes for the Subagents Extension
2
+
3
+ > **Building a new pi extension on this stack?** Start with the migration-oriented
4
+ > [`effect-v4-extension-guide.md`](./effect-v4-extension-guide.md) (toolchain setup, the
5
+ > `ManagedRuntime` + `runTool` boundary, when *not* to use Effect, per-extension recipes).
6
+ > This file is the deeper Effect API reference it points back to.
7
+
8
+ > **Verified against:** `effect@4.0.0-beta.98` and `@effect/platform-node@4.0.0-beta.98`
9
+ > (npm dist-tag `beta`, checked 2026-07-13). Every snippet in this doc was type-checked
10
+ > with `tsc --strict` against these packages, and the process-spawning / runtime snippets
11
+ > were executed with Node 24. v4 source lives in the **`Effect-TS/effect-smol`** repo
12
+ > (not `Effect-TS/effect`); the official migration guide is
13
+ > [`effect-smol/MIGRATION.md`](https://github.com/Effect-TS/effect-smol/blob/main/MIGRATION.md)
14
+ > plus the `migration/*.md` files next to it (including a machine-readable
15
+ > `migration/v3-to-v4.md` rename map).
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ npm install effect@beta @effect/platform-node@beta
21
+ ```
22
+
23
+ Big structural facts:
24
+
25
+ - **One version number for everything.** All ecosystem packages release together at
26
+ `4.0.0-beta.N`. `@effect/platform-node` must match `effect` exactly.
27
+ - **`@effect/platform` is gone — merged into core `effect`.** `FileSystem`, `Path`,
28
+ `PlatformError`, `Terminal`, `Stdio` are now top-level `effect` modules.
29
+ `@effect/platform-node` remains as the Node *implementation* package.
30
+ - **`effect/unstable/*` namespace.** Modules that may break in minor releases:
31
+ `effect/unstable/process` (child processes — the one we need), `http`, `rpc`, `cli`,
32
+ `ai`, `workers`, etc. Everything outside `unstable/` follows strict semver.
33
+ - **`"type": "module"`**, ESM-first. Works with `moduleResolution: NodeNext` or `Bundler`.
34
+ - Runtime keep-alive is built in now: a fiber suspended on `Deferred.await` etc. keeps
35
+ the Node process alive without `NodeRuntime.runMain` (v3 needed runMain for that).
36
+
37
+ ## Cheat sheet: v3 → v4 renames you will actually hit
38
+
39
+ | v3 | v4 |
40
+ | --- | --- |
41
+ | `Context.Tag` / `Effect.Service` | `Context.Service` (`Effect.Service` is **gone**) |
42
+ | `Effect.fork` | `Effect.forkChild` |
43
+ | `Effect.forkDaemon` | `Effect.forkDetach` |
44
+ | `Effect.async` | `Effect.callback` |
45
+ | `Effect.catchAll` | `Effect.catch` |
46
+ | `Effect.catchAllCause` / `catchAllDefect` | `Effect.catchCause` / `catchDefect` |
47
+ | `Effect.zipRight` / `zipLeft` | `Effect.andThen` / `Effect.tap` |
48
+ | `Effect.either` | `Effect.result` |
49
+ | `Either` module | `Result` (`Result.succeed` / `Result.fail`) |
50
+ | `Layer.scoped` | `Layer.effect` (all layers are scoped-capable now) |
51
+ | `Mailbox` | `Queue` (Queue absorbed Mailbox: done/fail signalling built in) |
52
+ | `FiberRef` | `Context.Reference` (module `effect/References`) |
53
+ | `Scope.extend` | `Scope.provide` |
54
+ | `Stream.async*` (all 4 variants) | `Stream.callback` |
55
+ | `Stream.fromChunk(s)` | `Stream.fromArray` / `Stream.fromArrays` (Chunk de-emphasized; arrays used) |
56
+ | `Schema.TaggedError` | `Schema.TaggedErrorClass` |
57
+ | `@effect/platform/Command` | `effect/unstable/process` → `ChildProcess` |
58
+ | `@effect/platform/CommandExecutor` | `effect/unstable/process` → `ChildProcessSpawner` |
59
+ | `@effect/platform/FileSystem` | `effect/FileSystem` |
60
+ | `Runtime.runPromise(runtime)(...)` | gone — use `ManagedRuntime` methods directly |
61
+ | `UnknownException` (tryPromise default) | `Cause.UnknownError` |
62
+
63
+ Removed with no replacement: `Effect.forkAll`, `Effect.forkWithErrorHandler`.
64
+ Early v4 betas renamed `Context` → `ServiceMap`; **that was reverted** — beta.98 uses
65
+ `Context` again (ignore older blog posts/AI answers mentioning `ServiceMap`).
66
+
67
+ ---
68
+
69
+ ## 1. Basics: `Effect.gen`, running, the Promise boundary
70
+
71
+ Unchanged in spirit from v3. `Effect<A, E, R>` = success `A`, typed error `E`,
72
+ required services `R`.
73
+
74
+ ```ts
75
+ import { Effect, Exit } from "effect"
76
+
77
+ const double = (n: number) => Effect.succeed(n * 2)
78
+
79
+ const program = Effect.gen(function* () {
80
+ const a = yield* Effect.succeed(1)
81
+ const b = yield* double(a)
82
+ yield* Effect.log(`result: ${b}`)
83
+ return b
84
+ })
85
+
86
+ // Entry-point conversion — only at the outermost layer (tool handlers):
87
+ const p: Promise<number> = Effect.runPromise(program) // rejects on failure/defect
88
+ const pe: Promise<Exit.Exit<number, never>> = Effect.runPromiseExit(program) // never rejects
89
+ const s: number = Effect.runSync(program) // throws if async
90
+ const fiber = Effect.runFork(program) // fire-and-forget fiber
91
+ ```
92
+
93
+ `runPromise` only accepts `Effect<A, E, never>` — all services must be provided first
94
+ (or use a `ManagedRuntime`, §8). `runPromiseExit` is the right choice inside tool
95
+ handlers when you want to convert failures to structured results instead of throws.
96
+
97
+ `Effect.fn` gives you named, traced effect functions (nice stack traces):
98
+
99
+ ```ts
100
+ const spawnJob = Effect.fn("spawnJob")(function* (name: string) {
101
+ yield* Effect.log(`spawning ${name}`)
102
+ return name
103
+ })
104
+ // spawnJob("x") : Effect<string>
105
+ ```
106
+
107
+ ## 2. Services & Layers
108
+
109
+ `Context.Tag` and the v3 `Effect.Service` helper class are **both gone**. The single
110
+ API is `Context.Service`, in two forms:
111
+
112
+ ```ts
113
+ import { Context, Effect, Layer } from "effect"
114
+
115
+ // Class-style (recommended — class value doubles as the key):
116
+ class Clock extends Context.Service<Clock, {
117
+ readonly now: Effect.Effect<number>
118
+ }>()("app/Clock") {}
119
+
120
+ // Function-style key:
121
+ const Random = Context.Service<{ next: Effect.Effect<number> }>("app/Random")
122
+
123
+ // Yielding the key retrieves the service (keys are Effects):
124
+ const use = Effect.gen(function* () {
125
+ const clock = yield* Clock
126
+ return yield* clock.now
127
+ })
128
+ ```
129
+
130
+ Layers work like v3 (`Layer.scoped` merged into `Layer.effect` — every `Layer.effect`
131
+ build can use scoped resources):
132
+
133
+ ```ts
134
+ const ClockLive = Layer.succeed(Clock, { now: Effect.sync(() => Date.now()) })
135
+
136
+ const RandomLive = Layer.effect(
137
+ Random,
138
+ Effect.gen(function* () {
139
+ yield* Effect.log("building Random")
140
+ return { next: Effect.sync(() => Math.random()) }
141
+ })
142
+ )
143
+
144
+ // Dependencies between layers:
145
+ class Ids extends Context.Service<Ids, { readonly nextId: Effect.Effect<string> }>()("app/Ids") {}
146
+
147
+ const IdsLive = Layer.effect(
148
+ Ids,
149
+ Effect.gen(function* () {
150
+ const random = yield* Random
151
+ return Ids.of({ nextId: Effect.map(random.next, (n) => `id-${n}`) })
152
+ })
153
+ )
154
+
155
+ const AppLayer = Layer.mergeAll(ClockLive, IdsLive.pipe(Layer.provide(RandomLive)))
156
+
157
+ const runnable = use.pipe(Effect.provide(AppLayer)) // R = never
158
+
159
+ // One-off service injection without a layer:
160
+ const withTestClock = use.pipe(Effect.provideService(Clock, { now: Effect.succeed(0) }))
161
+ ```
162
+
163
+ Also useful:
164
+
165
+ - `Context.Reference("key", { defaultValue: () => ... })` — a service **with a default**
166
+ (this replaces `FiberRef`); no layer needed, override with `Effect.provideService`.
167
+ - **Layer memoization changed:** layers are memoized *globally across separate
168
+ `Effect.provide` calls* by default in v4 (per-runtime MemoMap), so providing the same
169
+ layer to two effects builds it once.
170
+
171
+ ## 3. Error handling
172
+
173
+ `Data.TaggedError` survives unchanged; `Schema.TaggedError` is now
174
+ `Schema.TaggedErrorClass`. Errors are yieldable directly.
175
+
176
+ ```ts
177
+ import { Data, Effect, Schema } from "effect"
178
+
179
+ class SpawnError extends Data.TaggedError("SpawnError")<{
180
+ readonly command: string
181
+ readonly cause: unknown
182
+ }> {}
183
+
184
+ class TimeoutError extends Data.TaggedError("TimeoutError")<{ readonly ms: number }> {}
185
+
186
+ // Schema-validated variant:
187
+ class NotFound extends Schema.TaggedErrorClass<NotFound>()("NotFound", {
188
+ id: Schema.Number
189
+ }) {}
190
+
191
+ const risky: Effect.Effect<string, SpawnError | TimeoutError> = Effect.gen(function* () {
192
+ if (somethingBad) return yield* new SpawnError({ command: "codex", cause: "enoent" })
193
+ return "ok"
194
+ })
195
+
196
+ // catchTag narrows the error union:
197
+ const handled: Effect.Effect<string, TimeoutError> = risky.pipe(
198
+ Effect.catchTag("SpawnError", (e) => Effect.succeed(`spawn failed: ${e.command}`))
199
+ )
200
+
201
+ const handledAll: Effect.Effect<string> = risky.pipe(
202
+ Effect.catchTags({
203
+ SpawnError: (e) => Effect.succeed(`spawn: ${e.command}`),
204
+ TimeoutError: (e) => Effect.succeed(`timeout ${e.ms}ms`)
205
+ })
206
+ )
207
+ ```
208
+
209
+ Renames: `catchAll` → `Effect.catch`, `catchAllCause` → `catchCause`,
210
+ `catchAllDefect` → `catchDefect`, `tapErrorCause` → `tapCause`, `Effect.either` →
211
+ `Effect.result` (returns `Result`, the renamed `Either`). `Effect.match`,
212
+ `Effect.exit`, `Effect.orDie`, `Effect.mapError`, `Effect.tapError` all still exist.
213
+ The `Cause` data structure was **flattened** (no nested `Sequential`/`Parallel` trees;
214
+ a cause is now a flat list of failures — simpler to render in job status output).
215
+
216
+ ## 4. Promise / async / callback interop
217
+
218
+ ```ts
219
+ import { Cause, Data, Effect } from "effect"
220
+
221
+ // Promise that "can't" reject — rejection becomes a defect:
222
+ const a = Effect.promise(() => Promise.resolve(42))
223
+
224
+ // Promise that may reject — default error type is Cause.UnknownError (v3: UnknownException):
225
+ const b = Effect.tryPromise((signal) => fetch("https://x", { signal }))
226
+
227
+ // Typed error:
228
+ class HttpError extends Data.TaggedError("HttpError")<{ cause: unknown }> {}
229
+ const c = Effect.tryPromise({
230
+ try: (signal) => fetch("https://x", { signal }),
231
+ catch: (cause) => new HttpError({ cause })
232
+ })
233
+ ```
234
+
235
+ Both forms receive an `AbortSignal` that fires on fiber interruption — pass it to SDKs
236
+ (claude SDK, fetch, etc.) so interrupting a subagent fiber cancels the underlying call.
237
+
238
+ Callback APIs — `Effect.async` is now **`Effect.callback`**:
239
+
240
+ ```ts
241
+ // signature: Effect.callback<A, E, R>((resume, signal) => void | cleanupEffect)
242
+ const waitForExit = (child: import("node:child_process").ChildProcess) =>
243
+ Effect.callback<number>((resume) => {
244
+ child.once("exit", (code) => resume(Effect.succeed(code ?? -1)))
245
+ })
246
+
247
+ // cleanup on interruption via the AbortSignal:
248
+ const sleepy = Effect.callback<number>((resume, signal) => {
249
+ const t = setTimeout(() => resume(Effect.succeed(1)), 1000)
250
+ signal.addEventListener("abort", () => clearTimeout(t))
251
+ })
252
+ ```
253
+
254
+ ## 5. Scopes & resource management
255
+
256
+ Same shape as v3. Relevant rename: `Scope.extend` → `Scope.provide`.
257
+
258
+ ```ts
259
+ import { Effect, Exit, Scope } from "effect"
260
+
261
+ const managedProc = Effect.acquireRelease(
262
+ acquireEffect, // acquire (uninterruptible)
263
+ (proc, exit) => Effect.sync(() => proc.kill()) // release, gets the Exit
264
+ )
265
+
266
+ // Scoped region: release runs when the region ends
267
+ const useIt = Effect.scoped(
268
+ Effect.gen(function* () {
269
+ const proc = yield* managedProc
270
+ return proc.pid
271
+ })
272
+ )
273
+
274
+ // addFinalizer:
275
+ Effect.scoped(Effect.gen(function* () {
276
+ yield* Effect.addFinalizer((exit) => Effect.log(`closing, ok=${Exit.isSuccess(exit)}`))
277
+ }))
278
+ ```
279
+
280
+ **Key pattern for background subagents** — a manually-controlled scope so the process
281
+ outlives the spawning tool call, and killing the job = closing the scope:
282
+
283
+ ```ts
284
+ const startJob = Effect.gen(function* () {
285
+ const scope = yield* Scope.make()
286
+ const handle = yield* Scope.provide(managedProc, scope) // resource lives in `scope`
287
+ // store `scope` in your job registry; later, from any fiber:
288
+ // yield* Scope.close(scope, Exit.void) // runs finalizers -> kills process
289
+ return { handle, scope }
290
+ })
291
+ ```
292
+
293
+ `Effect.acquireUseRelease(acquire, use, release)` for one-shot bracketing.
294
+
295
+ ## 6. Child processes & FileSystem (the important part)
296
+
297
+ The v3 `@effect/platform` `Command`/`CommandExecutor` modules were redesigned into
298
+ **`effect/unstable/process`** with `ChildProcess` (command builder) and
299
+ `ChildProcessSpawner` (the service). The Node implementation comes from
300
+ `@effect/platform-node`.
301
+
302
+ Import gotcha: `import { ChildProcessSpawner } from "effect/unstable/process"` gives you
303
+ the **module namespace**, not the service class. Import the class from the submodule:
304
+
305
+ ```ts
306
+ import { ChildProcess } from "effect/unstable/process"
307
+ import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner"
308
+ import { NodeServices, NodeFileSystem } from "@effect/platform-node"
309
+ ```
310
+
311
+ `NodeServices.layer` provides everything at once:
312
+ `ChildProcessSpawner | Crypto | FileSystem | Path | Stdio | Terminal`.
313
+
314
+ ### Building commands
315
+
316
+ ```ts
317
+ // Template literal form:
318
+ const cmd1 = ChildProcess.make`echo hello`
319
+ // Options + template:
320
+ const cmd2 = ChildProcess.make({ cwd: "/tmp" })`ls -la`
321
+ // Array form (best for dynamic args — no shell parsing):
322
+ const cmd = ChildProcess.make("codex", ["exec", "--json", prompt], {
323
+ cwd: workDir,
324
+ env: { CODEX_API_KEY: key }, // merged over process.env when extendEnv: true
325
+ extendEnv: true,
326
+ stdin: "pipe", // "pipe" | "inherit" | "ignore" | a Stream<Uint8Array>
327
+ stdout: "pipe", // "pipe" | "inherit" | "ignore" | a Sink
328
+ stderr: "pipe"
329
+ })
330
+ // pipelines: cmdA.pipe(ChildProcess.pipeTo(cmdB, { from: "stderr" }))
331
+ // modifiers: ChildProcess.setCwd, ChildProcess.setEnv, ChildProcess.prefix
332
+ ```
333
+
334
+ Note `detached` defaults to **true on non-Windows** — the child gets its own process
335
+ group (good: killing it kills the group).
336
+
337
+ ### Running: two styles
338
+
339
+ **Style A — via the spawner service (simple, non-interactive):**
340
+
341
+ ```ts
342
+ const simple = Effect.gen(function* () {
343
+ const spawner = yield* ChildProcessSpawner
344
+ const text = yield* spawner.string(cmd) // full stdout as string
345
+ const lines = yield* spawner.lines(cmd) // string[]
346
+ const code = yield* spawner.exitCode(cmd) // ExitCode (branded number)
347
+ const lineStream = spawner.streamLines(cmd, { includeStderr: true }) // Stream<string>
348
+ })
349
+ ```
350
+
351
+ **Style B — the Command IS an Effect.** Yielding a command spawns it and returns a
352
+ `ChildProcessHandle`, with the process lifetime tied to the ambient `Scope`
353
+ (`Command extends Effect<ChildProcessHandle, PlatformError, ChildProcessSpawner | Scope>`):
354
+
355
+ ```ts
356
+ import { Effect, Stream } from "effect"
357
+
358
+ const streaming = Effect.scoped(
359
+ Effect.gen(function* () {
360
+ const handle = yield* cmd // <-- spawns; killed when scope closes
361
+ handle.pid // ProcessId (branded number)
362
+
363
+ // stdout is Stream<Uint8Array, PlatformError>; decode + split lines:
364
+ yield* handle.stdout.pipe(
365
+ Stream.decodeText(),
366
+ Stream.splitLines,
367
+ Stream.runForEach((line) => Effect.log(`out: ${line}`))
368
+ )
369
+
370
+ // stdin is a Sink<void, Uint8Array>; write by running a stream into it:
371
+ yield* Stream.fromArray([new TextEncoder().encode("hello\n")]).pipe(
372
+ Stream.run(handle.stdin)
373
+ )
374
+
375
+ // handle.stderr, handle.all (stdout+stderr interleaved) also available
376
+ const code = yield* handle.exitCode // waits for exit
377
+ const running = yield* handle.isRunning
378
+ yield* handle.kill({ killSignal: "SIGTERM", forceKillAfter: "5 seconds" })
379
+ return code
380
+ })
381
+ )
382
+ ```
383
+
384
+ Verified at runtime: interrupting a fiber that spawned a process inside its scope
385
+ (e.g. `Fiber.interrupt` on a fiber running `Effect.scoped(...)` around `sleep 30`)
386
+ kills the child process. This is the backbone of subagent cancellation.
387
+
388
+ There's also `handle.unref` for letting the parent exit independently, and
389
+ `additionalFds` for extra file descriptor channels (fd3+).
390
+
391
+ ### FileSystem / Path (now core)
392
+
393
+ ```ts
394
+ import { Effect, FileSystem, Path } from "effect"
395
+
396
+ const files = Effect.gen(function* () {
397
+ const fs = yield* FileSystem.FileSystem
398
+ const path = yield* Path.Path
399
+ const content = yield* fs.readFileString("/tmp/in.txt")
400
+ yield* fs.writeFileString(path.join("/tmp", "out.txt"), content)
401
+ })
402
+ // provide NodeFileSystem.layer, or NodeServices.layer for everything
403
+ ```
404
+
405
+ ## 7. Concurrency toolbox for a job manager
406
+
407
+ All verified compiling + running:
408
+
409
+ ```ts
410
+ import {
411
+ Cause, Deferred, Effect, Fiber, FiberMap, PubSub, Queue, Ref, Stream, Exit
412
+ } from "effect"
413
+
414
+ const forking = Effect.gen(function* () {
415
+ const f1 = yield* Effect.forkChild(work) // v3 fork — dies with parent
416
+ const f2 = yield* Effect.forkScoped(work) // tied to ambient Scope
417
+ const f3 = yield* Effect.forkDetach(work) // v3 forkDaemon — outlives parent ✅ for background jobs
418
+ // all fork variants accept { startImmediately?: boolean, uninterruptible?: boolean | "inherit" }
419
+
420
+ const r: number = yield* Fiber.join(f1) // propagates failure
421
+ const exit: Exit.Exit<number> = yield* Fiber.await(f3) // failure as data
422
+ yield* Fiber.interrupt(f2)
423
+ // fiber.pollUnsafe() -> Exit | undefined for sync status checks
424
+ })
425
+ ```
426
+
427
+ **Deferred** — one-shot completion signal (job finished):
428
+
429
+ ```ts
430
+ const done = yield* Deferred.make<Result, JobError>()
431
+ yield* Effect.forkDetach(job.pipe(Effect.exit, Effect.flatMap((e) => Deferred.done(done, e))))
432
+ const result = yield* Deferred.await(done) // keeps Node process alive in v4, no runMain needed
433
+ ```
434
+
435
+ **Ref** — shared job-table state: `Ref.make({})`, `Ref.update`, `Ref.get`, `Ref.set`.
436
+ (`SynchronizedRef` for effectful updates.)
437
+
438
+ **Queue** — absorbed v3's `Mailbox`: it can be ended/failed, and converts to a Stream.
439
+ To use `Queue.end`, the error type must include `Cause.Done`:
440
+
441
+ ```ts
442
+ const q = yield* Queue.make<string, Cause.Done>() // capacity/strategy via options
443
+ yield* Queue.offer(q, "line")
444
+ yield* Queue.offerAll(q, ["a", "b"])
445
+ yield* Queue.end(q) // signal "no more items"
446
+ const asStream = Stream.fromQueue(q) // ends when queue ends
447
+ // Queue.take / takeAll / takeN / poll for direct consumption
448
+ ```
449
+
450
+ **PubSub** — broadcast (e.g. multiple watchers of one job's output):
451
+
452
+ ```ts
453
+ const ps = yield* PubSub.unbounded<string>()
454
+ const sub = yield* PubSub.subscribe(ps) // scoped acquisition
455
+ yield* PubSub.publish(ps, "event")
456
+ const msg = yield* PubSub.take(sub) // function call, not sub.take
457
+ // Stream.fromPubSub(ps) for stream consumption
458
+ ```
459
+
460
+ **FiberMap / FiberSet / FiberHandle** — keyed fiber registries, ideal for a subagent
461
+ manager (auto-interrupts everything when its scope closes; adding under an existing key
462
+ interrupts the old fiber):
463
+
464
+ ```ts
465
+ const jobsDemo = Effect.scoped(Effect.gen(function* () {
466
+ const jobs = yield* FiberMap.make<string>() // FiberMap<string> (keys)
467
+ yield* FiberMap.run(jobs, "job-1", work) // fork into the map
468
+ const fiber = yield* FiberMap.get(jobs, "job-1")
469
+ yield* FiberMap.remove(jobs, "job-1") // interrupts it
470
+ }))
471
+ ```
472
+
473
+ **Stream** essentials for process output: `Stream.decodeText()`, `Stream.splitLines`,
474
+ `Stream.runForEach`, `Stream.runCollect`, `Stream.run(sink)`, `Stream.fromQueue`,
475
+ `Stream.fromPubSub`, `Stream.toAsyncIterable`, `Stream.callback` (v3 `Stream.async`),
476
+ `Stream.fromArray` (v3 `fromChunk` — v4 uses plain arrays, Chunk is de-emphasized).
477
+ Also `Stream.mkString` to collect into one string.
478
+
479
+ Combinators: `Effect.all([...], { concurrency: n })`, `Effect.race`,
480
+ `Effect.timeout("5 seconds")` (fails with `Cause.TimeoutError`, tag `"TimeoutError"`),
481
+ `Semaphore.make(n)` (moved out of `Effect.makeSemaphore`), `Latch.make()`.
482
+
483
+ ## 8. ManagedRuntime — the entry-point pattern for the extension
484
+
485
+ v3's `Runtime.runPromise(runtime)(effect)` API is gone; `effect/Runtime` now only holds
486
+ `runMain` plumbing. **`ManagedRuntime` is the way** to share layers across async entry
487
+ points:
488
+
489
+ ```ts
490
+ import { Context, Effect, Layer, ManagedRuntime } from "effect"
491
+ import { NodeServices } from "@effect/platform-node"
492
+
493
+ class JobStore extends Context.Service<JobStore, {
494
+ readonly list: Effect.Effect<Array<string>>
495
+ }>()("app/JobStore") {}
496
+
497
+ const JobStoreLive = Layer.sync(JobStore, () => ({ list: Effect.succeed([]) }))
498
+
499
+ const AppLayer = Layer.mergeAll(JobStoreLive, NodeServices.layer)
500
+
501
+ // Build ONCE at extension activation. Layers are built lazily on first run.
502
+ const runtime = ManagedRuntime.make(AppLayer)
503
+
504
+ // pi tool handler — the only place we touch Promises:
505
+ export async function handleToolCall() {
506
+ return await runtime.runPromise(
507
+ Effect.gen(function* () {
508
+ const store = yield* JobStore
509
+ return yield* store.list
510
+ })
511
+ )
512
+ }
513
+
514
+ // fire-and-forget background work from a sync/async context:
515
+ const fiber = runtime.runFork(backgroundEffect)
516
+
517
+ // extension deactivation — closes the runtime scope, runs ALL finalizers
518
+ // (i.e. kills any still-scoped child processes):
519
+ export async function shutdown() {
520
+ await runtime.dispose()
521
+ }
522
+ ```
523
+
524
+ `ManagedRuntime` also exposes `runSync`, `runSyncExit`, `runPromiseExit`, `runCallback`,
525
+ a `memoMap` (share layer memoization between multiple runtimes), and `.scope`.
526
+ Prefer `runPromiseExit` in tool handlers if you want to map typed failures to
527
+ tool-result errors instead of catching thrown `Cause` wrappers.
528
+
529
+ ---
530
+
531
+ ## Architecture sketch for subagents
532
+
533
+ ```
534
+ ManagedRuntime.make(Layer.mergeAll(NodeServices.layer, SubagentManagerLive))
535
+ │ built once at extension init; dispose() on shutdown
536
+ ▼
537
+ SubagentManager service (Context.Service):
538
+ - Ref<HashMap<JobId, JobEntry>> job table
539
+ - start(cmd): Scope.make() → Scope.provide(ChildProcess handle, scope)
540
+ → Effect.forkDetach(pump stdout → Queue<string, Cause.Done>)
541
+ → Deferred<ExitCode> completed on exit
542
+ - status(id): Deferred.isDone / handle.isRunning / Ref lookup
543
+ - output(id): drain Queue (takeAll) or Stream.fromQueue for tailing
544
+ - kill(id): Scope.close(scope, Exit.void) → finalizer kills the process
545
+ Tool handlers: async fns calling runtime.runPromise(Effect.gen(...))
546
+ ```
547
+
548
+ ## Surprises & gotchas (learned the hard way)
549
+
550
+ 1. **`effect/unstable/process` exports module namespaces.** The
551
+ `ChildProcessSpawner` class must be imported from
552
+ `"effect/unstable/process/ChildProcessSpawner"` (or use
553
+ `ChildProcessSpawner.ChildProcessSpawner` off the namespace).
554
+ 2. **`Effect.fork` does not exist** — code (or an LLM) writing v3-style `Effect.fork`
555
+ fails to compile. Use `forkChild` / `forkScoped` / `forkDetach` / `forkIn`.
556
+ 3. **`Queue.end` needs `Cause.Done` in the queue's error type** —
557
+ `Queue.make<A>()` defaults to `E = never` and won't accept `end`.
558
+ 4. **Early-beta content mentioning `ServiceMap` is stale** — it was renamed back to
559
+ `Context` during the beta. Similarly, some AI-generated content mentions APIs that
560
+ never shipped.
561
+ 5. **`Either` is `Result`**, `Effect.either` is `Effect.result`.
562
+ 6. **`Data.TaggedError` errors are yieldable** — `yield* new SpawnError({...})` fails
563
+ the effect directly, no `Effect.fail` wrapper needed (works in v3 too, but idiomatic
564
+ in v4 docs).
565
+ 7. **Chunk → Array**: stream element groups are plain arrays (`Stream.fromArray`,
566
+ `runCollect` returns `Array<A>`), not `Chunk`.
567
+ 8. `tryPromise` default error is `Cause.UnknownError` (was `UnknownException`).
568
+ 9. `unstable/*` modules can break between v4 minors — pin exact versions
569
+ (`4.0.0-beta.98`) and keep `effect` and `@effect/platform-node` in lockstep.
570
+ 10. Scratch workspace with all verified test files: `/tmp/effect-v4-scratch`
571
+ (`test1-basics.ts` … `test8-runtime.ts`, `smoke.mts` executed successfully).