@kolisachint/hoocode-agent 0.4.162 → 0.4.164

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 (339) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/cli/args.d.ts +0 -6
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +0 -31
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/config.d.ts +0 -40
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +4 -50
  9. package/dist/config.js.map +1 -1
  10. package/dist/core/agent-frontmatter.d.ts +0 -28
  11. package/dist/core/agent-frontmatter.d.ts.map +1 -1
  12. package/dist/core/agent-frontmatter.js +0 -6
  13. package/dist/core/agent-frontmatter.js.map +1 -1
  14. package/dist/core/agent-session-services.d.ts +0 -2
  15. package/dist/core/agent-session-services.d.ts.map +1 -1
  16. package/dist/core/agent-session-services.js +0 -2
  17. package/dist/core/agent-session-services.js.map +1 -1
  18. package/dist/core/agent-session.d.ts.map +1 -1
  19. package/dist/core/agent-session.js +0 -2
  20. package/dist/core/agent-session.js.map +1 -1
  21. package/dist/core/auth-guidance.d.ts +0 -1
  22. package/dist/core/auth-guidance.d.ts.map +1 -1
  23. package/dist/core/auth-guidance.js +1 -1
  24. package/dist/core/auth-guidance.js.map +1 -1
  25. package/dist/core/embsearch/chunker.d.ts +0 -2
  26. package/dist/core/embsearch/chunker.d.ts.map +1 -1
  27. package/dist/core/embsearch/chunker.js +1 -1
  28. package/dist/core/embsearch/chunker.js.map +1 -1
  29. package/dist/core/embsearch/index-meta.d.ts +0 -2
  30. package/dist/core/embsearch/index-meta.d.ts.map +1 -1
  31. package/dist/core/embsearch/index-meta.js +0 -6
  32. package/dist/core/embsearch/index-meta.js.map +1 -1
  33. package/dist/core/export-html/ansi-to-html.d.ts +0 -4
  34. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  35. package/dist/core/export-html/ansi-to-html.js +1 -1
  36. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  37. package/dist/core/extensions/index.d.ts +3 -3
  38. package/dist/core/extensions/index.d.ts.map +1 -1
  39. package/dist/core/extensions/index.js +1 -1
  40. package/dist/core/extensions/index.js.map +1 -1
  41. package/dist/core/extensions/plugins/authoring.d.ts +2 -2
  42. package/dist/core/extensions/plugins/authoring.d.ts.map +1 -1
  43. package/dist/core/extensions/plugins/authoring.js +0 -0
  44. package/dist/core/extensions/plugins/authoring.js.map +1 -1
  45. package/dist/core/extensions/plugins/formats/index.d.ts +2 -6
  46. package/dist/core/extensions/plugins/formats/index.d.ts.map +1 -1
  47. package/dist/core/extensions/plugins/formats/index.js +2 -3
  48. package/dist/core/extensions/plugins/formats/index.js.map +1 -1
  49. package/dist/core/extensions/plugins/formats/shared.d.ts +0 -2
  50. package/dist/core/extensions/plugins/formats/shared.d.ts.map +1 -1
  51. package/dist/core/extensions/plugins/formats/shared.js +1 -1
  52. package/dist/core/extensions/plugins/formats/shared.js.map +1 -1
  53. package/dist/core/extensions/plugins/formats/types.d.ts +4 -3
  54. package/dist/core/extensions/plugins/formats/types.d.ts.map +1 -1
  55. package/dist/core/extensions/plugins/formats/types.js.map +1 -1
  56. package/dist/core/extensions/plugins/install.d.ts +0 -2
  57. package/dist/core/extensions/plugins/install.d.ts.map +1 -1
  58. package/dist/core/extensions/plugins/install.js +1 -1
  59. package/dist/core/extensions/plugins/install.js.map +1 -1
  60. package/dist/core/extensions/plugins/manifest.d.ts +0 -6
  61. package/dist/core/extensions/plugins/manifest.d.ts.map +1 -1
  62. package/dist/core/extensions/plugins/manifest.js +0 -6
  63. package/dist/core/extensions/plugins/manifest.js.map +1 -1
  64. package/dist/core/extensions/plugins/marketplace.d.ts +3 -3
  65. package/dist/core/extensions/plugins/marketplace.d.ts.map +1 -1
  66. package/dist/core/extensions/plugins/marketplace.js.map +1 -1
  67. package/dist/core/extensions/types.d.ts +28 -28
  68. package/dist/core/extensions/types.d.ts.map +1 -1
  69. package/dist/core/extensions/types.js.map +1 -1
  70. package/dist/core/keybindings.d.ts +3 -3
  71. package/dist/core/keybindings.d.ts.map +1 -1
  72. package/dist/core/keybindings.js.map +1 -1
  73. package/dist/core/model-resolver.d.ts +0 -7
  74. package/dist/core/model-resolver.d.ts.map +1 -1
  75. package/dist/core/model-resolver.js +0 -56
  76. package/dist/core/model-resolver.js.map +1 -1
  77. package/dist/core/package-resource-discovery.d.ts +0 -10
  78. package/dist/core/package-resource-discovery.d.ts.map +1 -1
  79. package/dist/core/package-resource-discovery.js +7 -7
  80. package/dist/core/package-resource-discovery.js.map +1 -1
  81. package/dist/core/provider-health.d.ts +0 -2
  82. package/dist/core/provider-health.d.ts.map +1 -1
  83. package/dist/core/provider-health.js +1 -1
  84. package/dist/core/provider-health.js.map +1 -1
  85. package/dist/core/resolve-config-value.d.ts +0 -4
  86. package/dist/core/resolve-config-value.d.ts.map +1 -1
  87. package/dist/core/resolve-config-value.js +0 -15
  88. package/dist/core/resolve-config-value.js.map +1 -1
  89. package/dist/core/sdk.d.ts +3 -23
  90. package/dist/core/sdk.d.ts.map +1 -1
  91. package/dist/core/sdk.js +3 -5
  92. package/dist/core/sdk.js.map +1 -1
  93. package/dist/core/search/eval.d.ts +0 -3
  94. package/dist/core/search/eval.d.ts.map +1 -1
  95. package/dist/core/search/eval.js +1 -1
  96. package/dist/core/search/eval.js.map +1 -1
  97. package/dist/core/search/types.d.ts +2 -1
  98. package/dist/core/search/types.d.ts.map +1 -1
  99. package/dist/core/search/types.js.map +1 -1
  100. package/dist/core/session-cwd.d.ts +0 -1
  101. package/dist/core/session-cwd.d.ts.map +1 -1
  102. package/dist/core/session-cwd.js +1 -1
  103. package/dist/core/session-cwd.js.map +1 -1
  104. package/dist/core/settings-defaults.d.ts +0 -3
  105. package/dist/core/settings-defaults.d.ts.map +1 -1
  106. package/dist/core/settings-defaults.js +0 -3
  107. package/dist/core/settings-defaults.js.map +1 -1
  108. package/dist/core/settings-manager.d.ts +2 -9
  109. package/dist/core/settings-manager.d.ts.map +1 -1
  110. package/dist/core/settings-manager.js +0 -25
  111. package/dist/core/settings-manager.js.map +1 -1
  112. package/dist/core/settings-types.d.ts +9 -11
  113. package/dist/core/settings-types.d.ts.map +1 -1
  114. package/dist/core/settings-types.js.map +1 -1
  115. package/dist/core/subagent-inbox.d.ts +1 -3
  116. package/dist/core/subagent-inbox.d.ts.map +1 -1
  117. package/dist/core/subagent-inbox.js +1 -1
  118. package/dist/core/subagent-inbox.js.map +1 -1
  119. package/dist/core/subagent-pool.d.ts +0 -13
  120. package/dist/core/subagent-pool.d.ts.map +1 -1
  121. package/dist/core/subagent-pool.js +2 -2
  122. package/dist/core/subagent-pool.js.map +1 -1
  123. package/dist/core/task-store.d.ts +3 -3
  124. package/dist/core/task-store.d.ts.map +1 -1
  125. package/dist/core/task-store.js.map +1 -1
  126. package/dist/core/team-auto.d.ts +0 -2
  127. package/dist/core/team-auto.d.ts.map +1 -1
  128. package/dist/core/team-auto.js +1 -1
  129. package/dist/core/team-auto.js.map +1 -1
  130. package/dist/core/token-budget.d.ts +0 -13
  131. package/dist/core/token-budget.d.ts.map +1 -1
  132. package/dist/core/token-budget.js.map +1 -1
  133. package/dist/core/tools/bash.d.ts.map +1 -1
  134. package/dist/core/tools/bash.js +3 -1
  135. package/dist/core/tools/bash.js.map +1 -1
  136. package/dist/core/tools/edit-diff.d.ts +0 -38
  137. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  138. package/dist/core/tools/edit-diff.js +2 -9
  139. package/dist/core/tools/edit-diff.js.map +1 -1
  140. package/dist/core/tools/edit.d.ts.map +1 -1
  141. package/dist/core/tools/edit.js +5 -5
  142. package/dist/core/tools/edit.js.map +1 -1
  143. package/dist/core/tools/find.d.ts.map +1 -1
  144. package/dist/core/tools/find.js +8 -10
  145. package/dist/core/tools/find.js.map +1 -1
  146. package/dist/core/tools/grep.d.ts.map +1 -1
  147. package/dist/core/tools/grep.js +4 -4
  148. package/dist/core/tools/grep.js.map +1 -1
  149. package/dist/core/tools/index.d.ts +0 -24
  150. package/dist/core/tools/index.d.ts.map +1 -1
  151. package/dist/core/tools/index.js +0 -20
  152. package/dist/core/tools/index.js.map +1 -1
  153. package/dist/core/tools/ls.d.ts.map +1 -1
  154. package/dist/core/tools/ls.js +2 -2
  155. package/dist/core/tools/ls.js.map +1 -1
  156. package/dist/core/tools/native-search.d.ts +3 -2
  157. package/dist/core/tools/native-search.d.ts.map +1 -1
  158. package/dist/core/tools/native-search.js.map +1 -1
  159. package/dist/core/tools/path-utils.d.ts +0 -10
  160. package/dist/core/tools/path-utils.d.ts.map +1 -1
  161. package/dist/core/tools/path-utils.js +2 -2
  162. package/dist/core/tools/path-utils.js.map +1 -1
  163. package/dist/core/tools/plugins.d.ts +1 -20
  164. package/dist/core/tools/plugins.d.ts.map +1 -1
  165. package/dist/core/tools/plugins.js +2 -2
  166. package/dist/core/tools/plugins.js.map +1 -1
  167. package/dist/core/tools/propose-plugin.d.ts +0 -12
  168. package/dist/core/tools/propose-plugin.d.ts.map +1 -1
  169. package/dist/core/tools/propose-plugin.js +0 -1
  170. package/dist/core/tools/propose-plugin.js.map +1 -1
  171. package/dist/core/tools/read-dedup.d.ts +0 -2
  172. package/dist/core/tools/read-dedup.d.ts.map +1 -1
  173. package/dist/core/tools/read-dedup.js +1 -1
  174. package/dist/core/tools/read-dedup.js.map +1 -1
  175. package/dist/core/tools/read.d.ts.map +1 -1
  176. package/dist/core/tools/read.js +10 -8
  177. package/dist/core/tools/read.js.map +1 -1
  178. package/dist/core/tools/render-utils.d.ts +0 -5
  179. package/dist/core/tools/render-utils.d.ts.map +1 -1
  180. package/dist/core/tools/render-utils.js.map +1 -1
  181. package/dist/core/tools/search.d.ts +1 -4
  182. package/dist/core/tools/search.d.ts.map +1 -1
  183. package/dist/core/tools/search.js +6 -6
  184. package/dist/core/tools/search.js.map +1 -1
  185. package/dist/core/tools/webfetch.d.ts +1 -2
  186. package/dist/core/tools/webfetch.d.ts.map +1 -1
  187. package/dist/core/tools/webfetch.js.map +1 -1
  188. package/dist/core/tools/websearch.d.ts +1 -2
  189. package/dist/core/tools/websearch.d.ts.map +1 -1
  190. package/dist/core/tools/websearch.js.map +1 -1
  191. package/dist/core/tools/webtools-shared.d.ts +3 -5
  192. package/dist/core/tools/webtools-shared.d.ts.map +1 -1
  193. package/dist/core/tools/webtools-shared.js +1 -1
  194. package/dist/core/tools/webtools-shared.js.map +1 -1
  195. package/dist/core/warm-subagent-pool-instance.d.ts +0 -4
  196. package/dist/core/warm-subagent-pool-instance.d.ts.map +1 -1
  197. package/dist/core/warm-subagent-pool-instance.js +0 -10
  198. package/dist/core/warm-subagent-pool-instance.js.map +1 -1
  199. package/dist/core/wordmark.d.ts +1 -9
  200. package/dist/core/wordmark.d.ts.map +1 -1
  201. package/dist/core/wordmark.js +2 -26
  202. package/dist/core/wordmark.js.map +1 -1
  203. package/dist/extensions/core/config.d.ts +4 -3
  204. package/dist/extensions/core/config.d.ts.map +1 -1
  205. package/dist/extensions/core/config.js.map +1 -1
  206. package/dist/extensions/core/mcp-loader.d.ts +0 -18
  207. package/dist/extensions/core/mcp-loader.d.ts.map +1 -1
  208. package/dist/extensions/core/mcp-loader.js.map +1 -1
  209. package/dist/extensions/core/prompt-reactive/policy.d.ts +0 -8
  210. package/dist/extensions/core/prompt-reactive/policy.d.ts.map +1 -1
  211. package/dist/extensions/core/prompt-reactive/policy.js +1 -1
  212. package/dist/extensions/core/prompt-reactive/policy.js.map +1 -1
  213. package/dist/main.d.ts.map +1 -1
  214. package/dist/main.js +0 -30
  215. package/dist/main.js.map +1 -1
  216. package/dist/migrations.d.ts +0 -16
  217. package/dist/migrations.d.ts.map +1 -1
  218. package/dist/migrations.js +2 -2
  219. package/dist/migrations.js.map +1 -1
  220. package/dist/modes/interactive/brand.d.ts +0 -4
  221. package/dist/modes/interactive/brand.d.ts.map +1 -1
  222. package/dist/modes/interactive/brand.js +0 -4
  223. package/dist/modes/interactive/brand.js.map +1 -1
  224. package/dist/modes/interactive/components/index.d.ts +0 -4
  225. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  226. package/dist/modes/interactive/components/index.js +0 -5
  227. package/dist/modes/interactive/components/index.js.map +1 -1
  228. package/dist/modes/interactive/components/read-output.d.ts +0 -9
  229. package/dist/modes/interactive/components/read-output.d.ts.map +1 -1
  230. package/dist/modes/interactive/components/read-output.js +0 -20
  231. package/dist/modes/interactive/components/read-output.js.map +1 -1
  232. package/dist/modes/interactive/components/session-selector-search.d.ts +0 -17
  233. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  234. package/dist/modes/interactive/components/session-selector-search.js +2 -2
  235. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  236. package/dist/modes/interactive/components/settings-selector.d.ts +5 -14
  237. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  238. package/dist/modes/interactive/components/settings-selector.js +2 -2
  239. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  240. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  241. package/dist/modes/interactive/interactive-mode.js +0 -18
  242. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  243. package/dist/modes/interactive/login-controller.d.ts +1 -1
  244. package/dist/modes/interactive/login-controller.d.ts.map +1 -1
  245. package/dist/modes/interactive/login-controller.js +1 -1
  246. package/dist/modes/interactive/login-controller.js.map +1 -1
  247. package/dist/modes/interactive/resource-display.d.ts +0 -20
  248. package/dist/modes/interactive/resource-display.d.ts.map +1 -1
  249. package/dist/modes/interactive/resource-display.js +7 -7
  250. package/dist/modes/interactive/resource-display.js.map +1 -1
  251. package/dist/modes/interactive/theme/theme.d.ts +0 -4
  252. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  253. package/dist/modes/interactive/theme/theme.js +0 -7
  254. package/dist/modes/interactive/theme/theme.js.map +1 -1
  255. package/dist/modes/rpc/rpc-mode.d.ts +0 -1
  256. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  257. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  258. package/dist/modes/rpc/rpc-types.d.ts +0 -1
  259. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  260. package/dist/modes/rpc/rpc-types.js +3 -0
  261. package/dist/modes/rpc/rpc-types.js.map +1 -1
  262. package/dist/package-manager-cli.d.ts +0 -1
  263. package/dist/package-manager-cli.d.ts.map +1 -1
  264. package/dist/package-manager-cli.js.map +1 -1
  265. package/dist/utils/changelog.d.ts +0 -4
  266. package/dist/utils/changelog.d.ts.map +1 -1
  267. package/dist/utils/changelog.js +1 -1
  268. package/dist/utils/changelog.js.map +1 -1
  269. package/dist/utils/clipboard-native.d.ts +1 -1
  270. package/dist/utils/clipboard-native.d.ts.map +1 -1
  271. package/dist/utils/clipboard-native.js.map +1 -1
  272. package/dist/utils/paths.d.ts +0 -2
  273. package/dist/utils/paths.d.ts.map +1 -1
  274. package/dist/utils/paths.js +1 -1
  275. package/dist/utils/paths.js.map +1 -1
  276. package/dist/utils/plan/parser.d.ts +5 -4
  277. package/dist/utils/plan/parser.d.ts.map +1 -1
  278. package/dist/utils/plan/parser.js.map +1 -1
  279. package/dist/utils/tools-manager.d.ts +1 -2
  280. package/dist/utils/tools-manager.d.ts.map +1 -1
  281. package/dist/utils/tools-manager.js +2 -50
  282. package/dist/utils/tools-manager.js.map +1 -1
  283. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  284. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  285. package/examples/extensions/sandbox/package.json +1 -1
  286. package/examples/extensions/with-deps/package.json +1 -1
  287. package/package.json +4 -7
  288. package/dist/core/index.d.ts +0 -12
  289. package/dist/core/index.d.ts.map +0 -1
  290. package/dist/core/index.js +0 -12
  291. package/dist/core/index.js.map +0 -1
  292. package/dist/core/tools/browser/browser-continue.d.ts +0 -25
  293. package/dist/core/tools/browser/browser-continue.d.ts.map +0 -1
  294. package/dist/core/tools/browser/browser-continue.js +0 -84
  295. package/dist/core/tools/browser/browser-continue.js.map +0 -1
  296. package/dist/core/tools/browser/browser-run.d.ts +0 -48
  297. package/dist/core/tools/browser/browser-run.d.ts.map +0 -1
  298. package/dist/core/tools/browser/browser-run.js +0 -377
  299. package/dist/core/tools/browser/browser-run.js.map +0 -1
  300. package/dist/core/tools/browser/browsertools-shared.d.ts +0 -190
  301. package/dist/core/tools/browser/browsertools-shared.d.ts.map +0 -1
  302. package/dist/core/tools/browser/browsertools-shared.js +0 -335
  303. package/dist/core/tools/browser/browsertools-shared.js.map +0 -1
  304. package/dist/core/tools/browser/index.d.ts +0 -8
  305. package/dist/core/tools/browser/index.d.ts.map +0 -1
  306. package/dist/core/tools/browser/index.js +0 -8
  307. package/dist/core/tools/browser/index.js.map +0 -1
  308. package/dist/core/tools/doc/docedit.d.ts +0 -44
  309. package/dist/core/tools/doc/docedit.d.ts.map +0 -1
  310. package/dist/core/tools/doc/docedit.js +0 -133
  311. package/dist/core/tools/doc/docedit.js.map +0 -1
  312. package/dist/core/tools/doc/docgrep.d.ts +0 -28
  313. package/dist/core/tools/doc/docgrep.d.ts.map +0 -1
  314. package/dist/core/tools/doc/docgrep.js +0 -106
  315. package/dist/core/tools/doc/docgrep.js.map +0 -1
  316. package/dist/core/tools/doc/docpeek.d.ts +0 -25
  317. package/dist/core/tools/doc/docpeek.d.ts.map +0 -1
  318. package/dist/core/tools/doc/docpeek.js +0 -112
  319. package/dist/core/tools/doc/docpeek.js.map +0 -1
  320. package/dist/core/tools/doc/docread.d.ts +0 -32
  321. package/dist/core/tools/doc/docread.d.ts.map +0 -1
  322. package/dist/core/tools/doc/docread.js +0 -113
  323. package/dist/core/tools/doc/docread.js.map +0 -1
  324. package/dist/core/tools/doc/docscan.d.ts +0 -29
  325. package/dist/core/tools/doc/docscan.d.ts.map +0 -1
  326. package/dist/core/tools/doc/docscan.js +0 -110
  327. package/dist/core/tools/doc/docscan.js.map +0 -1
  328. package/dist/core/tools/doc/docwrite.d.ts +0 -44
  329. package/dist/core/tools/doc/docwrite.d.ts.map +0 -1
  330. package/dist/core/tools/doc/docwrite.js +0 -102
  331. package/dist/core/tools/doc/docwrite.js.map +0 -1
  332. package/dist/core/tools/doc/index.d.ts +0 -11
  333. package/dist/core/tools/doc/index.d.ts.map +0 -1
  334. package/dist/core/tools/doc/index.js +0 -11
  335. package/dist/core/tools/doc/index.js.map +0 -1
  336. package/dist/core/tools/filetools-shared.d.ts +0 -271
  337. package/dist/core/tools/filetools-shared.d.ts.map +0 -1
  338. package/dist/core/tools/filetools-shared.js +0 -403
  339. package/dist/core/tools/filetools-shared.js.map +0 -1
@@ -1,190 +0,0 @@
1
- /**
2
- * Shared plumbing for the `browser_run` and `browser_continue` tools.
3
- *
4
- * Unlike `webtools` (one-shot fetch/search subprocesses), `browsertools` drives
5
- * a *stateful* parent-in-the-loop protocol: a single long-lived `browsertools
6
- * serve` process holds the live Chromium and the paused-flow state in memory,
7
- * and the parent (hoocode) talks to it over newline-delimited JSON-RPC on
8
- * stdin/stdout. A flow can suspend mid-replay with `Outcome::NeedsParent`,
9
- * yielding a typed `ParentRequest` + `ResumeToken`; the parent reasons about it
10
- * (often by looking at a screenshot) and calls `flow_resume(token, response)` to
11
- * continue. See https://github.com/kolisachint/browsertools (contract.rs).
12
- *
13
- * Because that single serve process must survive *between* the `browser_run`
14
- * call that starts the flow and the `browser_continue` call that answers a
15
- * `NeedsParent`, this module owns a process-wide {@link sessionRegistry} keyed by
16
- * `ResumeToken`. Each paused session keeps its serve client alive and is reaped
17
- * after an idle timeout so an abandoned flow never leaks a Chromium forever.
18
- *
19
- * This module owns:
20
- * - the persistent JSON-RPC serve client (id-correlated request/response),
21
- * - the locked contract types (mirrors browsertools `src/contract.rs`),
22
- * - the paused-session registry + lifecycle (idle reap, round cap, teardown),
23
- * - binary + browser-path resolution.
24
- */
25
- /** Opaque token identifying a paused flow, returned with every `NeedsParent`. */
26
- export type ResumeToken = string;
27
- /** Reference to bytes (e.g. a screenshot) the parent can fetch via `get_resource`. */
28
- export type ResourceId = string;
29
- /**
30
- * A typed request the engine yields when replay hits ambiguity only an LLM can
31
- * resolve. The `request` discriminant matches the serde tag in contract.rs.
32
- * Fields beyond the discriminant are passed through verbatim to the model.
33
- */
34
- export interface ParentRequest {
35
- request: "classify_state" | "verify_visual" | "extract_semantic" | "decide_next_action" | "reidentify_element";
36
- /** Resource id of the screenshot captured at the suspension point, if any. */
37
- screenshot_ref?: ResourceId;
38
- [key: string]: unknown;
39
- }
40
- /** Result of a `flow_start` / `flow_resume` RPC (the `result` field's `outcome`). */
41
- export type FlowOutcome = {
42
- outcome: "complete";
43
- result?: unknown;
44
- } | {
45
- outcome: "needs_parent";
46
- request: ParentRequest;
47
- token: ResumeToken;
48
- } | {
49
- outcome: "failed";
50
- step_id?: string;
51
- kind?: string;
52
- detail?: string;
53
- };
54
- /** Result of a `get_resource` RPC. */
55
- export interface GetResourceResult {
56
- ref: ResourceId;
57
- mime: string;
58
- len: number;
59
- png_base64: string;
60
- }
61
- /** Default per-request RPC timeout. Flow steps drive a real browser, so this is
62
- * generous relative to webtools' 15s. */
63
- export declare const BROWSERTOOLS_REQUEST_TIMEOUT_MS = 120000;
64
- /** Default idle window a paused flow may sit in the registry before it is reaped
65
- * (killing its serve process + Chromium). Reset on every resume round. The
66
- * parent may reason / look at a screenshot / make other tool calls between
67
- * rounds, so this is minutes, not seconds. */
68
- export declare const BROWSERTOOLS_DEFAULT_IDLE_MS: number;
69
- /** Default hard cap on `NeedsParent` rounds for a single flow, bounding a runaway
70
- * suspend/resume loop. */
71
- export declare const BROWSERTOOLS_DEFAULT_MAX_ROUNDS = 12;
72
- /** Options threaded into the browser tools by their factories (tests/overrides). */
73
- export interface BrowsertoolsToolOptions {
74
- /** Explicit path to the `browsertools` binary; otherwise resolved via {@link ensureTool}. */
75
- binaryPath?: string;
76
- /** Chromium/Chrome executable path forwarded to the serve process. */
77
- browserPath?: string;
78
- /** Idle reap window for paused sessions (ms). */
79
- idleTimeoutMs?: number;
80
- /** Hard cap on NeedsParent rounds per flow. */
81
- maxParentRounds?: number;
82
- /** Per-request RPC timeout (ms). */
83
- requestTimeoutMs?: number;
84
- /** Extra args appended after `serve` (mainly for tests). */
85
- serveArgs?: string[];
86
- /** Launch a real on-screen Chromium window instead of headless (sets
87
- * `BROWSERTOOLS_HEADFUL=1` on the serve process). */
88
- headful?: boolean;
89
- /** Default the streamed live viewer on for every flow (the per-call `live_view`
90
- * param still overrides). Set by the --enable-browser-live-preview flag. */
91
- liveView?: boolean;
92
- }
93
- /** Resolve effective options from explicit overrides, then env, then defaults. */
94
- export declare function resolveBrowsertoolsOptions(options?: BrowsertoolsToolOptions): Required<Pick<BrowsertoolsToolOptions, "idleTimeoutMs" | "maxParentRounds" | "requestTimeoutMs">> & {
95
- binaryPath?: string;
96
- browserPath?: string;
97
- serveArgs: string[];
98
- headful: boolean;
99
- liveView: boolean;
100
- };
101
- /** Resolve the `browsertools` binary path (explicit override, else download/PATH). */
102
- export declare function resolveBrowsertoolsBinary(options?: BrowsertoolsToolOptions): Promise<string>;
103
- /**
104
- * A live `browsertools serve` process spoken to over newline-delimited JSON-RPC.
105
- *
106
- * Wire format (browsertools `src/serve.rs`):
107
- * request: `{ "id": <n>, "method": <string>, "params": <object> }\n`
108
- * response: `{ "id": <n>, "result": <value> }` or `{ "id": <n>, "error": <RpcError> }`\n
109
- *
110
- * Responses are correlated by `id`, so concurrent requests are safe, though the
111
- * tools drive it sequentially.
112
- */
113
- export declare class BrowsertoolsServeClient {
114
- /** URL of the live viewer once `live_view_start` has been issued for this
115
- * serve process, cached so a reused (reclaimed-idle) client does not start a
116
- * second viewer or auto-open another OS tab on the next browser_run call. */
117
- liveViewUrl?: string;
118
- private readonly proc;
119
- private readonly pending;
120
- private readonly requestTimeoutMs;
121
- private buffer;
122
- private nextId;
123
- private closed;
124
- private exitError;
125
- private stderrTail;
126
- constructor(binaryPath: string, opts: {
127
- cwd?: string;
128
- browserPath?: string;
129
- serveArgs: string[];
130
- requestTimeoutMs: number;
131
- headful?: boolean;
132
- });
133
- private onStdout;
134
- private onLine;
135
- /** Reject all in-flight requests and mark the client dead. Idempotent. */
136
- private fail;
137
- /** Send a JSON-RPC request and resolve with its `result` (or reject on `error`). */
138
- request<T = unknown>(method: string, params: Record<string, unknown>): Promise<T>;
139
- /** Kill the serve process and reject any outstanding requests. Idempotent. */
140
- dispose(): void;
141
- }
142
- interface PausedSession {
143
- client: BrowsertoolsServeClient;
144
- /** Number of NeedsParent rounds yielded so far for this flow. */
145
- rounds: number;
146
- idleTimer: ReturnType<typeof setTimeout>;
147
- idleTimeoutMs: number;
148
- /** Whether the browser was launched in headful mode for this session. */
149
- headful: boolean;
150
- /** Explicit browser path used for this session, if any. */
151
- browserPath?: string;
152
- }
153
- /**
154
- * Park a paused flow's live serve client under its resume token and arm the idle
155
- * reaper. Any previous entry for the token is disposed first.
156
- */
157
- export declare function parkSession(token: ResumeToken, client: BrowsertoolsServeClient, rounds: number, idleTimeoutMs: number, headful?: boolean, browserPath?: string): void;
158
- /**
159
- * Remove a paused session from the registry and return it, stopping its idle
160
- * timer. The caller now owns the client (to resume or dispose). Returns
161
- * undefined if the token is unknown (expired/reaped/already completed).
162
- */
163
- export declare function takeSession(token: ResumeToken): PausedSession | undefined;
164
- /** Dispose every parked session. Used on shutdown and in tests. */
165
- export declare function disposeAllSessions(): void;
166
- /** Number of currently parked sessions (for tests/diagnostics). */
167
- export declare function pausedSessionCount(): number;
168
- /** Configuration preserved from the original flow call so the idle client can
169
- * be matched and reused by a subsequent browser_run with the same settings. */
170
- export interface BrowserClientConfig {
171
- headful: boolean;
172
- browserPath?: string;
173
- idleTimeoutMs: number;
174
- }
175
- /**
176
- * Try to reclaim the shared idle client if its browser config matches.
177
- * Returns the live client (and clears the slot) on match, or null.
178
- */
179
- export declare function takeIdleClient(headful: boolean, browserPath?: string, _idleTimeoutMs?: number): BrowsertoolsServeClient | null;
180
- /**
181
- * Park a completed/failed flow's client as idle so the next browser_run call
182
- * can reuse the same Chromium process and live-view port.
183
- */
184
- export declare function parkIdleClient(client: BrowsertoolsServeClient, headful: boolean, browserPath?: string, idleTimeoutMs?: number): void;
185
- /** Dispose the shared idle client. Called on session shutdown. */
186
- export declare function disposeIdleClient(): void;
187
- /** Number of currently idle shared clients (0 or 1, for tests/diagnostics). */
188
- export declare function idleClientCount(): number;
189
- export {};
190
- //# sourceMappingURL=browsertools-shared.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browsertools-shared.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/browser/browsertools-shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AASH,iFAAiF;AACjF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,sFAAsF;AACtF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,gBAAgB,GAAG,eAAe,GAAG,kBAAkB,GAAG,oBAAoB,GAAG,oBAAoB,CAAC;IAC/G,8EAA8E;IAC9E,cAAc,CAAC,EAAE,UAAU,CAAC;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,qFAAqF;AACrF,MAAM,MAAM,WAAW,GACpB;IAAE,OAAO,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GACzC;IAAE,OAAO,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GACvE;IAAE,OAAO,EAAE,QAAQ,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,sCAAsC;AACtC,MAAM,WAAW,iBAAiB;IACjC,GAAG,EAAE,UAAU,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAA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M,EACrB,OAAO,UAAQ,EACf,WAAW,CAAC,EAAE,MAAM,GAClB,IAAI,CAeN;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,aAAa,GAAG,SAAS,CAMzE;AAED,mEAAmE;AACnE,wBAAgB,kBAAkB,IAAI,IAAI,CAOzC;AAED,mEAAmE;AACnE,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAMD;gFACgF;AAChF,MAAM,WAAW,mBAAmB;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACtB;AAWD;;;GAGG;AACH,wBAAgB,cAAc,CAC7B,OAAO,EAAE,OAAO,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,cAAc,GAAE,MAAqC,GACnD,uBAAuB,GAAG,IAAI,CAYhC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,uBAAuB,EAC/B,OAAO,EAAE,OAAO,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,aAAa,GAAE,MAAqC,GAClD,IAAI,CAaN;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,IAAI,IAAI,CAMxC;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,IAAI,MAAM,CAExC","sourcesContent":["/**\n * Shared plumbing for the `browser_run` and `browser_continue` tools.\n *\n * Unlike `webtools` (one-shot fetch/search subprocesses), `browsertools` drives\n * a *stateful* parent-in-the-loop protocol: a single long-lived `browsertools\n * serve` process holds the live Chromium and the paused-flow state in memory,\n * and the parent (hoocode) talks to it over newline-delimited JSON-RPC on\n * stdin/stdout. A flow can suspend mid-replay with `Outcome::NeedsParent`,\n * yielding a typed `ParentRequest` + `ResumeToken`; the parent reasons about it\n * (often by looking at a screenshot) and calls `flow_resume(token, response)` to\n * continue. See https://github.com/kolisachint/browsertools (contract.rs).\n *\n * Because that single serve process must survive *between* the `browser_run`\n * call that starts the flow and the `browser_continue` call that answers a\n * `NeedsParent`, this module owns a process-wide {@link sessionRegistry} keyed by\n * `ResumeToken`. Each paused session keeps its serve client alive and is reaped\n * after an idle timeout so an abandoned flow never leaks a Chromium forever.\n *\n * This module owns:\n * - the persistent JSON-RPC serve client (id-correlated request/response),\n * - the locked contract types (mirrors browsertools `src/contract.rs`),\n * - the paused-session registry + lifecycle (idle reap, round cap, teardown),\n * - binary + browser-path resolution.\n */\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport { ensureTool } from \"../../../utils/tools-manager.js\";\n\n// ============================================================================\n// Contract types (locked against browsertools `src/contract.rs`)\n// ============================================================================\n\n/** Opaque token identifying a paused flow, returned with every `NeedsParent`. */\nexport type ResumeToken = string;\n\n/** Reference to bytes (e.g. a screenshot) the parent can fetch via `get_resource`. */\nexport type ResourceId = string;\n\n/**\n * A typed request the engine yields when replay hits ambiguity only an LLM can\n * resolve. The `request` discriminant matches the serde tag in contract.rs.\n * Fields beyond the discriminant are passed through verbatim to the model.\n */\nexport interface ParentRequest {\n\trequest: \"classify_state\" | \"verify_visual\" | \"extract_semantic\" | \"decide_next_action\" | \"reidentify_element\";\n\t/** Resource id of the screenshot captured at the suspension point, if any. */\n\tscreenshot_ref?: ResourceId;\n\t[key: string]: unknown;\n}\n\n/** Result of a `flow_start` / `flow_resume` RPC (the `result` field's `outcome`). */\nexport type FlowOutcome =\n\t| { outcome: \"complete\"; result?: unknown }\n\t| { outcome: \"needs_parent\"; request: ParentRequest; token: ResumeToken }\n\t| { outcome: \"failed\"; step_id?: string; kind?: string; detail?: string };\n\n/** Result of a `get_resource` RPC. */\nexport interface GetResourceResult {\n\tref: ResourceId;\n\tmime: string;\n\tlen: number;\n\tpng_base64: string;\n}\n\n// ============================================================================\n// Configuration\n// ============================================================================\n\n/** Default per-request RPC timeout. Flow steps drive a real browser, so this is\n * generous relative to webtools' 15s. */\nexport const BROWSERTOOLS_REQUEST_TIMEOUT_MS = 120_000;\n\n/** Default idle window a paused flow may sit in the registry before it is reaped\n * (killing its serve process + Chromium). Reset on every resume round. The\n * parent may reason / look at a screenshot / make other tool calls between\n * rounds, so this is minutes, not seconds. */\nexport const BROWSERTOOLS_DEFAULT_IDLE_MS = 5 * 60 * 1000;\n\n/** Default hard cap on `NeedsParent` rounds for a single flow, bounding a runaway\n * suspend/resume loop. */\nexport const BROWSERTOOLS_DEFAULT_MAX_ROUNDS = 12;\n\n/** Options threaded into the browser tools by their factories (tests/overrides). */\nexport interface BrowsertoolsToolOptions {\n\t/** Explicit path to the `browsertools` binary; otherwise resolved via {@link ensureTool}. */\n\tbinaryPath?: string;\n\t/** Chromium/Chrome executable path forwarded to the serve process. */\n\tbrowserPath?: string;\n\t/** Idle reap window for paused sessions (ms). */\n\tidleTimeoutMs?: number;\n\t/** Hard cap on NeedsParent rounds per flow. */\n\tmaxParentRounds?: number;\n\t/** Per-request RPC timeout (ms). */\n\trequestTimeoutMs?: number;\n\t/** Extra args appended after `serve` (mainly for tests). */\n\tserveArgs?: string[];\n\t/** Launch a real on-screen Chromium window instead of headless (sets\n\t * `BROWSERTOOLS_HEADFUL=1` on the serve process). */\n\theadful?: boolean;\n\t/** Default the streamed live viewer on for every flow (the per-call `live_view`\n\t * param still overrides). Set by the --enable-browser-live-preview flag. */\n\tliveView?: boolean;\n}\n\nfunction envNumber(name: string): number | undefined {\n\tconst raw = process.env[name];\n\tif (!raw) return undefined;\n\tconst n = Number(raw);\n\treturn Number.isFinite(n) && n > 0 ? n : undefined;\n}\n\n/** Resolve effective options from explicit overrides, then env, then defaults. */\nexport function resolveBrowsertoolsOptions(options?: BrowsertoolsToolOptions): Required<\n\tPick<BrowsertoolsToolOptions, \"idleTimeoutMs\" | \"maxParentRounds\" | \"requestTimeoutMs\">\n> & {\n\tbinaryPath?: string;\n\tbrowserPath?: string;\n\tserveArgs: string[];\n\theadful: boolean;\n\tliveView: boolean;\n} {\n\treturn {\n\t\tbinaryPath: options?.binaryPath,\n\t\tbrowserPath: options?.browserPath ?? (process.env.HOOCODE_BROWSERTOOLS_BROWSER_PATH?.trim() || undefined),\n\t\theadful: options?.headful ?? false,\n\t\tliveView: options?.liveView ?? false,\n\t\tidleTimeoutMs:\n\t\t\toptions?.idleTimeoutMs ?? envNumber(\"HOOCODE_BROWSERTOOLS_IDLE_MS\") ?? BROWSERTOOLS_DEFAULT_IDLE_MS,\n\t\tmaxParentRounds:\n\t\t\toptions?.maxParentRounds ?? envNumber(\"HOOCODE_BROWSERTOOLS_MAX_ROUNDS\") ?? BROWSERTOOLS_DEFAULT_MAX_ROUNDS,\n\t\trequestTimeoutMs:\n\t\t\toptions?.requestTimeoutMs ??\n\t\t\tenvNumber(\"HOOCODE_BROWSERTOOLS_REQUEST_TIMEOUT_MS\") ??\n\t\t\tBROWSERTOOLS_REQUEST_TIMEOUT_MS,\n\t\tserveArgs: options?.serveArgs ?? [],\n\t};\n}\n\nconst BINARY_MISSING_MESSAGE =\n\t\"browsertools binary unavailable and could not be downloaded — the browser tools require the `browsertools` CLI on PATH or a published release for this platform\";\n\n/** Resolve the `browsertools` binary path (explicit override, else download/PATH). */\nexport async function resolveBrowsertoolsBinary(options?: BrowsertoolsToolOptions): Promise<string> {\n\tif (options?.binaryPath) return options.binaryPath;\n\tconst binaryPath = await ensureTool(\"browsertools\", true);\n\tif (!binaryPath) throw new Error(BINARY_MISSING_MESSAGE);\n\treturn binaryPath;\n}\n\n// ============================================================================\n// Persistent JSON-RPC serve client\n// ============================================================================\n\ninterface PendingRequest {\n\tresolve: (value: unknown) => void;\n\treject: (error: Error) => void;\n\ttimer: ReturnType<typeof setTimeout>;\n}\n\n/**\n * A live `browsertools serve` process spoken to over newline-delimited JSON-RPC.\n *\n * Wire format (browsertools `src/serve.rs`):\n * request: `{ \"id\": <n>, \"method\": <string>, \"params\": <object> }\\n`\n * response: `{ \"id\": <n>, \"result\": <value> }` or `{ \"id\": <n>, \"error\": <RpcError> }`\\n\n *\n * Responses are correlated by `id`, so concurrent requests are safe, though the\n * tools drive it sequentially.\n */\nexport class BrowsertoolsServeClient {\n\t/** URL of the live viewer once `live_view_start` has been issued for this\n\t * serve process, cached so a reused (reclaimed-idle) client does not start a\n\t * second viewer or auto-open another OS tab on the next browser_run call. */\n\tliveViewUrl?: string;\n\tprivate readonly proc: ChildProcess;\n\tprivate readonly pending = new Map<number, PendingRequest>();\n\tprivate readonly requestTimeoutMs: number;\n\tprivate buffer = \"\";\n\tprivate nextId = 1;\n\tprivate closed = false;\n\tprivate exitError: Error | undefined;\n\tprivate stderrTail = \"\";\n\n\tconstructor(\n\t\tbinaryPath: string,\n\t\topts: {\n\t\t\tcwd?: string;\n\t\t\tbrowserPath?: string;\n\t\t\tserveArgs: string[];\n\t\t\trequestTimeoutMs: number;\n\t\t\theadful?: boolean;\n\t\t},\n\t) {\n\t\tthis.requestTimeoutMs = opts.requestTimeoutMs;\n\t\t// The exact CLI flag for the browser path is not part of the locked RPC\n\t\t// contract; v0.1.3 added a \"configurable browser path\". We forward it via\n\t\t// env vars the binary is likely to read. Passing extra env is harmless if\n\t\t// the binary ignores them, and centralizing it here makes it a one-line\n\t\t// change once the exact mechanism is confirmed.\n\t\tconst env = { ...process.env };\n\t\tif (opts.browserPath) {\n\t\t\tenv.BROWSERTOOLS_BROWSER_PATH = opts.browserPath;\n\t\t\tenv.CHROME_PATH = opts.browserPath;\n\t\t}\n\t\t// Opt into a real on-screen Chromium window. The serve process reads this\n\t\t// in `Driver::launch`; harmless if an older binary ignores it.\n\t\tif (opts.headful) {\n\t\t\tenv.BROWSERTOOLS_HEADFUL = \"1\";\n\t\t}\n\t\t// Run the serve process in the project cwd so relative flow paths and the\n\t\t// evidence store resolve the same way the user expects.\n\t\tthis.proc = spawn(binaryPath, [\"serve\", ...opts.serveArgs], {\n\t\t\tcwd: opts.cwd,\n\t\t\tshell: false,\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\tenv,\n\t\t});\n\t\tthis.proc.stdout?.setEncoding(\"utf8\");\n\t\tthis.proc.stdout?.on(\"data\", (chunk: string) => this.onStdout(chunk));\n\t\tthis.proc.stderr?.setEncoding(\"utf8\");\n\t\tthis.proc.stderr?.on(\"data\", (chunk: string) => {\n\t\t\t// Keep only a bounded tail so a chatty serve can't grow unbounded; it is\n\t\t\t// surfaced in the error when the process dies unexpectedly.\n\t\t\tthis.stderrTail = (this.stderrTail + chunk).slice(-4000);\n\t\t});\n\t\tthis.proc.on(\"error\", (err) => this.fail(err instanceof Error ? err : new Error(String(err))));\n\t\tthis.proc.on(\"exit\", (code, sig) => {\n\t\t\tif (this.closed) return;\n\t\t\tconst detail = this.stderrTail.trim();\n\t\t\tthis.fail(\n\t\t\t\tnew Error(\n\t\t\t\t\t`browsertools serve exited unexpectedly (code=${code ?? \"null\"}, signal=${sig ?? \"null\"})` +\n\t\t\t\t\t\t(detail ? `: ${detail}` : \"\"),\n\t\t\t\t),\n\t\t\t);\n\t\t});\n\t}\n\n\tprivate onStdout(chunk: string): void {\n\t\tthis.buffer += chunk;\n\t\tlet newlineIndex = this.buffer.indexOf(\"\\n\");\n\t\twhile (newlineIndex !== -1) {\n\t\t\tconst line = this.buffer.slice(0, newlineIndex).trim();\n\t\t\tthis.buffer = this.buffer.slice(newlineIndex + 1);\n\t\t\tif (line) this.onLine(line);\n\t\t\tnewlineIndex = this.buffer.indexOf(\"\\n\");\n\t\t}\n\t}\n\n\tprivate onLine(line: string): void {\n\t\tlet message: { id?: unknown; result?: unknown; error?: unknown };\n\t\ttry {\n\t\t\tmessage = JSON.parse(line);\n\t\t} catch {\n\t\t\t// Non-JSON noise on stdout (shouldn't happen; logs go to stderr). Skip it\n\t\t\t// rather than corrupt id correlation.\n\t\t\treturn;\n\t\t}\n\t\tconst id = typeof message.id === \"number\" ? message.id : undefined;\n\t\tif (id === undefined) return;\n\t\tconst entry = this.pending.get(id);\n\t\tif (!entry) return;\n\t\tthis.pending.delete(id);\n\t\tclearTimeout(entry.timer);\n\t\tif (message.error !== undefined && message.error !== null) {\n\t\t\tentry.reject(new Error(`browsertools ${describeRpcError(message.error)}`));\n\t\t} else {\n\t\t\tentry.resolve(message.result);\n\t\t}\n\t}\n\n\t/** Reject all in-flight requests and mark the client dead. Idempotent. */\n\tprivate fail(error: Error): void {\n\t\tif (this.closed) return;\n\t\tthis.exitError = error;\n\t\tfor (const [, entry] of this.pending) {\n\t\t\tclearTimeout(entry.timer);\n\t\t\tentry.reject(error);\n\t\t}\n\t\tthis.pending.clear();\n\t}\n\n\t/** Send a JSON-RPC request and resolve with its `result` (or reject on `error`). */\n\trequest<T = unknown>(method: string, params: Record<string, unknown>): Promise<T> {\n\t\tif (this.closed) {\n\t\t\treturn Promise.reject(this.exitError ?? new Error(\"browsertools serve client is closed\"));\n\t\t}\n\t\tconst id = this.nextId++;\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tif (this.pending.delete(id)) {\n\t\t\t\t\treject(new Error(`browsertools ${method} timed out after ${this.requestTimeoutMs}ms`));\n\t\t\t\t}\n\t\t\t}, this.requestTimeoutMs);\n\t\t\tthis.pending.set(id, { resolve: resolve as (v: unknown) => void, reject, timer });\n\t\t\tconst payload = `${JSON.stringify({ id, method, params })}\\n`;\n\t\t\tthis.proc.stdin?.write(payload, (err) => {\n\t\t\t\tif (err && this.pending.delete(id)) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\treject(err);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/** Kill the serve process and reject any outstanding requests. Idempotent. */\n\tdispose(): void {\n\t\tif (this.closed) return;\n\t\tthis.fail(new Error(\"browsertools serve client disposed\"));\n\t\tthis.closed = true;\n\t\t// Best-effort graceful shutdown, then ensure the process is gone.\n\t\ttry {\n\t\t\tthis.proc.stdin?.write(`${JSON.stringify({ id: this.nextId++, method: \"shutdown\", params: {} })}\\n`);\n\t\t} catch {\n\t\t\t// stdin may already be closed; fall through to kill.\n\t\t}\n\t\tthis.proc.stdin?.end();\n\t\tthis.proc.kill(\"SIGTERM\");\n\t\tconst proc = this.proc;\n\t\tsetTimeout(() => {\n\t\t\tif (proc.exitCode === null && proc.signalCode === null) proc.kill(\"SIGKILL\");\n\t\t}, 3000).unref?.();\n\t}\n}\n\nfunction describeRpcError(error: unknown): string {\n\tif (error && typeof error === \"object\") {\n\t\tconst message = (error as { message?: unknown }).message;\n\t\tif (typeof message === \"string\" && message) return message;\n\t}\n\tif (typeof error === \"string\" && error) return error;\n\treturn `RPC error: ${JSON.stringify(error)}`;\n}\n\n// ============================================================================\n// Paused-session registry (process-wide, keyed by ResumeToken)\n// ============================================================================\n\ninterface PausedSession {\n\tclient: BrowsertoolsServeClient;\n\t/** Number of NeedsParent rounds yielded so far for this flow. */\n\trounds: number;\n\tidleTimer: ReturnType<typeof setTimeout>;\n\tidleTimeoutMs: number;\n\t/** Whether the browser was launched in headful mode for this session. */\n\theadful: boolean;\n\t/** Explicit browser path used for this session, if any. */\n\tbrowserPath?: string;\n}\n\nconst sessionRegistry = new Map<ResumeToken, PausedSession>();\n\n/**\n * Park a paused flow's live serve client under its resume token and arm the idle\n * reaper. Any previous entry for the token is disposed first.\n */\nexport function parkSession(\n\ttoken: ResumeToken,\n\tclient: BrowsertoolsServeClient,\n\trounds: number,\n\tidleTimeoutMs: number,\n\theadful = false,\n\tbrowserPath?: string,\n): void {\n\tconst existing = sessionRegistry.get(token);\n\tif (existing && existing.client !== client) {\n\t\tclearTimeout(existing.idleTimer);\n\t\texisting.client.dispose();\n\t}\n\tconst idleTimer = setTimeout(() => {\n\t\tconst session = sessionRegistry.get(token);\n\t\tif (session) {\n\t\t\tsessionRegistry.delete(token);\n\t\t\tsession.client.dispose();\n\t\t}\n\t}, idleTimeoutMs);\n\tidleTimer.unref?.();\n\tsessionRegistry.set(token, { client, rounds, idleTimer, idleTimeoutMs, headful, browserPath });\n}\n\n/**\n * Remove a paused session from the registry and return it, stopping its idle\n * timer. The caller now owns the client (to resume or dispose). Returns\n * undefined if the token is unknown (expired/reaped/already completed).\n */\nexport function takeSession(token: ResumeToken): PausedSession | undefined {\n\tconst session = sessionRegistry.get(token);\n\tif (!session) return undefined;\n\tclearTimeout(session.idleTimer);\n\tsessionRegistry.delete(token);\n\treturn session;\n}\n\n/** Dispose every parked session. Used on shutdown and in tests. */\nexport function disposeAllSessions(): void {\n\tfor (const [, session] of sessionRegistry) {\n\t\tclearTimeout(session.idleTimer);\n\t\tsession.client.dispose();\n\t}\n\tsessionRegistry.clear();\n\tdisposeIdleClient();\n}\n\n/** Number of currently parked sessions (for tests/diagnostics). */\nexport function pausedSessionCount(): number {\n\treturn sessionRegistry.size;\n}\n\n// ============================================================================\n// Shared idle client (one per session, reused across browser_run calls)\n// ============================================================================\n\n/** Configuration preserved from the original flow call so the idle client can\n * be matched and reused by a subsequent browser_run with the same settings. */\nexport interface BrowserClientConfig {\n\theadful: boolean;\n\tbrowserPath?: string;\n\tidleTimeoutMs: number;\n}\n\ninterface IdleClientEntry {\n\tclient: BrowsertoolsServeClient;\n\theadful: boolean;\n\tbrowserPath?: string;\n\tidleTimer: ReturnType<typeof setTimeout>;\n}\n\nlet sharedIdleClient: IdleClientEntry | null = null;\n\n/**\n * Try to reclaim the shared idle client if its browser config matches.\n * Returns the live client (and clears the slot) on match, or null.\n */\nexport function takeIdleClient(\n\theadful: boolean,\n\tbrowserPath?: string,\n\t_idleTimeoutMs: number = BROWSERTOOLS_DEFAULT_IDLE_MS,\n): BrowsertoolsServeClient | null {\n\tif (!sharedIdleClient) return null;\n\tclearTimeout(sharedIdleClient.idleTimer);\n\tif (sharedIdleClient.headful === headful && sharedIdleClient.browserPath === browserPath) {\n\t\tconst client = sharedIdleClient.client;\n\t\tsharedIdleClient = null;\n\t\treturn client;\n\t}\n\t// Config changed — dispose the stale idle client.\n\tsharedIdleClient.client.dispose();\n\tsharedIdleClient = null;\n\treturn null;\n}\n\n/**\n * Park a completed/failed flow's client as idle so the next browser_run call\n * can reuse the same Chromium process and live-view port.\n */\nexport function parkIdleClient(\n\tclient: BrowsertoolsServeClient,\n\theadful: boolean,\n\tbrowserPath?: string,\n\tidleTimeoutMs: number = BROWSERTOOLS_DEFAULT_IDLE_MS,\n): void {\n\tif (sharedIdleClient) {\n\t\tclearTimeout(sharedIdleClient.idleTimer);\n\t\tsharedIdleClient.client.dispose();\n\t}\n\tconst idleTimer = setTimeout(() => {\n\t\tif (sharedIdleClient?.client === client) {\n\t\t\tclient.dispose();\n\t\t\tsharedIdleClient = null;\n\t\t}\n\t}, idleTimeoutMs);\n\tidleTimer.unref?.();\n\tsharedIdleClient = { client, headful, browserPath, idleTimer };\n}\n\n/** Dispose the shared idle client. Called on session shutdown. */\nexport function disposeIdleClient(): void {\n\tif (sharedIdleClient) {\n\t\tclearTimeout(sharedIdleClient.idleTimer);\n\t\tsharedIdleClient.client.dispose();\n\t\tsharedIdleClient = null;\n\t}\n}\n\n/** Number of currently idle shared clients (0 or 1, for tests/diagnostics). */\nexport function idleClientCount(): number {\n\treturn sharedIdleClient ? 1 : 0;\n}\n"]}
@@ -1,335 +0,0 @@
1
- /**
2
- * Shared plumbing for the `browser_run` and `browser_continue` tools.
3
- *
4
- * Unlike `webtools` (one-shot fetch/search subprocesses), `browsertools` drives
5
- * a *stateful* parent-in-the-loop protocol: a single long-lived `browsertools
6
- * serve` process holds the live Chromium and the paused-flow state in memory,
7
- * and the parent (hoocode) talks to it over newline-delimited JSON-RPC on
8
- * stdin/stdout. A flow can suspend mid-replay with `Outcome::NeedsParent`,
9
- * yielding a typed `ParentRequest` + `ResumeToken`; the parent reasons about it
10
- * (often by looking at a screenshot) and calls `flow_resume(token, response)` to
11
- * continue. See https://github.com/kolisachint/browsertools (contract.rs).
12
- *
13
- * Because that single serve process must survive *between* the `browser_run`
14
- * call that starts the flow and the `browser_continue` call that answers a
15
- * `NeedsParent`, this module owns a process-wide {@link sessionRegistry} keyed by
16
- * `ResumeToken`. Each paused session keeps its serve client alive and is reaped
17
- * after an idle timeout so an abandoned flow never leaks a Chromium forever.
18
- *
19
- * This module owns:
20
- * - the persistent JSON-RPC serve client (id-correlated request/response),
21
- * - the locked contract types (mirrors browsertools `src/contract.rs`),
22
- * - the paused-session registry + lifecycle (idle reap, round cap, teardown),
23
- * - binary + browser-path resolution.
24
- */
25
- import { spawn } from "node:child_process";
26
- import { ensureTool } from "../../../utils/tools-manager.js";
27
- // ============================================================================
28
- // Configuration
29
- // ============================================================================
30
- /** Default per-request RPC timeout. Flow steps drive a real browser, so this is
31
- * generous relative to webtools' 15s. */
32
- export const BROWSERTOOLS_REQUEST_TIMEOUT_MS = 120_000;
33
- /** Default idle window a paused flow may sit in the registry before it is reaped
34
- * (killing its serve process + Chromium). Reset on every resume round. The
35
- * parent may reason / look at a screenshot / make other tool calls between
36
- * rounds, so this is minutes, not seconds. */
37
- export const BROWSERTOOLS_DEFAULT_IDLE_MS = 5 * 60 * 1000;
38
- /** Default hard cap on `NeedsParent` rounds for a single flow, bounding a runaway
39
- * suspend/resume loop. */
40
- export const BROWSERTOOLS_DEFAULT_MAX_ROUNDS = 12;
41
- function envNumber(name) {
42
- const raw = process.env[name];
43
- if (!raw)
44
- return undefined;
45
- const n = Number(raw);
46
- return Number.isFinite(n) && n > 0 ? n : undefined;
47
- }
48
- /** Resolve effective options from explicit overrides, then env, then defaults. */
49
- export function resolveBrowsertoolsOptions(options) {
50
- return {
51
- binaryPath: options?.binaryPath,
52
- browserPath: options?.browserPath ?? (process.env.HOOCODE_BROWSERTOOLS_BROWSER_PATH?.trim() || undefined),
53
- headful: options?.headful ?? false,
54
- liveView: options?.liveView ?? false,
55
- idleTimeoutMs: options?.idleTimeoutMs ?? envNumber("HOOCODE_BROWSERTOOLS_IDLE_MS") ?? BROWSERTOOLS_DEFAULT_IDLE_MS,
56
- maxParentRounds: options?.maxParentRounds ?? envNumber("HOOCODE_BROWSERTOOLS_MAX_ROUNDS") ?? BROWSERTOOLS_DEFAULT_MAX_ROUNDS,
57
- requestTimeoutMs: options?.requestTimeoutMs ??
58
- envNumber("HOOCODE_BROWSERTOOLS_REQUEST_TIMEOUT_MS") ??
59
- BROWSERTOOLS_REQUEST_TIMEOUT_MS,
60
- serveArgs: options?.serveArgs ?? [],
61
- };
62
- }
63
- const BINARY_MISSING_MESSAGE = "browsertools binary unavailable and could not be downloaded — the browser tools require the `browsertools` CLI on PATH or a published release for this platform";
64
- /** Resolve the `browsertools` binary path (explicit override, else download/PATH). */
65
- export async function resolveBrowsertoolsBinary(options) {
66
- if (options?.binaryPath)
67
- return options.binaryPath;
68
- const binaryPath = await ensureTool("browsertools", true);
69
- if (!binaryPath)
70
- throw new Error(BINARY_MISSING_MESSAGE);
71
- return binaryPath;
72
- }
73
- /**
74
- * A live `browsertools serve` process spoken to over newline-delimited JSON-RPC.
75
- *
76
- * Wire format (browsertools `src/serve.rs`):
77
- * request: `{ "id": <n>, "method": <string>, "params": <object> }\n`
78
- * response: `{ "id": <n>, "result": <value> }` or `{ "id": <n>, "error": <RpcError> }`\n
79
- *
80
- * Responses are correlated by `id`, so concurrent requests are safe, though the
81
- * tools drive it sequentially.
82
- */
83
- export class BrowsertoolsServeClient {
84
- /** URL of the live viewer once `live_view_start` has been issued for this
85
- * serve process, cached so a reused (reclaimed-idle) client does not start a
86
- * second viewer or auto-open another OS tab on the next browser_run call. */
87
- liveViewUrl;
88
- proc;
89
- pending = new Map();
90
- requestTimeoutMs;
91
- buffer = "";
92
- nextId = 1;
93
- closed = false;
94
- exitError;
95
- stderrTail = "";
96
- constructor(binaryPath, opts) {
97
- this.requestTimeoutMs = opts.requestTimeoutMs;
98
- // The exact CLI flag for the browser path is not part of the locked RPC
99
- // contract; v0.1.3 added a "configurable browser path". We forward it via
100
- // env vars the binary is likely to read. Passing extra env is harmless if
101
- // the binary ignores them, and centralizing it here makes it a one-line
102
- // change once the exact mechanism is confirmed.
103
- const env = { ...process.env };
104
- if (opts.browserPath) {
105
- env.BROWSERTOOLS_BROWSER_PATH = opts.browserPath;
106
- env.CHROME_PATH = opts.browserPath;
107
- }
108
- // Opt into a real on-screen Chromium window. The serve process reads this
109
- // in `Driver::launch`; harmless if an older binary ignores it.
110
- if (opts.headful) {
111
- env.BROWSERTOOLS_HEADFUL = "1";
112
- }
113
- // Run the serve process in the project cwd so relative flow paths and the
114
- // evidence store resolve the same way the user expects.
115
- this.proc = spawn(binaryPath, ["serve", ...opts.serveArgs], {
116
- cwd: opts.cwd,
117
- shell: false,
118
- stdio: ["pipe", "pipe", "pipe"],
119
- env,
120
- });
121
- this.proc.stdout?.setEncoding("utf8");
122
- this.proc.stdout?.on("data", (chunk) => this.onStdout(chunk));
123
- this.proc.stderr?.setEncoding("utf8");
124
- this.proc.stderr?.on("data", (chunk) => {
125
- // Keep only a bounded tail so a chatty serve can't grow unbounded; it is
126
- // surfaced in the error when the process dies unexpectedly.
127
- this.stderrTail = (this.stderrTail + chunk).slice(-4000);
128
- });
129
- this.proc.on("error", (err) => this.fail(err instanceof Error ? err : new Error(String(err))));
130
- this.proc.on("exit", (code, sig) => {
131
- if (this.closed)
132
- return;
133
- const detail = this.stderrTail.trim();
134
- this.fail(new Error(`browsertools serve exited unexpectedly (code=${code ?? "null"}, signal=${sig ?? "null"})` +
135
- (detail ? `: ${detail}` : "")));
136
- });
137
- }
138
- onStdout(chunk) {
139
- this.buffer += chunk;
140
- let newlineIndex = this.buffer.indexOf("\n");
141
- while (newlineIndex !== -1) {
142
- const line = this.buffer.slice(0, newlineIndex).trim();
143
- this.buffer = this.buffer.slice(newlineIndex + 1);
144
- if (line)
145
- this.onLine(line);
146
- newlineIndex = this.buffer.indexOf("\n");
147
- }
148
- }
149
- onLine(line) {
150
- let message;
151
- try {
152
- message = JSON.parse(line);
153
- }
154
- catch {
155
- // Non-JSON noise on stdout (shouldn't happen; logs go to stderr). Skip it
156
- // rather than corrupt id correlation.
157
- return;
158
- }
159
- const id = typeof message.id === "number" ? message.id : undefined;
160
- if (id === undefined)
161
- return;
162
- const entry = this.pending.get(id);
163
- if (!entry)
164
- return;
165
- this.pending.delete(id);
166
- clearTimeout(entry.timer);
167
- if (message.error !== undefined && message.error !== null) {
168
- entry.reject(new Error(`browsertools ${describeRpcError(message.error)}`));
169
- }
170
- else {
171
- entry.resolve(message.result);
172
- }
173
- }
174
- /** Reject all in-flight requests and mark the client dead. Idempotent. */
175
- fail(error) {
176
- if (this.closed)
177
- return;
178
- this.exitError = error;
179
- for (const [, entry] of this.pending) {
180
- clearTimeout(entry.timer);
181
- entry.reject(error);
182
- }
183
- this.pending.clear();
184
- }
185
- /** Send a JSON-RPC request and resolve with its `result` (or reject on `error`). */
186
- request(method, params) {
187
- if (this.closed) {
188
- return Promise.reject(this.exitError ?? new Error("browsertools serve client is closed"));
189
- }
190
- const id = this.nextId++;
191
- return new Promise((resolve, reject) => {
192
- const timer = setTimeout(() => {
193
- if (this.pending.delete(id)) {
194
- reject(new Error(`browsertools ${method} timed out after ${this.requestTimeoutMs}ms`));
195
- }
196
- }, this.requestTimeoutMs);
197
- this.pending.set(id, { resolve: resolve, reject, timer });
198
- const payload = `${JSON.stringify({ id, method, params })}\n`;
199
- this.proc.stdin?.write(payload, (err) => {
200
- if (err && this.pending.delete(id)) {
201
- clearTimeout(timer);
202
- reject(err);
203
- }
204
- });
205
- });
206
- }
207
- /** Kill the serve process and reject any outstanding requests. Idempotent. */
208
- dispose() {
209
- if (this.closed)
210
- return;
211
- this.fail(new Error("browsertools serve client disposed"));
212
- this.closed = true;
213
- // Best-effort graceful shutdown, then ensure the process is gone.
214
- try {
215
- this.proc.stdin?.write(`${JSON.stringify({ id: this.nextId++, method: "shutdown", params: {} })}\n`);
216
- }
217
- catch {
218
- // stdin may already be closed; fall through to kill.
219
- }
220
- this.proc.stdin?.end();
221
- this.proc.kill("SIGTERM");
222
- const proc = this.proc;
223
- setTimeout(() => {
224
- if (proc.exitCode === null && proc.signalCode === null)
225
- proc.kill("SIGKILL");
226
- }, 3000).unref?.();
227
- }
228
- }
229
- function describeRpcError(error) {
230
- if (error && typeof error === "object") {
231
- const message = error.message;
232
- if (typeof message === "string" && message)
233
- return message;
234
- }
235
- if (typeof error === "string" && error)
236
- return error;
237
- return `RPC error: ${JSON.stringify(error)}`;
238
- }
239
- const sessionRegistry = new Map();
240
- /**
241
- * Park a paused flow's live serve client under its resume token and arm the idle
242
- * reaper. Any previous entry for the token is disposed first.
243
- */
244
- export function parkSession(token, client, rounds, idleTimeoutMs, headful = false, browserPath) {
245
- const existing = sessionRegistry.get(token);
246
- if (existing && existing.client !== client) {
247
- clearTimeout(existing.idleTimer);
248
- existing.client.dispose();
249
- }
250
- const idleTimer = setTimeout(() => {
251
- const session = sessionRegistry.get(token);
252
- if (session) {
253
- sessionRegistry.delete(token);
254
- session.client.dispose();
255
- }
256
- }, idleTimeoutMs);
257
- idleTimer.unref?.();
258
- sessionRegistry.set(token, { client, rounds, idleTimer, idleTimeoutMs, headful, browserPath });
259
- }
260
- /**
261
- * Remove a paused session from the registry and return it, stopping its idle
262
- * timer. The caller now owns the client (to resume or dispose). Returns
263
- * undefined if the token is unknown (expired/reaped/already completed).
264
- */
265
- export function takeSession(token) {
266
- const session = sessionRegistry.get(token);
267
- if (!session)
268
- return undefined;
269
- clearTimeout(session.idleTimer);
270
- sessionRegistry.delete(token);
271
- return session;
272
- }
273
- /** Dispose every parked session. Used on shutdown and in tests. */
274
- export function disposeAllSessions() {
275
- for (const [, session] of sessionRegistry) {
276
- clearTimeout(session.idleTimer);
277
- session.client.dispose();
278
- }
279
- sessionRegistry.clear();
280
- disposeIdleClient();
281
- }
282
- /** Number of currently parked sessions (for tests/diagnostics). */
283
- export function pausedSessionCount() {
284
- return sessionRegistry.size;
285
- }
286
- let sharedIdleClient = null;
287
- /**
288
- * Try to reclaim the shared idle client if its browser config matches.
289
- * Returns the live client (and clears the slot) on match, or null.
290
- */
291
- export function takeIdleClient(headful, browserPath, _idleTimeoutMs = BROWSERTOOLS_DEFAULT_IDLE_MS) {
292
- if (!sharedIdleClient)
293
- return null;
294
- clearTimeout(sharedIdleClient.idleTimer);
295
- if (sharedIdleClient.headful === headful && sharedIdleClient.browserPath === browserPath) {
296
- const client = sharedIdleClient.client;
297
- sharedIdleClient = null;
298
- return client;
299
- }
300
- // Config changed — dispose the stale idle client.
301
- sharedIdleClient.client.dispose();
302
- sharedIdleClient = null;
303
- return null;
304
- }
305
- /**
306
- * Park a completed/failed flow's client as idle so the next browser_run call
307
- * can reuse the same Chromium process and live-view port.
308
- */
309
- export function parkIdleClient(client, headful, browserPath, idleTimeoutMs = BROWSERTOOLS_DEFAULT_IDLE_MS) {
310
- if (sharedIdleClient) {
311
- clearTimeout(sharedIdleClient.idleTimer);
312
- sharedIdleClient.client.dispose();
313
- }
314
- const idleTimer = setTimeout(() => {
315
- if (sharedIdleClient?.client === client) {
316
- client.dispose();
317
- sharedIdleClient = null;
318
- }
319
- }, idleTimeoutMs);
320
- idleTimer.unref?.();
321
- sharedIdleClient = { client, headful, browserPath, idleTimer };
322
- }
323
- /** Dispose the shared idle client. Called on session shutdown. */
324
- export function disposeIdleClient() {
325
- if (sharedIdleClient) {
326
- clearTimeout(sharedIdleClient.idleTimer);
327
- sharedIdleClient.client.dispose();
328
- sharedIdleClient = null;
329
- }
330
- }
331
- /** Number of currently idle shared clients (0 or 1, for tests/diagnostics). */
332
- export function idleClientCount() {
333
- return sharedIdleClient ? 1 : 0;
334
- }
335
- //# sourceMappingURL=browsertools-shared.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browsertools-shared.js","sourceRoot":"","sources":["../../../../src/core/tools/browser/browsertools-shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAsC7D,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E;0CAC0C;AAC1C,MAAM,CAAC,MAAM,+BAA+B,GAAG,OAAO,CAAC;AAEvD;;;+CAG+C;AAC/C,MA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I,gBAAgB,EAAE,CAAC;QACtB,YAAY,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACzC,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAClC,gBAAgB,GAAG,IAAI,CAAC;IACzB,CAAC;AAAA,CACD;AAED,+EAA+E;AAC/E,MAAM,UAAU,eAAe,GAAW;IACzC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAAA,CAChC","sourcesContent":["/**\n * Shared plumbing for the `browser_run` and `browser_continue` tools.\n *\n * Unlike `webtools` (one-shot fetch/search subprocesses), `browsertools` drives\n * a *stateful* parent-in-the-loop protocol: a single long-lived `browsertools\n * serve` process holds the live Chromium and the paused-flow state in memory,\n * and the parent (hoocode) talks to it over newline-delimited JSON-RPC on\n * stdin/stdout. A flow can suspend mid-replay with `Outcome::NeedsParent`,\n * yielding a typed `ParentRequest` + `ResumeToken`; the parent reasons about it\n * (often by looking at a screenshot) and calls `flow_resume(token, response)` to\n * continue. See https://github.com/kolisachint/browsertools (contract.rs).\n *\n * Because that single serve process must survive *between* the `browser_run`\n * call that starts the flow and the `browser_continue` call that answers a\n * `NeedsParent`, this module owns a process-wide {@link sessionRegistry} keyed by\n * `ResumeToken`. Each paused session keeps its serve client alive and is reaped\n * after an idle timeout so an abandoned flow never leaks a Chromium forever.\n *\n * This module owns:\n * - the persistent JSON-RPC serve client (id-correlated request/response),\n * - the locked contract types (mirrors browsertools `src/contract.rs`),\n * - the paused-session registry + lifecycle (idle reap, round cap, teardown),\n * - binary + browser-path resolution.\n */\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport { ensureTool } from \"../../../utils/tools-manager.js\";\n\n// ============================================================================\n// Contract types (locked against browsertools `src/contract.rs`)\n// ============================================================================\n\n/** Opaque token identifying a paused flow, returned with every `NeedsParent`. */\nexport type ResumeToken = string;\n\n/** Reference to bytes (e.g. a screenshot) the parent can fetch via `get_resource`. */\nexport type ResourceId = string;\n\n/**\n * A typed request the engine yields when replay hits ambiguity only an LLM can\n * resolve. The `request` discriminant matches the serde tag in contract.rs.\n * Fields beyond the discriminant are passed through verbatim to the model.\n */\nexport interface ParentRequest {\n\trequest: \"classify_state\" | \"verify_visual\" | \"extract_semantic\" | \"decide_next_action\" | \"reidentify_element\";\n\t/** Resource id of the screenshot captured at the suspension point, if any. */\n\tscreenshot_ref?: ResourceId;\n\t[key: string]: unknown;\n}\n\n/** Result of a `flow_start` / `flow_resume` RPC (the `result` field's `outcome`). */\nexport type FlowOutcome =\n\t| { outcome: \"complete\"; result?: unknown }\n\t| { outcome: \"needs_parent\"; request: ParentRequest; token: ResumeToken }\n\t| { outcome: \"failed\"; step_id?: string; kind?: string; detail?: string };\n\n/** Result of a `get_resource` RPC. */\nexport interface GetResourceResult {\n\tref: ResourceId;\n\tmime: string;\n\tlen: number;\n\tpng_base64: string;\n}\n\n// ============================================================================\n// Configuration\n// ============================================================================\n\n/** Default per-request RPC timeout. Flow steps drive a real browser, so this is\n * generous relative to webtools' 15s. */\nexport const BROWSERTOOLS_REQUEST_TIMEOUT_MS = 120_000;\n\n/** Default idle window a paused flow may sit in the registry before it is reaped\n * (killing its serve process + Chromium). Reset on every resume round. The\n * parent may reason / look at a screenshot / make other tool calls between\n * rounds, so this is minutes, not seconds. */\nexport const BROWSERTOOLS_DEFAULT_IDLE_MS = 5 * 60 * 1000;\n\n/** Default hard cap on `NeedsParent` rounds for a single flow, bounding a runaway\n * suspend/resume loop. */\nexport const BROWSERTOOLS_DEFAULT_MAX_ROUNDS = 12;\n\n/** Options threaded into the browser tools by their factories (tests/overrides). */\nexport interface BrowsertoolsToolOptions {\n\t/** Explicit path to the `browsertools` binary; otherwise resolved via {@link ensureTool}. */\n\tbinaryPath?: string;\n\t/** Chromium/Chrome executable path forwarded to the serve process. */\n\tbrowserPath?: string;\n\t/** Idle reap window for paused sessions (ms). */\n\tidleTimeoutMs?: number;\n\t/** Hard cap on NeedsParent rounds per flow. */\n\tmaxParentRounds?: number;\n\t/** Per-request RPC timeout (ms). */\n\trequestTimeoutMs?: number;\n\t/** Extra args appended after `serve` (mainly for tests). */\n\tserveArgs?: string[];\n\t/** Launch a real on-screen Chromium window instead of headless (sets\n\t * `BROWSERTOOLS_HEADFUL=1` on the serve process). */\n\theadful?: boolean;\n\t/** Default the streamed live viewer on for every flow (the per-call `live_view`\n\t * param still overrides). Set by the --enable-browser-live-preview flag. */\n\tliveView?: boolean;\n}\n\nfunction envNumber(name: string): number | undefined {\n\tconst raw = process.env[name];\n\tif (!raw) return undefined;\n\tconst n = Number(raw);\n\treturn Number.isFinite(n) && n > 0 ? n : undefined;\n}\n\n/** Resolve effective options from explicit overrides, then env, then defaults. */\nexport function resolveBrowsertoolsOptions(options?: BrowsertoolsToolOptions): Required<\n\tPick<BrowsertoolsToolOptions, \"idleTimeoutMs\" | \"maxParentRounds\" | \"requestTimeoutMs\">\n> & {\n\tbinaryPath?: string;\n\tbrowserPath?: string;\n\tserveArgs: string[];\n\theadful: boolean;\n\tliveView: boolean;\n} {\n\treturn {\n\t\tbinaryPath: options?.binaryPath,\n\t\tbrowserPath: options?.browserPath ?? (process.env.HOOCODE_BROWSERTOOLS_BROWSER_PATH?.trim() || undefined),\n\t\theadful: options?.headful ?? false,\n\t\tliveView: options?.liveView ?? false,\n\t\tidleTimeoutMs:\n\t\t\toptions?.idleTimeoutMs ?? envNumber(\"HOOCODE_BROWSERTOOLS_IDLE_MS\") ?? BROWSERTOOLS_DEFAULT_IDLE_MS,\n\t\tmaxParentRounds:\n\t\t\toptions?.maxParentRounds ?? envNumber(\"HOOCODE_BROWSERTOOLS_MAX_ROUNDS\") ?? BROWSERTOOLS_DEFAULT_MAX_ROUNDS,\n\t\trequestTimeoutMs:\n\t\t\toptions?.requestTimeoutMs ??\n\t\t\tenvNumber(\"HOOCODE_BROWSERTOOLS_REQUEST_TIMEOUT_MS\") ??\n\t\t\tBROWSERTOOLS_REQUEST_TIMEOUT_MS,\n\t\tserveArgs: options?.serveArgs ?? [],\n\t};\n}\n\nconst BINARY_MISSING_MESSAGE =\n\t\"browsertools binary unavailable and could not be downloaded — the browser tools require the `browsertools` CLI on PATH or a published release for this platform\";\n\n/** Resolve the `browsertools` binary path (explicit override, else download/PATH). */\nexport async function resolveBrowsertoolsBinary(options?: BrowsertoolsToolOptions): Promise<string> {\n\tif (options?.binaryPath) return options.binaryPath;\n\tconst binaryPath = await ensureTool(\"browsertools\", true);\n\tif (!binaryPath) throw new Error(BINARY_MISSING_MESSAGE);\n\treturn binaryPath;\n}\n\n// ============================================================================\n// Persistent JSON-RPC serve client\n// ============================================================================\n\ninterface PendingRequest {\n\tresolve: (value: unknown) => void;\n\treject: (error: Error) => void;\n\ttimer: ReturnType<typeof setTimeout>;\n}\n\n/**\n * A live `browsertools serve` process spoken to over newline-delimited JSON-RPC.\n *\n * Wire format (browsertools `src/serve.rs`):\n * request: `{ \"id\": <n>, \"method\": <string>, \"params\": <object> }\\n`\n * response: `{ \"id\": <n>, \"result\": <value> }` or `{ \"id\": <n>, \"error\": <RpcError> }`\\n\n *\n * Responses are correlated by `id`, so concurrent requests are safe, though the\n * tools drive it sequentially.\n */\nexport class BrowsertoolsServeClient {\n\t/** URL of the live viewer once `live_view_start` has been issued for this\n\t * serve process, cached so a reused (reclaimed-idle) client does not start a\n\t * second viewer or auto-open another OS tab on the next browser_run call. */\n\tliveViewUrl?: string;\n\tprivate readonly proc: ChildProcess;\n\tprivate readonly pending = new Map<number, PendingRequest>();\n\tprivate readonly requestTimeoutMs: number;\n\tprivate buffer = \"\";\n\tprivate nextId = 1;\n\tprivate closed = false;\n\tprivate exitError: Error | undefined;\n\tprivate stderrTail = \"\";\n\n\tconstructor(\n\t\tbinaryPath: string,\n\t\topts: {\n\t\t\tcwd?: string;\n\t\t\tbrowserPath?: string;\n\t\t\tserveArgs: string[];\n\t\t\trequestTimeoutMs: number;\n\t\t\theadful?: boolean;\n\t\t},\n\t) {\n\t\tthis.requestTimeoutMs = opts.requestTimeoutMs;\n\t\t// The exact CLI flag for the browser path is not part of the locked RPC\n\t\t// contract; v0.1.3 added a \"configurable browser path\". We forward it via\n\t\t// env vars the binary is likely to read. Passing extra env is harmless if\n\t\t// the binary ignores them, and centralizing it here makes it a one-line\n\t\t// change once the exact mechanism is confirmed.\n\t\tconst env = { ...process.env };\n\t\tif (opts.browserPath) {\n\t\t\tenv.BROWSERTOOLS_BROWSER_PATH = opts.browserPath;\n\t\t\tenv.CHROME_PATH = opts.browserPath;\n\t\t}\n\t\t// Opt into a real on-screen Chromium window. The serve process reads this\n\t\t// in `Driver::launch`; harmless if an older binary ignores it.\n\t\tif (opts.headful) {\n\t\t\tenv.BROWSERTOOLS_HEADFUL = \"1\";\n\t\t}\n\t\t// Run the serve process in the project cwd so relative flow paths and the\n\t\t// evidence store resolve the same way the user expects.\n\t\tthis.proc = spawn(binaryPath, [\"serve\", ...opts.serveArgs], {\n\t\t\tcwd: opts.cwd,\n\t\t\tshell: false,\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\tenv,\n\t\t});\n\t\tthis.proc.stdout?.setEncoding(\"utf8\");\n\t\tthis.proc.stdout?.on(\"data\", (chunk: string) => this.onStdout(chunk));\n\t\tthis.proc.stderr?.setEncoding(\"utf8\");\n\t\tthis.proc.stderr?.on(\"data\", (chunk: string) => {\n\t\t\t// Keep only a bounded tail so a chatty serve can't grow unbounded; it is\n\t\t\t// surfaced in the error when the process dies unexpectedly.\n\t\t\tthis.stderrTail = (this.stderrTail + chunk).slice(-4000);\n\t\t});\n\t\tthis.proc.on(\"error\", (err) => this.fail(err instanceof Error ? err : new Error(String(err))));\n\t\tthis.proc.on(\"exit\", (code, sig) => {\n\t\t\tif (this.closed) return;\n\t\t\tconst detail = this.stderrTail.trim();\n\t\t\tthis.fail(\n\t\t\t\tnew Error(\n\t\t\t\t\t`browsertools serve exited unexpectedly (code=${code ?? \"null\"}, signal=${sig ?? \"null\"})` +\n\t\t\t\t\t\t(detail ? `: ${detail}` : \"\"),\n\t\t\t\t),\n\t\t\t);\n\t\t});\n\t}\n\n\tprivate onStdout(chunk: string): void {\n\t\tthis.buffer += chunk;\n\t\tlet newlineIndex = this.buffer.indexOf(\"\\n\");\n\t\twhile (newlineIndex !== -1) {\n\t\t\tconst line = this.buffer.slice(0, newlineIndex).trim();\n\t\t\tthis.buffer = this.buffer.slice(newlineIndex + 1);\n\t\t\tif (line) this.onLine(line);\n\t\t\tnewlineIndex = this.buffer.indexOf(\"\\n\");\n\t\t}\n\t}\n\n\tprivate onLine(line: string): void {\n\t\tlet message: { id?: unknown; result?: unknown; error?: unknown };\n\t\ttry {\n\t\t\tmessage = JSON.parse(line);\n\t\t} catch {\n\t\t\t// Non-JSON noise on stdout (shouldn't happen; logs go to stderr). Skip it\n\t\t\t// rather than corrupt id correlation.\n\t\t\treturn;\n\t\t}\n\t\tconst id = typeof message.id === \"number\" ? message.id : undefined;\n\t\tif (id === undefined) return;\n\t\tconst entry = this.pending.get(id);\n\t\tif (!entry) return;\n\t\tthis.pending.delete(id);\n\t\tclearTimeout(entry.timer);\n\t\tif (message.error !== undefined && message.error !== null) {\n\t\t\tentry.reject(new Error(`browsertools ${describeRpcError(message.error)}`));\n\t\t} else {\n\t\t\tentry.resolve(message.result);\n\t\t}\n\t}\n\n\t/** Reject all in-flight requests and mark the client dead. Idempotent. */\n\tprivate fail(error: Error): void {\n\t\tif (this.closed) return;\n\t\tthis.exitError = error;\n\t\tfor (const [, entry] of this.pending) {\n\t\t\tclearTimeout(entry.timer);\n\t\t\tentry.reject(error);\n\t\t}\n\t\tthis.pending.clear();\n\t}\n\n\t/** Send a JSON-RPC request and resolve with its `result` (or reject on `error`). */\n\trequest<T = unknown>(method: string, params: Record<string, unknown>): Promise<T> {\n\t\tif (this.closed) {\n\t\t\treturn Promise.reject(this.exitError ?? new Error(\"browsertools serve client is closed\"));\n\t\t}\n\t\tconst id = this.nextId++;\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tif (this.pending.delete(id)) {\n\t\t\t\t\treject(new Error(`browsertools ${method} timed out after ${this.requestTimeoutMs}ms`));\n\t\t\t\t}\n\t\t\t}, this.requestTimeoutMs);\n\t\t\tthis.pending.set(id, { resolve: resolve as (v: unknown) => void, reject, timer });\n\t\t\tconst payload = `${JSON.stringify({ id, method, params })}\\n`;\n\t\t\tthis.proc.stdin?.write(payload, (err) => {\n\t\t\t\tif (err && this.pending.delete(id)) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\treject(err);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/** Kill the serve process and reject any outstanding requests. Idempotent. */\n\tdispose(): void {\n\t\tif (this.closed) return;\n\t\tthis.fail(new Error(\"browsertools serve client disposed\"));\n\t\tthis.closed = true;\n\t\t// Best-effort graceful shutdown, then ensure the process is gone.\n\t\ttry {\n\t\t\tthis.proc.stdin?.write(`${JSON.stringify({ id: this.nextId++, method: \"shutdown\", params: {} })}\\n`);\n\t\t} catch {\n\t\t\t// stdin may already be closed; fall through to kill.\n\t\t}\n\t\tthis.proc.stdin?.end();\n\t\tthis.proc.kill(\"SIGTERM\");\n\t\tconst proc = this.proc;\n\t\tsetTimeout(() => {\n\t\t\tif (proc.exitCode === null && proc.signalCode === null) proc.kill(\"SIGKILL\");\n\t\t}, 3000).unref?.();\n\t}\n}\n\nfunction describeRpcError(error: unknown): string {\n\tif (error && typeof error === \"object\") {\n\t\tconst message = (error as { message?: unknown }).message;\n\t\tif (typeof message === \"string\" && message) return message;\n\t}\n\tif (typeof error === \"string\" && error) return error;\n\treturn `RPC error: ${JSON.stringify(error)}`;\n}\n\n// ============================================================================\n// Paused-session registry (process-wide, keyed by ResumeToken)\n// ============================================================================\n\ninterface PausedSession {\n\tclient: BrowsertoolsServeClient;\n\t/** Number of NeedsParent rounds yielded so far for this flow. */\n\trounds: number;\n\tidleTimer: ReturnType<typeof setTimeout>;\n\tidleTimeoutMs: number;\n\t/** Whether the browser was launched in headful mode for this session. */\n\theadful: boolean;\n\t/** Explicit browser path used for this session, if any. */\n\tbrowserPath?: string;\n}\n\nconst sessionRegistry = new Map<ResumeToken, PausedSession>();\n\n/**\n * Park a paused flow's live serve client under its resume token and arm the idle\n * reaper. Any previous entry for the token is disposed first.\n */\nexport function parkSession(\n\ttoken: ResumeToken,\n\tclient: BrowsertoolsServeClient,\n\trounds: number,\n\tidleTimeoutMs: number,\n\theadful = false,\n\tbrowserPath?: string,\n): void {\n\tconst existing = sessionRegistry.get(token);\n\tif (existing && existing.client !== client) {\n\t\tclearTimeout(existing.idleTimer);\n\t\texisting.client.dispose();\n\t}\n\tconst idleTimer = setTimeout(() => {\n\t\tconst session = sessionRegistry.get(token);\n\t\tif (session) {\n\t\t\tsessionRegistry.delete(token);\n\t\t\tsession.client.dispose();\n\t\t}\n\t}, idleTimeoutMs);\n\tidleTimer.unref?.();\n\tsessionRegistry.set(token, { client, rounds, idleTimer, idleTimeoutMs, headful, browserPath });\n}\n\n/**\n * Remove a paused session from the registry and return it, stopping its idle\n * timer. The caller now owns the client (to resume or dispose). Returns\n * undefined if the token is unknown (expired/reaped/already completed).\n */\nexport function takeSession(token: ResumeToken): PausedSession | undefined {\n\tconst session = sessionRegistry.get(token);\n\tif (!session) return undefined;\n\tclearTimeout(session.idleTimer);\n\tsessionRegistry.delete(token);\n\treturn session;\n}\n\n/** Dispose every parked session. Used on shutdown and in tests. */\nexport function disposeAllSessions(): void {\n\tfor (const [, session] of sessionRegistry) {\n\t\tclearTimeout(session.idleTimer);\n\t\tsession.client.dispose();\n\t}\n\tsessionRegistry.clear();\n\tdisposeIdleClient();\n}\n\n/** Number of currently parked sessions (for tests/diagnostics). */\nexport function pausedSessionCount(): number {\n\treturn sessionRegistry.size;\n}\n\n// ============================================================================\n// Shared idle client (one per session, reused across browser_run calls)\n// ============================================================================\n\n/** Configuration preserved from the original flow call so the idle client can\n * be matched and reused by a subsequent browser_run with the same settings. */\nexport interface BrowserClientConfig {\n\theadful: boolean;\n\tbrowserPath?: string;\n\tidleTimeoutMs: number;\n}\n\ninterface IdleClientEntry {\n\tclient: BrowsertoolsServeClient;\n\theadful: boolean;\n\tbrowserPath?: string;\n\tidleTimer: ReturnType<typeof setTimeout>;\n}\n\nlet sharedIdleClient: IdleClientEntry | null = null;\n\n/**\n * Try to reclaim the shared idle client if its browser config matches.\n * Returns the live client (and clears the slot) on match, or null.\n */\nexport function takeIdleClient(\n\theadful: boolean,\n\tbrowserPath?: string,\n\t_idleTimeoutMs: number = BROWSERTOOLS_DEFAULT_IDLE_MS,\n): BrowsertoolsServeClient | null {\n\tif (!sharedIdleClient) return null;\n\tclearTimeout(sharedIdleClient.idleTimer);\n\tif (sharedIdleClient.headful === headful && sharedIdleClient.browserPath === browserPath) {\n\t\tconst client = sharedIdleClient.client;\n\t\tsharedIdleClient = null;\n\t\treturn client;\n\t}\n\t// Config changed — dispose the stale idle client.\n\tsharedIdleClient.client.dispose();\n\tsharedIdleClient = null;\n\treturn null;\n}\n\n/**\n * Park a completed/failed flow's client as idle so the next browser_run call\n * can reuse the same Chromium process and live-view port.\n */\nexport function parkIdleClient(\n\tclient: BrowsertoolsServeClient,\n\theadful: boolean,\n\tbrowserPath?: string,\n\tidleTimeoutMs: number = BROWSERTOOLS_DEFAULT_IDLE_MS,\n): void {\n\tif (sharedIdleClient) {\n\t\tclearTimeout(sharedIdleClient.idleTimer);\n\t\tsharedIdleClient.client.dispose();\n\t}\n\tconst idleTimer = setTimeout(() => {\n\t\tif (sharedIdleClient?.client === client) {\n\t\t\tclient.dispose();\n\t\t\tsharedIdleClient = null;\n\t\t}\n\t}, idleTimeoutMs);\n\tidleTimer.unref?.();\n\tsharedIdleClient = { client, headful, browserPath, idleTimer };\n}\n\n/** Dispose the shared idle client. Called on session shutdown. */\nexport function disposeIdleClient(): void {\n\tif (sharedIdleClient) {\n\t\tclearTimeout(sharedIdleClient.idleTimer);\n\t\tsharedIdleClient.client.dispose();\n\t\tsharedIdleClient = null;\n\t}\n}\n\n/** Number of currently idle shared clients (0 or 1, for tests/diagnostics). */\nexport function idleClientCount(): number {\n\treturn sharedIdleClient ? 1 : 0;\n}\n"]}