@agentrhq/webcmd 0.1.1 → 0.1.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 (415) hide show
  1. package/README.md +317 -24
  2. package/dist/src/adapter-shadow.d.ts +11 -0
  3. package/dist/src/adapter-shadow.js +72 -0
  4. package/dist/src/adapter-shadow.test.d.ts +1 -0
  5. package/dist/src/adapter-shadow.test.js +49 -0
  6. package/dist/src/adapter-source.d.ts +11 -0
  7. package/dist/src/adapter-source.js +24 -0
  8. package/dist/src/adapter-source.test.d.ts +1 -0
  9. package/dist/src/adapter-source.test.js +29 -0
  10. package/dist/src/brand.d.ts +9 -0
  11. package/dist/src/brand.js +9 -0
  12. package/dist/src/brand.test.d.ts +1 -0
  13. package/dist/src/brand.test.js +15 -0
  14. package/dist/src/browser/analyze.d.ts +118 -0
  15. package/dist/src/browser/analyze.js +405 -0
  16. package/dist/src/browser/analyze.test.d.ts +1 -0
  17. package/dist/src/browser/analyze.test.js +209 -0
  18. package/dist/src/browser/article-extract.d.ts +57 -0
  19. package/dist/src/browser/article-extract.e2e.test.d.ts +1 -0
  20. package/dist/src/browser/article-extract.e2e.test.js +105 -0
  21. package/dist/src/browser/article-extract.js +169 -0
  22. package/dist/src/browser/article-extract.test.d.ts +1 -0
  23. package/dist/src/browser/article-extract.test.js +94 -0
  24. package/dist/src/browser/ax-snapshot.d.ts +37 -0
  25. package/dist/src/browser/ax-snapshot.js +217 -0
  26. package/dist/src/browser/ax-snapshot.test.d.ts +1 -0
  27. package/dist/src/browser/ax-snapshot.test.js +91 -0
  28. package/dist/src/browser/base-page.d.ts +151 -0
  29. package/dist/src/browser/base-page.js +1060 -0
  30. package/dist/src/browser/base-page.test.d.ts +1 -0
  31. package/dist/src/browser/base-page.test.js +803 -0
  32. package/dist/src/browser/bridge-readiness.d.ts +14 -0
  33. package/dist/src/browser/bridge-readiness.js +24 -0
  34. package/dist/src/browser/bridge-readiness.test.d.ts +1 -0
  35. package/dist/src/browser/bridge-readiness.test.js +58 -0
  36. package/dist/src/browser/bridge.d.ts +26 -0
  37. package/dist/src/browser/bridge.js +58 -0
  38. package/dist/src/browser/cdp-click-fixture.test.d.ts +1 -0
  39. package/dist/src/browser/cdp-click-fixture.test.js +87 -0
  40. package/dist/src/browser/cdp.d.ts +46 -0
  41. package/dist/src/browser/cdp.js +536 -0
  42. package/dist/src/browser/cdp.test.d.ts +1 -0
  43. package/dist/src/browser/cdp.test.js +79 -0
  44. package/dist/src/browser/compound.d.ts +59 -0
  45. package/dist/src/browser/compound.js +112 -0
  46. package/dist/src/browser/compound.test.d.ts +1 -0
  47. package/dist/src/browser/compound.test.js +175 -0
  48. package/dist/src/browser/config.d.ts +2 -0
  49. package/dist/src/browser/config.js +14 -0
  50. package/dist/src/browser/daemon-client.d.ts +32 -0
  51. package/dist/src/browser/daemon-client.js +135 -0
  52. package/dist/src/browser/daemon-client.test.d.ts +1 -0
  53. package/dist/src/browser/daemon-client.test.js +326 -0
  54. package/dist/src/browser/daemon-lifecycle.d.ts +37 -0
  55. package/dist/src/browser/daemon-lifecycle.js +147 -0
  56. package/dist/src/browser/daemon-transport.d.ts +54 -0
  57. package/dist/src/browser/daemon-transport.js +68 -0
  58. package/dist/src/browser/daemon-version.d.ts +4 -0
  59. package/dist/src/browser/daemon-version.js +12 -0
  60. package/dist/src/browser/dom-helpers.d.ts +41 -0
  61. package/dist/src/browser/dom-helpers.js +239 -0
  62. package/dist/src/browser/dom-helpers.test.d.ts +1 -0
  63. package/dist/src/browser/dom-helpers.test.js +106 -0
  64. package/dist/src/browser/dom-snapshot.d.ts +93 -0
  65. package/dist/src/browser/dom-snapshot.js +894 -0
  66. package/dist/src/browser/dom-snapshot.test.d.ts +11 -0
  67. package/dist/src/browser/dom-snapshot.test.js +313 -0
  68. package/dist/src/browser/errors.d.ts +38 -0
  69. package/dist/src/browser/errors.js +79 -0
  70. package/dist/src/browser/errors.test.d.ts +1 -0
  71. package/dist/src/browser/errors.test.js +60 -0
  72. package/dist/src/browser/extract.d.ts +69 -0
  73. package/dist/src/browser/extract.js +132 -0
  74. package/dist/src/browser/extract.test.d.ts +1 -0
  75. package/dist/src/browser/extract.test.js +129 -0
  76. package/dist/src/browser/find.d.ts +84 -0
  77. package/dist/src/browser/find.js +398 -0
  78. package/dist/src/browser/find.test.d.ts +1 -0
  79. package/dist/src/browser/find.test.js +180 -0
  80. package/dist/src/browser/html-tree.d.ts +75 -0
  81. package/dist/src/browser/html-tree.js +112 -0
  82. package/dist/src/browser/html-tree.test.d.ts +1 -0
  83. package/dist/src/browser/html-tree.test.js +181 -0
  84. package/dist/src/browser/index.d.ts +14 -0
  85. package/dist/src/browser/index.js +12 -0
  86. package/dist/src/browser/network-cache.d.ts +49 -0
  87. package/dist/src/browser/network-cache.js +78 -0
  88. package/dist/src/browser/network-cache.test.d.ts +1 -0
  89. package/dist/src/browser/network-cache.test.js +75 -0
  90. package/dist/src/browser/network-interceptor.d.ts +11 -0
  91. package/dist/src/browser/network-interceptor.js +11 -0
  92. package/dist/src/browser/network-key.d.ts +22 -0
  93. package/dist/src/browser/network-key.js +66 -0
  94. package/dist/src/browser/network-key.test.d.ts +1 -0
  95. package/dist/src/browser/network-key.test.js +49 -0
  96. package/dist/src/browser/page.d.ts +83 -0
  97. package/dist/src/browser/page.js +453 -0
  98. package/dist/src/browser/page.test.d.ts +1 -0
  99. package/dist/src/browser/page.test.js +406 -0
  100. package/dist/src/browser/profile.d.ts +14 -0
  101. package/dist/src/browser/profile.js +86 -0
  102. package/dist/src/browser/protocol.d.ts +63 -0
  103. package/dist/src/browser/protocol.js +1 -0
  104. package/dist/src/browser/runtime/local-cloak/actions.d.ts +3 -0
  105. package/dist/src/browser/runtime/local-cloak/actions.js +240 -0
  106. package/dist/src/browser/runtime/local-cloak/downloads.d.ts +3 -0
  107. package/dist/src/browser/runtime/local-cloak/downloads.js +28 -0
  108. package/dist/src/browser/runtime/local-cloak/network.d.ts +28 -0
  109. package/dist/src/browser/runtime/local-cloak/network.js +120 -0
  110. package/dist/src/browser/runtime/local-cloak/network.test.d.ts +1 -0
  111. package/dist/src/browser/runtime/local-cloak/network.test.js +124 -0
  112. package/dist/src/browser/runtime/local-cloak/profiles.d.ts +6 -0
  113. package/dist/src/browser/runtime/local-cloak/profiles.js +17 -0
  114. package/dist/src/browser/runtime/local-cloak/profiles.test.d.ts +1 -0
  115. package/dist/src/browser/runtime/local-cloak/profiles.test.js +19 -0
  116. package/dist/src/browser/runtime/local-cloak/provider.d.ts +15 -0
  117. package/dist/src/browser/runtime/local-cloak/provider.js +27 -0
  118. package/dist/src/browser/runtime/local-cloak/provider.test.d.ts +1 -0
  119. package/dist/src/browser/runtime/local-cloak/provider.test.js +244 -0
  120. package/dist/src/browser/runtime/local-cloak/session-manager.d.ts +77 -0
  121. package/dist/src/browser/runtime/local-cloak/session-manager.js +280 -0
  122. package/dist/src/browser/runtime/local-cloak/session-manager.test.d.ts +1 -0
  123. package/dist/src/browser/runtime/local-cloak/session-manager.test.js +92 -0
  124. package/dist/src/browser/runtime/provider.d.ts +9 -0
  125. package/dist/src/browser/runtime/provider.js +1 -0
  126. package/dist/src/browser/runtime/provider.test.d.ts +2 -0
  127. package/dist/src/browser/runtime/provider.test.js +49 -0
  128. package/dist/src/browser/shape-filter.d.ts +52 -0
  129. package/dist/src/browser/shape-filter.js +101 -0
  130. package/dist/src/browser/shape-filter.test.d.ts +1 -0
  131. package/dist/src/browser/shape-filter.test.js +101 -0
  132. package/dist/src/browser/shape.d.ts +23 -0
  133. package/dist/src/browser/shape.js +95 -0
  134. package/dist/src/browser/shape.test.d.ts +1 -0
  135. package/dist/src/browser/shape.test.js +82 -0
  136. package/dist/src/browser/stealth.d.ts +11 -0
  137. package/dist/src/browser/stealth.js +359 -0
  138. package/dist/src/browser/stealth.test.d.ts +1 -0
  139. package/dist/src/browser/stealth.test.js +134 -0
  140. package/dist/src/browser/tabs.d.ts +13 -0
  141. package/dist/src/browser/tabs.js +70 -0
  142. package/dist/src/browser/target-errors.d.ts +39 -0
  143. package/dist/src/browser/target-errors.js +45 -0
  144. package/dist/src/browser/target-errors.test.d.ts +1 -0
  145. package/dist/src/browser/target-errors.test.js +94 -0
  146. package/dist/src/browser/target-resolver.d.ts +158 -0
  147. package/dist/src/browser/target-resolver.js +570 -0
  148. package/dist/src/browser/target-resolver.test.d.ts +1 -0
  149. package/dist/src/browser/target-resolver.test.js +118 -0
  150. package/dist/src/browser/utils.d.ts +20 -0
  151. package/dist/src/browser/utils.js +64 -0
  152. package/dist/src/browser/utils.test.d.ts +1 -0
  153. package/dist/src/browser/utils.test.js +29 -0
  154. package/dist/src/browser/verify-fixture.d.ts +65 -0
  155. package/dist/src/browser/verify-fixture.js +318 -0
  156. package/dist/src/browser/verify-fixture.test.d.ts +1 -0
  157. package/dist/src/browser/verify-fixture.test.js +219 -0
  158. package/dist/src/browser/visual-refs.d.ts +11 -0
  159. package/dist/src/browser/visual-refs.js +108 -0
  160. package/dist/src/browser.test.d.ts +1 -0
  161. package/dist/src/browser.test.js +297 -0
  162. package/dist/src/build-manifest.d.ts +103 -0
  163. package/dist/src/build-manifest.js +363 -0
  164. package/dist/src/build-manifest.test.d.ts +1 -0
  165. package/dist/src/build-manifest.test.js +341 -0
  166. package/dist/src/capabilityRouting.d.ts +19 -0
  167. package/dist/src/capabilityRouting.js +56 -0
  168. package/dist/src/capabilityRouting.test.d.ts +1 -0
  169. package/dist/src/capabilityRouting.test.js +63 -0
  170. package/dist/src/cli-argv-preprocess.d.ts +63 -0
  171. package/dist/src/cli-argv-preprocess.js +303 -0
  172. package/dist/src/cli-argv-preprocess.test.d.ts +1 -0
  173. package/dist/src/cli-argv-preprocess.test.js +304 -0
  174. package/dist/src/cli.d.ts +79 -0
  175. package/dist/src/cli.js +3350 -0
  176. package/dist/src/cli.test.d.ts +1 -0
  177. package/dist/src/cli.test.js +3041 -0
  178. package/dist/src/commanderAdapter.d.ts +21 -0
  179. package/dist/src/commanderAdapter.js +208 -0
  180. package/dist/src/commanderAdapter.test.d.ts +1 -0
  181. package/dist/src/commanderAdapter.test.js +352 -0
  182. package/dist/src/commands/auth.d.ts +40 -0
  183. package/dist/src/commands/auth.js +434 -0
  184. package/dist/src/commands/auth.test.d.ts +1 -0
  185. package/dist/src/commands/auth.test.js +252 -0
  186. package/dist/src/commands/daemon.d.ts +9 -0
  187. package/dist/src/commands/daemon.js +91 -0
  188. package/dist/src/commands/daemon.test.d.ts +1 -0
  189. package/dist/src/commands/daemon.test.js +293 -0
  190. package/dist/src/completion-fast.d.ts +22 -0
  191. package/dist/src/completion-fast.js +88 -0
  192. package/dist/src/completion-shared.d.ts +13 -0
  193. package/dist/src/completion-shared.js +61 -0
  194. package/dist/src/completion.d.ts +21 -0
  195. package/dist/src/completion.js +68 -0
  196. package/dist/src/completion.test.d.ts +1 -0
  197. package/dist/src/completion.test.js +24 -0
  198. package/dist/src/constants.d.ts +18 -0
  199. package/dist/src/constants.js +41 -0
  200. package/dist/src/convention-audit.d.ts +50 -0
  201. package/dist/src/convention-audit.js +553 -0
  202. package/dist/src/convention-audit.test.d.ts +1 -0
  203. package/dist/src/convention-audit.test.js +255 -0
  204. package/dist/src/daemon/server.d.ts +13 -0
  205. package/dist/src/daemon/server.js +185 -0
  206. package/dist/src/daemon/server.test.d.ts +1 -0
  207. package/dist/src/daemon/server.test.js +132 -0
  208. package/dist/src/daemon-utils.d.ts +18 -0
  209. package/dist/src/daemon-utils.js +37 -0
  210. package/dist/src/daemon.d.ts +1 -0
  211. package/dist/src/daemon.js +27 -0
  212. package/dist/src/daemon.test.d.ts +1 -0
  213. package/dist/src/daemon.test.js +60 -0
  214. package/dist/src/discovery.d.ts +46 -0
  215. package/dist/src/discovery.js +341 -0
  216. package/dist/src/doctor.d.ts +39 -0
  217. package/dist/src/doctor.js +168 -0
  218. package/dist/src/doctor.test.d.ts +1 -0
  219. package/dist/src/doctor.test.js +302 -0
  220. package/dist/src/download/article-download.d.ts +72 -0
  221. package/dist/src/download/article-download.js +305 -0
  222. package/dist/src/download/article-download.test.d.ts +1 -0
  223. package/dist/src/download/article-download.test.js +235 -0
  224. package/dist/src/download/index.d.ts +71 -0
  225. package/dist/src/download/index.js +363 -0
  226. package/dist/src/download/index.test.d.ts +1 -0
  227. package/dist/src/download/index.test.js +174 -0
  228. package/dist/src/download/media-download.d.ts +49 -0
  229. package/dist/src/download/media-download.js +127 -0
  230. package/dist/src/download/media-download.test.d.ts +1 -0
  231. package/dist/src/download/media-download.test.js +112 -0
  232. package/dist/src/download/progress.d.ts +36 -0
  233. package/dist/src/download/progress.js +120 -0
  234. package/dist/src/download/progress.test.d.ts +1 -0
  235. package/dist/src/download/progress.test.js +36 -0
  236. package/dist/src/electron-apps.d.ts +31 -0
  237. package/dist/src/electron-apps.js +91 -0
  238. package/dist/src/electron-apps.test.d.ts +1 -0
  239. package/dist/src/electron-apps.test.js +76 -0
  240. package/dist/src/engine.test.d.ts +1 -0
  241. package/dist/src/engine.test.js +312 -0
  242. package/dist/src/errors.d.ts +114 -0
  243. package/dist/src/errors.js +174 -0
  244. package/dist/src/errors.test.d.ts +1 -0
  245. package/dist/src/errors.test.js +109 -0
  246. package/dist/src/execution.d.ts +24 -0
  247. package/dist/src/execution.js +509 -0
  248. package/dist/src/execution.test.d.ts +1 -0
  249. package/dist/src/execution.test.js +645 -0
  250. package/dist/src/external.d.ts +49 -0
  251. package/dist/src/external.js +211 -0
  252. package/dist/src/external.test.d.ts +1 -0
  253. package/dist/src/external.test.js +110 -0
  254. package/dist/src/help.d.ts +88 -0
  255. package/dist/src/help.js +556 -0
  256. package/dist/src/help.test.d.ts +1 -0
  257. package/dist/src/help.test.js +58 -0
  258. package/dist/src/hooks.d.ts +46 -0
  259. package/dist/src/hooks.js +58 -0
  260. package/dist/src/hooks.test.d.ts +4 -0
  261. package/dist/src/hooks.test.js +92 -0
  262. package/dist/src/interceptor.d.ts +44 -0
  263. package/dist/src/interceptor.js +183 -0
  264. package/dist/src/interceptor.test.d.ts +4 -0
  265. package/dist/src/interceptor.test.js +81 -0
  266. package/dist/src/launcher.d.ts +41 -0
  267. package/dist/src/launcher.js +226 -0
  268. package/dist/src/launcher.test.d.ts +1 -0
  269. package/dist/src/launcher.test.js +153 -0
  270. package/dist/src/logger.d.ts +26 -0
  271. package/dist/src/logger.js +49 -0
  272. package/dist/src/main.d.ts +5 -0
  273. package/dist/src/main.js +177 -0
  274. package/dist/src/manifest-types.d.ts +43 -0
  275. package/dist/src/manifest-types.js +9 -0
  276. package/dist/src/node-network.d.ts +10 -0
  277. package/dist/src/node-network.js +174 -0
  278. package/dist/src/node-network.test.d.ts +1 -0
  279. package/dist/src/node-network.test.js +55 -0
  280. package/dist/src/observation/artifact.d.ts +16 -0
  281. package/dist/src/observation/artifact.js +260 -0
  282. package/dist/src/observation/artifact.test.d.ts +1 -0
  283. package/dist/src/observation/artifact.test.js +121 -0
  284. package/dist/src/observation/events.d.ts +89 -0
  285. package/dist/src/observation/events.js +1 -0
  286. package/dist/src/observation/index.d.ts +7 -0
  287. package/dist/src/observation/index.js +7 -0
  288. package/dist/src/observation/manager.d.ts +9 -0
  289. package/dist/src/observation/manager.js +27 -0
  290. package/dist/src/observation/manager.test.d.ts +1 -0
  291. package/dist/src/observation/manager.test.js +13 -0
  292. package/dist/src/observation/redaction.d.ts +11 -0
  293. package/dist/src/observation/redaction.js +81 -0
  294. package/dist/src/observation/redaction.test.d.ts +1 -0
  295. package/dist/src/observation/redaction.test.js +32 -0
  296. package/dist/src/observation/retention.d.ts +32 -0
  297. package/dist/src/observation/retention.js +160 -0
  298. package/dist/src/observation/retention.test.d.ts +1 -0
  299. package/dist/src/observation/retention.test.js +118 -0
  300. package/dist/src/observation/ring-buffer.d.ts +22 -0
  301. package/dist/src/observation/ring-buffer.js +45 -0
  302. package/dist/src/observation/ring-buffer.test.d.ts +1 -0
  303. package/dist/src/observation/ring-buffer.test.js +22 -0
  304. package/dist/src/observation/session.d.ts +25 -0
  305. package/dist/src/observation/session.js +50 -0
  306. package/dist/src/output.d.ts +14 -0
  307. package/dist/src/output.js +152 -0
  308. package/dist/src/output.test.d.ts +1 -0
  309. package/dist/src/output.test.js +53 -0
  310. package/dist/src/package-exports.test.d.ts +1 -0
  311. package/dist/src/package-exports.test.js +112 -0
  312. package/dist/src/package-paths.d.ts +8 -0
  313. package/dist/src/package-paths.js +41 -0
  314. package/dist/src/pipeline/executor.d.ts +11 -0
  315. package/dist/src/pipeline/executor.js +93 -0
  316. package/dist/src/pipeline/executor.test.d.ts +4 -0
  317. package/dist/src/pipeline/executor.test.js +182 -0
  318. package/dist/src/pipeline/index.d.ts +5 -0
  319. package/dist/src/pipeline/index.js +5 -0
  320. package/dist/src/pipeline/registry.d.ts +28 -0
  321. package/dist/src/pipeline/registry.js +55 -0
  322. package/dist/src/pipeline/steps/browser.d.ts +13 -0
  323. package/dist/src/pipeline/steps/browser.js +86 -0
  324. package/dist/src/pipeline/steps/download.d.ts +18 -0
  325. package/dist/src/pipeline/steps/download.js +252 -0
  326. package/dist/src/pipeline/steps/download.test.d.ts +1 -0
  327. package/dist/src/pipeline/steps/download.test.js +102 -0
  328. package/dist/src/pipeline/steps/fetch.d.ts +5 -0
  329. package/dist/src/pipeline/steps/fetch.js +122 -0
  330. package/dist/src/pipeline/steps/fetch.test.d.ts +1 -0
  331. package/dist/src/pipeline/steps/fetch.test.js +117 -0
  332. package/dist/src/pipeline/steps/intercept.d.ts +5 -0
  333. package/dist/src/pipeline/steps/intercept.js +50 -0
  334. package/dist/src/pipeline/steps/tap.d.ts +12 -0
  335. package/dist/src/pipeline/steps/tap.js +93 -0
  336. package/dist/src/pipeline/steps/transform.d.ts +9 -0
  337. package/dist/src/pipeline/steps/transform.js +70 -0
  338. package/dist/src/pipeline/template.d.ts +17 -0
  339. package/dist/src/pipeline/template.js +344 -0
  340. package/dist/src/pipeline/template.test.d.ts +4 -0
  341. package/dist/src/pipeline/template.test.js +197 -0
  342. package/dist/src/pipeline/transform.test.d.ts +4 -0
  343. package/dist/src/pipeline/transform.test.js +133 -0
  344. package/dist/src/plugin-manifest.d.ts +70 -0
  345. package/dist/src/plugin-manifest.js +160 -0
  346. package/dist/src/plugin-manifest.test.d.ts +4 -0
  347. package/dist/src/plugin-manifest.test.js +179 -0
  348. package/dist/src/plugin-scaffold.d.ts +28 -0
  349. package/dist/src/plugin-scaffold.js +143 -0
  350. package/dist/src/plugin-scaffold.test.d.ts +4 -0
  351. package/dist/src/plugin-scaffold.test.js +83 -0
  352. package/dist/src/plugin.d.ts +146 -0
  353. package/dist/src/plugin.js +1303 -0
  354. package/dist/src/plugin.test.d.ts +4 -0
  355. package/dist/src/plugin.test.js +1363 -0
  356. package/dist/src/registry-api.d.ts +13 -0
  357. package/dist/src/registry-api.js +10 -0
  358. package/dist/src/registry.d.ts +123 -0
  359. package/dist/src/registry.js +125 -0
  360. package/dist/src/registry.test.d.ts +4 -0
  361. package/dist/src/registry.test.js +209 -0
  362. package/dist/src/runtime-copy.test.d.ts +1 -0
  363. package/dist/src/runtime-copy.test.js +29 -0
  364. package/dist/src/runtime-detect.d.ts +31 -0
  365. package/dist/src/runtime-detect.js +47 -0
  366. package/dist/src/runtime-detect.test.d.ts +1 -0
  367. package/dist/src/runtime-detect.test.js +39 -0
  368. package/dist/src/runtime-identity.test.d.ts +1 -0
  369. package/dist/src/runtime-identity.test.js +18 -0
  370. package/dist/src/runtime.d.ts +47 -0
  371. package/dist/src/runtime.js +54 -0
  372. package/dist/src/scripts/framework.d.ts +7 -0
  373. package/dist/src/scripts/framework.js +25 -0
  374. package/dist/src/scripts/interact.d.ts +4 -0
  375. package/dist/src/scripts/interact.js +20 -0
  376. package/dist/src/scripts/store.d.ts +13 -0
  377. package/dist/src/scripts/store.js +48 -0
  378. package/dist/src/serialization.d.ts +42 -0
  379. package/dist/src/serialization.js +103 -0
  380. package/dist/src/serialization.test.d.ts +1 -0
  381. package/dist/src/serialization.test.js +78 -0
  382. package/dist/src/skills.d.ts +14 -0
  383. package/dist/src/skills.js +127 -0
  384. package/dist/src/skills.test.d.ts +1 -0
  385. package/dist/src/skills.test.js +71 -0
  386. package/dist/src/snapshotFormatter.d.ts +11 -0
  387. package/dist/src/snapshotFormatter.js +338 -0
  388. package/dist/src/snapshotFormatter.test.d.ts +7 -0
  389. package/dist/src/snapshotFormatter.test.js +521 -0
  390. package/dist/src/tui.d.ts +28 -0
  391. package/dist/src/tui.js +179 -0
  392. package/dist/src/tui.test.d.ts +1 -0
  393. package/dist/src/tui.test.js +19 -0
  394. package/dist/src/types.d.ts +236 -0
  395. package/dist/src/types.js +7 -0
  396. package/dist/src/update-check.d.ts +66 -0
  397. package/dist/src/update-check.js +206 -0
  398. package/dist/src/update-check.test.d.ts +1 -0
  399. package/dist/src/update-check.test.js +117 -0
  400. package/dist/src/utils.d.ts +57 -0
  401. package/dist/src/utils.js +152 -0
  402. package/dist/src/utils.test.d.ts +1 -0
  403. package/dist/src/utils.test.js +155 -0
  404. package/dist/src/validate.d.ts +21 -0
  405. package/dist/src/validate.js +130 -0
  406. package/dist/src/validate.test.d.ts +9 -0
  407. package/dist/src/validate.test.js +90 -0
  408. package/dist/src/verify.d.ts +26 -0
  409. package/dist/src/verify.js +67 -0
  410. package/dist/src/version.d.ts +4 -0
  411. package/dist/src/version.js +22 -0
  412. package/dist/src/weixin-download.test.d.ts +1 -0
  413. package/dist/src/weixin-download.test.js +45 -0
  414. package/package.json +4 -3
  415. package/scripts/check-package-bin.mjs +95 -0
@@ -0,0 +1,359 @@
1
+ /**
2
+ * Stealth anti-detection module.
3
+ *
4
+ * Generates JS code that patches browser globals to hide automation
5
+ * fingerprints (e.g. navigator.webdriver, missing chrome object, empty
6
+ * plugin list). Injected before page scripts run so that websites cannot
7
+ * detect CDP / extension-based control.
8
+ *
9
+ * Inspired by puppeteer-extra-plugin-stealth.
10
+ */
11
+ /**
12
+ * Return a self-contained JS string that, when evaluated in a page context,
13
+ * applies all stealth patches. Safe to call multiple times — the guard flag
14
+ * ensures patches are applied only once.
15
+ *
16
+ * The generated string is pure static (no dynamic parameters), so we cache
17
+ * it after the first call to avoid re-building ~350 lines on every goto().
18
+ */
19
+ let _cachedStealthJs;
20
+ export function generateStealthJs() {
21
+ if (_cachedStealthJs !== undefined)
22
+ return _cachedStealthJs;
23
+ return (_cachedStealthJs = `
24
+ (() => {
25
+ // Guard: prevent double-injection across separate CDP evaluations.
26
+ // We cannot use a closure variable (each eval is a fresh scope), and
27
+ // window properties / Symbols are discoverable by anti-bot scripts.
28
+ // Instead, stash the flag in a non-enumerable getter on a built-in
29
+ // prototype that fingerprinters are unlikely to scan.
30
+ const _gProto = EventTarget.prototype;
31
+ const _gKey = '__lsn'; // looks like an internal listener cache
32
+ if (_gProto[_gKey]) return 'skipped';
33
+ try {
34
+ Object.defineProperty(_gProto, _gKey, { value: true, enumerable: false, configurable: true });
35
+ } catch {}
36
+
37
+ // 1. navigator.webdriver → false
38
+ // Most common check; Playwright/Puppeteer/CDP set this to true.
39
+ // Real Chrome returns false (not undefined) — returning undefined is
40
+ // itself a detection signal for advanced fingerprinters.
41
+ try {
42
+ Object.defineProperty(navigator, 'webdriver', {
43
+ get: () => false,
44
+ configurable: true,
45
+ });
46
+ } catch {}
47
+
48
+ // 2. window.chrome stub
49
+ // Real Chrome exposes window.chrome with runtime, loadTimes, csi.
50
+ // Headless/automated Chrome may not have it.
51
+ try {
52
+ if (!window.chrome) {
53
+ window.chrome = {
54
+ runtime: {
55
+ onConnect: { addListener: () => {}, removeListener: () => {} },
56
+ onMessage: { addListener: () => {}, removeListener: () => {} },
57
+ },
58
+ loadTimes: () => ({}),
59
+ csi: () => ({}),
60
+ };
61
+ }
62
+ } catch {}
63
+
64
+ // 3. navigator.plugins — fake population only if empty
65
+ // Real user browser already has plugins; only patch in automated/headless
66
+ // contexts where the list is empty (overwriting real plugins with fakes
67
+ // would be counterproductive and detectable).
68
+ try {
69
+ if (!navigator.plugins || navigator.plugins.length === 0) {
70
+ const fakePlugins = [
71
+ { name: 'PDF Viewer', filename: 'internal-pdf-viewer', description: 'Portable Document Format' },
72
+ { name: 'Chrome PDF Viewer', filename: 'internal-pdf-viewer', description: '' },
73
+ { name: 'Chromium PDF Viewer', filename: 'internal-pdf-viewer', description: '' },
74
+ { name: 'Microsoft Edge PDF Viewer', filename: 'internal-pdf-viewer', description: '' },
75
+ { name: 'WebKit built-in PDF', filename: 'internal-pdf-viewer', description: '' },
76
+ ];
77
+ fakePlugins.item = (i) => fakePlugins[i] || null;
78
+ fakePlugins.namedItem = (n) => fakePlugins.find(p => p.name === n) || null;
79
+ fakePlugins.refresh = () => {};
80
+ Object.defineProperty(navigator, 'plugins', {
81
+ get: () => fakePlugins,
82
+ configurable: true,
83
+ });
84
+ }
85
+ } catch {}
86
+
87
+ // 4. navigator.languages — guarantee non-empty
88
+ // Some automated contexts return undefined or empty array.
89
+ try {
90
+ if (!navigator.languages || navigator.languages.length === 0) {
91
+ Object.defineProperty(navigator, 'languages', {
92
+ get: () => ['en-US', 'en'],
93
+ configurable: true,
94
+ });
95
+ }
96
+ } catch {}
97
+
98
+ // 5. Permissions.query — normalize notification permission
99
+ // Headless Chrome throws on Permissions.query({ name: 'notifications' }).
100
+ try {
101
+ const origQuery = window.Permissions?.prototype?.query;
102
+ if (origQuery) {
103
+ window.Permissions.prototype.query = function (parameters) {
104
+ if (parameters?.name === 'notifications') {
105
+ return Promise.resolve({ state: Notification.permission, onchange: null });
106
+ }
107
+ return origQuery.call(this, parameters);
108
+ };
109
+ }
110
+ } catch {}
111
+
112
+ // 6. Clean automation artifacts
113
+ // Remove properties left by Playwright, Puppeteer, or CDP injection.
114
+ try {
115
+ delete window.__playwright;
116
+ delete window.__puppeteer;
117
+ // ChromeDriver injects cdc_ prefixed globals; the suffix varies by version,
118
+ // so scan window for any matching property rather than hardcoding names.
119
+ for (const prop of Object.getOwnPropertyNames(window)) {
120
+ if (prop.startsWith('cdc_') || prop.startsWith('__cdc_')) {
121
+ try { delete window[prop]; } catch {}
122
+ }
123
+ }
124
+ } catch {}
125
+
126
+ // 7. CDP stack trace cleanup
127
+ // Runtime.evaluate injects scripts whose source URLs appear in Error
128
+ // stack traces (e.g. __puppeteer_evaluation_script__, pptr:, debugger://).
129
+ // Websites detect automation by doing: new Error().stack and inspecting it.
130
+ // We override the stack property getter on Error.prototype to filter them.
131
+ // Note: Error.prepareStackTrace is V8/Node-only and not available in
132
+ // browser page context, so we use a property descriptor approach instead.
133
+ // We use generic protocol patterns instead of product-specific names to
134
+ // also catch our own injected code frames without leaking identifiers.
135
+ try {
136
+ const _origDescriptor = Object.getOwnPropertyDescriptor(Error.prototype, 'stack');
137
+ const _cdpPatterns = [
138
+ 'puppeteer_evaluation_script',
139
+ 'pptr:',
140
+ 'debugger://',
141
+ '__playwright',
142
+ '__puppeteer',
143
+ ];
144
+ if (_origDescriptor && _origDescriptor.get) {
145
+ Object.defineProperty(Error.prototype, 'stack', {
146
+ get: function () {
147
+ const raw = _origDescriptor.get.call(this);
148
+ if (typeof raw !== 'string') return raw;
149
+ return raw.split('\\n').filter(line =>
150
+ !_cdpPatterns.some(p => line.includes(p))
151
+ ).join('\\n');
152
+ },
153
+ configurable: true,
154
+ });
155
+ }
156
+ } catch {}
157
+
158
+ // ── Shared toString disguise infrastructure ──
159
+ // Save the pristine Function.prototype.toString BEFORE any patches,
160
+ // so all subsequent disguises use the real native reference.
161
+ // Anti-bot scripts detect per-instance toString overrides via:
162
+ // Function.hasOwnProperty('toString') → true if patched
163
+ // Function.prototype.toString.call(fn) !== fn.toString()
164
+ // Instead we patch Function.prototype.toString once with a WeakMap
165
+ // lookup, making disguised functions indistinguishable from native.
166
+ const _origToString = Function.prototype.toString;
167
+ const _disguised = new WeakMap();
168
+ try {
169
+ Object.defineProperty(Function.prototype, 'toString', {
170
+ value: function() {
171
+ const override = _disguised.get(this);
172
+ return override !== undefined ? override : _origToString.call(this);
173
+ },
174
+ writable: true, configurable: true,
175
+ });
176
+ } catch {}
177
+ const _disguise = (fn, name) => {
178
+ _disguised.set(fn, 'function ' + name + '() { [native code] }');
179
+ try { Object.defineProperty(fn, 'name', { value: name, configurable: true }); } catch {}
180
+ return fn;
181
+ };
182
+
183
+ // 8. Anti-debugger statement trap
184
+ // Sites inject debugger statements to detect DevTools/CDP.
185
+ // When a CDP debugger is attached, the statement pauses execution
186
+ // and the site measures the time gap to confirm automation.
187
+ // We neutralize this by overriding the Function constructor and
188
+ // eval to strip debugger statements from dynamically created code.
189
+ // Note: this does NOT affect static debugger statements in parsed
190
+ // scripts — those require CDP Debugger.setBreakpointsActive(false)
191
+ // which we handle at the extension level.
192
+ // Caveat: the regex targets standalone debugger statements (preceded
193
+ // by a statement boundary) to minimise false positives inside string
194
+ // literals, but cannot perfectly distinguish all cases without a
195
+ // full parser. This is an acceptable trade-off for stealth code.
196
+ try {
197
+ const _OrigFunction = Function;
198
+ // Match standalone debugger statements preceded by a statement
199
+ // boundary (start of string, semicolon, brace, or newline).
200
+ // This avoids most false positives inside string literals like
201
+ // "use debugger mode" while still catching the anti-bot patterns.
202
+ const _debuggerRe = /(?:^|(?<=[;{}\\n\\r]))\\s*debugger\\s*;?/g;
203
+ const _cleanDebugger = (src) => typeof src === 'string' ? src.replace(_debuggerRe, '') : src;
204
+ // Patch Function constructor to strip debugger from dynamic code.
205
+ // Support both Function('code') and new Function('code') via
206
+ // new.target / Reflect.construct.
207
+ const _PatchedFunction = function(...args) {
208
+ if (args.length > 0) {
209
+ args[args.length - 1] = _cleanDebugger(args[args.length - 1]);
210
+ }
211
+ if (new.target) {
212
+ return Reflect.construct(_OrigFunction, args, new.target);
213
+ }
214
+ return _OrigFunction.apply(this, args);
215
+ };
216
+ _PatchedFunction.prototype = _OrigFunction.prototype;
217
+ Object.setPrototypeOf(_PatchedFunction, _OrigFunction);
218
+ _disguise(_PatchedFunction, 'Function');
219
+ try { window.Function = _PatchedFunction; } catch {}
220
+
221
+ // Patch eval to strip debugger
222
+ const _origEval = window.eval;
223
+ const _patchedEval = function(code) {
224
+ return _origEval.call(this, _cleanDebugger(code));
225
+ };
226
+ _disguise(_patchedEval, 'eval');
227
+ try { window.eval = _patchedEval; } catch {}
228
+ } catch {}
229
+
230
+ // 9. Console method fingerprinting defense
231
+ // When CDP Runtime.enable is called, Chrome replaces console.log etc.
232
+ // with CDP-bound versions. These bound functions have a different
233
+ // toString() output: "function log() { [native code] }" becomes
234
+ // something like "function () { [native code] }" (no name) or the
235
+ // bound function signature leaks. Anti-bot scripts check:
236
+ // console.log.toString().includes('[native code]')
237
+ // console.log.name === 'log'
238
+ // We re-wrap console methods and register them via the shared
239
+ // _disguise infrastructure so Function.prototype.toString.call()
240
+ // also returns the correct native string.
241
+ try {
242
+ const _consoleMethods = ['log', 'warn', 'error', 'info', 'debug', 'table', 'trace', 'dir', 'group', 'groupEnd', 'groupCollapsed', 'clear', 'count', 'assert', 'profile', 'profileEnd', 'time', 'timeEnd', 'timeStamp'];
243
+ for (const _m of _consoleMethods) {
244
+ if (typeof console[_m] !== 'function') continue;
245
+ const _origMethod = console[_m];
246
+ const _nativeStr = 'function ' + _m + '() { [native code] }';
247
+ // Only patch if toString is wrong (i.e. CDP has replaced it)
248
+ try {
249
+ const _currentStr = _origToString.call(_origMethod);
250
+ if (_currentStr === _nativeStr) continue; // already looks native
251
+ } catch {}
252
+ const _wrapper = function() { return _origMethod.apply(console, arguments); };
253
+ Object.defineProperty(_wrapper, 'length', { value: _origMethod.length || 0, configurable: true });
254
+ _disguise(_wrapper, _m);
255
+ try { console[_m] = _wrapper; } catch {}
256
+ }
257
+ } catch {}
258
+
259
+ // 10. window.outerWidth/outerHeight defense
260
+ // When DevTools or CDP debugger is attached, Chrome may alter the
261
+ // window dimensions. Anti-bot scripts compare outerWidth/innerWidth
262
+ // and outerHeight/innerHeight — a significant difference indicates
263
+ // DevTools is open. We freeze the relationship so the delta stays
264
+ // consistent with a normal browser window.
265
+ // Thresholds: width delta > 100px or height delta > 200px indicates
266
+ // a docked DevTools panel. When triggered, we report outerWidth
267
+ // equal to innerWidth (normal for maximised windows) and
268
+ // outerHeight as innerHeight + the captured "normal" delta (capped
269
+ // to a reasonable range), so the result is plausible across OSes.
270
+ try {
271
+ const _normalWidthDelta = window.outerWidth - window.innerWidth;
272
+ const _normalHeightDelta = window.outerHeight - window.innerHeight;
273
+ // Only patch if the delta looks suspicious (e.g. DevTools docked)
274
+ if (_normalWidthDelta > 100 || _normalHeightDelta > 200) {
275
+ Object.defineProperty(window, 'outerWidth', {
276
+ get: () => window.innerWidth,
277
+ configurable: true,
278
+ });
279
+ // Use a clamped height offset (40-120px covers macOS ~78px,
280
+ // Windows ~40px, and Linux ~37-50px title bar heights).
281
+ const _heightOffset = Math.max(40, Math.min(120, _normalHeightDelta));
282
+ Object.defineProperty(window, 'outerHeight', {
283
+ get: () => window.innerHeight + _heightOffset,
284
+ configurable: true,
285
+ });
286
+ }
287
+ } catch {}
288
+
289
+ // 11. Performance API cleanup
290
+ // CDP injects internal resources and timing entries that don't exist
291
+ // in normal browsing. Filter entries with debugger/devtools URLs.
292
+ try {
293
+ const _origGetEntries = Performance.prototype.getEntries;
294
+ const _origGetByType = Performance.prototype.getEntriesByType;
295
+ const _origGetByName = Performance.prototype.getEntriesByName;
296
+ const _suspiciousPatterns = ['debugger', 'devtools', '__puppeteer', '__playwright', 'pptr:'];
297
+ const _filterEntries = (entries) => {
298
+ if (!Array.isArray(entries)) return entries;
299
+ return entries.filter(e => {
300
+ const name = e.name || '';
301
+ return !_suspiciousPatterns.some(p => name.includes(p));
302
+ });
303
+ };
304
+ Performance.prototype.getEntries = function() {
305
+ return _filterEntries(_origGetEntries.call(this));
306
+ };
307
+ Performance.prototype.getEntriesByType = function(type) {
308
+ return _filterEntries(_origGetByType.call(this, type));
309
+ };
310
+ Performance.prototype.getEntriesByName = function(name, type) {
311
+ return _filterEntries(_origGetByName.call(this, name, type));
312
+ };
313
+ } catch {}
314
+
315
+ // 12. WebDriver-related property defense
316
+ // Some anti-bot systems check additional navigator properties
317
+ // and document properties that may indicate automation.
318
+ try {
319
+ // document.$cdc_ properties (ChromeDriver specific, backup for #6)
320
+ for (const _prop of Object.getOwnPropertyNames(document)) {
321
+ if (_prop.startsWith('$cdc_') || _prop.startsWith('$chrome_')) {
322
+ try { delete document[_prop]; } catch {}
323
+ }
324
+ }
325
+ } catch {}
326
+
327
+ // 13. Iframe contentWindow.chrome consistency
328
+ // Anti-bot scripts create iframes and check if
329
+ // iframe.contentWindow.chrome exists and matches the parent.
330
+ // CDP-controlled pages may have inconsistent iframe contexts.
331
+ try {
332
+ const _origHTMLIFrame = HTMLIFrameElement.prototype;
333
+ const _origContentWindow = Object.getOwnPropertyDescriptor(_origHTMLIFrame, 'contentWindow');
334
+ if (_origContentWindow && _origContentWindow.get) {
335
+ Object.defineProperty(_origHTMLIFrame, 'contentWindow', {
336
+ get: function() {
337
+ const _w = _origContentWindow.get.call(this);
338
+ if (_w) {
339
+ try {
340
+ if (!_w.chrome) {
341
+ Object.defineProperty(_w, 'chrome', {
342
+ value: window.chrome,
343
+ writable: true,
344
+ configurable: true,
345
+ });
346
+ }
347
+ } catch {}
348
+ }
349
+ return _w;
350
+ },
351
+ configurable: true,
352
+ });
353
+ }
354
+ } catch {}
355
+
356
+ return 'applied';
357
+ })()
358
+ `);
359
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,134 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { generateStealthJs } from './stealth.js';
3
+ /**
4
+ * Tests for the stealth anti-detection module.
5
+ *
6
+ * We test the generated JS string for expected content and structure.
7
+ * Evaluating in Node is fragile because stealth patches target browser
8
+ * globals (navigator, Performance, HTMLIFrameElement) that don't exist
9
+ * or behave differently in Node. Instead we verify the code string
10
+ * contains the right patches and is syntactically valid.
11
+ */
12
+ describe('generateStealthJs', () => {
13
+ it('returns a non-empty string', () => {
14
+ const code = generateStealthJs();
15
+ expect(typeof code).toBe('string');
16
+ expect(code.length).toBeGreaterThan(0);
17
+ });
18
+ it('is a valid self-contained IIFE', () => {
19
+ const code = generateStealthJs();
20
+ // Should start/end as an IIFE
21
+ expect(code.trim()).toMatch(/^\(\(\) => \{/);
22
+ expect(code.trim()).toMatch(/\}\)\(\)$/);
23
+ });
24
+ it('patches navigator.webdriver', () => {
25
+ const code = generateStealthJs();
26
+ expect(code).toContain("navigator, 'webdriver'");
27
+ expect(code).toContain('() => false');
28
+ });
29
+ it('stubs window.chrome', () => {
30
+ const code = generateStealthJs();
31
+ expect(code).toContain('window.chrome');
32
+ expect(code).toContain('runtime');
33
+ expect(code).toContain('loadTimes');
34
+ expect(code).toContain('csi');
35
+ });
36
+ it('fakes navigator.plugins if empty', () => {
37
+ const code = generateStealthJs();
38
+ expect(code).toContain('navigator.plugins');
39
+ expect(code).toContain('PDF Viewer');
40
+ expect(code).toContain('Chrome PDF Viewer');
41
+ });
42
+ it('ensures navigator.languages is non-empty', () => {
43
+ const code = generateStealthJs();
44
+ expect(code).toContain('navigator.languages');
45
+ expect(code).toContain("'en-US'");
46
+ });
47
+ it('normalizes Permissions.query for notifications', () => {
48
+ const code = generateStealthJs();
49
+ expect(code).toContain('Permissions');
50
+ expect(code).toContain('notifications');
51
+ });
52
+ it('cleans automation artifacts', () => {
53
+ const code = generateStealthJs();
54
+ expect(code).toContain('__playwright');
55
+ expect(code).toContain('__puppeteer');
56
+ expect(code).toContain("'cdc_'");
57
+ expect(code).toContain("'__cdc_'");
58
+ });
59
+ it('filters CDP patterns from Error.stack', () => {
60
+ const code = generateStealthJs();
61
+ expect(code).toContain('puppeteer_evaluation_script');
62
+ expect(code).toContain("'pptr:'");
63
+ expect(code).toContain("'debugger://'");
64
+ });
65
+ it('neutralizes debugger statement traps', () => {
66
+ const code = generateStealthJs();
67
+ // Should patch Function constructor with new.target / Reflect.construct
68
+ expect(code).toContain('_OrigFunction');
69
+ expect(code).toContain('_PatchedFunction');
70
+ expect(code).toContain('new.target');
71
+ expect(code).toContain('Reflect.construct');
72
+ // Should patch eval
73
+ expect(code).toContain('_origEval');
74
+ expect(code).toContain('_patchedEval');
75
+ // Regex to strip debugger (lookbehind for statement boundaries)
76
+ expect(code).toContain('_debuggerRe');
77
+ });
78
+ it('uses shared toString disguise via WeakMap', () => {
79
+ const code = generateStealthJs();
80
+ // Shared infrastructure at the top of the IIFE
81
+ expect(code).toContain('_origToString');
82
+ expect(code).toContain('WeakMap');
83
+ expect(code).toContain('_disguised');
84
+ expect(code).toContain('_disguise');
85
+ // Should NOT have per-instance toString overrides on Function/eval
86
+ // (they go through _disguise instead)
87
+ });
88
+ it('defends console method fingerprinting', () => {
89
+ const code = generateStealthJs();
90
+ expect(code).toContain('_consoleMethods');
91
+ expect(code).toContain("'log'");
92
+ expect(code).toContain("'warn'");
93
+ expect(code).toContain("'error'");
94
+ expect(code).toContain('[native code]');
95
+ // Uses saved _origToString reference
96
+ expect(code).toContain('_origToString.call');
97
+ });
98
+ it('defends window dimension detection', () => {
99
+ const code = generateStealthJs();
100
+ expect(code).toContain('outerWidth');
101
+ expect(code).toContain('outerHeight');
102
+ expect(code).toContain('innerWidth');
103
+ expect(code).toContain('innerHeight');
104
+ });
105
+ it('filters Performance API entries', () => {
106
+ const code = generateStealthJs();
107
+ expect(code).toContain('getEntries');
108
+ expect(code).toContain('getEntriesByType');
109
+ expect(code).toContain('getEntriesByName');
110
+ expect(code).toContain('_suspiciousPatterns');
111
+ });
112
+ it('cleans document $cdc_ properties', () => {
113
+ const code = generateStealthJs();
114
+ expect(code).toContain("'$cdc_'");
115
+ expect(code).toContain("'$chrome_'");
116
+ });
117
+ it('patches iframe contentWindow.chrome consistency', () => {
118
+ const code = generateStealthJs();
119
+ expect(code).toContain('contentWindow');
120
+ expect(code).toContain('HTMLIFrameElement');
121
+ });
122
+ it('uses non-enumerable guard flag on EventTarget.prototype', () => {
123
+ const code = generateStealthJs();
124
+ expect(code).toContain('EventTarget.prototype');
125
+ expect(code).toContain("'__lsn'");
126
+ expect(code).toContain('enumerable: false');
127
+ });
128
+ it('generates syntactically valid JavaScript', () => {
129
+ const code = generateStealthJs();
130
+ // new Function() parses the code without executing it in a real
131
+ // browser context, catching syntax errors from template literal issues.
132
+ expect(() => new Function(code)).not.toThrow();
133
+ });
134
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Browser tab management helpers: extract, diff, and cleanup tab state.
3
+ */
4
+ export declare function extractTabEntries(raw: unknown): Array<{
5
+ index: number;
6
+ identity: string;
7
+ }>;
8
+ export declare function extractTabIdentities(raw: unknown): string[];
9
+ export declare function diffTabIndexes(initialIdentities: string[], currentTabs: Array<{
10
+ index: number;
11
+ identity: string;
12
+ }>): number[];
13
+ export declare function appendLimited(current: string, chunk: string, limit: number): string;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Browser tab management helpers: extract, diff, and cleanup tab state.
3
+ */
4
+ export function extractTabEntries(raw) {
5
+ if (Array.isArray(raw)) {
6
+ return raw.map((tab, index) => ({
7
+ index,
8
+ identity: [
9
+ tab?.id ?? '',
10
+ tab?.url ?? '',
11
+ tab?.title ?? '',
12
+ tab?.name ?? '',
13
+ ].join('|'),
14
+ }));
15
+ }
16
+ if (typeof raw === 'string') {
17
+ return raw
18
+ .split('\n')
19
+ .map(line => line.trim())
20
+ .filter(Boolean)
21
+ .map(line => {
22
+ // Match tab list format: "- 0: (current) [title](url)" or "- 1: [title](url)"
23
+ const tabMatch = line.match(/^-\s+(\d+):\s*(.*)$/);
24
+ if (tabMatch) {
25
+ return {
26
+ index: parseInt(tabMatch[1], 10),
27
+ identity: tabMatch[2].trim() || `tab-${tabMatch[1]}`,
28
+ };
29
+ }
30
+ // Legacy format: "Tab 0 ..."
31
+ const legacyMatch = line.match(/Tab\s+(\d+)\s*(.*)$/);
32
+ if (legacyMatch) {
33
+ return {
34
+ index: parseInt(legacyMatch[1], 10),
35
+ identity: legacyMatch[2].trim() || `tab-${legacyMatch[1]}`,
36
+ };
37
+ }
38
+ return null;
39
+ })
40
+ .filter((entry) => entry !== null);
41
+ }
42
+ return [];
43
+ }
44
+ export function extractTabIdentities(raw) {
45
+ return extractTabEntries(raw).map(tab => tab.identity);
46
+ }
47
+ export function diffTabIndexes(initialIdentities, currentTabs) {
48
+ if (initialIdentities.length === 0 || currentTabs.length === 0)
49
+ return [];
50
+ const remaining = new Map();
51
+ for (const identity of initialIdentities) {
52
+ remaining.set(identity, (remaining.get(identity) ?? 0) + 1);
53
+ }
54
+ const tabsToClose = [];
55
+ for (const tab of currentTabs) {
56
+ const count = remaining.get(tab.identity) ?? 0;
57
+ if (count > 0) {
58
+ remaining.set(tab.identity, count - 1);
59
+ continue;
60
+ }
61
+ tabsToClose.push(tab.index);
62
+ }
63
+ return tabsToClose.sort((a, b) => b - a);
64
+ }
65
+ export function appendLimited(current, chunk, limit) {
66
+ const next = current + chunk;
67
+ if (next.length <= limit)
68
+ return next;
69
+ return next.slice(-limit);
70
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Structured error types for the target resolution system.
3
+ *
4
+ * Every browser action (click, type, select, get) that targets a DOM element
5
+ * goes through the unified resolver. When resolution fails, one of these
6
+ * structured errors is thrown so that AI agents and adapter authors get
7
+ * actionable diagnostics instead of a generic "Element not found".
8
+ *
9
+ * Numeric-ref codes (from snapshot indices):
10
+ * - not_found: the ref no longer exists in the DOM
11
+ * - stale_ref: the ref still exists but points to a different element
12
+ *
13
+ * CSS-selector codes (from `--selector <css>` entrypoints):
14
+ * - invalid_selector: selector syntax rejected by querySelectorAll
15
+ * - selector_not_found: 0 matches
16
+ * - selector_ambiguous: >1 matches for a write op without --nth
17
+ * - selector_nth_out_of_range: --nth beyond matches_n
18
+ * - not_editable: target exists but cannot accept text input
19
+ * - not_checkable: target exists but cannot be checked/unchecked
20
+ * - not_file_input: target exists but is not a usable file input
21
+ */
22
+ export type TargetErrorCode = 'not_found' | 'stale_ref' | 'invalid_selector' | 'selector_not_found' | 'selector_ambiguous' | 'selector_nth_out_of_range' | 'not_editable' | 'not_checkable' | 'not_file_input';
23
+ export interface TargetErrorInfo {
24
+ code: TargetErrorCode;
25
+ message: string;
26
+ hint: string;
27
+ candidates?: string[];
28
+ /** CSS-path match count, when the error was raised mid-resolution */
29
+ matches_n?: number;
30
+ }
31
+ export declare class TargetError extends Error {
32
+ readonly code: TargetErrorCode;
33
+ readonly hint: string;
34
+ readonly candidates?: string[];
35
+ readonly matches_n?: number;
36
+ constructor(info: TargetErrorInfo);
37
+ /** Serialize for structured output to AI agents */
38
+ toJSON(): TargetErrorInfo;
39
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Structured error types for the target resolution system.
3
+ *
4
+ * Every browser action (click, type, select, get) that targets a DOM element
5
+ * goes through the unified resolver. When resolution fails, one of these
6
+ * structured errors is thrown so that AI agents and adapter authors get
7
+ * actionable diagnostics instead of a generic "Element not found".
8
+ *
9
+ * Numeric-ref codes (from snapshot indices):
10
+ * - not_found: the ref no longer exists in the DOM
11
+ * - stale_ref: the ref still exists but points to a different element
12
+ *
13
+ * CSS-selector codes (from `--selector <css>` entrypoints):
14
+ * - invalid_selector: selector syntax rejected by querySelectorAll
15
+ * - selector_not_found: 0 matches
16
+ * - selector_ambiguous: >1 matches for a write op without --nth
17
+ * - selector_nth_out_of_range: --nth beyond matches_n
18
+ * - not_editable: target exists but cannot accept text input
19
+ * - not_checkable: target exists but cannot be checked/unchecked
20
+ * - not_file_input: target exists but is not a usable file input
21
+ */
22
+ export class TargetError extends Error {
23
+ code;
24
+ hint;
25
+ candidates;
26
+ matches_n;
27
+ constructor(info) {
28
+ super(info.message);
29
+ this.name = 'TargetError';
30
+ this.code = info.code;
31
+ this.hint = info.hint;
32
+ this.candidates = info.candidates;
33
+ this.matches_n = info.matches_n;
34
+ }
35
+ /** Serialize for structured output to AI agents */
36
+ toJSON() {
37
+ return {
38
+ code: this.code,
39
+ message: this.message,
40
+ hint: this.hint,
41
+ ...(this.candidates && { candidates: this.candidates }),
42
+ ...(this.matches_n !== undefined && { matches_n: this.matches_n }),
43
+ };
44
+ }
45
+ }
@@ -0,0 +1 @@
1
+ export {};