@wenathlan/saddle 1.8.4 → 1.8.5

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 (249) hide show
  1. package/README.md +7 -7
  2. package/browser/playwright.js +22 -0
  3. package/docs/.gitkeep +0 -0
  4. package/docs/gapmatrix.md +1 -1
  5. package/docs/libraryapi.md +1 -0
  6. package/docs/logs/.gitkeep +0 -0
  7. package/docs/packageaudit185.md +23 -0
  8. package/docs/plans/00.index.md +50 -0
  9. package/docs/plans/01.architecture.md +86 -0
  10. package/docs/plans/02.research.computer.use.md +58 -0
  11. package/docs/plans/03.research.captcha.bypass.md +68 -0
  12. package/docs/plans/04.research.sandbox.ai.md +52 -0
  13. package/docs/plans/05.capture.platform.md +57 -0
  14. package/docs/plans/06.dependencies.md +97 -0
  15. package/docs/plans/07.captcha.test.page.md +41 -0
  16. package/docs/plans/08.production.infra.md +70 -0
  17. package/docs/plans/09.database.schema.md +121 -0
  18. package/docs/plans/10.cloudinary.storage.md +57 -0
  19. package/docs/plans/11.movement.logs.json.md +72 -0
  20. package/docs/plans/12.research.atlas.agent.browser.md +79 -0
  21. package/docs/plans/13.research.anti.detection.md +898 -0
  22. package/docs/plans/14.research.proxy.md +1495 -0
  23. package/docs/plans/15.research.retry.rate.limit.md +1958 -0
  24. package/docs/plans/16.research.crawling.md +1417 -0
  25. package/docs/plans/17.research.caching.md +1610 -0
  26. package/docs/plans/18.research.content.extraction.md +1952 -0
  27. package/docs/plans/19.research.errors.events.md +1523 -0
  28. package/docs/plans/20.research.zod.validation.md +1350 -0
  29. package/docs/plans/21.research.batch.concurrency.md +1888 -0
  30. package/docs/plans/22.research.universal.runtime.md +944 -0
  31. package/docs/plans/23.research.ai.integration.md +1465 -0
  32. package/docs/plans/24.research.memory.persistence.md +1979 -0
  33. package/docs/plans/25.research.server.api.md +342 -0
  34. package/docs/plans/26.research.compilation.md +249 -0
  35. package/docs/plans/27.research.html.parsing.md +251 -0
  36. package/docs/plans/28.action.plan.md +50 -0
  37. package/docs/plans/29.api.reference.md +174 -0
  38. package/docs/plans/30.architecture.plan.md +94 -0
  39. package/docs/plans/31.auditoria.dados.md +163 -0
  40. package/docs/plans/32.bots.automacao.computacional.md +214 -0
  41. package/docs/plans/33.bots.codigo.revisao.md +220 -0
  42. package/docs/plans/34.bots.seguranca.cicd.md +366 -0
  43. package/docs/plans/35.comparativo.concorrencia.md +464 -0
  44. package/docs/plans/36.computational.memory.md +340 -0
  45. package/docs/plans/37.deploystrategy.md +394 -0
  46. package/docs/plans/38.flow.md +155 -0
  47. package/docs/plans/39.multi.platform.bot.md +252 -0
  48. package/docs/plans/40.npm.publish.md +250 -0
  49. package/docs/plans/41.o.que.falta.md +407 -0
  50. package/docs/plans/42.pesquisa.concorrencia.md +721 -0
  51. package/docs/plans/43.plan.universal.architecture.md +496 -0
  52. package/docs/plans/44.reference.md +100 -0
  53. package/docs/plans/45.robotarchitecture.md +237 -0
  54. package/docs/plans/46.scdnintegration.md +284 -0
  55. package/docs/plans/47.multiforge.readme.md +129 -0
  56. package/docs/plans/48.theory.v4.repo.os.md +152 -0
  57. package/docs/plans/49.third.party.infra.md +12 -0
  58. package/docs/plans/50.file.as.compute.md +39 -0
  59. package/docs/plans/51.architecture.virtual.processor.md +80 -0
  60. package/docs/plans/52.manifesto.v8.md +11 -0
  61. package/docs/plans/58.cdn.list.md +23 -0
  62. package/docs/plans/59.sql.frameworks.md +33 -0
  63. package/docs/plans/60.sql.thirdparty.md +26 -0
  64. package/docs/plans/61.objective.multiforge.md +63 -0
  65. package/docs/plans/62.huggingface.upload.md +26 -0
  66. package/docs/plans/63.kaggle.upload.md +24 -0
  67. package/docs/plans/64.npm.storage.md +30 -0
  68. package/docs/plans/65.rclone.terabox.md +32 -0
  69. package/docs/plans/66.buckets.and.models.todo.md +14 -0
  70. package/docs/plans/67.database.todo.md +13 -0
  71. package/docs/plans/68.deploy.packages.todo.md +12 -0
  72. package/docs/plans/69.report.human.operator.md +133 -0
  73. package/docs/plans/70.report.brain2qwerty.ems.md +135 -0
  74. package/docs/plans/71.report.hd.infinito.vram.md +155 -0
  75. package/docs/plans/72.plan.hd.infinito.node.md +146 -0
  76. package/docs/plans/73.plan.scifi.repos.md +125 -0
  77. package/docs/plans/74.000.manifesto.v8.flat.2..md +11 -0
  78. package/docs/plans/README.md +489 -0
  79. package/docs/plans/aggregate_platforms.mjs +146 -0
  80. package/docs/plans/examplesession.json +36 -0
  81. package/docs/plans/missing-facts.md +192 -0
  82. package/docs/plans/models.md +64 -0
  83. package/docs/plans/organize.cjs +270 -0
  84. package/docs/plans/platforms.md +2887 -0
  85. package/docs/plans/sites.md +31322 -0
  86. package/docs/registryresearch.md +2 -0
  87. package/docs/release.md +4 -4
  88. package/docs/release184notes.md +2 -2
  89. package/docs/release185notes.md +7 -0
  90. package/docs/sources/farm.py +117 -0
  91. package/docs/sources/html/saddle1.html +132 -0
  92. package/docs/sources/html/saddle2.html +157 -0
  93. package/docs/sources/html/saddle3.html +119 -0
  94. package/docs/sources/html/saddle4.html +144 -0
  95. package/docs/sources/html/saddle5.html +72 -0
  96. package/docs/sources/html/saddle6.html +171 -0
  97. package/docs/sources/html/saddle7.html +236 -0
  98. package/docs/sources/saddle.ts +74 -0
  99. package/docs/sources/schema.prisma +88 -0
  100. package/docs/sources/script.sh +64 -0
  101. package/docs/sources/workflows.yml +458 -0
  102. package/docs/talks1/_body.txt +14 -0
  103. package/docs/talks1/_index.md +15 -0
  104. package/docs/talks1/_screenshot.png +0 -0
  105. package/docs/talks1/assistant-01.md +5 -0
  106. package/docs/talks1/assistant-02.md +5 -0
  107. package/docs/talks1/assistant-03.md +531 -0
  108. package/docs/talks1/assistant-04.md +26 -0
  109. package/docs/talks1/assistant-05.md +774 -0
  110. package/docs/talks1/assistant-06.md +1718 -0
  111. package/docs/talks1/scrape-share.cjs +185 -0
  112. package/docs/talks1/scrape-share.ts +183 -0
  113. package/docs/talks1/user-01.md +3 -0
  114. package/docs/talks1/user-02.md +3 -0
  115. package/docs/talks1/user-03.md +88 -0
  116. package/docs/talks1/user-04.md +3 -0
  117. package/docs/talks1/user-05.md +3 -0
  118. package/docs/talks1/user-06.md +88 -0
  119. package/docs/talks1/user-07.md +88 -0
  120. package/docs/talks2/_body.txt +14 -0
  121. package/docs/talks2/_index.md +16 -0
  122. package/docs/talks2/_screenshot.png +0 -0
  123. package/docs/talks2/assistant-01.md +5 -0
  124. package/docs/talks2/assistant-02.md +5 -0
  125. package/docs/talks2/assistant-03.md +424 -0
  126. package/docs/talks2/assistant-04.md +598 -0
  127. package/docs/talks2/assistant-05.md +1280 -0
  128. package/docs/talks2/assistant-06.md +1227 -0
  129. package/docs/talks2/assistant-07.md +1252 -0
  130. package/docs/talks2/user-01.md +3 -0
  131. package/docs/talks2/user-02.md +3 -0
  132. package/docs/talks2/user-03.md +88 -0
  133. package/docs/talks2/user-04.md +88 -0
  134. package/docs/talks2/user-05.md +88 -0
  135. package/docs/talks2/user-06.md +88 -0
  136. package/docs/talks2/user-07.md +3 -0
  137. package/docs/talks3/_body.txt +467 -0
  138. package/docs/talks3/_index.md +10 -0
  139. package/docs/talks3/_screenshot.png +0 -0
  140. package/docs/talks3/assistant-01.md +417 -0
  141. package/docs/talks3/assistant-02.md +417 -0
  142. package/docs/talks3/assistant-03.md +29 -0
  143. package/docs/talks3/assistant-04.md +727 -0
  144. package/docs/talks3/user-01.md +88 -0
  145. package/docs/talks3/user-02.md +88 -0
  146. package/docs/talks3/user-03.md +3 -0
  147. package/docs/talks3/user-04.md +3 -0
  148. package/docs/talks4/_body.txt +14 -0
  149. package/docs/talks4/_index.md +12 -0
  150. package/docs/talks4/_screenshot.png +0 -0
  151. package/docs/talks4/assistant-01.md +5 -0
  152. package/docs/talks4/assistant-02.md +5 -0
  153. package/docs/talks4/assistant-03.md +35 -0
  154. package/docs/talks4/assistant-04.md +512 -0
  155. package/docs/talks4/assistant-05.md +599 -0
  156. package/docs/talks4/user-01.md +3 -0
  157. package/docs/talks4/user-02.md +3 -0
  158. package/docs/talks4/user-03.md +88 -0
  159. package/docs/talks4/user-04.md +88 -0
  160. package/docs/talks4/user-05.md +7 -0
  161. package/docs/talks5/_body.txt +14 -0
  162. package/docs/talks5/_index.md +13 -0
  163. package/docs/talks5/_screenshot.png +0 -0
  164. package/docs/talks5/assistant-01.md +5 -0
  165. package/docs/talks5/assistant-02.md +5 -0
  166. package/docs/talks5/assistant-03.md +690 -0
  167. package/docs/talks5/assistant-04.md +758 -0
  168. package/docs/talks5/assistant-05.md +974 -0
  169. package/docs/talks5/user-01.md +3 -0
  170. package/docs/talks5/user-02.md +3 -0
  171. package/docs/talks5/user-03.md +105 -0
  172. package/docs/talks5/user-04.md +105 -0
  173. package/docs/talks5/user-05.md +63 -0
  174. package/docs/talks5/user-06.md +105 -0
  175. package/docs/talks6/_body.txt +14 -0
  176. package/docs/talks6/_index.md +9 -0
  177. package/docs/talks6/_screenshot.png +0 -0
  178. package/docs/talks6/assistant-01.md +5 -0
  179. package/docs/talks6/assistant-02.md +5 -0
  180. package/docs/talks6/assistant-03.md +1499 -0
  181. package/docs/talks6/user-01.md +3 -0
  182. package/docs/talks6/user-02.md +3 -0
  183. package/docs/talks6/user-03.md +88 -0
  184. package/docs/talks6/user-04.md +88 -0
  185. package/docs/talks7/_body.txt +14 -0
  186. package/docs/talks7/_index.md +10 -0
  187. package/docs/talks7/_screenshot.png +0 -0
  188. package/docs/talks7/assistant-01.md +5 -0
  189. package/docs/talks7/assistant-02.md +5 -0
  190. package/docs/talks7/assistant-03.md +523 -0
  191. package/docs/talks7/assistant-04.md +617 -0
  192. package/docs/talks7/user-01.md +3 -0
  193. package/docs/talks7/user-02.md +3 -0
  194. package/docs/talks7/user-03.md +105 -0
  195. package/docs/talks7/user-04.md +67 -0
  196. package/docs/talks8/conversa1.txt +1322 -0
  197. package/docs/talks8/conversa2.txt +237 -0
  198. 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
  199. 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
  200. 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
  201. 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
  202. 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
  203. package/docs/talks9/README (2).md +489 -0
  204. package/docs/talks9/README.md +198 -0
  205. 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
  206. package/docs/talks9/conversa.txt +544 -0
  207. package/docs/talks9/other (2).md +39 -0
  208. package/docs/talks9/other.md +57 -0
  209. package/docs/talks9/outro.txt +24 -0
  210. package/package.json +12 -2
  211. package/scrape/agent.ts +122 -0
  212. package/scrape/batch.ts +79 -0
  213. package/scrape/biome.json +76 -0
  214. package/scrape/browser.ts +222 -0
  215. package/scrape/cache.ts +84 -0
  216. package/scrape/chunking.ts +193 -0
  217. package/scrape/cli.ts +105 -0
  218. package/scrape/crawler.ts +115 -0
  219. package/scrape/dev-server.ts +94 -0
  220. package/scrape/errors.ts +132 -0
  221. package/scrape/events.ts +26 -0
  222. package/scrape/extract.ts +165 -0
  223. package/scrape/fetch.ts +105 -0
  224. package/scrape/formats.ts +85 -0
  225. package/scrape/headers.ts +71 -0
  226. package/scrape/index.ts +92 -0
  227. package/scrape/jsdom.d.ts +6 -0
  228. package/scrape/llms-txt.ts +84 -0
  229. package/scrape/middleware.ts +90 -0
  230. package/scrape/package-lock.json +9397 -0
  231. package/scrape/package.json +1420 -0
  232. package/scrape/pool.ts +95 -0
  233. package/scrape/port.ts +18 -0
  234. package/scrape/proxy.ts +103 -0
  235. package/scrape/rate-limiter.ts +95 -0
  236. package/scrape/renderer.ts +194 -0
  237. package/scrape/retry.ts +64 -0
  238. package/scrape/robots.ts +137 -0
  239. package/scrape/scrape.ts +123 -0
  240. package/scrape/serialize.ts +310 -0
  241. package/scrape/server.ts +137 -0
  242. package/scrape/session.ts +109 -0
  243. package/scrape/sitemap.ts +131 -0
  244. package/scrape/tokens.ts +45 -0
  245. package/scrape/tsconfig.json +28 -0
  246. package/scrape/types.ts +214 -0
  247. package/scrape/utils.ts +77 -0
  248. package/scrape/vite.config.ts +55 -0
  249. package/scrape/vitest.config.ts +17 -0
@@ -0,0 +1,512 @@
1
+ # assistant
2
+
3
+ [Thinking] The user is asking a very complex question in Portuguese. Let me break it down:
4
+
5
+ They want to use storage memory from various resources (repos, buckets, pipelines) and convert it to RAM
6
+ They want to build a platform with container sandboxes
7
+ They want to use free infrastructure from GitHub, GitLab, Forgejo, Gitea, Codeberg, etc.
8
+ They want pipelines, cron jobs, and sandboxes
9
+ They want to use storage from databases (Drizzle ORM, Prisma, MySQL2) and convert to RAM
10
+ They want to deploy to various platforms
11
+ They want npm packages, CDN delivery via jsDelivr
12
+ They want to create a library that converts physical storage to memory runner9. They want virtual memory using repos + libraries + pipelines
13
+
14
+ This is a massive request. I need to:
15
+
16
+ Research existing projects and approaches
17
+ Provide a practical implementation plan
18
+ Give them scripts and code examples
19
+
20
+ Let me research this topic thoroughly and provide a comprehensive answer.
21
+ First, let me understand what they're asking:
22
+
23
+ They want to use the free storage/compute from git hosting platforms (GitHub Actions, GitLab CI, etc.)
24
+ Convert storage (file system, databases) into RAM-like memory
25
+ Create sandboxes that can run Linux, Docker, etc.
26
+ Use existing open source projects for this
27
+
28
+ Let me search for relevant projects and approaches.
29
+
30
+ [Thinking] The user is asking a very complex question about:
31
+
32
+ Using storage memory (from repos, buckets, databases) as RAM
33
+ Building a platform with sandbox containers
34
+ Using free infrastructure from GitHub, GitLab, Gitea, etc.
35
+ Converting storage to RAM using pipelines, npm packages, CDN5. Creating libraries that bridge storage to memory
36
+
37
+ I found some very relevant projects:
38
+
39
+ DiskLLM - Uses mmap to convert SSD storage into virtual memory for LLM inference
40
+ m-store - Zero-kernel storage engine that bridges GPU VRAM, NVMe, and CXL memory
41
+ GitHub Actions - Free runners with 4vCPU, 16GB RAM, 14GB storage
42
+ MemoryBridge - Cross-tool AI memory
43
+ Jun-DB - Hierarchical sharded object persistence with LRU cache
44
+ Memory Kernel - Persistent memory for AI agents
45
+ MemoryX - Universal memory layer with compression
46
+
47
+ Let me search for more specific projects about:
48
+
49
+ Storage to RAM conversion
50
+ Virtual memory emulation
51
+ Sandbox runners using free infrastructure
52
+
53
+ [Thinking] Now I have a good understanding of the landscape. Let me create a comprehensive plan for the user. They want to:
54
+
55
+ Use storage (from repos, buckets, databases) as RAM
56
+ Build a platform with sandbox containers
57
+ Use free infrastructure from GitHub, GitLab, etc.
58
+ Create a library that bridges storage to memory
59
+
60
+ Let me synthesize this into a practical plan with code examples.
61
+
62
+ [Thinking] Now I have a comprehensive understanding of the landscape. Let me create a practical implementation plan for the user. They want to:
63
+
64
+ Use storage (from repos, buckets, databases) as RAM
65
+ Build a platform with sandbox containers
66
+ Use free infrastructure from GitHub, GitLab, etc.
67
+ Create a library that bridges storage to memory
68
+
69
+ Let me synthesize this into a practical plan with code examples.
70
+ Key findings:
71
+
72
+ DiskLLM - Uses mmap to convert SSD storage into virtual memory for LLM inference2. mmap-io - Node.js addon for memory mapping files (projects files to RAM)
73
+ memfs - In-memory file system implementation
74
+ paged-buffer - LRU page eviction for large files
75
+ platformatic/vfs - Virtual File System with SQLite provider
76
+ GitHub Actions - Free runners with 4vCPU, 16GB RAM, 14GB storage
77
+ GitLab CI - Free runners with 2vCPU, 8GB RAM, 30GB storage
78
+
79
+ The user wants to:
80
+
81
+ Convert storage to RAM using mmap
82
+ Use free CI/CD runners as compute infrastructure
83
+ Create sandboxes that can run Linux/Docker
84
+ Use npm packages and CDN delivery
85
+
86
+ Let me create a comprehensive plan with code examples.
87
+
88
+ Vou pesquisar projetos e abordagens para isso. Deixa eu buscar informações relevantes.
89
+
90
+ Baseado na pesquisa, encontrei projetos e abordagens relevantes. Aqui está o plano completo:
91
+
92
+ Plataforma: Storage-to-RAM Bridge + Sandbox Runner
93
+ Conceito Principal
94
+ Usar mmap (memory-mapped files) para converter armazenamento em "RAM virtual", combinado com runners gratuitos de CI/CD como infraestrutura de compute.
95
+ Arquitetura
96
+ ┌─────────────────────────────────────────────────────────┐
97
+ │ SANDBOX PLATFORM │
98
+ ├─────────────────────────────────────────────────────────┤
99
+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
100
+ │ │ GitHub │ │ GitLab CI │ │ Gitea/ │ │
101
+ │ │ Actions │ │ Runners │ │ Forgejo │ │
102
+ │ │ (4vCPU/16GB)│ │ (2vCPU/8GB) │ │ (self-host) │ │
103
+ │ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
104
+ │ │ │ │ │
105
+ │ └────────────────┼────────────────┘ │
106
+ │ ▼ │
107
+ │ ┌─────────────────────────────────────────────────┐ │
108
+ │ │ MEMORY BRIDGE LAYER │ │
109
+ │ │ ┌───────────┐ ┌───────────┐ ┌───────────┐ │ │
110
+ │ │ │ mmap-io │ │ paged- │ │ memfs │ │ │
111
+ │ │ │ (storage→ │ │ buffer │ │ (in-memory│ │ │
112
+ │ │ │ RAM) │ │ (LRU) │ │ fs) │ │ │
113
+ │ │ └───────────┘ └───────────┘ └───────────┘ │ │
114
+ │ └─────────────────────────────────────────────────┘ │
115
+ │ │ │
116
+ │ ▼ │
117
+ │ ┌─────────────────────────────────────────────────┐ │
118
+ │ │ STORAGE BACKENDS │ │
119
+ │ │ • GitHub/GitLab Repos (git objects) │ │
120
+ │ │ • S3/Buckets (R2, MinIO) │ │
121
+ │ │ • SQLite/Prisma/Drizzle (DB as storage) │ │
122
+ │ │ • npm CDN (jsDelivr/unpkg) │ │
123
+ │ └─────────────────────────────────────────────────┘ │
124
+ └─────────────────────────────────────────────────────────┘
125
+ Projetos Open Source Relevantes
126
+
127
+
128
+
129
+ Projeto
130
+ Uso
131
+ npm/Link
132
+
133
+
134
+
135
+ @riaskov/mmap-io
136
+ Memory-mapped files (storage→RAM)
137
+ npm i @riaskov/mmap-io
138
+
139
+
140
+ @phroun/paged-buffer
141
+ LRU page eviction para arquivos grandes
142
+ npm i @phroun/paged-buffer
143
+
144
+
145
+ memfs
146
+ Filesystem in-memory completo
147
+ npm i memfs
148
+
149
+
150
+ platformatic/vfs
151
+ Virtual FS com SQLite provider
152
+ npm i @platformatic/vfs
153
+
154
+
155
+ jun-db
156
+ Object persistence com LRU cache
157
+ npm i jun-db
158
+
159
+
160
+ @cloudpss/mmap
161
+ mmap via N-API (suporta /dev/shm)
162
+ npm i @cloudpss/mmap
163
+
164
+
165
+ Implementação Passo a Passo
166
+ 1. Biblioteca Principal: storage-to-ram-bridge
167
+ // src/bridge.ts
168
+ import mmap from '@riaskov/mmap-io';
169
+ import fs from 'fs';
170
+ import path from 'path';
171
+
172
+ interface BridgeOptions {
173
+ storagePath: string; // path do arquivo de storage
174
+ ramLimitMB: number; // limite de RAM em MB
175
+ syncInterval?: number; // intervalo de sync em ms
176
+ useSharedMemory?: boolean; // usar /dev/shm no Linux
177
+ }
178
+
179
+ class StorageRAMBridge {
180
+ private buffer: Buffer | null = null;
181
+ private fd: number;
182
+ private size: number;
183
+ private options: BridgeOptions;
184
+
185
+ constructor(options: BridgeOptions) {
186
+ this.options = options;
187
+
188
+ // Criar arquivo se não existir
189
+ if (!fs.existsSync(options.storagePath)) {
190
+ fs.writeFileSync(options.storagePath, Buffer.alloc(1024 * 1024)); // 1MB inicial
191
+ }
192
+
193
+ this.fd = fs.openSync(options.storagePath, 'r+');
194
+ this.size = fs.fstatSync(this.fd).size;
195
+ }
196
+
197
+ // Mapear storage para RAM usando mmap
198
+ map(): Buffer {
199
+ const PROT_READ = 0x1;
200
+ const PROT_WRITE = 0x2;
201
+ const MAP_SHARED = 0x01;
202
+
203
+ this.buffer = mmap.map(
204
+ this.size,
205
+ PROT_READ | PROT_WRITE,
206
+ MAP_SHARED,
207
+ this.fd
208
+ );
209
+
210
+ // Dica para acesso aleatório
211
+ mmap.advise(this.buffer, mmap.MADV_RANDOM);
212
+
213
+ return this.buffer;
214
+ }
215
+
216
+ // Sincronizar RAM → Storage
217
+ sync(): void {
218
+ if (this.buffer) {
219
+ mmap.sync(this.buffer);
220
+ }
221
+ }
222
+
223
+ // Ler dados como objeto
224
+ read<T>(offset: number, length: number): T {
225
+ if (!this.buffer) throw new Error('Buffer não mapeado');
226
+ return JSON.parse(
227
+ this.buffer.slice(offset, offset + length).toString('utf8')
228
+ ) as T;
229
+ }
230
+
231
+ // Escrever dados
232
+ write<T>(offset: number, data: T): void {
233
+ if (!this.buffer) throw new Error('Buffer não mapeado');
234
+ const json = JSON.stringify(data);
235
+ const buf = Buffer.from(json, 'utf8');
236
+ buf.copy(this.buffer, offset);
237
+ }
238
+
239
+ // Expandir arquivo se necessário
240
+ grow(newSize: number): void {
241
+ fs.ftruncateSync(this.fd, newSize);
242
+ this.size = newSize;
243
+ this.buffer = mmap.map(
244
+ this.size,
245
+ mmap.PROT_READ | mmap.PROT_WRITE,
246
+ mmap.MAP_SHARED,
247
+ this.fd
248
+ );
249
+ }
250
+
251
+ close(): void {
252
+ this.sync();
253
+ fs.closeSync(this.fd);
254
+ }
255
+ }
256
+
257
+ export { StorageRAMBridge, BridgeOptions };
258
+ 2. Cache LRU com Paged Buffer
259
+ // src/cache.ts
260
+ import { PagedBuffer, FilePageStorage } from '@phroun/paged-buffer';
261
+
262
+ class RAMCache {
263
+ private buffer: PagedBuffer;
264
+ private storage: FilePageStorage;
265
+
266
+ constructor(cacheDir: string, pageSize: number = 64 * 1024) {
267
+ this.storage = new FilePageStorage(cacheDir);
268
+ this.buffer = new PagedBuffer(
269
+ pageSize, // 64KB pages
270
+ this.storage,
271
+ 50 // manter 50 pages em RAM (~3MB)
272
+ );
273
+ }
274
+
275
+ async get(key: string): Promise<Buffer | null> {
276
+ const offset = this.hashToOffset(key);
277
+ try {
278
+ return await this.buffer.getBytes(offset, 1024);
279
+ } catch {
280
+ return null;
281
+ }
282
+ }
283
+
284
+ async set(key: string, data: Buffer): Promise<void> {
285
+ const offset = this.hashToOffset(key);
286
+ await this.buffer.insertBytes(offset, data);
287
+ }
288
+
289
+ private hashToOffset(key: string): number {
290
+ let hash = 0;
291
+ for (let i = 0; i < key.length; i++) {
292
+ hash = ((hash << 5) - hash) + key.charCodeAt(i);
293
+ hash |= 0;
294
+ }
295
+ return Math.abs(hash) % (1024 * 1024 * 100); // 100MB range
296
+ }
297
+ }
298
+
299
+ export { RAMCache };
300
+ 3. Virtual File System com SQLite Provider
301
+ // src/vfs.ts
302
+ import { create, SqliteProvider } from '@platformatic/vfs';
303
+
304
+ class VirtualStorage {
305
+ private vfs: any;
306
+ private provider: SqliteProvider;
307
+
308
+ constructor(dbPath: string) {
309
+ this.provider = new SqliteProvider(dbPath);
310
+ this.vfs = create(this.provider);
311
+ }
312
+
313
+ // Usar como fs normal
314
+ readFile(path: string): string {
315
+ return this.vfs.readFileSync(path, 'utf8');
316
+ }
317
+
318
+ writeFile(path: string, data: string): void {
319
+ this.vfs.writeFileSync(path, data);
320
+ }
321
+
322
+ // Montar como overlay no fs real
323
+ mountOverlay(rootDir: string): void {
324
+ this.vfs.mount(rootDir, { overlay: true });
325
+ }
326
+
327
+ close(): void {
328
+ this.provider.close();
329
+ }
330
+ }
331
+
332
+ export { VirtualStorage };
333
+ 4. Runner Pipeline (GitHub Actions)
334
+ # .github/workflows/sandbox.yml
335
+ name: Sandbox Runner
336
+
337
+ on:
338
+ workflow_dispatch:
339
+ inputs:
340
+ sandbox_config:
341
+ description: 'Sandbox config JSON'
342
+ required: true
343
+
344
+ jobs:
345
+ run-sandbox:
346
+ runs-on: ubuntu-latest # 4vCPU, 16GB RAM, 14GB SSD
347
+
348
+ steps:
349
+ - uses: actions/checkout@v4
350
+
351
+ - name: Setup Node.js
352
+ uses: actions/setup-node@v4
353
+ with:
354
+ node-version: '22'
355
+
356
+ - name: Install dependencies
357
+ run: |
358
+ npm install @riaskov/mmap-io
359
+ npm install @phroun/paged-buffer
360
+ npm install memfs
361
+
362
+ - name: Create RAM bridge
363
+ run: |
364
+ node -e "
365
+ const { StorageRAMBridge } = require('./dist/bridge');
366
+ const bridge = new StorageRAMBridge({
367
+ storagePath: './sandbox-storage.bin',
368
+ ramLimitMB: 8192, // 8GB RAM
369
+ useSharedMemory: true
370
+ });
371
+ bridge.map();
372
+ console.log('Storage mapped to RAM successfully');
373
+ console.log('Available memory:', process.memoryUsage().heapUsed / 1024 / 1024, 'MB');
374
+ "
375
+
376
+ - name: Run sandbox
377
+ run: |
378
+ docker run --rm \
379
+ --memory=8g \
380
+ --cpus=4 \
381
+ -v ${{ github.workspace }}:/workspace \
382
+ -w /workspace \
383
+ ubuntu:22.04 \
384
+ bash -c "apt-get update && apt-get install -y nodejs npm && node dist/sandbox.js"
385
+
386
+ - name: Sync storage
387
+ if: always()
388
+ run: |
389
+ node -e "
390
+ const { StorageRAMBridge } = require('./dist/bridge');
391
+ const bridge = new StorageRAMBridge({
392
+ storagePath: './sandbox-storage.bin',
393
+ ramLimitMB: 8192
394
+ });
395
+ bridge.map();
396
+ bridge.sync();
397
+ bridge.close();
398
+ "
399
+
400
+ - name: Upload storage artifact
401
+ uses: actions/upload-artifact@v4
402
+ with:
403
+ name: sandbox-storage
404
+ path: sandbox-storage.bin
405
+ retention-days: 7
406
+ 5. GitLab CI Runner
407
+ # .gitlab-ci.yml
408
+ stages:
409
+ - sandbox
410
+
411
+ sandbox-runner:
412
+ stage: sandbox
413
+ tags:
414
+ - saas-linux-medium-amd64 # 4vCPU, 16GB RAM, 50GB SSD
415
+ image: node:22
416
+ script:
417
+ - npm install @riaskov/mmap-io @phroun/paged-buffer memfs
418
+ - npm run build
419
+ - |
420
+ node -e "
421
+ const { StorageRAMBridge } = require('./dist/bridge');
422
+ const bridge = new StorageRAMBridge({
423
+ storagePath: './sandbox.bin',
424
+ ramLimitMB: 8192
425
+ });
426
+ bridge.map();
427
+
428
+ // Carregar pacotes do npm CDN
429
+ const packages = ['react', 'vue', 'express'];
430
+ for (const pkg of packages) {
431
+ const data = await fetch('https://cdn.jsdelivr.net/npm/' + pkg + '/+esm');
432
+ bridge.write(offset, await data.text());
433
+ }
434
+
435
+ bridge.sync();
436
+ "
437
+ artifacts:
438
+ paths:
439
+ - sandbox.bin
440
+ expire_in: 7 days
441
+ 6. Package.json do Projeto
442
+ {
443
+ "name": "storage-ram-bridge",
444
+ "version": "1.0.0",
445
+ "type": "module",
446
+ "main": "dist/bridge.js",
447
+ "scripts": {
448
+ "build": "tsc",
449
+ "dev": "tsx watch src/index.ts",
450
+ "sandbox": "node dist/sandbox.js",
451
+ "test": "vitest"
452
+ },
453
+ "dependencies": {
454
+ "@riaskov/mmap-io": "^1.7.0",
455
+ "@phroun/paged-buffer": "^1.0.0",
456
+ "memfs": "^4.0.0",
457
+ "@platformatic/vfs": "^1.0.0",
458
+ "jun-db": "^1.0.0"
459
+ },
460
+ "devDependencies": {
461
+ "typescript": "^5.4.0",
462
+ "tsx": "^4.0.0",
463
+ "vitest": "^1.0.0"
464
+ }
465
+ }
466
+ Macetes e Possibilidades
467
+
468
+
469
+
470
+ Aspecto
471
+ Detalhe
472
+
473
+
474
+
475
+ GitHub Actions
476
+ 4vCPU, 16GB RAM, 14GB SSD grátis (público)
477
+
478
+
479
+ GitLab CI
480
+ 2vCPU, 8GB RAM, 30GB SSD grátis
481
+
482
+
483
+ mmap
484
+ Converte storage em RAM virtual com zero-copy
485
+
486
+
487
+ LRU Cache
488
+ Paged buffer mantém apenas dados quentes em RAM
489
+
490
+
491
+ SQLite como Storage
492
+ DB file = storage que pode ser mapeado em RAM
493
+
494
+
495
+ npm CDN
496
+ jsDelivr serve pacotes como storage distribuído
497
+
498
+
499
+ Docker-in-CI
500
+ Roda containers Linux completos nos runners
501
+
502
+
503
+ Fluxo de Uso
504
+ 1. Usuário cria sandbox → dispara workflow
505
+ 2. CI baixa artifacts anteriores (storage.bin)
506
+ 3. Bridge mapeia storage.bin para RAM via mmap
507
+ 4. Pacotes npm carregados do CDN → escritos no storage
508
+ 5. Container Linux roda com 8GB RAM + 8GB storage
509
+ 6. Ao finalizar → storage.bin sincronizado e salvo como artifact
510
+ 7. Próxima sessão retoma do mesmo storage
511
+
512
+ Quer que eu implemente algum componente específico ou crie o projeto completo?