@asterxsk/kiln 0.3.0 → 0.4.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 (267) hide show
  1. package/README.md +2 -2
  2. package/agent/version.txt +1 -1
  3. package/bin/kiln.js +10 -8
  4. package/package.json +1 -1
  5. package/agent.bak.20260905-190020/AGENTS.md +0 -67
  6. package/agent.bak.20260905-190020/README.md +0 -5
  7. package/agent.bak.20260905-190020/extensions/ask-user/index.ts +0 -418
  8. package/agent.bak.20260905-190020/extensions/ask-user/install.ps1 +0 -23
  9. package/agent.bak.20260905-190020/extensions/ask-user/install.sh +0 -21
  10. package/agent.bak.20260905-190020/extensions/ask-user/package-lock.json +0 -769
  11. package/agent.bak.20260905-190020/extensions/ask-user/package.json +0 -19
  12. package/agent.bak.20260905-190020/extensions/ask-user/prompt.ts +0 -45
  13. package/agent.bak.20260905-190020/extensions/ask-user/tsconfig.json +0 -7
  14. package/agent.bak.20260905-190020/extensions/background-terminals/docs/implementation-guide.md +0 -942
  15. package/agent.bak.20260905-190020/extensions/background-terminals/index.ts +0 -629
  16. package/agent.bak.20260905-190020/extensions/background-terminals/install.ps1 +0 -23
  17. package/agent.bak.20260905-190020/extensions/background-terminals/install.sh +0 -21
  18. package/agent.bak.20260905-190020/extensions/background-terminals/package-lock.json +0 -769
  19. package/agent.bak.20260905-190020/extensions/background-terminals/package.json +0 -17
  20. package/agent.bak.20260905-190020/extensions/background-terminals/src/domain.ts +0 -87
  21. package/agent.bak.20260905-190020/extensions/background-terminals/src/manager.ts +0 -907
  22. package/agent.bak.20260905-190020/extensions/background-terminals/src/output.ts +0 -84
  23. package/agent.bak.20260905-190020/extensions/background-terminals/src/prompt.ts +0 -142
  24. package/agent.bak.20260905-190020/extensions/background-terminals/src/result-delivery.ts +0 -27
  25. package/agent.bak.20260905-190020/extensions/background-terminals/src/runtime.ts +0 -36
  26. package/agent.bak.20260905-190020/extensions/background-terminals/src/ui/output-view.ts +0 -79
  27. package/agent.bak.20260905-190020/extensions/background-terminals/src/ui/ps.ts +0 -621
  28. package/agent.bak.20260905-190020/extensions/background-terminals/src/widget-order.ts +0 -121
  29. package/agent.bak.20260905-190020/extensions/background-terminals/test/manager.test.ts +0 -735
  30. package/agent.bak.20260905-190020/extensions/background-terminals/test/output.test.ts +0 -109
  31. package/agent.bak.20260905-190020/extensions/background-terminals/test/prompt.test.ts +0 -125
  32. package/agent.bak.20260905-190020/extensions/background-terminals/test/ps.test.ts +0 -82
  33. package/agent.bak.20260905-190020/extensions/background-terminals/test/result-delivery.test.ts +0 -44
  34. package/agent.bak.20260905-190020/extensions/background-terminals/tsconfig.json +0 -7
  35. package/agent.bak.20260905-190020/extensions/destructive/README.md +0 -34
  36. package/agent.bak.20260905-190020/extensions/destructive/index.ts +0 -124
  37. package/agent.bak.20260905-190020/extensions/destructive/install.ps1 +0 -23
  38. package/agent.bak.20260905-190020/extensions/destructive/install.sh +0 -21
  39. package/agent.bak.20260905-190020/extensions/file-search/index.ts +0 -459
  40. package/agent.bak.20260905-190020/extensions/file-search/install.ps1 +0 -23
  41. package/agent.bak.20260905-190020/extensions/file-search/install.sh +0 -21
  42. package/agent.bak.20260905-190020/extensions/file-search/package-lock.json +0 -2253
  43. package/agent.bak.20260905-190020/extensions/file-search/package.json +0 -23
  44. package/agent.bak.20260905-190020/extensions/file-search/src/args.ts +0 -122
  45. package/agent.bak.20260905-190020/extensions/file-search/src/binaries.ts +0 -422
  46. package/agent.bak.20260905-190020/extensions/file-search/src/output.ts +0 -126
  47. package/agent.bak.20260905-190020/extensions/file-search/src/process.ts +0 -146
  48. package/agent.bak.20260905-190020/extensions/file-search/src/prompt.ts +0 -52
  49. package/agent.bak.20260905-190020/extensions/file-search/test/index.spec.ts +0 -443
  50. package/agent.bak.20260905-190020/extensions/file-search/tsconfig.json +0 -7
  51. package/agent.bak.20260905-190020/extensions/goal/README.md +0 -50
  52. package/agent.bak.20260905-190020/extensions/goal/index.ts +0 -155
  53. package/agent.bak.20260905-190020/extensions/goal/install.ps1 +0 -23
  54. package/agent.bak.20260905-190020/extensions/goal/install.sh +0 -21
  55. package/agent.bak.20260905-190020/extensions/kiln-update/README.md +0 -25
  56. package/agent.bak.20260905-190020/extensions/kiln-update/index.ts +0 -99
  57. package/agent.bak.20260905-190020/extensions/kiln-update/install.ps1 +0 -23
  58. package/agent.bak.20260905-190020/extensions/kiln-update/install.sh +0 -21
  59. package/agent.bak.20260905-190020/extensions/modelconf/PLAN.md +0 -915
  60. package/agent.bak.20260905-190020/extensions/modelconf/README.md +0 -66
  61. package/agent.bak.20260905-190020/extensions/modelconf/index.ts +0 -296
  62. package/agent.bak.20260905-190020/extensions/modelconf/install.ps1 +0 -23
  63. package/agent.bak.20260905-190020/extensions/modelconf/install.sh +0 -21
  64. package/agent.bak.20260905-190020/extensions/modelconf/package-lock.json +0 -1809
  65. package/agent.bak.20260905-190020/extensions/modelconf/package.json +0 -13
  66. package/agent.bak.20260905-190020/extensions/modelconf/src/fuzzy.ts +0 -26
  67. package/agent.bak.20260905-190020/extensions/modelconf/src/glob.ts +0 -13
  68. package/agent.bak.20260905-190020/extensions/modelconf/src/persistence.test.ts +0 -46
  69. package/agent.bak.20260905-190020/extensions/modelconf/src/persistence.ts +0 -164
  70. package/agent.bak.20260905-190020/extensions/modelconf/src/ui/ModelConfView.test.ts +0 -75
  71. package/agent.bak.20260905-190020/extensions/modelconf/src/ui/ModelConfView.ts +0 -1101
  72. package/agent.bak.20260905-190020/extensions/modelconf/tsconfig.json +0 -15
  73. package/agent.bak.20260905-190020/extensions/pi-web-access/CHANGELOG.md +0 -690
  74. package/agent.bak.20260905-190020/extensions/pi-web-access/LICENSE +0 -21
  75. package/agent.bak.20260905-190020/extensions/pi-web-access/README.md +0 -470
  76. package/agent.bak.20260905-190020/extensions/pi-web-access/SECURITY.md +0 -5
  77. package/agent.bak.20260905-190020/extensions/pi-web-access/activity.ts +0 -101
  78. package/agent.bak.20260905-190020/extensions/pi-web-access/auth-fetch.ts +0 -148
  79. package/agent.bak.20260905-190020/extensions/pi-web-access/banner.png +0 -0
  80. package/agent.bak.20260905-190020/extensions/pi-web-access/brightdata-unlocker.ts +0 -272
  81. package/agent.bak.20260905-190020/extensions/pi-web-access/chrome-cookies.ts +0 -669
  82. package/agent.bak.20260905-190020/extensions/pi-web-access/content-find.ts +0 -139
  83. package/agent.bak.20260905-190020/extensions/pi-web-access/credential-source.ts +0 -191
  84. package/agent.bak.20260905-190020/extensions/pi-web-access/data-uri-sanitize.ts +0 -406
  85. package/agent.bak.20260905-190020/extensions/pi-web-access/datalab-pdf-extract.ts +0 -568
  86. package/agent.bak.20260905-190020/extensions/pi-web-access/declared-web-links.ts +0 -173
  87. package/agent.bak.20260905-190020/extensions/pi-web-access/evidence/CONTRACT-EVIDENCE.md +0 -496
  88. package/agent.bak.20260905-190020/extensions/pi-web-access/evidence/contract-probe.mjs +0 -140
  89. package/agent.bak.20260905-190020/extensions/pi-web-access/exa.ts +0 -526
  90. package/agent.bak.20260905-190020/extensions/pi-web-access/extract.ts +0 -1196
  91. package/agent.bak.20260905-190020/extensions/pi-web-access/feature-config.ts +0 -29
  92. package/agent.bak.20260905-190020/extensions/pi-web-access/fetch-params.ts +0 -111
  93. package/agent.bak.20260905-190020/extensions/pi-web-access/gemini-adc.ts +0 -298
  94. package/agent.bak.20260905-190020/extensions/pi-web-access/gemini-api.ts +0 -353
  95. package/agent.bak.20260905-190020/extensions/pi-web-access/gemini-pdf-extract.ts +0 -108
  96. package/agent.bak.20260905-190020/extensions/pi-web-access/gemini-search.ts +0 -21
  97. package/agent.bak.20260905-190020/extensions/pi-web-access/gemini-url-context.ts +0 -128
  98. package/agent.bak.20260905-190020/extensions/pi-web-access/gemini-web-config.ts +0 -101
  99. package/agent.bak.20260905-190020/extensions/pi-web-access/gemini-web.ts +0 -487
  100. package/agent.bak.20260905-190020/extensions/pi-web-access/github-api.ts +0 -197
  101. package/agent.bak.20260905-190020/extensions/pi-web-access/github-extract.ts +0 -746
  102. package/agent.bak.20260905-190020/extensions/pi-web-access/github-issue-pr.ts +0 -700
  103. package/agent.bak.20260905-190020/extensions/pi-web-access/index.ts +0 -1737
  104. package/agent.bak.20260905-190020/extensions/pi-web-access/package-lock.json +0 -5808
  105. package/agent.bak.20260905-190020/extensions/pi-web-access/package.json +0 -64
  106. package/agent.bak.20260905-190020/extensions/pi-web-access/page-query.ts +0 -96
  107. package/agent.bak.20260905-190020/extensions/pi-web-access/pdf-extract.ts +0 -409
  108. package/agent.bak.20260905-190020/extensions/pi-web-access/pi-web-fetch-demo.mp4 +0 -0
  109. package/agent.bak.20260905-190020/extensions/pi-web-access/promise-try.d.ts +0 -7
  110. package/agent.bak.20260905-190020/extensions/pi-web-access/query-rewrite.ts +0 -51
  111. package/agent.bak.20260905-190020/extensions/pi-web-access/render-search-error.ts +0 -170
  112. package/agent.bak.20260905-190020/extensions/pi-web-access/rsc-extract.ts +0 -338
  113. package/agent.bak.20260905-190020/extensions/pi-web-access/search-types.ts +0 -20
  114. package/agent.bak.20260905-190020/extensions/pi-web-access/source-check.ts +0 -282
  115. package/agent.bak.20260905-190020/extensions/pi-web-access/ssrf-protection.ts +0 -526
  116. package/agent.bak.20260905-190020/extensions/pi-web-access/storage.ts +0 -521
  117. package/agent.bak.20260905-190020/extensions/pi-web-access/summary-model-scope.ts +0 -125
  118. package/agent.bak.20260905-190020/extensions/pi-web-access/test/auth-fetch.test.mjs +0 -208
  119. package/agent.bak.20260905-190020/extensions/pi-web-access/test/brightdata-unlocker.test.mjs +0 -840
  120. package/agent.bak.20260905-190020/extensions/pi-web-access/test/chrome-cookie-extraction.test.mjs +0 -441
  121. package/agent.bak.20260905-190020/extensions/pi-web-access/test/config-path.test.mjs +0 -283
  122. package/agent.bak.20260905-190020/extensions/pi-web-access/test/content-find.test.mjs +0 -25
  123. package/agent.bak.20260905-190020/extensions/pi-web-access/test/credential-source.test.mjs +0 -118
  124. package/agent.bak.20260905-190020/extensions/pi-web-access/test/data-uri-sanitize.test.mjs +0 -210
  125. package/agent.bak.20260905-190020/extensions/pi-web-access/test/datalab-pdf-extract.test.mjs +0 -552
  126. package/agent.bak.20260905-190020/extensions/pi-web-access/test/declared-web-links.test.mjs +0 -212
  127. package/agent.bak.20260905-190020/extensions/pi-web-access/test/fetch-answer-storage.test.mjs +0 -40
  128. package/agent.bak.20260905-190020/extensions/pi-web-access/test/fetch-cache-storage.test.mjs +0 -334
  129. package/agent.bak.20260905-190020/extensions/pi-web-access/test/fetch-content-domain-policy.test.mjs +0 -95
  130. package/agent.bak.20260905-190020/extensions/pi-web-access/test/fetch-modes.test.mjs +0 -53
  131. package/agent.bak.20260905-190020/extensions/pi-web-access/test/fetch-not-found-guidance.test.mjs +0 -92
  132. package/agent.bak.20260905-190020/extensions/pi-web-access/test/fetch-params.test.mjs +0 -86
  133. package/agent.bak.20260905-190020/extensions/pi-web-access/test/fetch-render-call.test.mjs +0 -34
  134. package/agent.bak.20260905-190020/extensions/pi-web-access/test/fetch-routing.test.mjs +0 -173
  135. package/agent.bak.20260905-190020/extensions/pi-web-access/test/gemini-adc-auth.test.mjs +0 -257
  136. package/agent.bak.20260905-190020/extensions/pi-web-access/test/gemini-api-transport.test.mjs +0 -170
  137. package/agent.bak.20260905-190020/extensions/pi-web-access/test/gemini-pdf-extract.test.mjs +0 -133
  138. package/agent.bak.20260905-190020/extensions/pi-web-access/test/gemini-web-cookie-opt-in.test.mjs +0 -178
  139. package/agent.bak.20260905-190020/extensions/pi-web-access/test/gemini-web-header-overflow.test.mjs +0 -148
  140. package/agent.bak.20260905-190020/extensions/pi-web-access/test/get-search-content.test.mjs +0 -223
  141. package/agent.bak.20260905-190020/extensions/pi-web-access/test/github-extract.test.mjs +0 -378
  142. package/agent.bak.20260905-190020/extensions/pi-web-access/test/github-issue-pr.test.mjs +0 -565
  143. package/agent.bak.20260905-190020/extensions/pi-web-access/test/inline-content-config.test.mjs +0 -99
  144. package/agent.bak.20260905-190020/extensions/pi-web-access/test/lazy-extract-load.test.mjs +0 -118
  145. package/agent.bak.20260905-190020/extensions/pi-web-access/test/local-video-oversize.test.mjs +0 -52
  146. package/agent.bak.20260905-190020/extensions/pi-web-access/test/package-typebox-dependency.test.mjs +0 -50
  147. package/agent.bak.20260905-190020/extensions/pi-web-access/test/page-query.test.mjs +0 -51
  148. package/agent.bak.20260905-190020/extensions/pi-web-access/test/pdf-config.test.mjs +0 -140
  149. package/agent.bak.20260905-190020/extensions/pi-web-access/test/pdf-extract.test.mjs +0 -500
  150. package/agent.bak.20260905-190020/extensions/pi-web-access/test/proxy-transport.test.mjs +0 -286
  151. package/agent.bak.20260905-190020/extensions/pi-web-access/test/query-rewrite.test.mjs +0 -52
  152. package/agent.bak.20260905-190020/extensions/pi-web-access/test/rsc-fallback.test.mjs +0 -102
  153. package/agent.bak.20260905-190020/extensions/pi-web-access/test/search-error-render.test.mjs +0 -152
  154. package/agent.bak.20260905-190020/extensions/pi-web-access/test/search-providers.test.mjs +0 -274
  155. package/agent.bak.20260905-190020/extensions/pi-web-access/test/source-check.test.mjs +0 -179
  156. package/agent.bak.20260905-190020/extensions/pi-web-access/test/ssrf-allow-ranges-config.test.mjs +0 -205
  157. package/agent.bak.20260905-190020/extensions/pi-web-access/test/ssrf-protection.test.mjs +0 -456
  158. package/agent.bak.20260905-190020/extensions/pi-web-access/test/summary-model-scope.test.mjs +0 -106
  159. package/agent.bak.20260905-190020/extensions/pi-web-access/test/tool-registration-config.test.mjs +0 -182
  160. package/agent.bak.20260905-190020/extensions/pi-web-access/test/web-search-answer-render.test.mjs +0 -66
  161. package/agent.bak.20260905-190020/extensions/pi-web-access/test/youtube-extract-errors.test.mjs +0 -64
  162. package/agent.bak.20260905-190020/extensions/pi-web-access/tsconfig.json +0 -11
  163. package/agent.bak.20260905-190020/extensions/pi-web-access/utils.ts +0 -451
  164. package/agent.bak.20260905-190020/extensions/pi-web-access/video-extract.ts +0 -392
  165. package/agent.bak.20260905-190020/extensions/pi-web-access/youtube-extract.ts +0 -328
  166. package/agent.bak.20260905-190020/extensions/shared/activity-status.ts +0 -31
  167. package/agent.bak.20260905-190020/extensions/shared/child-session.ts +0 -148
  168. package/agent.bak.20260905-190020/extensions/shared/context-utilization.ts +0 -47
  169. package/agent.bak.20260905-190020/extensions/shared/dashboard-state.ts +0 -99
  170. package/agent.bak.20260905-190020/extensions/shared/install.ps1 +0 -23
  171. package/agent.bak.20260905-190020/extensions/shared/install.sh +0 -21
  172. package/agent.bak.20260905-190020/extensions/shared/test/child-session.test.ts +0 -270
  173. package/agent.bak.20260905-190020/extensions/shared/test/context-utilization.test.ts +0 -48
  174. package/agent.bak.20260905-190020/extensions/shared/test/tool-call-timeout.test.ts +0 -117
  175. package/agent.bak.20260905-190020/extensions/shared/test/widget-order.test.ts +0 -167
  176. package/agent.bak.20260905-190020/extensions/shared/tool-call-timeout.ts +0 -104
  177. package/agent.bak.20260905-190020/extensions/skillsconf/README.md +0 -74
  178. package/agent.bak.20260905-190020/extensions/skillsconf/index.ts +0 -92
  179. package/agent.bak.20260905-190020/extensions/skillsconf/install.ps1 +0 -23
  180. package/agent.bak.20260905-190020/extensions/skillsconf/install.sh +0 -21
  181. package/agent.bak.20260905-190020/extensions/skillsconf/package-lock.json +0 -1809
  182. package/agent.bak.20260905-190020/extensions/skillsconf/package.json +0 -18
  183. package/agent.bak.20260905-190020/extensions/skillsconf/src/delete-skill.test.ts +0 -64
  184. package/agent.bak.20260905-190020/extensions/skillsconf/src/delete-skill.ts +0 -45
  185. package/agent.bak.20260905-190020/extensions/skillsconf/src/filter.test.ts +0 -80
  186. package/agent.bak.20260905-190020/extensions/skillsconf/src/filter.ts +0 -74
  187. package/agent.bak.20260905-190020/extensions/skillsconf/src/fuzzy.ts +0 -26
  188. package/agent.bak.20260905-190020/extensions/skillsconf/src/persistence.test.ts +0 -72
  189. package/agent.bak.20260905-190020/extensions/skillsconf/src/persistence.ts +0 -169
  190. package/agent.bak.20260905-190020/extensions/skillsconf/src/ui/SkillConfView.test.ts +0 -337
  191. package/agent.bak.20260905-190020/extensions/skillsconf/src/ui/SkillConfView.ts +0 -758
  192. package/agent.bak.20260905-190020/extensions/skillsconf/src/ui/text-input.ts +0 -91
  193. package/agent.bak.20260905-190020/extensions/skillsconf/src/ui/tui-helpers.ts +0 -144
  194. package/agent.bak.20260905-190020/extensions/skillsconf/tsconfig.json +0 -15
  195. package/agent.bak.20260905-190020/extensions/statusline/index.ts +0 -282
  196. package/agent.bak.20260905-190020/extensions/statusline/install.ps1 +0 -23
  197. package/agent.bak.20260905-190020/extensions/statusline/install.sh +0 -21
  198. package/agent.bak.20260905-190020/extensions/subagents/docs/design-plan.md +0 -568
  199. package/agent.bak.20260905-190020/extensions/subagents/docs/effect-v4-extension-guide.md +0 -354
  200. package/agent.bak.20260905-190020/extensions/subagents/docs/effect-v4-notes.md +0 -571
  201. package/agent.bak.20260905-190020/extensions/subagents/index.ts +0 -826
  202. package/agent.bak.20260905-190020/extensions/subagents/install.ps1 +0 -23
  203. package/agent.bak.20260905-190020/extensions/subagents/install.sh +0 -21
  204. package/agent.bak.20260905-190020/extensions/subagents/package-lock.json +0 -2244
  205. package/agent.bak.20260905-190020/extensions/subagents/package.json +0 -19
  206. package/agent.bak.20260905-190020/extensions/subagents/src/backend.ts +0 -73
  207. package/agent.bak.20260905-190020/extensions/subagents/src/backends/claude.ts +0 -701
  208. package/agent.bak.20260905-190020/extensions/subagents/src/backends/codex.ts +0 -1060
  209. package/agent.bak.20260905-190020/extensions/subagents/src/backends/pi.ts +0 -575
  210. package/agent.bak.20260905-190020/extensions/subagents/src/backends/stub.ts +0 -300
  211. package/agent.bak.20260905-190020/extensions/subagents/src/by-the-way.ts +0 -21
  212. package/agent.bak.20260905-190020/extensions/subagents/src/domain.ts +0 -253
  213. package/agent.bak.20260905-190020/extensions/subagents/src/format.ts +0 -74
  214. package/agent.bak.20260905-190020/extensions/subagents/src/manager.ts +0 -736
  215. package/agent.bak.20260905-190020/extensions/subagents/src/prompt.ts +0 -92
  216. package/agent.bak.20260905-190020/extensions/subagents/src/result-delivery.ts +0 -20
  217. package/agent.bak.20260905-190020/extensions/subagents/src/runtime.ts +0 -53
  218. package/agent.bak.20260905-190020/extensions/subagents/src/ui/takeover.ts +0 -583
  219. package/agent.bak.20260905-190020/extensions/subagents/src/ui/transcript.ts +0 -201
  220. package/agent.bak.20260905-190020/extensions/subagents/src/widget-order.ts +0 -121
  221. package/agent.bak.20260905-190020/extensions/subagents/test/by-the-way.test.ts +0 -29
  222. package/agent.bak.20260905-190020/extensions/subagents/test/claude.test.ts +0 -119
  223. package/agent.bak.20260905-190020/extensions/subagents/test/codex.test.ts +0 -102
  224. package/agent.bak.20260905-190020/extensions/subagents/test/context-usage.test.ts +0 -107
  225. package/agent.bak.20260905-190020/extensions/subagents/test/manager.test.ts +0 -276
  226. package/agent.bak.20260905-190020/extensions/subagents/test/result-delivery.test.ts +0 -27
  227. package/agent.bak.20260905-190020/extensions/subagents/test/takeover.test.ts +0 -29
  228. package/agent.bak.20260905-190020/extensions/subagents/tsconfig.json +0 -7
  229. package/agent.bak.20260905-190020/extensions/taste/index.ts +0 -443
  230. package/agent.bak.20260905-190020/extensions/taste/install.ps1 +0 -23
  231. package/agent.bak.20260905-190020/extensions/taste/install.sh +0 -21
  232. package/agent.bak.20260905-190020/extensions/todo/AGENTS.md +0 -38
  233. package/agent.bak.20260905-190020/extensions/todo/LICENSE +0 -21
  234. package/agent.bak.20260905-190020/extensions/todo/config.ts +0 -55
  235. package/agent.bak.20260905-190020/extensions/todo/index.ts +0 -151
  236. package/agent.bak.20260905-190020/extensions/todo/install.ps1 +0 -23
  237. package/agent.bak.20260905-190020/extensions/todo/install.sh +0 -21
  238. package/agent.bak.20260905-190020/extensions/todo/locales/de.json +0 -17
  239. package/agent.bak.20260905-190020/extensions/todo/locales/en.json +0 -15
  240. package/agent.bak.20260905-190020/extensions/todo/locales/es.json +0 -17
  241. package/agent.bak.20260905-190020/extensions/todo/locales/fr.json +0 -17
  242. package/agent.bak.20260905-190020/extensions/todo/locales/pt-BR.json +0 -17
  243. package/agent.bak.20260905-190020/extensions/todo/locales/pt.json +0 -17
  244. package/agent.bak.20260905-190020/extensions/todo/locales/ru.json +0 -17
  245. package/agent.bak.20260905-190020/extensions/todo/locales/uk.json +0 -17
  246. package/agent.bak.20260905-190020/extensions/todo/locales/zh.json +0 -17
  247. package/agent.bak.20260905-190020/extensions/todo/package-lock.json +0 -3358
  248. package/agent.bak.20260905-190020/extensions/todo/package.json +0 -67
  249. package/agent.bak.20260905-190020/extensions/todo/state/i18n-bridge.ts +0 -64
  250. package/agent.bak.20260905-190020/extensions/todo/state/invariants.ts +0 -20
  251. package/agent.bak.20260905-190020/extensions/todo/state/replay.ts +0 -38
  252. package/agent.bak.20260905-190020/extensions/todo/state/selectors.ts +0 -107
  253. package/agent.bak.20260905-190020/extensions/todo/state/state-reducer.ts +0 -326
  254. package/agent.bak.20260905-190020/extensions/todo/state/state.ts +0 -18
  255. package/agent.bak.20260905-190020/extensions/todo/state/store.ts +0 -82
  256. package/agent.bak.20260905-190020/extensions/todo/state/task-graph.ts +0 -57
  257. package/agent.bak.20260905-190020/extensions/todo/todo-overlay.ts +0 -204
  258. package/agent.bak.20260905-190020/extensions/todo/todo.ts +0 -155
  259. package/agent.bak.20260905-190020/extensions/todo/tool/response-envelope.ts +0 -109
  260. package/agent.bak.20260905-190020/extensions/todo/tool/types.ts +0 -206
  261. package/agent.bak.20260905-190020/extensions/todo/view/format.ts +0 -177
  262. package/agent.bak.20260905-190020/extensions/todo/widget-order.ts +0 -121
  263. package/agent.bak.20260905-190020/extensions/trim-context/README.md +0 -54
  264. package/agent.bak.20260905-190020/extensions/trim-context/index.ts +0 -487
  265. package/agent.bak.20260905-190020/extensions/trim-context/install.ps1 +0 -23
  266. package/agent.bak.20260905-190020/extensions/trim-context/install.sh +0 -21
  267. package/agent.bak.20260905-190020/keybindings.json +0 -7
@@ -1,907 +0,0 @@
1
- /**
2
- * TerminalManager — owns the registry of running/settled background
3
- * terminals.
4
- *
5
- * Each terminal is a raw `node:child_process` spawn (own process group on
6
- * POSIX, stdin ignored) whose stdout/stderr 'data' callbacks fold into two
7
- * bounded OutputBuffers. Closing a terminal's scope kills the whole process
8
- * tree (SIGTERM → SIGKILL escalation).
9
- *
10
- * The manager also exposes a synchronous `TerminalReadModel` so the
11
- * imperative TUI components (which render synchronously) can read snapshots
12
- * and issue fire-and-forget kills without touching the Effect runtime.
13
- */
14
-
15
- import { spawn, type ChildProcess } from "node:child_process";
16
- import * as fs from "node:fs";
17
- import * as os from "node:os";
18
- import * as path from "node:path";
19
- import {
20
- Context,
21
- Deferred,
22
- Effect,
23
- Exit,
24
- FiberSet,
25
- Layer,
26
- Scope,
27
- } from "effect";
28
- import {
29
- ConcurrencyLimitError,
30
- formatExit,
31
- SpawnError,
32
- UnknownTerminalError,
33
- type TerminalSnapshot,
34
- type TerminalStatus,
35
- } from "./domain.ts";
36
- import { OutputBuffer } from "./output.ts";
37
-
38
- export const MAX_RUNNING = 8;
39
- export const MAX_TRACKED = 32;
40
- const MAX_SETTLED_HISTORY = MAX_TRACKED * 4;
41
- /** In-memory retained cap per stream. */
42
- export const RETAINED_PER_STREAM = 2 * 1024 * 1024;
43
- /** Private full-log spills are bounded so a firehose cannot fill the temp disk. */
44
- export const MAX_SPILL_BYTES_PER_STREAM = 256 * 1024 * 1024;
45
- const STOP_TIMEOUT_MS = 5_000;
46
- /** SIGTERM is normally enough; the second deadline covers a wedged process. */
47
- const FORCE_KILL_AFTER_MS = 2_000;
48
- /** After termination, how long to wait for the natural close→flush→settle
49
- * path before force-settling (a grandchild can hold the stdio pipes open). */
50
- const SETTLE_GRACE_MS = 1_000;
51
- /** Bound on waiting for spill WriteStreams to flush before settling; a hung
52
- * filesystem must not leave an exited entry "running" (and kill() waiting).
53
- * Terminate (≤2.5s) + settle grace (1s) + flush (1.5s) stays inside the 5s
54
- * scope-close bound, so teardown remains bounded end to end. */
55
- const SPILL_FLUSH_TIMEOUT_MS = 1_500;
56
- const ERROR_TEXT_MAX_LENGTH = 4_096;
57
-
58
- function bounded(text: string) {
59
- return text.slice(0, ERROR_TEXT_MAX_LENGTH);
60
- }
61
-
62
- function boundedError(error: unknown) {
63
- return bounded(error instanceof Error ? error.message : String(error));
64
- }
65
-
66
- // --- Internal state -----------------------------------------------------------
67
-
68
- /** Mutable snapshot; exposed to readers via the readonly TerminalSnapshot type.
69
- * stdout/stderr are getters over the live OutputBuffers. */
70
- interface MutableSnapshot extends TerminalSnapshot {
71
- status: TerminalStatus;
72
- pid?: number;
73
- settledAt?: number;
74
- exitCode?: number;
75
- signal?: string;
76
- errorText?: string;
77
- }
78
-
79
- interface Entry {
80
- snapshot: MutableSnapshot;
81
- child: ChildProcess;
82
- scope: Scope.Closeable;
83
- stdoutBuf: OutputBuffer;
84
- stderrBuf: OutputBuffer;
85
- spillStreams: fs.WriteStream[];
86
- /** Set in the same synchronous effect that sends SIGTERM so a natural exit
87
- * before signaling keeps its truthful status. */
88
- killSignaled: boolean;
89
- /** The child emitted 'error' (spawn failure etc.); settles as "failed".
90
- * Kept separate from errorText, which also carries non-fatal notes
91
- * (spill failures) that must not flip a clean exit to "failed". */
92
- processErrored: boolean;
93
- /** 'exit' event observed (code/signal recorded). */
94
- exited: boolean;
95
- /** 'close' event observed (stdio flushed; the settle trigger). */
96
- stdioClosed: boolean;
97
- /** A settle-after-spill-flush is in flight; don't start a second one. */
98
- settling: boolean;
99
- /** The shell exited without stdio closing; a bounded scope close is queued
100
- * to reap descendants that still hold the inherited pipes open. */
101
- exitCleanupStarted: boolean;
102
- /** Completed exactly once when the entry settles. Kill callers and the scope
103
- * finalizer can all await the same result without missing a notification. */
104
- settled: Deferred.Deferred<void>;
105
- }
106
-
107
- export interface StartOptions {
108
- readonly command: string;
109
- readonly title: string;
110
- readonly cwd: string;
111
- }
112
-
113
- export interface KillResult {
114
- readonly id: string;
115
- readonly title: string;
116
- readonly status: TerminalStatus;
117
- /** True when the entry was still running when this kill began. */
118
- readonly wasRunning: boolean;
119
- /** True when this call initiated the termination AND the entry settled as
120
- * killed (a natural exit that won the race reports killed: false). */
121
- readonly killed: boolean;
122
- /** Final exit rendering ("exit 0", "SIGTERM", ...) captured at settle time,
123
- * so reports stay accurate even if the entry is pruned afterwards. */
124
- readonly exit: string;
125
- }
126
-
127
- // --- Read model ----------------------------------------------------------------
128
-
129
- /** Synchronous bridge for the TUI. Snapshots are live objects; do not mutate. */
130
- export interface TerminalReadModel {
131
- list(): ReadonlyArray<TerminalSnapshot>;
132
- get(id: string): TerminalSnapshot | undefined;
133
- size(): number;
134
- /** Any-change notification (widget, /ps list). */
135
- subscribe(listener: () => void): () => void;
136
- /** Per-terminal notification (/ps detail view). */
137
- subscribeTo(id: string, listener: () => void): () => void;
138
- /** Fire-and-forget kill (dashboard/detail `x`). Not marked consumed: the
139
- * settle still flows back to the model as a follow-up message. */
140
- requestKill(id: string): void;
141
- /**
142
- * Register the settle hook. `consumed` is true when an active bg_kill is
143
- * collecting the result (so it must not also be delivered as a follow-up).
144
- */
145
- setOnSettled(
146
- hook: ((snap: TerminalSnapshot, consumed: boolean) => void) | undefined,
147
- ): void;
148
- }
149
-
150
- // --- Service --------------------------------------------------------------------
151
-
152
- export interface TerminalManagerShape {
153
- start(
154
- options: StartOptions,
155
- ): Effect.Effect<TerminalSnapshot, SpawnError | ConcurrencyLimitError>;
156
- status(id: string): Effect.Effect<TerminalSnapshot, UnknownTerminalError>;
157
- /** Kill running terminals; resolves only after they have settled. */
158
- kill(ids: ReadonlyArray<string>): Effect.Effect<ReadonlyArray<KillResult>>;
159
- readonly list: Effect.Effect<ReadonlyArray<TerminalSnapshot>>;
160
- readonly disposeAll: Effect.Effect<void>;
161
- readonly view: TerminalReadModel;
162
- }
163
-
164
- export class TerminalManager extends Context.Service<
165
- TerminalManager,
166
- TerminalManagerShape
167
- >()("background-terminals/TerminalManager") {}
168
-
169
- // --- Process helpers ------------------------------------------------------------
170
-
171
- function shellInvocation(command: string) {
172
- if (process.platform === "win32") {
173
- const shell = process.env.ComSpec ?? "cmd.exe";
174
- return { shell, args: ["/d", "/s", "/c", command] };
175
- }
176
- return { shell: "/bin/sh", args: ["-c", command] };
177
- }
178
-
179
- /** Signal the whole process group on POSIX so descendants (servers a shell
180
- * command spawned) die with it; a wedged child must not orphan its tree. */
181
- function killTree(child: ChildProcess, signal: NodeJS.Signals) {
182
- if (process.platform === "win32" && child.pid) {
183
- try {
184
- const killer = spawn(
185
- "taskkill",
186
- [
187
- "/pid",
188
- String(child.pid),
189
- "/T",
190
- ...(signal === "SIGKILL" ? ["/F"] : []),
191
- ],
192
- { stdio: "ignore", windowsHide: true },
193
- );
194
- killer.once("error", () => {
195
- try {
196
- child.kill(signal);
197
- } catch {
198
- // Process may already be gone.
199
- }
200
- });
201
- killer.once("exit", (code) => {
202
- if (code === 0) return;
203
- try {
204
- child.kill(signal);
205
- } catch {
206
- // Process may already be gone.
207
- }
208
- });
209
- killer.unref();
210
- return;
211
- } catch {
212
- // Fall through to the direct signal when taskkill cannot be launched.
213
- }
214
- }
215
- if (process.platform !== "win32" && child.pid) {
216
- try {
217
- process.kill(-child.pid, signal);
218
- return;
219
- } catch {
220
- // Group may already be gone; fall through to the direct signal.
221
- }
222
- }
223
- try {
224
- child.kill(signal);
225
- } catch {
226
- // Process may already be gone.
227
- }
228
- }
229
-
230
- /** Await stdio closure without retaining a listener after interruption. */
231
- function awaitChildClose(child: ChildProcess, closed: () => boolean) {
232
- return Effect.callback<void>((resume) => {
233
- if (closed()) {
234
- resume(Effect.void);
235
- return;
236
- }
237
- const onClose = () => resume(Effect.void);
238
- child.once("close", onClose);
239
- return Effect.sync(() => child.off("close", onClose));
240
- });
241
- }
242
-
243
- /** SIGTERM → deadline → SIGKILL; waits for stdio closure rather than only the
244
- * shell's exit because descendants can keep the inherited pipes and process
245
- * group alive after the shell itself is gone. */
246
- function terminateChild(
247
- child: ChildProcess,
248
- closed: () => boolean,
249
- onSignal: () => void,
250
- ) {
251
- return Effect.suspend(() => {
252
- if (closed()) return Effect.void;
253
- return Effect.gen(function* () {
254
- yield* Effect.sync(() => {
255
- onSignal();
256
- killTree(child, "SIGTERM");
257
- });
258
- yield* awaitChildClose(child, closed).pipe(
259
- Effect.timeout(FORCE_KILL_AFTER_MS),
260
- Effect.ignore,
261
- );
262
- if (closed()) return;
263
- yield* Effect.sync(() => killTree(child, "SIGKILL"));
264
- yield* awaitChildClose(child, closed).pipe(
265
- Effect.timeout(500),
266
- Effect.ignore,
267
- );
268
- });
269
- });
270
- }
271
-
272
- // --- Implementation --------------------------------------------------------------
273
-
274
- const makeManager = Effect.gen(function* () {
275
- // Scoped detached forker for sync contexts (read-model kills, process-event
276
- // settlement, pruning). Completed fibers remove themselves; manager scope
277
- // close interrupts any work that outlives the bounded disposeAll wait.
278
- const cleanupFibers = yield* FiberSet.make();
279
- const runCleanup = yield* FiberSet.runtime(cleanupFibers)();
280
-
281
- const entries = new Map<string, Entry>();
282
- /** Small immutable tombstones preserve truthful kill reports if pruning
283
- * races the tool boundary after an id was validated. */
284
- const settledHistory = new Map<
285
- string,
286
- Pick<KillResult, "title" | "status" | "exit">
287
- >();
288
- /** ids with an in-flight kill() collecting the result (settle → consumed). */
289
- const killInterest = new Map<string, number>();
290
- const listeners = new Set<() => void>();
291
- const idListeners = new Map<string, Set<() => void>>();
292
- let counter = 0;
293
- let reserved = 0;
294
- let disposed = false;
295
- let spillDir: string | undefined | null;
296
- let onSettled:
297
- ((snap: TerminalSnapshot, consumed: boolean) => void) | undefined;
298
-
299
- const notify = (id?: string) => {
300
- for (const listener of [...listeners]) {
301
- try {
302
- listener();
303
- } catch {
304
- // A failed widget/render listener must not corrupt lifecycle state.
305
- }
306
- }
307
- if (id) {
308
- for (const listener of idListeners.get(id) ?? []) {
309
- try {
310
- listener();
311
- } catch {
312
- // Same.
313
- }
314
- }
315
- }
316
- };
317
-
318
- const runningCount = () =>
319
- [...entries.values()].filter((e) => e.snapshot.status === "running").length;
320
-
321
- const addKillInterest = (ids: ReadonlyArray<string>) => {
322
- for (const id of ids) killInterest.set(id, (killInterest.get(id) ?? 0) + 1);
323
- };
324
- const releaseKillInterest = (ids: ReadonlyArray<string>) => {
325
- for (const id of ids) {
326
- const count = (killInterest.get(id) ?? 1) - 1;
327
- if (count <= 0) killInterest.delete(id);
328
- else killInterest.set(id, count);
329
- }
330
- };
331
-
332
- const closeEntryScope = (entry: Entry) =>
333
- Scope.close(entry.scope, Exit.void).pipe(Effect.ignore);
334
-
335
- const pruneSettled = () => {
336
- if (entries.size <= MAX_TRACKED) return;
337
- const candidates = [...entries.values()]
338
- .filter(
339
- (e) =>
340
- e.snapshot.status !== "running" && !killInterest.has(e.snapshot.id),
341
- )
342
- .sort(
343
- (a, b) =>
344
- (a.snapshot.settledAt ?? a.snapshot.createdAt) -
345
- (b.snapshot.settledAt ?? b.snapshot.createdAt),
346
- );
347
- for (const entry of candidates) {
348
- if (entries.size <= MAX_TRACKED) break;
349
- entries.delete(entry.snapshot.id);
350
- runCleanup(closeEntryScope(entry));
351
- }
352
- };
353
-
354
- /** End all spill streams; resolves when their buffers are flushed to disk
355
- * (bounded), so a settle notification never points at a partial file. */
356
- const flushSpillStreams = (entry: Entry) => {
357
- const streams = entry.spillStreams;
358
- entry.spillStreams = [];
359
- return Effect.forEach(
360
- streams,
361
- (stream) =>
362
- Effect.callback<void>((resume) => {
363
- const done = () => resume(Effect.void);
364
- try {
365
- stream.end(done);
366
- } catch {
367
- // Best effort; tmpdir contents are disposable.
368
- done();
369
- }
370
- }),
371
- { concurrency: "unbounded", discard: true },
372
- ).pipe(
373
- Effect.timeoutOrElse({
374
- duration: SPILL_FLUSH_TIMEOUT_MS,
375
- orElse: () =>
376
- Effect.sync(() => {
377
- entry.stdoutBuf.spillPath = undefined;
378
- entry.stderrBuf.spillPath = undefined;
379
- entry.snapshot.errorText ??=
380
- "Full-log spill flush timed out; full output may be incomplete";
381
- }),
382
- }),
383
- );
384
- };
385
-
386
- /** Single settle path — idempotent; kill vs natural exit vs error races are
387
- * resolved by whichever lands first (the second call is a no-op). */
388
- const settle = (entry: Entry) => {
389
- const s = entry.snapshot;
390
- if (s.status !== "running") return;
391
- s.settledAt = Date.now();
392
- s.status = entry.killSignaled
393
- ? "killed"
394
- : entry.processErrored
395
- ? "failed"
396
- : s.exitCode === 0
397
- ? "done"
398
- : "failed";
399
- settledHistory.set(s.id, {
400
- title: s.title,
401
- status: s.status,
402
- exit: formatExit(s),
403
- });
404
- while (settledHistory.size > MAX_SETTLED_HISTORY) {
405
- const oldest = settledHistory.keys().next().value;
406
- if (oldest === undefined) break;
407
- settledHistory.delete(oldest);
408
- }
409
- // Completing the Deferred can immediately resume kill waiters, whose
410
- // ensuring blocks release interest. Snapshot consumption first so the
411
- // settle hook observes the interest that existed when settlement won.
412
- const consumed = (killInterest.get(s.id) ?? 0) > 0;
413
- Deferred.doneUnsafe(entry.settled, Effect.void);
414
- notify(s.id);
415
- try {
416
- // During teardown, don't queue results into a shutting-down session.
417
- if (!disposed) onSettled?.(s, consumed);
418
- } catch {
419
- // The parent session may be unavailable; settlement stays final.
420
- }
421
- pruneSettled();
422
- };
423
-
424
- /** Flush the spill files, then settle: the completion follow-up (and the
425
- * kill() resolution) reference the spill path, so the full capture must be
426
- * on disk before anyone is told about it. Idempotent via `settling`. */
427
- const settleAfterFlush = (entry: Entry) => {
428
- if (entry.settling || entry.snapshot.status !== "running") return;
429
- entry.settling = true;
430
- runCleanup(
431
- flushSpillStreams(entry).pipe(
432
- Effect.andThen(Effect.sync(() => settle(entry))),
433
- ),
434
- );
435
- };
436
-
437
- const scheduleExitCleanup = (entry: Entry) => {
438
- if (entry.exitCleanupStarted) return;
439
- entry.exitCleanupStarted = true;
440
- runCleanup(
441
- Effect.sleep(SETTLE_GRACE_MS).pipe(
442
- Effect.andThen(
443
- Effect.suspend(() =>
444
- entry.snapshot.status === "running" && !entry.stdioClosed
445
- ? closeEntryScope(entry).pipe(
446
- Effect.timeout(STOP_TIMEOUT_MS),
447
- Effect.ignore,
448
- )
449
- : Effect.void,
450
- ),
451
- ),
452
- ),
453
- );
454
- };
455
-
456
- const resolveSpillDir = () => {
457
- if (spillDir !== undefined) return spillDir ?? undefined;
458
- try {
459
- const base = path.join(os.tmpdir(), "pi-background-terminals");
460
- fs.mkdirSync(base, { recursive: true, mode: 0o700 });
461
- fs.chmodSync(base, 0o700);
462
- spillDir = fs.mkdtempSync(path.join(base, "session-"));
463
- fs.chmodSync(spillDir, 0o700);
464
- } catch {
465
- spillDir = null;
466
- }
467
- return spillDir ?? undefined;
468
- };
469
-
470
- const makeSpill = (
471
- entry: () => Entry | undefined,
472
- id: string,
473
- stream: "stdout" | "stderr",
474
- resumeSource: () => void,
475
- ) => {
476
- const dir = resolveSpillDir();
477
- if (!dir) return undefined;
478
- const spillPath = path.join(dir, `${id}.${stream}.log`);
479
- try {
480
- const file = fs.createWriteStream(spillPath, {
481
- flags: "a",
482
- mode: 0o600,
483
- });
484
- let broken = false;
485
- let capped = false;
486
- let writtenBytes = 0;
487
- file.on("error", (error) => {
488
- broken = true;
489
- resumeSource();
490
- const current = entry();
491
- if (current) {
492
- const buf =
493
- stream === "stdout" ? current.stdoutBuf : current.stderrBuf;
494
- buf.spillPath = undefined;
495
- current.snapshot.errorText ??= bounded(
496
- `Full-log spill to ${spillPath} failed: ${boundedError(error)}`,
497
- );
498
- }
499
- });
500
- return {
501
- spillPath,
502
- file,
503
- write: (chunk: string) => {
504
- // writableEnded guard: late 'data' after the settle flush must not
505
- // error the ended stream (and falsely report the spill as broken).
506
- if (broken || capped || file.writableEnded) return true;
507
- const chunkBytes = Buffer.byteLength(chunk, "utf8");
508
- if (writtenBytes + chunkBytes > MAX_SPILL_BYTES_PER_STREAM) {
509
- capped = true;
510
- const current = entry();
511
- if (current) {
512
- const buf =
513
- stream === "stdout" ? current.stdoutBuf : current.stderrBuf;
514
- buf.spillPath = undefined;
515
- current.snapshot.errorText ??= bounded(
516
- `${stream} full-log spill reached the ${MAX_SPILL_BYTES_PER_STREAM}-byte safety limit`,
517
- );
518
- }
519
- return true;
520
- }
521
- writtenBytes += chunkBytes;
522
- const accepted = file.write(chunk);
523
- if (!accepted) file.once("drain", resumeSource);
524
- return accepted;
525
- },
526
- };
527
- } catch {
528
- return undefined;
529
- }
530
- };
531
-
532
- const start = (options: StartOptions) =>
533
- Effect.gen(function* () {
534
- // Reserve synchronously (before the first yield inside doStart) so
535
- // parallel tool calls cannot race past the cap.
536
- yield* Effect.suspend(
537
- (): Effect.Effect<void, SpawnError | ConcurrencyLimitError> => {
538
- if (disposed) {
539
- return new SpawnError({
540
- message: "Background terminal manager is shutting down.",
541
- });
542
- }
543
- if (runningCount() + reserved >= MAX_RUNNING) {
544
- return new ConcurrencyLimitError({
545
- message: `Max ${MAX_RUNNING} background terminals can run concurrently. Stop one with bg_kill before starting another.`,
546
- });
547
- }
548
- reserved++;
549
- return Effect.void;
550
- },
551
- );
552
-
553
- const doStart = Effect.gen(function* () {
554
- const { shell, args } = shellInvocation(options.command);
555
- const child = yield* Effect.try({
556
- try: () =>
557
- spawn(shell, args, {
558
- cwd: options.cwd,
559
- env: process.env,
560
- // stdin IGNORED: there is no input surface, ever. A process
561
- // that reads stdin sees EOF immediately.
562
- stdio: ["ignore", "pipe", "pipe"],
563
- // Own process group on POSIX → group kill takes the whole tree.
564
- detached: process.platform !== "win32",
565
- }),
566
- catch: (error) => new SpawnError({ message: boundedError(error) }),
567
- });
568
-
569
- const id = `bt-${++counter}`;
570
- const entryRef = () => entries.get(id);
571
- const stdoutSpill = makeSpill(entryRef, id, "stdout", () =>
572
- child.stdout?.resume(),
573
- );
574
- const stderrSpill = makeSpill(entryRef, id, "stderr", () =>
575
- child.stderr?.resume(),
576
- );
577
- const stdoutBuf = new OutputBuffer(
578
- RETAINED_PER_STREAM,
579
- stdoutSpill?.write,
580
- );
581
- const stderrBuf = new OutputBuffer(
582
- RETAINED_PER_STREAM,
583
- stderrSpill?.write,
584
- );
585
- stdoutBuf.spillPath = stdoutSpill?.spillPath;
586
- stderrBuf.spillPath = stderrSpill?.spillPath;
587
-
588
- const snapshot: MutableSnapshot = {
589
- id,
590
- command: options.command,
591
- title: options.title,
592
- cwd: options.cwd,
593
- pid: child.pid,
594
- status: "running",
595
- createdAt: Date.now(),
596
- get stdout() {
597
- return stdoutBuf.view();
598
- },
599
- get stderr() {
600
- return stderrBuf.view();
601
- },
602
- };
603
-
604
- const scope = yield* Scope.make();
605
- const settled = yield* Deferred.make<void>();
606
- const entry: Entry = {
607
- snapshot,
608
- child,
609
- scope,
610
- stdoutBuf,
611
- stderrBuf,
612
- spillStreams: [stdoutSpill?.file, stderrSpill?.file].filter(
613
- (file): file is fs.WriteStream => file !== undefined,
614
- ),
615
- killSignaled: false,
616
- processErrored: false,
617
- exited: false,
618
- stdioClosed: false,
619
- settling: false,
620
- exitCleanupStarted: false,
621
- settled,
622
- };
623
-
624
- // Plain-callback stream plumbing (the codex-backend precedent):
625
- // setEncoding's internal StringDecoder is multibyte-safe across
626
- // chunk boundaries.
627
- child.stdout?.setEncoding("utf8");
628
- child.stdout?.on("data", (chunk: string) => {
629
- if (!stdoutBuf.push(chunk)) child.stdout?.pause();
630
- notify(id);
631
- });
632
- child.stderr?.setEncoding("utf8");
633
- child.stderr?.on("data", (chunk: string) => {
634
- if (!stderrBuf.push(chunk)) child.stderr?.pause();
635
- notify(id);
636
- });
637
- // Spawn failures (ENOENT etc.) arrive via 'error', not a throw. Node
638
- // still emits 'close' afterwards (with a bogus errno as code), so
639
- // record the failure here and let the close path do the one settle.
640
- child.once("error", (error) => {
641
- entry.processErrored = true;
642
- snapshot.errorText ??= boundedError(error);
643
- entry.exited = true;
644
- settleAfterFlush(entry);
645
- });
646
- // Record code/signal on 'exit'; settle on 'close' so the completion
647
- // notification always carries the final flushed output.
648
- child.once("exit", (code, signal) => {
649
- entry.exited = true;
650
- snapshot.exitCode = code ?? undefined;
651
- snapshot.signal = signal ?? undefined;
652
- // A descendant can keep the pipes open after the shell exits. Give
653
- // close a short natural grace, then close the scope to terminate
654
- // the surviving process group and force a bounded settlement.
655
- scheduleExitCleanup(entry);
656
- });
657
- child.once("close", (code, signal) => {
658
- entry.exited = true;
659
- entry.stdioClosed = true;
660
- // Only trust close's code/signal when 'exit' never fired (a spawn
661
- // 'error' close reports the errno, e.g. -2, as its code).
662
- if (!entry.processErrored) {
663
- snapshot.exitCode ??= code ?? undefined;
664
- snapshot.signal ??= signal ?? undefined;
665
- }
666
- settleAfterFlush(entry);
667
- });
668
-
669
- // One teardown path: kill(), requestKill, pruning, disposeAll, and
670
- // runtime.dispose() all converge on closing this scope.
671
- yield* Scope.provide(
672
- Effect.addFinalizer(() =>
673
- Effect.gen(function* () {
674
- // Only claim "killed" when we are actually about to signal a
675
- // live process; a natural exit that already happened (still
676
- // waiting on 'close') keeps its truthful done/failed status.
677
- yield* terminateChild(
678
- child,
679
- () => entry.stdioClosed,
680
- () => {
681
- entry.killSignaled ||=
682
- !entry.exited && entry.snapshot.status === "running";
683
- },
684
- );
685
- // Give the natural close→flush→settle path a bounded grace,
686
- // then force the settle: a grandchild holding the pipe open
687
- // (detached into a new group) must not leave the entry
688
- // "running" forever.
689
- if (entry.snapshot.status === "running") {
690
- yield* Deferred.await(entry.settled).pipe(
691
- Effect.timeout(SETTLE_GRACE_MS),
692
- Effect.ignore,
693
- );
694
- }
695
- if (entry.snapshot.status === "running" && !entry.settling) {
696
- // Force the settle ourselves. When `settling` is set, the
697
- // close path's flush→settle is already in flight (bounded by
698
- // SPILL_FLUSH_TIMEOUT_MS) — settling here first would cite a
699
- // spill file that is still being flushed.
700
- if (!entry.stdioClosed) {
701
- entry.snapshot.errorText ??=
702
- "stdio did not close after termination; output may be incomplete";
703
- }
704
- entry.settling = true;
705
- yield* flushSpillStreams(entry);
706
- settle(entry);
707
- }
708
- }),
709
- ),
710
- scope,
711
- );
712
-
713
- // disposeAll may have swept the entries map while we were setting up;
714
- // an entry added after the sweep would never be torn down. Close our
715
- // own scope (kills the child) and fail instead (subagents precedent).
716
- if (disposed) {
717
- yield* closeEntryScope(entry);
718
- return yield* new SpawnError({
719
- message: "Background terminal manager shut down while starting.",
720
- });
721
- }
722
- entries.set(id, entry);
723
- notify(id);
724
- return snapshot as TerminalSnapshot;
725
- });
726
-
727
- // Uninterruptible: between spawn() and entries.set there must be no
728
- // window where an interrupt (tool abort, runtime dispose) leaves a
729
- // live child that no scope/registry knows about. All steps are sync.
730
- return yield* doStart.pipe(
731
- Effect.uninterruptible,
732
- Effect.ensuring(
733
- Effect.sync(() => {
734
- reserved--;
735
- notify();
736
- }),
737
- ),
738
- );
739
- });
740
-
741
- const status = (id: string) =>
742
- Effect.suspend(
743
- (): Effect.Effect<TerminalSnapshot, UnknownTerminalError> => {
744
- const entry = entries.get(id);
745
- if (!entry) {
746
- const known = [...entries.keys()];
747
- return new UnknownTerminalError({
748
- message: `Unknown terminal id "${id}". Known: ${known.join(", ") || "none"}.`,
749
- });
750
- }
751
- return Effect.succeed(entry.snapshot as TerminalSnapshot);
752
- },
753
- );
754
-
755
- /** Kill one running entry: close the scope — whose finalizer marks the kill
756
- * at the signal point, terminates the tree, and force-settles —
757
- * in a DETACHED fiber. Once the flag is set the termination must actually
758
- * happen; a tool abort interrupting the caller cannot cancel it (this is
759
- * what makes "termination continues in the background" truthful). */
760
- const killEntry = (entry: Entry) =>
761
- Effect.sync(() => {
762
- if (entry.snapshot.status !== "running") return;
763
- runCleanup(
764
- closeEntryScope(entry).pipe(
765
- Effect.timeout(STOP_TIMEOUT_MS),
766
- Effect.ignore,
767
- ),
768
- );
769
- });
770
-
771
- const kill = (ids: ReadonlyArray<string>) =>
772
- Effect.suspend(() => {
773
- const unique = [...new Set(ids)];
774
- const byId = new Map(
775
- unique
776
- .map((id) => entries.get(id))
777
- .filter((entry): entry is Entry => entry !== undefined)
778
- .map((entry) => [entry.snapshot.id, entry]),
779
- );
780
- const running = [...byId.values()].filter(
781
- (entry) => entry.snapshot.status === "running",
782
- );
783
- const runningIds = running.map((entry) => entry.snapshot.id);
784
- // Mark consumed before signaling so this kill's settlements are not
785
- // ALSO queued as automatic follow-up messages to the model.
786
- addKillInterest(runningIds);
787
- const work = Effect.gen(function* () {
788
- yield* Effect.forEach(running, killEntry, {
789
- concurrency: "unbounded",
790
- });
791
- // Every caller waits on the entries that were running when its kill
792
- // began. Deferred completion cannot be missed and supports concurrent
793
- // overlapping/multi-id kill calls.
794
- yield* Effect.forEach(
795
- running,
796
- (entry) => Deferred.await(entry.settled),
797
- { concurrency: "unbounded", discard: true },
798
- );
799
- // Capture the report BEFORE the ensuring below releases interest and
800
- // prunes — a just-settled entry must not vanish out from under it.
801
- return unique.map((id): KillResult => {
802
- const snapshot = byId.get(id)?.snapshot;
803
- const history = settledHistory.get(id);
804
- const status = snapshot?.status ?? history?.status ?? "killed";
805
- const wasRunning = runningIds.includes(id);
806
- return {
807
- id,
808
- title: snapshot?.title ?? history?.title ?? "?",
809
- status,
810
- wasRunning,
811
- // A natural exit can win the race with our SIGTERM; report what
812
- // actually happened rather than claiming the kill did it.
813
- killed: wasRunning && status === "killed",
814
- exit: snapshot
815
- ? formatExit(snapshot)
816
- : (history?.exit ?? "unknown"),
817
- };
818
- });
819
- });
820
- return work.pipe(
821
- Effect.ensuring(
822
- Effect.sync(() => {
823
- releaseKillInterest(runningIds);
824
- pruneSettled();
825
- }),
826
- ),
827
- );
828
- });
829
-
830
- const disposeAll = Effect.gen(function* () {
831
- disposed = true;
832
- const all = [...entries.values()];
833
- entries.clear();
834
- yield* Effect.forEach(
835
- all,
836
- (entry) =>
837
- closeEntryScope(entry).pipe(
838
- Effect.timeout(STOP_TIMEOUT_MS),
839
- Effect.ignore,
840
- ),
841
- { concurrency: "unbounded" },
842
- );
843
- // Detached kill/prune/flush work is scoped to the manager. Wait for it
844
- // within the shutdown bound; the FiberSet finalizer interrupts anything
845
- // still live when the manager scope closes, so cleanup cannot leak.
846
- yield* FiberSet.awaitEmpty(cleanupFibers).pipe(
847
- Effect.timeout(STOP_TIMEOUT_MS),
848
- Effect.ignore,
849
- );
850
- yield* Effect.sync(() => {
851
- const dir = spillDir;
852
- spillDir = null;
853
- if (dir) fs.rmSync(dir, { recursive: true, force: true });
854
- });
855
- yield* Effect.sync(() => notify());
856
- });
857
-
858
- const view: TerminalReadModel = {
859
- list: () => [...entries.values()].map((entry) => entry.snapshot),
860
- get: (id) => entries.get(id)?.snapshot,
861
- size: () => entries.size,
862
- subscribe: (listener) => {
863
- listeners.add(listener);
864
- return () => listeners.delete(listener);
865
- },
866
- subscribeTo: (id, listener) => {
867
- let set = idListeners.get(id);
868
- if (!set) {
869
- set = new Set();
870
- idListeners.set(id, set);
871
- }
872
- set.add(listener);
873
- return () => {
874
- set.delete(listener);
875
- if (set.size === 0) idListeners.delete(id);
876
- };
877
- },
878
- requestKill: (id) => {
879
- const entry = entries.get(id);
880
- if (!entry) return;
881
- // UI-initiated kills are not "consumed": the killed result still flows
882
- // back to the model as a follow-up message (subagents precedent).
883
- runCleanup(killEntry(entry).pipe(Effect.ignore));
884
- },
885
- setOnSettled: (hook) => {
886
- onSettled = hook;
887
- },
888
- };
889
-
890
- // Safety net: disposing the ManagedRuntime tears everything down even if
891
- // the extension forgot to call disposeAll explicitly.
892
- yield* Effect.addFinalizer(() => disposeAll);
893
-
894
- return TerminalManager.of({
895
- start,
896
- status,
897
- kill,
898
- list: Effect.sync(() => [...entries.values()].map((e) => e.snapshot)),
899
- disposeAll,
900
- view,
901
- });
902
- });
903
-
904
- export const TerminalManagerLive: Layer.Layer<TerminalManager> = Layer.effect(
905
- TerminalManager,
906
- makeManager,
907
- );