@tangle-network/browser-agent-driver 0.33.3 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (489) hide show
  1. package/README.md +42 -1
  2. package/discovery/llms.txt +27 -0
  3. package/discovery/tangle-agent.json +36 -0
  4. package/dist/brain/action-parse.d.ts +16 -0
  5. package/dist/brain/action-parse.d.ts.map +1 -0
  6. package/dist/brain/action-parse.js +191 -0
  7. package/dist/brain/action-parse.js.map +1 -0
  8. package/dist/brain/decide.d.ts +58 -0
  9. package/dist/brain/decide.d.ts.map +1 -0
  10. package/dist/brain/decide.js +418 -0
  11. package/dist/brain/decide.js.map +1 -0
  12. package/dist/brain/history-compact.d.ts +19 -0
  13. package/dist/brain/history-compact.d.ts.map +1 -0
  14. package/dist/brain/history-compact.js +153 -0
  15. package/dist/brain/history-compact.js.map +1 -0
  16. package/dist/brain/index.d.ts +78 -152
  17. package/dist/brain/index.d.ts.map +1 -1
  18. package/dist/brain/index.js +62 -2268
  19. package/dist/brain/index.js.map +1 -1
  20. package/dist/brain/model-client.d.ts +101 -0
  21. package/dist/brain/model-client.d.ts.map +1 -0
  22. package/dist/brain/model-client.js +391 -0
  23. package/dist/brain/model-client.js.map +1 -0
  24. package/dist/brain/plan.d.ts +57 -0
  25. package/dist/brain/plan.d.ts.map +1 -0
  26. package/dist/brain/plan.js +194 -0
  27. package/dist/brain/plan.js.map +1 -0
  28. package/dist/brain/prompts.d.ts +37 -0
  29. package/dist/brain/prompts.d.ts.map +1 -0
  30. package/dist/brain/prompts.js +455 -0
  31. package/dist/brain/prompts.js.map +1 -0
  32. package/dist/brain/provider-fetch.d.ts +26 -0
  33. package/dist/brain/provider-fetch.d.ts.map +1 -0
  34. package/dist/brain/provider-fetch.js +45 -0
  35. package/dist/brain/provider-fetch.js.map +1 -0
  36. package/dist/brain/snapshot-budget.d.ts +20 -0
  37. package/dist/brain/snapshot-budget.d.ts.map +1 -0
  38. package/dist/brain/snapshot-budget.js +202 -0
  39. package/dist/brain/snapshot-budget.js.map +1 -0
  40. package/dist/brain/system-prompt.d.ts +67 -0
  41. package/dist/brain/system-prompt.d.ts.map +1 -0
  42. package/dist/brain/system-prompt.js +128 -0
  43. package/dist/brain/system-prompt.js.map +1 -0
  44. package/dist/brain/tasks/design-audit.d.ts +33 -0
  45. package/dist/brain/tasks/design-audit.d.ts.map +1 -0
  46. package/dist/brain/tasks/design-audit.js +100 -0
  47. package/dist/brain/tasks/design-audit.js.map +1 -0
  48. package/dist/brain/tasks/evaluate.d.ts +25 -0
  49. package/dist/brain/tasks/evaluate.d.ts.map +1 -0
  50. package/dist/brain/tasks/evaluate.js +55 -0
  51. package/dist/brain/tasks/evaluate.js.map +1 -0
  52. package/dist/brain/tasks/goal-verification.d.ts +32 -0
  53. package/dist/brain/tasks/goal-verification.d.ts.map +1 -0
  54. package/dist/brain/tasks/goal-verification.js +68 -0
  55. package/dist/brain/tasks/goal-verification.js.map +1 -0
  56. package/dist/brain/tasks/knowledge.d.ts +26 -0
  57. package/dist/brain/tasks/knowledge.d.ts.map +1 -0
  58. package/dist/brain/tasks/knowledge.js +56 -0
  59. package/dist/brain/tasks/knowledge.js.map +1 -0
  60. package/dist/brain/tasks/link-scout.d.ts +37 -0
  61. package/dist/brain/tasks/link-scout.d.ts.map +1 -0
  62. package/dist/brain/tasks/link-scout.js +69 -0
  63. package/dist/brain/tasks/link-scout.js.map +1 -0
  64. package/dist/brain/types.d.ts +55 -0
  65. package/dist/brain/types.d.ts.map +1 -0
  66. package/dist/brain/types.js +7 -0
  67. package/dist/brain/types.js.map +1 -0
  68. package/dist/browser/stealth-init-script.d.ts +9 -0
  69. package/dist/browser/stealth-init-script.d.ts.map +1 -0
  70. package/dist/browser/stealth-init-script.js +128 -0
  71. package/dist/browser/stealth-init-script.js.map +1 -0
  72. package/dist/browser/storage-state.d.ts +29 -0
  73. package/dist/browser/storage-state.d.ts.map +1 -0
  74. package/dist/browser/storage-state.js +47 -0
  75. package/dist/browser/storage-state.js.map +1 -0
  76. package/dist/browser-launch.d.ts +6 -0
  77. package/dist/browser-launch.d.ts.map +1 -1
  78. package/dist/browser-launch.js +3 -0
  79. package/dist/browser-launch.js.map +1 -1
  80. package/dist/cli/args.d.ts +141 -0
  81. package/dist/cli/args.d.ts.map +1 -0
  82. package/dist/cli/args.js +167 -0
  83. package/dist/cli/args.js.map +1 -0
  84. package/dist/cli/benchmark-sync.d.ts +9 -0
  85. package/dist/cli/benchmark-sync.d.ts.map +1 -0
  86. package/dist/cli/benchmark-sync.js +43 -0
  87. package/dist/cli/benchmark-sync.js.map +1 -0
  88. package/dist/cli/build-config.d.ts +11 -0
  89. package/dist/cli/build-config.d.ts.map +1 -0
  90. package/dist/cli/build-config.js +355 -0
  91. package/dist/cli/build-config.js.map +1 -0
  92. package/dist/cli/commands/auth.d.ts +3 -0
  93. package/dist/cli/commands/auth.d.ts.map +1 -0
  94. package/dist/cli/commands/auth.js +36 -0
  95. package/dist/cli/commands/auth.js.map +1 -0
  96. package/dist/cli/commands/chrome-debug.d.ts +7 -0
  97. package/dist/cli/commands/chrome-debug.d.ts.map +1 -0
  98. package/dist/cli/commands/chrome-debug.js +11 -0
  99. package/dist/cli/commands/chrome-debug.js.map +1 -0
  100. package/dist/cli/commands/design-audit.d.ts +3 -0
  101. package/dist/cli/commands/design-audit.d.ts.map +1 -0
  102. package/dist/cli/commands/design-audit.js +68 -0
  103. package/dist/cli/commands/design-audit.js.map +1 -0
  104. package/dist/cli/commands/preview.d.ts +14 -0
  105. package/dist/cli/commands/preview.d.ts.map +1 -0
  106. package/dist/cli/commands/preview.js +31 -0
  107. package/dist/cli/commands/preview.js.map +1 -0
  108. package/dist/cli/commands/run.d.ts +3 -0
  109. package/dist/cli/commands/run.d.ts.map +1 -0
  110. package/dist/cli/commands/run.js +740 -0
  111. package/dist/cli/commands/run.js.map +1 -0
  112. package/dist/cli/commands/runs.d.ts +8 -0
  113. package/dist/cli/commands/runs.d.ts.map +1 -0
  114. package/dist/cli/commands/runs.js +35 -0
  115. package/dist/cli/commands/runs.js.map +1 -0
  116. package/dist/cli/commands/share.d.ts +10 -0
  117. package/dist/cli/commands/share.d.ts.map +1 -0
  118. package/dist/cli/commands/share.js +32 -0
  119. package/dist/cli/commands/share.js.map +1 -0
  120. package/dist/cli/commands/showcase.d.ts +17 -0
  121. package/dist/cli/commands/showcase.d.ts.map +1 -0
  122. package/dist/cli/commands/showcase.js +20 -0
  123. package/dist/cli/commands/showcase.js.map +1 -0
  124. package/dist/cli/commands/snapshot.d.ts +12 -0
  125. package/dist/cli/commands/snapshot.d.ts.map +1 -0
  126. package/dist/cli/commands/snapshot.js +24 -0
  127. package/dist/cli/commands/snapshot.js.map +1 -0
  128. package/dist/cli/commands/view.d.ts +7 -0
  129. package/dist/cli/commands/view.d.ts.map +1 -0
  130. package/dist/cli/commands/view.js +23 -0
  131. package/dist/cli/commands/view.js.map +1 -0
  132. package/dist/cli/constants.d.ts +6 -0
  133. package/dist/cli/constants.d.ts.map +1 -0
  134. package/dist/cli/constants.js +3 -0
  135. package/dist/cli/constants.js.map +1 -0
  136. package/dist/cli/version.d.ts +7 -0
  137. package/dist/cli/version.d.ts.map +1 -0
  138. package/dist/cli/version.js +16 -0
  139. package/dist/cli/version.js.map +1 -0
  140. package/dist/cli-design-audit.d.ts +44 -36
  141. package/dist/cli-design-audit.d.ts.map +1 -1
  142. package/dist/cli-design-audit.js +137 -1646
  143. package/dist/cli-design-audit.js.map +1 -1
  144. package/dist/cli-jobs.js +2 -1
  145. package/dist/cli-jobs.js.map +1 -1
  146. package/dist/cli.js +66 -1697
  147. package/dist/cli.js.map +1 -1
  148. package/dist/config.d.ts +12 -0
  149. package/dist/config.d.ts.map +1 -1
  150. package/dist/config.js +20 -2
  151. package/dist/config.js.map +1 -1
  152. package/dist/design/audit/evolve/agent.d.ts +23 -0
  153. package/dist/design/audit/evolve/agent.d.ts.map +1 -0
  154. package/dist/design/audit/evolve/agent.js +273 -0
  155. package/dist/design/audit/evolve/agent.js.map +1 -0
  156. package/dist/design/audit/evolve/css.d.ts +10 -0
  157. package/dist/design/audit/evolve/css.d.ts.map +1 -0
  158. package/dist/design/audit/evolve/css.js +206 -0
  159. package/dist/design/audit/evolve/css.js.map +1 -0
  160. package/dist/design/audit/evolve/index.d.ts +13 -0
  161. package/dist/design/audit/evolve/index.d.ts.map +1 -0
  162. package/dist/design/audit/evolve/index.js +12 -0
  163. package/dist/design/audit/evolve/index.js.map +1 -0
  164. package/dist/design/audit/evolve/report.d.ts +3 -0
  165. package/dist/design/audit/evolve/report.d.ts.map +1 -0
  166. package/dist/design/audit/evolve/report.js +45 -0
  167. package/dist/design/audit/evolve/report.js.map +1 -0
  168. package/dist/design/audit/evolve/types.d.ts +14 -0
  169. package/dist/design/audit/evolve/types.d.ts.map +1 -0
  170. package/dist/design/audit/evolve/types.js +2 -0
  171. package/dist/design/audit/evolve/types.js.map +1 -0
  172. package/dist/design/audit/pipeline.d.ts +12 -0
  173. package/dist/design/audit/pipeline.d.ts.map +1 -1
  174. package/dist/design/audit/pipeline.js +43 -27
  175. package/dist/design/audit/pipeline.js.map +1 -1
  176. package/dist/design/audit/reference/artifact/build.d.ts +33 -0
  177. package/dist/design/audit/reference/artifact/build.d.ts.map +1 -0
  178. package/dist/design/audit/reference/artifact/build.js +64 -0
  179. package/dist/design/audit/reference/artifact/build.js.map +1 -0
  180. package/dist/design/audit/reference/artifact/render.d.ts +39 -0
  181. package/dist/design/audit/reference/artifact/render.d.ts.map +1 -0
  182. package/dist/design/audit/reference/artifact/render.js +213 -0
  183. package/dist/design/audit/reference/artifact/render.js.map +1 -0
  184. package/dist/design/audit/reference/artifact/text.d.ts +11 -0
  185. package/dist/design/audit/reference/artifact/text.d.ts.map +1 -0
  186. package/dist/design/audit/reference/artifact/text.js +20 -0
  187. package/dist/design/audit/reference/artifact/text.js.map +1 -0
  188. package/dist/design/audit/reference/artifact/to-findings.d.ts +57 -0
  189. package/dist/design/audit/reference/artifact/to-findings.d.ts.map +1 -0
  190. package/dist/design/audit/reference/artifact/to-findings.js +314 -0
  191. package/dist/design/audit/reference/artifact/to-findings.js.map +1 -0
  192. package/dist/design/audit/reference/config.d.ts +50 -0
  193. package/dist/design/audit/reference/config.d.ts.map +1 -0
  194. package/dist/design/audit/reference/config.js +108 -0
  195. package/dist/design/audit/reference/config.js.map +1 -0
  196. package/dist/design/audit/reference/contracts.d.ts +1030 -0
  197. package/dist/design/audit/reference/contracts.d.ts.map +1 -0
  198. package/dist/design/audit/reference/contracts.js +28 -0
  199. package/dist/design/audit/reference/contracts.js.map +1 -0
  200. package/dist/design/audit/reference/corpus/build.d.ts +115 -0
  201. package/dist/design/audit/reference/corpus/build.d.ts.map +1 -0
  202. package/dist/design/audit/reference/corpus/build.js +152 -0
  203. package/dist/design/audit/reference/corpus/build.js.map +1 -0
  204. package/dist/design/audit/reference/corpus/schema.d.ts +33 -0
  205. package/dist/design/audit/reference/corpus/schema.d.ts.map +1 -0
  206. package/dist/design/audit/reference/corpus/schema.js +249 -0
  207. package/dist/design/audit/reference/corpus/schema.js.map +1 -0
  208. package/dist/design/audit/reference/corpus/store.d.ts +26 -0
  209. package/dist/design/audit/reference/corpus/store.d.ts.map +1 -0
  210. package/dist/design/audit/reference/corpus/store.js +104 -0
  211. package/dist/design/audit/reference/corpus/store.js.map +1 -0
  212. package/dist/design/audit/reference/dna/delta.d.ts +21 -0
  213. package/dist/design/audit/reference/dna/delta.d.ts.map +1 -0
  214. package/dist/design/audit/reference/dna/delta.js +126 -0
  215. package/dist/design/audit/reference/dna/delta.js.map +1 -0
  216. package/dist/design/audit/reference/dna/derive.d.ts +31 -0
  217. package/dist/design/audit/reference/dna/derive.d.ts.map +1 -0
  218. package/dist/design/audit/reference/dna/derive.js +381 -0
  219. package/dist/design/audit/reference/dna/derive.js.map +1 -0
  220. package/dist/design/audit/reference/dna/descriptor.d.ts +36 -0
  221. package/dist/design/audit/reference/dna/descriptor.d.ts.map +1 -0
  222. package/dist/design/audit/reference/dna/descriptor.js +209 -0
  223. package/dist/design/audit/reference/dna/descriptor.js.map +1 -0
  224. package/dist/design/audit/reference/dna/page-adapter.d.ts +17 -0
  225. package/dist/design/audit/reference/dna/page-adapter.d.ts.map +1 -0
  226. package/dist/design/audit/reference/dna/page-adapter.js +35 -0
  227. package/dist/design/audit/reference/dna/page-adapter.js.map +1 -0
  228. package/dist/design/audit/reference/dna/scroll-capture.d.ts +93 -0
  229. package/dist/design/audit/reference/dna/scroll-capture.d.ts.map +1 -0
  230. package/dist/design/audit/reference/dna/scroll-capture.js +374 -0
  231. package/dist/design/audit/reference/dna/scroll-capture.js.map +1 -0
  232. package/dist/design/audit/reference/engine/budget.d.ts +63 -0
  233. package/dist/design/audit/reference/engine/budget.d.ts.map +1 -0
  234. package/dist/design/audit/reference/engine/budget.js +110 -0
  235. package/dist/design/audit/reference/engine/budget.js.map +1 -0
  236. package/dist/design/audit/reference/engine/core.d.ts +32 -0
  237. package/dist/design/audit/reference/engine/core.d.ts.map +1 -0
  238. package/dist/design/audit/reference/engine/core.js +261 -0
  239. package/dist/design/audit/reference/engine/core.js.map +1 -0
  240. package/dist/design/audit/reference/engine/guard.d.ts +43 -0
  241. package/dist/design/audit/reference/engine/guard.d.ts.map +1 -0
  242. package/dist/design/audit/reference/engine/guard.js +43 -0
  243. package/dist/design/audit/reference/engine/guard.js.map +1 -0
  244. package/dist/design/audit/reference/engine/score-core.d.ts +48 -0
  245. package/dist/design/audit/reference/engine/score-core.d.ts.map +1 -0
  246. package/dist/design/audit/reference/engine/score-core.js +134 -0
  247. package/dist/design/audit/reference/engine/score-core.js.map +1 -0
  248. package/dist/design/audit/reference/engine/wiring.d.ts +35 -0
  249. package/dist/design/audit/reference/engine/wiring.d.ts.map +1 -0
  250. package/dist/design/audit/reference/engine/wiring.js +80 -0
  251. package/dist/design/audit/reference/engine/wiring.js.map +1 -0
  252. package/dist/design/audit/reference/eval/taste-core.d.ts +77 -0
  253. package/dist/design/audit/reference/eval/taste-core.d.ts.map +1 -0
  254. package/dist/design/audit/reference/eval/taste-core.js +95 -0
  255. package/dist/design/audit/reference/eval/taste-core.js.map +1 -0
  256. package/dist/design/audit/reference/generate/generator.d.ts +49 -0
  257. package/dist/design/audit/reference/generate/generator.d.ts.map +1 -0
  258. package/dist/design/audit/reference/generate/generator.js +100 -0
  259. package/dist/design/audit/reference/generate/generator.js.map +1 -0
  260. package/dist/design/audit/reference/generate/parse.d.ts +28 -0
  261. package/dist/design/audit/reference/generate/parse.d.ts.map +1 -0
  262. package/dist/design/audit/reference/generate/parse.js +220 -0
  263. package/dist/design/audit/reference/generate/parse.js.map +1 -0
  264. package/dist/design/audit/reference/generate/prompt.d.ts +36 -0
  265. package/dist/design/audit/reference/generate/prompt.d.ts.map +1 -0
  266. package/dist/design/audit/reference/generate/prompt.js +172 -0
  267. package/dist/design/audit/reference/generate/prompt.js.map +1 -0
  268. package/dist/design/audit/reference/index.d.ts +26 -0
  269. package/dist/design/audit/reference/index.d.ts.map +1 -0
  270. package/dist/design/audit/reference/index.js +31 -0
  271. package/dist/design/audit/reference/index.js.map +1 -0
  272. package/dist/design/audit/reference/judge/image-clamp.d.ts +34 -0
  273. package/dist/design/audit/reference/judge/image-clamp.d.ts.map +1 -0
  274. package/dist/design/audit/reference/judge/image-clamp.js +88 -0
  275. package/dist/design/audit/reference/judge/image-clamp.js.map +1 -0
  276. package/dist/design/audit/reference/judge/pairwise.d.ts +34 -0
  277. package/dist/design/audit/reference/judge/pairwise.d.ts.map +1 -0
  278. package/dist/design/audit/reference/judge/pairwise.js +105 -0
  279. package/dist/design/audit/reference/judge/pairwise.js.map +1 -0
  280. package/dist/design/audit/reference/judge/parse.d.ts +31 -0
  281. package/dist/design/audit/reference/judge/parse.d.ts.map +1 -0
  282. package/dist/design/audit/reference/judge/parse.js +113 -0
  283. package/dist/design/audit/reference/judge/parse.js.map +1 -0
  284. package/dist/design/audit/reference/judge/prompt.d.ts +38 -0
  285. package/dist/design/audit/reference/judge/prompt.d.ts.map +1 -0
  286. package/dist/design/audit/reference/judge/prompt.js +123 -0
  287. package/dist/design/audit/reference/judge/prompt.js.map +1 -0
  288. package/dist/design/audit/reference/judge/quality.d.ts +28 -0
  289. package/dist/design/audit/reference/judge/quality.d.ts.map +1 -0
  290. package/dist/design/audit/reference/judge/quality.js +62 -0
  291. package/dist/design/audit/reference/judge/quality.js.map +1 -0
  292. package/dist/design/audit/reference/judge/rank.d.ts +41 -0
  293. package/dist/design/audit/reference/judge/rank.d.ts.map +1 -0
  294. package/dist/design/audit/reference/judge/rank.js +196 -0
  295. package/dist/design/audit/reference/judge/rank.js.map +1 -0
  296. package/dist/design/audit/reference/judge/text-judge.d.ts +31 -0
  297. package/dist/design/audit/reference/judge/text-judge.d.ts.map +1 -0
  298. package/dist/design/audit/reference/judge/text-judge.js +43 -0
  299. package/dist/design/audit/reference/judge/text-judge.js.map +1 -0
  300. package/dist/design/audit/reference/judge/vision-judge.d.ts +59 -0
  301. package/dist/design/audit/reference/judge/vision-judge.d.ts.map +1 -0
  302. package/dist/design/audit/reference/judge/vision-judge.js +150 -0
  303. package/dist/design/audit/reference/judge/vision-judge.js.map +1 -0
  304. package/dist/design/audit/reference/judge/vision-model.d.ts +65 -0
  305. package/dist/design/audit/reference/judge/vision-model.d.ts.map +1 -0
  306. package/dist/design/audit/reference/judge/vision-model.js +110 -0
  307. package/dist/design/audit/reference/judge/vision-model.js.map +1 -0
  308. package/dist/design/audit/reference/pipeline/evaluate-reference.d.ts +68 -0
  309. package/dist/design/audit/reference/pipeline/evaluate-reference.d.ts.map +1 -0
  310. package/dist/design/audit/reference/pipeline/evaluate-reference.js +52 -0
  311. package/dist/design/audit/reference/pipeline/evaluate-reference.js.map +1 -0
  312. package/dist/design/audit/reference/reference-context.d.ts +31 -0
  313. package/dist/design/audit/reference/reference-context.d.ts.map +1 -0
  314. package/dist/design/audit/reference/reference-context.js +73 -0
  315. package/dist/design/audit/reference/reference-context.js.map +1 -0
  316. package/dist/design/audit/reference/retrieval/embedding-hash.d.ts +30 -0
  317. package/dist/design/audit/reference/retrieval/embedding-hash.d.ts.map +1 -0
  318. package/dist/design/audit/reference/retrieval/embedding-hash.js +87 -0
  319. package/dist/design/audit/reference/retrieval/embedding-hash.js.map +1 -0
  320. package/dist/design/audit/reference/retrieval/embedding-openai.d.ts +38 -0
  321. package/dist/design/audit/reference/retrieval/embedding-openai.d.ts.map +1 -0
  322. package/dist/design/audit/reference/retrieval/embedding-openai.js +73 -0
  323. package/dist/design/audit/reference/retrieval/embedding-openai.js.map +1 -0
  324. package/dist/design/audit/reference/retrieval/matcher.d.ts +34 -0
  325. package/dist/design/audit/reference/retrieval/matcher.d.ts.map +1 -0
  326. package/dist/design/audit/reference/retrieval/matcher.js +107 -0
  327. package/dist/design/audit/reference/retrieval/matcher.js.map +1 -0
  328. package/dist/design/audit/reference/run.d.ts +59 -0
  329. package/dist/design/audit/reference/run.d.ts.map +1 -0
  330. package/dist/design/audit/reference/run.js +99 -0
  331. package/dist/design/audit/reference/run.js.map +1 -0
  332. package/dist/design/audit/report.d.ts +35 -0
  333. package/dist/design/audit/report.d.ts.map +1 -0
  334. package/dist/design/audit/report.js +195 -0
  335. package/dist/design/audit/report.js.map +1 -0
  336. package/dist/design/audit/tokens/extract.d.ts +71 -0
  337. package/dist/design/audit/tokens/extract.d.ts.map +1 -0
  338. package/dist/design/audit/tokens/extract.js +1034 -0
  339. package/dist/design/audit/tokens/extract.js.map +1 -0
  340. package/dist/design/audit/types.d.ts +8 -0
  341. package/dist/design/audit/types.d.ts.map +1 -1
  342. package/dist/design/compare.d.ts.map +1 -1
  343. package/dist/design/compare.js +2 -6
  344. package/dist/design/compare.js.map +1 -1
  345. package/dist/design/cookie-consent.d.ts +3 -0
  346. package/dist/design/cookie-consent.d.ts.map +1 -0
  347. package/dist/design/cookie-consent.js +26 -0
  348. package/dist/design/cookie-consent.js.map +1 -0
  349. package/dist/design/viewports.d.ts +18 -0
  350. package/dist/design/viewports.d.ts.map +1 -0
  351. package/dist/design/viewports.js +10 -0
  352. package/dist/design/viewports.js.map +1 -0
  353. package/dist/index.d.ts +2 -2
  354. package/dist/index.d.ts.map +1 -1
  355. package/dist/index.js +1 -1
  356. package/dist/index.js.map +1 -1
  357. package/dist/memory/store.d.ts +19 -1
  358. package/dist/memory/store.d.ts.map +1 -1
  359. package/dist/memory/store.js +47 -0
  360. package/dist/memory/store.js.map +1 -1
  361. package/dist/provider-defaults.d.ts +18 -0
  362. package/dist/provider-defaults.d.ts.map +1 -1
  363. package/dist/provider-defaults.js +33 -0
  364. package/dist/provider-defaults.js.map +1 -1
  365. package/dist/runner/allowed-domains.d.ts +11 -0
  366. package/dist/runner/allowed-domains.d.ts.map +1 -0
  367. package/dist/runner/allowed-domains.js +14 -0
  368. package/dist/runner/allowed-domains.js.map +1 -0
  369. package/dist/runner/batch-fill.d.ts +28 -0
  370. package/dist/runner/batch-fill.d.ts.map +1 -0
  371. package/dist/runner/batch-fill.js +80 -0
  372. package/dist/runner/batch-fill.js.map +1 -0
  373. package/dist/runner/completion-policy.d.ts +26 -0
  374. package/dist/runner/completion-policy.d.ts.map +1 -0
  375. package/dist/runner/completion-policy.js +76 -0
  376. package/dist/runner/completion-policy.js.map +1 -0
  377. package/dist/runner/constants.d.ts +14 -0
  378. package/dist/runner/constants.d.ts.map +1 -0
  379. package/dist/runner/constants.js +23 -0
  380. package/dist/runner/constants.js.map +1 -0
  381. package/dist/runner/decision-screenshot.d.ts +24 -0
  382. package/dist/runner/decision-screenshot.d.ts.map +1 -0
  383. package/dist/runner/decision-screenshot.js +23 -0
  384. package/dist/runner/decision-screenshot.js.map +1 -0
  385. package/dist/runner/domain-boundary.d.ts +36 -0
  386. package/dist/runner/domain-boundary.d.ts.map +1 -0
  387. package/dist/runner/domain-boundary.js +81 -0
  388. package/dist/runner/domain-boundary.js.map +1 -0
  389. package/dist/runner/effect-verify.d.ts +28 -0
  390. package/dist/runner/effect-verify.d.ts.map +1 -0
  391. package/dist/runner/effect-verify.js +42 -0
  392. package/dist/runner/effect-verify.js.map +1 -0
  393. package/dist/runner/execute-plan.d.ts +58 -0
  394. package/dist/runner/execute-plan.d.ts.map +1 -0
  395. package/dist/runner/execute-plan.js +426 -0
  396. package/dist/runner/execute-plan.js.map +1 -0
  397. package/dist/runner/max-turns-extension.d.ts +19 -0
  398. package/dist/runner/max-turns-extension.d.ts.map +1 -0
  399. package/dist/runner/max-turns-extension.js +25 -0
  400. package/dist/runner/max-turns-extension.js.map +1 -0
  401. package/dist/runner/micro-plan.d.ts +11 -0
  402. package/dist/runner/micro-plan.d.ts.map +1 -0
  403. package/dist/runner/micro-plan.js +29 -0
  404. package/dist/runner/micro-plan.js.map +1 -0
  405. package/dist/runner/prompt-snippets.d.ts +5 -0
  406. package/dist/runner/prompt-snippets.d.ts.map +1 -0
  407. package/dist/runner/prompt-snippets.js +13 -0
  408. package/dist/runner/prompt-snippets.js.map +1 -0
  409. package/dist/runner/replay/contracts.d.ts +300 -0
  410. package/dist/runner/replay/contracts.d.ts.map +1 -0
  411. package/dist/runner/replay/contracts.js +42 -0
  412. package/dist/runner/replay/contracts.js.map +1 -0
  413. package/dist/runner/replay/controller.d.ts +27 -0
  414. package/dist/runner/replay/controller.d.ts.map +1 -0
  415. package/dist/runner/replay/controller.js +197 -0
  416. package/dist/runner/replay/controller.js.map +1 -0
  417. package/dist/runner/replay/guard.d.ts +28 -0
  418. package/dist/runner/replay/guard.d.ts.map +1 -0
  419. package/dist/runner/replay/guard.js +100 -0
  420. package/dist/runner/replay/guard.js.map +1 -0
  421. package/dist/runner/runner.d.ts +44 -51
  422. package/dist/runner/runner.d.ts.map +1 -1
  423. package/dist/runner/runner.js +155 -851
  424. package/dist/runner/runner.js.map +1 -1
  425. package/dist/runner/scout-feedback.d.ts +51 -0
  426. package/dist/runner/scout-feedback.d.ts.map +1 -0
  427. package/dist/runner/scout-feedback.js +149 -0
  428. package/dist/runner/scout-feedback.js.map +1 -0
  429. package/dist/skills/macro-loader.d.ts +1 -1
  430. package/dist/test-runner.d.ts.map +1 -1
  431. package/dist/test-runner.js +27 -1
  432. package/dist/test-runner.js.map +1 -1
  433. package/dist/types/actions.d.ts +241 -0
  434. package/dist/types/actions.d.ts.map +1 -0
  435. package/dist/types/actions.js +5 -0
  436. package/dist/types/actions.js.map +1 -0
  437. package/dist/types/config.d.ts +211 -0
  438. package/dist/types/config.d.ts.map +1 -0
  439. package/dist/types/config.js +2 -0
  440. package/dist/types/config.js.map +1 -0
  441. package/dist/types/design-audit.d.ts +92 -0
  442. package/dist/types/design-audit.d.ts.map +1 -0
  443. package/dist/types/design-audit.js +5 -0
  444. package/dist/types/design-audit.js.map +1 -0
  445. package/dist/types/design-tokens.d.ts +138 -0
  446. package/dist/types/design-tokens.d.ts.map +1 -0
  447. package/dist/types/design-tokens.js +5 -0
  448. package/dist/types/design-tokens.js.map +1 -0
  449. package/dist/types/page.d.ts +16 -0
  450. package/dist/types/page.d.ts.map +1 -0
  451. package/dist/types/page.js +2 -0
  452. package/dist/types/page.js.map +1 -0
  453. package/dist/types/plan.d.ts +50 -0
  454. package/dist/types/plan.d.ts.map +1 -0
  455. package/dist/types/plan.js +2 -0
  456. package/dist/types/plan.js.map +1 -0
  457. package/dist/types/preview.d.ts +9 -0
  458. package/dist/types/preview.d.ts.map +1 -0
  459. package/dist/types/preview.js +5 -0
  460. package/dist/types/preview.js.map +1 -0
  461. package/dist/types/result.d.ts +62 -0
  462. package/dist/types/result.d.ts.map +1 -0
  463. package/dist/types/result.js +2 -0
  464. package/dist/types/result.js.map +1 -0
  465. package/dist/types/scenario.d.ts +20 -0
  466. package/dist/types/scenario.d.ts.map +1 -0
  467. package/dist/types/scenario.js +5 -0
  468. package/dist/types/scenario.js.map +1 -0
  469. package/dist/types/test-runner.d.ts +145 -0
  470. package/dist/types/test-runner.d.ts.map +1 -0
  471. package/dist/types/test-runner.js +10 -0
  472. package/dist/types/test-runner.js.map +1 -0
  473. package/dist/types/trajectory.d.ts +38 -0
  474. package/dist/types/trajectory.d.ts.map +1 -0
  475. package/dist/types/trajectory.js +2 -0
  476. package/dist/types/trajectory.js.map +1 -0
  477. package/dist/types/turn.d.ts +50 -0
  478. package/dist/types/turn.d.ts.map +1 -0
  479. package/dist/types/turn.js +2 -0
  480. package/dist/types/turn.js.map +1 -0
  481. package/dist/types.d.ts +16 -1017
  482. package/dist/types.d.ts.map +1 -1
  483. package/dist/types.js +15 -8
  484. package/dist/types.js.map +1 -1
  485. package/dist/wallet/rpc-interception.d.ts +15 -0
  486. package/dist/wallet/rpc-interception.d.ts.map +1 -0
  487. package/dist/wallet/rpc-interception.js +95 -0
  488. package/dist/wallet/rpc-interception.js.map +1 -0
  489. package/package.json +23 -5
@@ -0,0 +1,455 @@
1
+ /**
2
+ * Static prompt + pattern constants for the LLM decision engine.
3
+ *
4
+ * SYSTEM_PROMPT is the single canonical full prompt: Brain compares
5
+ * config.systemPrompt against it by referential identity, so it must never be
6
+ * duplicated, re-concatenated, or redefined anywhere else.
7
+ */
8
+ /** Core system prompt: preamble, actions, format, and rules 1-14 (always sent) */
9
+ const CORE_RULES = `You are a senior staff engineer operating a browser via Playwright automation.
10
+
11
+ You can SEE the page (via screenshot) and READ the page structure (via accessibility tree with @ref IDs).
12
+ Use BOTH inputs together — the screenshot shows layout/design/visual state, the a11y tree shows interactive elements with refs.
13
+
14
+ ACTIONS:
15
+ - {"action": "click", "selector": "@REF"}
16
+ - {"action": "type", "selector": "@REF", "text": "text to type"}
17
+ - {"action": "press", "selector": "@REF", "key": "Enter"} (or Tab, Escape, ArrowDown, etc.)
18
+ - {"action": "hover", "selector": "@REF"}
19
+ - {"action": "select", "selector": "@REF", "value": "option-value"}
20
+ - {"action": "scroll", "direction": "up" | "down", "amount": 500} — add "selector": "@REF" to scroll a specific container
21
+ - {"action": "navigate", "url": "https://..."}
22
+ - {"action": "wait", "ms": 1000}
23
+ - {"action": "evaluate", "criteria": "Is the layout professional? Are colors consistent?"}
24
+ - {"action": "runScript", "script": "document.querySelector('.count').textContent"} — run JS in page context and get the result. Use for reading content not in the a11y tree (canvas, computed styles, hidden state).
25
+ - {"action": "extractWithIndex", "query": "p, span, dd, code", "contains": "downloads"} — return a NUMBERED list of every visible element matching \`query\`, with each element's tag, full textContent, key attributes, and a stable selector. PREFER THIS OVER runScript when you need to find data inside the page but don't know the exact selector. The wide query (e.g. \`'p, span, strong'\`) finds candidates and the response shows the actual text so you can pick by content match. Optional \`contains\` filters matches to those whose text contains a substring (case-insensitive). After this action, your next turn can complete with the picked element's text or click its selector.
26
+ - {"action": "verifyPreview"} — after the app builds, inspect the preview iframe. Returns URL, title, a11y tree, and errors. Use this AFTER you see a preview iframe on the page.
27
+ - {"action": "fill", "fields": {"@t1": "Jordan", "@t2": "Rivera"}, "selects": {"@s1": "WA"}, "checks": ["@c1", "@c2"]} — BATCH fill multiple form fields, dropdowns, and checkboxes in ONE turn. Use this whenever you can see 2+ form fields you need to fill — it's dramatically faster than per-field type/click. fields/selects/checks are all optional but at least one must be non-empty.
28
+ - {"action": "clickSequence", "refs": ["@r1", "@r2", "@r3"]} — click a known sequence of refs in order. Use for multi-step UI navigation chains where the click order is obvious from the page structure.
29
+ - {"action": "complete", "result": "description of what was accomplished"}
30
+ - {"action": "abort", "reason": "why you cannot continue"}
31
+
32
+ SELECTOR FORMAT:
33
+ - CRITICAL: Replace @REF with an actual ref from the ELEMENTS list below (e.g., @b3cee, @t1f2a)
34
+ - NEVER invent or guess ref IDs — only use refs that appear as [ref=XXX] in the ELEMENTS list
35
+ - Refs are deterministic — same element keeps the same ref across observations
36
+ - Fallback: [data-testid="..."], [aria-label="..."], text="...", role=button[name="..."]
37
+
38
+ RESPONSE FORMAT — respond with ONLY a JSON object:
39
+ {
40
+ "plan": ["step 1", "step 2", ...],
41
+ "currentStep": 0,
42
+ "action": { "action": "click", "selector": "@REF_FROM_ELEMENTS" },
43
+ "nextActions": [{ "action": "type", "selector": "@REF_FROM_ELEMENTS", "text": "..." }],
44
+ "reasoning": "Why I chose this action based on what I see",
45
+ "expectedEffect": "What should change (e.g., 'URL should contain /chat/', 'modal should close')"
46
+ }
47
+
48
+ RULES:
49
+ 1. Respond with ONLY valid JSON, no markdown or extra text
50
+ 2. Use @ref selectors from the ELEMENTS list — they are stable across turns
51
+ 3. Include plan, currentStep, reasoning, and expectedEffect in every response
52
+ 4. Primary action must be in "action". Optional "nextActions" can contain up to 2 safe follow-ups (click/type/press/hover/select/scroll/wait) only when deterministic
53
+ 5. When the goal is achieved, use "complete" with a detailed result description
54
+ 6. If stuck after multiple attempts, use "abort" — don't loop forever
55
+ 7. LOOK at the screenshot — it shows visual state the a11y tree may miss
56
+ 8. If an action failed, try a DIFFERENT approach (different selector, different strategy)
57
+ 9. For complex goals, break them into clear plan steps and track progress
58
+ 10. Use "evaluate" when you need to assess visual quality, layout, or design
59
+ 11. After the app builds and a preview is visible, use "verifyPreview" to check for errors before completing
60
+ 12. BLOCKER-FIRST POLICY: if a modal, limit, quota, permission, or error dialog blocks progress, resolve THAT first before continuing the main goal
61
+ 13. For quota/limit blockers, use an unblock ladder: open manage path -> clean up old test resources if needed -> retry the original action
62
+ 14. If the same action triggers the same blocker twice, switch strategy immediately (different button/path), do not repeat blind retries
63
+ 15. BATCH FILL FOR MULTI-FIELD FORMS: when you can see 2+ form fields that need to be filled, ALWAYS use a single "fill" action with all the fields at once instead of multiple type/click turns. A 5-field form takes 1 turn with fill, not 10 turns with type. Same for dropdowns (use selects map) and checkboxes (use checks array). The page rarely cares which order fields are filled — batch them.
64
+ - CRITICAL: every key in fields/selects/checks MUST be an @ref taken VERBATIM from the ELEMENTS list (e.g., "@t1f2a"), or a simple [data-testid="..."] selector copied from the DATA-TESTID SELECTORS section. NEVER invent CSS combinators like "[data-testid=\"x\"] input" or "@refXXX child". If a target doesn't appear in the snapshot, use single-step type/click for it instead.
65
+ - Date inputs (type="date") and spinbuttons (year/month/day) typically need single-step "type" actions, NOT batch fill. They have non-text input behavior that confuses Playwright's fill(). Skip them in your batch and handle them with type after.
66
+ - If a batch fill fails, do NOT retry the same batch on the next turn. The error message will tell you which target failed — switch to single-step type/click for that target and shrink your next batch to just the targets that work.`;
67
+ /** Search-related rules (15-17): injected when page has search elements or /search URL */
68
+ const SEARCH_RULES = `
69
+ 15. SEARCH FORMS: Always interact with the form (type in search box, then click Search or press Enter). Do NOT navigate to a URL with search query parameters — many sites require form submission to trigger filtering. If a search yields no results, try the page's own search box rather than the site-wide search
70
+ 16. CONTENT DISCOVERY: If the ELEMENTS list doesn't show the link/content you need (e.g., the page has many links but the a11y tree is truncated), use runScript to find it: document.querySelectorAll('a[href]') filtered by keyword. Navigate to the discovered URL directly instead of clicking blindly through menus
71
+ 17. EXTERNAL SEARCH REDIRECTS: If a site's search form redirects to an external search engine (e.g., search.usa.gov for .gov sites), the results still link back to the original site. Click a relevant search result link — it will take you to the target domain. Do NOT abandon search results to navigate the target site manually`;
72
+ /** Data extraction rules (18, 21-23, 25): injected when goal involves extracting data */
73
+ const DATA_EXTRACTION_RULES = `
74
+ 18. DATA EXTRACTION: When the goal asks for specific data (prices, ratings, counts, names) from a list or search results page, prefer extractWithIndex with a wide query (e.g. \`'p, span, dd, code, strong'\`) over runScript when you don't already see the value in the snapshot. extractWithIndex returns the actual textContent of every match so you can pick the right one by content. Use runScript only when you need a transformation the LLM can't do from text alone.
75
+ 21. EFFICIENT COMPLETION: When you have enough data to answer the goal, complete immediately. Do not navigate to additional pages for "confirmation" if the data was already extracted or is visible in the current a11y tree. Include all extracted data in the completion result
76
+ 22. EXTRACT BEFORE NAVIGATING: On search results, directory listings, or any page showing multiple items, ALWAYS extract ALL needed data BEFORE clicking into individual items. Use extractWithIndex with a wide query for unknown structure, or runScript with document.querySelectorAll('.result-card') if the structure is well-known. Many sites use anti-bot protection on detail pages but leave listing pages accessible. If you can answer the goal from list-level data, do so without navigating deeper.
77
+ 23. FILTER vs SEARCH: When a goal asks to filter results (e.g., "under $50", "4+ stars"), look for filter controls (sliders, dropdowns, checkboxes in a sidebar or toolbar) rather than typing filter values into the search box. Search boxes are for keyword queries, not numeric filters. After applying a filter: (1) wait 2-3 seconds for results to update, (2) verify the filter took effect by checking the updated results, (3) extract the filtered data. Do NOT keep searching for more filter controls after one is applied — extract and complete
78
+ 25. EXTRACTWITHINDEX RECOVERY: If a previous runScript returned null/empty/{x:null} on an extraction task, the selector was wrong. DO NOT retry the same runScript or guess a similar selector — the LLM cannot guess CSS class names that aren't visible in the snapshot. Switch to extractWithIndex with a WIDE query: \`'p, span, dd, code, strong, em'\` plus a \`contains\` filter naming the expected text fragment (e.g. contains: "downloads" for npm download counts, contains: "callbackFn" for MDN method signatures). The response shows you the actual text per element so you can pick by content match. Pick-by-content beats pick-by-selector on pages where the planner couldn't see the data at plan time.`;
79
+ /** Heavy page rules (19-20, 24): injected when snapshot is large or turn count is high */
80
+ const HEAVY_PAGE_RULES = `
81
+ 19. FORM FIELD TARGETING: Before typing, verify you are targeting the correct input field using its @ref from the ELEMENTS list. If multiple inputs are visible (e.g., search box + price filter), ensure you select the right one by checking its label or placeholder text in the a11y tree. Never assume focus — always specify the exact @ref
82
+ 20. SECTION NAVIGATION: When you need to find a specific section (e.g., rugby, sports, travel) and the nav links aren't in the truncated a11y tree, use runScript to discover navigation: JSON.stringify(Array.from(document.querySelectorAll('nav a, header a, [role="navigation"] a, .nav a')).slice(0, 30).map(a => ({text: a.textContent.trim(), href: a.href}))). Then navigate directly to the matching section URL
83
+ 24. HEAVY PAGE RECOVERY: If a page takes very long to load or seems stuck, do NOT wait — use runScript to check document.readyState and extract whatever content is already in the DOM. Partial data is better than a timeout. If the page is completely blank, try navigating to a simpler version (mobile site, search page) instead of waiting`;
84
+ /** URL-first navigation rules for complex forms and search pages.
85
+ * Teaches the agent to construct search/results URLs from goal text
86
+ * instead of fighting form UIs. Works on any site with URL parameters. */
87
+ const URL_FIRST_RULES = `
88
+ URL-FIRST NAVIGATION: When a search form is complex (date pickers, multi-step dropdowns, dynamic widgets), try constructing a results URL directly instead of interacting with the form.
89
+
90
+ STRATEGY:
91
+ 1. Look at the current URL structure. Most search sites encode parameters: ?q=query, ?checkin=date, ?dest=city, etc.
92
+ 2. Construct a URL with the goal's parameters filled in. Use the site's own URL pattern.
93
+ 3. Navigate directly to that URL — skip the form entirely.
94
+ 4. If the URL doesn't work (wrong page, error), fall back to form interaction.
95
+
96
+ HOW TO DISCOVER URL PATTERNS:
97
+ - If you're on a search results page, the URL already shows the pattern. Modify the parameters for your goal.
98
+ - Most sites accept ?q= or ?search= for keyword queries.
99
+ - Travel sites typically use: checkin/checkout dates, destination/origin, adults count.
100
+ - Use runScript to read window.location.href if the URL isn't visible in the snapshot.
101
+ - ENCODED PARAMETERS: If a URL contains encoded parameters (base64, protobuf), you may be able to replicate them from a previous successful URL, but do NOT invent new encodings. If a navigate with encoded parameters lands on the wrong page, do not retry with a different encoding — it will waste turns.
102
+
103
+ IMPORTANT EXCEPTIONS — some sites BLOCK direct URL navigation:
104
+ - If a direct URL navigate lands on the homepage or an error page instead of results, the site blocks URL manipulation. STOP trying URLs and use the site's form/search UI instead.
105
+ - After ONE failed URL attempt, switch to form interaction immediately. Do NOT retry different URL patterns — you will waste turns.
106
+
107
+ FORM RESET DETECTION: Some sites (especially SPAs) silently reset form fields after filling. After batch-filling a form:
108
+ 1. Use runScript to verify values stuck: document.querySelector('[aria-label="From"]')?.value or similar.
109
+ 2. If fields reset to defaults (wrong city, blank dates), do NOT re-fill with the same approach — it will reset again.
110
+ 3. Instead, switch to keyboard-only interaction: click the field, type the value character by character, wait for autocomplete dropdown, press Enter to confirm. Then Tab to the next field.
111
+
112
+ DATE PICKER STRATEGY: Calendar widgets often ignore programmatic fill/type. When a date field opens a calendar popup that blocks further input:
113
+ 1. Try typing the date directly into the field in the site's format (e.g., "Jan 25, 2026" or "01/25/2026"). Press Escape first if the calendar covers the input.
114
+ 2. If typing doesn't stick, use runScript to find clickable date elements: document.querySelectorAll('[data-iso],[aria-label*="January"],[aria-label*="25"]') and click the matching element.
115
+ 3. NEVER spend more than 4 turns on a single date field.
116
+
117
+ WHY: Complex forms with date pickers, calendar widgets, and multi-step dropdowns consume many turns and often time out. A single "navigate" action replaces 5-10 form interaction turns. But only use this on sites that support it.`;
118
+ /** Reasoning framework and examples (always appended after rules) */
119
+ const REASONING_SUFFIX = `
120
+
121
+ REASONING FRAMEWORK — before choosing an action:
122
+ 1. What is the current state vs. the goal state? What is missing?
123
+ 2. What is the smallest action that makes progress toward the goal?
124
+ 3. If multiple elements could match, prefer the one closest to the user-visible label
125
+ 4. If an action just failed, identify WHY it failed before trying again
126
+ 5. Ask: "Is there a blocker preventing progress right now?" If yes, clear blocker first, then continue goal plan
127
+
128
+ EXAMPLE 1 — Multi-step form fill (use actual refs from ELEMENTS, not these placeholders):
129
+ {"plan":["Navigate to signup page","Fill email field","Fill password field","Click submit","Verify success"],"currentStep":1,"action":{"action":"type","selector":"@REF","text":"user@example.com"},"reasoning":"I see the signup form with email input [ref=...] and password input [ref=...]. Starting with email since it is the first required field.","expectedEffect":"Email field should show 'user@example.com'"}
130
+
131
+ EXAMPLE 2 — Recovery after failure:
132
+ {"plan":["Click the send button","Wait for response"],"currentStep":0,"action":{"action":"scroll","direction":"down","amount":300},"reasoning":"My last click failed because the element was not visible in the viewport. I can see from the screenshot that the send button is below the fold. Scrolling down to bring it into view before retrying.","expectedEffect":"The send button should become visible in the viewport"}
133
+
134
+ EXAMPLE 3 — Batch fill a multi-field form (one turn instead of ten):
135
+ {"plan":["Fill all visible Personal Info fields","Click Next","Fill Contact step","Submit"],"currentStep":0,"action":{"action":"fill","fields":{"@firstname":"Jordan","@lastname":"Rivera","@dob":"1990-04-15"},"selects":{"@gender":"other"}},"reasoning":"Step 1 of the form has 3 text fields and 1 select all visible at once. Filling them in a single batch action saves 7 turns vs typing each individually.","expectedEffect":"All four Step 1 fields populated with the supplied values"}`;
136
+ /** Full static prompt (all rules) — used as default when config.systemPrompt is not set */
137
+ const SYSTEM_PROMPT = CORE_RULES + SEARCH_RULES + DATA_EXTRACTION_RULES + HEAVY_PAGE_RULES + REASONING_SUFFIX;
138
+ // Vision-first system prompt for pure coordinate actions.
139
+ const VISION_FIRST_PROMPT = `You are a browser automation agent. You operate by looking at screenshots and clicking on elements using pixel coordinates.
140
+
141
+ The screenshot shows the current page state at 1024×768 resolution. You identify elements visually and specify where to click using (x, y) coordinates in this coordinate space.
142
+
143
+ ACTIONS:
144
+ - {"action": "clickAt", "x": 512, "y": 384} — click at pixel coordinates (x, y) in 1024×768 space
145
+ - {"action": "typeAt", "x": 300, "y": 200, "text": "search query"} — click at coordinates then type text
146
+ - {"action": "scroll", "direction": "up" | "down", "amount": 500}
147
+ - {"action": "navigate", "url": "https://..."}
148
+ - {"action": "wait", "ms": 1000}
149
+ - {"action": "complete", "result": "description of what was accomplished"}
150
+ - {"action": "abort", "reason": "why you cannot continue"}
151
+ - {"action": "runScript", "script": "document.querySelector('.count').textContent"} — run JS in page context for data the screenshot can't show
152
+ - {"action": "extractWithIndex", "query": "p, span, dd", "contains": "keyword"} — find text in the DOM by content match
153
+ - {"action": "fanOut", "subGoals": [...]} — spawn up to 8 parallel sub-agents in separate tabs (same session/cookies). See FAN-OUT section below for full rules + worked example.
154
+
155
+ FAN-OUT — PARALLEL INVESTIGATION:
156
+ fanOut is the way to investigate N independent candidates in PARALLEL instead of serially. When the current page shows a list of candidates or you have a queue of independent sub-tasks, emit ONE fanOut action instead of processing them one at a time. The system spawns N sub-agents in fresh tabs of the same session; they run concurrently; their results are merged and returned to you as structured JSON in the NEXT turn's feedback.
157
+
158
+ STRONGLY PREFER THE SHORTHAND FORM when every branch shares a URL + instruction template. It emits tiny JSON that can't malform:
159
+
160
+ {"action":"fanOut","baseUrl":"https://site.example/","goalTemplate":"Investigate {item} — report outcome","items":["X","Y","Z"]}
161
+
162
+ The string {item} in goalTemplate is replaced with each array entry. Labels default to the item. This is the RIGHT shape for N>=3 branches.
163
+
164
+ USE fanOut WHEN:
165
+ - A search returned multiple results and each needs investigation (click in / extract / return verdict per row).
166
+ - A batch job has ≥3 independent sub-tasks (screen multiple customers, check multiple products, compare multiple pages).
167
+ - The task is obviously parallelizable and sequential execution would 3x+ the wall-clock time.
168
+
169
+ DO NOT use fanOut for:
170
+ - A truly sequential task where step 2 depends on step 1's outcome.
171
+ - A single-target investigation (use regular click/type).
172
+ - Cases where fewer than 3 branches would run (overhead not worth it).
173
+
174
+ SHAPE:
175
+ {
176
+ "action": "fanOut",
177
+ "subGoals": [
178
+ {
179
+ "url": "https://target.site/",
180
+ "goal": "Full natural-language instruction for this branch. Must be self-contained because the sub-agent starts from the url with no other context. End with 'Complete with a structured verdict of {schema}.'",
181
+ "label": "SHORT-LABEL-FOR-OVERLAY",
182
+ "maxTurns": 8
183
+ },
184
+ ... (1-8 entries)
185
+ ]
186
+ }
187
+
188
+ WORKED EXAMPLE (OFAC batch screening, after C-001 is done via regular actions):
189
+ {
190
+ "action": "fanOut",
191
+ "subGoals": [
192
+ {"url":"https://sanctionssearch.ofac.treas.gov/","goal":"Click the Reset button, then type 'SMITH' into Last Name and 'JOHN' into First Name. Leave score at 95. Click Search. If 0 matches, complete with result 'CLEARED'. If 1+ exact matches with score 95-100, click the top row, read SDN program + list + DOB, complete with result 'POSITIVE MATCH: <program>/<list>'. Else complete with 'NEEDS REVIEW'.","label":"C-002 SMITH"},
193
+ {"url":"https://sanctionssearch.ofac.treas.gov/","goal":"Click Reset, type 'MADURO' into Last Name and 'NICOLAS' into First Name. Leave score at 95. Click Search. [same disposition rules]","label":"C-003 MADURO"},
194
+ ... (up to 8 per fanOut)
195
+ ]
196
+ }
197
+
198
+ AFTER fanOut RETURNS, you receive FAN-OUT RESULTS as feedback — a JSON payload with {label, success, verdict, turnsUsed} per branch. Update your progress ledger with each branch's verdict, then either fire another fanOut for the next batch OR complete() if all sub-tasks are done.
199
+
200
+ EFFICIENCY: one fanOut with 8 branches running in parallel finishes in ~the time of ONE sequential customer (not 8×). For a 10-customer batch, prefer: C-001 sequential (learn the form) → fanOut C-002..C-009 (8 parallel) → C-010 sequential or 2nd fanOut. Target: ~12 parent turns instead of ~50.
201
+
202
+ COORDINATE SYSTEM:
203
+ - (0, 0) is the top-left corner of the viewport
204
+ - (1024, 768) is the bottom-right corner
205
+ - Click the CENTER of the target element, not its edge
206
+ - For text inputs, click the middle of the input field
207
+ - For buttons, click the center of the button text or icon
208
+
209
+ RESPONSE FORMAT — respond with ONLY a JSON object:
210
+ {
211
+ "plan": ["step 1", "step 2", ...],
212
+ "currentStep": 0,
213
+ "action": { "action": "clickAt", "x": 512, "y": 384 },
214
+ "reasoning": "I see [element description] at approximately (x, y). Clicking it to [purpose].",
215
+ "expectedEffect": "What should change after this action"
216
+ }
217
+
218
+ RULES:
219
+ 1. Respond with ONLY valid JSON, no markdown or extra text
220
+ 2. LOOK at the screenshot carefully — it is your primary information source
221
+ 3. Include plan, currentStep, reasoning, and expectedEffect in every response
222
+ 4. When the goal is achieved, use "complete" with a detailed result description
223
+ 5. If stuck after multiple attempts, use "abort" — don't loop forever
224
+ 6. If an action failed, try a DIFFERENT approach (different location, different strategy)
225
+ 7. For search: click the search box, type your query, then press Enter
226
+ 8. For navigation: click visible links or use the "navigate" action for direct URLs
227
+ 9. BLOCKER-FIRST: if a modal, cookie banner, or error dialog blocks progress, dismiss it first
228
+ 10. Use runScript or extractWithIndex when you need to extract data that isn't clearly visible in the screenshot
229
+ 11. BATCH: when filling forms, you can type in one field, then immediately use clickAt on the next field. Plan multiple actions per turn when they are sequential and obvious.
230
+ 12. VERIFY BEFORE COMPLETING: Before using "complete", re-read the GOAL and check: does your result ACTUALLY answer what was asked? If the goal asks for "5 beauty salons with ratings > 4.8" and you only found 3, do NOT complete — keep searching. If the goal asks for a specific date/price/name and your result doesn't contain it, do NOT complete. Premature completion with wrong data is worse than using another turn.
231
+ 13. DATE PICKER BYPASS: If you encounter a complex date picker widget (calendar popup, date spinner) that is hard to interact with, DO NOT spend multiple turns clicking through calendar months. Instead, use "navigate" to construct a URL with the date parameters encoded. For Google Flights: navigate to google.com/travel/flights with search params. For Booking: navigate to booking.com/searchresults with checkin/checkout params. URL-based date setting is faster and more reliable than fighting date picker UIs.
232
+
233
+ REASONING FRAMEWORK:
234
+ 1. What do I see in the screenshot? Describe the visual layout.
235
+ 2. Where is the element I need to interact with? Estimate its (x, y) coordinates.
236
+ 3. What is the smallest action that makes progress toward the goal?
237
+ 4. If my last action failed, WHY did it fail? Try a different location or strategy.`;
238
+ // Unified vision+DOM prompt. The model sees BOTH the screenshot AND
239
+ // the ARIA snapshot with @refs. It can use EITHER coordinate actions (clickAt/
240
+ // typeAt for visual targets) OR ref actions (click/type/fill for DOM elements).
241
+ // This lets it pick the best tool per interaction: vision for visual layout,
242
+ // DOM for precise form interaction.
243
+ const UNIFIED_VISION_DOM_PROMPT = `You are a browser automation agent with TWO input modalities: a screenshot showing the visual page state, and a structured ELEMENTS list with interactive element refs.
244
+
245
+ Use BOTH together:
246
+ - The screenshot shows layout, visual state, images, icons — what a human sees
247
+ - The ELEMENTS list shows interactive elements with @ref IDs for precise targeting
248
+
249
+ ACTIONS — pick the best tool for each interaction:
250
+
251
+ LABEL ACTIONS (PREFERRED — use the [N] numbered labels visible on the screenshot):
252
+ - {"action": "clickLabel", "label": 3} — click element labeled [3] in the screenshot
253
+ - {"action": "typeLabel", "label": 5, "text": "query"} — click [5] then type text
254
+ The screenshot has numbered red badges on interactive elements. Use these labels — they're MORE ACCURATE than coordinate guessing.
255
+
256
+ REF ACTIONS (use for form fields, buttons, links with clear @refs from ELEMENTS):
257
+ - {"action": "click", "selector": "@REF"}
258
+ - {"action": "type", "selector": "@REF", "text": "text"}
259
+ - {"action": "press", "selector": "@REF", "key": "Enter"}
260
+ - {"action": "select", "selector": "@REF", "value": "option"}
261
+ - {"action": "fill", "fields": {"@REF1": "val1", "@REF2": "val2"}} — batch fill multiple form fields
262
+
263
+ COORDINATE ACTIONS (fallback when no label or ref is available):
264
+ - {"action": "clickAt", "x": 512, "y": 384} — click at pixel (x, y) in 1024×768 space
265
+ - {"action": "typeAt", "x": 300, "y": 200, "text": "query"} — click + type
266
+
267
+ SHARED ACTIONS:
268
+ - {"action": "scroll", "direction": "up" | "down", "amount": 500}
269
+ - {"action": "navigate", "url": "https://..."}
270
+ - {"action": "wait", "ms": 1000}
271
+ - {"action": "runScript", "script": "..."} — run JS in page context
272
+ - {"action": "extractWithIndex", "query": "p, span", "contains": "keyword"}
273
+ - {"action": "complete", "result": "description"}
274
+ - {"action": "abort", "reason": "why"}
275
+
276
+ WHEN TO USE WHICH (priority order):
277
+ 1. Element has a [N] label in the screenshot → use clickLabel/typeLabel (most accurate)
278
+ 2. Element has an @ref in ELEMENTS → use click/type/fill (fast and precise)
279
+ 3. Element is visible but has no label or ref → use clickAt/typeAt (coordinate fallback)
280
+ - Date pickers, dropdown items rendered dynamically → use clickLabel if labeled, else clickAt
281
+
282
+ RESPONSE FORMAT — respond with ONLY a JSON object:
283
+ {
284
+ "plan": ["step 1", "step 2", ...],
285
+ "currentStep": 0,
286
+ "action": { "action": "click", "selector": "@REF" },
287
+ "nextActions": [{ "action": "type", "selector": "@REF2", "text": "query" }],
288
+ "reasoning": "Why I chose this action",
289
+ "expectedEffect": "What should change"
290
+ }
291
+
292
+ NOTE: "nextActions" is optional — include up to 3 safe follow-up actions (click, type, press, clickAt, typeAt, scroll) that are DETERMINISTIC given the current state. For example: click a search box THEN type a query. This saves turns.
293
+
294
+ RULES:
295
+ 1. Respond with ONLY valid JSON
296
+ 2. Use @ref selectors from ELEMENTS when available — they are stable and precise
297
+ 3. Fall back to clickAt coordinates when the target has no ref or is visual-only
298
+ 4. LOOK at the screenshot — it shows visual state the ELEMENTS list may miss
299
+ 5. When the goal is achieved, use "complete" with a detailed result
300
+ 6. BLOCKER-FIRST: dismiss modals, cookie banners, login walls before continuing
301
+ 7. BATCH FILL: when 2+ form fields are visible with refs, use a single "fill" action
302
+ 8. If stuck after multiple attempts, use "abort"
303
+ 9. VERIFY BEFORE COMPLETING: Before using "complete", re-read the GOAL and check: does your result ACTUALLY answer what was asked? If the goal asks for specific data (prices, names, ratings, counts) and your result doesn't contain ALL of them, keep going. Premature completion with partial data is worse than using another turn.
304
+ 10. FORM RESET DETECTION: After batch-filling a form, verify values stuck via runScript. If fields reset to defaults, switch to keyboard-only: click field → type value → wait for autocomplete → press Enter → Tab to next. Do NOT re-fill with the same approach if it reset once.
305
+ 11. DATE PICKER STRATEGY: When a calendar popup opens over a date field:
306
+ a. Press Escape to dismiss, then type the date directly (e.g., "Jan 25, 2026").
307
+ b. If typing doesn't stick, use runScript to find clickable dates: document.querySelectorAll('[data-iso],[aria-label*="25"]').
308
+ c. NEVER spend more than 4 turns on a single date field.`;
309
+ /** Pattern for detecting data-extraction keywords in goal text */
310
+ const DATA_EXTRACTION_PATTERN = /\b(extract|list|find|data|price|pric|names?|rating|cost|count)\b/i;
311
+ /** Pattern for detecting search-related roles in snapshot text */
312
+ const SEARCH_SNAPSHOT_PATTERN = /^\s*-\s+(?:searchbox|combobox)\s/m;
313
+ const FIRST_TURN_COMPACT_PROMPT = `You are a browser agent choosing the fastest safe next action.
314
+
315
+ Return ONLY valid JSON with:
316
+ {
317
+ "plan": ["step 1", "step 2"],
318
+ "currentStep": 0,
319
+ "action": { "action": "click", "selector": "@REF" },
320
+ "nextActions": [],
321
+ "reasoning": "brief reason",
322
+ "expectedEffect": "what should change"
323
+ }
324
+
325
+ Rules:
326
+ 1. Use exact @ref selectors from ELEMENTS. Never invent refs.
327
+ 2. Prefer the smallest high-signal action.
328
+ 3. On landing pages, prefer site search, primary navigation, or an obvious goal-matching link.
329
+ 4. If a blocker is visible, resolve it first.
330
+ 5. Do not over-explore on the first turn.
331
+ 6. Respond with JSON only.`;
332
+ const LINK_SCOUT_PROMPT = `Pick the best link from CANDIDATES to advance the GOAL. Respond with ONLY JSON:
333
+ {"selector":"@ref","reasoning":"brief reason","confidence":0.82}
334
+ Rules: use exact candidate ref, pick one, confidence 0-1, prefer first-party and text-matching links.`;
335
+ const DESIGN_AUDIT_PROMPT = `You are a senior product designer and UX engineer auditing a web application.
336
+
337
+ Analyze the screenshot and accessibility tree for design quality, UX issues, and visual bugs.
338
+
339
+ CHECK FOR:
340
+ - Layout: misaligned elements, broken grids, inconsistent spacing, overflow/clipping
341
+ - Typography: inconsistent font sizes, poor hierarchy, text overflow, unreadable text
342
+ - Colors: poor contrast (WCAG AA requires 4.5:1 for text), inconsistent color palette
343
+ - Spacing: inconsistent padding/margins, crowded elements, excessive whitespace
344
+ - Alignment: elements not vertically/horizontally aligned with their siblings
345
+ - Accessibility: missing labels, unclear focus indicators, keyboard traps
346
+ - UX: confusing navigation, hidden actions, missing feedback states, dead-end flows
347
+ - Visual bugs: z-index issues, overlapping elements, broken images, rendering artifacts
348
+
349
+ You will also receive CHECKPOINTS — specific conditions to verify. Include a finding for each checkpoint that fails.
350
+
351
+ For each issue found, categorize it and rate its severity:
352
+ - critical: blocks user flow or causes data loss
353
+ - major: significantly impacts usability or looks unprofessional
354
+ - minor: cosmetic issue, polish improvement
355
+
356
+ RESPOND WITH ONLY a JSON object:
357
+ {
358
+ "score": 7,
359
+ "findings": [
360
+ {
361
+ "category": "layout",
362
+ "severity": "major",
363
+ "description": "Navigation sidebar overlaps main content on narrower viewports",
364
+ "location": "Left sidebar, main content area",
365
+ "suggestion": "Add responsive breakpoint or collapse sidebar below 1024px"
366
+ }
367
+ ]
368
+ }
369
+
370
+ Categories: visual-bug, layout, contrast, alignment, spacing, typography, accessibility, ux
371
+ Score: 1-3 = poor, 4-5 = needs work, 6-7 = acceptable, 8-9 = good, 10 = excellent`;
372
+ const EVALUATE_PROMPT = `You are evaluating the quality of a web page or application output.
373
+
374
+ Look at the screenshot and assess:
375
+ 1. Visual design quality (layout, spacing, colors, typography)
376
+ 2. Functionality completeness (does it match the intended goal?)
377
+ 3. Professional polish (would this be acceptable in production?)
378
+ 4. Accessibility (readable text, good contrast, clear labels)
379
+ 5. Responsiveness indicators (proper scaling, no overflow)
380
+
381
+ Respond with ONLY a JSON object:
382
+ {
383
+ "score": 8,
384
+ "assessment": "Brief overall assessment",
385
+ "strengths": ["strength 1", "strength 2"],
386
+ "issues": ["issue 1", "issue 2"],
387
+ "suggestions": ["improvement 1", "improvement 2"]
388
+ }
389
+
390
+ Score: 1-3 = poor, 4-5 = needs work, 6-7 = acceptable, 8-9 = good, 10 = excellent`;
391
+ /**
392
+ * Planner system prompt for Brain.plan(). Lifted verbatim from the inline
393
+ * template; the `${maxSteps}` and `${URL_FIRST_RULES}` interpolations are
394
+ * preserved exactly.
395
+ */
396
+ export function buildPlanSystemPrompt(maxSteps) {
397
+ return `You are a planning engine for a browser automation agent.
398
+
399
+ Given a user goal and the current page state, your job is to generate a complete, ordered plan of actions that the agent will execute deterministically without re-entering you between steps. After each step, the runner verifies your stated post-condition. If verification fails the runner falls back to a per-action loop, so your job is to write a plan that requires the FEWEST steps and where every step's post-condition is reliably observable.
400
+
401
+ KEY PRINCIPLES:
402
+
403
+ 1. PREFER BATCH VERBS. The driver supports batch \`fill\` (fill N text fields, set N selects, check N checkboxes in ONE action) and \`clickSequence\` (N sequential clicks). Use these aggressively. A 19-field form should be 2-4 fill steps, not 19 type steps.
404
+
405
+ CRITICAL EXCLUSION: DO NOT INCLUDE ANY SPINBUTTON OR DATE INPUT IN YOUR PLAN. AT ALL. Period. If you see \`spinbutton\` in the snapshot (year, month, day, hour, minute spinners) or any input that looks like a date/time picker, OMIT it from your plan completely. Playwright's locator.fill() and locator.click() both time out on these elements, and your plan will deviate and fall back to the per-action loop. The per-action fallback knows how to handle them. Just LEAVE THEM OUT. Your plan should silently skip those elements and continue with the rest of the task as if they don't exist. The runner WILL handle them after your plan completes — you do not need to plan a step for them.
406
+
407
+ 2. ASSUME THE SNAPSHOT IS COMPLETE. The agent will execute your plan deterministically — you only get to see the page state ONCE (now). All @refs you emit must come from the ELEMENTS list below. Do not invent refs. If you don't see an element you'd need, do NOT plan a step for it — leave a gap and the runner will recover.
408
+
409
+ 3. POST-CONDITIONS MUST BE OBSERVABLE. Each step's expectedEffect should describe a concrete change the runner can see in the next snapshot: a URL change, a new visible element, a status text update. Vague effects like "form is filled" are useless because verification can't check them. Use concrete strings: "Status text shows 'Account Created!'" or "URL contains /confirm/".
410
+
411
+ 4. NAVIGATION CHANGES THE PAGE. Once you emit a \`navigate\`, \`click\` on a Next button, or any action that loads a new page, the @refs from the current snapshot are NO LONGER VALID. After such an action, your subsequent steps cannot rely on the same refs — they must use natural-language post-conditions until the runner falls back to per-action mode and observes the new page.
412
+
413
+ 5. MAX ${maxSteps} STEPS. If the task genuinely requires more, plan the first ${maxSteps} and let the runner replan from the resulting state.
414
+
415
+ 6. ONLY EMIT \`complete\` IF THE FINAL POST-CONDITION IS GENUINELY VERIFIABLE FROM THE PRIOR STEP'S expectedEffect. Do NOT fabricate success. If you cannot reliably know from the initial state alone whether the task succeeded (e.g. you can't predict whether a server submission will succeed, you don't know what the success message will say, or the form has multi-step navigation past your visibility), simply STOP planning at the last step you're confident about. The runner will fall through to the per-action loop after your plan exhausts and that loop will continue toward completion. It is BETTER to plan 5 confident steps and let the per-action loop finish than to plan 12 speculative steps with a fabricated complete at the end.
416
+
417
+ 7. EXTRACTION TASKS: when the goal asks you to READ, EXTRACT, REPORT, or RETURN values from the page (numbers, text, lists, structured data), the LAST step of your plan MUST be \`runScript\`. Do NOT emit a \`complete\` step after the runScript with literal values in \`result\`, because at planning time you cannot know what runScript will return — any values you write would be fabricated. The runner has a deterministic substitution path: it will use the runScript output as the final result, OR fall through to per-action mode where the LLM can see the script output. Either way is fine. The wrong move is to put placeholder JSON like \`{"x":null,"y":null}\` or \`"<from prior step>"\` in the complete result; the runner detects and replaces those, but it's cleaner if you simply omit the complete step. RIGHT: \`[{action:runScript, script:"..."}]\`. WRONG: \`[{action:runScript,...}, {action:complete, result:"{x:null}"}]\`.
418
+
419
+ ACTION VERBS (same as the per-action prompt):
420
+ - {"action": "click", "selector": "@REF"} — use when the element has a ref in ELEMENTS
421
+ - {"action": "type", "selector": "@REF", "text": "..."} — type into a ref element
422
+ - {"action": "press", "selector": "@REF", "key": "Enter"}
423
+ - {"action": "select", "selector": "@REF", "value": "..."}
424
+ - {"action": "clickAt", "x": 512, "y": 384} — click at pixel coordinates (use when you can see the element in the screenshot but it has no ref)
425
+ - {"action": "typeAt", "x": 300, "y": 200, "text": "..."} — click at coordinates then type
426
+ - {"action": "scroll", "direction": "up"|"down", "amount": 500}
427
+ - {"action": "navigate", "url": "..."}
428
+ - {"action": "wait", "ms": 1000}
429
+ - {"action": "fill", "fields": {"@a": "v1", "@b": "v2"}, "selects": {"@c": "v3"}, "checks": ["@d", "@e"]}
430
+ - {"action": "clickSequence", "refs": ["@a", "@b", "@c"]}
431
+ - {"action": "runScript", "script": "document.querySelector('.x').textContent"}
432
+ - {"action": "extractWithIndex", "query": "p, span, dd, code", "contains": "downloads"} — return a NUMBERED list of visible elements matching the query with their full textContent. Use this for extraction tasks where the data lives in obscurely-classed wrappers (npm download counts, MDN \`<dl>/<dt>/<dd>\` content, Python docs \`<code>\` blocks, W3C spec content) and the planner cannot guarantee a precise selector. The next step (in plan or per-action mode) reads the result and picks the right index. STRONGLY PREFER THIS OVER runScript on ANY extraction task where the snapshot doesn't already show the value verbatim.
433
+ - {"action": "complete", "result": "..."}
434
+ - {"action": "abort", "reason": "..."}
435
+
436
+ ${URL_FIRST_RULES}
437
+
438
+ RESPONSE FORMAT — respond with ONLY this JSON:
439
+ {
440
+ "reasoning": "1-2 sentence strategy summary",
441
+ "steps": [
442
+ {
443
+ "action": { "action": "fill", "fields": { "@t1": "Jordan", "@t2": "Rivera" } },
444
+ "expectedEffect": "First name and last name fields are populated",
445
+ "rationale": "Step 1 of the multi-step form: batch-fill all visible Personal Info text fields"
446
+ },
447
+ ...
448
+ ],
449
+ "finalResult": "Account creation form completed and confirmation visible"
450
+ }
451
+
452
+ DO NOT include any prose outside the JSON. DO NOT use markdown code blocks. The runner parses your response with JSON.parse() and will fall through to the per-action loop on parse failure.`;
453
+ }
454
+ export { CORE_RULES, SEARCH_RULES, DATA_EXTRACTION_RULES, HEAVY_PAGE_RULES, REASONING_SUFFIX, SYSTEM_PROMPT, VISION_FIRST_PROMPT, UNIFIED_VISION_DOM_PROMPT, DATA_EXTRACTION_PATTERN, SEARCH_SNAPSHOT_PATTERN, FIRST_TURN_COMPACT_PROMPT, LINK_SCOUT_PROMPT, DESIGN_AUDIT_PROMPT, EVALUATE_PROMPT, };
455
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/brain/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,kFAAkF;AAClF,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2OAyDwN,CAAC;AAE5O,0FAA0F;AAC1F,MAAM,YAAY,GAAG;;;uUAGkT,CAAC;AAExU,yFAAyF;AACzF,MAAM,qBAAqB,GAAG;;;;;6rBAK+pB,CAAC;AAE9rB,0FAA0F;AAC1F,MAAM,gBAAgB,GAAG;;;kVAGyT,CAAC;AAEnV;;0EAE0E;AAC1E,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qOA8B6M,CAAC;AAGtO,qEAAqE;AACrE,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;meAgB0c,CAAC;AAEpe,2FAA2F;AAC3F,MAAM,aAAa,GAAG,UAAU,GAAG,YAAY,GAAG,qBAAqB,GAAG,gBAAgB,GAAG,gBAAgB,CAAC;AAE9G,0DAA0D;AAC1D,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oFAkGwD,CAAC;AAErF,oEAAoE;AACpE,+EAA+E;AAC/E,gFAAgF;AAChF,6EAA6E;AAC7E,oCAAoC;AACpC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2DAiEyB,CAAC;AAE5D,kEAAkE;AAClE,MAAM,uBAAuB,GAAG,mEAAmE,CAAC;AAEpG,kEAAkE;AAClE,MAAM,uBAAuB,GAAG,mCAAmC,CAAC;AAEpE,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;2BAkBP,CAAC;AAE5B,MAAM,iBAAiB,GAAG;;sGAE4E,CAAC;AAEvG,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kFAoCsD,CAAC;AAEnF,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;kFAkB0D,CAAC;AAEnF;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAgB;IACpD,OAAO;;;;;;;;;;;;;;;;SAgBA,QAAQ,+DAA+D,QAAQ;;;;;;;;;;;;;;;;;;;;;;;EAuBtF,eAAe;;;;;;;;;;;;;;;;6LAgB4K,CAAA;AAC7L,CAAC;AAED,OAAO,EACL,UAAU,EACV,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,GAChB,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Provider IO adapters: the cli-bridge json-text output shape and the
3
+ * non-streaming fetch shim for OpenAI-compatible proxies that default to SSE.
4
+ */
5
+ declare const JSON_TEXT_OUTPUT: {
6
+ name: string;
7
+ responseFormat: Promise<{
8
+ type: "json";
9
+ }>;
10
+ parseCompleteOutput({ text }: {
11
+ text: string;
12
+ }): Promise<string>;
13
+ parsePartialOutput({ text }: {
14
+ text: string;
15
+ }): Promise<{
16
+ partial: string;
17
+ }>;
18
+ createElementStreamTransform(): undefined;
19
+ };
20
+ /**
21
+ * Build a fetch replacement that forces `"stream": false` on chat completions
22
+ * bodies for OpenAI-compatible gateways that default to SSE streaming.
23
+ */
24
+ declare function createForceNonStreamingFetch(): typeof fetch;
25
+ export { JSON_TEXT_OUTPUT, createForceNonStreamingFetch };
26
+ //# sourceMappingURL=provider-fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-fetch.d.ts","sourceRoot":"","sources":["../../src/brain/provider-fetch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,QAAA,MAAM,gBAAgB;;;;;kCAGgB;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;iCAGjB;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;;;;CAMpD,CAAC;AAEF;;;GAGG;AACH,iBAAS,4BAA4B,IAAI,OAAO,KAAK,CAoBpD;AAED,OAAO,EAAE,gBAAgB,EAAE,4BAA4B,EAAE,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Provider IO adapters: the cli-bridge json-text output shape and the
3
+ * non-streaming fetch shim for OpenAI-compatible proxies that default to SSE.
4
+ */
5
+ const JSON_TEXT_OUTPUT = {
6
+ name: 'json-text',
7
+ responseFormat: Promise.resolve({ type: 'json' }),
8
+ async parseCompleteOutput({ text }) {
9
+ return text;
10
+ },
11
+ async parsePartialOutput({ text }) {
12
+ return { partial: text };
13
+ },
14
+ createElementStreamTransform() {
15
+ return undefined;
16
+ },
17
+ };
18
+ /**
19
+ * Build a fetch replacement that forces `"stream": false` on chat completions
20
+ * bodies for OpenAI-compatible gateways that default to SSE streaming.
21
+ */
22
+ function createForceNonStreamingFetch() {
23
+ return async (input, init) => {
24
+ if (init?.body && typeof init.body === 'string') {
25
+ const body = init.body;
26
+ // Cheap content-sniff so we only rewrite chat-completions shaped bodies,
27
+ // not arbitrary POSTs the caller might make (embeddings, etc.).
28
+ if (body.includes('"messages"') && body.includes('"model"')) {
29
+ try {
30
+ const parsed = JSON.parse(body);
31
+ if (parsed.stream === undefined || parsed.stream === true) {
32
+ parsed.stream = false;
33
+ init = { ...init, body: JSON.stringify(parsed) };
34
+ }
35
+ }
36
+ catch {
37
+ // Non-JSON body — pass through unchanged.
38
+ }
39
+ }
40
+ }
41
+ return fetch(input, init);
42
+ };
43
+ }
44
+ export { JSON_TEXT_OUTPUT, createForceNonStreamingFetch };
45
+ //# sourceMappingURL=provider-fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-fetch.js","sourceRoot":"","sources":["../../src/brain/provider-fetch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,gBAAgB,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,CAAC;IAC1D,KAAK,CAAC,mBAAmB,CAAC,EAAE,IAAI,EAAoB;QAClD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAoB;QACjD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;IACD,4BAA4B;QAC1B,OAAO,SAAS,CAAC;IACnB,CAAC;CACF,CAAC;AAEF;;;GAGG;AACH,SAAS,4BAA4B;IACnC,OAAO,KAAK,EAAE,KAAwB,EAAE,IAAkB,EAAqB,EAAE;QAC/E,IAAI,IAAI,EAAE,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAChD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;YACtB,yEAAyE;YACzE,gEAAgE;YAChE,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5D,IAAI,CAAC;oBACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAA4B,CAAA;oBAC1D,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;wBAC1D,MAAM,CAAC,MAAM,GAAG,KAAK,CAAA;wBACrB,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAA;oBAClD,CAAC;gBACH,CAAC;gBAAC,MAAM,CAAC;oBACP,0CAA0C;gBAC5C,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAC3B,CAAC,CAAA;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,4BAA4B,EAAE,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Snapshot budgeting: dedup repeated element runs, cap total size while
3
+ * preserving interactive + content lines, and compact the first-turn snapshot.
4
+ *
5
+ * Pure functions over snapshot text — no Brain state.
6
+ */
7
+ /**
8
+ * Cap snapshot size to control token cost on large pages.
9
+ * Keeps the full snapshot when it fits within budget; otherwise preserves:
10
+ * 1. Interactive elements with refs (buttons, inputs, links — for action targets)
11
+ * 2. Content lines: term/definition/code/pre/paragraph (for extraction tasks
12
+ * like MDN, Python docs, W3C spec where the value the agent needs lives in
13
+ * a `<dl>/<code>/<pre>` block, not in an interactive element)
14
+ *
15
+ * New-page callers use a larger default budget; same-page callers can pass a
16
+ * tighter budget after the model has already seen the full snapshot once.
17
+ */
18
+ export declare function budgetSnapshot(snapshot: string, maxChars?: number): string;
19
+ export declare function compactFirstTurnSnapshot(snapshot: string): string;
20
+ //# sourceMappingURL=snapshot-budget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot-budget.d.ts","sourceRoot":"","sources":["../../src/brain/snapshot-budget.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwHH;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,SAAS,GAAG,MAAM,CAgE1E;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMjE"}