@wenathlan/saddle 1.8.4 → 1.8.6

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 (263) hide show
  1. package/README.md +10 -10
  2. package/browser/playwright.js +22 -0
  3. package/docs/.gitkeep +0 -0
  4. package/docs/actionsincident.md +29 -0
  5. package/docs/branchaudit.md +21 -0
  6. package/docs/ecosystemplan.md +3 -3
  7. package/docs/featureaudit.md +1 -1
  8. package/docs/gapmatrix.md +8 -7
  9. package/docs/libraryapi.md +1 -0
  10. package/docs/logs/.gitkeep +0 -0
  11. package/docs/packageaudit185.md +23 -0
  12. package/docs/plans/00.index.md +50 -0
  13. package/docs/plans/01.architecture.md +86 -0
  14. package/docs/plans/02.research.computer.use.md +58 -0
  15. package/docs/plans/03.research.captcha.bypass.md +68 -0
  16. package/docs/plans/04.research.sandbox.ai.md +52 -0
  17. package/docs/plans/05.capture.platform.md +57 -0
  18. package/docs/plans/06.dependencies.md +97 -0
  19. package/docs/plans/07.captcha.test.page.md +41 -0
  20. package/docs/plans/08.production.infra.md +70 -0
  21. package/docs/plans/09.database.schema.md +121 -0
  22. package/docs/plans/10.cloudinary.storage.md +57 -0
  23. package/docs/plans/11.movement.logs.json.md +72 -0
  24. package/docs/plans/12.research.atlas.agent.browser.md +79 -0
  25. package/docs/plans/13.research.anti.detection.md +898 -0
  26. package/docs/plans/14.research.proxy.md +1495 -0
  27. package/docs/plans/15.research.retry.rate.limit.md +1958 -0
  28. package/docs/plans/16.research.crawling.md +1417 -0
  29. package/docs/plans/17.research.caching.md +1610 -0
  30. package/docs/plans/18.research.content.extraction.md +1952 -0
  31. package/docs/plans/19.research.errors.events.md +1523 -0
  32. package/docs/plans/20.research.zod.validation.md +1350 -0
  33. package/docs/plans/21.research.batch.concurrency.md +1888 -0
  34. package/docs/plans/22.research.universal.runtime.md +944 -0
  35. package/docs/plans/23.research.ai.integration.md +1465 -0
  36. package/docs/plans/24.research.memory.persistence.md +1979 -0
  37. package/docs/plans/25.research.server.api.md +342 -0
  38. package/docs/plans/26.research.compilation.md +249 -0
  39. package/docs/plans/27.research.html.parsing.md +251 -0
  40. package/docs/plans/28.action.plan.md +50 -0
  41. package/docs/plans/29.api.reference.md +174 -0
  42. package/docs/plans/30.architecture.plan.md +94 -0
  43. package/docs/plans/31.auditoria.dados.md +163 -0
  44. package/docs/plans/32.bots.automacao.computacional.md +214 -0
  45. package/docs/plans/33.bots.codigo.revisao.md +220 -0
  46. package/docs/plans/34.bots.seguranca.cicd.md +366 -0
  47. package/docs/plans/35.comparativo.concorrencia.md +464 -0
  48. package/docs/plans/36.computational.memory.md +340 -0
  49. package/docs/plans/37.deploystrategy.md +394 -0
  50. package/docs/plans/38.flow.md +155 -0
  51. package/docs/plans/39.multi.platform.bot.md +252 -0
  52. package/docs/plans/40.npm.publish.md +250 -0
  53. package/docs/plans/41.o.que.falta.md +407 -0
  54. package/docs/plans/42.pesquisa.concorrencia.md +721 -0
  55. package/docs/plans/43.plan.universal.architecture.md +496 -0
  56. package/docs/plans/44.reference.md +100 -0
  57. package/docs/plans/45.robotarchitecture.md +237 -0
  58. package/docs/plans/46.scdnintegration.md +284 -0
  59. package/docs/plans/47.multiforge.readme.md +129 -0
  60. package/docs/plans/48.theory.v4.repo.os.md +152 -0
  61. package/docs/plans/49.third.party.infra.md +12 -0
  62. package/docs/plans/50.file.as.compute.md +39 -0
  63. package/docs/plans/51.architecture.virtual.processor.md +80 -0
  64. package/docs/plans/52.manifesto.v8.md +11 -0
  65. package/docs/plans/58.cdn.list.md +23 -0
  66. package/docs/plans/59.sql.frameworks.md +33 -0
  67. package/docs/plans/60.sql.thirdparty.md +26 -0
  68. package/docs/plans/61.objective.multiforge.md +63 -0
  69. package/docs/plans/62.huggingface.upload.md +26 -0
  70. package/docs/plans/63.kaggle.upload.md +24 -0
  71. package/docs/plans/64.npm.storage.md +30 -0
  72. package/docs/plans/65.rclone.terabox.md +32 -0
  73. package/docs/plans/66.buckets.and.models.todo.md +14 -0
  74. package/docs/plans/67.database.todo.md +13 -0
  75. package/docs/plans/68.deploy.packages.todo.md +12 -0
  76. package/docs/plans/69.report.human.operator.md +133 -0
  77. package/docs/plans/70.report.brain2qwerty.ems.md +135 -0
  78. package/docs/plans/71.report.hd.infinito.vram.md +155 -0
  79. package/docs/plans/72.plan.hd.infinito.node.md +146 -0
  80. package/docs/plans/73.plan.scifi.repos.md +125 -0
  81. package/docs/plans/74.000.manifesto.v8.flat.2..md +11 -0
  82. package/docs/plans/README.md +489 -0
  83. package/docs/plans/aggregate_platforms.mjs +146 -0
  84. package/docs/plans/examplesession.json +36 -0
  85. package/docs/plans/missing-facts.md +192 -0
  86. package/docs/plans/models.md +64 -0
  87. package/docs/plans/organize.cjs +270 -0
  88. package/docs/plans/platforms.md +2887 -0
  89. package/docs/plans/sites.md +31322 -0
  90. package/docs/platformpipelineaudit.md +6 -2
  91. package/docs/registryresearch.md +2 -0
  92. package/docs/release.md +4 -4
  93. package/docs/release184notes.md +2 -2
  94. package/docs/release185notes.md +7 -0
  95. package/docs/releaseassets.md +16 -0
  96. package/docs/sources/farm.py +117 -0
  97. package/docs/sources/html/saddle1.html +132 -0
  98. package/docs/sources/html/saddle2.html +157 -0
  99. package/docs/sources/html/saddle3.html +119 -0
  100. package/docs/sources/html/saddle4.html +144 -0
  101. package/docs/sources/html/saddle5.html +72 -0
  102. package/docs/sources/html/saddle6.html +171 -0
  103. package/docs/sources/html/saddle7.html +236 -0
  104. package/docs/sources/saddle.ts +74 -0
  105. package/docs/sources/schema.prisma +88 -0
  106. package/docs/sources/script.sh +64 -0
  107. package/docs/sources/workflows.yml +458 -0
  108. package/docs/talks1/_body.txt +14 -0
  109. package/docs/talks1/_index.md +15 -0
  110. package/docs/talks1/_screenshot.png +0 -0
  111. package/docs/talks1/assistant-01.md +5 -0
  112. package/docs/talks1/assistant-02.md +5 -0
  113. package/docs/talks1/assistant-03.md +531 -0
  114. package/docs/talks1/assistant-04.md +26 -0
  115. package/docs/talks1/assistant-05.md +774 -0
  116. package/docs/talks1/assistant-06.md +1718 -0
  117. package/docs/talks1/scrape-share.cjs +185 -0
  118. package/docs/talks1/scrape-share.ts +183 -0
  119. package/docs/talks1/user-01.md +3 -0
  120. package/docs/talks1/user-02.md +3 -0
  121. package/docs/talks1/user-03.md +88 -0
  122. package/docs/talks1/user-04.md +3 -0
  123. package/docs/talks1/user-05.md +3 -0
  124. package/docs/talks1/user-06.md +88 -0
  125. package/docs/talks1/user-07.md +88 -0
  126. package/docs/talks2/_body.txt +14 -0
  127. package/docs/talks2/_index.md +16 -0
  128. package/docs/talks2/_screenshot.png +0 -0
  129. package/docs/talks2/assistant-01.md +5 -0
  130. package/docs/talks2/assistant-02.md +5 -0
  131. package/docs/talks2/assistant-03.md +424 -0
  132. package/docs/talks2/assistant-04.md +598 -0
  133. package/docs/talks2/assistant-05.md +1280 -0
  134. package/docs/talks2/assistant-06.md +1227 -0
  135. package/docs/talks2/assistant-07.md +1252 -0
  136. package/docs/talks2/user-01.md +3 -0
  137. package/docs/talks2/user-02.md +3 -0
  138. package/docs/talks2/user-03.md +88 -0
  139. package/docs/talks2/user-04.md +88 -0
  140. package/docs/talks2/user-05.md +88 -0
  141. package/docs/talks2/user-06.md +88 -0
  142. package/docs/talks2/user-07.md +3 -0
  143. package/docs/talks3/_body.txt +467 -0
  144. package/docs/talks3/_index.md +10 -0
  145. package/docs/talks3/_screenshot.png +0 -0
  146. package/docs/talks3/assistant-01.md +417 -0
  147. package/docs/talks3/assistant-02.md +417 -0
  148. package/docs/talks3/assistant-03.md +29 -0
  149. package/docs/talks3/assistant-04.md +727 -0
  150. package/docs/talks3/user-01.md +88 -0
  151. package/docs/talks3/user-02.md +88 -0
  152. package/docs/talks3/user-03.md +3 -0
  153. package/docs/talks3/user-04.md +3 -0
  154. package/docs/talks4/_body.txt +14 -0
  155. package/docs/talks4/_index.md +12 -0
  156. package/docs/talks4/_screenshot.png +0 -0
  157. package/docs/talks4/assistant-01.md +5 -0
  158. package/docs/talks4/assistant-02.md +5 -0
  159. package/docs/talks4/assistant-03.md +35 -0
  160. package/docs/talks4/assistant-04.md +512 -0
  161. package/docs/talks4/assistant-05.md +599 -0
  162. package/docs/talks4/user-01.md +3 -0
  163. package/docs/talks4/user-02.md +3 -0
  164. package/docs/talks4/user-03.md +88 -0
  165. package/docs/talks4/user-04.md +88 -0
  166. package/docs/talks4/user-05.md +7 -0
  167. package/docs/talks5/_body.txt +14 -0
  168. package/docs/talks5/_index.md +13 -0
  169. package/docs/talks5/_screenshot.png +0 -0
  170. package/docs/talks5/assistant-01.md +5 -0
  171. package/docs/talks5/assistant-02.md +5 -0
  172. package/docs/talks5/assistant-03.md +690 -0
  173. package/docs/talks5/assistant-04.md +758 -0
  174. package/docs/talks5/assistant-05.md +974 -0
  175. package/docs/talks5/user-01.md +3 -0
  176. package/docs/talks5/user-02.md +3 -0
  177. package/docs/talks5/user-03.md +105 -0
  178. package/docs/talks5/user-04.md +105 -0
  179. package/docs/talks5/user-05.md +63 -0
  180. package/docs/talks5/user-06.md +105 -0
  181. package/docs/talks6/_body.txt +14 -0
  182. package/docs/talks6/_index.md +9 -0
  183. package/docs/talks6/_screenshot.png +0 -0
  184. package/docs/talks6/assistant-01.md +5 -0
  185. package/docs/talks6/assistant-02.md +5 -0
  186. package/docs/talks6/assistant-03.md +1499 -0
  187. package/docs/talks6/user-01.md +3 -0
  188. package/docs/talks6/user-02.md +3 -0
  189. package/docs/talks6/user-03.md +88 -0
  190. package/docs/talks6/user-04.md +88 -0
  191. package/docs/talks7/_body.txt +14 -0
  192. package/docs/talks7/_index.md +10 -0
  193. package/docs/talks7/_screenshot.png +0 -0
  194. package/docs/talks7/assistant-01.md +5 -0
  195. package/docs/talks7/assistant-02.md +5 -0
  196. package/docs/talks7/assistant-03.md +523 -0
  197. package/docs/talks7/assistant-04.md +617 -0
  198. package/docs/talks7/user-01.md +3 -0
  199. package/docs/talks7/user-02.md +3 -0
  200. package/docs/talks7/user-03.md +105 -0
  201. package/docs/talks7/user-04.md +67 -0
  202. package/docs/talks8/conversa1.txt +1322 -0
  203. package/docs/talks8/conversa2.txt +237 -0
  204. package/docs/talks9/Beyond the Obvious_ 50 Plataformas Auto-Hospedadas de Forja de C/303/263digo para Al/303/251m de Gitea e GitLab.md" +174 -0
  205. package/docs/talks9/De NPM a Multi-Linguagem_ Uma Arquitetura T/303/251cnica para a Execu/303/247/303/243o Integrada de C/303/263digo no Ecossistema Node.js.md" +59 -0
  206. package/docs/talks9/De NPM a VMs Virtuais_ Uma An/303/241lise Arquitet/303/264nica para a Realiza/303/247/303/243o do Ciclo de Vida do Projeto SADDLE.md" +91 -0
  207. package/docs/talks9/Mapeamento da Engrenagem Computacional_ Uma Arquitetura para Execu/303/247/303/243o Isolada e Persist/303/252ncia em Ambientes Distribu/303/255dos.md" +116 -0
  208. package/docs/talks9/O Cen/303/241rio Pr/303/241tico do SADDLE_ Uma An/303/241lise de Viabilidade e Modelo de Ciclo de Vida Integrado.md" +128 -0
  209. package/docs/talks9/README (2).md +489 -0
  210. package/docs/talks9/README.md +198 -0
  211. package/docs/talks9/Viabilidade do Saddle_ Uma An/303/241lise T/303/251cnica da Transforma/303/247/303/243o de Armazenamento Remoto em Mem/303/263ria Computacional.md" +80 -0
  212. package/docs/talks9/conversa.txt +544 -0
  213. package/docs/talks9/other (2).md +39 -0
  214. package/docs/talks9/other.md +57 -0
  215. package/docs/talks9/outro.txt +24 -0
  216. package/extension/README.md +2 -2
  217. package/extension/build.js +1 -1
  218. package/extension/content.js +46 -4
  219. package/extension/manifest.json +1 -1
  220. package/extension/pagebridge.js +41 -0
  221. package/extension/protocol.js +21 -2
  222. package/extension/serviceworker.js +12 -5
  223. package/package.json +165 -10
  224. package/release/assets.js +70 -0
  225. package/scrape/agent.ts +122 -0
  226. package/scrape/batch.ts +79 -0
  227. package/scrape/biome.json +76 -0
  228. package/scrape/browser.ts +222 -0
  229. package/scrape/cache.ts +84 -0
  230. package/scrape/chunking.ts +193 -0
  231. package/scrape/cli.ts +105 -0
  232. package/scrape/crawler.ts +115 -0
  233. package/scrape/dev-server.ts +94 -0
  234. package/scrape/errors.ts +132 -0
  235. package/scrape/events.ts +26 -0
  236. package/scrape/extract.ts +165 -0
  237. package/scrape/fetch.ts +105 -0
  238. package/scrape/formats.ts +85 -0
  239. package/scrape/headers.ts +71 -0
  240. package/scrape/index.ts +92 -0
  241. package/scrape/jsdom.d.ts +6 -0
  242. package/scrape/llms-txt.ts +84 -0
  243. package/scrape/middleware.ts +90 -0
  244. package/scrape/package-lock.json +9397 -0
  245. package/scrape/package.json +1420 -0
  246. package/scrape/pool.ts +95 -0
  247. package/scrape/port.ts +18 -0
  248. package/scrape/proxy.ts +103 -0
  249. package/scrape/rate-limiter.ts +95 -0
  250. package/scrape/renderer.ts +194 -0
  251. package/scrape/retry.ts +64 -0
  252. package/scrape/robots.ts +137 -0
  253. package/scrape/scrape.ts +123 -0
  254. package/scrape/serialize.ts +310 -0
  255. package/scrape/server.ts +137 -0
  256. package/scrape/session.ts +109 -0
  257. package/scrape/sitemap.ts +131 -0
  258. package/scrape/tokens.ts +45 -0
  259. package/scrape/tsconfig.json +28 -0
  260. package/scrape/types.ts +214 -0
  261. package/scrape/utils.ts +77 -0
  262. package/scrape/vite.config.ts +55 -0
  263. package/scrape/vitest.config.ts +17 -0
@@ -0,0 +1,496 @@
1
+ # Plano: Arquitetura Universal WebScrape v2.0
2
+
3
+ ## 1. Visão Geral
4
+
5
+ A biblioteca `@devthink/webscrape` precisa funcionar em **TODOS os modos**:
6
+
7
+ | Modo | Como funciona |
8
+ |------|--------------|
9
+ | **Com navegador** | Playwright (Chromium/Firefox/WebKit) para páginas SPA/JS |
10
+ | **Sem navegador** | fetch + Cheerio para HTML estático |
11
+ | **Com Node.js** | `node:fs`, `node:child_process`, SQLite |
12
+ | **Sem Node.js** | Bun, Deno, edge runtimes, browsers |
13
+ | **Com web** | API HTTP (Hono), WebSocket, SSE |
14
+ | **Sem web** | CLI, binário compilado, biblioteca |
15
+ | **Com IA** | Token counting, chunking semântico, llms.txt, RAG |
16
+ | **Sem IA** | Scraping puro, extração de dados |
17
+ | **Com memória** | Redis, SQLite, IndexedDB, Workers KV |
18
+ | **Sem memória** | In-memory LRU, efêmero |
19
+ | **Com desktop** | CLI TUI, Electron, Tauri |
20
+ | **Sem desktop** | Web UI, serverless |
21
+ | **Com servidor** | API server, worker pool |
22
+ | **Sem servidor** | Standalone, binário compilado |
23
+ | **Com script** | npm package, ESM/CJS |
24
+ | **Sem script** | Bun compile binary, WASM |
25
+
26
+ ## 2. Estrutura de Diretórios
27
+
28
+ ```
29
+ WebScrape/
30
+ ├── index.ts # Barrel principal (lib universal)
31
+ ├── types.ts # Tipos + Zod schemas
32
+ ├── errors.ts # Hierarquia de erros
33
+ ├── events.ts # Typed EventEmitter (hooks)
34
+
35
+ ├── # ── Core Scraping ──
36
+ ├── fetch.ts # HTTP fetch universal (sem navegador)
37
+ ├── browser.ts # AgentBrowser (Playwright)
38
+ ├── scrape.ts # Strategy cascade: fetch → browser
39
+ ├── extract.ts # Extração HTML (Cheerio + Readability)
40
+ ├── serialize.ts # Serialização multi-formato
41
+ ├── formats.ts # Registros de formato
42
+
43
+ ├── # ── Infraestrutura ──
44
+ ├── retry.ts # Retry com backoff
45
+ ├── proxy.ts # Proxy rotation + pool
46
+ ├── rate-limiter.ts # Rate limiting por domínio
47
+ ├── cache.ts # Cache multi-camada
48
+ ├── session.ts # Cookie jar + sessões
49
+
50
+ ├── # ── Anti-Detection ──
51
+ ├── stealth.ts # Anti-detection (playwright-extra)
52
+ ├── fingerprint.ts # Geração de fingerprints
53
+ ├── headers.ts # Rotação de headers/UA
54
+
55
+ ├── # ── Crawling ──
56
+ ├── crawler.ts # BFS crawling com depth limit
57
+ ├── sitemap.ts # Parser de sitemap XML
58
+ ├── robots.ts # Parser de robots.txt
59
+
60
+ ├── # ── AI/LLM ──
61
+ ├── agent.ts # Formatação para LLMs
62
+ ├── tokens.ts # Token counting multi-modelo
63
+ ├── chunking.ts # Chunking semântico
64
+ ├── llms-txt.ts # Geração de llms.txt
65
+
66
+ ├── # ── Batch & Concurrency ──
67
+ ├── batch.ts # Batch scraping concorrente
68
+ ├── pool.ts # Browser pool
69
+
70
+ ├── # ── Middleware ──
71
+ ├── middleware.ts # Pipeline de middleware
72
+
73
+ ├── # ── Utilitários ──
74
+ ├── utils.ts # Funções utilitárias
75
+ ├── url.ts # URL normalization
76
+
77
+ ├── # ── CLI ──
78
+ ├── cli.ts # CLI binary (commander)
79
+
80
+ ├── # ── Server ──
81
+ ├── server.ts # API HTTP (Hono)
82
+
83
+ ├── # ── Renderer ──
84
+ ├── renderer.ts # Pygame bridge (opcional)
85
+
86
+ ├── # ── Config ──
87
+ ├── package.json
88
+ ├── tsconfig.json
89
+ ├── vite.config.ts
90
+ ├── vitest.config.ts
91
+ ├── biome.json
92
+ ├── .npmrc
93
+ ├── .gitignore
94
+ ├── .husky/
95
+ ├── .github/workflows/
96
+
97
+ ├── # ── Web UI ──
98
+ ├── web/
99
+ │ └── index.html
100
+
101
+ ├── # ── Docs ──
102
+ ├── docs/
103
+ │ ├── README.md
104
+ │ ├── API.md
105
+ │ ├── ARCHITECTURE.md
106
+ │ ├── CHANGELOG.md
107
+ │ └── RESEARCH-*.md
108
+
109
+ └── # ── Tests ──
110
+ └── tests/
111
+ ├── fetch.test.ts
112
+ ├── browser.test.ts
113
+ ├── scrape.test.ts
114
+ ├── extract.test.ts
115
+ ├── serialize.test.ts
116
+ ├── retry.test.ts
117
+ ├── proxy.test.ts
118
+ ├── cache.test.ts
119
+ ├── crawler.test.ts
120
+ ├── batch.test.ts
121
+ ├── agent.test.ts
122
+ ├── tokens.test.ts
123
+ ├── chunking.test.ts
124
+ ├── errors.test.ts
125
+ ├── events.test.ts
126
+ ├── middleware.test.ts
127
+ └── utils.test.ts
128
+ ```
129
+
130
+ ## 3. Strategy Cascade Architecture
131
+
132
+ ```
133
+ scrape(url, options)
134
+
135
+ ├─── options.mode === 'fetch' ──→ fetch.ts (HTTP + Cheerio)
136
+
137
+ ├─── options.mode === 'browser' ──→ browser.ts (Playwright)
138
+
139
+ └─── options.mode === 'auto' (default) ──→ scrape.ts
140
+
141
+ ├── 1. Tentar fetch (rápido, barato)
142
+ ├── 2. Detectar se precisa de JS rendering
143
+ │ ├── Estático → usar resultado do fetch
144
+ │ └── Dinâmico → usar Playwright
145
+ └── 3. Return resultado mais limpo
146
+ ```
147
+
148
+ ## 4. Módulos Novos — Especificações
149
+
150
+ ### 4.1 errors.ts — Hierarquia de Erros
151
+
152
+ ```typescript
153
+ WebScrapeError (base)
154
+ ├── ValidationError (400)
155
+ ├── TimeoutError (504)
156
+ ├── BlockedError (403)
157
+ ├── RateLimitError (429)
158
+ ├── ProxyError (502)
159
+ ├── ParseError (422)
160
+ ├── AuthError (401)
161
+ └── NetworkError (503)
162
+ ```
163
+
164
+ - Cada erro tem `code`, `statusCode`, `isRetryable`, `details`
165
+ - `Object.setPrototypeOf` para `instanceof` correto
166
+ - Recovery suggestions em cada erro
167
+
168
+ ### 4.2 events.ts — Hooks de Lifecycle
169
+
170
+ ```typescript
171
+ interface WebScrapeEvents {
172
+ 'request:start': [url: string, options: RequestOptions]
173
+ 'request:response': [response: Response, attempt: number]
174
+ 'request:error': [error: Error, attempt: number]
175
+ 'request:retry': [attempt: number, maxRetries: number]
176
+ 'request:complete': [stats: CrawlStats]
177
+ 'cache:hit': [key: string]
178
+ 'cache:miss': [key: string]
179
+ 'proxy:rotate': [proxy: string, reason: string]
180
+ 'proxy:error': [proxy: string, error: Error]
181
+ 'crawl:discover': [url: string, depth: number]
182
+ 'crawl:complete': [stats: CrawlStats]
183
+ }
184
+ ```
185
+
186
+ - Usa `emittery` (typed, async-first, AbortSignal, Symbol.dispose)
187
+ - Substitui EventEmitter padrão do Node
188
+
189
+ ### 4.3 fetch.ts — HTTP Universal
190
+
191
+ - Usa `globalThis.fetch` (disponível em TODOS os runtimes 2026)
192
+ - Suporta: cookies, headers rotation, proxy, timeout, retry
193
+ - Detecta se a página precisa de JS rendering
194
+ - Suporta HTTP/2 via undici (quando disponível)
195
+ - Cookie management via tough-cookie
196
+
197
+ ### 4.4 proxy.ts — Proxy Rotation
198
+
199
+ - Pool de proxies com health checking
200
+ - Estratégias: round-robin, random, sticky session
201
+ - Auto-disable em proxies mortos (3 failures consecutivas)
202
+ - Cooldown com revive automático
203
+ - Suporta: HTTP, HTTPS, SOCKS5
204
+
205
+ ### 4.5 cache.ts — Cache Multi-Camada
206
+
207
+ - L1: In-memory LRU (lru-cache v11)
208
+ - L2: Persistent (keyv com adapter: SQLite/Redis/IndexedDB)
209
+ - TTL por tipo de conteúdo:
210
+ - Estático (about, policies): 24-72h
211
+ - Semi-estático (produtos): 1-6h
212
+ - Dinâmico (search): 30s-5min
213
+ - ETag/Last-Modified conditional GET
214
+
215
+ ### 4.6 chunking.ts — Chunking Semântico
216
+
217
+ - Split por headings Markdown (H1/H2/H3)
218
+ - Overlap de 10-20%
219
+ - Max 512 tokens por chunk
220
+ - Preserva código blocks inteiros
221
+ - Inclui heading path em cada chunk
222
+ - Hierarchical parent-child para RAG
223
+
224
+ ### 4.7 tokens.ts — Token Counting Multi-Modelo
225
+
226
+ - OpenAI: js-tiktoken (o200k_base)
227
+ - Claude: API ou approximação (p50k_base ±10-30%)
228
+ - Gemini: API ou bpe-lite (100% accuracy)
229
+ - Fallback: estimateTokens (chars/4)
230
+ - Edge runtime compatible
231
+
232
+ ### 4.8 llms-txt.ts — Geração de llms.txt
233
+
234
+ - Extrai headings, links, descriptions de páginas
235
+ - Gera formato padronizado (llmstxt.org)
236
+ - Suporta llms-full.txt (conteúdo concatenado)
237
+ - Validação: exato H1, blockquote summary, URLs absolutas
238
+
239
+ ### 4.9 middleware.ts — Pipeline
240
+
241
+ - Koa-style onion model
242
+ - Cada middleware recebe `ctx` e `next`
243
+ - Middleware para: auth, rate-limit, retry, cache, logging
244
+ - Extensível via plugins
245
+
246
+ ### 4.10 server.ts — API HTTP
247
+
248
+ - Hono framework (multi-runtime)
249
+ - Endpoints:
250
+ - `POST /v1/scrape` — sync scrape
251
+ - `POST /v1/scrape/async` — async scrape
252
+ - `GET /v1/scrape/:taskId` — get result
253
+ - `POST /v1/batch` — batch scrape
254
+ - `POST /v1/crawl` — start crawl
255
+ - `GET /health` — health check
256
+ - SSE para progress updates
257
+ - Rate limiting por API key
258
+ - OpenAPI spec gerado
259
+
260
+ ## 5. Dependências
261
+
262
+ ### Production (adicionar)
263
+
264
+ | Pacote | Versão | Propósito |
265
+ |--------|--------|-----------|
266
+ | `zod` | ^4.4.3 | Validação runtime |
267
+ | `p-retry` | ^8.0.0 | Retry com backoff |
268
+ | `p-limit` | ^7.3.0 | Controle concorrência |
269
+ | `p-queue` | ^9.2.0 | Fila com prioridade |
270
+ | `robots-parser` | ^3.0.1 | Parser robots.txt |
271
+ | `sitemapper` | ^4.1.6 | Parser sitemap XML |
272
+ | `turndown` | ^7.2.4 | HTML → Markdown |
273
+ | `turndown-plugin-gfm` | ^1.0.2 | GFM tables |
274
+ | `@mozilla/readability` | ^0.6.0 | Extração conteúdo principal |
275
+ | `lru-cache` | ^11.0.0 | Cache LRU |
276
+ | `keyv` | ^5.6.0 | KV store cross-runtime |
277
+ | `hono` | ^4.0.0 | HTTP server |
278
+ | `commander` | ^14.0.3 | CLI |
279
+ | `emittery` | ^2.0.0 | Typed EventEmitter |
280
+ | `normalize-url` | ^9.0.0 | URL normalization |
281
+
282
+ ### Production (manter)
283
+
284
+ | Pacote | Nota |
285
+ |--------|------|
286
+ | `playwright` | ^1.60.0 |
287
+ | `cheerio` | ^1.2.0 |
288
+ | `jsdom` | ^29.1.1 |
289
+ | `chalk` | ^5.6.2 |
290
+
291
+ ### Production (REMOVER)
292
+
293
+ | Pacote | Motivo |
294
+ |--------|--------|
295
+ | `@inquirer/prompts` | UI interativa, não core |
296
+ | `@inkjs/ui` | Ink components |
297
+ | `@inquirer/core` | UI interativa |
298
+ | `@opencode-ai/plugin` | Plugin específico |
299
+ | `@types/blessed` | TUI blessed |
300
+ | `better-sqlite3` | Mover para optional |
301
+ | `blessed` | TUI framework |
302
+ | `cfonts` | ASCII art fonts |
303
+ | `chalk-animation` | CLI animations |
304
+ | `cli-table3` | CLI tables |
305
+ | `cross-spawn` | Subprocess spawning |
306
+ | `figlet` | ASCII art |
307
+ | `fuzzysort` | Fuzzy matching |
308
+ | `gradient-string` | CLI gradient |
309
+ | `hls.js` | Video streaming |
310
+ | `ink` | React TUI |
311
+ | `ink-big-text` | Ink component |
312
+ | `ink-gradient` | Ink component |
313
+ | `ink-link` | Ink component |
314
+ | `listr2` | Task runner |
315
+ | `marked` | MD parser (usar turndown) |
316
+ | `ora` | Spinner |
317
+ | `react` | UI framework |
318
+ | `react-devtools-core` | Dev tools |
319
+ | `react-reconciler` | React internals |
320
+ | `scheduler` | React scheduler |
321
+ | `sharp` | Image processing |
322
+
323
+ ### Optional (novo)
324
+
325
+ | Pacote | Versão | Propósito |
326
+ |--------|--------|-----------|
327
+ | `playwright` | ^1.60.0 | Opcional para quem só quer fetch |
328
+ | `playwright-extra` | ^1.7.9 | Stealth plugin |
329
+ | `puppeteer-extra-plugin-stealth` | ^2.11.2 | Evasion modules |
330
+
331
+ ### Dev Dependencies (adicionar)
332
+
333
+ | Pacote | Propósito |
334
+ |--------|-----------|
335
+ | `unplugin-dts` | Gerar .d.ts (sucessor vite-plugin-dts) |
336
+ | `@arethetypeswrong/cli` | Validar tipos |
337
+ | `publint` | Validar package.json |
338
+ | `husky` ^9.0.0 | Git hooks |
339
+ | `lint-staged` ^15.0.0 | Lint staged files |
340
+
341
+ ## 6. Configurações de Build
342
+
343
+ ### tsconfig.json
344
+
345
+ ```json
346
+ {
347
+ "compilerOptions": {
348
+ "target": "ES2024",
349
+ "module": "ESNext",
350
+ "moduleResolution": "bundler",
351
+ "lib": ["ES2024", "DOM", "DOM.Iterable"],
352
+ "strict": true,
353
+ "declaration": true,
354
+ "declarationMap": true,
355
+ "sourceMap": true,
356
+ "outDir": "./dist",
357
+ "rootDir": ".",
358
+ "noEmit": true,
359
+ "isolatedModules": true,
360
+ "esModuleInterop": true,
361
+ "skipLibCheck": true,
362
+ "verbatimModuleSyntax": true,
363
+ "types": ["node"]
364
+ },
365
+ "include": ["*.ts"],
366
+ "exclude": ["node_modules", "dist", "web", "tests"]
367
+ }
368
+ ```
369
+
370
+ ### vite.config.ts
371
+
372
+ ```typescript
373
+ import { defineConfig } from "vite";
374
+ import dts from "vite-plugin-dts";
375
+ import { resolve } from "path";
376
+
377
+ export default defineConfig({
378
+ root: "web",
379
+ build: {
380
+ lib: {
381
+ entry: resolve(__dirname, "index.ts"),
382
+ name: "DevThinkWebScrape",
383
+ formats: ["es", "cjs"],
384
+ fileName: (format) => `index.${format === "es" ? "mjs" : "js"}`,
385
+ },
386
+ rollupOptions: {
387
+ external: [
388
+ "playwright", "cheerio", "jsdom",
389
+ "zod", "p-retry", "p-limit", "p-queue",
390
+ "robots-parser", "sitemapper",
391
+ "turndown", "turndown-plugin-gfm",
392
+ "@mozilla/readability", "lru-cache", "keyv",
393
+ "hono", "commander", "emittery", "normalize-url",
394
+ "node:fs", "node:path", "node:child_process", "node:http",
395
+ ],
396
+ },
397
+ },
398
+ plugins: [dts()],
399
+ server: { port: 5175, host: "127.0.0.1", cors: true },
400
+ });
401
+ ```
402
+
403
+ ### package.json (atualizado)
404
+
405
+ ```json
406
+ {
407
+ "name": "@devthink/webscrape",
408
+ "version": "2.0.0",
409
+ "type": "module",
410
+ "main": "./dist/index.js",
411
+ "types": "./dist/index.d.ts",
412
+ "bin": { "webscrape": "./dist/cli.js" },
413
+ "exports": {
414
+ ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
415
+ "./fetch": { "types": "./dist/fetch.d.ts", "import": "./dist/fetch.js" },
416
+ "./browser": { "types": "./dist/browser.d.ts", "import": "./dist/browser.js" },
417
+ "./scrape": { "types": "./dist/scrape.d.ts", "import": "./dist/scrape.js" },
418
+ "./agent": { "types": "./dist/agent.d.ts", "import": "./dist/agent.js" },
419
+ "./server": { "types": "./dist/server.d.ts", "import": "./dist/server.js" },
420
+ "./cli": { "import": "./dist/cli.js" },
421
+ "./types": { "types": "./dist/types.d.ts", "import": "./dist/types.js" }
422
+ },
423
+ "files": ["dist", "web/", "docs/", "README.md"],
424
+ "sideEffects": false,
425
+ "scripts": {
426
+ "build": "tsc --noEmit && vite build",
427
+ "dev": "vite",
428
+ "test": "vitest run",
429
+ "test:watch": "vitest",
430
+ "test:coverage": "vitest run --coverage",
431
+ "lint": "biome check .",
432
+ "lint:fix": "biome check --write .",
433
+ "typecheck": "tsc --noEmit",
434
+ "check": "npm run typecheck && npm run lint && npm run test",
435
+ "validate": "publint && attw"
436
+ },
437
+ "engines": { "node": ">=20.0.0", "bun": ">=1.0.0" },
438
+ "publishConfig": { "access": "public" }
439
+ }
440
+ ```
441
+
442
+ ## 7. Fases de Execução
443
+
444
+ ### Fase 1: Limpeza (1 subagente)
445
+ - Remover `src/`, `webscrape.exe`, `webscrape.ts`, `web/demo.html`
446
+ - Limpar package.json de deps desnecessárias
447
+ - Atualizar tsconfig.json
448
+
449
+ ### Fase 2: Core Infrastructure (5 subagentes paralelos)
450
+ - `errors.ts` + `events.ts` + `types.ts` (com Zod schemas)
451
+ - `retry.ts` + `rate-limiter.ts`
452
+ - `proxy.ts` + `session.ts` + `headers.ts`
453
+ - `cache.ts` (multi-camada com lru-cache + keyv)
454
+ - `middleware.ts`
455
+
456
+ ### Fase 3: Core Scraping (4 subagentes paralelos)
457
+ - `fetch.ts` (HTTP universal com Cheerio)
458
+ - `browser.ts` (refatorar AgentBrowser)
459
+ - `scrape.ts` (strategy cascade)
460
+ - `extract.ts` (melhorar com Readability + JSON-LD)
461
+
462
+ ### Fase 4: Crawling & Batch (3 subagentes paralelos)
463
+ - `crawler.ts` (BFS + depth limit)
464
+ - `sitemap.ts` + `robots.ts`
465
+ - `batch.ts` + `pool.ts`
466
+
467
+ ### Fase 5: AI/LLM (3 subagentes paralelos)
468
+ - `agent.ts` (melhorar formatação)
469
+ - `tokens.ts` + `chunking.ts`
470
+ - `llms-txt.ts`
471
+
472
+ ### Fase 6: Server & CLI (2 subagentes paralelos)
473
+ - `server.ts` (Hono API)
474
+ - `cli.ts` (refatorar com commander)
475
+
476
+ ### Fase 7: Build & Config (1 subagente)
477
+ - Atualizar package.json, vite.config, biome.json
478
+ - Criar .husky/, .github/workflows/
479
+ - Build e validação
480
+
481
+ ### Fase 8: Tests (2 subagentes paralelos)
482
+ - Testes unitários para todos os novos módulos
483
+ - Cobertura mínima 60%
484
+
485
+ ### Fase 9: Docs & Preview (1 subagente)
486
+ - Atualizar README.md, API.md, ARCHITECTURE.md
487
+ - Atualizar web/index.html com novas features
488
+ - Criar CHANGELOG.md
489
+
490
+ **Total: ~22 subagentes de implementação**
491
+
492
+ ## 8. Referências
493
+
494
+ - Pesquisa completa em `docs/RESEARCH-01-anti-detection.md` até `docs/RESEARCH-15-html-parsing.md`
495
+ - 18 subagentes de pesquisa executados
496
+ - Dados coletados de npm, GitHub, documentação oficial, benchmarks 2026
@@ -0,0 +1,100 @@
1
+ # Saddle Robot Documentation Reference
2
+
3
+ > Reference index for all saddle robot documentation.
4
+ > Auto-generated summary of planning documents.
5
+
6
+ ## Project Overview
7
+
8
+ **saddle** -- Super bot platform combining browser automation,
9
+ scraping, captcha bypass, and multi-platform bot capability
10
+ with computational memory architecture.
11
+
12
+ ## Documentation Structure
13
+
14
+ ### Planning Documents (`docs/plans`)
15
+
16
+ | # | Document | Purpose |
17
+ |---|----------|---------|
18
+ | — | `00-indice-geral.md` | Primary index (original project) |
19
+ | — | `action-plan.md` | Action plan and next steps |
20
+ | 1 | `saddlerobotarchitecture.md` | Super bot architecture overview |
21
+ | 2 | `saddledeploystrategy.md` | Deploy strategies for all platforms |
22
+ | 3 | `saddlecomputationalmemory.md` | Storage-to-compute memory system |
23
+ | 4 | `saddlemultiplatformbot.md` | Multi-platform bot engine |
24
+ | 5 | `saddlenpmpublish.md` | NPM package publishing guide |
25
+ | 6 | `saddlescdnintegration.md` | SCDN integration documentation |
26
+ | — | `bots-codigo-revisao.md` | Best AI code review bots (research) |
27
+ | — | `bots-automacao-computacional.md` | Best computational automation bots (research) |
28
+ | — | `bots-seguranca-cicd.md` | Bot research (security + CI/CD) |
29
+
30
+ ### Historical Research
31
+
32
+ | Document | Purpose |
33
+ |----------|---------|
34
+ | `RESEARCH-01-anti-detection.md` | Anti-detection techniques |
35
+ | `RESEARCH-02-proxy.md` | Proxy configuration |
36
+ | `RESEARCH-03-retry-rate-limit.md` | Retry and rate limiting |
37
+ | `RESEARCH-04-crawling.md` | Web crawling strategies |
38
+ | `RESEARCH-05-caching.md` | Caching patterns |
39
+ | `RESEARCH-06-content-extraction.md` | Content extraction methods |
40
+ | `RESEARCH-07-errors-events.md` | Error handling and events |
41
+ | `RESEARCH-08-zod-validation.md` | Schema validation |
42
+ | `RESEARCH-09-batch-concurrency.md` | Batch processing concurrency |
43
+ | `RESEARCH-10-universal-runtime.md` | Universal runtime configuration |
44
+ | `RESEARCH-11-ai-integration.md` | AI integration patterns |
45
+ | `RESEARCH-12-memory-persistence.md` | Memory persistence strategies |
46
+ | `RESEARCH-13-server-api.md` | Server API design |
47
+ | `RESEARCH-14-compilation.md` | Compilation strategies |
48
+ | `RESEARCH-15-html-parsing.md` | HTML parsing techniques |
49
+
50
+ ### Decision Transcripts (`docs/talks`)
51
+
52
+ Architecture and design decision transcripts.
53
+
54
+ ### Logs (`docs/logs`)
55
+
56
+ JSON movement logs from Brave capture sessions.
57
+
58
+ ## Key Concepts
59
+
60
+ ### Computational Memory
61
+
62
+ Transform storage objects (files, blobs in repositories)
63
+ into virtual RAM and GPU memory for processing. This
64
+ enables effectively unlimited memory capacity.
65
+
66
+ ### Multi-Platform Bot
67
+
68
+ Unified bot interface operating across GitHub, GitLab,
69
+ Forgejo, Gitea, and Discord via adapter pattern.
70
+
71
+ ### Deploy Strategies
72
+
73
+ Six deployment strategies: Netlify, Vercel, GitHub Actions,
74
+ GitLab CI, Forgejo Actions, Gitea Actions, and Docker/VM
75
+ self-hosted.
76
+
77
+ ### SCDN Integration
78
+
79
+ Static Content Delivery Network for browser assets, capture
80
+ files, and deployment payloads with edge caching.
81
+
82
+ ### NPM Publishing
83
+
84
+ Package `@devthink/saddle` available as both library and
85
+ CLI binary.
86
+
87
+ ## Architecture Rules (from arch skill)
88
+
89
+ - No `src/` folder. Root based.
90
+ - No deep nesting. Subfolders organized by domain only.
91
+ - lowercase code, lowercase files. No uppercase. No underscore. No hyphen.
92
+ - English docs. JSDoc comments. No emoji.
93
+ - Logic grouped. Up to 20 related logics per file.
94
+ - Error catcher embedded in every script.
95
+ - No hardcoded hostnames. No localhost. Ports randomized then locked.
96
+ - Library works as binary, CLI, headless, and browser.
97
+
98
+ ## License
99
+
100
+ MIT