@code-yeongyu/senpi 2026.9.15 → 2026.9.16-2

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 (333) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +1 -1
  3. package/dist/core/agent-session.d.ts +28 -0
  4. package/dist/core/agent-session.d.ts.map +1 -1
  5. package/dist/core/agent-session.js +111 -13
  6. package/dist/core/agent-session.js.map +1 -1
  7. package/dist/core/compaction/compaction.d.ts.map +1 -1
  8. package/dist/core/compaction/compaction.js +4 -2
  9. package/dist/core/compaction/compaction.js.map +1 -1
  10. package/dist/core/compaction/stream-watchdog.d.ts +56 -2
  11. package/dist/core/compaction/stream-watchdog.d.ts.map +1 -1
  12. package/dist/core/compaction/stream-watchdog.js +93 -15
  13. package/dist/core/compaction/stream-watchdog.js.map +1 -1
  14. package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.d.ts +6 -0
  15. package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.d.ts.map +1 -1
  16. package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js +17 -0
  17. package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js.map +1 -1
  18. package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.d.ts +4 -1
  19. package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.d.ts.map +1 -1
  20. package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.js +31 -0
  21. package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.js.map +1 -1
  22. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts +2 -0
  23. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts.map +1 -1
  24. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js +16 -0
  25. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js.map +1 -1
  26. package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.d.ts.map +1 -1
  27. package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js +19 -8
  28. package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js.map +1 -1
  29. package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.d.ts.map +1 -1
  30. package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.js +2 -1
  31. package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.js.map +1 -1
  32. package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts +13 -1
  33. package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts.map +1 -1
  34. package/dist/core/extensions/builtin/compaction/deterministic-fallback.js +66 -2
  35. package/dist/core/extensions/builtin/compaction/deterministic-fallback.js.map +1 -1
  36. package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
  37. package/dist/core/extensions/builtin/compaction/index.js +16 -10
  38. package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
  39. package/dist/core/extensions/builtin/compaction/speculative-summary.d.ts.map +1 -1
  40. package/dist/core/extensions/builtin/compaction/speculative-summary.js +4 -2
  41. package/dist/core/extensions/builtin/compaction/speculative-summary.js.map +1 -1
  42. package/dist/core/extensions/builtin/compaction/speculative.d.ts +8 -1
  43. package/dist/core/extensions/builtin/compaction/speculative.d.ts.map +1 -1
  44. package/dist/core/extensions/builtin/compaction/speculative.js +31 -7
  45. package/dist/core/extensions/builtin/compaction/speculative.js.map +1 -1
  46. package/dist/core/extensions/builtin/compaction/transient-failure.d.ts.map +1 -1
  47. package/dist/core/extensions/builtin/compaction/transient-failure.js +6 -3
  48. package/dist/core/extensions/builtin/compaction/transient-failure.js.map +1 -1
  49. package/dist/core/extensions/builtin/config-reload/index.d.ts.map +1 -1
  50. package/dist/core/extensions/builtin/config-reload/index.js +25 -8
  51. package/dist/core/extensions/builtin/config-reload/index.js.map +1 -1
  52. package/dist/core/extensions/builtin/config-reload/watch-engine.d.ts +4 -5
  53. package/dist/core/extensions/builtin/config-reload/watch-engine.d.ts.map +1 -1
  54. package/dist/core/extensions/builtin/config-reload/watch-engine.js +14 -18
  55. package/dist/core/extensions/builtin/config-reload/watch-engine.js.map +1 -1
  56. package/dist/core/extensions/builtin/config-reload/watch-event-source.d.ts.map +1 -1
  57. package/dist/core/extensions/builtin/config-reload/watch-event-source.js +32 -9
  58. package/dist/core/extensions/builtin/config-reload/watch-event-source.js.map +1 -1
  59. package/dist/core/extensions/builtin/cursor-cli-oauth/catalog-refresh.d.ts +23 -0
  60. package/dist/core/extensions/builtin/cursor-cli-oauth/catalog-refresh.d.ts.map +1 -0
  61. package/dist/core/extensions/builtin/cursor-cli-oauth/catalog-refresh.js +48 -0
  62. package/dist/core/extensions/builtin/cursor-cli-oauth/catalog-refresh.js.map +1 -0
  63. package/dist/core/extensions/builtin/cursor-cli-oauth/environment.d.ts +13 -0
  64. package/dist/core/extensions/builtin/cursor-cli-oauth/environment.d.ts.map +1 -0
  65. package/dist/core/extensions/builtin/cursor-cli-oauth/environment.js +24 -0
  66. package/dist/core/extensions/builtin/cursor-cli-oauth/environment.js.map +1 -0
  67. package/dist/core/extensions/builtin/cursor-cli-oauth/executable.d.ts +1 -0
  68. package/dist/core/extensions/builtin/cursor-cli-oauth/executable.d.ts.map +1 -1
  69. package/dist/core/extensions/builtin/cursor-cli-oauth/executable.js +7 -1
  70. package/dist/core/extensions/builtin/cursor-cli-oauth/executable.js.map +1 -1
  71. package/dist/core/extensions/builtin/cursor-cli-oauth/index.d.ts +2 -0
  72. package/dist/core/extensions/builtin/cursor-cli-oauth/index.d.ts.map +1 -1
  73. package/dist/core/extensions/builtin/cursor-cli-oauth/index.js +11 -9
  74. package/dist/core/extensions/builtin/cursor-cli-oauth/index.js.map +1 -1
  75. package/dist/core/extensions/builtin/cursor-cli-oauth/models-probe.d.ts +18 -0
  76. package/dist/core/extensions/builtin/cursor-cli-oauth/models-probe.d.ts.map +1 -0
  77. package/dist/core/extensions/builtin/cursor-cli-oauth/models-probe.js +61 -0
  78. package/dist/core/extensions/builtin/cursor-cli-oauth/models-probe.js.map +1 -0
  79. package/dist/core/extensions/builtin/cursor-cli-oauth/models.d.ts +4 -1
  80. package/dist/core/extensions/builtin/cursor-cli-oauth/models.d.ts.map +1 -1
  81. package/dist/core/extensions/builtin/cursor-cli-oauth/models.js +1 -44
  82. package/dist/core/extensions/builtin/cursor-cli-oauth/models.js.map +1 -1
  83. package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.d.ts +22 -0
  84. package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.d.ts.map +1 -1
  85. package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.js +1 -1
  86. package/dist/core/extensions/builtin/cursor-cli-oauth/oauth-login.js.map +1 -1
  87. package/dist/core/extensions/builtin/cursor-cli-oauth/transport.d.ts.map +1 -1
  88. package/dist/core/extensions/builtin/cursor-cli-oauth/transport.js +2 -13
  89. package/dist/core/extensions/builtin/cursor-cli-oauth/transport.js.map +1 -1
  90. package/dist/core/extensions/builtin/terminal/monitor-file-digest.d.ts +3 -0
  91. package/dist/core/extensions/builtin/terminal/monitor-file-digest.d.ts.map +1 -0
  92. package/dist/core/extensions/builtin/terminal/monitor-file-digest.js +25 -0
  93. package/dist/core/extensions/builtin/terminal/monitor-file-digest.js.map +1 -0
  94. package/dist/core/extensions/builtin/terminal/monitor-file-watch.d.ts +9 -0
  95. package/dist/core/extensions/builtin/terminal/monitor-file-watch.d.ts.map +1 -0
  96. package/dist/core/extensions/builtin/terminal/monitor-file-watch.js +33 -0
  97. package/dist/core/extensions/builtin/terminal/monitor-file-watch.js.map +1 -0
  98. package/dist/core/extensions/builtin/terminal/monitor-line-buffer.d.ts +6 -0
  99. package/dist/core/extensions/builtin/terminal/monitor-line-buffer.d.ts.map +1 -0
  100. package/dist/core/extensions/builtin/terminal/monitor-line-buffer.js +22 -0
  101. package/dist/core/extensions/builtin/terminal/monitor-line-buffer.js.map +1 -0
  102. package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts.map +1 -1
  103. package/dist/core/extensions/builtin/terminal/monitor-registry.js +14 -35
  104. package/dist/core/extensions/builtin/terminal/monitor-registry.js.map +1 -1
  105. package/dist/core/extensions/kernel-tools-context.d.ts +13 -0
  106. package/dist/core/extensions/kernel-tools-context.d.ts.map +1 -0
  107. package/dist/core/extensions/kernel-tools-context.js +3 -0
  108. package/dist/core/extensions/kernel-tools-context.js.map +1 -0
  109. package/dist/core/extensions/runner.d.ts +19 -0
  110. package/dist/core/extensions/runner.d.ts.map +1 -1
  111. package/dist/core/extensions/runner.js +103 -1
  112. package/dist/core/extensions/runner.js.map +1 -1
  113. package/dist/core/extensions/types.d.ts +21 -0
  114. package/dist/core/extensions/types.d.ts.map +1 -1
  115. package/dist/core/extensions/types.js.map +1 -1
  116. package/dist/core/keybindings.d.ts +5 -0
  117. package/dist/core/keybindings.d.ts.map +1 -1
  118. package/dist/core/keybindings.js +1 -0
  119. package/dist/core/keybindings.js.map +1 -1
  120. package/dist/core/resource-loader.d.ts.map +1 -1
  121. package/dist/core/resource-loader.js +9 -17
  122. package/dist/core/resource-loader.js.map +1 -1
  123. package/dist/core/retry-fallback/settings.d.ts +3 -0
  124. package/dist/core/retry-fallback/settings.d.ts.map +1 -1
  125. package/dist/core/retry-fallback/settings.js.map +1 -1
  126. package/dist/core/sdk.d.ts.map +1 -1
  127. package/dist/core/sdk.js +1 -0
  128. package/dist/core/sdk.js.map +1 -1
  129. package/dist/core/session-manager.d.ts +30 -1
  130. package/dist/core/session-manager.d.ts.map +1 -1
  131. package/dist/core/session-manager.js +92 -5
  132. package/dist/core/session-manager.js.map +1 -1
  133. package/dist/core/session-resident-store.d.ts +33 -7
  134. package/dist/core/session-resident-store.d.ts.map +1 -1
  135. package/dist/core/session-resident-store.js +163 -14
  136. package/dist/core/session-resident-store.js.map +1 -1
  137. package/dist/core/session-write-reservation.d.ts +6 -0
  138. package/dist/core/session-write-reservation.d.ts.map +1 -1
  139. package/dist/core/session-write-reservation.js +19 -0
  140. package/dist/core/session-write-reservation.js.map +1 -1
  141. package/dist/core/settings-manager.d.ts +35 -1
  142. package/dist/core/settings-manager.d.ts.map +1 -1
  143. package/dist/core/settings-manager.js +62 -0
  144. package/dist/core/settings-manager.js.map +1 -1
  145. package/dist/core/slash-commands.d.ts.map +1 -1
  146. package/dist/core/slash-commands.js +2 -1
  147. package/dist/core/slash-commands.js.map +1 -1
  148. package/dist/core/tools/index.d.ts +1 -1
  149. package/dist/core/tools/index.d.ts.map +1 -1
  150. package/dist/core/tools/index.js +4 -3
  151. package/dist/core/tools/index.js.map +1 -1
  152. package/dist/core/tools/read.d.ts +3 -1
  153. package/dist/core/tools/read.d.ts.map +1 -1
  154. package/dist/core/tools/read.js +16 -2
  155. package/dist/core/tools/read.js.map +1 -1
  156. package/dist/index.d.ts +1 -0
  157. package/dist/index.d.ts.map +1 -1
  158. package/dist/index.js +1 -0
  159. package/dist/index.js.map +1 -1
  160. package/dist/modes/interactive/components/assistant-render-descriptors.d.ts.map +1 -1
  161. package/dist/modes/interactive/components/assistant-render-descriptors.js +12 -5
  162. package/dist/modes/interactive/components/assistant-render-descriptors.js.map +1 -1
  163. package/dist/modes/interactive/components/extension-input.d.ts +2 -0
  164. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  165. package/dist/modes/interactive/components/extension-input.js +5 -0
  166. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  167. package/dist/modes/interactive/interactive-mode.d.ts +19 -2
  168. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  169. package/dist/modes/interactive/interactive-mode.js +69 -17
  170. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  171. package/dist/modes/interactive/tips/catalog/session-tips.js +1 -1
  172. package/dist/modes/interactive/tips/catalog/session-tips.js.map +1 -1
  173. package/dist/modes/interactive/working-status.d.ts +3 -2
  174. package/dist/modes/interactive/working-status.d.ts.map +1 -1
  175. package/dist/modes/interactive/working-status.js +17 -4
  176. package/dist/modes/interactive/working-status.js.map +1 -1
  177. package/dist/modes/print-mode.d.ts +1 -1
  178. package/dist/modes/print-mode.d.ts.map +1 -1
  179. package/dist/modes/print-mode.js +5 -1
  180. package/dist/modes/print-mode.js.map +1 -1
  181. package/dist/modes/rpc/host-watchdog.d.ts.map +1 -1
  182. package/dist/modes/rpc/host-watchdog.js +5 -24
  183. package/dist/modes/rpc/host-watchdog.js.map +1 -1
  184. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  185. package/dist/modes/rpc/rpc-mode.js +3 -8
  186. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  187. package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
  188. package/dist/modes/rpc/session-command-router.js +3 -0
  189. package/dist/modes/rpc/session-command-router.js.map +1 -1
  190. package/dist/modes/rpc/session-worker-client.d.ts +3 -0
  191. package/dist/modes/rpc/session-worker-client.d.ts.map +1 -1
  192. package/dist/modes/rpc/session-worker-client.js +17 -6
  193. package/dist/modes/rpc/session-worker-client.js.map +1 -1
  194. package/dist/modes/rpc/shutdown.d.ts +3 -0
  195. package/dist/modes/rpc/shutdown.d.ts.map +1 -0
  196. package/dist/modes/rpc/shutdown.js +17 -0
  197. package/dist/modes/rpc/shutdown.js.map +1 -0
  198. package/docs/extensions.md +5 -2
  199. package/docs/keybindings.md +1 -0
  200. package/docs/session-format.md +1 -1
  201. package/docs/sessions.md +3 -3
  202. package/docs/settings.md +31 -1
  203. package/docs/usage.md +1 -1
  204. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +50 -0
  205. package/node_modules/@code-yeongyu/senpi-codemode/README.md +24 -0
  206. package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
  207. package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/http-server.ts +7 -1
  208. package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/kernel-tools-protocol.ts +85 -0
  209. package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/protocol.ts +6 -0
  210. package/node_modules/@code-yeongyu/senpi-codemode/src/bridges/agent-bridge.ts +30 -11
  211. package/node_modules/@code-yeongyu/senpi-codemode/src/extension/session-manager.ts +11 -0
  212. package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +10 -0
  213. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/prelude.jl +46 -0
  214. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/runner.jl +1 -1
  215. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/context-manager.ts +58 -10
  216. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-contract.ts +12 -0
  217. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-context.d.ts +13 -0
  218. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-context.js +7 -0
  219. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-define.d.ts +10 -0
  220. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-define.js +12 -0
  221. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-errors.js +22 -0
  222. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-errors.ts +26 -0
  223. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-host.ts +134 -0
  224. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-naming.js +28 -0
  225. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-parse.d.ts +5 -0
  226. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-parse.js +255 -0
  227. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-pump.js +105 -0
  228. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-registry.d.ts +27 -0
  229. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-registry.js +127 -0
  230. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-schema.js +69 -0
  231. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-tools-types.ts +42 -0
  232. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/prelude.ts +2 -0
  233. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-core.js +26 -3
  234. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-runtime.js +20 -8
  235. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-slot.ts +6 -1
  236. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-startup.ts +9 -7
  237. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/workpool.js +37 -0
  238. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/kernel-tools-unavailable.ts +5 -0
  239. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/kernel.ts +13 -0
  240. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/prelude.py +57 -3
  241. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/prelude.rb +13 -2
  242. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/workpool.rb +38 -0
  243. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-kernel.ts +13 -0
  244. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-queue.ts +9 -1
  245. package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt-template.ts +4 -2
  246. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/cell-handler.ts +31 -3
  247. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-manager.ts +36 -71
  248. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/image-resize.ts +52 -0
  249. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/image.ts +37 -72
  250. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/managed-cell.ts +78 -0
  251. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/render.ts +30 -5
  252. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/run-eval-cell.ts +52 -30
  253. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/terminal-snapshot-store.ts +35 -0
  254. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/tool-result-marshal.ts +23 -0
  255. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/types.ts +2 -0
  256. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  257. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +30 -3
  258. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
  259. package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts +5 -0
  260. package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts.map +1 -1
  261. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js +2 -0
  262. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js.map +1 -1
  263. package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.d.ts.map +1 -1
  264. package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.js +51 -12
  265. package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.js.map +1 -1
  266. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.d.ts +3 -0
  267. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.d.ts.map +1 -1
  268. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.js +18 -3
  269. package/node_modules/@earendil-works/pi-agent-core/dist/harness/tools/read.js.map +1 -1
  270. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/brace-scanner.d.ts +4 -0
  271. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/brace-scanner.d.ts.map +1 -0
  272. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/brace-scanner.js +268 -0
  273. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/brace-scanner.js.map +1 -0
  274. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/header-protection.d.ts +18 -0
  275. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/header-protection.d.ts.map +1 -0
  276. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/header-protection.js +69 -0
  277. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/header-protection.js.map +1 -0
  278. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/index.d.ts +27 -0
  279. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/index.d.ts.map +1 -0
  280. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/index.js +118 -0
  281. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/index.js.map +1 -0
  282. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-context.d.ts +21 -0
  283. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-context.d.ts.map +1 -0
  284. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-context.js +24 -0
  285. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-context.js.map +1 -0
  286. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-spans.d.ts +12 -0
  287. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-spans.d.ts.map +1 -0
  288. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-spans.js +92 -0
  289. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/lexical-spans.js.map +1 -0
  290. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/types.d.ts +47 -0
  291. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/types.d.ts.map +1 -0
  292. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/types.js +8 -0
  293. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/read-folders/types.js.map +1 -0
  294. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/segmented-read-view.d.ts +52 -0
  295. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/segmented-read-view.d.ts.map +1 -0
  296. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/segmented-read-view.js +155 -0
  297. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/segmented-read-view.js.map +1 -0
  298. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +4 -0
  299. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts.map +1 -1
  300. package/node_modules/@earendil-works/pi-agent-core/dist/index.js +3 -0
  301. package/node_modules/@earendil-works/pi-agent-core/dist/index.js.map +1 -1
  302. package/node_modules/@earendil-works/pi-agent-core/dist/stream-throughput-watchdog.d.ts +101 -0
  303. package/node_modules/@earendil-works/pi-agent-core/dist/stream-throughput-watchdog.d.ts.map +1 -0
  304. package/node_modules/@earendil-works/pi-agent-core/dist/stream-throughput-watchdog.js +178 -0
  305. package/node_modules/@earendil-works/pi-agent-core/dist/stream-throughput-watchdog.js.map +1 -0
  306. package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +9 -0
  307. package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts.map +1 -1
  308. package/node_modules/@earendil-works/pi-agent-core/dist/types.js.map +1 -1
  309. package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  310. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +1 -0
  311. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
  312. package/node_modules/@earendil-works/pi-ai/dist/index.js +1 -0
  313. package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
  314. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  315. package/node_modules/@earendil-works/pi-ai/dist/providers/data/alibaba-token-plan.json +1 -1
  316. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  317. package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  318. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  319. package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  320. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  321. package/node_modules/@earendil-works/pi-ai/dist/utils/empty-response-errors.d.ts +15 -0
  322. package/node_modules/@earendil-works/pi-ai/dist/utils/empty-response-errors.d.ts.map +1 -0
  323. package/node_modules/@earendil-works/pi-ai/dist/utils/empty-response-errors.js +15 -0
  324. package/node_modules/@earendil-works/pi-ai/dist/utils/empty-response-errors.js.map +1 -0
  325. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts +24 -0
  326. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
  327. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +92 -0
  328. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
  329. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  330. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  331. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  332. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  333. package/package.json +7 -7
@@ -0,0 +1,33 @@
1
+ // fs.watch misses events under rename-heavy writers, so file monitors poll. A paused watch
2
+ // clears its timer entirely (zero wakeups, zero stat/digest work) and resume() runs one
3
+ // immediate check, so a change made during the pause is still detected and fired.
4
+ export const FILE_MONITOR_POLL_MS = 250;
5
+ export class FileWatchLoop {
6
+ #check;
7
+ #timer;
8
+ #stopped = false;
9
+ constructor(check) {
10
+ this.#check = check;
11
+ this.#start();
12
+ }
13
+ pause() {
14
+ if (this.#timer === undefined)
15
+ return;
16
+ clearInterval(this.#timer);
17
+ this.#timer = undefined;
18
+ }
19
+ resume() {
20
+ if (this.#stopped || this.#timer !== undefined)
21
+ return;
22
+ this.#start();
23
+ this.#check();
24
+ }
25
+ stop() {
26
+ this.#stopped = true;
27
+ this.pause();
28
+ }
29
+ #start() {
30
+ this.#timer = setInterval(this.#check, FILE_MONITOR_POLL_MS);
31
+ }
32
+ }
33
+ //# sourceMappingURL=monitor-file-watch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monitor-file-watch.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-file-watch.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,wFAAwF;AACxF,kFAAkF;AAClF,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAExC,MAAM,OAAO,aAAa;IAChB,MAAM,CAAa;IAC5B,MAAM,CAA6C;IACnD,QAAQ,GAAG,KAAK,CAAC;IAEjB,YAAY,KAAiB;QAC5B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,MAAM,EAAE,CAAC;IACf,CAAC;IAED,KAAK;QACJ,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,OAAO;QACtC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IACzB,CAAC;IAED,MAAM;QACL,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,OAAO;QACvD,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,IAAI,CAAC,MAAM,EAAE,CAAC;IACf,CAAC;IAED,IAAI;QACH,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,KAAK,EAAE,CAAC;IACd,CAAC;IAED,MAAM;QACL,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAC9D,CAAC;CACD","sourcesContent":["// fs.watch misses events under rename-heavy writers, so file monitors poll. A paused watch\n// clears its timer entirely (zero wakeups, zero stat/digest work) and resume() runs one\n// immediate check, so a change made during the pause is still detected and fired.\nexport const FILE_MONITOR_POLL_MS = 250;\n\nexport class FileWatchLoop {\n\treadonly #check: () => void;\n\t#timer: ReturnType<typeof setInterval> | undefined;\n\t#stopped = false;\n\n\tconstructor(check: () => void) {\n\t\tthis.#check = check;\n\t\tthis.#start();\n\t}\n\n\tpause(): void {\n\t\tif (this.#timer === undefined) return;\n\t\tclearInterval(this.#timer);\n\t\tthis.#timer = undefined;\n\t}\n\n\tresume(): void {\n\t\tif (this.#stopped || this.#timer !== undefined) return;\n\t\tthis.#start();\n\t\tthis.#check();\n\t}\n\n\tstop(): void {\n\t\tthis.#stopped = true;\n\t\tthis.pause();\n\t}\n\n\t#start(): void {\n\t\tthis.#timer = setInterval(this.#check, FILE_MONITOR_POLL_MS);\n\t}\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export declare const MONITOR_LINE_BUFFER_MAX_CHARS = 65536;
2
+ export declare class MonitorLineBuffer {
3
+ #private;
4
+ append(chunk: string): string[];
5
+ }
6
+ //# sourceMappingURL=monitor-line-buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monitor-line-buffer.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-line-buffer.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAEpD,qBAAa,iBAAiB;;IAG7B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAa9B;CACD"}
@@ -0,0 +1,22 @@
1
+ // A newline-less stream must not grow the retained tail without bound; an over-cap line is
2
+ // truncated to its last MONITOR_LINE_BUFFER_MAX_CHARS characters.
3
+ export const MONITOR_LINE_BUFFER_MAX_CHARS = 65_536;
4
+ export class MonitorLineBuffer {
5
+ #tail = "";
6
+ append(chunk) {
7
+ let remaining = this.#tail + chunk;
8
+ const lines = [];
9
+ for (;;) {
10
+ const newline = remaining.indexOf("\n");
11
+ if (newline < 0)
12
+ break;
13
+ const rawLine = remaining.slice(0, newline);
14
+ remaining = remaining.slice(newline + 1);
15
+ lines.push(rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine);
16
+ }
17
+ this.#tail =
18
+ remaining.length > MONITOR_LINE_BUFFER_MAX_CHARS ? remaining.slice(-MONITOR_LINE_BUFFER_MAX_CHARS) : remaining;
19
+ return lines;
20
+ }
21
+ }
22
+ //# sourceMappingURL=monitor-line-buffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monitor-line-buffer.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-line-buffer.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,kEAAkE;AAClE,MAAM,CAAC,MAAM,6BAA6B,GAAG,MAAM,CAAC;AAEpD,MAAM,OAAO,iBAAiB;IAC7B,KAAK,GAAG,EAAE,CAAC;IAEX,MAAM,CAAC,KAAa;QACnB,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,SAAS,CAAC;YACT,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACxC,IAAI,OAAO,GAAG,CAAC;gBAAE,MAAM;YACvB,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YAC5C,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;YACzC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,CAAC,KAAK;YACT,SAAS,CAAC,MAAM,GAAG,6BAA6B,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAChH,OAAO,KAAK,CAAC;IACd,CAAC;CACD","sourcesContent":["// A newline-less stream must not grow the retained tail without bound; an over-cap line is\n// truncated to its last MONITOR_LINE_BUFFER_MAX_CHARS characters.\nexport const MONITOR_LINE_BUFFER_MAX_CHARS = 65_536;\n\nexport class MonitorLineBuffer {\n\t#tail = \"\";\n\n\tappend(chunk: string): string[] {\n\t\tlet remaining = this.#tail + chunk;\n\t\tconst lines: string[] = [];\n\t\tfor (;;) {\n\t\t\tconst newline = remaining.indexOf(\"\\n\");\n\t\t\tif (newline < 0) break;\n\t\t\tconst rawLine = remaining.slice(0, newline);\n\t\t\tremaining = remaining.slice(newline + 1);\n\t\t\tlines.push(rawLine.endsWith(\"\\r\") ? rawLine.slice(0, -1) : rawLine);\n\t\t}\n\t\tthis.#tail =\n\t\t\tremaining.length > MONITOR_LINE_BUFFER_MAX_CHARS ? remaining.slice(-MONITOR_LINE_BUFFER_MAX_CHARS) : remaining;\n\t\treturn lines;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"monitor-registry.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-registry.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACX,yBAAyB,IAAI,iBAAiB,EAC9C,0BAA0B,IAAI,kBAAkB,EAChD,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAGrE,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW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,sBAAsB,GAAG,MAAM,CAkChD;IAED,KAAK,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAUtC;IAED,QAAQ,IAAI,MAAM,EAAE,CAEnB;IAED,MAAM,CAAC,GAAG,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,mBAAmB,EAAE,CAgBrD;IAED,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE/B;IAED,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,CAMpC;IAED,+GAA+G;IAC/G,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAOzE;IAED,OAAO,IAAI,IAAI,CAQd;CA8JD"}
1
+ {"version":3,"file":"monitor-registry.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-registry.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACX,yBAAyB,IAAI,iBAAiB,EAC9C,0BAA0B,IAAI,kBAAkB,EAChD,MAAM,2BAA2B,CAAC;AAInC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAGrE,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,YAAY,GAAG,gBA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ED,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE/B;IAED,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,CAMpC;IAED,+GAA+G;IAC/G,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAOzE;IAED,OAAO,IAAI,IAAI,CAQd;CAsID"}
@@ -1,9 +1,12 @@
1
- import { createHash, randomBytes } from "node:crypto";
1
+ import { randomBytes } from "node:crypto";
2
2
  import { watch } from "node:fs";
3
3
  import { access, lstat, open, stat } from "node:fs/promises";
4
4
  import { basename, dirname, join, resolve } from "node:path";
5
5
  import { canonicalWatchPath, probeDirectoryOpenable } from "../../../../utils/fs-watch.js";
6
6
  import { realpathWithoutOpen } from "../../../../utils/paths.js";
7
+ import { digestFileHandle } from "./monitor-file-digest.js";
8
+ import { FileWatchLoop } from "./monitor-file-watch.js";
9
+ import { MonitorLineBuffer } from "./monitor-line-buffer.js";
7
10
  import { DEFAULT_DURABLE_MONITOR_FIRE_BUDGET, FIRE_BUDGET_AUTO_MUTE_SUMMARY, FIRE_BUDGET_WINDOW_MS } from "./shared.js";
8
11
  import { describeExit } from "./tools/spawn.js";
9
12
  const MONITOR_ID_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
@@ -237,7 +240,7 @@ export class MonitorRegistry {
237
240
  event: options.event,
238
241
  watcher,
239
242
  release: release ?? (() => { }),
240
- poll: setInterval(() => void this.#checkFile(id), 250),
243
+ watch: new FileWatchLoop(() => void this.#checkFile(id)),
241
244
  paused: false,
242
245
  settled: false,
243
246
  present: initial !== null,
@@ -300,7 +303,7 @@ export class MonitorRegistry {
300
303
  if (record.settled)
301
304
  return;
302
305
  record.settled = true;
303
- clearInterval(record.poll);
306
+ record.watch.stop();
304
307
  clearTimeout(record.deadline);
305
308
  record.watcher.close();
306
309
  record.release();
@@ -318,7 +321,7 @@ export class MonitorRegistry {
318
321
  }
319
322
  async #checkFile(id) {
320
323
  const record = this.#files.get(id);
321
- if (!record || record.settled)
324
+ if (!record || record.settled || record.paused)
322
325
  return;
323
326
  if (record.checking) {
324
327
  record.dirty = true;
@@ -442,7 +445,7 @@ export class MonitorRegistry {
442
445
  expiresAt: options.expiresAt,
443
446
  runtime: options.runtime,
444
447
  filter: options.filter,
445
- lineBuffer: "",
448
+ lineBuffer: new MonitorLineBuffer(),
446
449
  mutedDropped: 0,
447
450
  paused: false,
448
451
  settled: false,
@@ -468,6 +471,8 @@ export class MonitorRegistry {
468
471
  if (!record || record.paused)
469
472
  continue;
470
473
  record.paused = true;
474
+ if ("watch" in record)
475
+ record.watch.pause();
471
476
  paused.push(record.id);
472
477
  }
473
478
  if (paused.length > 0)
@@ -492,8 +497,8 @@ export class MonitorRegistry {
492
497
  if ("fireWindow" in record && record.fireWindow !== undefined)
493
498
  record.fireWindow.count = 0;
494
499
  resumed.push({ id: record.id, mutedDropped });
495
- if ("pendingChange" in record && record.pendingChange)
496
- void this.#checkFile(record.id);
500
+ if ("watch" in record)
501
+ record.watch.resume();
497
502
  }
498
503
  if (resumed.length > 0)
499
504
  this.#notifyChange();
@@ -568,25 +573,7 @@ export class MonitorRegistry {
568
573
  return Promise.race([guarded, abort]);
569
574
  }
570
575
  async #digestHandle(handle, signal) {
571
- const SAMPLE_SIZE = 64 * 1024;
572
- if (signal?.aborted)
573
- throw new Error("file monitor registration cancelled");
574
- const metadata = await handle.stat();
575
- const hash = createHash("sha256");
576
- const first = Buffer.alloc(Math.min(SAMPLE_SIZE, metadata.size));
577
- if (first.length > 0) {
578
- await handle.read(first, 0, first.length, 0);
579
- hash.update(first);
580
- }
581
- if (metadata.size > SAMPLE_SIZE) {
582
- const middle = Buffer.alloc(SAMPLE_SIZE);
583
- await handle.read(middle, 0, middle.length, Math.floor((metadata.size - middle.length) / 2));
584
- hash.update(middle);
585
- const last = Buffer.alloc(SAMPLE_SIZE);
586
- await handle.read(last, 0, last.length, metadata.size - last.length);
587
- hash.update(last);
588
- }
589
- return `${metadata.size}:${hash.digest("hex")}`;
576
+ return digestFileHandle(handle, signal);
590
577
  }
591
578
  #notifyChange() {
592
579
  this.#onChange?.(this.snapshot());
@@ -594,14 +581,7 @@ export class MonitorRegistry {
594
581
  #consume(record, chunk) {
595
582
  if (record.settled || chunk.length === 0)
596
583
  return;
597
- let remaining = record.lineBuffer + chunk;
598
- for (;;) {
599
- const newline = remaining.indexOf("\n");
600
- if (newline < 0)
601
- break;
602
- const rawLine = remaining.slice(0, newline);
603
- remaining = remaining.slice(newline + 1);
604
- const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
584
+ for (const line of record.lineBuffer.append(chunk)) {
605
585
  const matchesFilter = !record.filter || record.filter.test(line);
606
586
  if (!matchesFilter)
607
587
  continue;
@@ -627,7 +607,6 @@ export class MonitorRegistry {
627
607
  }
628
608
  }
629
609
  }
630
- record.lineBuffer = remaining;
631
610
  }
632
611
  #settle(record) {
633
612
  if (record.settled)
@@ -1 +1 @@
1
- {"version":3,"file":"monitor-registry.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAkB,KAAK,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,MAAM,EAAmB,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAMjE,OAAO,EAAE,mCAAmC,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAExH,OAAO,EAAE,YAAY,EAAE,M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AS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,MAAM;YACN,QAAQ;YACR,SAAS,EAAE,MAAM,CAAC,SAAS;SAC3B,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import { createHash, randomBytes } from \"node:crypto\";\nimport { type FSWatcher, watch } from \"node:fs\";\nimport { access, type FileHandle, lstat, open, stat } from \"node:fs/promises\";\nimport { basename, dirname, join, resolve } from \"node:path\";\nimport { canonicalWatchPath, probeDirectoryOpenable } from \"../../../../utils/fs-watch.ts\";\nimport { realpathWithoutOpen } from \"../../../../utils/paths.ts\";\nimport type {\n\tTerminalMonitorEndedEvent as MonitorEndedEvent,\n\tTerminalMonitorEndedReason as MonitorEndedReason,\n} from \"../monitor-state-event.ts\";\nimport type { TerminalRuntimeSession } from \"./runtime-session.ts\";\nimport { DEFAULT_DURABLE_MONITOR_FIRE_BUDGET, FIRE_BUDGET_AUTO_MUTE_SUMMARY, FIRE_BUDGET_WINDOW_MS } from \"./shared.ts\";\nimport type { MonitorDurabilityClass } from \"./terminal-manifest.ts\";\nimport { describeExit } from \"./tools/spawn.ts\";\n\nexport interface MonitorLineEvent {\n\treadonly type: \"line\";\n\treadonly id: string;\n\treadonly description: string;\n\treadonly line: string;\n}\n\nexport interface MonitorSummaryEvent {\n\treadonly type: \"summary\";\n\treadonly id: string;\n\treadonly description: string;\n\treadonly summary: string;\n}\n\nexport type MonitorEvent = MonitorLineEvent | MonitorSummaryEvent;\n\nexport type MonitorRearmResult = \"rearmed\" | \"not_paused\" | \"not_found\";\n\nexport interface MonitorResumeResult {\n\treadonly id: string;\n\treadonly mutedDropped: number;\n}\n\nconst MONITOR_ID_ALPHABET = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\n\n/** Allocate a stable monitor identity: \"mon_\" + 16 Crockford base-32 chars (80 random bits). */\nexport function allocateMonitorId(): string {\n\tlet id = \"mon_\";\n\tlet buffer = 0;\n\tlet bits = 0;\n\tfor (const byte of randomBytes(10)) {\n\t\tbuffer = (buffer << 8) | byte;\n\t\tbits += 8;\n\t\twhile (bits >= 5) {\n\t\t\tbits -= 5;\n\t\t\tid += MONITOR_ID_ALPHABET[(buffer >> bits) & 31];\n\t\t}\n\t}\n\treturn id;\n}\n\nexport type MonitorFireWindow = { startMs: number; count: number };\nexport interface MonitorSnapshotEntry {\n\treadonly id: string;\n\t/** Stable \"mon_\" identity carried alongside the runtime id; always set on live snapshots. */\n\treadonly monitorId?: string;\n\treadonly description: string;\n\treadonly paused: boolean;\n\t/** Epoch milliseconds when the watch registered; feeds the footer's live elapsed label. */\n\treadonly startedAtMs: number;\n\treadonly command?: string | null;\n\treadonly filter?: string | null;\n\treadonly persistent?: boolean;\n\treadonly deadlineMs?: number | null;\n\treadonly fireCount?: number;\n\treadonly lastFiredAtMs?: number | null;\n\t/** Durability deadline of a restart-surviving watch; undefined for every ephemeral one. */\n\treadonly expiresAt?: number;\n\treadonly fireWindow?: MonitorFireWindow;\n}\n\nexport type { MonitorEndedEvent, MonitorEndedReason };\n\nexport interface MonitorRegistryOptions {\n\t/** Observes every registry transition (register/pause/rearm/settle/dispose) with the live snapshot. */\n\treadonly onChange?: (snapshot: readonly MonitorSnapshotEntry[]) => void;\n\t/** Fire-stat refreshes are separate from lifecycle transitions (which persist the manifest). */\n\treadonly onFire?: (snapshot: readonly MonitorSnapshotEntry[]) => void;\n\t/** Observes each monitor exactly once when it leaves the registry. */\n\treadonly onEnded?: (event: MonitorEndedEvent) => void;\n\t/** Reserves one shared terminal capacity slot for a native watch. */\n\treadonly reserve?: () => (() => void) | null;\n}\n\nexport interface RegisterFileMonitorOptions {\n\treadonly description: string;\n\treadonly path: string;\n\treadonly persistent?: boolean;\n\treadonly deadlineMs?: number | null;\n\t/** Caller-supplied stable identity so a restore can re-bind the same \"mon_\" id. */\n\treadonly monitorId?: string;\n\treadonly event: \"create\" | \"modify\";\n\treadonly timeoutMs: number;\n\treadonly cwd: string;\n\treadonly approvedParent?: string;\n\t/** Durability deadline of a `checkpointed-file` watch; omitted for a one-shot ephemeral one. */\n\treadonly expiresAt?: number;\n}\n\nexport interface RegisterMonitorOptions {\n\treadonly id: string;\n\treadonly command?: string | null;\n\treadonly persistent?: boolean;\n\treadonly deadlineMs?: number | null;\n\t/** Caller-supplied stable identity so a restore can re-bind the same \"mon_\" id. */\n\treadonly monitorId?: string;\n\treadonly description: string;\n\treadonly runtime: TerminalRuntimeSession;\n\treadonly filter?: RegExp;\n\t/** Durability class from the manifest spec; non-ephemeral records carry the fire budget. */\n\treadonly durabilityClass?: MonitorDurabilityClass;\n\t/** Persisted fire window re-bound by a restore, so a restart cannot reset the budget. */\n\treadonly fireWindow?: MonitorFireWindow;\n\t/** Durability deadline of a durable watch; omitted for an ephemeral one. */\n\treadonly expiresAt?: number;\n}\n\ninterface PendingFileRegistration {\n\trelease: (() => void) | undefined;\n\treadonly abort: AbortController;\n\treadonly deadline: ReturnType<typeof setTimeout>;\n\tsettled: boolean;\n}\n\ninterface FileMonitorRecord {\n\treadonly id: string;\n\treadonly monitorId: string;\n\treadonly sessionId: string;\n\treadonly description: string;\n\treadonly startedAtMs: number;\n\treadonly command: null;\n\treadonly filter: null;\n\treadonly persistent: boolean;\n\treadonly deadlineMs: number | null;\n\tfireCount: number;\n\tlastFiredAtMs: number | null;\n\treadonly expiresAt: number | undefined;\n\treadonly path: string;\n\treadonly canonicalPath: string;\n\treadonly canonicalParent: string;\n\treadonly event: \"create\" | \"modify\";\n\treadonly watcher: FSWatcher;\n\treadonly release: () => void;\n\treadonly poll: ReturnType<typeof setInterval>;\n\tpaused: boolean;\n\tsettled: boolean;\n\tpresent: boolean;\n\tmtimeMs: number;\n\tsize: number;\n\tdigest: string;\n\tdevice: number;\n\tinode: number;\n\tpendingChange: boolean;\n\tdirty: boolean;\n\tdirtyPasses: number;\n\tdirtyWindowStartedAt: number;\n\tchecking: Promise<void> | undefined;\n\treadonly deadline: ReturnType<typeof setTimeout>;\n}\n\ninterface MonitorRecord {\n\treadonly id: string;\n\treadonly monitorId: string;\n\treadonly sessionId: string;\n\treadonly description: string;\n\treadonly startedAtMs: number;\n\treadonly command: string | null;\n\treadonly persistent: boolean;\n\treadonly deadlineMs: number | null;\n\tfireCount: number;\n\tlastFiredAtMs: number | null;\n\treadonly expiresAt: number | undefined;\n\treadonly runtime: TerminalRuntimeSession;\n\treadonly filter: RegExp | undefined;\n\tlineBuffer: string;\n\tmutedDropped: number;\n\tpaused: boolean;\n\tsettled: boolean;\n\tfireWindow: MonitorFireWindow | undefined;\n\tunsubscribeOutput: (() => void) | undefined;\n\tunsubscribeExit: (() => void) | undefined;\n}\n\n/**\n * Tracks active monitor sessions alongside the terminal manager's existing bash-id registry.\n * Output is deliberately retained only by TerminalRuntimeSession's bounded history; this\n * registry holds at most one unfinished line for each live monitor.\n */\nexport class MonitorRegistry {\n\treadonly #records = new Map<string, MonitorRecord>();\n\treadonly #emit: (event: MonitorEvent) => void;\n\treadonly #onChange: ((snapshot: readonly MonitorSnapshotEntry[]) => void) | undefined;\n\treadonly #onEnded: ((event: MonitorEndedEvent) => void) | undefined;\n\treadonly #onFire: ((snapshot: readonly MonitorSnapshotEntry[]) => void) | undefined;\n\treadonly #reserve: (() => (() => void) | null) | undefined;\n\treadonly #files = new Map<string, FileMonitorRecord>();\n\t#nextFileId = 1;\n\t#disposed = false;\n\t#pendingRegistrations = 0;\n\treadonly #pending = new Set<PendingFileRegistration>();\n\t#lifecycle = 0;\n\n\tconstructor(emit: (event: MonitorEvent) => void, options?: MonitorRegistryOptions) {\n\t\tthis.#emit = emit;\n\t\tthis.#onChange = options?.onChange;\n\t\tthis.#onEnded = options?.onEnded;\n\t\tthis.#onFire = options?.onFire;\n\t\tthis.#reserve = options?.reserve;\n\t}\n\n\tsnapshot(): readonly MonitorSnapshotEntry[] {\n\t\treturn [...this.#records.values(), ...this.#files.values()].map((record) => ({\n\t\t\tid: record.id,\n\t\t\tmonitorId: record.monitorId,\n\t\t\tdescription: record.description,\n\t\t\tpaused: record.paused,\n\t\t\tstartedAtMs: record.startedAtMs,\n\t\t\tcommand: record.command,\n\t\t\tfilter: record.filter?.source ?? null,\n\t\t\tpersistent: record.persistent,\n\t\t\tdeadlineMs: record.deadlineMs,\n\t\t\tfireCount: record.fireCount,\n\t\t\tlastFiredAtMs: record.lastFiredAtMs,\n\t\t\texpiresAt: record.expiresAt,\n\t\t\tfireWindow: \"fireWindow\" in record ? record.fireWindow : undefined,\n\t\t}));\n\t}\n\n\tasync registerFile(options: RegisterFileMonitorOptions): Promise<{ id: string; monitorId: string }> {\n\t\tif (this.#disposed) throw new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\tthis.#pendingRegistrations += 1;\n\t\tconst lifecycle = this.#lifecycle;\n\t\tconst release = this.#reserve?.();\n\t\tif (this.#reserve && !release) {\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tthrow new Error(\"Cannot create file monitor: terminal capacity is already in use.\");\n\t\t}\n\t\tconst pending: PendingFileRegistration = {\n\t\t\trelease: release ?? undefined,\n\t\t\tabort: new AbortController(),\n\t\t\tdeadline: setTimeout(() => pending.abort.abort(), options.timeoutMs),\n\t\t\tsettled: false,\n\t\t};\n\t\tthis.#pending.add(pending);\n\t\tconst path = resolve(options.cwd, options.path);\n\t\tconst parent = dirname(path);\n\t\tlet approvedParent: string;\n\t\ttry {\n\t\t\tawait this.#registrationAwait(pending, access(parent));\n\t\t\t// Identity is derived without open(2), with the same walker the permission parser used, so the\n\t\t\t// two sides agree byte-for-byte and neither can block on a wedged mount.\n\t\t\tapprovedParent = realpathWithoutOpen(parent);\n\t\t\tconst approvedParentAtPermission = options.approvedParent;\n\t\t\tif (approvedParentAtPermission !== undefined && approvedParent !== approvedParentAtPermission) {\n\t\t\t\tthrow new Error(`Cannot watch file: parent directory changed during permission approval: ${parent}`);\n\t\t\t}\n\t\t\tif (this.#disposed) throw new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t} catch (error) {\n\t\t\tthis.#finishPending(pending);\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tif (error instanceof Error && error.message.includes(\"disposed\")) throw error;\n\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"ENOENT\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot access parent directory ${parent}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new Error(`Cannot watch file: parent directory does not exist: ${parent}`);\n\t\t}\n\t\tlet initial: Awaited<ReturnType<typeof stat>> | null = null;\n\t\tlet initialHandle: FileHandle | undefined;\n\t\ttry {\n\t\t\tconst target = await this.#registrationAwait(pending, lstat(path));\n\t\t\tif (target.isSymbolicLink()) throw new Error(`Cannot watch file: target is a symbolic link: ${path}`);\n\t\t\tinitialHandle = await this.#registrationAwait(pending, open(path, \"r\"), async (handle) => {\n\t\t\t\tawait handle.close();\n\t\t\t});\n\t\t\tinitial = await this.#registrationAwait(pending, initialHandle.stat());\n\t\t\tif (!initial.isFile()) throw new Error(`Cannot watch file: target is not a regular file: ${path}`);\n\t\t\tconst resolvedTarget = realpathWithoutOpen(path);\n\t\t\tif (resolvedTarget !== join(approvedParent, basename(path)))\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${path}`);\n\t\t\tconst rebound = await this.#registrationAwait(pending, lstat(path));\n\t\t\tif (rebound.isSymbolicLink()) throw new Error(`Cannot watch file: target identity changed: ${path}`);\n\t\t\tconst reboundStat = await this.#registrationAwait(pending, stat(path));\n\t\t\tif (!reboundStat.isFile() || reboundStat.dev !== initial.dev || reboundStat.ino !== initial.ino)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${path}`);\n\t\t} catch (error) {\n\t\t\tawait initialHandle?.close();\n\t\t\tinitialHandle = undefined;\n\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"ENOENT\") {\n\t\t\t\tthis.#finishPending(pending);\n\t\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif (this.#disposed || lifecycle !== this.#lifecycle || this.#pendingRegistrations < 1) {\n\t\t\tthis.#finishPending(pending);\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tthrow new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tconst id = `watch_${this.#nextFileId++}`;\n\t\tlet watcher: FSWatcher;\n\t\ttry {\n\t\t\tconst activationParent = realpathWithoutOpen(parent);\n\t\t\tif (activationParent !== approvedParent) {\n\t\t\t\tthrow new Error(`Cannot watch file: parent directory changed during registration: ${parent}`);\n\t\t\t}\n\t\t\t// watch() opens the directory synchronously on this thread; prove the open completes on the\n\t\t\t// async pool first so a wedged mount fails at the registration deadline instead of freezing.\n\t\t\tawait this.#registrationAwait(pending, probeDirectoryOpenable(activationParent));\n\t\t\twatcher = watch(canonicalWatchPath(activationParent), (_kind, name) => {\n\t\t\t\tif (!name || basename(String(name)) === basename(path)) void this.#checkFile(id);\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthis.#finishPending(pending);\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tthrow new Error(`Cannot watch file ${path}: ${error instanceof Error ? error.message : String(error)}`);\n\t\t}\n\t\tlet registrationError: string | undefined;\n\t\twatcher.on(\"error\", (error) => {\n\t\t\tregistrationError = `watcher error: ${error instanceof Error ? error.message : String(error)}`;\n\t\t\tconst record = this.#files.get(id);\n\t\t\tif (record) this.#settleFile(record, registrationError);\n\t\t});\n\t\tlet registrationCleaned = false;\n\t\tconst finishRegistration = () => {\n\t\t\tif (registrationCleaned) return;\n\t\t\tregistrationCleaned = true;\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t};\n\t\tconst cleanupRegistration = () => {\n\t\t\tif (registrationCleaned) return;\n\t\t\twatcher.close();\n\t\t\tfinishRegistration();\n\t\t\tthis.#finishPending(pending);\n\t\t};\n\t\tif (this.#disposed || lifecycle !== this.#lifecycle) {\n\t\t\tcleanupRegistration();\n\t\t\tthrow new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tconst canonicalPath = join(approvedParent, basename(path));\n\t\tlet digest: string;\n\t\ttry {\n\t\t\tdigest =\n\t\t\t\tinitial && initialHandle\n\t\t\t\t\t? await this.#registrationAwait(pending, this.#digestHandle(initialHandle, pending.abort.signal))\n\t\t\t\t\t: \"\";\n\t\t} catch (error) {\n\t\t\tcleanupRegistration();\n\t\t\tawait initialHandle?.close();\n\t\t\tinitialHandle = undefined;\n\t\t\tif (registrationError) {\n\t\t\t\tthis.#emit({ type: \"summary\", id, description: options.description, summary: registrationError });\n\t\t\t\tthrow new Error(registrationError);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tawait initialHandle?.close();\n\t\tinitialHandle = undefined;\n\t\tif (registrationError) {\n\t\t\tcleanupRegistration();\n\t\t\tthis.#emit({ type: \"summary\", id, description: options.description, summary: registrationError });\n\t\t\tthrow new Error(registrationError);\n\t\t}\n\t\tif (this.#disposed || lifecycle !== this.#lifecycle) {\n\t\t\tcleanupRegistration();\n\t\t\tthrow new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tconst record: FileMonitorRecord = {\n\t\t\tid,\n\t\t\tmonitorId: options.monitorId ?? allocateMonitorId(),\n\t\t\tsessionId: id,\n\t\t\tdescription: options.description,\n\t\t\tstartedAtMs: Date.now(),\n\t\t\tcommand: null,\n\t\t\tfilter: null,\n\t\t\tpersistent: options.persistent ?? options.expiresAt !== undefined,\n\t\t\tdeadlineMs:\n\t\t\t\t(options.persistent ?? options.expiresAt !== undefined)\n\t\t\t\t\t? null\n\t\t\t\t\t: (options.deadlineMs ?? Date.now() + options.timeoutMs),\n\t\t\tfireCount: 0,\n\t\t\tlastFiredAtMs: null,\n\t\t\texpiresAt: options.expiresAt,\n\t\t\tpath,\n\t\t\tcanonicalPath,\n\t\t\tcanonicalParent: approvedParent,\n\t\t\tevent: options.event,\n\t\t\twatcher,\n\t\t\trelease: release ?? (() => {}),\n\t\t\tpoll: setInterval(() => void this.#checkFile(id), 250),\n\t\t\tpaused: false,\n\t\t\tsettled: false,\n\t\t\tpresent: initial !== null,\n\t\t\tmtimeMs: initial?.mtimeMs ?? 0,\n\t\t\tsize: initial?.size ?? 0,\n\t\t\tdigest,\n\t\t\tdevice: initial?.dev ?? 0,\n\t\t\tinode: initial?.ino ?? 0,\n\t\t\tpendingChange: false,\n\t\t\tdirty: false,\n\t\t\tdirtyPasses: 0,\n\t\t\tdirtyWindowStartedAt: 0,\n\t\t\tchecking: undefined,\n\t\t\tdeadline: setTimeout(() => {\n\t\t\t\tconst current = this.#files.get(id);\n\t\t\t\tif (current) this.#settleFile(current, \"watcher timed_out\");\n\t\t\t}, options.timeoutMs),\n\t\t};\n\t\tthis.#files.set(id, record);\n\t\tfinishRegistration();\n\t\tthis.#finishPending(pending, true);\n\t\tif (registrationError || this.#disposed || lifecycle !== this.#lifecycle) {\n\t\t\tthis.#settleFile(record, registrationError ?? \"watcher killed\");\n\t\t\tthrow new Error(registrationError ?? \"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tthis.#notifyChange();\n\t\treturn { id, monitorId: record.monitorId };\n\t}\n\n\t/** Live identity tuple of one file watch; undefined when the id is not a live file watch. */\n\tfileCheckpoint(id: string) {\n\t\tconst r = this.#files.get(id);\n\t\treturn (\n\t\t\tr && { dev: r.device, ino: r.inode, size: r.size, mtimeMs: r.mtimeMs, digest: r.digest, present: r.present }\n\t\t);\n\t}\n\n\t/** Emit one restored-watch line through the SAME sink a live watch uses (coalescing, wake budget). */\n\temitFileLine(id: string, line: string): boolean {\n\t\tconst record = this.#files.get(id);\n\t\tif (!record || record.settled) return false;\n\t\tthis.#emitForRecord(record, { type: \"line\", id: record.id, description: record.description, line });\n\t\treturn true;\n\t}\n\n\tasync stopFile(id: string): Promise<boolean> {\n\t\tconst record = this.#files.get(id);\n\t\tif (!record) return false;\n\t\tthis.#settleFile(record, \"watcher killed\");\n\t\treturn true;\n\t}\n\n\tasync stopAllFiles(): Promise<number> {\n\t\tthis.#lifecycle += 1;\n\t\tconst records = [...this.#files.values()];\n\t\tfor (const record of records) this.#settleFile(record, \"watcher killed\");\n\t\tfor (const pending of [...this.#pending]) this.#finishPending(pending);\n\t\treturn records.length;\n\t}\n\n\t#settleFile(record: FileMonitorRecord, summary: string): void {\n\t\tif (record.settled) return;\n\t\trecord.settled = true;\n\t\tclearInterval(record.poll);\n\t\tclearTimeout(record.deadline);\n\t\trecord.watcher.close();\n\t\trecord.release();\n\t\tthis.#files.delete(record.id);\n\t\tthis.#notifyChange();\n\t\tthis.#emitForRecord(record, { type: \"summary\", id: record.id, description: record.description, summary });\n\t\tconst reason =\n\t\t\tsummary === \"watcher timed_out\"\n\t\t\t\t? \"timeout\"\n\t\t\t\t: summary === \"watcher killed\"\n\t\t\t\t\t? \"killed\"\n\t\t\t\t\t: summary === \"watcher disposed\"\n\t\t\t\t\t\t? \"disposed\"\n\t\t\t\t\t\t: \"exit\";\n\t\tthis.#emitEnded(record, reason, null);\n\t}\n\n\tasync #checkFile(id: string): Promise<void> {\n\t\tconst record = this.#files.get(id);\n\t\tif (!record || record.settled) return;\n\t\tif (record.checking) {\n\t\t\trecord.dirty = true;\n\t\t\treturn;\n\t\t}\n\t\trecord.checking = this.#checkFileImpl(record)\n\t\t\t.catch((error) => {\n\t\t\t\tif (!record.settled)\n\t\t\t\t\tthis.#settleFile(record, `watcher error: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\trecord.checking = undefined;\n\t\t\t\tconst now = Date.now();\n\t\t\t\tif (now - record.dirtyWindowStartedAt >= 1_000) {\n\t\t\t\t\trecord.dirtyWindowStartedAt = now;\n\t\t\t\t\trecord.dirtyPasses = 0;\n\t\t\t\t}\n\t\t\t\tif (record.dirty && !record.settled && record.dirtyPasses < 1) {\n\t\t\t\t\trecord.dirty = false;\n\t\t\t\t\trecord.dirtyPasses += 1;\n\t\t\t\t\tvoid this.#checkFile(id);\n\t\t\t\t} else {\n\t\t\t\t\trecord.dirty = false;\n\t\t\t\t}\n\t\t\t});\n\t\treturn record.checking;\n\t}\n\n\tasync #checkFileImpl(record: FileMonitorRecord): Promise<void> {\n\t\tif (record.settled) return;\n\t\tlet current: Awaited<ReturnType<typeof stat>> | null = null;\n\t\tlet handle: FileHandle | undefined;\n\t\ttry {\n\t\t\tconst currentParent = realpathWithoutOpen(dirname(record.path));\n\t\t\tif (currentParent !== record.canonicalParent) {\n\t\t\t\tthis.#settleFile(record, `watcher error: monitored parent changed: ${dirname(record.path)}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst target = await lstat(record.canonicalPath);\n\t\t\tif (target.isSymbolicLink()) throw new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\tconst resolvedTarget = realpathWithoutOpen(record.canonicalPath);\n\t\t\tif (resolvedTarget !== record.canonicalPath)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\thandle = await open(record.canonicalPath, \"r\");\n\t\t\tconst opened = await handle.stat();\n\t\t\tif (!opened.isFile()) throw new Error(`Cannot watch file: target is not a regular file: ${record.path}`);\n\t\t\tif ((opened.dev !== record.device || opened.ino !== record.inode) && opened.nlink > 1)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\tcurrent = opened;\n\t\t\tconst rebound = await lstat(record.canonicalPath);\n\t\t\tif (rebound.isSymbolicLink()) throw new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\tconst reboundPath = await stat(record.canonicalPath);\n\t\t\tif (!reboundPath.isFile() || reboundPath.dev !== opened.dev || reboundPath.ino !== opened.ino)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t} catch (error) {\n\t\t\tawait handle?.close();\n\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"ENOENT\") {\n\t\t\t\tthis.#settleFile(record, `watcher error: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tconst present = current !== null;\n\t\tlet digest = \"\";\n\t\ttry {\n\t\t\tdigest = present && handle ? await this.#digestHandle(handle) : \"\";\n\t\t\tif (present && handle) {\n\t\t\t\tconst afterDigest = await stat(record.canonicalPath);\n\t\t\t\tconst opened = await handle.stat();\n\t\t\t\tif (afterDigest.dev !== opened.dev || afterDigest.ino !== opened.ino)\n\t\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\t}\n\t\t} finally {\n\t\t\tawait handle?.close();\n\t\t}\n\t\tconst changed =\n\t\t\trecord.event === \"create\"\n\t\t\t\t? !record.present && present\n\t\t\t\t: record.present &&\n\t\t\t\t\tpresent &&\n\t\t\t\t\t(current!.mtimeMs !== record.mtimeMs || current!.size !== record.size || digest !== record.digest);\n\t\trecord.pendingChange ||= changed;\n\t\tif (!record.present && current) {\n\t\t\trecord.device = current.dev;\n\t\t\trecord.inode = current.ino;\n\t\t}\n\t\trecord.present = present;\n\t\trecord.mtimeMs = current?.mtimeMs ?? 0;\n\t\trecord.size = current?.size ?? 0;\n\t\trecord.digest = digest;\n\t\tif (!record.pendingChange || record.paused || record.settled) return;\n\t\trecord.pendingChange = false;\n\t\tif (record.settled) return;\n\t\tthis.#emitForRecord(record, {\n\t\t\ttype: \"line\",\n\t\t\tid: record.id,\n\t\t\tdescription: record.description,\n\t\t\tline: `${record.event} ${record.path}`,\n\t\t});\n\t\tthis.#settleFile(record, \"watcher completed\");\n\t}\n\n\tregister(options: RegisterMonitorOptions): string {\n\t\tconst durable = options.durabilityClass !== undefined && options.durabilityClass !== \"ephemeral\";\n\t\tconst record: MonitorRecord = {\n\t\t\tid: options.id,\n\t\t\tmonitorId: options.monitorId ?? allocateMonitorId(),\n\t\t\tsessionId: options.id,\n\t\t\tdescription: options.description,\n\t\t\tstartedAtMs: Date.now(),\n\t\t\tcommand: options.command ?? null,\n\t\t\tpersistent: options.persistent ?? durable,\n\t\t\tdeadlineMs: (options.persistent ?? durable) ? null : (options.deadlineMs ?? null),\n\t\t\tfireCount: 0,\n\t\t\tlastFiredAtMs: null,\n\t\t\texpiresAt: options.expiresAt,\n\t\t\truntime: options.runtime,\n\t\t\tfilter: options.filter,\n\t\t\tlineBuffer: \"\",\n\t\t\tmutedDropped: 0,\n\t\t\tpaused: false,\n\t\t\tsettled: false,\n\t\t\tfireWindow: durable ? { ...(options.fireWindow ?? { startMs: Date.now(), count: 0 }) } : undefined,\n\t\t\tunsubscribeOutput: undefined,\n\t\t\tunsubscribeExit: undefined,\n\t\t};\n\t\tthis.#records.set(record.id, record);\n\t\tthis.#notifyChange();\n\n\t\t// Runtime output is already bounded. Read what was produced before monitor registration,\n\t\t// then subscribe synchronously so a fast watcher cannot lose its first line.\n\t\tthis.#consume(record, record.runtime.fullOutput());\n\t\trecord.unsubscribeOutput = record.runtime.onOutput((chunk) => this.#consume(record, chunk));\n\t\trecord.unsubscribeExit = record.runtime.session.onExit(() => this.#settle(record));\n\t\tif (record.runtime.exited) this.#settle(record);\n\t\treturn record.monitorId;\n\t}\n\n\tpause(ids: readonly string[]): string[] {\n\t\tconst paused: string[] = [];\n\t\tfor (const id of ids) {\n\t\t\tconst record = this.#records.get(id) ?? this.#files.get(id);\n\t\t\tif (!record || record.paused) continue;\n\t\t\trecord.paused = true;\n\t\t\tpaused.push(record.id);\n\t\t}\n\t\tif (paused.length > 0) this.#notifyChange();\n\t\treturn paused;\n\t}\n\n\tpauseAll(): string[] {\n\t\treturn this.pause([...this.#records.keys(), ...this.#files.keys()]);\n\t}\n\n\tresume(ids?: readonly string[]): MonitorResumeResult[] {\n\t\tconst candidates = ids ?? [...this.#records.keys(), ...this.#files.keys()];\n\t\tconst resumed: MonitorResumeResult[] = [];\n\t\tfor (const id of candidates) {\n\t\t\tconst record = this.#records.get(id) ?? this.#files.get(id);\n\t\t\tif (!record?.paused) continue;\n\t\t\trecord.paused = false;\n\t\t\tconst mutedDropped = \"mutedDropped\" in record ? record.mutedDropped : 0;\n\t\t\tif (\"mutedDropped\" in record) record.mutedDropped = 0;\n\t\t\t// A rearm (or any resume) restarts the rolling fire budget while keeping its window start.\n\t\t\tif (\"fireWindow\" in record && record.fireWindow !== undefined) record.fireWindow.count = 0;\n\t\t\tresumed.push({ id: record.id, mutedDropped });\n\t\t\tif (\"pendingChange\" in record && record.pendingChange) void this.#checkFile(record.id);\n\t\t}\n\t\tif (resumed.length > 0) this.#notifyChange();\n\t\treturn resumed;\n\t}\n\n\tmutedDropped(id: string): number {\n\t\treturn this.#records.get(id)?.mutedDropped ?? 0;\n\t}\n\n\trearm(id: string): MonitorRearmResult {\n\t\tconst record = this.#records.get(id) ?? this.#files.get(id);\n\t\tif (!record) return \"not_found\";\n\t\tif (!record.paused) return \"not_paused\";\n\t\tthis.resume([id]);\n\t\treturn \"rearmed\";\n\t}\n\n\t/** Re-bind a persisted fire window onto the record for a durable monitor id (a restore re-arms the budget). */\n\tadoptFireWindow(monitorId: string, fireWindow: MonitorFireWindow): boolean {\n\t\tfor (const record of this.#records.values()) {\n\t\t\tif (record.monitorId !== monitorId) continue;\n\t\t\trecord.fireWindow = { ...fireWindow };\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tdispose(): void {\n\t\tthis.#disposed = true;\n\t\tthis.#lifecycle += 1;\n\t\tfor (const record of [...this.#records.values()]) this.#disposeRecord(record);\n\t\tfor (const record of this.#files.values()) this.#settleFile(record, \"watcher disposed\");\n\t\tfor (const pending of this.#pending) this.#finishPending(pending);\n\t\tthis.#records.clear();\n\t\tthis.#notifyChange();\n\t}\n\n\t#finishPending(pending: PendingFileRegistration, transfer = false): void {\n\t\tif (pending.settled) return;\n\t\tpending.settled = true;\n\t\tclearTimeout(pending.deadline);\n\t\tthis.#pending.delete(pending);\n\t\tif (transfer) pending.release = undefined;\n\t\telse {\n\t\t\tpending.abort.abort();\n\t\t\tpending.release?.();\n\t\t}\n\t}\n\n\tasync #registrationAwait<T>(\n\t\tpending: PendingFileRegistration,\n\t\toperation: Promise<T>,\n\t\tlateCleanup?: (value: T) => Promise<void>,\n\t): Promise<T> {\n\t\tif (pending.abort.signal.aborted) {\n\t\t\tvoid operation.then(\n\t\t\t\t(value) => lateCleanup?.(value),\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\tthrow new Error(\"Cannot create file monitor: registration timed out or was disposed.\");\n\t\t}\n\t\tlet aborted = false;\n\t\tconst abort = new Promise<never>((_, reject) =>\n\t\t\tpending.abort.signal.addEventListener(\n\t\t\t\t\"abort\",\n\t\t\t\t() => {\n\t\t\t\t\taborted = true;\n\t\t\t\t\treject(new Error(\"Cannot create file monitor: registration timed out or was disposed.\"));\n\t\t\t\t},\n\t\t\t\t{ once: true },\n\t\t\t),\n\t\t);\n\t\tconst guarded = operation.then(\n\t\t\t(value) => {\n\t\t\t\tif (aborted) void lateCleanup?.(value);\n\t\t\t\treturn value;\n\t\t\t},\n\t\t\t(error) => {\n\t\t\t\tif (aborted) return undefined as T;\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\treturn Promise.race([guarded, abort]);\n\t}\n\n\tasync #digestHandle(handle: FileHandle, signal?: AbortSignal): Promise<string> {\n\t\tconst SAMPLE_SIZE = 64 * 1024;\n\t\tif (signal?.aborted) throw new Error(\"file monitor registration cancelled\");\n\t\tconst metadata = await handle.stat();\n\t\tconst hash = createHash(\"sha256\");\n\t\tconst first = Buffer.alloc(Math.min(SAMPLE_SIZE, metadata.size));\n\t\tif (first.length > 0) {\n\t\t\tawait handle.read(first, 0, first.length, 0);\n\t\t\thash.update(first);\n\t\t}\n\t\tif (metadata.size > SAMPLE_SIZE) {\n\t\t\tconst middle = Buffer.alloc(SAMPLE_SIZE);\n\t\t\tawait handle.read(middle, 0, middle.length, Math.floor((metadata.size - middle.length) / 2));\n\t\t\thash.update(middle);\n\t\t\tconst last = Buffer.alloc(SAMPLE_SIZE);\n\t\t\tawait handle.read(last, 0, last.length, metadata.size - last.length);\n\t\t\thash.update(last);\n\t\t}\n\t\treturn `${metadata.size}:${hash.digest(\"hex\")}`;\n\t}\n\n\t#notifyChange(): void {\n\t\tthis.#onChange?.(this.snapshot());\n\t}\n\n\t#consume(record: MonitorRecord, chunk: string): void {\n\t\tif (record.settled || chunk.length === 0) return;\n\t\tlet remaining = record.lineBuffer + chunk;\n\t\tfor (;;) {\n\t\t\tconst newline = remaining.indexOf(\"\\n\");\n\t\t\tif (newline < 0) break;\n\t\t\tconst rawLine = remaining.slice(0, newline);\n\t\t\tremaining = remaining.slice(newline + 1);\n\t\t\tconst line = rawLine.endsWith(\"\\r\") ? rawLine.slice(0, -1) : rawLine;\n\t\t\tconst matchesFilter = !record.filter || record.filter.test(line);\n\t\t\tif (!matchesFilter) continue;\n\t\t\tif (record.paused) {\n\t\t\t\trecord.mutedDropped += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.#emitForRecord(record, { type: \"line\", id: record.id, description: record.description, line });\n\t\t\tif (record.fireWindow !== undefined) {\n\t\t\t\tconst now = Date.now();\n\t\t\t\tif (now - record.fireWindow.startMs >= FIRE_BUDGET_WINDOW_MS)\n\t\t\t\t\trecord.fireWindow = { startMs: now, count: 0 };\n\t\t\t\trecord.fireWindow.count += 1;\n\t\t\t\tif (record.fireWindow.count >= DEFAULT_DURABLE_MONITOR_FIRE_BUDGET) {\n\t\t\t\t\trecord.paused = true;\n\t\t\t\t\tthis.#emitForRecord(record, {\n\t\t\t\t\t\ttype: \"summary\",\n\t\t\t\t\t\tid: record.id,\n\t\t\t\t\t\tdescription: record.description,\n\t\t\t\t\t\tsummary: FIRE_BUDGET_AUTO_MUTE_SUMMARY,\n\t\t\t\t\t});\n\t\t\t\t\tthis.#notifyChange();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\trecord.lineBuffer = remaining;\n\t}\n\n\t#settle(record: MonitorRecord): void {\n\t\tif (record.settled) return;\n\t\trecord.settled = true;\n\t\trecord.unsubscribeOutput?.();\n\t\trecord.unsubscribeExit?.();\n\t\tthis.#records.delete(record.id);\n\t\tthis.#notifyChange();\n\t\tconst status = describeExit(record.runtime) ?? \"exited\";\n\t\tconst code = record.runtime.exitResult?.exitCode;\n\t\tconst codeText = code === null || code === undefined ? \"\" : ` (exit code ${code})`;\n\t\tthis.#emitForRecord(record, {\n\t\t\ttype: \"summary\",\n\t\t\tid: record.id,\n\t\t\tdescription: record.description,\n\t\t\tsummary: `watcher ${status}${codeText}`,\n\t\t});\n\t\tconst exit = record.runtime.exitResult;\n\t\tthis.#emitEnded(record, exit?.timedOut ? \"timeout\" : exit?.cancelled ? \"killed\" : \"exit\", code ?? null);\n\t}\n\n\t#disposeRecord(record: MonitorRecord): void {\n\t\tif (record.settled) return;\n\t\trecord.settled = true;\n\t\trecord.unsubscribeOutput?.();\n\t\trecord.unsubscribeExit?.();\n\t\tthis.#records.delete(record.id);\n\t\tthis.#emitEnded(record, \"disposed\", null);\n\t}\n\n\t#emitForRecord(record: MonitorRecord | FileMonitorRecord, event: MonitorEvent): void {\n\t\trecord.fireCount += 1;\n\t\trecord.lastFiredAtMs = Date.now();\n\t\tthis.#emit(event);\n\t\tif (!record.settled) this.#onFire?.(this.snapshot());\n\t}\n\n\t#emitEnded(record: MonitorRecord | FileMonitorRecord, reason: MonitorEndedReason, exitCode: number | null): void {\n\t\tthis.#onEnded?.({\n\t\t\tid: record.id,\n\t\t\tdescription: record.description,\n\t\t\tstartedAtMs: record.startedAtMs,\n\t\t\tendedAtMs: Date.now(),\n\t\t\treason,\n\t\t\texitCode,\n\t\t\tfireCount: record.fireCount,\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"monitor-registry.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAkB,KAAK,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,MAAM,EAAmB,KAAK,EAAE,IAAI,EAAE,IAAI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EAAE,MAAM,CAAC,EAAE;YACb,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,MAAM;YACN,QAAQ;YACR,SAAS,EAAE,MAAM,CAAC,SAAS;SAC3B,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { type FSWatcher, watch } from \"node:fs\";\nimport { access, type FileHandle, lstat, open, stat } from \"node:fs/promises\";\nimport { basename, dirname, join, resolve } from \"node:path\";\nimport { canonicalWatchPath, probeDirectoryOpenable } from \"../../../../utils/fs-watch.ts\";\nimport { realpathWithoutOpen } from \"../../../../utils/paths.ts\";\nimport type {\n\tTerminalMonitorEndedEvent as MonitorEndedEvent,\n\tTerminalMonitorEndedReason as MonitorEndedReason,\n} from \"../monitor-state-event.ts\";\nimport { digestFileHandle } from \"./monitor-file-digest.ts\";\nimport { FileWatchLoop } from \"./monitor-file-watch.ts\";\nimport { MonitorLineBuffer } from \"./monitor-line-buffer.ts\";\nimport type { TerminalRuntimeSession } from \"./runtime-session.ts\";\nimport { DEFAULT_DURABLE_MONITOR_FIRE_BUDGET, FIRE_BUDGET_AUTO_MUTE_SUMMARY, FIRE_BUDGET_WINDOW_MS } from \"./shared.ts\";\nimport type { MonitorDurabilityClass } from \"./terminal-manifest.ts\";\nimport { describeExit } from \"./tools/spawn.ts\";\n\nexport interface MonitorLineEvent {\n\treadonly type: \"line\";\n\treadonly id: string;\n\treadonly description: string;\n\treadonly line: string;\n}\n\nexport interface MonitorSummaryEvent {\n\treadonly type: \"summary\";\n\treadonly id: string;\n\treadonly description: string;\n\treadonly summary: string;\n}\n\nexport type MonitorEvent = MonitorLineEvent | MonitorSummaryEvent;\n\nexport type MonitorRearmResult = \"rearmed\" | \"not_paused\" | \"not_found\";\n\nexport interface MonitorResumeResult {\n\treadonly id: string;\n\treadonly mutedDropped: number;\n}\n\nconst MONITOR_ID_ALPHABET = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\n\n/** Allocate a stable monitor identity: \"mon_\" + 16 Crockford base-32 chars (80 random bits). */\nexport function allocateMonitorId(): string {\n\tlet id = \"mon_\";\n\tlet buffer = 0;\n\tlet bits = 0;\n\tfor (const byte of randomBytes(10)) {\n\t\tbuffer = (buffer << 8) | byte;\n\t\tbits += 8;\n\t\twhile (bits >= 5) {\n\t\t\tbits -= 5;\n\t\t\tid += MONITOR_ID_ALPHABET[(buffer >> bits) & 31];\n\t\t}\n\t}\n\treturn id;\n}\n\nexport type MonitorFireWindow = { startMs: number; count: number };\nexport interface MonitorSnapshotEntry {\n\treadonly id: string;\n\t/** Stable \"mon_\" identity carried alongside the runtime id; always set on live snapshots. */\n\treadonly monitorId?: string;\n\treadonly description: string;\n\treadonly paused: boolean;\n\t/** Epoch milliseconds when the watch registered; feeds the footer's live elapsed label. */\n\treadonly startedAtMs: number;\n\treadonly command?: string | null;\n\treadonly filter?: string | null;\n\treadonly persistent?: boolean;\n\treadonly deadlineMs?: number | null;\n\treadonly fireCount?: number;\n\treadonly lastFiredAtMs?: number | null;\n\t/** Durability deadline of a restart-surviving watch; undefined for every ephemeral one. */\n\treadonly expiresAt?: number;\n\treadonly fireWindow?: MonitorFireWindow;\n}\n\nexport type { MonitorEndedEvent, MonitorEndedReason };\n\nexport interface MonitorRegistryOptions {\n\t/** Observes every registry transition (register/pause/rearm/settle/dispose) with the live snapshot. */\n\treadonly onChange?: (snapshot: readonly MonitorSnapshotEntry[]) => void;\n\t/** Fire-stat refreshes are separate from lifecycle transitions (which persist the manifest). */\n\treadonly onFire?: (snapshot: readonly MonitorSnapshotEntry[]) => void;\n\t/** Observes each monitor exactly once when it leaves the registry. */\n\treadonly onEnded?: (event: MonitorEndedEvent) => void;\n\t/** Reserves one shared terminal capacity slot for a native watch. */\n\treadonly reserve?: () => (() => void) | null;\n}\n\nexport interface RegisterFileMonitorOptions {\n\treadonly description: string;\n\treadonly path: string;\n\treadonly persistent?: boolean;\n\treadonly deadlineMs?: number | null;\n\t/** Caller-supplied stable identity so a restore can re-bind the same \"mon_\" id. */\n\treadonly monitorId?: string;\n\treadonly event: \"create\" | \"modify\";\n\treadonly timeoutMs: number;\n\treadonly cwd: string;\n\treadonly approvedParent?: string;\n\t/** Durability deadline of a `checkpointed-file` watch; omitted for a one-shot ephemeral one. */\n\treadonly expiresAt?: number;\n}\n\nexport interface RegisterMonitorOptions {\n\treadonly id: string;\n\treadonly command?: string | null;\n\treadonly persistent?: boolean;\n\treadonly deadlineMs?: number | null;\n\t/** Caller-supplied stable identity so a restore can re-bind the same \"mon_\" id. */\n\treadonly monitorId?: string;\n\treadonly description: string;\n\treadonly runtime: TerminalRuntimeSession;\n\treadonly filter?: RegExp;\n\t/** Durability class from the manifest spec; non-ephemeral records carry the fire budget. */\n\treadonly durabilityClass?: MonitorDurabilityClass;\n\t/** Persisted fire window re-bound by a restore, so a restart cannot reset the budget. */\n\treadonly fireWindow?: MonitorFireWindow;\n\t/** Durability deadline of a durable watch; omitted for an ephemeral one. */\n\treadonly expiresAt?: number;\n}\n\ninterface PendingFileRegistration {\n\trelease: (() => void) | undefined;\n\treadonly abort: AbortController;\n\treadonly deadline: ReturnType<typeof setTimeout>;\n\tsettled: boolean;\n}\n\ninterface FileMonitorRecord {\n\treadonly id: string;\n\treadonly monitorId: string;\n\treadonly sessionId: string;\n\treadonly description: string;\n\treadonly startedAtMs: number;\n\treadonly command: null;\n\treadonly filter: null;\n\treadonly persistent: boolean;\n\treadonly deadlineMs: number | null;\n\tfireCount: number;\n\tlastFiredAtMs: number | null;\n\treadonly expiresAt: number | undefined;\n\treadonly path: string;\n\treadonly canonicalPath: string;\n\treadonly canonicalParent: string;\n\treadonly event: \"create\" | \"modify\";\n\treadonly watcher: FSWatcher;\n\treadonly release: () => void;\n\treadonly watch: FileWatchLoop;\n\tpaused: boolean;\n\tsettled: boolean;\n\tpresent: boolean;\n\tmtimeMs: number;\n\tsize: number;\n\tdigest: string;\n\tdevice: number;\n\tinode: number;\n\tpendingChange: boolean;\n\tdirty: boolean;\n\tdirtyPasses: number;\n\tdirtyWindowStartedAt: number;\n\tchecking: Promise<void> | undefined;\n\treadonly deadline: ReturnType<typeof setTimeout>;\n}\n\ninterface MonitorRecord {\n\treadonly id: string;\n\treadonly monitorId: string;\n\treadonly sessionId: string;\n\treadonly description: string;\n\treadonly startedAtMs: number;\n\treadonly command: string | null;\n\treadonly persistent: boolean;\n\treadonly deadlineMs: number | null;\n\tfireCount: number;\n\tlastFiredAtMs: number | null;\n\treadonly expiresAt: number | undefined;\n\treadonly runtime: TerminalRuntimeSession;\n\treadonly filter: RegExp | undefined;\n\tlineBuffer: MonitorLineBuffer;\n\tmutedDropped: number;\n\tpaused: boolean;\n\tsettled: boolean;\n\tfireWindow: MonitorFireWindow | undefined;\n\tunsubscribeOutput: (() => void) | undefined;\n\tunsubscribeExit: (() => void) | undefined;\n}\n\n/**\n * Tracks active monitor sessions alongside the terminal manager's existing bash-id registry.\n * Output is deliberately retained only by TerminalRuntimeSession's bounded history; this\n * registry holds at most one unfinished line for each live monitor.\n */\nexport class MonitorRegistry {\n\treadonly #records = new Map<string, MonitorRecord>();\n\treadonly #emit: (event: MonitorEvent) => void;\n\treadonly #onChange: ((snapshot: readonly MonitorSnapshotEntry[]) => void) | undefined;\n\treadonly #onEnded: ((event: MonitorEndedEvent) => void) | undefined;\n\treadonly #onFire: ((snapshot: readonly MonitorSnapshotEntry[]) => void) | undefined;\n\treadonly #reserve: (() => (() => void) | null) | undefined;\n\treadonly #files = new Map<string, FileMonitorRecord>();\n\t#nextFileId = 1;\n\t#disposed = false;\n\t#pendingRegistrations = 0;\n\treadonly #pending = new Set<PendingFileRegistration>();\n\t#lifecycle = 0;\n\n\tconstructor(emit: (event: MonitorEvent) => void, options?: MonitorRegistryOptions) {\n\t\tthis.#emit = emit;\n\t\tthis.#onChange = options?.onChange;\n\t\tthis.#onEnded = options?.onEnded;\n\t\tthis.#onFire = options?.onFire;\n\t\tthis.#reserve = options?.reserve;\n\t}\n\n\tsnapshot(): readonly MonitorSnapshotEntry[] {\n\t\treturn [...this.#records.values(), ...this.#files.values()].map((record) => ({\n\t\t\tid: record.id,\n\t\t\tmonitorId: record.monitorId,\n\t\t\tdescription: record.description,\n\t\t\tpaused: record.paused,\n\t\t\tstartedAtMs: record.startedAtMs,\n\t\t\tcommand: record.command,\n\t\t\tfilter: record.filter?.source ?? null,\n\t\t\tpersistent: record.persistent,\n\t\t\tdeadlineMs: record.deadlineMs,\n\t\t\tfireCount: record.fireCount,\n\t\t\tlastFiredAtMs: record.lastFiredAtMs,\n\t\t\texpiresAt: record.expiresAt,\n\t\t\tfireWindow: \"fireWindow\" in record ? record.fireWindow : undefined,\n\t\t}));\n\t}\n\n\tasync registerFile(options: RegisterFileMonitorOptions): Promise<{ id: string; monitorId: string }> {\n\t\tif (this.#disposed) throw new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\tthis.#pendingRegistrations += 1;\n\t\tconst lifecycle = this.#lifecycle;\n\t\tconst release = this.#reserve?.();\n\t\tif (this.#reserve && !release) {\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tthrow new Error(\"Cannot create file monitor: terminal capacity is already in use.\");\n\t\t}\n\t\tconst pending: PendingFileRegistration = {\n\t\t\trelease: release ?? undefined,\n\t\t\tabort: new AbortController(),\n\t\t\tdeadline: setTimeout(() => pending.abort.abort(), options.timeoutMs),\n\t\t\tsettled: false,\n\t\t};\n\t\tthis.#pending.add(pending);\n\t\tconst path = resolve(options.cwd, options.path);\n\t\tconst parent = dirname(path);\n\t\tlet approvedParent: string;\n\t\ttry {\n\t\t\tawait this.#registrationAwait(pending, access(parent));\n\t\t\t// Identity is derived without open(2), with the same walker the permission parser used, so the\n\t\t\t// two sides agree byte-for-byte and neither can block on a wedged mount.\n\t\t\tapprovedParent = realpathWithoutOpen(parent);\n\t\t\tconst approvedParentAtPermission = options.approvedParent;\n\t\t\tif (approvedParentAtPermission !== undefined && approvedParent !== approvedParentAtPermission) {\n\t\t\t\tthrow new Error(`Cannot watch file: parent directory changed during permission approval: ${parent}`);\n\t\t\t}\n\t\t\tif (this.#disposed) throw new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t} catch (error) {\n\t\t\tthis.#finishPending(pending);\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tif (error instanceof Error && error.message.includes(\"disposed\")) throw error;\n\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"ENOENT\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot access parent directory ${parent}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow new Error(`Cannot watch file: parent directory does not exist: ${parent}`);\n\t\t}\n\t\tlet initial: Awaited<ReturnType<typeof stat>> | null = null;\n\t\tlet initialHandle: FileHandle | undefined;\n\t\ttry {\n\t\t\tconst target = await this.#registrationAwait(pending, lstat(path));\n\t\t\tif (target.isSymbolicLink()) throw new Error(`Cannot watch file: target is a symbolic link: ${path}`);\n\t\t\tinitialHandle = await this.#registrationAwait(pending, open(path, \"r\"), async (handle) => {\n\t\t\t\tawait handle.close();\n\t\t\t});\n\t\t\tinitial = await this.#registrationAwait(pending, initialHandle.stat());\n\t\t\tif (!initial.isFile()) throw new Error(`Cannot watch file: target is not a regular file: ${path}`);\n\t\t\tconst resolvedTarget = realpathWithoutOpen(path);\n\t\t\tif (resolvedTarget !== join(approvedParent, basename(path)))\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${path}`);\n\t\t\tconst rebound = await this.#registrationAwait(pending, lstat(path));\n\t\t\tif (rebound.isSymbolicLink()) throw new Error(`Cannot watch file: target identity changed: ${path}`);\n\t\t\tconst reboundStat = await this.#registrationAwait(pending, stat(path));\n\t\t\tif (!reboundStat.isFile() || reboundStat.dev !== initial.dev || reboundStat.ino !== initial.ino)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${path}`);\n\t\t} catch (error) {\n\t\t\tawait initialHandle?.close();\n\t\t\tinitialHandle = undefined;\n\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"ENOENT\") {\n\t\t\t\tthis.#finishPending(pending);\n\t\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif (this.#disposed || lifecycle !== this.#lifecycle || this.#pendingRegistrations < 1) {\n\t\t\tthis.#finishPending(pending);\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tthrow new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tconst id = `watch_${this.#nextFileId++}`;\n\t\tlet watcher: FSWatcher;\n\t\ttry {\n\t\t\tconst activationParent = realpathWithoutOpen(parent);\n\t\t\tif (activationParent !== approvedParent) {\n\t\t\t\tthrow new Error(`Cannot watch file: parent directory changed during registration: ${parent}`);\n\t\t\t}\n\t\t\t// watch() opens the directory synchronously on this thread; prove the open completes on the\n\t\t\t// async pool first so a wedged mount fails at the registration deadline instead of freezing.\n\t\t\tawait this.#registrationAwait(pending, probeDirectoryOpenable(activationParent));\n\t\t\twatcher = watch(canonicalWatchPath(activationParent), (_kind, name) => {\n\t\t\t\tif (!name || basename(String(name)) === basename(path)) void this.#checkFile(id);\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthis.#finishPending(pending);\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t\tthrow new Error(`Cannot watch file ${path}: ${error instanceof Error ? error.message : String(error)}`);\n\t\t}\n\t\tlet registrationError: string | undefined;\n\t\twatcher.on(\"error\", (error) => {\n\t\t\tregistrationError = `watcher error: ${error instanceof Error ? error.message : String(error)}`;\n\t\t\tconst record = this.#files.get(id);\n\t\t\tif (record) this.#settleFile(record, registrationError);\n\t\t});\n\t\tlet registrationCleaned = false;\n\t\tconst finishRegistration = () => {\n\t\t\tif (registrationCleaned) return;\n\t\t\tregistrationCleaned = true;\n\t\t\tthis.#pendingRegistrations -= 1;\n\t\t};\n\t\tconst cleanupRegistration = () => {\n\t\t\tif (registrationCleaned) return;\n\t\t\twatcher.close();\n\t\t\tfinishRegistration();\n\t\t\tthis.#finishPending(pending);\n\t\t};\n\t\tif (this.#disposed || lifecycle !== this.#lifecycle) {\n\t\t\tcleanupRegistration();\n\t\t\tthrow new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tconst canonicalPath = join(approvedParent, basename(path));\n\t\tlet digest: string;\n\t\ttry {\n\t\t\tdigest =\n\t\t\t\tinitial && initialHandle\n\t\t\t\t\t? await this.#registrationAwait(pending, this.#digestHandle(initialHandle, pending.abort.signal))\n\t\t\t\t\t: \"\";\n\t\t} catch (error) {\n\t\t\tcleanupRegistration();\n\t\t\tawait initialHandle?.close();\n\t\t\tinitialHandle = undefined;\n\t\t\tif (registrationError) {\n\t\t\t\tthis.#emit({ type: \"summary\", id, description: options.description, summary: registrationError });\n\t\t\t\tthrow new Error(registrationError);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tawait initialHandle?.close();\n\t\tinitialHandle = undefined;\n\t\tif (registrationError) {\n\t\t\tcleanupRegistration();\n\t\t\tthis.#emit({ type: \"summary\", id, description: options.description, summary: registrationError });\n\t\t\tthrow new Error(registrationError);\n\t\t}\n\t\tif (this.#disposed || lifecycle !== this.#lifecycle) {\n\t\t\tcleanupRegistration();\n\t\t\tthrow new Error(\"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tconst record: FileMonitorRecord = {\n\t\t\tid,\n\t\t\tmonitorId: options.monitorId ?? allocateMonitorId(),\n\t\t\tsessionId: id,\n\t\t\tdescription: options.description,\n\t\t\tstartedAtMs: Date.now(),\n\t\t\tcommand: null,\n\t\t\tfilter: null,\n\t\t\tpersistent: options.persistent ?? options.expiresAt !== undefined,\n\t\t\tdeadlineMs:\n\t\t\t\t(options.persistent ?? options.expiresAt !== undefined)\n\t\t\t\t\t? null\n\t\t\t\t\t: (options.deadlineMs ?? Date.now() + options.timeoutMs),\n\t\t\tfireCount: 0,\n\t\t\tlastFiredAtMs: null,\n\t\t\texpiresAt: options.expiresAt,\n\t\t\tpath,\n\t\t\tcanonicalPath,\n\t\t\tcanonicalParent: approvedParent,\n\t\t\tevent: options.event,\n\t\t\twatcher,\n\t\t\trelease: release ?? (() => {}),\n\t\t\twatch: new FileWatchLoop(() => void this.#checkFile(id)),\n\t\t\tpaused: false,\n\t\t\tsettled: false,\n\t\t\tpresent: initial !== null,\n\t\t\tmtimeMs: initial?.mtimeMs ?? 0,\n\t\t\tsize: initial?.size ?? 0,\n\t\t\tdigest,\n\t\t\tdevice: initial?.dev ?? 0,\n\t\t\tinode: initial?.ino ?? 0,\n\t\t\tpendingChange: false,\n\t\t\tdirty: false,\n\t\t\tdirtyPasses: 0,\n\t\t\tdirtyWindowStartedAt: 0,\n\t\t\tchecking: undefined,\n\t\t\tdeadline: setTimeout(() => {\n\t\t\t\tconst current = this.#files.get(id);\n\t\t\t\tif (current) this.#settleFile(current, \"watcher timed_out\");\n\t\t\t}, options.timeoutMs),\n\t\t};\n\t\tthis.#files.set(id, record);\n\t\tfinishRegistration();\n\t\tthis.#finishPending(pending, true);\n\t\tif (registrationError || this.#disposed || lifecycle !== this.#lifecycle) {\n\t\t\tthis.#settleFile(record, registrationError ?? \"watcher killed\");\n\t\t\tthrow new Error(registrationError ?? \"Cannot create file monitor: monitor registry is disposed.\");\n\t\t}\n\t\tthis.#notifyChange();\n\t\treturn { id, monitorId: record.monitorId };\n\t}\n\n\t/** Live identity tuple of one file watch; undefined when the id is not a live file watch. */\n\tfileCheckpoint(id: string) {\n\t\tconst r = this.#files.get(id);\n\t\treturn (\n\t\t\tr && { dev: r.device, ino: r.inode, size: r.size, mtimeMs: r.mtimeMs, digest: r.digest, present: r.present }\n\t\t);\n\t}\n\n\t/** Emit one restored-watch line through the SAME sink a live watch uses (coalescing, wake budget). */\n\temitFileLine(id: string, line: string): boolean {\n\t\tconst record = this.#files.get(id);\n\t\tif (!record || record.settled) return false;\n\t\tthis.#emitForRecord(record, { type: \"line\", id: record.id, description: record.description, line });\n\t\treturn true;\n\t}\n\n\tasync stopFile(id: string): Promise<boolean> {\n\t\tconst record = this.#files.get(id);\n\t\tif (!record) return false;\n\t\tthis.#settleFile(record, \"watcher killed\");\n\t\treturn true;\n\t}\n\n\tasync stopAllFiles(): Promise<number> {\n\t\tthis.#lifecycle += 1;\n\t\tconst records = [...this.#files.values()];\n\t\tfor (const record of records) this.#settleFile(record, \"watcher killed\");\n\t\tfor (const pending of [...this.#pending]) this.#finishPending(pending);\n\t\treturn records.length;\n\t}\n\n\t#settleFile(record: FileMonitorRecord, summary: string): void {\n\t\tif (record.settled) return;\n\t\trecord.settled = true;\n\t\trecord.watch.stop();\n\t\tclearTimeout(record.deadline);\n\t\trecord.watcher.close();\n\t\trecord.release();\n\t\tthis.#files.delete(record.id);\n\t\tthis.#notifyChange();\n\t\tthis.#emitForRecord(record, { type: \"summary\", id: record.id, description: record.description, summary });\n\t\tconst reason =\n\t\t\tsummary === \"watcher timed_out\"\n\t\t\t\t? \"timeout\"\n\t\t\t\t: summary === \"watcher killed\"\n\t\t\t\t\t? \"killed\"\n\t\t\t\t\t: summary === \"watcher disposed\"\n\t\t\t\t\t\t? \"disposed\"\n\t\t\t\t\t\t: \"exit\";\n\t\tthis.#emitEnded(record, reason, null);\n\t}\n\n\tasync #checkFile(id: string): Promise<void> {\n\t\tconst record = this.#files.get(id);\n\t\tif (!record || record.settled || record.paused) return;\n\t\tif (record.checking) {\n\t\t\trecord.dirty = true;\n\t\t\treturn;\n\t\t}\n\t\trecord.checking = this.#checkFileImpl(record)\n\t\t\t.catch((error) => {\n\t\t\t\tif (!record.settled)\n\t\t\t\t\tthis.#settleFile(record, `watcher error: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\trecord.checking = undefined;\n\t\t\t\tconst now = Date.now();\n\t\t\t\tif (now - record.dirtyWindowStartedAt >= 1_000) {\n\t\t\t\t\trecord.dirtyWindowStartedAt = now;\n\t\t\t\t\trecord.dirtyPasses = 0;\n\t\t\t\t}\n\t\t\t\tif (record.dirty && !record.settled && record.dirtyPasses < 1) {\n\t\t\t\t\trecord.dirty = false;\n\t\t\t\t\trecord.dirtyPasses += 1;\n\t\t\t\t\tvoid this.#checkFile(id);\n\t\t\t\t} else {\n\t\t\t\t\trecord.dirty = false;\n\t\t\t\t}\n\t\t\t});\n\t\treturn record.checking;\n\t}\n\n\tasync #checkFileImpl(record: FileMonitorRecord): Promise<void> {\n\t\tif (record.settled) return;\n\t\tlet current: Awaited<ReturnType<typeof stat>> | null = null;\n\t\tlet handle: FileHandle | undefined;\n\t\ttry {\n\t\t\tconst currentParent = realpathWithoutOpen(dirname(record.path));\n\t\t\tif (currentParent !== record.canonicalParent) {\n\t\t\t\tthis.#settleFile(record, `watcher error: monitored parent changed: ${dirname(record.path)}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst target = await lstat(record.canonicalPath);\n\t\t\tif (target.isSymbolicLink()) throw new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\tconst resolvedTarget = realpathWithoutOpen(record.canonicalPath);\n\t\t\tif (resolvedTarget !== record.canonicalPath)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\thandle = await open(record.canonicalPath, \"r\");\n\t\t\tconst opened = await handle.stat();\n\t\t\tif (!opened.isFile()) throw new Error(`Cannot watch file: target is not a regular file: ${record.path}`);\n\t\t\tif ((opened.dev !== record.device || opened.ino !== record.inode) && opened.nlink > 1)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\tcurrent = opened;\n\t\t\tconst rebound = await lstat(record.canonicalPath);\n\t\t\tif (rebound.isSymbolicLink()) throw new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\tconst reboundPath = await stat(record.canonicalPath);\n\t\t\tif (!reboundPath.isFile() || reboundPath.dev !== opened.dev || reboundPath.ino !== opened.ino)\n\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t} catch (error) {\n\t\t\tawait handle?.close();\n\t\t\tif ((error as NodeJS.ErrnoException)?.code !== \"ENOENT\") {\n\t\t\t\tthis.#settleFile(record, `watcher error: ${error instanceof Error ? error.message : String(error)}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tconst present = current !== null;\n\t\tlet digest = \"\";\n\t\ttry {\n\t\t\tdigest = present && handle ? await this.#digestHandle(handle) : \"\";\n\t\t\tif (present && handle) {\n\t\t\t\tconst afterDigest = await stat(record.canonicalPath);\n\t\t\t\tconst opened = await handle.stat();\n\t\t\t\tif (afterDigest.dev !== opened.dev || afterDigest.ino !== opened.ino)\n\t\t\t\t\tthrow new Error(`Cannot watch file: target identity changed: ${record.path}`);\n\t\t\t}\n\t\t} finally {\n\t\t\tawait handle?.close();\n\t\t}\n\t\tconst changed =\n\t\t\trecord.event === \"create\"\n\t\t\t\t? !record.present && present\n\t\t\t\t: record.present &&\n\t\t\t\t\tpresent &&\n\t\t\t\t\t(current!.mtimeMs !== record.mtimeMs || current!.size !== record.size || digest !== record.digest);\n\t\trecord.pendingChange ||= changed;\n\t\tif (!record.present && current) {\n\t\t\trecord.device = current.dev;\n\t\t\trecord.inode = current.ino;\n\t\t}\n\t\trecord.present = present;\n\t\trecord.mtimeMs = current?.mtimeMs ?? 0;\n\t\trecord.size = current?.size ?? 0;\n\t\trecord.digest = digest;\n\t\tif (!record.pendingChange || record.paused || record.settled) return;\n\t\trecord.pendingChange = false;\n\t\tif (record.settled) return;\n\t\tthis.#emitForRecord(record, {\n\t\t\ttype: \"line\",\n\t\t\tid: record.id,\n\t\t\tdescription: record.description,\n\t\t\tline: `${record.event} ${record.path}`,\n\t\t});\n\t\tthis.#settleFile(record, \"watcher completed\");\n\t}\n\n\tregister(options: RegisterMonitorOptions): string {\n\t\tconst durable = options.durabilityClass !== undefined && options.durabilityClass !== \"ephemeral\";\n\t\tconst record: MonitorRecord = {\n\t\t\tid: options.id,\n\t\t\tmonitorId: options.monitorId ?? allocateMonitorId(),\n\t\t\tsessionId: options.id,\n\t\t\tdescription: options.description,\n\t\t\tstartedAtMs: Date.now(),\n\t\t\tcommand: options.command ?? null,\n\t\t\tpersistent: options.persistent ?? durable,\n\t\t\tdeadlineMs: (options.persistent ?? durable) ? null : (options.deadlineMs ?? null),\n\t\t\tfireCount: 0,\n\t\t\tlastFiredAtMs: null,\n\t\t\texpiresAt: options.expiresAt,\n\t\t\truntime: options.runtime,\n\t\t\tfilter: options.filter,\n\t\t\tlineBuffer: new MonitorLineBuffer(),\n\t\t\tmutedDropped: 0,\n\t\t\tpaused: false,\n\t\t\tsettled: false,\n\t\t\tfireWindow: durable ? { ...(options.fireWindow ?? { startMs: Date.now(), count: 0 }) } : undefined,\n\t\t\tunsubscribeOutput: undefined,\n\t\t\tunsubscribeExit: undefined,\n\t\t};\n\t\tthis.#records.set(record.id, record);\n\t\tthis.#notifyChange();\n\n\t\t// Runtime output is already bounded. Read what was produced before monitor registration,\n\t\t// then subscribe synchronously so a fast watcher cannot lose its first line.\n\t\tthis.#consume(record, record.runtime.fullOutput());\n\t\trecord.unsubscribeOutput = record.runtime.onOutput((chunk) => this.#consume(record, chunk));\n\t\trecord.unsubscribeExit = record.runtime.session.onExit(() => this.#settle(record));\n\t\tif (record.runtime.exited) this.#settle(record);\n\t\treturn record.monitorId;\n\t}\n\n\tpause(ids: readonly string[]): string[] {\n\t\tconst paused: string[] = [];\n\t\tfor (const id of ids) {\n\t\t\tconst record = this.#records.get(id) ?? this.#files.get(id);\n\t\t\tif (!record || record.paused) continue;\n\t\t\trecord.paused = true;\n\t\t\tif (\"watch\" in record) record.watch.pause();\n\t\t\tpaused.push(record.id);\n\t\t}\n\t\tif (paused.length > 0) this.#notifyChange();\n\t\treturn paused;\n\t}\n\n\tpauseAll(): string[] {\n\t\treturn this.pause([...this.#records.keys(), ...this.#files.keys()]);\n\t}\n\n\tresume(ids?: readonly string[]): MonitorResumeResult[] {\n\t\tconst candidates = ids ?? [...this.#records.keys(), ...this.#files.keys()];\n\t\tconst resumed: MonitorResumeResult[] = [];\n\t\tfor (const id of candidates) {\n\t\t\tconst record = this.#records.get(id) ?? this.#files.get(id);\n\t\t\tif (!record?.paused) continue;\n\t\t\trecord.paused = false;\n\t\t\tconst mutedDropped = \"mutedDropped\" in record ? record.mutedDropped : 0;\n\t\t\tif (\"mutedDropped\" in record) record.mutedDropped = 0;\n\t\t\t// A rearm (or any resume) restarts the rolling fire budget while keeping its window start.\n\t\t\tif (\"fireWindow\" in record && record.fireWindow !== undefined) record.fireWindow.count = 0;\n\t\t\tresumed.push({ id: record.id, mutedDropped });\n\t\t\tif (\"watch\" in record) record.watch.resume();\n\t\t}\n\t\tif (resumed.length > 0) this.#notifyChange();\n\t\treturn resumed;\n\t}\n\n\tmutedDropped(id: string): number {\n\t\treturn this.#records.get(id)?.mutedDropped ?? 0;\n\t}\n\n\trearm(id: string): MonitorRearmResult {\n\t\tconst record = this.#records.get(id) ?? this.#files.get(id);\n\t\tif (!record) return \"not_found\";\n\t\tif (!record.paused) return \"not_paused\";\n\t\tthis.resume([id]);\n\t\treturn \"rearmed\";\n\t}\n\n\t/** Re-bind a persisted fire window onto the record for a durable monitor id (a restore re-arms the budget). */\n\tadoptFireWindow(monitorId: string, fireWindow: MonitorFireWindow): boolean {\n\t\tfor (const record of this.#records.values()) {\n\t\t\tif (record.monitorId !== monitorId) continue;\n\t\t\trecord.fireWindow = { ...fireWindow };\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tdispose(): void {\n\t\tthis.#disposed = true;\n\t\tthis.#lifecycle += 1;\n\t\tfor (const record of [...this.#records.values()]) this.#disposeRecord(record);\n\t\tfor (const record of this.#files.values()) this.#settleFile(record, \"watcher disposed\");\n\t\tfor (const pending of this.#pending) this.#finishPending(pending);\n\t\tthis.#records.clear();\n\t\tthis.#notifyChange();\n\t}\n\n\t#finishPending(pending: PendingFileRegistration, transfer = false): void {\n\t\tif (pending.settled) return;\n\t\tpending.settled = true;\n\t\tclearTimeout(pending.deadline);\n\t\tthis.#pending.delete(pending);\n\t\tif (transfer) pending.release = undefined;\n\t\telse {\n\t\t\tpending.abort.abort();\n\t\t\tpending.release?.();\n\t\t}\n\t}\n\n\tasync #registrationAwait<T>(\n\t\tpending: PendingFileRegistration,\n\t\toperation: Promise<T>,\n\t\tlateCleanup?: (value: T) => Promise<void>,\n\t): Promise<T> {\n\t\tif (pending.abort.signal.aborted) {\n\t\t\tvoid operation.then(\n\t\t\t\t(value) => lateCleanup?.(value),\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\tthrow new Error(\"Cannot create file monitor: registration timed out or was disposed.\");\n\t\t}\n\t\tlet aborted = false;\n\t\tconst abort = new Promise<never>((_, reject) =>\n\t\t\tpending.abort.signal.addEventListener(\n\t\t\t\t\"abort\",\n\t\t\t\t() => {\n\t\t\t\t\taborted = true;\n\t\t\t\t\treject(new Error(\"Cannot create file monitor: registration timed out or was disposed.\"));\n\t\t\t\t},\n\t\t\t\t{ once: true },\n\t\t\t),\n\t\t);\n\t\tconst guarded = operation.then(\n\t\t\t(value) => {\n\t\t\t\tif (aborted) void lateCleanup?.(value);\n\t\t\t\treturn value;\n\t\t\t},\n\t\t\t(error) => {\n\t\t\t\tif (aborted) return undefined as T;\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\treturn Promise.race([guarded, abort]);\n\t}\n\n\tasync #digestHandle(handle: FileHandle, signal?: AbortSignal): Promise<string> {\n\t\treturn digestFileHandle(handle, signal);\n\t}\n\n\t#notifyChange(): void {\n\t\tthis.#onChange?.(this.snapshot());\n\t}\n\n\t#consume(record: MonitorRecord, chunk: string): void {\n\t\tif (record.settled || chunk.length === 0) return;\n\t\tfor (const line of record.lineBuffer.append(chunk)) {\n\t\t\tconst matchesFilter = !record.filter || record.filter.test(line);\n\t\t\tif (!matchesFilter) continue;\n\t\t\tif (record.paused) {\n\t\t\t\trecord.mutedDropped += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.#emitForRecord(record, { type: \"line\", id: record.id, description: record.description, line });\n\t\t\tif (record.fireWindow !== undefined) {\n\t\t\t\tconst now = Date.now();\n\t\t\t\tif (now - record.fireWindow.startMs >= FIRE_BUDGET_WINDOW_MS)\n\t\t\t\t\trecord.fireWindow = { startMs: now, count: 0 };\n\t\t\t\trecord.fireWindow.count += 1;\n\t\t\t\tif (record.fireWindow.count >= DEFAULT_DURABLE_MONITOR_FIRE_BUDGET) {\n\t\t\t\t\trecord.paused = true;\n\t\t\t\t\tthis.#emitForRecord(record, {\n\t\t\t\t\t\ttype: \"summary\",\n\t\t\t\t\t\tid: record.id,\n\t\t\t\t\t\tdescription: record.description,\n\t\t\t\t\t\tsummary: FIRE_BUDGET_AUTO_MUTE_SUMMARY,\n\t\t\t\t\t});\n\t\t\t\t\tthis.#notifyChange();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t#settle(record: MonitorRecord): void {\n\t\tif (record.settled) return;\n\t\trecord.settled = true;\n\t\trecord.unsubscribeOutput?.();\n\t\trecord.unsubscribeExit?.();\n\t\tthis.#records.delete(record.id);\n\t\tthis.#notifyChange();\n\t\tconst status = describeExit(record.runtime) ?? \"exited\";\n\t\tconst code = record.runtime.exitResult?.exitCode;\n\t\tconst codeText = code === null || code === undefined ? \"\" : ` (exit code ${code})`;\n\t\tthis.#emitForRecord(record, {\n\t\t\ttype: \"summary\",\n\t\t\tid: record.id,\n\t\t\tdescription: record.description,\n\t\t\tsummary: `watcher ${status}${codeText}`,\n\t\t});\n\t\tconst exit = record.runtime.exitResult;\n\t\tthis.#emitEnded(record, exit?.timedOut ? \"timeout\" : exit?.cancelled ? \"killed\" : \"exit\", code ?? null);\n\t}\n\n\t#disposeRecord(record: MonitorRecord): void {\n\t\tif (record.settled) return;\n\t\trecord.settled = true;\n\t\trecord.unsubscribeOutput?.();\n\t\trecord.unsubscribeExit?.();\n\t\tthis.#records.delete(record.id);\n\t\tthis.#emitEnded(record, \"disposed\", null);\n\t}\n\n\t#emitForRecord(record: MonitorRecord | FileMonitorRecord, event: MonitorEvent): void {\n\t\trecord.fireCount += 1;\n\t\trecord.lastFiredAtMs = Date.now();\n\t\tthis.#emit(event);\n\t\tif (!record.settled) this.#onFire?.(this.snapshot());\n\t}\n\n\t#emitEnded(record: MonitorRecord | FileMonitorRecord, reason: MonitorEndedReason, exitCode: number | null): void {\n\t\tthis.#onEnded?.({\n\t\t\tid: record.id,\n\t\t\tdescription: record.description,\n\t\t\tstartedAtMs: record.startedAtMs,\n\t\t\tendedAtMs: Date.now(),\n\t\t\treason,\n\t\t\texitCode,\n\t\t\tfireCount: record.fireCount,\n\t\t});\n\t}\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ export type ExtensionKernelTools = {
3
+ describe(names: readonly string[]): Promise<unknown>;
4
+ invoke(request: {
5
+ name: string;
6
+ kernel_generation: number;
7
+ definition_revision: number;
8
+ args: unknown;
9
+ call_id: string;
10
+ }, signal?: AbortSignal): Promise<unknown>;
11
+ };
12
+ export declare const kernelToolsStorage: AsyncLocalStorage<ExtensionKernelTools>;
13
+ //# sourceMappingURL=kernel-tools-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel-tools-context.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/kernel-tools-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,MAAM,oBAAoB,GAAG;IAClC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACrD,MAAM,CACL,OAAO,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,iBAAiB,EAAE,MAAM,CAAC;QAC1B,mBAAmB,EAAE,MAAM,CAAC;QAC5B,IAAI,EAAE,OAAO,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;KAChB,EACD,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,OAAO,CAAC,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,kBAAkB,yCAAgD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ export const kernelToolsStorage = new AsyncLocalStorage();
3
+ //# sourceMappingURL=kernel-tools-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel-tools-context.js","sourceRoot":"","sources":["../../../src/core/extensions/kernel-tools-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAgBrD,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,iBAAiB,EAAwB,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nexport type ExtensionKernelTools = {\n\tdescribe(names: readonly string[]): Promise<unknown>;\n\tinvoke(\n\t\trequest: {\n\t\t\tname: string;\n\t\t\tkernel_generation: number;\n\t\t\tdefinition_revision: number;\n\t\t\targs: unknown;\n\t\t\tcall_id: string;\n\t\t},\n\t\tsignal?: AbortSignal,\n\t): Promise<unknown>;\n};\n\nexport const kernelToolsStorage = new AsyncLocalStorage<ExtensionKernelTools>();\n"]}
@@ -97,6 +97,9 @@ export type ShutdownHandler = () => void;
97
97
  /**
98
98
  * Helper function to emit session_shutdown event to extensions.
99
99
  * Returns true if the event was emitted, false if there were no handlers.
100
+ *
101
+ * Each handler runs under the host's shutdown budget (see
102
+ * `ExtensionRunner.emit`), so a hung extension cannot hold teardown hostage.
100
103
  */
101
104
  export declare function emitSessionShutdownEvent(extensionRunner: ExtensionRunner, event: SessionShutdownEvent): Promise<boolean>;
102
105
  export declare function emitProjectTrustEvent(extensionsResult: LoadExtensionsResult, event: ProjectTrustEvent, ctx: ProjectTrustContext): Promise<{
@@ -232,6 +235,22 @@ export declare class ExtensionRunner {
232
235
  createContext(excludeBeforeProviderRequestExtensionPath?: string): ExtensionContext;
233
236
  createCommandContext(): ExtensionCommandContext;
234
237
  private isSessionBeforeEvent;
238
+ /**
239
+ * Host budget for `session_shutdown` handlers, read from settings once per
240
+ * shutdown emission (teardown runs once per runner, so a settings edit takes
241
+ * effect without a reload). A malformed value must never break teardown, so
242
+ * an invalid setting is reported and the shipped defaults are used.
243
+ */
244
+ private resolveSessionShutdownBudget;
245
+ /**
246
+ * Runs one `session_shutdown` handler under the host budget. The handler sees
247
+ * the budget through `event.signal`, which this runner aborts at the hard cap;
248
+ * the host then stops waiting (the handler itself keeps running detached),
249
+ * reports an extension error and lets teardown continue with the next handler.
250
+ * Handler rejections are rethrown so emit()'s existing error path reports them
251
+ * exactly as before.
252
+ */
253
+ private runSessionShutdownHandler;
235
254
  emit<TEvent extends RunnerEmitEvent>(event: TEvent): Promise<RunnerEmitResult<TEvent>>;
236
255
  emitModelSelect(event: ModelSelectEvent): Promise<ModelSelectEventResult | undefined>;
237
256
  emitMessageEnd(event: MessageEndEvent): Promise<AgentMessage | undefined>;