@wenathlan/saddle 1.8.18 → 2.0.3

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 (802) hide show
  1. package/Dockerfile +1346 -0
  2. package/README.md +33 -12
  3. package/alternatives.ts +1218 -0
  4. package/biome.json +153 -0
  5. package/boards.json +1517 -0
  6. package/compute.ts +3144 -0
  7. package/cores.json +1801 -0
  8. package/dist/acquisition.d.ts +359 -0
  9. package/dist/acquisition.d.ts.map +1 -0
  10. package/dist/acquisition.js +629 -0
  11. package/dist/acquisition.js.map +1 -0
  12. package/dist/alternatives.d.ts +509 -0
  13. package/dist/alternatives.d.ts.map +1 -0
  14. package/dist/alternatives.js +951 -0
  15. package/dist/alternatives.js.map +1 -0
  16. package/dist/automation.d.ts +426 -0
  17. package/dist/automation.d.ts.map +1 -0
  18. package/dist/automation.js +561 -0
  19. package/dist/automation.js.map +1 -0
  20. package/dist/browser.d.ts +562 -0
  21. package/dist/browser.d.ts.map +1 -0
  22. package/dist/browser.js +1057 -0
  23. package/dist/browser.js.map +1 -0
  24. package/dist/capacitor.config.d.ts +13 -0
  25. package/dist/capacitor.config.d.ts.map +1 -0
  26. package/dist/capacitor.config.js +26 -0
  27. package/dist/capacitor.config.js.map +1 -0
  28. package/dist/cli.d.ts +17 -0
  29. package/dist/cli.d.ts.map +1 -0
  30. package/dist/cli.js +111 -0
  31. package/dist/cli.js.map +1 -0
  32. package/dist/communication.d.ts +192 -0
  33. package/dist/communication.d.ts.map +1 -0
  34. package/dist/communication.js +418 -0
  35. package/dist/communication.js.map +1 -0
  36. package/dist/compute.d.ts +1161 -0
  37. package/dist/compute.d.ts.map +1 -0
  38. package/dist/compute.js +2273 -0
  39. package/dist/compute.js.map +1 -0
  40. package/dist/distribution.d.ts +529 -0
  41. package/dist/distribution.d.ts.map +1 -0
  42. package/dist/distribution.js +811 -0
  43. package/dist/distribution.js.map +1 -0
  44. package/dist/execution.d.ts +530 -0
  45. package/dist/execution.d.ts.map +1 -0
  46. package/dist/execution.js +761 -0
  47. package/dist/execution.js.map +1 -0
  48. package/dist/format.d.ts +19 -0
  49. package/dist/format.d.ts.map +1 -0
  50. package/dist/format.js +60 -0
  51. package/dist/format.js.map +1 -0
  52. package/dist/foundation.d.ts +176 -0
  53. package/dist/foundation.d.ts.map +1 -0
  54. package/dist/foundation.js +309 -0
  55. package/dist/foundation.js.map +1 -0
  56. package/dist/index.d.ts +733 -123
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +1018 -123
  59. package/dist/index.js.map +1 -1
  60. package/dist/integration.d.ts +236 -0
  61. package/dist/integration.d.ts.map +1 -0
  62. package/dist/integration.js +236 -0
  63. package/dist/integration.js.map +1 -0
  64. package/dist/intelligence.d.ts +94 -0
  65. package/dist/intelligence.d.ts.map +1 -0
  66. package/dist/intelligence.js +145 -0
  67. package/dist/intelligence.js.map +1 -0
  68. package/dist/{isolation/contracts.d.ts → isolation.d.ts} +12 -1
  69. package/dist/isolation.d.ts.map +1 -0
  70. package/dist/{isolation/contracts.js → isolation.js} +13 -1
  71. package/dist/isolation.js.map +1 -0
  72. package/dist/media.d.ts +344 -0
  73. package/dist/media.d.ts.map +1 -0
  74. package/dist/media.js +986 -0
  75. package/dist/media.js.map +1 -0
  76. package/dist/modes.d.ts +359 -0
  77. package/dist/modes.d.ts.map +1 -0
  78. package/dist/modes.js +134 -0
  79. package/dist/modes.js.map +1 -0
  80. package/dist/{library/public.d.ts → operations.d.ts} +15 -1
  81. package/dist/operations.d.ts.map +1 -0
  82. package/dist/{library/public.js → operations.js} +18 -7
  83. package/dist/operations.js.map +1 -0
  84. package/dist/orchestrator.d.ts +1339 -0
  85. package/dist/orchestrator.d.ts.map +1 -0
  86. package/dist/orchestrator.js +4308 -0
  87. package/dist/orchestrator.js.map +1 -0
  88. package/dist/packager/targetcli.js +4 -22
  89. package/dist/performance.d.ts +416 -0
  90. package/dist/performance.d.ts.map +1 -0
  91. package/dist/performance.js +827 -0
  92. package/dist/performance.js.map +1 -0
  93. package/dist/quantum.d.ts +810 -0
  94. package/dist/quantum.d.ts.map +1 -0
  95. package/dist/quantum.js +2073 -0
  96. package/dist/quantum.js.map +1 -0
  97. package/dist/render.d.ts +381 -0
  98. package/dist/render.d.ts.map +1 -0
  99. package/dist/render.js +1073 -0
  100. package/dist/render.js.map +1 -0
  101. package/dist/scheduler.d.ts +596 -0
  102. package/dist/scheduler.d.ts.map +1 -0
  103. package/dist/scheduler.js +1259 -0
  104. package/dist/scheduler.js.map +1 -0
  105. package/dist/security.d.ts +501 -0
  106. package/dist/security.d.ts.map +1 -0
  107. package/dist/security.js +1170 -0
  108. package/dist/security.js.map +1 -0
  109. package/dist/server.d.ts +21 -0
  110. package/dist/server.d.ts.map +1 -0
  111. package/dist/{server/node.js → server.js} +16 -2
  112. package/dist/server.js.map +1 -0
  113. package/dist/tiers.d.ts +1002 -0
  114. package/dist/tiers.d.ts.map +1 -0
  115. package/dist/tiers.js +2165 -0
  116. package/dist/tiers.js.map +1 -0
  117. package/dist/virtual.d.ts +641 -0
  118. package/dist/virtual.d.ts.map +1 -0
  119. package/dist/virtual.js +1285 -0
  120. package/dist/virtual.js.map +1 -0
  121. package/dist/virtualcpu.d.ts +316 -0
  122. package/dist/virtualcpu.d.ts.map +1 -0
  123. package/dist/virtualcpu.js +1180 -0
  124. package/dist/virtualcpu.js.map +1 -0
  125. package/dist/virtualgpu.d.ts +345 -0
  126. package/dist/virtualgpu.d.ts.map +1 -0
  127. package/dist/virtualgpu.js +1000 -0
  128. package/dist/virtualgpu.js.map +1 -0
  129. package/dist/virtualization.d.ts +607 -0
  130. package/dist/virtualization.d.ts.map +1 -0
  131. package/dist/virtualization.js +1187 -0
  132. package/dist/virtualization.js.map +1 -0
  133. package/dist/virtualmemory.d.ts +818 -0
  134. package/dist/virtualmemory.d.ts.map +1 -0
  135. package/dist/virtualmemory.js +1796 -0
  136. package/dist/virtualmemory.js.map +1 -0
  137. package/dist/webscrape.d.ts +720 -0
  138. package/dist/webscrape.d.ts.map +1 -0
  139. package/dist/webscrape.js +2697 -0
  140. package/dist/webscrape.js.map +1 -0
  141. package/docker.config +769 -0
  142. package/docs/CONVERSA.txt +1523 -0
  143. package/docs/alternatives.md +499 -0
  144. package/docs/architecture-1.8.19.md +76 -0
  145. package/docs/architecture-1.8.19.mmd +33 -0
  146. package/docs/architecture-1.8.19.png +0 -0
  147. package/docs/architecture.md +355 -0
  148. package/docs/brancharchive-2026-08-18.md +18 -0
  149. package/docs/browser.md +7 -0
  150. package/docs/consolidation.md +70 -0
  151. package/docs/e2ugh-engine.md +528 -0
  152. package/{dist/examples/localjob.js → docs/example-localjob.ts} +3 -3
  153. package/{dist/examples/publicapi.js → docs/example-publicapi.ts} +2 -2
  154. package/docs/hardware.md +342 -0
  155. package/docs/optimization.md +126 -0
  156. package/docs/performance.md +499 -0
  157. package/docs/planning.1.8.18.md +94 -0
  158. package/docs/planning.1.8.19.md +49 -0
  159. package/docs/releasenotes-1.8.19.md +35 -0
  160. package/docs/research-1.8.19-virtual-browser.md +27 -0
  161. package/docs/security.md +454 -0
  162. package/docs/todo-1.8.18.md +12 -0
  163. package/docs/todo-1.8.19.md +241 -0
  164. package/docs/viability.md +777 -0
  165. package/docs/virtualization.md +335 -0
  166. package/docs/web-duplicatecleanup.md +9 -0
  167. package/docs/web-ideas.md +106 -0
  168. package/docs/workflowimprovements-2026-08-19.md +70 -0
  169. package/gpumonitor.cpp +1543 -0
  170. package/gpus.json +2408 -0
  171. package/index.ts +1478 -0
  172. package/media.ts +1337 -0
  173. package/mttg.config +1549 -0
  174. package/orchestrator.ts +5462 -0
  175. package/package.json +304 -56
  176. package/passage.config +1331 -0
  177. package/performance.ts +1049 -0
  178. package/processors.json +2217 -0
  179. package/qemu.config +1062 -0
  180. package/qemubridge.py +1340 -0
  181. package/quantum.ts +2393 -0
  182. package/render.ts +1325 -0
  183. package/scheduler.ts +1600 -0
  184. package/security.ts +1449 -0
  185. package/tiers.ts +2871 -0
  186. package/tsconfig.json +29 -0
  187. package/virtualcpu.ts +1273 -0
  188. package/virtualgpu.ts +1181 -0
  189. package/virtualhardware.c +1011 -0
  190. package/virtualhardware.json +739 -0
  191. package/virtualization.ts +1628 -0
  192. package/virtualizationcore.cpp +4635 -0
  193. package/virtualmemory.ts +2303 -0
  194. package/vm.config.json +1910 -0
  195. package/{extension → web/extension}/manifest.json +1 -1
  196. package/web/readme.md +382 -0
  197. package/web/tsconfig.json +25 -0
  198. package/dist/adapters/forge.d.ts +0 -17
  199. package/dist/adapters/forge.d.ts.map +0 -1
  200. package/dist/adapters/forge.js +0 -19
  201. package/dist/adapters/forge.js.map +0 -1
  202. package/dist/adapters/forgejo.d.ts +0 -49
  203. package/dist/adapters/forgejo.d.ts.map +0 -1
  204. package/dist/adapters/forgejo.js +0 -8
  205. package/dist/adapters/forgejo.js.map +0 -1
  206. package/dist/adapters/github.d.ts +0 -12
  207. package/dist/adapters/github.d.ts.map +0 -1
  208. package/dist/adapters/github.js +0 -20
  209. package/dist/adapters/github.js.map +0 -1
  210. package/dist/adapters/gitlab.d.ts +0 -17
  211. package/dist/adapters/gitlab.d.ts.map +0 -1
  212. package/dist/adapters/gitlab.js +0 -10
  213. package/dist/adapters/gitlab.js.map +0 -1
  214. package/dist/adapters/huggingface.d.ts +0 -17
  215. package/dist/adapters/huggingface.d.ts.map +0 -1
  216. package/dist/adapters/huggingface.js +0 -6
  217. package/dist/adapters/huggingface.js.map +0 -1
  218. package/dist/adapters/socket.d.ts +0 -11
  219. package/dist/adapters/socket.d.ts.map +0 -1
  220. package/dist/adapters/socket.js +0 -17
  221. package/dist/adapters/socket.js.map +0 -1
  222. package/dist/adapters/transport.d.ts +0 -7
  223. package/dist/adapters/transport.d.ts.map +0 -1
  224. package/dist/adapters/transport.js +0 -36
  225. package/dist/adapters/transport.js.map +0 -1
  226. package/dist/ai/chunk.d.ts +0 -2
  227. package/dist/ai/chunk.d.ts.map +0 -1
  228. package/dist/ai/chunk.js +0 -36
  229. package/dist/ai/chunk.js.map +0 -1
  230. package/dist/ai/llmstxt.d.ts +0 -6
  231. package/dist/ai/llmstxt.d.ts.map +0 -1
  232. package/dist/ai/llmstxt.js +0 -12
  233. package/dist/ai/llmstxt.js.map +0 -1
  234. package/dist/ai/provenance.d.ts +0 -22
  235. package/dist/ai/provenance.d.ts.map +0 -1
  236. package/dist/ai/provenance.js +0 -25
  237. package/dist/ai/provenance.js.map +0 -1
  238. package/dist/ai/rag.d.ts +0 -26
  239. package/dist/ai/rag.d.ts.map +0 -1
  240. package/dist/ai/rag.js +0 -22
  241. package/dist/ai/rag.js.map +0 -1
  242. package/dist/ai/tokens.d.ts +0 -15
  243. package/dist/ai/tokens.d.ts.map +0 -1
  244. package/dist/ai/tokens.js +0 -9
  245. package/dist/ai/tokens.js.map +0 -1
  246. package/dist/api/auth.d.ts +0 -16
  247. package/dist/api/auth.d.ts.map +0 -1
  248. package/dist/api/auth.js +0 -19
  249. package/dist/api/auth.js.map +0 -1
  250. package/dist/api/contracts.d.ts +0 -28
  251. package/dist/api/contracts.d.ts.map +0 -1
  252. package/dist/api/contracts.js +0 -14
  253. package/dist/api/contracts.js.map +0 -1
  254. package/dist/api/control.d.ts +0 -10
  255. package/dist/api/control.d.ts.map +0 -1
  256. package/dist/api/control.js +0 -35
  257. package/dist/api/control.js.map +0 -1
  258. package/dist/api/http.d.ts +0 -7
  259. package/dist/api/http.d.ts.map +0 -1
  260. package/dist/api/http.js +0 -12
  261. package/dist/api/http.js.map +0 -1
  262. package/dist/api/rate.d.ts +0 -28
  263. package/dist/api/rate.d.ts.map +0 -1
  264. package/dist/api/rate.js +0 -36
  265. package/dist/api/rate.js.map +0 -1
  266. package/dist/api/security.d.ts +0 -12
  267. package/dist/api/security.d.ts.map +0 -1
  268. package/dist/api/security.js +0 -56
  269. package/dist/api/security.js.map +0 -1
  270. package/dist/api/service.d.ts +0 -5
  271. package/dist/api/service.d.ts.map +0 -1
  272. package/dist/api/service.js +0 -70
  273. package/dist/api/service.js.map +0 -1
  274. package/dist/apps/registry.d.ts +0 -33
  275. package/dist/apps/registry.d.ts.map +0 -1
  276. package/dist/apps/registry.js +0 -24
  277. package/dist/apps/registry.js.map +0 -1
  278. package/dist/binary/archive.d.ts +0 -27
  279. package/dist/binary/archive.d.ts.map +0 -1
  280. package/dist/binary/archive.js +0 -46
  281. package/dist/binary/archive.js.map +0 -1
  282. package/dist/binary/build.d.ts +0 -29
  283. package/dist/binary/build.d.ts.map +0 -1
  284. package/dist/binary/build.js +0 -17
  285. package/dist/binary/build.js.map +0 -1
  286. package/dist/binary/transform.d.ts +0 -70
  287. package/dist/binary/transform.d.ts.map +0 -1
  288. package/dist/binary/transform.js +0 -105
  289. package/dist/binary/transform.js.map +0 -1
  290. package/dist/bot/adapter.d.ts +0 -5
  291. package/dist/bot/adapter.d.ts.map +0 -1
  292. package/dist/bot/adapter.js +0 -11
  293. package/dist/bot/adapter.js.map +0 -1
  294. package/dist/bot/bot.d.ts +0 -28
  295. package/dist/bot/bot.d.ts.map +0 -1
  296. package/dist/bot/bot.js +0 -52
  297. package/dist/bot/bot.js.map +0 -1
  298. package/dist/bot/commands.d.ts +0 -8
  299. package/dist/bot/commands.d.ts.map +0 -1
  300. package/dist/bot/commands.js +0 -19
  301. package/dist/bot/commands.js.map +0 -1
  302. package/dist/bot/permissions.d.ts +0 -13
  303. package/dist/bot/permissions.d.ts.map +0 -1
  304. package/dist/bot/permissions.js +0 -16
  305. package/dist/bot/permissions.js.map +0 -1
  306. package/dist/browser/actions.d.ts +0 -33
  307. package/dist/browser/actions.d.ts.map +0 -1
  308. package/dist/browser/actions.js +0 -44
  309. package/dist/browser/actions.js.map +0 -1
  310. package/dist/browser/agent.d.ts +0 -21
  311. package/dist/browser/agent.d.ts.map +0 -1
  312. package/dist/browser/agent.js +0 -13
  313. package/dist/browser/agent.js.map +0 -1
  314. package/dist/browser/context.d.ts +0 -43
  315. package/dist/browser/context.d.ts.map +0 -1
  316. package/dist/browser/context.js +0 -54
  317. package/dist/browser/context.js.map +0 -1
  318. package/dist/browser/fingerprint.d.ts +0 -4
  319. package/dist/browser/fingerprint.d.ts.map +0 -1
  320. package/dist/browser/fingerprint.js +0 -12
  321. package/dist/browser/fingerprint.js.map +0 -1
  322. package/dist/browser/index.d.ts +0 -11
  323. package/dist/browser/index.d.ts.map +0 -1
  324. package/dist/browser/index.js +0 -11
  325. package/dist/browser/index.js.map +0 -1
  326. package/dist/browser/playwright.d.ts +0 -11
  327. package/dist/browser/playwright.d.ts.map +0 -1
  328. package/dist/browser/playwright.js +0 -24
  329. package/dist/browser/playwright.js.map +0 -1
  330. package/dist/browser/recorder.d.ts +0 -21
  331. package/dist/browser/recorder.d.ts.map +0 -1
  332. package/dist/browser/recorder.js +0 -58
  333. package/dist/browser/recorder.js.map +0 -1
  334. package/dist/browser/session.d.ts +0 -14
  335. package/dist/browser/session.d.ts.map +0 -1
  336. package/dist/browser/session.js +0 -21
  337. package/dist/browser/session.js.map +0 -1
  338. package/dist/browser/snapshot.d.ts +0 -69
  339. package/dist/browser/snapshot.d.ts.map +0 -1
  340. package/dist/browser/snapshot.js +0 -133
  341. package/dist/browser/snapshot.js.map +0 -1
  342. package/dist/captcha/contract.d.ts +0 -35
  343. package/dist/captcha/contract.d.ts.map +0 -1
  344. package/dist/captcha/contract.js +0 -17
  345. package/dist/captcha/contract.js.map +0 -1
  346. package/dist/captcha/evidence.d.ts +0 -10
  347. package/dist/captcha/evidence.d.ts.map +0 -1
  348. package/dist/captcha/evidence.js +0 -9
  349. package/dist/captcha/evidence.js.map +0 -1
  350. package/dist/captcha/guard.d.ts +0 -23
  351. package/dist/captcha/guard.d.ts.map +0 -1
  352. package/dist/captcha/guard.js +0 -12
  353. package/dist/captcha/guard.js.map +0 -1
  354. package/dist/cli/main.d.ts +0 -4
  355. package/dist/cli/main.d.ts.map +0 -1
  356. package/dist/cli/main.js +0 -46
  357. package/dist/cli/main.js.map +0 -1
  358. package/dist/core/errors.d.ts +0 -84
  359. package/dist/core/errors.d.ts.map +0 -1
  360. package/dist/core/errors.js +0 -54
  361. package/dist/core/errors.js.map +0 -1
  362. package/dist/core/events.d.ts +0 -9
  363. package/dist/core/events.d.ts.map +0 -1
  364. package/dist/core/events.js +0 -21
  365. package/dist/core/events.js.map +0 -1
  366. package/dist/core/hash.d.ts +0 -10
  367. package/dist/core/hash.d.ts.map +0 -1
  368. package/dist/core/hash.js +0 -82
  369. package/dist/core/hash.js.map +0 -1
  370. package/dist/core/ids.d.ts +0 -10
  371. package/dist/core/ids.d.ts.map +0 -1
  372. package/dist/core/ids.js +0 -15
  373. package/dist/core/ids.js.map +0 -1
  374. package/dist/delivery/manifest.d.ts +0 -35
  375. package/dist/delivery/manifest.d.ts.map +0 -1
  376. package/dist/delivery/manifest.js +0 -68
  377. package/dist/delivery/manifest.js.map +0 -1
  378. package/dist/deploy/index.d.ts +0 -6
  379. package/dist/deploy/index.d.ts.map +0 -1
  380. package/dist/deploy/index.js +0 -6
  381. package/dist/deploy/index.js.map +0 -1
  382. package/dist/dispatch/resumable.d.ts +0 -102
  383. package/dist/dispatch/resumable.d.ts.map +0 -1
  384. package/dist/dispatch/resumable.js +0 -64
  385. package/dist/dispatch/resumable.js.map +0 -1
  386. package/dist/dispatch/workflow.d.ts +0 -6
  387. package/dist/dispatch/workflow.d.ts.map +0 -1
  388. package/dist/dispatch/workflow.js +0 -37
  389. package/dist/dispatch/workflow.js.map +0 -1
  390. package/dist/domain/artifacts.d.ts +0 -12
  391. package/dist/domain/artifacts.d.ts.map +0 -1
  392. package/dist/domain/artifacts.js +0 -14
  393. package/dist/domain/artifacts.js.map +0 -1
  394. package/dist/domain/jobs.d.ts +0 -12
  395. package/dist/domain/jobs.d.ts.map +0 -1
  396. package/dist/domain/jobs.js +0 -20
  397. package/dist/domain/jobs.js.map +0 -1
  398. package/dist/domain/providers.d.ts +0 -10
  399. package/dist/domain/providers.d.ts.map +0 -1
  400. package/dist/domain/providers.js +0 -8
  401. package/dist/domain/providers.js.map +0 -1
  402. package/dist/domain/runtime.d.ts +0 -14
  403. package/dist/domain/runtime.d.ts.map +0 -1
  404. package/dist/domain/runtime.js +0 -10
  405. package/dist/domain/runtime.js.map +0 -1
  406. package/dist/domain/sessions.d.ts +0 -12
  407. package/dist/domain/sessions.d.ts.map +0 -1
  408. package/dist/domain/sessions.js +0 -57
  409. package/dist/domain/sessions.js.map +0 -1
  410. package/dist/examples/localjob.d.ts +0 -2
  411. package/dist/examples/localjob.d.ts.map +0 -1
  412. package/dist/examples/localjob.js.map +0 -1
  413. package/dist/examples/publicapi.d.ts +0 -2
  414. package/dist/examples/publicapi.d.ts.map +0 -1
  415. package/dist/examples/publicapi.js.map +0 -1
  416. package/dist/extension/build.d.ts +0 -9
  417. package/dist/extension/build.d.ts.map +0 -1
  418. package/dist/extension/build.js +0 -85
  419. package/dist/extension/build.js.map +0 -1
  420. package/dist/extension/content.d.ts +0 -6
  421. package/dist/extension/content.d.ts.map +0 -1
  422. package/dist/extension/content.js +0 -135
  423. package/dist/extension/content.js.map +0 -1
  424. package/dist/extension/index.d.ts +0 -7
  425. package/dist/extension/index.d.ts.map +0 -1
  426. package/dist/extension/index.js +0 -7
  427. package/dist/extension/index.js.map +0 -1
  428. package/dist/extension/pagebridge.d.ts +0 -6
  429. package/dist/extension/pagebridge.d.ts.map +0 -1
  430. package/dist/extension/pagebridge.js +0 -42
  431. package/dist/extension/pagebridge.js.map +0 -1
  432. package/dist/extension/permissions.d.ts +0 -26
  433. package/dist/extension/permissions.d.ts.map +0 -1
  434. package/dist/extension/permissions.js +0 -28
  435. package/dist/extension/permissions.js.map +0 -1
  436. package/dist/extension/popup.d.ts +0 -5
  437. package/dist/extension/popup.d.ts.map +0 -1
  438. package/dist/extension/popup.js +0 -26
  439. package/dist/extension/popup.js.map +0 -1
  440. package/dist/extension/protocol.d.ts +0 -58
  441. package/dist/extension/protocol.d.ts.map +0 -1
  442. package/dist/extension/protocol.js +0 -101
  443. package/dist/extension/protocol.js.map +0 -1
  444. package/dist/extension/serviceworker.d.ts +0 -25
  445. package/dist/extension/serviceworker.d.ts.map +0 -1
  446. package/dist/extension/serviceworker.js +0 -102
  447. package/dist/extension/serviceworker.js.map +0 -1
  448. package/dist/extension/worker.d.ts +0 -28
  449. package/dist/extension/worker.d.ts.map +0 -1
  450. package/dist/extension/worker.js +0 -22
  451. package/dist/extension/worker.js.map +0 -1
  452. package/dist/format/check.d.ts +0 -8
  453. package/dist/format/check.d.ts.map +0 -1
  454. package/dist/format/check.js +0 -38
  455. package/dist/format/check.js.map +0 -1
  456. package/dist/isolation/contracts.d.ts.map +0 -1
  457. package/dist/isolation/contracts.js.map +0 -1
  458. package/dist/library/public.d.ts.map +0 -1
  459. package/dist/library/public.js.map +0 -1
  460. package/dist/mcp/browser.d.ts +0 -9
  461. package/dist/mcp/browser.d.ts.map +0 -1
  462. package/dist/mcp/browser.js +0 -13
  463. package/dist/mcp/browser.js.map +0 -1
  464. package/dist/mcp/server.d.ts +0 -35
  465. package/dist/mcp/server.d.ts.map +0 -1
  466. package/dist/mcp/server.js +0 -40
  467. package/dist/mcp/server.js.map +0 -1
  468. package/dist/mcp/transport.d.ts +0 -7
  469. package/dist/mcp/transport.d.ts.map +0 -1
  470. package/dist/mcp/transport.js +0 -17
  471. package/dist/mcp/transport.js.map +0 -1
  472. package/dist/memory/bridge.d.ts +0 -14
  473. package/dist/memory/bridge.d.ts.map +0 -1
  474. package/dist/memory/bridge.js +0 -16
  475. package/dist/memory/bridge.js.map +0 -1
  476. package/dist/memory/engine.d.ts +0 -38
  477. package/dist/memory/engine.d.ts.map +0 -1
  478. package/dist/memory/engine.js +0 -109
  479. package/dist/memory/engine.js.map +0 -1
  480. package/dist/memory/modes.d.ts +0 -43
  481. package/dist/memory/modes.d.ts.map +0 -1
  482. package/dist/memory/modes.js +0 -66
  483. package/dist/memory/modes.js.map +0 -1
  484. package/dist/memory/objects.d.ts +0 -21
  485. package/dist/memory/objects.d.ts.map +0 -1
  486. package/dist/memory/objects.js +0 -20
  487. package/dist/memory/objects.js.map +0 -1
  488. package/dist/memory/planner.d.ts +0 -66
  489. package/dist/memory/planner.d.ts.map +0 -1
  490. package/dist/memory/planner.js +0 -108
  491. package/dist/memory/planner.js.map +0 -1
  492. package/dist/memory/targets.d.ts +0 -78
  493. package/dist/memory/targets.d.ts.map +0 -1
  494. package/dist/memory/targets.js +0 -29
  495. package/dist/memory/targets.js.map +0 -1
  496. package/dist/memory/transforms.d.ts +0 -19
  497. package/dist/memory/transforms.d.ts.map +0 -1
  498. package/dist/memory/transforms.js +0 -14
  499. package/dist/memory/transforms.js.map +0 -1
  500. package/dist/modes/matrix.d.ts +0 -23
  501. package/dist/modes/matrix.d.ts.map +0 -1
  502. package/dist/modes/matrix.js +0 -18
  503. package/dist/modes/matrix.js.map +0 -1
  504. package/dist/modes/modes.d.ts +0 -33
  505. package/dist/modes/modes.d.ts.map +0 -1
  506. package/dist/modes/modes.js +0 -15
  507. package/dist/modes/modes.js.map +0 -1
  508. package/dist/modes/resolve.d.ts +0 -96
  509. package/dist/modes/resolve.d.ts.map +0 -1
  510. package/dist/modes/resolve.js +0 -48
  511. package/dist/modes/resolve.js.map +0 -1
  512. package/dist/observability/metrics.d.ts +0 -14
  513. package/dist/observability/metrics.d.ts.map +0 -1
  514. package/dist/observability/metrics.js +0 -18
  515. package/dist/observability/metrics.js.map +0 -1
  516. package/dist/packager/manifest.d.ts +0 -66
  517. package/dist/packager/manifest.d.ts.map +0 -1
  518. package/dist/packager/manifest.js +0 -94
  519. package/dist/packager/manifest.js.map +0 -1
  520. package/dist/packager/publish.d.ts +0 -51
  521. package/dist/packager/publish.d.ts.map +0 -1
  522. package/dist/packager/publish.js +0 -18
  523. package/dist/packager/publish.js.map +0 -1
  524. package/dist/packager/targetcli.d.ts +0 -7
  525. package/dist/packager/targetcli.d.ts.map +0 -1
  526. package/dist/packager/targetcli.js.map +0 -1
  527. package/dist/persistence/adapter.d.ts +0 -5
  528. package/dist/persistence/adapter.d.ts.map +0 -1
  529. package/dist/persistence/adapter.js +0 -11
  530. package/dist/persistence/adapter.js.map +0 -1
  531. package/dist/persistence/drizzle.d.ts +0 -2
  532. package/dist/persistence/drizzle.d.ts.map +0 -1
  533. package/dist/persistence/drizzle.js +0 -12
  534. package/dist/persistence/drizzle.js.map +0 -1
  535. package/dist/persistence/memory.d.ts +0 -2
  536. package/dist/persistence/memory.d.ts.map +0 -1
  537. package/dist/persistence/memory.js +0 -27
  538. package/dist/persistence/memory.js.map +0 -1
  539. package/dist/persistence/migrations.d.ts +0 -19
  540. package/dist/persistence/migrations.d.ts.map +0 -1
  541. package/dist/persistence/migrations.js +0 -13
  542. package/dist/persistence/migrations.js.map +0 -1
  543. package/dist/persistence/prisma.d.ts +0 -2
  544. package/dist/persistence/prisma.d.ts.map +0 -1
  545. package/dist/persistence/prisma.js +0 -25
  546. package/dist/persistence/prisma.js.map +0 -1
  547. package/dist/persistence/schema.d.ts +0 -63
  548. package/dist/persistence/schema.d.ts.map +0 -1
  549. package/dist/persistence/schema.js +0 -28
  550. package/dist/persistence/schema.js.map +0 -1
  551. package/dist/persistence/sql.d.ts +0 -3
  552. package/dist/persistence/sql.d.ts.map +0 -1
  553. package/dist/persistence/sql.js +0 -37
  554. package/dist/persistence/sql.js.map +0 -1
  555. package/dist/protocol/blocks.d.ts +0 -10
  556. package/dist/protocol/blocks.d.ts.map +0 -1
  557. package/dist/protocol/blocks.js +0 -26
  558. package/dist/protocol/blocks.js.map +0 -1
  559. package/dist/protocol/json.d.ts +0 -6
  560. package/dist/protocol/json.d.ts.map +0 -1
  561. package/dist/protocol/json.js +0 -6
  562. package/dist/protocol/json.js.map +0 -1
  563. package/dist/protocol/ndjson.d.ts +0 -3
  564. package/dist/protocol/ndjson.d.ts.map +0 -1
  565. package/dist/protocol/ndjson.js +0 -20
  566. package/dist/protocol/ndjson.js.map +0 -1
  567. package/dist/protocol/sse.d.ts +0 -7
  568. package/dist/protocol/sse.d.ts.map +0 -1
  569. package/dist/protocol/sse.js +0 -25
  570. package/dist/protocol/sse.js.map +0 -1
  571. package/dist/proxy/pool.d.ts +0 -9
  572. package/dist/proxy/pool.d.ts.map +0 -1
  573. package/dist/proxy/pool.js +0 -27
  574. package/dist/proxy/pool.js.map +0 -1
  575. package/dist/queue/idempotency.d.ts +0 -10
  576. package/dist/queue/idempotency.d.ts.map +0 -1
  577. package/dist/queue/idempotency.js +0 -13
  578. package/dist/queue/idempotency.js.map +0 -1
  579. package/dist/queue/persistent.d.ts +0 -14
  580. package/dist/queue/persistent.d.ts.map +0 -1
  581. package/dist/queue/persistent.js +0 -66
  582. package/dist/queue/persistent.js.map +0 -1
  583. package/dist/queue/queue.d.ts +0 -7
  584. package/dist/queue/queue.d.ts.map +0 -1
  585. package/dist/queue/queue.js +0 -55
  586. package/dist/queue/queue.js.map +0 -1
  587. package/dist/queue/saga.d.ts +0 -5
  588. package/dist/queue/saga.d.ts.map +0 -1
  589. package/dist/queue/saga.js +0 -20
  590. package/dist/queue/saga.js.map +0 -1
  591. package/dist/release/assets.d.ts +0 -144
  592. package/dist/release/assets.d.ts.map +0 -1
  593. package/dist/release/assets.js +0 -157
  594. package/dist/release/assets.js.map +0 -1
  595. package/dist/release/evidence.d.ts +0 -92
  596. package/dist/release/evidence.d.ts.map +0 -1
  597. package/dist/release/evidence.js +0 -148
  598. package/dist/release/evidence.js.map +0 -1
  599. package/dist/release/verify.d.ts +0 -12
  600. package/dist/release/verify.d.ts.map +0 -1
  601. package/dist/release/verify.js +0 -112
  602. package/dist/release/verify.js.map +0 -1
  603. package/dist/runners/chain.d.ts +0 -125
  604. package/dist/runners/chain.d.ts.map +0 -1
  605. package/dist/runners/chain.js +0 -95
  606. package/dist/runners/chain.js.map +0 -1
  607. package/dist/runners/health.d.ts +0 -36
  608. package/dist/runners/health.d.ts.map +0 -1
  609. package/dist/runners/health.js +0 -26
  610. package/dist/runners/health.js.map +0 -1
  611. package/dist/runners/heartbeat.d.ts +0 -23
  612. package/dist/runners/heartbeat.d.ts.map +0 -1
  613. package/dist/runners/heartbeat.js +0 -29
  614. package/dist/runners/heartbeat.js.map +0 -1
  615. package/dist/runners/inprocess.d.ts +0 -17
  616. package/dist/runners/inprocess.d.ts.map +0 -1
  617. package/dist/runners/inprocess.js +0 -20
  618. package/dist/runners/inprocess.js.map +0 -1
  619. package/dist/runners/scheduler.d.ts +0 -5
  620. package/dist/runners/scheduler.d.ts.map +0 -1
  621. package/dist/runners/scheduler.js +0 -19
  622. package/dist/runners/scheduler.js.map +0 -1
  623. package/dist/runtime/abort.d.ts +0 -8
  624. package/dist/runtime/abort.d.ts.map +0 -1
  625. package/dist/runtime/abort.js +0 -13
  626. package/dist/runtime/abort.js.map +0 -1
  627. package/dist/runtime/compatibility.d.ts +0 -37
  628. package/dist/runtime/compatibility.d.ts.map +0 -1
  629. package/dist/runtime/compatibility.js +0 -10
  630. package/dist/runtime/compatibility.js.map +0 -1
  631. package/dist/runtime/detect.d.ts +0 -13
  632. package/dist/runtime/detect.d.ts.map +0 -1
  633. package/dist/runtime/detect.js +0 -18
  634. package/dist/runtime/detect.js.map +0 -1
  635. package/dist/runtime/engine.d.ts +0 -20
  636. package/dist/runtime/engine.d.ts.map +0 -1
  637. package/dist/runtime/engine.js +0 -61
  638. package/dist/runtime/engine.js.map +0 -1
  639. package/dist/runtime/retry.d.ts +0 -19
  640. package/dist/runtime/retry.d.ts.map +0 -1
  641. package/dist/runtime/retry.js +0 -54
  642. package/dist/runtime/retry.js.map +0 -1
  643. package/dist/runtime/worker.d.ts +0 -10
  644. package/dist/runtime/worker.d.ts.map +0 -1
  645. package/dist/runtime/worker.js +0 -25
  646. package/dist/runtime/worker.js.map +0 -1
  647. package/dist/scrape/cache.d.ts +0 -45
  648. package/dist/scrape/cache.d.ts.map +0 -1
  649. package/dist/scrape/cache.js +0 -45
  650. package/dist/scrape/cache.js.map +0 -1
  651. package/dist/scrape/crawl.d.ts +0 -47
  652. package/dist/scrape/crawl.d.ts.map +0 -1
  653. package/dist/scrape/crawl.js +0 -114
  654. package/dist/scrape/crawl.js.map +0 -1
  655. package/dist/scrape/extract.d.ts +0 -63
  656. package/dist/scrape/extract.d.ts.map +0 -1
  657. package/dist/scrape/extract.js +0 -47
  658. package/dist/scrape/extract.js.map +0 -1
  659. package/dist/scrape/normalize.d.ts +0 -52
  660. package/dist/scrape/normalize.d.ts.map +0 -1
  661. package/dist/scrape/normalize.js +0 -102
  662. package/dist/scrape/normalize.js.map +0 -1
  663. package/dist/scrape/robots.d.ts +0 -37
  664. package/dist/scrape/robots.d.ts.map +0 -1
  665. package/dist/scrape/robots.js +0 -71
  666. package/dist/scrape/robots.js.map +0 -1
  667. package/dist/scrape/schema.d.ts +0 -23
  668. package/dist/scrape/schema.d.ts.map +0 -1
  669. package/dist/scrape/schema.js +0 -92
  670. package/dist/scrape/schema.js.map +0 -1
  671. package/dist/scrape/scraper.d.ts +0 -6
  672. package/dist/scrape/scraper.d.ts.map +0 -1
  673. package/dist/scrape/scraper.js +0 -46
  674. package/dist/scrape/scraper.js.map +0 -1
  675. package/dist/scrape/semantic.d.ts +0 -25
  676. package/dist/scrape/semantic.d.ts.map +0 -1
  677. package/dist/scrape/semantic.js +0 -27
  678. package/dist/scrape/semantic.js.map +0 -1
  679. package/dist/server/node.d.ts +0 -7
  680. package/dist/server/node.d.ts.map +0 -1
  681. package/dist/server/node.js.map +0 -1
  682. package/dist/sessions/file.d.ts +0 -25
  683. package/dist/sessions/file.d.ts.map +0 -1
  684. package/dist/sessions/file.js +0 -13
  685. package/dist/sessions/file.js.map +0 -1
  686. package/dist/sessions/replay.d.ts +0 -9
  687. package/dist/sessions/replay.d.ts.map +0 -1
  688. package/dist/sessions/replay.js +0 -70
  689. package/dist/sessions/replay.js.map +0 -1
  690. package/dist/sessions/store.d.ts +0 -25
  691. package/dist/sessions/store.d.ts.map +0 -1
  692. package/dist/sessions/store.js +0 -13
  693. package/dist/sessions/store.js.map +0 -1
  694. package/dist/storage/adapter.d.ts +0 -5
  695. package/dist/storage/adapter.d.ts.map +0 -1
  696. package/dist/storage/adapter.js +0 -11
  697. package/dist/storage/adapter.js.map +0 -1
  698. package/dist/storage/cache.d.ts +0 -23
  699. package/dist/storage/cache.d.ts.map +0 -1
  700. package/dist/storage/cache.js +0 -79
  701. package/dist/storage/cache.js.map +0 -1
  702. package/dist/storage/checksum.d.ts +0 -3
  703. package/dist/storage/checksum.d.ts.map +0 -1
  704. package/dist/storage/checksum.js +0 -19
  705. package/dist/storage/checksum.js.map +0 -1
  706. package/dist/storage/chunked.d.ts +0 -21
  707. package/dist/storage/chunked.d.ts.map +0 -1
  708. package/dist/storage/chunked.js +0 -67
  709. package/dist/storage/chunked.js.map +0 -1
  710. package/dist/storage/content.d.ts +0 -24
  711. package/dist/storage/content.d.ts.map +0 -1
  712. package/dist/storage/content.js +0 -44
  713. package/dist/storage/content.js.map +0 -1
  714. package/dist/storage/filehosting.d.ts +0 -2
  715. package/dist/storage/filehosting.d.ts.map +0 -1
  716. package/dist/storage/filehosting.js +0 -24
  717. package/dist/storage/filehosting.js.map +0 -1
  718. package/dist/storage/githubcontents.d.ts +0 -2
  719. package/dist/storage/githubcontents.d.ts.map +0 -1
  720. package/dist/storage/githubcontents.js +0 -29
  721. package/dist/storage/githubcontents.js.map +0 -1
  722. package/dist/storage/index.d.ts +0 -12
  723. package/dist/storage/index.d.ts.map +0 -1
  724. package/dist/storage/index.js +0 -12
  725. package/dist/storage/index.js.map +0 -1
  726. package/dist/storage/local.d.ts +0 -2
  727. package/dist/storage/local.d.ts.map +0 -1
  728. package/dist/storage/local.js +0 -72
  729. package/dist/storage/local.js.map +0 -1
  730. package/dist/storage/memory.d.ts +0 -6
  731. package/dist/storage/memory.d.ts.map +0 -1
  732. package/dist/storage/memory.js +0 -36
  733. package/dist/storage/memory.js.map +0 -1
  734. package/dist/storage/pool.d.ts +0 -95
  735. package/dist/storage/pool.d.ts.map +0 -1
  736. package/dist/storage/pool.js +0 -202
  737. package/dist/storage/pool.js.map +0 -1
  738. package/dist/storage/s3compatible.d.ts +0 -3
  739. package/dist/storage/s3compatible.d.ts.map +0 -1
  740. package/dist/storage/s3compatible.js +0 -70
  741. package/dist/storage/s3compatible.js.map +0 -1
  742. package/dist/storage/sync.d.ts +0 -47
  743. package/dist/storage/sync.d.ts.map +0 -1
  744. package/dist/storage/sync.js +0 -75
  745. package/dist/storage/sync.js.map +0 -1
  746. package/dist/surfaces/adapters.d.ts +0 -97
  747. package/dist/surfaces/adapters.d.ts.map +0 -1
  748. package/dist/surfaces/adapters.js +0 -50
  749. package/dist/surfaces/adapters.js.map +0 -1
  750. package/dist/surfaces/controls.d.ts +0 -18
  751. package/dist/surfaces/controls.d.ts.map +0 -1
  752. package/dist/surfaces/controls.js +0 -45
  753. package/dist/surfaces/controls.js.map +0 -1
  754. package/dist/surfaces/manifest.d.ts +0 -68
  755. package/dist/surfaces/manifest.d.ts.map +0 -1
  756. package/dist/surfaces/manifest.js +0 -42
  757. package/dist/surfaces/manifest.js.map +0 -1
  758. package/dist/surfaces/n8n.d.ts +0 -25
  759. package/dist/surfaces/n8n.d.ts.map +0 -1
  760. package/dist/surfaces/n8n.js +0 -31
  761. package/dist/surfaces/n8n.js.map +0 -1
  762. package/dist/surfaces/operations.d.ts +0 -32
  763. package/dist/surfaces/operations.d.ts.map +0 -1
  764. package/dist/surfaces/operations.js +0 -53
  765. package/dist/surfaces/operations.js.map +0 -1
  766. package/dist/surfaces/requirements.d.ts +0 -29
  767. package/dist/surfaces/requirements.d.ts.map +0 -1
  768. package/dist/surfaces/requirements.js +0 -50
  769. package/dist/surfaces/requirements.js.map +0 -1
  770. package/dist/surfaces/targets.d.ts +0 -196
  771. package/dist/surfaces/targets.d.ts.map +0 -1
  772. package/dist/surfaces/targets.js +0 -27
  773. package/dist/surfaces/targets.js.map +0 -1
  774. package/dist/webhook/delivery.d.ts +0 -18
  775. package/dist/webhook/delivery.d.ts.map +0 -1
  776. package/dist/webhook/delivery.js +0 -36
  777. package/dist/webhook/delivery.js.map +0 -1
  778. package/dist/webhook/receiver.d.ts +0 -26
  779. package/dist/webhook/receiver.d.ts.map +0 -1
  780. package/dist/webhook/receiver.js +0 -24
  781. package/dist/webhook/receiver.js.map +0 -1
  782. package/dist/webhook/signature.d.ts +0 -3
  783. package/dist/webhook/signature.d.ts.map +0 -1
  784. package/dist/webhook/signature.js +0 -7
  785. package/dist/webhook/signature.js.map +0 -1
  786. package/dist/workflow/manifest.d.ts +0 -22
  787. package/dist/workflow/manifest.d.ts.map +0 -1
  788. package/dist/workflow/manifest.js +0 -21
  789. package/dist/workflow/manifest.js.map +0 -1
  790. package/dist/workflow/registry.d.ts +0 -7
  791. package/dist/workflow/registry.d.ts.map +0 -1
  792. package/dist/workflow/registry.js +0 -18
  793. package/dist/workflow/registry.js.map +0 -1
  794. package/dist/workflow/templates.d.ts +0 -6
  795. package/dist/workflow/templates.d.ts.map +0 -1
  796. package/dist/workflow/templates.js +0 -18
  797. package/dist/workflow/templates.js.map +0 -1
  798. package/dist/workflow/triggers.d.ts +0 -64
  799. package/dist/workflow/triggers.d.ts.map +0 -1
  800. package/dist/workflow/triggers.js +0 -99
  801. package/dist/workflow/triggers.js.map +0 -1
  802. /package/{extension/README.md → docs/extension.md} +0 -0
@@ -0,0 +1,827 @@
1
+ /**
2
+ * performance.ts - Virtual Hardware Engine v5
3
+ *
4
+ * Seven composable optimization layers plus a measurement harness: percentile
5
+ * metrics (p50/p95/p99), regression detection and profile mode. Every layer
6
+ * emits a concrete patch (environment variables, process arguments, docker
7
+ * flags, planned kernel writes) so the same code drives local runs, CI jobs
8
+ * and documentation.
9
+ *
10
+ * Layer index:
11
+ * 1. cpu - AVX-512 vector width, LP thread saturation, OMP presets
12
+ * 2. gpu - Rusticl OpenCL 3.1 virtual identity, lavapipe Vulkan 1.4, LP_PERF flags
13
+ * 3. memory - unlimited swap, 2g shm, overcommit, KSM, 1G huge pages, tmpfs cache
14
+ * 4. microvm - Firecracker warm pool (3-5ms restores, 150 VMs/s, <5 MiB per VM)
15
+ * 5. tcg - QEMU 11.1 MTTCG, thread=multi, tb-size 1024, EPYC-v5, nitro accel
16
+ * 6. build - buildx gha cache (103s to 25s measured), multi-stage, LLVM -O3
17
+ * 7. network - keepalive, connection pooling, TAP pre-setup
18
+ *
19
+ * Related contexts covered by this file (25):
20
+ * LLVMpipe, Gallivm, AVX-512, MR !17813, LP_MAX_THREADS, MR 31551, OpenMP,
21
+ * Rusticl, OpenCL 3.1, RUSTICL_DEVICE_TYPE, lavapipe, Vulkan 1.4, LP_PERF,
22
+ * Docker memory-swap, ShmSize, vm.overcommit_memory, KSM, huge pages, tmpfs,
23
+ * Firecracker snapshots, QEMU MTTCG, buildx type=gha, LLVM -O3 -flto, undici
24
+ * keepalive, TAP/tun devices.
25
+ *
26
+ * Module rules: no emoji, JSDoc in English, third-person voice, lowercase
27
+ * identifiers, `using`/`satisfies`/`#private` modern TypeScript, node:* imports
28
+ * first, try/catch on every fallible path, no hardcoded localhost endpoints.
29
+ */
30
+ import { randomInt } from 'node:crypto';
31
+ import { EventEmitter } from 'node:events';
32
+ import { performance } from 'node:perf_hooks';
33
+ /** Empty patch helper so layers only declare what they change. */
34
+ function patch(layer, partial) {
35
+ return {
36
+ layer,
37
+ env: partial.env ?? {},
38
+ args: partial.args ?? [],
39
+ dockerArgs: partial.dockerArgs ?? [],
40
+ kernelWrites: partial.kernelWrites ?? [],
41
+ mounts: partial.mounts ?? [],
42
+ notes: partial.notes ?? [],
43
+ };
44
+ }
45
+ /** Picks an ephemeral port for local listeners; never a hardcoded endpoint. */
46
+ export function randomPort() {
47
+ try {
48
+ return randomInt(20000, 60999);
49
+ }
50
+ catch {
51
+ return 34917;
52
+ }
53
+ }
54
+ // ===========================================================================
55
+ // Layer 1 of 7 - CPU vector width and thread saturation
56
+ // ===========================================================================
57
+ /** OMP thread presets the engine validates against (up to the 192c EPYC 9965). */
58
+ export const ompPresets = [1, 2, 4, 8, 16, 32, 64, 96, 128, 192];
59
+ /**
60
+ * Picks the largest OMP preset that does not exceed the available CPUs.
61
+ * Presets exist so benchmark grids compare identical thread counts across
62
+ * hosts (1, 2, 4, 8, 16, 32, 64, 96, 128, 192).
63
+ */
64
+ export function pickOmpThreads(cpus) {
65
+ if (cpus < 1)
66
+ throw new Error('cpus must be at least 1');
67
+ let chosen = ompPresets[0];
68
+ for (const preset of ompPresets) {
69
+ if (preset <= cpus)
70
+ chosen = preset;
71
+ }
72
+ return chosen;
73
+ }
74
+ /**
75
+ * LLVMpipe rasterization threads: `LP_NUM_THREADS=0` selects every core
76
+ * automatically, capped by the compile-time ceiling LP_MAX_THREADS=32 that
77
+ * Mesa carries since MR 31551.
78
+ */
79
+ export function llvmpipeThreads(cpus) {
80
+ const effective = Math.min(Math.max(cpus, 1), 32);
81
+ return { envValue: '0', effective };
82
+ }
83
+ /**
84
+ * Layer 1/7 - CPU.
85
+ * AVX-512 reaches LLVMpipe through Gallivm (MR !17813) with runtime CPU
86
+ * detection; forcing LP_NATIVE_VECTOR_WIDTH=512 keeps the JIT on 512-bit
87
+ * vectors for the whole process lifetime. MESA_NO_ERROR removes per-draw
88
+ * error checks that pure-software rasterization does not need.
89
+ */
90
+ export class CpuLayer {
91
+ id = 'cpu';
92
+ title = 'CPU vector width and thread saturation';
93
+ contexts = [
94
+ 'LLVMpipe',
95
+ 'Gallivm',
96
+ 'AVX-512',
97
+ 'MR !17813',
98
+ 'LP_MAX_THREADS',
99
+ 'MR 31551',
100
+ 'OpenMP',
101
+ 'EPYC 9965',
102
+ ];
103
+ #vectorWidth = 512;
104
+ /** Docs note 128-bit JIT is occasionally faster; this switch supports A/B runs. */
105
+ setVectorWidth(width) {
106
+ this.#vectorWidth = width;
107
+ return this;
108
+ }
109
+ apply(target) {
110
+ const threads = llvmpipeThreads(target.cpus);
111
+ const omp = pickOmpThreads(target.cpus);
112
+ return patch('cpu', {
113
+ env: {
114
+ LP_NATIVE_VECTOR_WIDTH: String(this.#vectorWidth),
115
+ LP_NUM_THREADS: threads.envValue,
116
+ OMP_NUM_THREADS: String(omp),
117
+ MESA_NO_ERROR: '1',
118
+ },
119
+ notes: [
120
+ `LP_NUM_THREADS=0 auto-selects all ${target.cpus} cores, ceiling LP_MAX_THREADS=32 (MR 31551)`,
121
+ `OMP_NUM_THREADS=${omp} from presets ${ompPresets.join('/')}`,
122
+ `LP_NATIVE_VECTOR_WIDTH=${this.#vectorWidth} pins gallivm to ${this.#vectorWidth}-bit vectors (AVX-512 via MR !17813)`,
123
+ ],
124
+ });
125
+ }
126
+ }
127
+ const lpPerfFlags = {
128
+ balanced: [],
129
+ benchmark: ['no_blend', 'no_depth'],
130
+ 'no-depth': ['no_depth'],
131
+ 'no-tex': ['no_tex'],
132
+ };
133
+ /**
134
+ * Layer 2/7 - GPU.
135
+ * Presents the software rasterizer as a real GPU: Rusticl reports
136
+ * CL_DEVICE_TYPE_GPU with OpenCL 3.1 (the Mesa 26.2 level), lavapipe serves
137
+ * Vulkan 1.4, and the Vulkan loader selects the lavapipe ICD through
138
+ * VK_DRIVER_FILES (VK_ICD_FILENAMES is deprecated in 2026 loaders).
139
+ */
140
+ export class GpuLayer {
141
+ id = 'gpu';
142
+ title = 'Rusticl GPU virtual identity and lavapipe Vulkan 1.4';
143
+ contexts = [
144
+ 'Rusticl',
145
+ 'OpenCL 3.1',
146
+ 'RUSTICL_DEVICE_TYPE',
147
+ 'lavapipe',
148
+ 'Vulkan 1.4',
149
+ 'VK_DRIVER_FILES',
150
+ 'LP_PERF',
151
+ 'MESA_VK_WSI_HEADLESS_SWAPCHAIN',
152
+ ];
153
+ #profile = 'balanced';
154
+ #icdPath = '/usr/share/vulkan/icd.d/lvp_icd.x86_64.json';
155
+ setProfile(profile) {
156
+ this.#profile = profile;
157
+ return this;
158
+ }
159
+ setIcdPath(path) {
160
+ this.#icdPath = path;
161
+ return this;
162
+ }
163
+ apply(target) {
164
+ const env = {
165
+ LIBGL_ALWAYS_SOFTWARE: 'true',
166
+ GALLIUM_DRIVER: 'llvmpipe',
167
+ RUSTICL_ENABLE: 'llvmpipe',
168
+ RUSTICL_DEVICE_TYPE: 'gpu',
169
+ RUSTICL_CL_VERSION: '3.1',
170
+ VK_DRIVER_FILES: this.#icdPath,
171
+ MESA_VK_VERSION_OVERRIDE: '1.4',
172
+ };
173
+ if (target.headless) {
174
+ env.MESA_VK_WSI_HEADLESS_SWAPCHAIN = '1';
175
+ }
176
+ const flags = lpPerfFlags[this.#profile];
177
+ if (flags.length > 0) {
178
+ env.LP_PERF = flags.join(',');
179
+ }
180
+ return patch('gpu', {
181
+ env,
182
+ notes: [
183
+ 'RUSTICL_DEVICE_TYPE=gpu makes clGetDeviceInfo report CL_DEVICE_TYPE_GPU on llvmpipe',
184
+ 'Rusticl is the only Mesa OpenCL frontend since 25.2 (Clover deleted); OpenCL 3.1 ships with Mesa 26.2',
185
+ `lavapipe ICD selected via VK_DRIVER_FILES=${this.#icdPath}`,
186
+ flags.length > 0
187
+ ? `LP_PERF=${flags.join(',')} skips raster stages for benchmark runs only`
188
+ : 'LP_PERF left unset for correctness runs',
189
+ ],
190
+ });
191
+ }
192
+ }
193
+ // ===========================================================================
194
+ // Layer 3 of 7 - memory: swap, shm, overcommit, KSM, huge pages, tmpfs
195
+ // ===========================================================================
196
+ /**
197
+ * Plans the vm.overcommit_memory=2 (never overcommit) setting together with
198
+ * the commit floor the engine reserves for guest memory backends.
199
+ */
200
+ export function planOvercommit(reserveGb) {
201
+ return {
202
+ path: '/proc/sys/vm/overcommit_memory',
203
+ content: '2',
204
+ rationale: `strict accounting with ${reserveGb}GB reserved prevents OOM kills inside sandboxes while QEMU maps guest RAM`,
205
+ };
206
+ }
207
+ /** Plans Kernel Samepage Merging: deduplicates identical guest pages (N:N sandboxes share one kernel image). */
208
+ export function planKsm(pagesToScan = 1000, sleepMs = 20) {
209
+ return {
210
+ writes: [
211
+ { path: '/sys/kernel/mm/ksm/run', content: '1' },
212
+ { path: '/sys/kernel/mm/ksm/pages_to_scan', content: String(pagesToScan) },
213
+ { path: '/sys/kernel/mm/ksm/sleep_millisecs', content: String(sleepMs) },
214
+ ],
215
+ expectedSaving: 'dedup of shared pages across sandboxes; gains grow with the number of identical guests',
216
+ };
217
+ }
218
+ /** Plans 1 GiB huge page reservations backing QEMU guest memory. */
219
+ export function planHugePages1g(guestGb) {
220
+ const pages = Math.max(1, Math.ceil(guestGb));
221
+ return {
222
+ writes: [{ path: '/proc/sys/vm/nr_hugepages', content: String(pages) }],
223
+ bootArgs: ['default_hugepagesz=1G', 'hugepagesz=1G', `hugepages=${pages}`],
224
+ };
225
+ }
226
+ /** Plans the 20G tmpfs that backs the Mesa shader cache in hot loops. */
227
+ export function planShaderTmpfs(sizeGb = 20) {
228
+ return {
229
+ mounts: [`tmpfs /var/cache/mesa-shader-cache tmpfs size=${sizeGb}G,mode=1777 0 0`],
230
+ env: {
231
+ MESA_SHADER_CACHE_DIR: '/var/cache/mesa-shader-cache',
232
+ MESA_SHADER_CACHE_MAX_SIZE: `${sizeGb * 1024 * 1024 * 1024}`,
233
+ },
234
+ };
235
+ }
236
+ /**
237
+ * Layer 3/7 - memory.
238
+ * Docker runs with unlimited swap (--memory-swap -1) and 2g of shared memory
239
+ * so PyTorch DataLoaders never bus-error; the kernel side enables strict
240
+ * overcommit accounting, KSM dedup and 1 GiB huge pages, while a 20G tmpfs
241
+ * keeps the shader cache entirely in RAM (tmpfs is up to 4x faster than
242
+ * overlayfs on small files).
243
+ */
244
+ export class MemoryLayer {
245
+ id = 'memory';
246
+ title = 'unlimited swap, 2g shm, overcommit, KSM, huge pages, tmpfs cache';
247
+ contexts = [
248
+ '--memory-swap',
249
+ '--shm-size',
250
+ 'overcommit_memory',
251
+ 'KSM',
252
+ 'nr_hugepages',
253
+ 'tmpfs',
254
+ 'MESA_SHADER_CACHE_DIR',
255
+ 'DataLoader bus error',
256
+ ];
257
+ #shmSize = '2g';
258
+ #shaderTmpfsGb = 20;
259
+ setShmSize(size) {
260
+ this.#shmSize = size;
261
+ return this;
262
+ }
263
+ apply(target) {
264
+ const ksm = planKsm();
265
+ const huge = planHugePages1g(Math.min(target.memoryGb, 64));
266
+ const shaderCache = planShaderTmpfs(this.#shaderTmpfsGb);
267
+ return patch('memory', {
268
+ env: shaderCache.env,
269
+ dockerArgs: ['--memory-swap', '-1', '--shm-size', this.#shmSize],
270
+ kernelWrites: [planOvercommit(target.memoryGb), ...ksm.writes, ...huge.writes].map((w) => ({
271
+ path: w.path,
272
+ content: w.content,
273
+ })),
274
+ mounts: shaderCache.mounts,
275
+ notes: [
276
+ '--memory-swap -1 removes the swap ceiling; cgroups v2 memory.max still bounds the sandbox',
277
+ `--shm-size ${this.#shmSize} avoids the PyTorch DataLoader shared-memory bus error`,
278
+ 'vm.overcommit_memory=2: strict accounting, no surprise OOM inside guests',
279
+ 'KSM run=1 dedups identical guest pages (per-sandbox <5 MiB overhead makes dedup profitable)',
280
+ `${huge.bootArgs.join(' ')} backs guest RAM with 1GiB pages`,
281
+ `tmpfs ${this.#shaderTmpfsGb}G shader cache: up to 4x faster than disk-backed caches`,
282
+ ],
283
+ });
284
+ }
285
+ }
286
+ /**
287
+ * Layer 4/7 - microVM.
288
+ * Keeps Firecracker microVMs pre-restored from snapshots: acquiring a sandbox
289
+ * costs one restore (3-5ms with File backend, ~1ms more with Uffd), each VM
290
+ * stays under 5 MiB of overhead, and a host sustains roughly 150 microVM
291
+ * creations per second. The pool refills in the background so bursts never
292
+ * hit the cold path.
293
+ */
294
+ export class FirecrackerWarmPool extends EventEmitter {
295
+ id = 'microvm';
296
+ title = 'Firecracker warm pool (3-5ms restores, 150 VMs/s, <5 MiB per VM)';
297
+ contexts = [
298
+ 'Firecracker v1.16.1',
299
+ 'File snapshot backend',
300
+ 'Uffd backend',
301
+ 'userfaultfd',
302
+ 'MAP_PRIVATE',
303
+ 'cold boot 125ms',
304
+ 'warm restore 3-5ms',
305
+ '150 microVMs/s',
306
+ ];
307
+ #warm = [];
308
+ #vmCounter = 0;
309
+ targetSize;
310
+ #restoreMs;
311
+ #capacityPerSec = 150;
312
+ #memoryPerVmMib = 5;
313
+ constructor(targetSize = 8, restoreMs = 4) {
314
+ super();
315
+ this.targetSize = targetSize;
316
+ this.#restoreMs = restoreMs;
317
+ }
318
+ get warmCount() {
319
+ return this.#warm.length;
320
+ }
321
+ get restoreMs() {
322
+ return this.#restoreMs;
323
+ }
324
+ /** Creates a pre-restored VM record; ports come from the ephemeral range. */
325
+ #spawn() {
326
+ this.#vmCounter += 1;
327
+ return { vmId: `fc-${this.#vmCounter}`, apiPort: randomPort(), warmedAtMs: Date.now() };
328
+ }
329
+ /** Fills the pool up to the target size; returns the number added. */
330
+ refill() {
331
+ let added = 0;
332
+ while (this.#warm.length < this.targetSize) {
333
+ this.#warm.push(this.#spawn());
334
+ added += 1;
335
+ }
336
+ if (added > 0)
337
+ this.emit('refilled', { added, warm: this.#warm.length });
338
+ return added;
339
+ }
340
+ /**
341
+ * Acquires a warm VM or synthesizes a cold one when the pool is empty.
342
+ * Cold boots cost ~125ms; warm restores cost the modeled restore time.
343
+ */
344
+ acquire() {
345
+ const warm = this.#warm.shift();
346
+ if (warm !== undefined) {
347
+ this.emit('acquired', { vmId: warm.vmId, cold: false });
348
+ setImmediate(() => this.refill());
349
+ return { vmId: warm.vmId, apiPort: warm.apiPort, bootMs: this.#restoreMs };
350
+ }
351
+ const cold = this.#spawn();
352
+ this.emit('acquired', { vmId: cold.vmId, cold: true });
353
+ return { vmId: cold.vmId, apiPort: cold.apiPort, bootMs: 125 };
354
+ }
355
+ /** Sustained creation capacity of one host and the per-VM overhead. */
356
+ capacity() {
357
+ return { vmsPerSec: this.#capacityPerSec, memoryPerVmMib: this.#memoryPerVmMib };
358
+ }
359
+ apply(target) {
360
+ const poolSize = Math.max(2, Math.min(16, Math.floor(target.cpus / 8)));
361
+ return patch('microvm', {
362
+ args: ['--api-sock', '/run/firecracker/api.sock', '--snapshot-backend', 'File'],
363
+ notes: [
364
+ `pool of ${poolSize} pre-restored microVMs absorbs bursts; restore ${this.#restoreMs}ms vs 125ms cold boot`,
365
+ 'File backend maps memory MAP_PRIVATE: kernel faults pages in with copy-on-write',
366
+ 'Uffd backend pages guest memory through userfaultfd while vCPUs already run',
367
+ 'host capacity ~150 microVMs/s; each VM costs <5 MiB of process overhead',
368
+ 'snapshots require KVM: CI hosts without /dev/kvm fall back to QEMU TCG (layer 5)',
369
+ ],
370
+ });
371
+ }
372
+ [Symbol.dispose]() {
373
+ this.#warm = [];
374
+ this.removeAllListeners();
375
+ }
376
+ }
377
+ /**
378
+ * Builds the QEMU 11.1 command line for software virtualization.
379
+ * MTTCG (`thread=multi`) binds one host thread per vCPU (the default when
380
+ * host and guest are both x86_64), tb-size caches translation blocks and
381
+ * EPYC-v5 is the newest AMD server model in target/i386/cpu.c.
382
+ */
383
+ export function buildQemuTcgArgs(opts) {
384
+ if (opts.vcpus < 1)
385
+ throw new Error('vcpus must be at least 1');
386
+ const args = [
387
+ 'qemu-system-x86_64',
388
+ '-accel',
389
+ `tcg,thread=multi,tb-size=${opts.tbSizeMiB ?? 1024}`,
390
+ '-cpu',
391
+ opts.cpuModel ?? 'EPYC-v5',
392
+ '-smp',
393
+ String(opts.vcpus),
394
+ '-m',
395
+ String(opts.memoryMb),
396
+ '-machine',
397
+ opts.machine ?? 'microvm',
398
+ '-nodefaults',
399
+ '-no-reboot',
400
+ '-display',
401
+ 'none',
402
+ ];
403
+ if (opts.kernel !== undefined)
404
+ args.push('-kernel', opts.kernel);
405
+ if (opts.initrd !== undefined)
406
+ args.push('-initrd', opts.initrd);
407
+ if (opts.append !== undefined)
408
+ args.push('-append', opts.append);
409
+ return args;
410
+ }
411
+ /**
412
+ * Layer 5/7 - TCG.
413
+ * Used where KVM is unavailable (GitHub-hosted runners expose no /dev/kvm):
414
+ * MTTCG keeps a 1:1 vCPU-to-host-thread mapping, the translation block cache
415
+ * is sized at 1024 MiB for compile-heavy guests, and the microvm machine
416
+ * with a direct -kernel boot trims device enumeration to a minimum. QEMU
417
+ * 11.1 also ships the nitro accelerator for AWS enclave-shaped guests.
418
+ */
419
+ export class TcgLayer {
420
+ id = 'tcg';
421
+ title = 'QEMU 11.1 MTTCG, tb-size 1024, EPYC-v5, nitro accel';
422
+ contexts = [
423
+ 'QEMU 11.1.0',
424
+ 'MTTCG',
425
+ 'thread=multi',
426
+ 'tb-size',
427
+ 'EPYC-v5',
428
+ 'microvm machine',
429
+ 'nitro accelerator',
430
+ 'qboot',
431
+ ];
432
+ #tbSizeMiB = 1024;
433
+ #machine = 'microvm';
434
+ setTbSizeMiB(mib) {
435
+ if (mib < 16 || mib > 4096)
436
+ throw new Error('tb-size must stay between 16 and 4096 MiB');
437
+ this.#tbSizeMiB = mib;
438
+ return this;
439
+ }
440
+ setMachine(machine) {
441
+ this.#machine = machine;
442
+ return this;
443
+ }
444
+ apply(target) {
445
+ const args = buildQemuTcgArgs({
446
+ vcpus: target.cpus,
447
+ memoryMb: target.memoryGb * 1024,
448
+ machine: this.#machine,
449
+ tbSizeMiB: this.#tbSizeMiB,
450
+ });
451
+ return patch('tcg', {
452
+ args,
453
+ notes: [
454
+ 'MTTCG thread=multi: one host thread per vCPU, the default for x86_64-on-x86_64; single only with -icount',
455
+ `tb-size=${this.#tbSizeMiB} MiB translation block cache (default would cap at 32 MiB)`,
456
+ '-cpu EPYC-v5: newest AMD server model in QEMU 11.1 target/i386/cpu.c; add +avx512f,+avx512vl when the guest probes vector units',
457
+ '-machine microvm with qboot: minimal device model, fastest TCG boot',
458
+ 'QEMU 11.0+ adds the nitro accelerator for AWS-shaped enclave guests',
459
+ 'GitHub-hosted CI has no /dev/kvm: this layer is the documented path there',
460
+ ],
461
+ });
462
+ }
463
+ }
464
+ // ===========================================================================
465
+ // Layer 6 of 7 - build pipeline
466
+ // ===========================================================================
467
+ /** buildx cache configuration: measured 103s cold down to 25s warm on gha. */
468
+ export function buildxCacheConfig(scope) {
469
+ return {
470
+ cacheFrom: `type=gha,scope=${scope}`,
471
+ cacheTo: `type=gha,mode=max,scope=${scope}`,
472
+ measured: { coldSec: 103, warmSec: 25 },
473
+ };
474
+ }
475
+ /** LLVM maximum-optimization flags for native components (software GPU shims, overlay hooks). */
476
+ export function llvmNativeCflags(march = 'native') {
477
+ return {
478
+ cflags: `-O3 -march=${march} -flto`,
479
+ cxxflags: `-O3 -march=${march} -flto`,
480
+ ldflags: `-flto -fuse-ld=lld`,
481
+ };
482
+ }
483
+ /** Plans a multi-stage Dockerfile stage graph with cache-mount annotations. */
484
+ export function planMultiStage(stages) {
485
+ const dockerfile = ['# syntax=docker/dockerfile:1'];
486
+ for (let i = 0; i < stages.length; i += 1) {
487
+ dockerfile.push(`FROM base-${stages[i]} AS ${stages[i]}`);
488
+ if (i > 0)
489
+ dockerfile.push(`COPY --from=${stages[i - 1]} /out /in`);
490
+ }
491
+ const cacheMounts = ['/root/.cache/llvm', '/root/.cargo/registry', '/var/cache/apt'];
492
+ return { dockerfile, cacheMounts };
493
+ }
494
+ /**
495
+ * Layer 6/7 - build.
496
+ * The build layer moves compile time out of the critical path: buildx gha
497
+ * caching took the engine image from 103s cold to 25s warm, multi-stage
498
+ * builds keep the final image at runtime-only layers, and native components
499
+ * compile with LLVM -O3 -march=native -flto against the host ISA.
500
+ */
501
+ export class BuildLayer {
502
+ id = 'build';
503
+ title = 'buildx gha cache (103s to 25s), multi-stage, LLVM -O3 -march=native -flto';
504
+ contexts = [
505
+ 'buildx v0.36.1',
506
+ 'type=gha',
507
+ 'mode=max',
508
+ 'multi-stage Dockerfile',
509
+ 'LLVM 22.1.8',
510
+ '-O3',
511
+ '-march=native',
512
+ '-flto',
513
+ ];
514
+ #scope = 'vhe';
515
+ #cacheMode = 'max';
516
+ setScope(scope) {
517
+ this.#scope = scope;
518
+ return this;
519
+ }
520
+ apply(target) {
521
+ const cache = buildxCacheConfig(this.#scope);
522
+ const flags = llvmNativeCflags();
523
+ const stages = planMultiStage(['deps', 'build', 'runtime']);
524
+ return patch('build', {
525
+ env: {
526
+ CFLAGS: flags.cflags,
527
+ CXXFLAGS: flags.cxxflags,
528
+ LDFLAGS: flags.ldflags,
529
+ },
530
+ args: [
531
+ 'docker',
532
+ 'buildx',
533
+ 'build',
534
+ '--cache-from',
535
+ cache.cacheFrom,
536
+ '--cache-to',
537
+ `type=gha,mode=${this.#cacheMode},scope=${this.#scope}`,
538
+ '--push',
539
+ '.',
540
+ ],
541
+ notes: [
542
+ `buildx type=gha cache: measured ${cache.measured.coldSec}s cold -> ${cache.measured.warmSec}s warm`,
543
+ `cache-to mode=${this.#cacheMode} exports intermediate layers${this.#cacheMode === 'max' ? ' (larger cache, faster restores)' : ''}`,
544
+ `multi-stage stages deps -> build -> runtime; cache mounts: ${stages.cacheMounts.join(', ')}`,
545
+ `native components compile with CFLAGS="${flags.cflags}" (LLVM 22.1.8, tuned to the ${target.cpus}-core host)`,
546
+ ],
547
+ });
548
+ }
549
+ }
550
+ // ===========================================================================
551
+ // Layer 7 of 7 - network
552
+ // ===========================================================================
553
+ /** undici-style connection pool tuning for the engine control plane. */
554
+ export function poolingConfig(cores) {
555
+ return {
556
+ keepAliveTimeoutMs: 4_000,
557
+ keepAliveMaxTimeoutMs: 600_000,
558
+ connectionsPerOrigin: Math.max(4, cores),
559
+ pipelining: 1,
560
+ };
561
+ }
562
+ /** Plans TAP device pre-setup so VM boot does not pay interface creation cost. */
563
+ export function planTapPreSetup(tapName) {
564
+ return {
565
+ commands: [
566
+ `ip tuntap add dev ${tapName} mode tap`,
567
+ `ip link set ${tapName} up`,
568
+ `ip link set ${tapName} master vhe-br0`,
569
+ ],
570
+ savedBootMs: 35,
571
+ };
572
+ }
573
+ /**
574
+ * Layer 7 of 7 - network.
575
+ * The control plane keeps HTTP connections alive and pooled (undici Agent
576
+ * semantics: keepAliveTimeout 4s, per-origin connection floors scaled to
577
+ * cores), and TAP devices are created before the VM starts so the boot path
578
+ * skips interface setup entirely.
579
+ */
580
+ export class NetworkLayer {
581
+ id = 'network';
582
+ title = 'keepalive, connection pooling, TAP pre-setup';
583
+ contexts = [
584
+ 'undici Agent',
585
+ 'keepAliveTimeout',
586
+ 'connection pooling',
587
+ 'HTTP/1.1 pipelining',
588
+ 'ip tuntap',
589
+ 'TAP device',
590
+ 'vhe-br0 bridge',
591
+ 'ephemeral port range',
592
+ ];
593
+ #tapName = 'vhe-tap0';
594
+ setTapName(name) {
595
+ this.#tapName = name;
596
+ return this;
597
+ }
598
+ apply(target) {
599
+ const pool = poolingConfig(target.cpus);
600
+ const tap = planTapPreSetup(this.#tapName);
601
+ return patch('network', {
602
+ env: {
603
+ VHE_KEEPALIVE_TIMEOUT_MS: String(pool.keepAliveTimeoutMs),
604
+ VHE_POOL_CONNECTIONS: String(pool.connectionsPerOrigin),
605
+ },
606
+ args: tap.commands,
607
+ notes: [
608
+ `keepalive ${pool.keepAliveTimeoutMs}ms with pooling of ${pool.connectionsPerOrigin} connections per origin removes TCP+TLS handshake cost from hot calls`,
609
+ `TAP device ${this.#tapName} pre-setup saves ~${tap.savedBootMs}ms of VM boot time`,
610
+ 'listener sockets always bind ephemeral ports picked at random; no fixed localhost endpoints',
611
+ ],
612
+ });
613
+ }
614
+ }
615
+ // ===========================================================================
616
+ // Layer stack facade
617
+ // ===========================================================================
618
+ /**
619
+ * Composes the seven layers into one target-specific profile. The stack is
620
+ * the single entry point the engine uses to configure a run: it merges
621
+ * environment variables, collects process arguments, docker flags, kernel
622
+ * writes and mounts, and renders a human-readable report.
623
+ */
624
+ export class PerformanceStack {
625
+ #layers = [];
626
+ add(layer) {
627
+ this.#layers.push(layer);
628
+ return this;
629
+ }
630
+ applyAll(target) {
631
+ const patches = [];
632
+ for (const layer of this.#layers) {
633
+ try {
634
+ patches.push(layer.apply(target));
635
+ }
636
+ catch (err) {
637
+ // One broken layer must not abort the whole profile.
638
+ patches.push(patch(layer.id, { notes: [`layer failed: ${String(err)}`] }));
639
+ }
640
+ }
641
+ return patches;
642
+ }
643
+ /** Merges every patch environment into a single flat record. */
644
+ composeEnv(patches) {
645
+ const env = {};
646
+ for (const p of patches)
647
+ Object.assign(env, p.env);
648
+ return env;
649
+ }
650
+ /** Markdown report of what each layer would do for the given target. */
651
+ report(target) {
652
+ const lines = [
653
+ `# performance profile (${target.cpus} cpus, ${target.memoryGb} gb, ${target.gpus} gpus)`,
654
+ '',
655
+ ];
656
+ for (const p of this.applyAll(target)) {
657
+ lines.push(`## ${p.layer}`);
658
+ for (const note of p.notes)
659
+ lines.push(`- ${note}`);
660
+ const envKeys = Object.keys(p.env);
661
+ if (envKeys.length > 0)
662
+ lines.push(`- env: ${envKeys.map((k) => `${k}=${p.env[k]}`).join(' ')}`);
663
+ }
664
+ return lines.join('\n');
665
+ }
666
+ }
667
+ /** Stack with all seven layers in canonical order. */
668
+ export function createDefaultStack() {
669
+ return new PerformanceStack()
670
+ .add(new CpuLayer())
671
+ .add(new GpuLayer())
672
+ .add(new MemoryLayer())
673
+ .add(new FirecrackerWarmPool())
674
+ .add(new TcgLayer())
675
+ .add(new BuildLayer())
676
+ .add(new NetworkLayer());
677
+ }
678
+ /** Computes p50/p95/p99 from an already collected sample set. */
679
+ export function percentiles(samples) {
680
+ if (samples.length === 0)
681
+ throw new Error('percentiles require at least one sample');
682
+ const sorted = [...samples].sort((a, b) => a - b);
683
+ const at = (q) => {
684
+ const index = Math.min(sorted.length - 1, Math.floor(q * sorted.length));
685
+ return Number(sorted[index].toFixed(3));
686
+ };
687
+ return { p50: at(0.5), p95: at(0.95), p99: at(0.99) };
688
+ }
689
+ /**
690
+ * Benchmark harness with warmup, outlier-free percentile reporting and a
691
+ * post-run GC hint. Each iteration is timed with performance.now().
692
+ */
693
+ export class BenchmarkHarness {
694
+ #results = new Map();
695
+ async run(name, fn, opts = {}) {
696
+ const iterations = opts.iterations ?? 50;
697
+ const warmup = opts.warmup ?? 5;
698
+ for (let i = 0; i < warmup; i += 1) {
699
+ await fn(i);
700
+ }
701
+ const samplesMs = [];
702
+ for (let i = 0; i < iterations; i += 1) {
703
+ const startedAt = performance.now();
704
+ await fn(i);
705
+ samplesMs.push(performance.now() - startedAt);
706
+ }
707
+ const stats = this.summarize(name, samplesMs);
708
+ this.#results.set(name, stats);
709
+ return stats;
710
+ }
711
+ summarize(name, samplesMs) {
712
+ const { p50, p95, p99 } = percentiles(samplesMs);
713
+ const mean = samplesMs.reduce((a, b) => a + b, 0) / samplesMs.length;
714
+ const variance = samplesMs.reduce((a, b) => a + (b - mean) ** 2, 0) / samplesMs.length;
715
+ return {
716
+ name,
717
+ iterations: samplesMs.length,
718
+ samplesMs,
719
+ p50,
720
+ p95,
721
+ p99,
722
+ mean: Number(mean.toFixed(3)),
723
+ min: Number(Math.min(...samplesMs).toFixed(3)),
724
+ max: Number(Math.max(...samplesMs).toFixed(3)),
725
+ stdev: Number(Math.sqrt(variance).toFixed(3)),
726
+ };
727
+ }
728
+ result(name) {
729
+ return this.#results.get(name);
730
+ }
731
+ get names() {
732
+ return [...this.#results.keys()];
733
+ }
734
+ }
735
+ /**
736
+ * Regression detector: compares a current benchmark against a stored
737
+ * baseline and flags any percentile that degraded beyond the threshold
738
+ * (default 10%). Verdicts: ok (all within threshold), warn (regressed but
739
+ * under twice the threshold), fail (at least one metric beyond 2x).
740
+ */
741
+ export class RegressionDetector {
742
+ thresholdPct;
743
+ constructor(thresholdPct = 10) {
744
+ if (thresholdPct <= 0)
745
+ throw new Error('thresholdPct must be positive');
746
+ this.thresholdPct = thresholdPct;
747
+ }
748
+ compare(baseline, current) {
749
+ const metrics = ['p50', 'p95', 'p99', 'mean'];
750
+ const checks = metrics.map((metric) => {
751
+ const base = baseline[metric];
752
+ const now = current[metric];
753
+ const deltaPct = base === 0
754
+ ? now === 0
755
+ ? 0
756
+ : Number.POSITIVE_INFINITY
757
+ : Number((((now - base) / base) * 100).toFixed(2));
758
+ return { metric, baseline: base, current: now, deltaPct };
759
+ });
760
+ const worst = Math.max(...checks.map((c) => c.deltaPct));
761
+ const verdict = worst <= this.thresholdPct ? 'ok' : worst <= this.thresholdPct * 2 ? 'warn' : 'fail';
762
+ return { verdict, checks };
763
+ }
764
+ }
765
+ /**
766
+ * Profile mode: wraps named phases with performance.mark/measure pairs and
767
+ * accumulates a phase timeline. The report is plain text so CI logs stay
768
+ * grep-friendly.
769
+ */
770
+ export class ProfileMode {
771
+ #phases = [];
772
+ #enabled = true;
773
+ setEnabled(enabled) {
774
+ this.#enabled = enabled;
775
+ return this;
776
+ }
777
+ async phase(name, fn) {
778
+ if (!this.#enabled) {
779
+ return await fn();
780
+ }
781
+ const markStart = `${name}-start`;
782
+ const markEnd = `${name}-end`;
783
+ performance.mark(markStart);
784
+ try {
785
+ return await fn();
786
+ }
787
+ finally {
788
+ performance.mark(markEnd);
789
+ try {
790
+ performance.measure(name, markStart, markEnd);
791
+ const entries = performance.getEntriesByName(name);
792
+ const last = entries[entries.length - 1];
793
+ this.#phases.push({
794
+ name,
795
+ durationMs: Number(last.duration.toFixed(3)),
796
+ marks: entries.length,
797
+ });
798
+ }
799
+ catch {
800
+ // measurement failures must never mask the phase result
801
+ }
802
+ }
803
+ }
804
+ report() {
805
+ const lines = this.#phases.map((p) => `${p.name}: ${p.durationMs} ms`);
806
+ const total = this.#phases.reduce((a, p) => a + p.durationMs, 0);
807
+ return [...lines, `total: ${total.toFixed(3)} ms`].join('\n');
808
+ }
809
+ get phases() {
810
+ return this.#phases;
811
+ }
812
+ }
813
+ /**
814
+ * Convenience wrapper: profiles a benchmark scenario across the seven-layer
815
+ * stack, detects regressions against an optional baseline and returns both
816
+ * the patch profile and the measurement in one call.
817
+ */
818
+ export async function profileScenario(opts) {
819
+ const stack = createDefaultStack();
820
+ const patches = stack.applyAll(opts.target);
821
+ const env = stack.composeEnv(patches);
822
+ const harness = new BenchmarkHarness();
823
+ const result = await harness.run(opts.name, opts.fn, { iterations: opts.iterations });
824
+ const regression = opts.baseline === undefined ? null : new RegressionDetector().compare(opts.baseline, result);
825
+ return { patches, env, result, regression };
826
+ }
827
+ //# sourceMappingURL=performance.js.map