@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,894 @@
1
+ /**
2
+ * DOM Snapshot Engine — Advanced DOM pruning for LLM consumption.
3
+ *
4
+ * Inspired by browser-use's multi-layer pruning pipeline, adapted for webcmd's
5
+ * Chrome Extension + CDP architecture. Runs entirely in-page via Runtime.evaluate.
6
+ *
7
+ * Pipeline:
8
+ * 1. Walk DOM tree, collect visibility + layout + interactivity signals
9
+ * 2. Prune invisible, zero-area, non-content elements
10
+ * 3. SVG & decoration collapse
11
+ * 4. Shadow DOM traversal
12
+ * 5. Same-origin iframe content extraction
13
+ * 6. Bounding-box parent-child dedup (link/button wrapping children)
14
+ * 7. Paint-order occlusion detection (overlay/modal coverage)
15
+ * 8. Attribute whitelist filtering
16
+ * 9. Table-aware serialization (markdown tables)
17
+ * 10. Token-efficient serialization with interactive indices
18
+ * 11. data-ref annotation for click/type targeting
19
+ * 12. Hidden interactive element hints (scroll-to-reveal)
20
+ * 13. Incremental diff (mark new elements with *)
21
+ *
22
+ * Additional tools:
23
+ * - scrollToRefJs(ref) — scroll to a data-webcmd-ref element
24
+ * - getFormStateJs() — extract all form fields as structured JSON
25
+ *
26
+ * Compound sidecar:
27
+ * After the tree, a `compounds:` section lists rich JSON for every
28
+ * date/select/file ref — format, full option list (up to cap) with
29
+ * `options_total` reflecting the true count, file `accept` + `multiple`.
30
+ * This is what the snapshot's inline attr dump cannot express and what
31
+ * agents kept blowing turns on.
32
+ */
33
+ import { COMPOUND_INFO_JS } from './compound.js';
34
+ // ─── Utility JS Generators ───────────────────────────────────────────
35
+ /**
36
+ * Generate JS to scroll to an element identified by data-webcmd-ref.
37
+ * Completes the snapshot→action loop: snapshot identifies `[3]<button>`,
38
+ * caller can then `scrollToRef('3')` to bring it into view.
39
+ */
40
+ export function scrollToRefJs(ref) {
41
+ const safeRef = JSON.stringify(ref);
42
+ return `
43
+ (() => {
44
+ const ref = ${safeRef};
45
+ const el = document.querySelector('[data-webcmd-ref="' + ref + '"]')
46
+ || document.querySelector('[data-ref="' + ref + '"]');
47
+ if (!el) throw new Error('Element not found: ref=' + ref);
48
+ el.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' });
49
+ return { scrolled: true, tag: el.tagName.toLowerCase(), text: (el.textContent || '').trim().slice(0, 80) };
50
+ })()
51
+ `.trim();
52
+ }
53
+ /**
54
+ * Generate JS to extract all form field values from the page.
55
+ * Returns structured JSON: { forms: [{ id, action, fields: [{ tag, type, name, value, ... }] }] }
56
+ */
57
+ export function getFormStateJs() {
58
+ return `
59
+ (() => {
60
+ const result = { forms: [], orphanFields: [] };
61
+
62
+ // Collect all forms
63
+ for (const form of document.forms) {
64
+ const formData = {
65
+ id: form.id || null,
66
+ name: form.name || null,
67
+ action: form.action || null,
68
+ method: (form.method || 'get').toUpperCase(),
69
+ fields: [],
70
+ };
71
+ for (const el of form.elements) {
72
+ const field = extractField(el);
73
+ if (field) formData.fields.push(field);
74
+ }
75
+ if (formData.fields.length > 0) result.forms.push(formData);
76
+ }
77
+
78
+ // Collect orphan fields (not inside a form)
79
+ const allInputs = document.querySelectorAll('input, textarea, select, [contenteditable="true"]');
80
+ for (const el of allInputs) {
81
+ if (el.form) continue; // already in a form
82
+ const field = extractField(el);
83
+ if (field) result.orphanFields.push(field);
84
+ }
85
+
86
+ function extractField(el) {
87
+ const tag = el.tagName.toLowerCase();
88
+ const type = (el.getAttribute('type') || (tag === 'textarea' ? 'textarea' : tag === 'select' ? 'select' : 'text')).toLowerCase();
89
+ if (type === 'hidden' || type === 'submit' || type === 'button' || type === 'reset') return null;
90
+ const name = el.name || el.id || null;
91
+ const ref = el.getAttribute('data-webcmd-ref') || null;
92
+ const label = findLabel(el);
93
+ let value;
94
+ if (tag === 'select') {
95
+ const opt = el.options?.[el.selectedIndex];
96
+ value = opt ? opt.textContent.trim() : '';
97
+ } else if (type === 'checkbox' || type === 'radio') {
98
+ value = el.checked;
99
+ } else if (type === 'password') {
100
+ value = el.value ? '••••' : '';
101
+ } else if (el.isContentEditable) {
102
+ value = (el.textContent || '').trim().slice(0, 200);
103
+ } else {
104
+ value = (el.value || '').slice(0, 200);
105
+ }
106
+ return { tag, type, name, ref, label, value, required: el.required || false, disabled: el.disabled || false };
107
+ }
108
+
109
+ function findLabel(el) {
110
+ // 1. aria-label
111
+ if (el.getAttribute('aria-label')) return el.getAttribute('aria-label');
112
+ // 2. associated <label>
113
+ if (el.id) {
114
+ const label = document.querySelector('label[for="' + el.id + '"]');
115
+ if (label) return label.textContent.trim().slice(0, 80);
116
+ }
117
+ // 3. parent label
118
+ const parentLabel = el.closest('label');
119
+ if (parentLabel) return parentLabel.textContent.trim().slice(0, 80);
120
+ // 4. placeholder
121
+ return el.placeholder || null;
122
+ }
123
+
124
+ return result;
125
+ })()
126
+ `.trim();
127
+ }
128
+ // ─── Main Snapshot JS Generator ──────────────────────────────────────
129
+ /**
130
+ * Generate JavaScript code that, when evaluated in a page context via CDP
131
+ * Runtime.evaluate, returns a pruned DOM snapshot string optimised for LLMs.
132
+ *
133
+ * The snapshot output format:
134
+ * [42]<button type=submit>Search</button>
135
+ * |scroll|<div> (0.5↑ 3.2↓)
136
+ * *[58]<a href=/r/1>Result 1</a>
137
+ * [59]<a href=/r/2>Result 2</a>
138
+ *
139
+ * - `[id]` — interactive element with backend index for targeting
140
+ * - `*` prefix — newly appeared element (incremental diff)
141
+ * - `|scroll|` — scrollable container with page counts
142
+ * - `|shadow|` — Shadow DOM boundary
143
+ * - `|iframe|` — iframe content
144
+ * - `|table|` — markdown table rendering
145
+ */
146
+ export function generateSnapshotJs(opts = {}) {
147
+ const viewportExpand = opts.viewportExpand ?? 800;
148
+ const maxDepth = Math.max(1, Math.min(opts.maxDepth ?? 50, 200));
149
+ const interactiveOnly = opts.interactiveOnly ?? false;
150
+ const maxTextLength = opts.maxTextLength ?? 120;
151
+ const includeScrollInfo = opts.includeScrollInfo ?? true;
152
+ const bboxDedup = opts.bboxDedup ?? true;
153
+ const includeShadowDom = opts.includeShadowDom ?? true;
154
+ const includeIframes = opts.includeIframes ?? true;
155
+ const maxIframes = opts.maxIframes ?? 5;
156
+ const paintOrderCheck = opts.paintOrderCheck ?? true;
157
+ const annotateRefs = opts.annotateRefs ?? true;
158
+ const reportHidden = opts.reportHidden ?? true;
159
+ const filterAds = opts.filterAds ?? true;
160
+ const markdownTables = opts.markdownTables ?? true;
161
+ const previousHashes = opts.previousHashes ?? null;
162
+ return `
163
+ (() => {
164
+ 'use strict';
165
+
166
+ ${COMPOUND_INFO_JS}
167
+
168
+ // ── Config ─────────────────────────────────────────────────────────
169
+ const VIEWPORT_EXPAND = ${viewportExpand};
170
+ const MAX_DEPTH = ${maxDepth};
171
+ const INTERACTIVE_ONLY = ${interactiveOnly};
172
+ const MAX_TEXT_LEN = ${maxTextLength};
173
+ const INCLUDE_SCROLL_INFO = ${includeScrollInfo};
174
+ const BBOX_DEDUP = ${bboxDedup};
175
+ const INCLUDE_SHADOW_DOM = ${includeShadowDom};
176
+ const INCLUDE_IFRAMES = ${includeIframes};
177
+ const MAX_IFRAMES = ${maxIframes};
178
+ const PAINT_ORDER_CHECK = ${paintOrderCheck};
179
+ const ANNOTATE_REFS = ${annotateRefs};
180
+ const REPORT_HIDDEN = ${reportHidden};
181
+ const FILTER_ADS = ${filterAds};
182
+ const MARKDOWN_TABLES = ${markdownTables};
183
+ const PREV_HASHES = ${previousHashes ? `new Set(${previousHashes})` : 'null'};
184
+
185
+ // ── Constants ──────────────────────────────────────────────────────
186
+
187
+ const SKIP_TAGS = new Set([
188
+ 'script', 'style', 'noscript', 'link', 'meta', 'head',
189
+ 'template', 'br', 'wbr', 'col', 'colgroup',
190
+ ]);
191
+
192
+ const SVG_CHILDREN = new Set([
193
+ 'path', 'rect', 'g', 'circle', 'ellipse', 'line', 'polyline',
194
+ 'polygon', 'use', 'defs', 'clippath', 'mask', 'pattern',
195
+ 'text', 'tspan', 'lineargradient', 'radialgradient', 'stop',
196
+ 'filter', 'fegaussianblur', 'fecolormatrix', 'feblend',
197
+ 'symbol', 'marker', 'foreignobject', 'desc', 'title',
198
+ ]);
199
+
200
+ const INTERACTIVE_TAGS = new Set([
201
+ 'a', 'button', 'input', 'select', 'textarea', 'details',
202
+ 'summary', 'option', 'optgroup',
203
+ ]);
204
+
205
+ const INTERACTIVE_ROLES = new Set([
206
+ 'button', 'link', 'menuitem', 'option', 'radio', 'checkbox',
207
+ 'tab', 'textbox', 'combobox', 'slider', 'spinbutton',
208
+ 'searchbox', 'switch', 'menuitemcheckbox', 'menuitemradio',
209
+ 'treeitem', 'gridcell', 'row',
210
+ ]);
211
+
212
+ const LANDMARK_ROLES = new Set([
213
+ 'main', 'navigation', 'banner', 'search', 'region',
214
+ 'complementary', 'contentinfo', 'form', 'dialog',
215
+ ]);
216
+
217
+ const LANDMARK_TAGS = new Set([
218
+ 'nav', 'main', 'header', 'footer', 'aside', 'form',
219
+ 'search', 'dialog', 'section', 'article',
220
+ ]);
221
+
222
+ const ATTR_WHITELIST = new Set([
223
+ 'id', 'name', 'type', 'value', 'placeholder', 'title', 'alt',
224
+ 'role', 'aria-label', 'aria-expanded', 'aria-checked', 'aria-selected',
225
+ 'aria-disabled', 'aria-valuemin', 'aria-valuemax', 'aria-valuenow',
226
+ 'aria-haspopup', 'aria-live', 'aria-required',
227
+ 'href', 'src', 'action', 'method', 'for', 'checked', 'selected',
228
+ 'disabled', 'required', 'multiple', 'accept', 'min', 'max',
229
+ 'pattern', 'maxlength', 'minlength', 'data-testid', 'data-test',
230
+ 'contenteditable', 'tabindex', 'autocomplete',
231
+ ]);
232
+
233
+ const PROPAGATING_TAGS = new Set(['a', 'button']);
234
+
235
+ // Roles whose element wraps its own interactive descendants (icon spans
236
+ // inside a role=button, chevron inside role=link). When we see one of these,
237
+ // we propagate its bbox to children so we can suppress duplicate refs on
238
+ // undistinctive descendants that are ≥99% contained.
239
+ const PROPAGATING_ROLES = new Set(['button', 'link', 'menuitem', 'tab', 'option']);
240
+
241
+ function isBboxPropagator(el, tag) {
242
+ if (PROPAGATING_TAGS.has(tag)) return true;
243
+ const role = el.getAttribute('role');
244
+ return !!(role && PROPAGATING_ROLES.has(role));
245
+ }
246
+
247
+ // True when an interactive element still deserves its own [N] ref even
248
+ // though it's visually subsumed by a propagating ancestor. Anything with
249
+ // an aria-label, aria-labelledby, id, test id, name, or its own form
250
+ // semantics is treated as distinctive — everything else (naked spans /
251
+ // divs / svgs that merely inherit click from the parent button) gets
252
+ // folded into the parent so the snapshot doesn't ship [1]<button>[2]<svg>.
253
+ function isDistinctivelyInteractive(el) {
254
+ if (el.hasAttribute('aria-label')) return true;
255
+ if (el.hasAttribute('aria-labelledby')) return true;
256
+ if (el.id) return true;
257
+ if (el.getAttribute('data-testid') || el.getAttribute('data-test')) return true;
258
+ if (el.hasAttribute('name')) return true;
259
+ const tag = el.tagName.toLowerCase();
260
+ // Real form controls always stand on their own, even when nested in a label/button
261
+ if (tag === 'input' || tag === 'select' || tag === 'textarea') return true;
262
+ // Anchors with their own href are distinct targets
263
+ if (tag === 'a' && el.hasAttribute('href')) return true;
264
+ return false;
265
+ }
266
+
267
+ const AD_PATTERNS = [
268
+ 'googleadservices.com', 'doubleclick.net', 'googlesyndication.com',
269
+ 'facebook.com/tr', 'analytics.google.com', 'connect.facebook.net',
270
+ 'ad.doubleclick', 'pagead', 'adsense',
271
+ ];
272
+
273
+ const AD_SELECTOR_RE = /\\b(ad[_-]?(?:banner|container|wrapper|slot|unit|block|frame|leaderboard|sidebar)|google[_-]?ad|sponsored|adsbygoogle|banner[_-]?ad)\\b/i;
274
+
275
+ // Search element indicators for heuristic detection
276
+ const SEARCH_INDICATORS = new Set([
277
+ 'search', 'magnify', 'glass', 'lookup', 'find', 'query',
278
+ 'search-icon', 'search-btn', 'search-button', 'searchbox',
279
+ 'fa-search', 'icon-search', 'btn-search',
280
+ ]);
281
+
282
+ // ── Viewport & Layout Helpers ──────────────────────────────────────
283
+
284
+ const vw = window.innerWidth;
285
+ const vh = window.innerHeight;
286
+
287
+ function isInExpandedViewport(rect) {
288
+ if (!rect || (rect.width === 0 && rect.height === 0)) return false;
289
+ return rect.bottom > -VIEWPORT_EXPAND && rect.top < vh + VIEWPORT_EXPAND &&
290
+ rect.right > -VIEWPORT_EXPAND && rect.left < vw + VIEWPORT_EXPAND;
291
+ }
292
+
293
+ function isVisibleByCSS(el) {
294
+ const style = el.style;
295
+ if (style.display === 'none') return false;
296
+ if (style.visibility === 'hidden' || style.visibility === 'collapse') return false;
297
+ if (style.opacity === '0') return false;
298
+ try {
299
+ const cs = window.getComputedStyle(el);
300
+ if (cs.display === 'none') return false;
301
+ if (cs.visibility === 'hidden') return false;
302
+ if (parseFloat(cs.opacity) <= 0) return false;
303
+ if (cs.clip === 'rect(0px, 0px, 0px, 0px)' && cs.position === 'absolute') return false;
304
+ if (cs.overflow === 'hidden' && el.offsetWidth === 0 && el.offsetHeight === 0) return false;
305
+ } catch {}
306
+ return true;
307
+ }
308
+
309
+ // ── Paint Order Occlusion ──────────────────────────────────────────
310
+
311
+ function isOccludedByOverlay(el) {
312
+ if (!PAINT_ORDER_CHECK) return false;
313
+ try {
314
+ const rect = el.getBoundingClientRect();
315
+ if (rect.width === 0 || rect.height === 0) return false;
316
+ const cx = rect.left + rect.width / 2;
317
+ const cy = rect.top + rect.height / 2;
318
+ if (cx < 0 || cy < 0 || cx > vw || cy > vh) return false;
319
+ const topEl = document.elementFromPoint(cx, cy);
320
+ if (!topEl || topEl === el || el.contains(topEl) || topEl.contains(el)) return false;
321
+ const cs = window.getComputedStyle(topEl);
322
+ if (parseFloat(cs.opacity) < 0.5) return false;
323
+ const bg = cs.backgroundColor;
324
+ if (bg === 'rgba(0, 0, 0, 0)' || bg === 'transparent') return false;
325
+ return true;
326
+ } catch { return false; }
327
+ }
328
+
329
+ // ── Ad/Noise Detection ─────────────────────────────────────────────
330
+
331
+ function isAdElement(el) {
332
+ if (!FILTER_ADS) return false;
333
+ try {
334
+ const id = el.id || '';
335
+ const cls = el.className || '';
336
+ const testStr = id + ' ' + (typeof cls === 'string' ? cls : '');
337
+ if (AD_SELECTOR_RE.test(testStr)) return true;
338
+ if (el.tagName === 'IFRAME') {
339
+ const src = el.src || '';
340
+ for (const p of AD_PATTERNS) { if (src.includes(p)) return true; }
341
+ }
342
+ if (el.hasAttribute('data-ad') || el.hasAttribute('data-ad-slot') ||
343
+ el.hasAttribute('data-adunit') || el.hasAttribute('data-google-query-id')) return true;
344
+ } catch {}
345
+ return false;
346
+ }
347
+
348
+ // ── Interactivity Detection ────────────────────────────────────────
349
+
350
+ // Check if element contains a form control within limited depth (handles label/span wrappers)
351
+ function hasFormControlDescendant(el, maxDepth = 2) {
352
+ if (maxDepth <= 0) return false;
353
+ for (const child of el.children || []) {
354
+ const tag = child.tagName?.toLowerCase();
355
+ if (tag === 'input' || tag === 'select' || tag === 'textarea') return true;
356
+ if (hasFormControlDescendant(child, maxDepth - 1)) return true;
357
+ }
358
+ return false;
359
+ }
360
+
361
+ function isInteractive(el) {
362
+ const tag = el.tagName.toLowerCase();
363
+ if (INTERACTIVE_TAGS.has(tag)) {
364
+ // Skip labels that proxy via "for" to avoid double-activating external inputs
365
+ if (tag === 'label') {
366
+ if (el.hasAttribute('for')) return false;
367
+ // Detect labels that wrap form controls up to two levels deep (label > span > input)
368
+ if (hasFormControlDescendant(el, 2)) return true;
369
+ }
370
+ if (el.disabled && (tag === 'button' || tag === 'input')) return false;
371
+ return true;
372
+ }
373
+ // Span wrappers for UI components - check if they contain form controls
374
+ if (tag === 'span') {
375
+ if (hasFormControlDescendant(el, 2)) return true;
376
+ }
377
+ const role = el.getAttribute('role');
378
+ if (role && INTERACTIVE_ROLES.has(role)) return true;
379
+ if (el.hasAttribute('onclick') || el.hasAttribute('onmousedown') || el.hasAttribute('ontouchstart')) return true;
380
+ if (el.hasAttribute('tabindex') && el.getAttribute('tabindex') !== '-1') return true;
381
+ // Framework event listener detection (React/Vue/Angular onClick)
382
+ if (hasFrameworkListener(el)) return true;
383
+ try { if (window.getComputedStyle(el).cursor === 'pointer') return true; } catch {}
384
+ if (el.isContentEditable && el.getAttribute('contenteditable') !== 'false') return true;
385
+ // Search element heuristic detection
386
+ if (isSearchElement(el)) return true;
387
+ return false;
388
+ }
389
+
390
+ function hasFrameworkListener(el) {
391
+ try {
392
+ // React: __reactProps$xxx / __reactEvents$xxx with onClick/onMouseDown
393
+ for (const key of Object.keys(el)) {
394
+ if (key.startsWith('__reactProps$') || key.startsWith('__reactEvents$')) {
395
+ const props = el[key];
396
+ if (props && (props.onClick || props.onMouseDown || props.onPointerDown)) return true;
397
+ }
398
+ }
399
+ // Vue 3: _vei (Vue Event Invoker) with onClick
400
+ if (el._vei && (el._vei.onClick || el._vei.click || el._vei.onMousedown)) return true;
401
+ // Vue 2: __vue__ instance with $listeners
402
+ if (el.__vue__?.$listeners?.click) return true;
403
+ // Angular: ng-reflect-click binding
404
+ if (el.hasAttribute('ng-reflect-click')) return true;
405
+ } catch { /* ignore errors from cross-origin or frozen objects */ }
406
+ return false;
407
+ }
408
+
409
+ function isSearchElement(el) {
410
+ // Check class names for search indicators
411
+ // Note: SVG elements have className as SVGAnimatedString (not a string), use baseVal
412
+ const className = (typeof el.className === 'string' ? el.className : el.className?.baseVal || '').toLowerCase();
413
+ const classes = className.split(/\\s+/).filter(Boolean);
414
+ for (const cls of classes) {
415
+ const cleaned = cls.replace(/[^a-z0-9-]/g, '');
416
+ if (SEARCH_INDICATORS.has(cleaned)) return true;
417
+ }
418
+ // Check id for search indicators
419
+ const id = el.id?.toLowerCase() || '';
420
+ const cleanedId = id.replace(/[^a-z0-9-]/g, '');
421
+ if (SEARCH_INDICATORS.has(cleanedId)) return true;
422
+ // Check data-* attributes for search functionality
423
+ for (const attr of el.attributes || []) {
424
+ if (attr.name.startsWith('data-')) {
425
+ const value = attr.value.toLowerCase();
426
+ for (const kw of SEARCH_INDICATORS) {
427
+ if (value.includes(kw)) return true;
428
+ }
429
+ }
430
+ }
431
+ return false;
432
+ }
433
+
434
+ function isLandmark(el) {
435
+ const role = el.getAttribute('role');
436
+ if (role && LANDMARK_ROLES.has(role)) return true;
437
+ return LANDMARK_TAGS.has(el.tagName.toLowerCase());
438
+ }
439
+
440
+ // ── Scrollability Detection ────────────────────────────────────────
441
+
442
+ function getScrollInfo(el) {
443
+ if (!INCLUDE_SCROLL_INFO) return null;
444
+ const sh = el.scrollHeight, ch = el.clientHeight;
445
+ const sw = el.scrollWidth, cw = el.clientWidth;
446
+ const isV = sh > ch + 5, isH = sw > cw + 5;
447
+ if (!isV && !isH) return null;
448
+ try {
449
+ const cs = window.getComputedStyle(el);
450
+ const scrollable = ['auto', 'scroll', 'overlay'];
451
+ const tag = el.tagName.toLowerCase();
452
+ const isBody = tag === 'body' || tag === 'html';
453
+ if (isV && !isBody && !scrollable.includes(cs.overflowY)) return null;
454
+ const info = {};
455
+ if (isV) {
456
+ const above = ch > 0 ? +(el.scrollTop / ch).toFixed(1) : 0;
457
+ const below = ch > 0 ? +((sh - ch - el.scrollTop) / ch).toFixed(1) : 0;
458
+ if (above > 0 || below > 0) info.v = { above, below };
459
+ }
460
+ if (isH && scrollable.includes(cs.overflowX)) {
461
+ info.h = { pct: cw > 0 ? Math.round(el.scrollLeft / (sw - cw) * 100) : 0 };
462
+ }
463
+ return Object.keys(info).length > 0 ? info : null;
464
+ } catch { return null; }
465
+ }
466
+
467
+ // ── BBox Containment Check ─────────────────────────────────────────
468
+
469
+ function isContainedBy(childRect, parentRect, threshold) {
470
+ if (!childRect || !parentRect) return false;
471
+ const cArea = childRect.width * childRect.height;
472
+ if (cArea === 0) return false;
473
+ const xO = Math.max(0, Math.min(childRect.right, parentRect.right) - Math.max(childRect.left, parentRect.left));
474
+ const yO = Math.max(0, Math.min(childRect.bottom, parentRect.bottom) - Math.max(childRect.top, parentRect.top));
475
+ return (xO * yO) / cArea >= threshold;
476
+ }
477
+
478
+ // ── Text Helpers ───────────────────────────────────────────────────
479
+
480
+ function getDirectText(el) {
481
+ let text = '';
482
+ for (const child of el.childNodes) {
483
+ if (child.nodeType === 3) {
484
+ const t = child.textContent.trim();
485
+ if (t) text += (text ? ' ' : '') + t;
486
+ }
487
+ }
488
+ return text;
489
+ }
490
+
491
+ function capText(s) {
492
+ if (!s) return '';
493
+ const t = s.replace(/\\s+/g, ' ').trim();
494
+ return t.length > MAX_TEXT_LEN ? t.slice(0, MAX_TEXT_LEN) + '…' : t;
495
+ }
496
+
497
+ // ── Element Hashing (for incremental diff) ─────────────────────────
498
+
499
+ function hashElement(el) {
500
+ // Simple hash: tag + id + className + textContent prefix
501
+ const tag = el.tagName || '';
502
+ const id = el.id || '';
503
+ const cls = (typeof el.className === 'string' ? el.className : '').slice(0, 50);
504
+ const text = (el.textContent || '').trim().slice(0, 40);
505
+ const s = tag + '|' + id + '|' + cls + '|' + text;
506
+ let h = 0;
507
+ for (let i = 0; i < s.length; i++) {
508
+ h = ((h << 5) - h + s.charCodeAt(i)) | 0;
509
+ }
510
+ return '' + (h >>> 0); // unsigned
511
+ }
512
+
513
+ // ── Attribute Serialization ────────────────────────────────────────
514
+
515
+ function serializeAttrs(el) {
516
+ const parts = [];
517
+ for (const attr of el.attributes) {
518
+ if (!ATTR_WHITELIST.has(attr.name)) continue;
519
+ let val = attr.value.trim();
520
+ if (!val) continue;
521
+ if (val.length > 120) val = val.slice(0, 100) + '…';
522
+ if (attr.name === 'type' && val.toLowerCase() === el.tagName.toLowerCase()) continue;
523
+ if (attr.name === 'value' && el.getAttribute('type') === 'password') { parts.push('value=••••'); continue; }
524
+ if (attr.name === 'href') {
525
+ if (val.startsWith('javascript:')) continue;
526
+ try {
527
+ const u = new URL(val, location.origin);
528
+ if (u.origin === location.origin) val = u.pathname + u.search + u.hash;
529
+ } catch {}
530
+ }
531
+ parts.push(attr.name + '=' + val);
532
+ }
533
+ // Synthetic attributes
534
+ const tag = el.tagName;
535
+ if (tag === 'INPUT') {
536
+ const type = (el.getAttribute('type') || 'text').toLowerCase();
537
+ const fmts = { 'date':'YYYY-MM-DD', 'time':'HH:MM', 'datetime-local':'YYYY-MM-DDTHH:MM', 'month':'YYYY-MM', 'week':'YYYY-W##' };
538
+ if (fmts[type]) parts.push('format=' + fmts[type]);
539
+ if (['text','email','tel','url','search','number','date','time','datetime-local','month','week'].includes(type)) {
540
+ if (el.value && !parts.some(p => p.startsWith('value='))) parts.push('value=' + capText(el.value));
541
+ }
542
+ if (type === 'password' && el.value && !parts.some(p => p.startsWith('value='))) parts.push('value=••••');
543
+ if ((type === 'checkbox' || type === 'radio') && el.checked && !parts.some(p => p.startsWith('checked'))) parts.push('checked');
544
+ if (type === 'file' && el.files && el.files.length > 0) parts.push('files=' + Array.from(el.files).map(f => f.name).join(','));
545
+ }
546
+ if (tag === 'TEXTAREA' && el.value && !parts.some(p => p.startsWith('value='))) parts.push('value=' + capText(el.value));
547
+ if (tag === 'SELECT') {
548
+ const sel = el.options?.[el.selectedIndex];
549
+ if (sel && !parts.some(p => p.startsWith('value='))) parts.push('value=' + capText(sel.textContent));
550
+ const optEls = Array.from(el.options || []).slice(0, 6);
551
+ if (optEls.length > 0) {
552
+ const ot = optEls.map(o => capText(o.textContent).slice(0, 30));
553
+ if (el.options.length > 6) ot.push('…' + (el.options.length - 6) + ' more');
554
+ parts.push('options=[' + ot.join('|') + ']');
555
+ }
556
+ }
557
+ return parts.join(' ');
558
+ }
559
+
560
+ // ── Table → Markdown Serialization ─────────────────────────────────
561
+
562
+ function serializeTable(table, depth) {
563
+ if (!MARKDOWN_TABLES) return false;
564
+ try {
565
+ const rows = table.querySelectorAll('tr');
566
+ if (rows.length === 0 || rows.length > 50) return false; // skip huge tables
567
+ const grid = [];
568
+ let maxCols = 0;
569
+ for (const row of rows) {
570
+ const cells = [];
571
+ for (const cell of row.querySelectorAll('th, td')) {
572
+ let text = capText(cell.textContent || '');
573
+ // Include interactive elements in cells
574
+ const links = cell.querySelectorAll('a[href]');
575
+ if (links.length === 1 && text) {
576
+ const href = links[0].getAttribute('href');
577
+ if (href && !href.startsWith('javascript:')) {
578
+ try {
579
+ const u = new URL(href, location.origin);
580
+ text = '[' + text + '](' + (u.origin === location.origin ? u.pathname + u.search : href) + ')';
581
+ } catch { text = '[' + text + '](' + href + ')'; }
582
+ }
583
+ }
584
+ cells.push(text || '');
585
+ }
586
+ if (cells.length > 0) {
587
+ grid.push(cells);
588
+ if (cells.length > maxCols) maxCols = cells.length;
589
+ }
590
+ }
591
+ if (grid.length < 2 || maxCols === 0) return false; // need at least header + 1 row
592
+ // Pad rows to maxCols
593
+ for (const row of grid) { while (row.length < maxCols) row.push(''); }
594
+ // Compute column widths
595
+ const widths = [];
596
+ for (let c = 0; c < maxCols; c++) {
597
+ let w = 3;
598
+ for (const row of grid) { if (row[c].length > w) w = Math.min(row[c].length, 40); }
599
+ widths.push(w);
600
+ }
601
+ const indent = ' '.repeat(depth);
602
+ const tableLines = [];
603
+ // Header
604
+ tableLines.push(indent + '| ' + grid[0].map((c, i) => c.padEnd(widths[i])).join(' | ') + ' |');
605
+ tableLines.push(indent + '| ' + widths.map(w => '-'.repeat(w)).join(' | ') + ' |');
606
+ // Body
607
+ for (let r = 1; r < grid.length; r++) {
608
+ tableLines.push(indent + '| ' + grid[r].map((c, i) => c.padEnd(widths[i])).join(' | ') + ' |');
609
+ }
610
+ return tableLines;
611
+ } catch { return false; }
612
+ }
613
+
614
+ // ── Main Tree Walk ─────────────────────────────────────────────────
615
+
616
+ let interactiveIndex = 0;
617
+ const lines = [];
618
+ const hiddenInteractives = [];
619
+ const currentHashes = [];
620
+ const refIdentity = {};
621
+ const compoundInfos = {};
622
+ let iframeCount = 0;
623
+ let crossOriginIndex = 0;
624
+
625
+ function walk(el, depth, parentPropagatingRect) {
626
+ if (depth > MAX_DEPTH) return false;
627
+ if (el.nodeType !== 1) return false;
628
+
629
+ const tag = el.tagName.toLowerCase();
630
+ if (SKIP_TAGS.has(tag)) return false;
631
+ if (isAdElement(el)) return false;
632
+
633
+ // SVG: emit tag, collapse children
634
+ if (tag === 'svg') {
635
+ const attrs = serializeAttrs(el);
636
+ const interactive = isInteractive(el);
637
+ let prefix = '';
638
+ if (interactive) {
639
+ interactiveIndex++;
640
+ if (ANNOTATE_REFS) el.setAttribute('data-webcmd-ref', '' + interactiveIndex);
641
+ prefix = '[' + interactiveIndex + ']';
642
+ }
643
+ lines.push(' '.repeat(depth) + prefix + '<svg' + (attrs ? ' ' + attrs : '') + ' />');
644
+ return interactive;
645
+ }
646
+ if (SVG_CHILDREN.has(tag)) return false;
647
+
648
+ // Table: try markdown serialization before generic walk
649
+ if (tag === 'table' && MARKDOWN_TABLES) {
650
+ const tableLines = serializeTable(el, depth);
651
+ if (tableLines) {
652
+ const indent = ' '.repeat(depth);
653
+ lines.push(indent + '|table|');
654
+ for (const tl of tableLines) lines.push(tl);
655
+ return false; // tables usually non-interactive
656
+ }
657
+ // Fall through to generic walk if markdown failed
658
+ }
659
+
660
+ // iframe handling
661
+ if (tag === 'iframe' && INCLUDE_IFRAMES && iframeCount < MAX_IFRAMES) {
662
+ return walkIframe(el, depth);
663
+ }
664
+
665
+ // Visibility check
666
+ let rect;
667
+ try { rect = el.getBoundingClientRect(); } catch { return false; }
668
+ const hasArea = rect.width > 0 && rect.height > 0;
669
+ if (hasArea && !isVisibleByCSS(el)) {
670
+ if (!(tag === 'input' && el.type === 'file')) return false;
671
+ }
672
+
673
+ // \`interactive\` gets demoted below if bbox containment folds this node
674
+ // into a propagating ancestor — using \`let\` so the dedup pass can mutate it.
675
+ let interactive = isInteractive(el);
676
+
677
+ // Viewport threshold pruning
678
+ if (hasArea && !isInExpandedViewport(rect)) {
679
+ if (interactive && REPORT_HIDDEN) {
680
+ const scrollDist = rect.top > vh ? rect.top - vh : -rect.bottom;
681
+ const pagesAway = Math.abs(scrollDist / vh).toFixed(1);
682
+ const direction = rect.top > vh ? 'below' : 'above';
683
+ const text = capText(getDirectText(el) || el.getAttribute('aria-label') || el.getAttribute('title') || '');
684
+ hiddenInteractives.push({ tag, text, direction, pagesAway });
685
+ }
686
+ return false;
687
+ }
688
+
689
+ // Paint order occlusion
690
+ if (interactive && hasArea && isOccludedByOverlay(el)) return false;
691
+
692
+ const landmark = isLandmark(el);
693
+ const scrollInfo = getScrollInfo(el);
694
+ const isScrollable = scrollInfo !== null;
695
+
696
+ // BBox dedup — tier 1 (non-interactive descendants, 0.95 threshold)
697
+ let excludedByParent = false;
698
+ if (BBOX_DEDUP && parentPropagatingRect && !interactive) {
699
+ if (hasArea && isContainedBy(rect, parentPropagatingRect, 0.95)) {
700
+ const hasSemantic = el.hasAttribute('aria-label') ||
701
+ (el.getAttribute('role') && INTERACTIVE_ROLES.has(el.getAttribute('role')));
702
+ if (!hasSemantic && !['input','select','textarea','label'].includes(tag)) {
703
+ excludedByParent = true;
704
+ }
705
+ }
706
+ }
707
+
708
+ // BBox dedup — tier 2 (interactive descendants, 0.99 threshold, browser-use style).
709
+ // This kills the "[1]<button> [2]<svg> [3]<span>" noise on icon-buttons by
710
+ // folding the icon / chevron into the button's ref. The 0.99 threshold + the
711
+ // isDistinctivelyInteractive gate together ensure we only drop nodes that
712
+ // add no new actionable surface — a nested <input> or <a href> stays.
713
+ if (BBOX_DEDUP && parentPropagatingRect && interactive && hasArea) {
714
+ if (isContainedBy(rect, parentPropagatingRect, 0.99) && !isDistinctivelyInteractive(el)) {
715
+ interactive = false;
716
+ }
717
+ }
718
+
719
+ let propagateRect = parentPropagatingRect;
720
+ if (BBOX_DEDUP && hasArea && isBboxPropagator(el, tag)) propagateRect = rect;
721
+
722
+ // Process children
723
+ const origLen = lines.length;
724
+ let hasInteractiveDescendant = false;
725
+
726
+ for (const child of el.children) {
727
+ const r = walk(child, depth + 1, propagateRect);
728
+ if (r) hasInteractiveDescendant = true;
729
+ }
730
+
731
+ // Shadow DOM
732
+ if (INCLUDE_SHADOW_DOM && el.shadowRoot) {
733
+ const shadowOrigLen = lines.length;
734
+ for (const child of el.shadowRoot.children) {
735
+ const r = walk(child, depth + 1, propagateRect);
736
+ if (r) hasInteractiveDescendant = true;
737
+ }
738
+ if (lines.length > shadowOrigLen) {
739
+ lines.splice(shadowOrigLen, 0, ' '.repeat(depth + 1) + '|shadow|');
740
+ }
741
+ }
742
+
743
+ const childLinesCount = lines.length - origLen;
744
+ const text = capText(getDirectText(el));
745
+
746
+ // Decide whether to emit
747
+ if (INTERACTIVE_ONLY && !interactive && !landmark && !hasInteractiveDescendant && !text) {
748
+ lines.length = origLen;
749
+ return false;
750
+ }
751
+ if (excludedByParent && !interactive && !isScrollable) return hasInteractiveDescendant;
752
+ if (!interactive && !isScrollable && !text && childLinesCount === 0 && !landmark) return false;
753
+
754
+ // ── Emit node ────────────────────────────────────────────────────
755
+ const indent = ' '.repeat(depth);
756
+ let line = indent;
757
+
758
+ // Incremental diff: mark new elements with *
759
+ if (PREV_HASHES) {
760
+ const h = hashElement(el);
761
+ currentHashes.push(h);
762
+ if (!PREV_HASHES.has(h)) line += '*';
763
+ } else {
764
+ currentHashes.push(hashElement(el));
765
+ }
766
+
767
+ // Scroll marker
768
+ if (isScrollable && !interactive) line += '|scroll|';
769
+
770
+ // Interactive index + data-ref + fingerprint
771
+ if (interactive) {
772
+ interactiveIndex++;
773
+ if (ANNOTATE_REFS) el.setAttribute('data-webcmd-ref', '' + interactiveIndex);
774
+ line += isScrollable ? '|scroll[' + interactiveIndex + ']|' : '[' + interactiveIndex + ']';
775
+ // Store fingerprint for stale-ref detection
776
+ refIdentity['' + interactiveIndex] = {
777
+ tag: tag,
778
+ role: el.getAttribute('role') || '',
779
+ text: (el.textContent || '').trim().slice(0, 30),
780
+ ariaLabel: el.getAttribute('aria-label') || '',
781
+ id: el.id || '',
782
+ testId: el.getAttribute('data-testid') || el.getAttribute('data-test') || '',
783
+ };
784
+ // Compound contract for date/select/file — captured per-ref so the
785
+ // sidecar maps one-to-one with the [N] tokens in the tree.
786
+ const compound = compoundInfoOf(el);
787
+ if (compound) compoundInfos['' + interactiveIndex] = compound;
788
+ }
789
+
790
+ // Tag + attributes
791
+ const attrs = serializeAttrs(el);
792
+ line += '<' + tag;
793
+ if (attrs) line += ' ' + attrs;
794
+
795
+ // Scroll info suffix, inline text, or self-close
796
+ if (isScrollable && scrollInfo) {
797
+ const parts = [];
798
+ if (scrollInfo.v) parts.push(scrollInfo.v.above + '↑ ' + scrollInfo.v.below + '↓');
799
+ if (scrollInfo.h) parts.push('h:' + scrollInfo.h.pct + '%');
800
+ line += ' /> (' + parts.join(', ') + ')';
801
+ } else if (text && childLinesCount === 0) {
802
+ line += '>' + text + '</' + tag + '>';
803
+ } else {
804
+ line += ' />';
805
+ }
806
+
807
+ lines.splice(origLen, 0, line);
808
+ if (text && childLinesCount > 0) lines.splice(origLen + 1, 0, indent + ' ' + text);
809
+
810
+ return interactive || hasInteractiveDescendant;
811
+ }
812
+
813
+ // ── iframe Processing ──────────────────────────────────────────────
814
+
815
+ function walkIframe(el, depth) {
816
+ const indent = ' '.repeat(depth);
817
+ try {
818
+ const doc = el.contentDocument;
819
+ if (!doc || !doc.body) {
820
+ const attrs = serializeAttrs(el);
821
+ const frameLabel = '[F' + crossOriginIndex + ']';
822
+ lines.push(indent + '|iframe|' + frameLabel + '<iframe' + (attrs ? ' ' + attrs : '') + ' /> (cross-origin, use: webcmd browser frames + browser eval --frame <index>)');
823
+ crossOriginIndex++;
824
+ return false;
825
+ }
826
+ iframeCount++;
827
+ const attrs = serializeAttrs(el);
828
+ lines.push(indent + '|iframe|<iframe' + (attrs ? ' ' + attrs : '') + ' />');
829
+ let has = false;
830
+ for (const child of doc.body.children) {
831
+ if (walk(child, depth + 1, null)) has = true;
832
+ }
833
+ return has;
834
+ } catch {
835
+ const attrs = serializeAttrs(el);
836
+ const frameLabel = '[F' + crossOriginIndex + ']';
837
+ lines.push(indent + '|iframe|' + frameLabel + '<iframe' + (attrs ? ' ' + attrs : '') + ' /> (blocked, use: webcmd browser frames + browser eval --frame <index>)');
838
+ crossOriginIndex++;
839
+ return false;
840
+ }
841
+ }
842
+
843
+ // ── Entry Point ────────────────────────────────────────────────────
844
+
845
+ lines.push('url: ' + location.href);
846
+ lines.push('title: ' + document.title);
847
+ lines.push('viewport: ' + vw + 'x' + vh);
848
+ const pageScrollInfo = getScrollInfo(document.documentElement) || getScrollInfo(document.body);
849
+ if (pageScrollInfo && pageScrollInfo.v) {
850
+ lines.push('page_scroll: ' + pageScrollInfo.v.above + '↑ ' + pageScrollInfo.v.below + '↓');
851
+ }
852
+ lines.push('---');
853
+
854
+ const root = document.body || document.documentElement;
855
+ if (root) walk(root, 0, null);
856
+
857
+ // Hidden interactive elements hint
858
+ if (REPORT_HIDDEN && hiddenInteractives.length > 0) {
859
+ lines.push('---');
860
+ lines.push('hidden_interactive (' + hiddenInteractives.length + '):');
861
+ const shown = hiddenInteractives.slice(0, 10);
862
+ for (const h of shown) {
863
+ const label = h.text ? ' "' + h.text + '"' : '';
864
+ lines.push(' <' + h.tag + '>' + label + ' ~' + h.pagesAway + ' pages ' + h.direction);
865
+ }
866
+ if (hiddenInteractives.length > 10) lines.push(' …' + (hiddenInteractives.length - 10) + ' more');
867
+ }
868
+
869
+ // Compound sidecar — rich JSON for date/select/file refs. Keys align with [N] tokens in the tree.
870
+ const compoundRefs = Object.keys(compoundInfos);
871
+ if (compoundRefs.length > 0) {
872
+ lines.push('---');
873
+ lines.push('compounds (' + compoundRefs.length + '):');
874
+ compoundRefs.sort(function (a, b) { return parseInt(a, 10) - parseInt(b, 10); });
875
+ for (const ref of compoundRefs) {
876
+ try {
877
+ lines.push(' [' + ref + '] ' + JSON.stringify(compoundInfos[ref]));
878
+ } catch {}
879
+ }
880
+ }
881
+
882
+ // Footer
883
+ lines.push('---');
884
+ lines.push('interactive: ' + interactiveIndex + ' | iframes: ' + iframeCount);
885
+
886
+ // Store hashes on window for next diff snapshot
887
+ try { window.__webcmd_prev_hashes = JSON.stringify(currentHashes); } catch {}
888
+ // Store ref identity map for stale-ref detection by target resolver
889
+ try { window.__webcmd_ref_identity = refIdentity; } catch {}
890
+
891
+ return lines.join('\\n');
892
+ })()
893
+ `.trim();
894
+ }