@wenathlan/saddle 1.8.18 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (802) hide show
  1. package/Dockerfile +1339 -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/performance.d.ts +416 -0
  89. package/dist/performance.d.ts.map +1 -0
  90. package/dist/performance.js +827 -0
  91. package/dist/performance.js.map +1 -0
  92. package/dist/quantum.d.ts +810 -0
  93. package/dist/quantum.d.ts.map +1 -0
  94. package/dist/quantum.js +2073 -0
  95. package/dist/quantum.js.map +1 -0
  96. package/dist/render.d.ts +381 -0
  97. package/dist/render.d.ts.map +1 -0
  98. package/dist/render.js +1073 -0
  99. package/dist/render.js.map +1 -0
  100. package/dist/scheduler.d.ts +596 -0
  101. package/dist/scheduler.d.ts.map +1 -0
  102. package/dist/scheduler.js +1259 -0
  103. package/dist/scheduler.js.map +1 -0
  104. package/dist/security.d.ts +501 -0
  105. package/dist/security.d.ts.map +1 -0
  106. package/dist/security.js +1170 -0
  107. package/dist/security.js.map +1 -0
  108. package/dist/server.d.ts +21 -0
  109. package/dist/server.d.ts.map +1 -0
  110. package/dist/{server/node.js → server.js} +16 -2
  111. package/dist/server.js.map +1 -0
  112. package/dist/tiers.d.ts +1002 -0
  113. package/dist/tiers.d.ts.map +1 -0
  114. package/dist/tiers.js +2165 -0
  115. package/dist/tiers.js.map +1 -0
  116. package/dist/virtual.d.ts +641 -0
  117. package/dist/virtual.d.ts.map +1 -0
  118. package/dist/virtual.js +1285 -0
  119. package/dist/virtual.js.map +1 -0
  120. package/dist/virtualcpu.d.ts +316 -0
  121. package/dist/virtualcpu.d.ts.map +1 -0
  122. package/dist/virtualcpu.js +1180 -0
  123. package/dist/virtualcpu.js.map +1 -0
  124. package/dist/virtualgpu.d.ts +345 -0
  125. package/dist/virtualgpu.d.ts.map +1 -0
  126. package/dist/virtualgpu.js +1000 -0
  127. package/dist/virtualgpu.js.map +1 -0
  128. package/dist/virtualization.d.ts +607 -0
  129. package/dist/virtualization.d.ts.map +1 -0
  130. package/dist/virtualization.js +1187 -0
  131. package/dist/virtualization.js.map +1 -0
  132. package/dist/virtualmemory.d.ts +818 -0
  133. package/dist/virtualmemory.d.ts.map +1 -0
  134. package/dist/virtualmemory.js +1796 -0
  135. package/dist/virtualmemory.js.map +1 -0
  136. package/dist/webscrape.d.ts +720 -0
  137. package/dist/webscrape.d.ts.map +1 -0
  138. package/dist/webscrape.js +2697 -0
  139. package/dist/webscrape.js.map +1 -0
  140. package/docker.config +769 -0
  141. package/docs/CONVERSA.txt +1523 -0
  142. package/docs/alternatives.md +499 -0
  143. package/docs/architecture-1.8.19.md +76 -0
  144. package/docs/architecture-1.8.19.mmd +33 -0
  145. package/docs/architecture-1.8.19.png +0 -0
  146. package/docs/architecture.md +355 -0
  147. package/docs/brancharchive-2026-08-18.md +18 -0
  148. package/docs/browser.md +7 -0
  149. package/docs/consolidation.md +70 -0
  150. package/docs/e2ugh-engine.md +528 -0
  151. package/{dist/examples/localjob.js → docs/example-localjob.ts} +3 -3
  152. package/{dist/examples/publicapi.js → docs/example-publicapi.ts} +2 -2
  153. package/docs/hardware.md +342 -0
  154. package/docs/optimization.md +126 -0
  155. package/docs/performance.md +499 -0
  156. package/docs/planning.1.8.18.md +94 -0
  157. package/docs/planning.1.8.19.md +49 -0
  158. package/docs/releasenotes-1.8.19.md +35 -0
  159. package/docs/research-1.8.19-virtual-browser.md +27 -0
  160. package/docs/security.md +454 -0
  161. package/docs/todo-1.8.18.md +12 -0
  162. package/docs/todo-1.8.19.md +241 -0
  163. package/docs/viability.md +777 -0
  164. package/docs/virtualization.md +335 -0
  165. package/docs/web-duplicatecleanup.md +9 -0
  166. package/docs/web-ideas.md +106 -0
  167. package/docs/workflowimprovements-2026-08-19.md +70 -0
  168. package/gpumonitor.cpp +1543 -0
  169. package/gpus.json +2408 -0
  170. package/index.ts +1478 -0
  171. package/media.ts +1337 -0
  172. package/mttg.config +1549 -0
  173. package/orchestrator.ts +5462 -0
  174. package/package.json +304 -56
  175. package/passage.config +1331 -0
  176. package/performance.ts +1049 -0
  177. package/processors.json +2217 -0
  178. package/qemu.config +1062 -0
  179. package/qemubridge.py +1340 -0
  180. package/quantum.ts +2393 -0
  181. package/render.ts +1325 -0
  182. package/scheduler.ts +1600 -0
  183. package/security.ts +1449 -0
  184. package/tiers.ts +2871 -0
  185. package/tsconfig.json +29 -0
  186. package/virtualcpu.ts +1273 -0
  187. package/virtualgpu.ts +1181 -0
  188. package/virtualhardware.c +1011 -0
  189. package/virtualhardware.json +739 -0
  190. package/virtualization.ts +1628 -0
  191. package/virtualizationcore.cpp +4635 -0
  192. package/virtualmemory.ts +2303 -0
  193. package/vm.config.json +1910 -0
  194. package/{extension → web/extension}/manifest.json +1 -1
  195. package/web/readme.md +382 -0
  196. package/web/tsconfig.json +25 -0
  197. package/dist/adapters/forge.d.ts +0 -17
  198. package/dist/adapters/forge.d.ts.map +0 -1
  199. package/dist/adapters/forge.js +0 -19
  200. package/dist/adapters/forge.js.map +0 -1
  201. package/dist/adapters/forgejo.d.ts +0 -49
  202. package/dist/adapters/forgejo.d.ts.map +0 -1
  203. package/dist/adapters/forgejo.js +0 -8
  204. package/dist/adapters/forgejo.js.map +0 -1
  205. package/dist/adapters/github.d.ts +0 -12
  206. package/dist/adapters/github.d.ts.map +0 -1
  207. package/dist/adapters/github.js +0 -20
  208. package/dist/adapters/github.js.map +0 -1
  209. package/dist/adapters/gitlab.d.ts +0 -17
  210. package/dist/adapters/gitlab.d.ts.map +0 -1
  211. package/dist/adapters/gitlab.js +0 -10
  212. package/dist/adapters/gitlab.js.map +0 -1
  213. package/dist/adapters/huggingface.d.ts +0 -17
  214. package/dist/adapters/huggingface.d.ts.map +0 -1
  215. package/dist/adapters/huggingface.js +0 -6
  216. package/dist/adapters/huggingface.js.map +0 -1
  217. package/dist/adapters/socket.d.ts +0 -11
  218. package/dist/adapters/socket.d.ts.map +0 -1
  219. package/dist/adapters/socket.js +0 -17
  220. package/dist/adapters/socket.js.map +0 -1
  221. package/dist/adapters/transport.d.ts +0 -7
  222. package/dist/adapters/transport.d.ts.map +0 -1
  223. package/dist/adapters/transport.js +0 -36
  224. package/dist/adapters/transport.js.map +0 -1
  225. package/dist/ai/chunk.d.ts +0 -2
  226. package/dist/ai/chunk.d.ts.map +0 -1
  227. package/dist/ai/chunk.js +0 -36
  228. package/dist/ai/chunk.js.map +0 -1
  229. package/dist/ai/llmstxt.d.ts +0 -6
  230. package/dist/ai/llmstxt.d.ts.map +0 -1
  231. package/dist/ai/llmstxt.js +0 -12
  232. package/dist/ai/llmstxt.js.map +0 -1
  233. package/dist/ai/provenance.d.ts +0 -22
  234. package/dist/ai/provenance.d.ts.map +0 -1
  235. package/dist/ai/provenance.js +0 -25
  236. package/dist/ai/provenance.js.map +0 -1
  237. package/dist/ai/rag.d.ts +0 -26
  238. package/dist/ai/rag.d.ts.map +0 -1
  239. package/dist/ai/rag.js +0 -22
  240. package/dist/ai/rag.js.map +0 -1
  241. package/dist/ai/tokens.d.ts +0 -15
  242. package/dist/ai/tokens.d.ts.map +0 -1
  243. package/dist/ai/tokens.js +0 -9
  244. package/dist/ai/tokens.js.map +0 -1
  245. package/dist/api/auth.d.ts +0 -16
  246. package/dist/api/auth.d.ts.map +0 -1
  247. package/dist/api/auth.js +0 -19
  248. package/dist/api/auth.js.map +0 -1
  249. package/dist/api/contracts.d.ts +0 -28
  250. package/dist/api/contracts.d.ts.map +0 -1
  251. package/dist/api/contracts.js +0 -14
  252. package/dist/api/contracts.js.map +0 -1
  253. package/dist/api/control.d.ts +0 -10
  254. package/dist/api/control.d.ts.map +0 -1
  255. package/dist/api/control.js +0 -35
  256. package/dist/api/control.js.map +0 -1
  257. package/dist/api/http.d.ts +0 -7
  258. package/dist/api/http.d.ts.map +0 -1
  259. package/dist/api/http.js +0 -12
  260. package/dist/api/http.js.map +0 -1
  261. package/dist/api/rate.d.ts +0 -28
  262. package/dist/api/rate.d.ts.map +0 -1
  263. package/dist/api/rate.js +0 -36
  264. package/dist/api/rate.js.map +0 -1
  265. package/dist/api/security.d.ts +0 -12
  266. package/dist/api/security.d.ts.map +0 -1
  267. package/dist/api/security.js +0 -56
  268. package/dist/api/security.js.map +0 -1
  269. package/dist/api/service.d.ts +0 -5
  270. package/dist/api/service.d.ts.map +0 -1
  271. package/dist/api/service.js +0 -70
  272. package/dist/api/service.js.map +0 -1
  273. package/dist/apps/registry.d.ts +0 -33
  274. package/dist/apps/registry.d.ts.map +0 -1
  275. package/dist/apps/registry.js +0 -24
  276. package/dist/apps/registry.js.map +0 -1
  277. package/dist/binary/archive.d.ts +0 -27
  278. package/dist/binary/archive.d.ts.map +0 -1
  279. package/dist/binary/archive.js +0 -46
  280. package/dist/binary/archive.js.map +0 -1
  281. package/dist/binary/build.d.ts +0 -29
  282. package/dist/binary/build.d.ts.map +0 -1
  283. package/dist/binary/build.js +0 -17
  284. package/dist/binary/build.js.map +0 -1
  285. package/dist/binary/transform.d.ts +0 -70
  286. package/dist/binary/transform.d.ts.map +0 -1
  287. package/dist/binary/transform.js +0 -105
  288. package/dist/binary/transform.js.map +0 -1
  289. package/dist/bot/adapter.d.ts +0 -5
  290. package/dist/bot/adapter.d.ts.map +0 -1
  291. package/dist/bot/adapter.js +0 -11
  292. package/dist/bot/adapter.js.map +0 -1
  293. package/dist/bot/bot.d.ts +0 -28
  294. package/dist/bot/bot.d.ts.map +0 -1
  295. package/dist/bot/bot.js +0 -52
  296. package/dist/bot/bot.js.map +0 -1
  297. package/dist/bot/commands.d.ts +0 -8
  298. package/dist/bot/commands.d.ts.map +0 -1
  299. package/dist/bot/commands.js +0 -19
  300. package/dist/bot/commands.js.map +0 -1
  301. package/dist/bot/permissions.d.ts +0 -13
  302. package/dist/bot/permissions.d.ts.map +0 -1
  303. package/dist/bot/permissions.js +0 -16
  304. package/dist/bot/permissions.js.map +0 -1
  305. package/dist/browser/actions.d.ts +0 -33
  306. package/dist/browser/actions.d.ts.map +0 -1
  307. package/dist/browser/actions.js +0 -44
  308. package/dist/browser/actions.js.map +0 -1
  309. package/dist/browser/agent.d.ts +0 -21
  310. package/dist/browser/agent.d.ts.map +0 -1
  311. package/dist/browser/agent.js +0 -13
  312. package/dist/browser/agent.js.map +0 -1
  313. package/dist/browser/context.d.ts +0 -43
  314. package/dist/browser/context.d.ts.map +0 -1
  315. package/dist/browser/context.js +0 -54
  316. package/dist/browser/context.js.map +0 -1
  317. package/dist/browser/fingerprint.d.ts +0 -4
  318. package/dist/browser/fingerprint.d.ts.map +0 -1
  319. package/dist/browser/fingerprint.js +0 -12
  320. package/dist/browser/fingerprint.js.map +0 -1
  321. package/dist/browser/index.d.ts +0 -11
  322. package/dist/browser/index.d.ts.map +0 -1
  323. package/dist/browser/index.js +0 -11
  324. package/dist/browser/index.js.map +0 -1
  325. package/dist/browser/playwright.d.ts +0 -11
  326. package/dist/browser/playwright.d.ts.map +0 -1
  327. package/dist/browser/playwright.js +0 -24
  328. package/dist/browser/playwright.js.map +0 -1
  329. package/dist/browser/recorder.d.ts +0 -21
  330. package/dist/browser/recorder.d.ts.map +0 -1
  331. package/dist/browser/recorder.js +0 -58
  332. package/dist/browser/recorder.js.map +0 -1
  333. package/dist/browser/session.d.ts +0 -14
  334. package/dist/browser/session.d.ts.map +0 -1
  335. package/dist/browser/session.js +0 -21
  336. package/dist/browser/session.js.map +0 -1
  337. package/dist/browser/snapshot.d.ts +0 -69
  338. package/dist/browser/snapshot.d.ts.map +0 -1
  339. package/dist/browser/snapshot.js +0 -133
  340. package/dist/browser/snapshot.js.map +0 -1
  341. package/dist/captcha/contract.d.ts +0 -35
  342. package/dist/captcha/contract.d.ts.map +0 -1
  343. package/dist/captcha/contract.js +0 -17
  344. package/dist/captcha/contract.js.map +0 -1
  345. package/dist/captcha/evidence.d.ts +0 -10
  346. package/dist/captcha/evidence.d.ts.map +0 -1
  347. package/dist/captcha/evidence.js +0 -9
  348. package/dist/captcha/evidence.js.map +0 -1
  349. package/dist/captcha/guard.d.ts +0 -23
  350. package/dist/captcha/guard.d.ts.map +0 -1
  351. package/dist/captcha/guard.js +0 -12
  352. package/dist/captcha/guard.js.map +0 -1
  353. package/dist/cli/main.d.ts +0 -4
  354. package/dist/cli/main.d.ts.map +0 -1
  355. package/dist/cli/main.js +0 -46
  356. package/dist/cli/main.js.map +0 -1
  357. package/dist/core/errors.d.ts +0 -84
  358. package/dist/core/errors.d.ts.map +0 -1
  359. package/dist/core/errors.js +0 -54
  360. package/dist/core/errors.js.map +0 -1
  361. package/dist/core/events.d.ts +0 -9
  362. package/dist/core/events.d.ts.map +0 -1
  363. package/dist/core/events.js +0 -21
  364. package/dist/core/events.js.map +0 -1
  365. package/dist/core/hash.d.ts +0 -10
  366. package/dist/core/hash.d.ts.map +0 -1
  367. package/dist/core/hash.js +0 -82
  368. package/dist/core/hash.js.map +0 -1
  369. package/dist/core/ids.d.ts +0 -10
  370. package/dist/core/ids.d.ts.map +0 -1
  371. package/dist/core/ids.js +0 -15
  372. package/dist/core/ids.js.map +0 -1
  373. package/dist/delivery/manifest.d.ts +0 -35
  374. package/dist/delivery/manifest.d.ts.map +0 -1
  375. package/dist/delivery/manifest.js +0 -68
  376. package/dist/delivery/manifest.js.map +0 -1
  377. package/dist/deploy/index.d.ts +0 -6
  378. package/dist/deploy/index.d.ts.map +0 -1
  379. package/dist/deploy/index.js +0 -6
  380. package/dist/deploy/index.js.map +0 -1
  381. package/dist/dispatch/resumable.d.ts +0 -102
  382. package/dist/dispatch/resumable.d.ts.map +0 -1
  383. package/dist/dispatch/resumable.js +0 -64
  384. package/dist/dispatch/resumable.js.map +0 -1
  385. package/dist/dispatch/workflow.d.ts +0 -6
  386. package/dist/dispatch/workflow.d.ts.map +0 -1
  387. package/dist/dispatch/workflow.js +0 -37
  388. package/dist/dispatch/workflow.js.map +0 -1
  389. package/dist/domain/artifacts.d.ts +0 -12
  390. package/dist/domain/artifacts.d.ts.map +0 -1
  391. package/dist/domain/artifacts.js +0 -14
  392. package/dist/domain/artifacts.js.map +0 -1
  393. package/dist/domain/jobs.d.ts +0 -12
  394. package/dist/domain/jobs.d.ts.map +0 -1
  395. package/dist/domain/jobs.js +0 -20
  396. package/dist/domain/jobs.js.map +0 -1
  397. package/dist/domain/providers.d.ts +0 -10
  398. package/dist/domain/providers.d.ts.map +0 -1
  399. package/dist/domain/providers.js +0 -8
  400. package/dist/domain/providers.js.map +0 -1
  401. package/dist/domain/runtime.d.ts +0 -14
  402. package/dist/domain/runtime.d.ts.map +0 -1
  403. package/dist/domain/runtime.js +0 -10
  404. package/dist/domain/runtime.js.map +0 -1
  405. package/dist/domain/sessions.d.ts +0 -12
  406. package/dist/domain/sessions.d.ts.map +0 -1
  407. package/dist/domain/sessions.js +0 -57
  408. package/dist/domain/sessions.js.map +0 -1
  409. package/dist/examples/localjob.d.ts +0 -2
  410. package/dist/examples/localjob.d.ts.map +0 -1
  411. package/dist/examples/localjob.js.map +0 -1
  412. package/dist/examples/publicapi.d.ts +0 -2
  413. package/dist/examples/publicapi.d.ts.map +0 -1
  414. package/dist/examples/publicapi.js.map +0 -1
  415. package/dist/extension/build.d.ts +0 -9
  416. package/dist/extension/build.d.ts.map +0 -1
  417. package/dist/extension/build.js +0 -85
  418. package/dist/extension/build.js.map +0 -1
  419. package/dist/extension/content.d.ts +0 -6
  420. package/dist/extension/content.d.ts.map +0 -1
  421. package/dist/extension/content.js +0 -135
  422. package/dist/extension/content.js.map +0 -1
  423. package/dist/extension/index.d.ts +0 -7
  424. package/dist/extension/index.d.ts.map +0 -1
  425. package/dist/extension/index.js +0 -7
  426. package/dist/extension/index.js.map +0 -1
  427. package/dist/extension/pagebridge.d.ts +0 -6
  428. package/dist/extension/pagebridge.d.ts.map +0 -1
  429. package/dist/extension/pagebridge.js +0 -42
  430. package/dist/extension/pagebridge.js.map +0 -1
  431. package/dist/extension/permissions.d.ts +0 -26
  432. package/dist/extension/permissions.d.ts.map +0 -1
  433. package/dist/extension/permissions.js +0 -28
  434. package/dist/extension/permissions.js.map +0 -1
  435. package/dist/extension/popup.d.ts +0 -5
  436. package/dist/extension/popup.d.ts.map +0 -1
  437. package/dist/extension/popup.js +0 -26
  438. package/dist/extension/popup.js.map +0 -1
  439. package/dist/extension/protocol.d.ts +0 -58
  440. package/dist/extension/protocol.d.ts.map +0 -1
  441. package/dist/extension/protocol.js +0 -101
  442. package/dist/extension/protocol.js.map +0 -1
  443. package/dist/extension/serviceworker.d.ts +0 -25
  444. package/dist/extension/serviceworker.d.ts.map +0 -1
  445. package/dist/extension/serviceworker.js +0 -102
  446. package/dist/extension/serviceworker.js.map +0 -1
  447. package/dist/extension/worker.d.ts +0 -28
  448. package/dist/extension/worker.d.ts.map +0 -1
  449. package/dist/extension/worker.js +0 -22
  450. package/dist/extension/worker.js.map +0 -1
  451. package/dist/format/check.d.ts +0 -8
  452. package/dist/format/check.d.ts.map +0 -1
  453. package/dist/format/check.js +0 -38
  454. package/dist/format/check.js.map +0 -1
  455. package/dist/isolation/contracts.d.ts.map +0 -1
  456. package/dist/isolation/contracts.js.map +0 -1
  457. package/dist/library/public.d.ts.map +0 -1
  458. package/dist/library/public.js.map +0 -1
  459. package/dist/mcp/browser.d.ts +0 -9
  460. package/dist/mcp/browser.d.ts.map +0 -1
  461. package/dist/mcp/browser.js +0 -13
  462. package/dist/mcp/browser.js.map +0 -1
  463. package/dist/mcp/server.d.ts +0 -35
  464. package/dist/mcp/server.d.ts.map +0 -1
  465. package/dist/mcp/server.js +0 -40
  466. package/dist/mcp/server.js.map +0 -1
  467. package/dist/mcp/transport.d.ts +0 -7
  468. package/dist/mcp/transport.d.ts.map +0 -1
  469. package/dist/mcp/transport.js +0 -17
  470. package/dist/mcp/transport.js.map +0 -1
  471. package/dist/memory/bridge.d.ts +0 -14
  472. package/dist/memory/bridge.d.ts.map +0 -1
  473. package/dist/memory/bridge.js +0 -16
  474. package/dist/memory/bridge.js.map +0 -1
  475. package/dist/memory/engine.d.ts +0 -38
  476. package/dist/memory/engine.d.ts.map +0 -1
  477. package/dist/memory/engine.js +0 -109
  478. package/dist/memory/engine.js.map +0 -1
  479. package/dist/memory/modes.d.ts +0 -43
  480. package/dist/memory/modes.d.ts.map +0 -1
  481. package/dist/memory/modes.js +0 -66
  482. package/dist/memory/modes.js.map +0 -1
  483. package/dist/memory/objects.d.ts +0 -21
  484. package/dist/memory/objects.d.ts.map +0 -1
  485. package/dist/memory/objects.js +0 -20
  486. package/dist/memory/objects.js.map +0 -1
  487. package/dist/memory/planner.d.ts +0 -66
  488. package/dist/memory/planner.d.ts.map +0 -1
  489. package/dist/memory/planner.js +0 -108
  490. package/dist/memory/planner.js.map +0 -1
  491. package/dist/memory/targets.d.ts +0 -78
  492. package/dist/memory/targets.d.ts.map +0 -1
  493. package/dist/memory/targets.js +0 -29
  494. package/dist/memory/targets.js.map +0 -1
  495. package/dist/memory/transforms.d.ts +0 -19
  496. package/dist/memory/transforms.d.ts.map +0 -1
  497. package/dist/memory/transforms.js +0 -14
  498. package/dist/memory/transforms.js.map +0 -1
  499. package/dist/modes/matrix.d.ts +0 -23
  500. package/dist/modes/matrix.d.ts.map +0 -1
  501. package/dist/modes/matrix.js +0 -18
  502. package/dist/modes/matrix.js.map +0 -1
  503. package/dist/modes/modes.d.ts +0 -33
  504. package/dist/modes/modes.d.ts.map +0 -1
  505. package/dist/modes/modes.js +0 -15
  506. package/dist/modes/modes.js.map +0 -1
  507. package/dist/modes/resolve.d.ts +0 -96
  508. package/dist/modes/resolve.d.ts.map +0 -1
  509. package/dist/modes/resolve.js +0 -48
  510. package/dist/modes/resolve.js.map +0 -1
  511. package/dist/observability/metrics.d.ts +0 -14
  512. package/dist/observability/metrics.d.ts.map +0 -1
  513. package/dist/observability/metrics.js +0 -18
  514. package/dist/observability/metrics.js.map +0 -1
  515. package/dist/packager/manifest.d.ts +0 -66
  516. package/dist/packager/manifest.d.ts.map +0 -1
  517. package/dist/packager/manifest.js +0 -94
  518. package/dist/packager/manifest.js.map +0 -1
  519. package/dist/packager/publish.d.ts +0 -51
  520. package/dist/packager/publish.d.ts.map +0 -1
  521. package/dist/packager/publish.js +0 -18
  522. package/dist/packager/publish.js.map +0 -1
  523. package/dist/packager/targetcli.d.ts +0 -7
  524. package/dist/packager/targetcli.d.ts.map +0 -1
  525. package/dist/packager/targetcli.js +0 -22
  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
package/index.ts ADDED
@@ -0,0 +1,1478 @@
1
+ /**
2
+ * index.ts — the stable public API of the saddle grand merge (v2.0.0).
3
+ *
4
+ * Section 1 carries the e2ugh virtual-hardware engine core (the library-first
5
+ * entry point of the merged e2ugh repository: the main factory
6
+ * createVirtualEngine, the dependency-free specification validator
7
+ * validateSpec, the random endpoint allocator randomPort, the Map-based
8
+ * internal memory store InternalMemory, the disposable metrics store
9
+ * MetricsStore, the strongly typed event bus enginebus, and the plan planner
10
+ * absorbed from the former architect.ts).
11
+ *
12
+ * Section 2 routes the saddle domain surface through the root-level domain
13
+ * files of the consolidation: one optimized TypeScript file per correlated
14
+ * domain, every former nested folder of both repositories folded at the
15
+ * repository root.
16
+ */
17
+
18
+ /* ── Section 1: the e2ugh virtual-hardware engine core ── */
19
+
20
+ import { randomInt, randomUUID } from 'node:crypto';
21
+ import { EventEmitter } from 'node:events';
22
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
23
+ import { join } from 'node:path';
24
+ import type { migprofileid } from './virtualmemory.js';
25
+
26
+ /* ------------------------------------------------------------------ */
27
+ /* Section 1: reference versions */
28
+ /* ------------------------------------------------------------------ */
29
+
30
+ /**
31
+ * Frozen table of the reference toolchain versions that the engine targets.
32
+ * Every value was confirmed against primary sources on 2026-08-22 and is
33
+ * embedded here so generated documentation and workflows can cite exact
34
+ * versions without a network round trip. the v2 merge adds the microvm
35
+ * runtime anchors so every module (orchestrator, virtualization, security)
36
+ * cites the same ledger.
37
+ */
38
+ export const engineversions = {
39
+ /** npm latest confirmed 2026-08-23 (v12 shipped july 2026). */
40
+ npm: '12.0.2',
41
+ /** python stable confirmed 2026-08-23. */
42
+ python: '3.14.7',
43
+ nodecurrent: '26.7.0',
44
+ nodelts: '24.19.0',
45
+ typescript: '7.0.2',
46
+ docker: '29.7.2',
47
+ compose: '5.5.0',
48
+ mesaa: '26.2.1',
49
+ qemu: '11.1.0',
50
+ firecracker: '1.16.1',
51
+ kata: '4.1.0',
52
+ gvisor: 'release-20260817.0',
53
+ cloudhypervisor: '53.0',
54
+ criu: '4.2.1',
55
+ /* v3-VERIFY corrections (worklog 2026-08-23): kernel "7.2.1" never
56
+ * existed (mainline 7.2, stable 7.1.9, longterm 6.18.45) and wgpu
57
+ * moved from 24.x to 30.x; wasmtime 48.0.0 LTS confirmed. */
58
+ kernelmainline: '7.2',
59
+ kernelstable: '7.1.9',
60
+ kernellongterm: '6.18.45',
61
+ wasmtime: '48.0.0',
62
+ wgpu: '30.x',
63
+ } as const satisfies Record<string, string>;
64
+
65
+ /** Union of every key available in the engineversions table. */
66
+ export type engineversionkey = keyof typeof engineversions;
67
+
68
+ /* ------------------------------------------------------------------ */
69
+ /* Section 2: engine limits and specification types */
70
+ /* ------------------------------------------------------------------ */
71
+
72
+ /** Numeric bounds applied to every engine specification. */
73
+ export type enginelimits = {
74
+ readonly minvcpu: number;
75
+ readonly maxvcpu: number;
76
+ readonly minramgb: number;
77
+ readonly maxramgb: number;
78
+ readonly minvramgb: number;
79
+ readonly maxvramgb: number;
80
+ readonly minport: number;
81
+ readonly maxport: number;
82
+ };
83
+
84
+ /**
85
+ * Hard limits of the virtual hardware generation. Values mirror the extremes
86
+ * of the embedded processor bank: 1 to 192 vCPUs (EPYC 9965 class), 1 to
87
+ * 1024 GB of guest RAM, 8 to 96 GB of virtualized VRAM (RTX PRO 6000 class with
88
+ * MIG slicing) and the random port range 30000-59999.
89
+ */
90
+ export const enginelimits = {
91
+ minvcpu: 1,
92
+ maxvcpu: 192,
93
+ minramgb: 1,
94
+ maxramgb: 1024,
95
+ minvramgb: 8,
96
+ maxvramgb: 96,
97
+ minport: 30000,
98
+ maxport: 59999,
99
+ } as const satisfies enginelimits;
100
+
101
+ /** Runtime backend that executes the virtual machine workload. */
102
+ export type engineruntime = 'qemu' | 'firecracker' | 'docker' | 'gvisor';
103
+
104
+ /** Lifecycle states of a virtual engine instance. */
105
+ export type enginestate = 'created' | 'starting' | 'running' | 'degraded' | 'stopped';
106
+
107
+ /** Full declarative specification of one virtual hardware machine. */
108
+ export type enginespec = {
109
+ readonly model: string;
110
+ readonly vcpus: number;
111
+ readonly ramgb: number;
112
+ readonly vramgb: number;
113
+ readonly mig: migprofileid;
114
+ readonly runtime: engineruntime;
115
+ readonly host: string;
116
+ readonly port: number;
117
+ readonly metricsintervalms: number;
118
+ };
119
+
120
+ /** Resolved network endpoint of a running engine. */
121
+ export type engineendpoint = {
122
+ readonly host: string;
123
+ readonly port: number;
124
+ readonly url: string;
125
+ };
126
+
127
+ /** Options accepted by createVirtualEngine; every field is optional. */
128
+ export type engineoptions = {
129
+ readonly model?: string;
130
+ readonly vcpus?: number;
131
+ readonly ramgb?: number;
132
+ readonly vramgb?: number;
133
+ readonly mig?: migprofileid;
134
+ readonly runtime?: engineruntime;
135
+ readonly host?: string;
136
+ readonly port?: number;
137
+ readonly metricsintervalms?: number;
138
+ };
139
+
140
+ /* ------------------------------------------------------------------ */
141
+ /* Section 3: random port allocation and host resolution */
142
+ /* ------------------------------------------------------------------ */
143
+
144
+ /**
145
+ * Returns a random TCP port in the 30000-59999 range using a
146
+ * cryptographically secure generator (node:crypto randomInt). The user may
147
+ * override the random draw by passing an explicit port, which is validated
148
+ * against the engine limits before being returned.
149
+ *
150
+ * @param override Explicit port chosen by the user; when omitted a random
151
+ * port is drawn, which keeps the library free of fixed addresses.
152
+ */
153
+ export function randomPort(override?: number): number {
154
+ try {
155
+ if (typeof override === 'number') {
156
+ if (
157
+ !Number.isInteger(override) ||
158
+ override < enginelimits.minport ||
159
+ override > enginelimits.maxport
160
+ ) {
161
+ throw new RangeError(
162
+ `port must be an integer between ${enginelimits.minport} and ${enginelimits.maxport}`,
163
+ );
164
+ }
165
+ return override;
166
+ }
167
+ return 30000 + randomInt(30000);
168
+ } catch (cause) {
169
+ throw new engineerror('randomPort failed', { cause: cause as Error });
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Resolves the bind host from explicit preference or the environment
175
+ * variables `virtualenginehost` or `vhehost`. No default address such as
176
+ * localhost is ever assumed implicitly: when neither argument nor
177
+ * environment provides a host the function fails loudly, keeping the
178
+ * address 100 percent a user choice (an explicit loopback is honored
179
+ * because it is the explicit decision of the caller).
180
+ *
181
+ * @param preferred Host explicitly chosen by the caller; wins over env.
182
+ */
183
+ export function resolveHost(preferred?: string): string {
184
+ try {
185
+ const fromenv = process.env.virtualenginehost ?? process.env.vhehost;
186
+ const chosen = preferred ?? fromenv;
187
+ if (typeof chosen !== 'string' || chosen.trim().length === 0) {
188
+ throw new engineerror(
189
+ 'host is required: pass an explicit host or set virtualenginehost; the engine never assumes a default address',
190
+ );
191
+ }
192
+ return chosen.trim();
193
+ } catch (cause) {
194
+ if (cause instanceof engineerror) {
195
+ throw cause;
196
+ }
197
+ throw new engineerror('resolveHost failed', { cause: cause as Error });
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Combines a host and a port into an endpoint descriptor. The port falls
203
+ * back to randomPort when omitted so the endpoint is always concrete.
204
+ */
205
+ export function buildEndpoint(host: string, port?: number): engineendpoint {
206
+ try {
207
+ const resolvedhost = resolveHost(host);
208
+ const resolvedport = randomPort(port);
209
+ return {
210
+ host: resolvedhost,
211
+ port: resolvedport,
212
+ url: `http://${resolvedhost}:${resolvedport}`,
213
+ };
214
+ } catch (cause) {
215
+ throw new engineerror('buildEndpoint failed', { cause: cause as Error });
216
+ }
217
+ }
218
+
219
+ /* ------------------------------------------------------------------ */
220
+ /* Section 4: zod-like specification validation */
221
+ /* ------------------------------------------------------------------ */
222
+
223
+ /** Kinds of primitives understood by the built-in rule engine. */
224
+ export type rulekind = 'number' | 'string' | 'boolean' | 'enum';
225
+
226
+ /** One validation rule bound to a specification field. */
227
+ export type specrule = {
228
+ readonly key: keyof enginespec;
229
+ readonly kind: rulekind;
230
+ readonly min?: number;
231
+ readonly max?: number;
232
+ readonly pattern?: RegExp;
233
+ readonly values?: readonly string[];
234
+ readonly optional?: boolean;
235
+ readonly description: string;
236
+ };
237
+
238
+ /** Result of running validateSpec over a candidate specification. */
239
+ export type specvalidationresult = {
240
+ readonly valid: boolean;
241
+ readonly errors: readonly string[];
242
+ readonly warnings: readonly string[];
243
+ readonly normalized: enginespec | null;
244
+ };
245
+
246
+ /**
247
+ * Default rule table derived from enginelimits. It behaves like a small
248
+ * dependency-free schema: each entry describes bounds and shape for one
249
+ * field of enginespec and validateSpec walks the table collecting errors.
250
+ */
251
+ export const specschema: readonly specrule[] = [
252
+ { key: 'model', kind: 'string', pattern: /\S+/, description: 'non-empty processor model name' },
253
+ {
254
+ key: 'vcpus',
255
+ kind: 'number',
256
+ min: enginelimits.minvcpu,
257
+ max: enginelimits.maxvcpu,
258
+ description: 'vCPU count between 1 and 192',
259
+ },
260
+ {
261
+ key: 'ramgb',
262
+ kind: 'number',
263
+ min: enginelimits.minramgb,
264
+ max: enginelimits.maxramgb,
265
+ description: 'guest RAM in GB between 1 and 1024',
266
+ },
267
+ {
268
+ key: 'vramgb',
269
+ kind: 'number',
270
+ min: enginelimits.minvramgb,
271
+ max: enginelimits.maxvramgb,
272
+ description: 'virtualized VRAM in GB between 8 and 96',
273
+ },
274
+ {
275
+ key: 'mig',
276
+ kind: 'enum',
277
+ values: ['1g.24gb', '2g.48gb', '4g.96gb', 'off'],
278
+ description: 'MIG slicing profile',
279
+ },
280
+ {
281
+ key: 'runtime',
282
+ kind: 'enum',
283
+ values: ['qemu', 'firecracker', 'docker', 'gvisor'],
284
+ description: 'execution backend',
285
+ },
286
+ {
287
+ key: 'host',
288
+ kind: 'string',
289
+ pattern: /\S+/,
290
+ description: 'user chosen bind host, never defaulted',
291
+ },
292
+ {
293
+ key: 'port',
294
+ kind: 'number',
295
+ min: enginelimits.minport,
296
+ max: enginelimits.maxport,
297
+ description: 'port between 30000 and 59999',
298
+ },
299
+ {
300
+ key: 'metricsintervalms',
301
+ kind: 'number',
302
+ min: 100,
303
+ max: 3600000,
304
+ description: 'sampling interval in milliseconds',
305
+ },
306
+ ];
307
+
308
+ /**
309
+ * Validates a candidate specification against the rule table. The function
310
+ * is zod-like in spirit but has zero external dependencies: it type-checks
311
+ * each field, enforces numeric bounds, matches string patterns and rejects
312
+ * unknown enum values, then returns the errors, soft warnings and a frozen
313
+ * normalized copy when everything passes.
314
+ *
315
+ * @param spec Candidate specification; the const type parameter preserves
316
+ * literal inference for callers that pass object literals.
317
+ */
318
+ export function validateSpec<const T extends enginespec>(spec: T): specvalidationresult {
319
+ const errors: string[] = [];
320
+ const warnings: string[] = [];
321
+ try {
322
+ for (const rule of specschema) {
323
+ const value: unknown = (spec as Record<string, unknown>)[rule.key as string];
324
+ if (value === undefined) {
325
+ if (rule.optional !== true) {
326
+ errors.push(`${rule.key}: missing required field (${rule.description})`);
327
+ }
328
+ continue;
329
+ }
330
+ switch (rule.kind) {
331
+ case 'number': {
332
+ if (typeof value !== 'number' || !Number.isFinite(value)) {
333
+ errors.push(`${rule.key}: expected a finite number`);
334
+ break;
335
+ }
336
+ if (rule.min !== undefined && value < rule.min) {
337
+ errors.push(`${rule.key}: ${value} is below the minimum ${rule.min}`);
338
+ }
339
+ if (rule.max !== undefined && value > rule.max) {
340
+ errors.push(`${rule.key}: ${value} is above the maximum ${rule.max}`);
341
+ }
342
+ break;
343
+ }
344
+ case 'string': {
345
+ if (typeof value !== 'string') {
346
+ errors.push(`${rule.key}: expected a string`);
347
+ break;
348
+ }
349
+ if (rule.pattern !== undefined && !rule.pattern.test(value)) {
350
+ errors.push(`${rule.key}: fails pattern ${String(rule.pattern)} (${rule.description})`);
351
+ }
352
+ break;
353
+ }
354
+ case 'boolean': {
355
+ if (typeof value !== 'boolean') {
356
+ errors.push(`${rule.key}: expected a boolean`);
357
+ }
358
+ break;
359
+ }
360
+ case 'enum': {
361
+ if (typeof value !== 'string' || rule.values?.includes(value as string) !== true) {
362
+ errors.push(`${rule.key}: expected one of ${rule.values?.join(', ') ?? 'nothing'}`);
363
+ }
364
+ break;
365
+ }
366
+ default: {
367
+ errors.push(`${rule.key}: unknown rule kind`);
368
+ }
369
+ }
370
+ }
371
+ if (
372
+ typeof spec.vramgb === 'number' &&
373
+ typeof spec.ramgb === 'number' &&
374
+ spec.vramgb > spec.ramgb
375
+ ) {
376
+ warnings.push(
377
+ 'vramgb exceeds ramgb: legitimate for GPU-first layouts, confirm this is intended',
378
+ );
379
+ }
380
+ if (spec.mig === 'off' && typeof spec.vramgb === 'number' && spec.vramgb >= 96) {
381
+ warnings.push('vramgb of 96 GB without MIG slicing dedicates the whole device to one guest');
382
+ }
383
+ if (typeof spec.vcpus === 'number' && spec.vcpus > 64 && spec.runtime === 'firecracker') {
384
+ warnings.push(
385
+ 'firecracker boots fastest with small vCPU counts; large counts increase restore time',
386
+ );
387
+ }
388
+ if (errors.length > 0) {
389
+ return { valid: false, errors, warnings, normalized: null };
390
+ }
391
+ const normalized: enginespec = {
392
+ model: String(spec.model),
393
+ vcpus: Number(spec.vcpus),
394
+ ramgb: Number(spec.ramgb),
395
+ vramgb: Number(spec.vramgb),
396
+ mig: spec.mig,
397
+ runtime: spec.runtime,
398
+ host: String(spec.host),
399
+ port: Number(spec.port),
400
+ metricsintervalms: Number(spec.metricsintervalms),
401
+ };
402
+ return { valid: true, errors, warnings, normalized: Object.freeze(normalized) };
403
+ } catch (cause) {
404
+ return {
405
+ valid: false,
406
+ errors: [`validateSpec crashed: ${(cause as Error).message}`],
407
+ warnings,
408
+ normalized: null,
409
+ };
410
+ }
411
+ }
412
+
413
+ /* ------------------------------------------------------------------ */
414
+ /* Section 5: metrics types and InternalMemory store */
415
+ /* ------------------------------------------------------------------ */
416
+
417
+ /** One immutable metric sample. */
418
+ export type metricssample = {
419
+ readonly at: number;
420
+ readonly cpuutilization: number;
421
+ readonly memusedgb: number;
422
+ readonly memtotalgb: number;
423
+ readonly vramusedgb: number;
424
+ readonly vramtotalgb: number;
425
+ readonly iops: number;
426
+ };
427
+
428
+ /** Aggregate view over the stored samples of one engine. */
429
+ export type metricsaggregate = {
430
+ readonly count: number;
431
+ readonly cpuavg: number;
432
+ readonly cpupeak: number;
433
+ readonly memavggb: number;
434
+ readonly newest: metricssample | null;
435
+ };
436
+
437
+ /**
438
+ * Map-based internal memory store used by every engine instance. Gauges,
439
+ * counters, labels and rolling samples live in plain Map containers which
440
+ * guarantees deterministic iteration, cheap snapshots and no binding to any
441
+ * runtime-specific global. The store also owns a WeakMap side table for
442
+ * ephemeral probes that must never keep engines alive.
443
+ */
444
+ export class InternalMemory {
445
+ #gauges: Map<string, number>;
446
+ #counters: Map<string, number>;
447
+ #labels: Map<string, string>;
448
+ #series: Map<string, metricssample[]>;
449
+ #probes: WeakMap<object, metricssample>;
450
+
451
+ constructor() {
452
+ this.#gauges = new Map<string, number>();
453
+ this.#counters = new Map<string, number>();
454
+ this.#labels = new Map<string, string>();
455
+ this.#series = new Map<string, metricssample[]>();
456
+ this.#probes = new WeakMap<object, metricssample>();
457
+ }
458
+
459
+ /** Number of distinct gauges currently registered. */
460
+ get gaugecount(): number {
461
+ return this.#gauges.size;
462
+ }
463
+
464
+ /** Private accessor that folds counters and gauges into one size metric. */
465
+ get #totalslots(): number {
466
+ return this.#gauges.size + this.#counters.size + this.#labels.size + this.#series.size;
467
+ }
468
+
469
+ /** Reports how many storage slots are live across all containers. */
470
+ get slotcount(): number {
471
+ return this.#totalslots;
472
+ }
473
+
474
+ /** Sets a gauge value, creating it when missing. */
475
+ setgauge(name: string, value: number): this {
476
+ try {
477
+ if (!Number.isFinite(value)) {
478
+ throw new TypeError(`gauge ${name} must be a finite number`);
479
+ }
480
+ this.#gauges.set(name, value);
481
+ return this;
482
+ } catch (cause) {
483
+ throw new engineerror('setgauge failed', { cause: cause as Error });
484
+ }
485
+ }
486
+
487
+ /** Reads a gauge, returning the fallback when the gauge is absent. */
488
+ readgauge(name: string, fallback = 0): number {
489
+ return this.#gauges.get(name) ?? fallback;
490
+ }
491
+
492
+ /** Increments a counter by delta (default 1) and returns the new total. */
493
+ bump(name: string, delta = 1): number {
494
+ const next = (this.#counters.get(name) ?? 0) + delta;
495
+ this.#counters.set(name, next);
496
+ return next;
497
+ }
498
+
499
+ /** Reads a counter without mutating it. */
500
+ readcounter(name: string): number {
501
+ return this.#counters.get(name) ?? 0;
502
+ }
503
+
504
+ /** Attaches a human readable label for observability tooling. */
505
+ setlabel(name: string, value: string): this {
506
+ this.#labels.set(name, value);
507
+ return this;
508
+ }
509
+
510
+ /** Returns a frozen copy of all labels. */
511
+ readlabels(): Readonly<Record<string, string>> {
512
+ return Object.freeze({ ...Object.fromEntries(this.#labels) });
513
+ }
514
+
515
+ /** Pushes a sample into the rolling series of one engine. */
516
+ pushsample(engineid: string, sample: metricssample, keep = 720): number {
517
+ try {
518
+ const bucket = this.#series.get(engineid) ?? [];
519
+ bucket.push(sample);
520
+ while (bucket.length > keep) {
521
+ bucket.shift();
522
+ }
523
+ this.#series.set(engineid, bucket);
524
+ return bucket.length;
525
+ } catch (cause) {
526
+ throw new engineerror('pushsample failed', { cause: cause as Error });
527
+ }
528
+ }
529
+
530
+ /** Computes cpu and memory averages plus peaks for one engine. */
531
+ aggregate(engineid: string): metricsaggregate {
532
+ const bucket = this.#series.get(engineid) ?? [];
533
+ if (bucket.length === 0) {
534
+ return { count: 0, cpuavg: 0, cpupeak: 0, memavggb: 0, newest: null };
535
+ }
536
+ let cpusum = 0;
537
+ let cpupeak = 0;
538
+ let memsum = 0;
539
+ for (const sample of bucket) {
540
+ cpusum += sample.cpuutilization;
541
+ cpupeak = Math.max(cpupeak, sample.cpuutilization);
542
+ memsum += sample.memusedgb;
543
+ }
544
+ return {
545
+ count: bucket.length,
546
+ cpuavg: Number((cpusum / bucket.length).toFixed(4)),
547
+ cpupeak,
548
+ memavggb: Number((memsum / bucket.length).toFixed(4)),
549
+ newest: bucket[bucket.length - 1] ?? null,
550
+ };
551
+ }
552
+
553
+ /** Stores an ephemeral probe keyed by a weak object reference. */
554
+ attachprobe(owner: object, sample: metricssample): void {
555
+ this.#probes.set(owner, sample);
556
+ }
557
+
558
+ /** Reads an ephemeral probe; returns null when the owner is gone. */
559
+ readprobe(owner: object): metricssample | null {
560
+ return this.#probes.get(owner) ?? null;
561
+ }
562
+
563
+ /** Drops every container, leaving the store empty but reusable. */
564
+ clear(): void {
565
+ this.#gauges.clear();
566
+ this.#counters.clear();
567
+ this.#labels.clear();
568
+ this.#series.clear();
569
+ }
570
+ }
571
+
572
+ /* ------------------------------------------------------------------ */
573
+ /* Section 6: disposable MetricsStore for using declarations */
574
+ /* ------------------------------------------------------------------ */
575
+
576
+ /**
577
+ * Disposable metrics facade. Instances are designed for explicit resource
578
+ * management: `using store = new MetricsStore()` flushes the snapshot to
579
+ * disk on scope exit through Symbol.dispose, while `await using` performs
580
+ * the same through Symbol.asyncDispose after letting pending samples
581
+ * settle. Both disposers are idempotent so double disposal is harmless.
582
+ * The v2 orchestrator subclasses this store (sandboxmetrics) so the whole
583
+ * engine keeps exactly one metrics component.
584
+ */
585
+ export class MetricsStore {
586
+ #memory: InternalMemory;
587
+ #engineid: string;
588
+ #snapshotdir: string | null;
589
+ #disposed: boolean;
590
+
591
+ constructor(engineid: string, snapshotdir?: string) {
592
+ this.#memory = new InternalMemory();
593
+ this.#engineid = engineid;
594
+ this.#snapshotdir = snapshotdir ?? null;
595
+ this.#disposed = false;
596
+ }
597
+
598
+ /** Direct access to the underlying InternalMemory containers. */
599
+ get memory(): InternalMemory {
600
+ return this.#memory;
601
+ }
602
+
603
+ /** Engine identifier this store is bound to. */
604
+ get engineid(): string {
605
+ return this.#engineid;
606
+ }
607
+
608
+ /** True once a disposer has run for this instance. */
609
+ get disposed(): boolean {
610
+ return this.#disposed;
611
+ }
612
+
613
+ /** Records a sample into the rolling series. */
614
+ record(sample: metricssample): this {
615
+ if (this.#disposed) {
616
+ throw new engineerror('MetricsStore is disposed and cannot record');
617
+ }
618
+ this.#memory.pushsample(this.#engineid, sample);
619
+ this.#memory.setgauge('lastcpu', sample.cpuutilization);
620
+ this.#memory.setgauge('lastmemgb', sample.memusedgb);
621
+ return this;
622
+ }
623
+
624
+ /** Persists the current aggregate snapshot to the configured directory. */
625
+ flush(): string | null {
626
+ try {
627
+ if (this.#snapshotdir === null) {
628
+ return null;
629
+ }
630
+ const aggregate = this.#memory.aggregate(this.#engineid);
631
+ const payload = JSON.stringify(
632
+ { engineid: this.#engineid, at: Date.now(), aggregate, labels: this.#memory.readlabels() },
633
+ null,
634
+ 2,
635
+ );
636
+ mkdirSync(this.#snapshotdir, { recursive: true });
637
+ const file = join(this.#snapshotdir, `${this.#engineid}.metrics.json`);
638
+ writeFileSync(file, payload, 'utf8');
639
+ return file;
640
+ } catch (cause) {
641
+ throw new engineerror('MetricsStore.flush failed', { cause: cause as Error });
642
+ }
643
+ }
644
+
645
+ /** Loads a previously persisted snapshot, returning null when missing. */
646
+ restore(): Record<string, unknown> | null {
647
+ try {
648
+ if (this.#snapshotdir === null) {
649
+ return null;
650
+ }
651
+ const file = join(this.#snapshotdir, `${this.#engineid}.metrics.json`);
652
+ const raw = readFileSync(file, 'utf8');
653
+ return JSON.parse(raw) as Record<string, unknown>;
654
+ } catch {
655
+ return null;
656
+ }
657
+ }
658
+
659
+ /** Synchronous disposer used by `using store = new MetricsStore(...)`. */
660
+ [Symbol.dispose](): void {
661
+ if (this.#disposed) {
662
+ return;
663
+ }
664
+ try {
665
+ this.flush();
666
+ } catch {
667
+ /* persistence failures must never mask scope exit */
668
+ } finally {
669
+ this.#disposed = true;
670
+ }
671
+ }
672
+
673
+ /** Asynchronous disposer used by `await using` declarations. */
674
+ async [Symbol.asyncDispose](): Promise<void> {
675
+ this[Symbol.dispose]();
676
+ }
677
+ }
678
+
679
+ /* ------------------------------------------------------------------ */
680
+ /* Section 7: typed event bus — the single bus of the v2 merge */
681
+ /* ------------------------------------------------------------------ */
682
+
683
+ /**
684
+ * Map of every event topic emitted by the engine to its payload type.
685
+ *
686
+ * The v2 merge collapses the three buses of the pool (the v5 enginebus,
687
+ * the Meta TypedEventBus and the Meta SaddleEventBus) into this single
688
+ * topology: the original engine:* and metrics:* topics plus the full
689
+ * sandbox:* and vm plane surface (vm, vcpu, vram, gpu, sriov, passage,
690
+ * mttg, docker, qemu, health, autoscale, numa, migration, snapshot,
691
+ * checkpoint, config, plugin, rbac, audit, leader, quota, preemption,
692
+ * drain and system) that orchestrator.ts publishes through sandboxevents,
693
+ * a subclass of enginebus. no second bus exists anywhere in the library.
694
+ */
695
+ export type enginetopics = {
696
+ readonly 'engine:created': { readonly engineid: string; readonly at: number };
697
+ readonly 'engine:starting': { readonly engineid: string; readonly spec: enginespec };
698
+ readonly 'engine:running': { readonly engineid: string; readonly endpoint: engineendpoint };
699
+ readonly 'engine:stopped': { readonly engineid: string; readonly uptimems: number };
700
+ readonly 'engine:error': { readonly engineid: string; readonly error: Error };
701
+ readonly 'metrics:sample': { readonly engineid: string; readonly sample: metricssample };
702
+ readonly 'engine:statechanged': {
703
+ readonly engineid: string;
704
+ readonly from: enginestate;
705
+ readonly to: enginestate;
706
+ };
707
+ readonly 'sandbox:created': {
708
+ readonly id: string;
709
+ readonly runtime: string;
710
+ readonly host: string;
711
+ readonly ports: readonly { readonly host: number; readonly container: number }[];
712
+ };
713
+ readonly 'sandbox:started': {
714
+ readonly id: string;
715
+ readonly runtime: string;
716
+ readonly bootms: number;
717
+ };
718
+ readonly 'sandbox:stopped': { readonly id: string; readonly reason: string };
719
+ readonly 'sandbox:snapshotted': { readonly id: string; readonly file: string };
720
+ readonly 'sandbox:restored': { readonly id: string; readonly snapshotfile: string };
721
+ readonly 'sandbox:destroyed': { readonly id: string };
722
+ readonly 'sandbox:pooled': { readonly size: number };
723
+ readonly 'sandbox:error': {
724
+ readonly id?: string;
725
+ readonly phase: string;
726
+ readonly message: string;
727
+ };
728
+ readonly 'vm:created': { readonly vmid: string; readonly tenantid: string };
729
+ readonly 'vm:started': { readonly vmid: string; readonly pid: number };
730
+ readonly 'vm:stopped': { readonly vmid: string; readonly reason: string };
731
+ readonly 'vm:error': { readonly vmid: string; readonly error: string };
732
+ readonly 'vm:phase': { readonly vmid: string; readonly to: string };
733
+ readonly 'vcpu:scheduled': {
734
+ readonly vmid: string;
735
+ readonly vcpuid: string;
736
+ readonly cpu: number;
737
+ };
738
+ readonly 'sched:overcommitwarn': {
739
+ readonly vmid: string;
740
+ readonly requested: number;
741
+ readonly host: number;
742
+ readonly overcommit: number;
743
+ };
744
+ readonly 'vram:adjusted': {
745
+ readonly vmid: string;
746
+ readonly targetmib: number;
747
+ readonly actualmib: number;
748
+ };
749
+ readonly 'gpu:assigned': {
750
+ readonly vmid: string;
751
+ readonly gpuid: string;
752
+ readonly vfid?: string;
753
+ };
754
+ readonly 'gpu:released': { readonly gpuid: string; readonly vmid: string };
755
+ readonly 'sriov:vfcreated': { readonly pf: string; readonly vfid: string };
756
+ readonly 'passage:routecreated': {
757
+ readonly id: string;
758
+ readonly srcvm: string;
759
+ readonly dstvm: string;
760
+ readonly protocol: string;
761
+ };
762
+ readonly 'mttg:jobdone': { readonly jobid: string; readonly durationms: number };
763
+ readonly 'mttg:enqueued': {
764
+ readonly jobid: string;
765
+ readonly tenant: string;
766
+ readonly qos: string;
767
+ };
768
+ readonly 'mttg:preempted': { readonly incoming: string; readonly preempted: readonly string[] };
769
+ readonly 'docker:attached': {
770
+ readonly vmid: string;
771
+ readonly bridge: string;
772
+ readonly ipv4: string;
773
+ };
774
+ readonly 'qemu:exit': { readonly vmid: string; readonly code: number | null };
775
+ readonly 'qemu:versionmismatch': { readonly expected: string; readonly got: string };
776
+ readonly 'health:change': {
777
+ readonly checkid: string;
778
+ readonly old: string;
779
+ readonly new: string;
780
+ };
781
+ readonly 'autoscale:trigger': {
782
+ readonly policyid: string;
783
+ readonly action: string;
784
+ readonly count: number;
785
+ };
786
+ readonly 'numa:rebalance': { readonly moves: number; readonly from: number; readonly to: number };
787
+ readonly 'migration:progress': {
788
+ readonly jobid: string;
789
+ readonly vmid: string;
790
+ readonly state: string;
791
+ readonly progress: number;
792
+ };
793
+ readonly 'snapshot:created': { readonly snapshotid: string; readonly vmid: string };
794
+ readonly 'checkpoint:created': {
795
+ readonly checkpointid: string;
796
+ readonly vmid: string;
797
+ readonly method: string;
798
+ };
799
+ readonly 'config:reloaded': { readonly file: string };
800
+ readonly 'plugin:loaded': { readonly pluginid: string };
801
+ readonly 'plugin:unloaded': { readonly pluginid: string };
802
+ readonly 'rbac:denied': { readonly userid: string; readonly action: string };
803
+ readonly 'audit:entry': {
804
+ readonly actor: string;
805
+ readonly action: string;
806
+ readonly target: string;
807
+ readonly result: string;
808
+ };
809
+ readonly 'leader:changed': { readonly leader: string; readonly term: number };
810
+ readonly 'quota:set': {
811
+ readonly tenantid: string;
812
+ readonly vcpu: number;
813
+ readonly vrammib: number;
814
+ readonly gpu: number;
815
+ };
816
+ readonly 'node:drained': {
817
+ readonly labelkey: string;
818
+ readonly labelvalue: string;
819
+ readonly drained: readonly string[];
820
+ };
821
+ readonly 'system:error': { readonly kind: string; readonly message: string };
822
+ readonly 'otel:exporterstarted': { readonly host: string; readonly port: number };
823
+ };
824
+
825
+ /** Union of all topic names; template literal types keep it extensible. */
826
+ export type enginetopicname = keyof enginetopics;
827
+
828
+ /**
829
+ * Strongly typed observer bus built on node:events EventEmitter. Publish and
830
+ * subscribe are generic over the topic map so listeners receive exactly the
831
+ * payload type of the topic they choose; the underlying EventEmitter is kept
832
+ * private so external code cannot bypass typing. This class is the single
833
+ * bus of the engine: orchestrator.ts extends it (sandboxevents) and every
834
+ * subsystem publishes here instead of creating its own emitter.
835
+ */
836
+ export class enginebus {
837
+ #emitter: EventEmitter;
838
+
839
+ constructor() {
840
+ this.#emitter = new EventEmitter();
841
+ this.#emitter.setMaxListeners(0);
842
+ }
843
+
844
+ /** Subscribes a typed listener to one topic. */
845
+ subscribe<t extends enginetopicname>(
846
+ topic: t,
847
+ listener: (payload: enginetopics[t]) => void,
848
+ ): this {
849
+ this.#emitter.on(topic, listener as (...args: unknown[]) => void);
850
+ return this;
851
+ }
852
+
853
+ /** Removes a previously subscribed listener. */
854
+ unsubscribe<t extends enginetopicname>(
855
+ topic: t,
856
+ listener: (payload: enginetopics[t]) => void,
857
+ ): this {
858
+ this.#emitter.off(topic, listener as (...args: unknown[]) => void);
859
+ return this;
860
+ }
861
+
862
+ /** Publishes one event; the boolean mirrors EventEmitter emit results. */
863
+ publish<t extends enginetopicname>(topic: t, payload: enginetopics[t]): boolean {
864
+ return this.#emitter.emit(topic, payload);
865
+ }
866
+
867
+ /** Waits until one topic fires, resolving with its payload. */
868
+ waitfor<t extends enginetopicname>(topic: t): Promise<enginetopics[t]> {
869
+ return new Promise<enginetopics[t]>((resolve) => {
870
+ this.#emitter.once(topic, (payload: enginetopics[t]) => {
871
+ resolve(payload);
872
+ });
873
+ });
874
+ }
875
+
876
+ /** Returns how many listeners are attached to one topic. */
877
+ listenercount(topic: enginetopicname): number {
878
+ return this.#emitter.listenerCount(topic);
879
+ }
880
+ }
881
+
882
+ /** Process-wide bus shared by factories in this module. */
883
+ export const engineeventbus = new enginebus();
884
+
885
+ /* ------------------------------------------------------------------ */
886
+ /* Section 8: error type and safe execution helpers */
887
+ /* ------------------------------------------------------------------ */
888
+
889
+ /** Error thrown by every engine subsystem with an optional cause chain. */
890
+ export class engineerror extends Error {
891
+ /** Machine readable subsystem tag. */
892
+ readonly subsystem: string;
893
+
894
+ constructor(message: string, options?: { cause?: Error; subsystem?: string }) {
895
+ super(message, options);
896
+ this.name = 'engineerror';
897
+ this.subsystem = options?.subsystem ?? 'core';
898
+ }
899
+ }
900
+
901
+ /** Outcome shape returned by safecall. */
902
+ export type safeoutcome<t> =
903
+ | { readonly ok: true; readonly value: t }
904
+ | { readonly ok: false; readonly error: Error };
905
+
906
+ /**
907
+ * Runs an action inside a try/catch catcher and reports the outcome as a
908
+ * discriminated union instead of throwing, which lets library callers decide
909
+ * how failures surface. The fallback runs only when the action throws.
910
+ */
911
+ export function safecall<t>(label: string, action: () => t, fallback?: () => t): safeoutcome<t> {
912
+ try {
913
+ return { ok: true, value: action() };
914
+ } catch (cause) {
915
+ const error =
916
+ cause instanceof Error
917
+ ? cause
918
+ : new engineerror(`safecall ${label} failed`, { cause: cause as Error });
919
+ engineeventbus.publish('engine:error', { engineid: label, error });
920
+ if (fallback !== undefined) {
921
+ try {
922
+ return { ok: true, value: fallback() };
923
+ } catch (inner) {
924
+ return {
925
+ ok: false,
926
+ error: new engineerror(`safecall ${label} fallback failed`, { cause: inner as Error }),
927
+ };
928
+ }
929
+ }
930
+ return { ok: false, error };
931
+ }
932
+ }
933
+
934
+ /* ------------------------------------------------------------------ */
935
+ /* Section 9: snapshot, health report and engine facade */
936
+ /* ------------------------------------------------------------------ */
937
+
938
+ /** Point-in-time snapshot of an engine. */
939
+ export type enginesnapshot = {
940
+ readonly engineid: string;
941
+ readonly state: enginestate;
942
+ readonly spec: enginespec;
943
+ readonly uptimems: number;
944
+ readonly metrics: metricsaggregate;
945
+ readonly versions: typeof engineversions;
946
+ };
947
+
948
+ /** Health report produced by periodic probing. */
949
+ export type healthreport = {
950
+ readonly engineid: string;
951
+ readonly healthy: boolean;
952
+ readonly state: enginestate;
953
+ readonly checks: readonly {
954
+ readonly name: string;
955
+ readonly passed: boolean;
956
+ readonly detail: string;
957
+ }[];
958
+ };
959
+
960
+ /**
961
+ * Facade object returned by createVirtualEngine. The class keeps its state
962
+ * machine private and exposes only intentful operations, emitting typed
963
+ * events on every transition so orchestrators can react without polling.
964
+ */
965
+ export class VirtualEngine {
966
+ #id: string;
967
+ #spec: enginespec;
968
+ #state: enginestate;
969
+ #memory: InternalMemory;
970
+ #bus: enginebus;
971
+ #createdat: number;
972
+ #startedat: number | null;
973
+ #endpoint: engineendpoint | null;
974
+
975
+ constructor(spec: enginespec, bus: enginebus) {
976
+ this.#id = randomUUID();
977
+ this.#spec = spec;
978
+ this.#state = 'created';
979
+ this.#memory = new InternalMemory();
980
+ this.#bus = bus;
981
+ this.#createdat = Date.now();
982
+ this.#startedat = null;
983
+ this.#endpoint = null;
984
+ this.#memory.setlabel('model', spec.model);
985
+ this.#memory.setlabel('runtime', spec.runtime);
986
+ }
987
+
988
+ /** Unique identifier of this engine instance. */
989
+ get id(): string {
990
+ return this.#id;
991
+ }
992
+
993
+ /** Frozen specification the engine was created with. */
994
+ get spec(): enginespec {
995
+ return this.#spec;
996
+ }
997
+
998
+ /** Current lifecycle state. */
999
+ get state(): enginestate {
1000
+ return this.#state;
1001
+ }
1002
+
1003
+ /** Milliseconds elapsed since creation. */
1004
+ get uptimems(): number {
1005
+ return Date.now() - this.#createdat;
1006
+ }
1007
+
1008
+ /** Endpoint after a successful start, otherwise null. */
1009
+ get endpoint(): engineendpoint | null {
1010
+ return this.#endpoint;
1011
+ }
1012
+
1013
+ /** Internal metrics store of this engine. */
1014
+ get memory(): InternalMemory {
1015
+ return this.#memory;
1016
+ }
1017
+
1018
+ #transition(to: enginestate): void {
1019
+ const from = this.#state;
1020
+ this.#state = to;
1021
+ this.#bus.publish('engine:statechanged', { engineid: this.#id, from, to });
1022
+ }
1023
+
1024
+ /** Moves the engine to running, binding the resolved endpoint. */
1025
+ start(): engineendpoint {
1026
+ try {
1027
+ if (this.#state === 'running') {
1028
+ throw new engineerror('engine is already running');
1029
+ }
1030
+ this.#transition('starting');
1031
+ this.#bus.publish('engine:starting', { engineid: this.#id, spec: this.#spec });
1032
+ this.#endpoint = buildEndpoint(this.#spec.host, this.#spec.port);
1033
+ this.#startedat = Date.now();
1034
+ this.#memory.setgauge('port', this.#endpoint.port);
1035
+ this.#memory.bump('starts');
1036
+ this.#transition('running');
1037
+ this.#bus.publish('engine:running', { engineid: this.#id, endpoint: this.#endpoint });
1038
+ return this.#endpoint;
1039
+ } catch (cause) {
1040
+ this.#transition('degraded');
1041
+ const error =
1042
+ cause instanceof Error ? cause : new engineerror('start failed', { cause: cause as Error });
1043
+ this.#bus.publish('engine:error', { engineid: this.#id, error });
1044
+ throw error;
1045
+ }
1046
+ }
1047
+
1048
+ /** Stops a running engine and publishes the measured uptime. */
1049
+ stop(): void {
1050
+ if (this.#state === 'stopped') {
1051
+ return;
1052
+ }
1053
+ const started = this.#startedat ?? this.#createdat;
1054
+ this.#memory.bump('stops');
1055
+ this.#transition('stopped');
1056
+ this.#bus.publish('engine:stopped', { engineid: this.#id, uptimems: Date.now() - started });
1057
+ }
1058
+
1059
+ /** Builds an immutable snapshot of the engine state. */
1060
+ snapshot(): enginesnapshot {
1061
+ return Object.freeze({
1062
+ engineid: this.#id,
1063
+ state: this.#state,
1064
+ spec: this.#spec,
1065
+ uptimems: this.uptimems,
1066
+ metrics: this.#memory.aggregate(this.#id),
1067
+ versions: engineversions,
1068
+ });
1069
+ }
1070
+
1071
+ /** Runs structural health checks over spec, state and metrics. */
1072
+ healthcheck(): healthreport {
1073
+ const checks: { name: string; passed: boolean; detail: string }[] = [];
1074
+ const validation = validateSpec(this.#spec);
1075
+ checks.push({
1076
+ name: 'spec',
1077
+ passed: validation.valid,
1078
+ detail: validation.valid
1079
+ ? 'specification passes the rule table'
1080
+ : validation.errors.join('; '),
1081
+ });
1082
+ checks.push({
1083
+ name: 'state',
1084
+ passed: this.#state === 'running' || this.#state === 'created',
1085
+ detail: `current state is ${this.#state}`,
1086
+ });
1087
+ checks.push({
1088
+ name: 'endpoint',
1089
+ passed: this.#state !== 'running' || this.#endpoint !== null,
1090
+ detail:
1091
+ this.#endpoint === null
1092
+ ? 'no endpoint bound'
1093
+ : `bound to ${this.#endpoint.host}:${this.#endpoint.port}`,
1094
+ });
1095
+ checks.push({
1096
+ name: 'samples',
1097
+ passed: true,
1098
+ detail: `${this.#memory.aggregate(this.#id).count} samples retained`,
1099
+ });
1100
+ const healthy = checks.every((check) => check.passed);
1101
+ return Object.freeze({ engineid: this.#id, healthy, state: this.#state, checks });
1102
+ }
1103
+ }
1104
+
1105
+ /* ------------------------------------------------------------------ */
1106
+ /* Section 10: registry and main factory */
1107
+ /* ------------------------------------------------------------------ */
1108
+
1109
+ /** Registry of live engines keyed by engine id. */
1110
+ export const engineRegistry: ReadonlyMap<string, VirtualEngine> = new Map<string, VirtualEngine>();
1111
+
1112
+ /** Ephemeral health probes; WeakMap keeps engines garbage collectable. */
1113
+ const healthprobes = new WeakMap<VirtualEngine, healthreport>();
1114
+
1115
+ /**
1116
+ * Creates a fully wired virtual engine from user options. The factory
1117
+ * resolves the host (user choice only), draws a random port in the
1118
+ * 30000-59999 range when none is given, validates the merged specification
1119
+ * with validateSpec, registers the instance in engineRegistry and emits the
1120
+ * engine:created topic. Failures are converted to engineerror instances so
1121
+ * callers always see a typed cause chain.
1122
+ *
1123
+ * @param options Partial specification; only the host is mandatory because
1124
+ * the library refuses to assume any default address.
1125
+ */
1126
+ export function createVirtualEngine(options: engineoptions): VirtualEngine {
1127
+ try {
1128
+ const host = resolveHost(options.host);
1129
+ const candidate: enginespec = {
1130
+ model: options.model ?? 'AMD EPYC 9965',
1131
+ vcpus: options.vcpus ?? 8,
1132
+ ramgb: options.ramgb ?? 16,
1133
+ vramgb: options.vramgb ?? 24,
1134
+ mig: options.mig ?? '1g.24gb',
1135
+ runtime: options.runtime ?? 'qemu',
1136
+ host,
1137
+ port: randomPort(options.port),
1138
+ metricsintervalms: options.metricsintervalms ?? 1000,
1139
+ };
1140
+ const validation = validateSpec(candidate);
1141
+ if (!validation.valid || validation.normalized === null) {
1142
+ throw new engineerror(`invalid engine specification: ${validation.errors.join('; ')}`);
1143
+ }
1144
+ const engine = new VirtualEngine(validation.normalized, engineeventbus);
1145
+ (engineRegistry as Map<string, VirtualEngine>).set(engine.id, engine);
1146
+ engine.memory.setgauge('vcpus', validation.normalized.vcpus);
1147
+ engine.memory.setgauge('ramgb', validation.normalized.ramgb);
1148
+ engine.memory.setgauge('vramgb', validation.normalized.vramgb);
1149
+ engineeventbus.publish('engine:created', { engineid: engine.id, at: Date.now() });
1150
+ return engine;
1151
+ } catch (cause) {
1152
+ if (cause instanceof engineerror) {
1153
+ throw cause;
1154
+ }
1155
+ throw new engineerror('createVirtualEngine failed', { cause: cause as Error });
1156
+ }
1157
+ }
1158
+
1159
+ /** Registers a fresh health probe for an engine and returns it. */
1160
+ export function probeengine(engine: VirtualEngine): healthreport {
1161
+ const report = engine.healthcheck();
1162
+ healthprobes.set(engine, report);
1163
+ return report;
1164
+ }
1165
+
1166
+ /** Reads the latest health probe recorded for an engine, if any. */
1167
+ export function lastprobe(engine: VirtualEngine): healthreport | null {
1168
+ return healthprobes.get(engine) ?? null;
1169
+ }
1170
+
1171
+ /** Removes an engine from the registry; returns true when it existed. */
1172
+ export function disposeengine(engineid: string): boolean {
1173
+ return (engineRegistry as Map<string, VirtualEngine>).delete(engineid);
1174
+ }
1175
+
1176
+ /* ------------------------------------------------------------------ */
1177
+ /* Section 11: sampling loop helper */
1178
+ /* ------------------------------------------------------------------ */
1179
+
1180
+ /** Handle returned by startsampling; disposable for `using` blocks. */
1181
+ export type samplinghandle = { readonly stop: () => void };
1182
+
1183
+ /**
1184
+ * Starts a periodic sampling loop that fabricates metric samples with the
1185
+ * node:crypto random generator and records them into the engine metrics
1186
+ * store, emitting a metrics:sample event per iteration. The returned handle
1187
+ * implements Symbol.dispose so it composes with `using` declarations.
1188
+ */
1189
+ export function startsampling(
1190
+ engine: VirtualEngine,
1191
+ store: MetricsStore,
1192
+ ): samplinghandle & Disposable {
1193
+ let _tick = 0;
1194
+ const total = engine.spec.ramgb;
1195
+ const vtotal = engine.spec.vramgb;
1196
+ const timer = setInterval(() => {
1197
+ _tick += 1;
1198
+ const sample: metricssample = {
1199
+ at: Date.now(),
1200
+ cpuutilization: Number((randomInt(5, 95) + Math.random()).toFixed(4)),
1201
+ memusedgb: Number((total * (randomInt(20, 80) / 100)).toFixed(3)),
1202
+ memtotalgb: total,
1203
+ vramusedgb: Number((vtotal * (randomInt(10, 90) / 100)).toFixed(3)),
1204
+ vramtotalgb: vtotal,
1205
+ iops: randomInt(1000, 250000),
1206
+ };
1207
+ store.record(sample);
1208
+ engineeventbus.publish('metrics:sample', { engineid: engine.id, sample });
1209
+ }, engine.spec.metricsintervalms);
1210
+ const handle = {
1211
+ stop: () => {
1212
+ clearInterval(timer);
1213
+ },
1214
+ [Symbol.dispose]: () => {
1215
+ clearInterval(timer);
1216
+ },
1217
+ };
1218
+ return handle;
1219
+ }
1220
+
1221
+ /* ------------------------------------------------------------------ */
1222
+ /* Section 12: plan planner (absorbed from architect.ts) */
1223
+ /* ------------------------------------------------------------------ */
1224
+
1225
+ /**
1226
+ * GPU mode of a plan. this mirrors the GpuMode enum of forge.hpp (the C++
1227
+ * control plane) and stays intentionally distinct from the runtime gpu
1228
+ * assignment modes of orchestrator.ts (none/passthrough/vgpu/mdev).
1229
+ */
1230
+ export type plangpumode = 'vfio' | 'vgpu' | 'mig' | 'virtio' | 'none';
1231
+
1232
+ /** Declarative machine plan consumed by the argv renderers below. */
1233
+ export type plan = {
1234
+ readonly name: string;
1235
+ readonly cpu: string;
1236
+ readonly gpu: string;
1237
+ readonly sockets: number;
1238
+ readonly dies: number;
1239
+ readonly cores: number;
1240
+ readonly threads: 1 | 2;
1241
+ readonly vcpus: number;
1242
+ readonly memorygib: number;
1243
+ readonly vramgib: number;
1244
+ readonly overcommit: number;
1245
+ readonly gpumode: plangpumode;
1246
+ readonly mttg: boolean;
1247
+ readonly mttgthreads: number;
1248
+ };
1249
+
1250
+ /**
1251
+ * Default plan: a desktop zen5 lab (9950X3D with two CCDs) paired with an
1252
+ * RTX 5090, 65536 multiplexed MTTG threads and a 4x cpu overcommit.
1253
+ */
1254
+ export const defaultplan = {
1255
+ name: 'aether-lab',
1256
+ cpu: 'AMD Ryzen 9 9950X3D',
1257
+ gpu: 'NVIDIA GeForce RTX 5090',
1258
+ sockets: 1,
1259
+ dies: 2,
1260
+ cores: 8,
1261
+ threads: 2,
1262
+ vcpus: 16,
1263
+ memorygib: 64,
1264
+ vramgib: 32,
1265
+ overcommit: 4,
1266
+ gpumode: 'vfio',
1267
+ mttg: true,
1268
+ mttgthreads: 65536,
1269
+ } as const satisfies plan;
1270
+
1271
+ /**
1272
+ * Returns the topology product of a plan (sockets x dies x cores x
1273
+ * threads); distinct from solvetopology of virtualcpu.ts which maps a
1274
+ * processor spec to its physical package view.
1275
+ */
1276
+ export function plantopology(candidate: plan): number {
1277
+ return candidate.sockets * candidate.dies * candidate.cores * candidate.threads;
1278
+ }
1279
+
1280
+ /**
1281
+ * Renders the lean qemu argv of a plan: maxcpus headroom, hotplug memory
1282
+ * slots (maxmem), topology-aware -smp, the mttg thread count exported
1283
+ * through -fw_cfg, and per-gpu-mode device selection. the complete
1284
+ * "turbo" argv (TDX/SEV/vfio romfile/venus) lives in buildqemucmd of
1285
+ * virtualization.ts; the runtime strategy argv lives in orchestrator.ts.
1286
+ */
1287
+ export function qemuargv(candidate: plan): readonly string[] {
1288
+ const maxcpus = Math.max(candidate.vcpus, plantopology(candidate));
1289
+ const args: string[] = [
1290
+ 'qemu-system-x86_64',
1291
+ '-nodefaults',
1292
+ '-machine',
1293
+ 'q35,accel=kvm,kernel-irqchip=split,hpet=off',
1294
+ '-cpu',
1295
+ 'host,kvm=on,l3-cache=on,topoext=on,+x2apic',
1296
+ '-smp',
1297
+ `cpus=${Math.min(candidate.vcpus, plantopology(candidate))},sockets=${candidate.sockets},dies=${candidate.dies},cores=${candidate.cores},threads=${candidate.threads},maxcpus=${maxcpus}`,
1298
+ '-m',
1299
+ `${candidate.memorygib}G,slots=4,maxmem=${Math.max(candidate.memorygib * 2, candidate.memorygib + 32)}G`,
1300
+ '-name',
1301
+ `${candidate.name},debug-threads=on`,
1302
+ '-nographic',
1303
+ '-serial',
1304
+ 'mon:stdio',
1305
+ '-device',
1306
+ 'virtio-balloon-pci,deflate-on-oom=on,free-page-reporting=on',
1307
+ '-device',
1308
+ 'virtio-net-pci,netdev=n0,mq=on,vectors=10',
1309
+ '-netdev',
1310
+ 'tap,id=n0,vhost=on,queues=4,script=no,downscript=no',
1311
+ ];
1312
+ if (candidate.gpumode === 'vfio') {
1313
+ args.push('-device', 'vfio-pci,host=01:00.0,multifunction=on,x-vga=on', '-vga', 'none');
1314
+ } else if (candidate.gpumode === 'virtio') {
1315
+ args.push('-device', 'virtio-gpu-gl,hostmem=8G,blob=on,venus=on');
1316
+ }
1317
+ if (candidate.mttg) {
1318
+ args.push('-fw_cfg', `name=opt/aetherforge/mttg,string=${candidate.mttgthreads}`);
1319
+ }
1320
+ return args;
1321
+ }
1322
+
1323
+ /** renders the plan argv as a copy-pasteable shell command. */
1324
+ export function qemucommand(candidate: plan): string {
1325
+ return qemuargv(candidate)
1326
+ .map((token) => (token.includes(' ') || token.includes(',') ? `'${token}'` : token))
1327
+ .join(' \\\n ');
1328
+ }
1329
+
1330
+ /**
1331
+ * renders the docker run command of a plan: cpu divided by the overcommit
1332
+ * factor, unbounded pids cgroup (--pids-limit=0) and the MTTG thread
1333
+ * budget exported through AETHER_MTTG_THREADS.
1334
+ */
1335
+ export function dockerrun(candidate: plan): string {
1336
+ const cpus = (candidate.vcpus / Math.max(1, candidate.overcommit)).toFixed(2);
1337
+ return [
1338
+ `docker run --rm -it --name ${candidate.name}`,
1339
+ ` --cpus=${cpus} --memory=${candidate.memorygib}g --pids-limit=0`,
1340
+ ` -e AETHER_MTTG_THREADS=${candidate.mttgthreads}`,
1341
+ candidate.gpumode === 'none' || candidate.gpumode === 'virtio' ? '' : ' --gpus all',
1342
+ ' ghcr.io/aetherforge/runtime:5',
1343
+ ]
1344
+ .filter(Boolean)
1345
+ .join(' \\\n');
1346
+ }
1347
+
1348
+ /** renders the vm.config.toml block of a plan. */
1349
+ export function plantoml(candidate: plan): string {
1350
+ return `# generated by the saddle v6 planner
1351
+ [machine]
1352
+ name = "${candidate.name}"
1353
+ [cpu]
1354
+ model = "${candidate.cpu}"
1355
+ sockets = ${candidate.sockets}
1356
+ dies = ${candidate.dies}
1357
+ cores = ${candidate.cores}
1358
+ threads = ${candidate.threads}
1359
+ vcpus = ${candidate.vcpus}
1360
+ overcommit = ${candidate.overcommit}
1361
+ [memory]
1362
+ gib = ${candidate.memorygib}
1363
+ [gpu]
1364
+ model = "${candidate.gpu}"
1365
+ mode = "${candidate.gpumode}"
1366
+ vram_gib = ${candidate.vramgib}
1367
+ [mttg]
1368
+ enabled = ${candidate.mttg}
1369
+ virtual_threads = ${candidate.mttgthreads}
1370
+ `;
1371
+ }
1372
+
1373
+ /**
1374
+ * lints a plan: the MTTG thread budget must cover the vCPUs, the
1375
+ * overcommit ceiling is 64x, the vCPU ceiling is 4096 and the topology
1376
+ * product must equal the vCPU count.
1377
+ */
1378
+ export function planlint(candidate: plan): readonly string[] {
1379
+ const notes: string[] = [];
1380
+ if (candidate.mttg && candidate.mttgthreads < candidate.vcpus) {
1381
+ notes.push('mttg threads must cover the vcpu count');
1382
+ }
1383
+ if (candidate.overcommit > 64) {
1384
+ notes.push('overcommit ceiling is 64x');
1385
+ }
1386
+ if (candidate.vcpus > 4096) {
1387
+ notes.push('vcpu ceiling is 4096');
1388
+ }
1389
+ if (plantopology(candidate) !== candidate.vcpus) {
1390
+ notes.push(`topology product ${plantopology(candidate)} differs from vcpus ${candidate.vcpus}`);
1391
+ }
1392
+ return notes;
1393
+ }
1394
+
1395
+ /* ------------------------------------------------------------------ */
1396
+ /* Section 13: export barrel (v2 modules) */
1397
+ /* ------------------------------------------------------------------ */
1398
+
1399
+ /** Re-exports the compute domain (wasm/wasmtime 48 lts, webgpu on
1400
+ * lavapipe, node 26 runtime surface, ai workload planners, wasm canary,
1401
+ * wasi:gfx, chatops, gpu ebpf telemetry, ai migration predictor). */
1402
+ export * from './compute.js';
1403
+ /** Re-exports the media pipeline and transcode domain (24-stage
1404
+ * pipeline, ffmpeg 7.1 NVENC p1-p7 command synthesis, createoptimal
1405
+ * encoder policy, passage ed25519+chacha20-poly1305 channel, 30
1406
+ * transcode modes). */
1407
+ export * from './media.js';
1408
+ export {
1409
+ bellstate,
1410
+ deutsch,
1411
+ dnacapacity,
1412
+ dnavaultdecode,
1413
+ dnavaultencode,
1414
+ ghzstate,
1415
+ grover2,
1416
+ grover3,
1417
+ opticalplan,
1418
+ qteleport,
1419
+ quantuminspiredrandom,
1420
+ quantumregistry,
1421
+ quantumsim,
1422
+ runbb84,
1423
+ rune91,
1424
+ } from './quantum.js';
1425
+ /** Re-exports the scheduling and allocation domain (typecheck sharding,
1426
+ * shared-memory cache, project graph, MIG/vCPU/RAM/GPU/NUMA/PCI
1427
+ * allocation, aipsched, psi lstm, tenant QoS, anomaly detector,
1428
+ * hot reload, otel, health, shutdown, plugin hooks). */
1429
+ export * from './scheduler.js';
1430
+ export {
1431
+ cgroupsv2slice,
1432
+ creatiersengine,
1433
+ FREEPOOL,
1434
+ githubstorage,
1435
+ LATENCYLADDER,
1436
+ npmchunkregistry,
1437
+ plannpmchunks,
1438
+ publishplan,
1439
+ rambufferbackend,
1440
+ reassembleplan,
1441
+ sqlitekv,
1442
+ sqlitel3backend,
1443
+ swapfilerecipe,
1444
+ sysctldropin,
1445
+ TIERS,
1446
+ tierserror,
1447
+ tmpfsrecipe,
1448
+ zramrecipe,
1449
+ } from './tiers.js';
1450
+ /** Re-exports the virtual processor bank and cpuinfo generators. */
1451
+ export * from './virtualcpu.js';
1452
+ /** Re-exports the gpu passthrough surface (vfio, rom dump, vgpu data). */
1453
+ export * from './virtualgpu.js';
1454
+ /** Re-exports the virtualization surface (qemu turbo argv, passage,
1455
+ * mttg cgroups, mttg grid, checkpoint and restore, virtualizationcore
1456
+ * bridge). */
1457
+ export * from './virtualization.js';
1458
+ /** Re-exports the MIG profile union declared by the memory module. */
1459
+ export type { migprofileid } from './virtualmemory.js';
1460
+ /** Re-exports the memory tier catalog and virtual memory manager. */
1461
+ export * from './virtualmemory.js';
1462
+
1463
+
1464
+ /* ── Section 2: the saddle domain routing barrel ── */
1465
+
1466
+ export * from "./foundation.js";
1467
+ export * from "./isolation.js";
1468
+ export * from "./virtual.js";
1469
+ export * from "./execution.js";
1470
+ export * from "./browser.js";
1471
+ export * from "./acquisition.js";
1472
+ export * from "./communication.js";
1473
+ export * from "./integration.js";
1474
+ export * from "./automation.js";
1475
+ export * from "./intelligence.js";
1476
+ export * from "./distribution.js";
1477
+ export * from "./modes.js";
1478
+ export * from "./operations.js";