@ultrst-armada/krnl 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/README.md +67 -65
  2. package/package.json +13 -9
  3. package/packages/cli/dist/bin/krnl.cjs +1535 -9508
  4. package/packages/cli/dist/bin/krnl.js +55 -1915
  5. package/packages/cli/dist/chunk-6SHSECXR.js +1628 -0
  6. package/packages/cli/dist/index.cjs +1244 -7373
  7. package/packages/cli/dist/index.d.cts +45 -2
  8. package/packages/cli/dist/index.d.ts +45 -2
  9. package/packages/cli/dist/index.js +5 -20
  10. package/packages/cli/package.json +17 -10
  11. package/packages/core/dist/index.cjs +3039 -141
  12. package/packages/core/dist/index.d.cts +633 -27
  13. package/packages/core/dist/index.d.ts +633 -27
  14. package/packages/core/dist/index.js +3028 -139
  15. package/packages/core/package.json +15 -7
  16. package/packages/create-krnl/dist/index.cjs +322 -316
  17. package/packages/create-krnl/dist/index.js +322 -316
  18. package/packages/create-krnl/package.json +5 -3
  19. package/packages/eslint-plugin/dist/index.cjs +17 -55
  20. package/packages/eslint-plugin/dist/index.d.cts +8 -43
  21. package/packages/eslint-plugin/dist/index.d.ts +8 -43
  22. package/packages/eslint-plugin/dist/index.js +17 -55
  23. package/packages/eslint-plugin/package.json +5 -4
  24. package/packages/validate/dist/index.cjs +692 -361
  25. package/packages/validate/dist/index.d.cts +12 -14
  26. package/packages/validate/dist/index.d.ts +12 -14
  27. package/packages/validate/dist/index.js +692 -361
  28. package/packages/validate/package.json +14 -7
  29. package/packages/cli/dist/K_ENT_Entity-PQ5MURQY-ZG6FZXXX.js +0 -13
  30. package/packages/cli/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW-K4CRQYA5.js +0 -8
  31. package/packages/cli/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF-LNPXZYOE.js +0 -110
  32. package/packages/cli/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF-3ALZPNX4.js +0 -11
  33. package/packages/cli/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X-PJTICYSW.js +0 -11
  34. package/packages/cli/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW-M5TYU55O.js +0 -8
  35. package/packages/cli/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2-H6STOXRK.js +0 -20
  36. package/packages/cli/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK-XPJXSF7D.js +0 -19
  37. package/packages/cli/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7-CUYGTWOW.js +0 -7
  38. package/packages/cli/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU-VR6T4N6J.js +0 -17
  39. package/packages/cli/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5-RLJ4QWDP.js +0 -58
  40. package/packages/cli/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF-BOQGUASC.js +0 -22
  41. package/packages/cli/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG-XJI7KIT5.js +0 -8
  42. package/packages/cli/dist/K_LIB_Krnl_Telemetry-77FRZ3KV-K5VCWAFW.js +0 -9
  43. package/packages/cli/dist/chunk-3TRM6CYL.js +0 -152
  44. package/packages/cli/dist/chunk-5JDK35TG.js +0 -3872
  45. package/packages/cli/dist/chunk-63PTK33I.js +0 -997
  46. package/packages/cli/dist/chunk-6NIKAMUZ.js +0 -82
  47. package/packages/cli/dist/chunk-BOXWWXQG.js +0 -400
  48. package/packages/cli/dist/chunk-EEKLK7QJ.js +0 -565
  49. package/packages/cli/dist/chunk-EG7T2IAD.js +0 -107
  50. package/packages/cli/dist/chunk-F5EHXE2O.js +0 -1036
  51. package/packages/cli/dist/chunk-F65ANSQG.js +0 -269
  52. package/packages/cli/dist/chunk-FDNCADFE.js +0 -71
  53. package/packages/cli/dist/chunk-GDLRMDAN.js +0 -127
  54. package/packages/cli/dist/chunk-HWMTCMOS.js +0 -656
  55. package/packages/cli/dist/chunk-I74QIQOD.js +0 -5536
  56. package/packages/cli/dist/chunk-JTLSTO25.js +0 -71
  57. package/packages/cli/dist/chunk-JULBBJ27.js +0 -1033
  58. package/packages/cli/dist/chunk-OHVMVRBP.js +0 -117
  59. package/packages/cli/dist/chunk-P2PCLEKX.js +0 -666
  60. package/packages/cli/dist/chunk-PJQIUOX2.js +0 -7767
  61. package/packages/cli/dist/chunk-PPOF3DJW.js +0 -471
  62. package/packages/cli/dist/chunk-Q45257P6.js +0 -173
  63. package/packages/cli/dist/chunk-QNROWGBI.js +0 -1036
  64. package/packages/cli/dist/chunk-RJNYUXZD.js +0 -977
  65. package/packages/cli/dist/chunk-SRTOPJ5W.js +0 -104
  66. package/packages/cli/dist/chunk-TCEX3MPS.js +0 -702
  67. package/packages/cli/dist/chunk-TNOAJO2J.js +0 -675
  68. package/packages/cli/dist/chunk-UR2SUCSF.js +0 -701
  69. package/packages/cli/dist/chunk-X5LOIFM7.js +0 -68
  70. package/packages/cli/dist/chunk-XIRFOO3H.js +0 -589
  71. package/packages/cli/dist/chunk-ZAAV3JXQ.js +0 -809
  72. package/packages/core/dist/K_ENT_Entity-4MB7CU4A.js +0 -12
  73. package/packages/core/dist/K_ENT_Entity-DEJGIDGH.js +0 -12
  74. package/packages/core/dist/K_ENT_Entity-FXZO5UZ2.js +0 -12
  75. package/packages/core/dist/K_ENT_Entity-HDSCXC5F.js +0 -12
  76. package/packages/core/dist/K_ENT_Entity-JILABHLW.js +0 -12
  77. package/packages/core/dist/K_ENT_Entity-PQ5MURQY.js +0 -13
  78. package/packages/core/dist/K_ENT_Entity-ROAKDIHW.js +0 -12
  79. package/packages/core/dist/K_ENT_Entity-TBVFSKDV.js +0 -12
  80. package/packages/core/dist/K_ENT_Entity-ZFLKG3JO.js +0 -12
  81. package/packages/core/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW.js +0 -8
  82. package/packages/core/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF.js +0 -110
  83. package/packages/core/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF.js +0 -9
  84. package/packages/core/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X.js +0 -9
  85. package/packages/core/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW.js +0 -8
  86. package/packages/core/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2.js +0 -20
  87. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-4C6GBQAG.js +0 -18
  88. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-6V23A6F6.js +0 -18
  89. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK.js +0 -19
  90. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-DYLLC5G2.js +0 -18
  91. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-F4FOFAUP.js +0 -18
  92. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-FBOXXMI3.js +0 -18
  93. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-Q73BWLNP.js +0 -18
  94. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-QM2C4MVA.js +0 -18
  95. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-QUGI6SMP.js +0 -18
  96. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-RGMTBHNP.js +0 -18
  97. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-RWR7UNDW.js +0 -18
  98. package/packages/core/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7.js +0 -7
  99. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-32MFJJ5Z.js +0 -17
  100. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-4J4CEWRY.js +0 -17
  101. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-A366YHF2.js +0 -17
  102. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-LK4LYJHI.js +0 -17
  103. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU.js +0 -17
  104. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-NW3K63II.js +0 -17
  105. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-QDHTI5ZV.js +0 -17
  106. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-VHCT6VIW.js +0 -17
  107. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-WBRKF24R.js +0 -17
  108. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-XKYQYT6Q.js +0 -17
  109. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-Z2PWZYDZ.js +0 -17
  110. package/packages/core/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5.js +0 -58
  111. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-2EZU7QF4.js +0 -21
  112. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-6G3AQNAV.js +0 -21
  113. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-B2NZMQUG.js +0 -21
  114. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-C2RABMZP.js +0 -21
  115. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-HHE3NZ4F.js +0 -21
  116. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-LHFGR6WK.js +0 -21
  117. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-M74BLM3N.js +0 -21
  118. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-PT6ZA6EA.js +0 -21
  119. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-SP52V3CX.js +0 -21
  120. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF.js +0 -22
  121. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-YNSEUHJJ.js +0 -21
  122. package/packages/core/dist/K_LIB_Krnl_System_Unified_Http_Adapter-M6SBHIVA.js +0 -8
  123. package/packages/core/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG.js +0 -8
  124. package/packages/core/dist/K_LIB_Krnl_Telemetry-77FRZ3KV.js +0 -9
  125. package/packages/core/dist/chunk-33L2J7V7.js +0 -82
  126. package/packages/core/dist/chunk-3ES4K2ZP.js +0 -817
  127. package/packages/core/dist/chunk-3SMHVVLL.js +0 -82
  128. package/packages/core/dist/chunk-3UEZ7JQA.js +0 -4877
  129. package/packages/core/dist/chunk-3XIE6KBD.js +0 -4877
  130. package/packages/core/dist/chunk-46ZLCML6.js +0 -107
  131. package/packages/core/dist/chunk-4UEL3DWJ.js +0 -107
  132. package/packages/core/dist/chunk-54GWZ5PC.js +0 -82
  133. package/packages/core/dist/chunk-6QCYRS5L.js +0 -127
  134. package/packages/core/dist/chunk-6ULMHNXR.js +0 -104
  135. package/packages/core/dist/chunk-7WUETJEV.js +0 -117
  136. package/packages/core/dist/chunk-A5KRAYDB.js +0 -107
  137. package/packages/core/dist/chunk-ANEAZ3PO.js +0 -107
  138. package/packages/core/dist/chunk-BE76RL6F.js +0 -82
  139. package/packages/core/dist/chunk-CIARVYDO.js +0 -107
  140. package/packages/core/dist/chunk-CR2ANE62.js +0 -107
  141. package/packages/core/dist/chunk-DI27MOR7.js +0 -173
  142. package/packages/core/dist/chunk-E6RLFHM5.js +0 -596
  143. package/packages/core/dist/chunk-EELAPMNV.js +0 -4877
  144. package/packages/core/dist/chunk-ENZ2RQVJ.js +0 -107
  145. package/packages/core/dist/chunk-F2U6CX4F.js +0 -4877
  146. package/packages/core/dist/chunk-FKG64OHL.js +0 -82
  147. package/packages/core/dist/chunk-FYAZJYM5.js +0 -772
  148. package/packages/core/dist/chunk-G4NP4RDQ.js +0 -82
  149. package/packages/core/dist/chunk-GADIRLRS.js +0 -473
  150. package/packages/core/dist/chunk-GR6CSLQJ.js +0 -772
  151. package/packages/core/dist/chunk-HDS7AT6O.js +0 -772
  152. package/packages/core/dist/chunk-HIMEZUU2.js +0 -71
  153. package/packages/core/dist/chunk-IB4UHG5I.js +0 -596
  154. package/packages/core/dist/chunk-J7ZYNVRS.js +0 -772
  155. package/packages/core/dist/chunk-JVLZU4K7.js +0 -604
  156. package/packages/core/dist/chunk-JYXXI7Q3.js +0 -82
  157. package/packages/core/dist/chunk-K54K2KZW.js +0 -192
  158. package/packages/core/dist/chunk-K6VHLBNH.js +0 -3316
  159. package/packages/core/dist/chunk-KCBP7ZYA.js +0 -596
  160. package/packages/core/dist/chunk-KFQGP6VL.js +0 -33
  161. package/packages/core/dist/chunk-KIUEUI7K.js +0 -82
  162. package/packages/core/dist/chunk-LB67NIZP.js +0 -949
  163. package/packages/core/dist/chunk-LDTYFUNW.js +0 -596
  164. package/packages/core/dist/chunk-MLVWARD4.js +0 -596
  165. package/packages/core/dist/chunk-MPYVXHKO.js +0 -2777
  166. package/packages/core/dist/chunk-MRQ3MITU.js +0 -772
  167. package/packages/core/dist/chunk-MVUN7I7O.js +0 -107
  168. package/packages/core/dist/chunk-NDDOIRW7.js +0 -596
  169. package/packages/core/dist/chunk-O3KDB5MH.js +0 -3330
  170. package/packages/core/dist/chunk-OEINUDSE.js +0 -400
  171. package/packages/core/dist/chunk-OPDENPT4.js +0 -4877
  172. package/packages/core/dist/chunk-P6XEM2LA.js +0 -429
  173. package/packages/core/dist/chunk-QKMRSQV4.js +0 -82
  174. package/packages/core/dist/chunk-R6CCWALL.js +0 -4877
  175. package/packages/core/dist/chunk-RAMMOO73.js +0 -774
  176. package/packages/core/dist/chunk-S3FTZFG6.js +0 -772
  177. package/packages/core/dist/chunk-T2ZVN434.js +0 -4877
  178. package/packages/core/dist/chunk-TFHLDMIA.js +0 -107
  179. package/packages/core/dist/chunk-TI3QUCIJ.js +0 -107
  180. package/packages/core/dist/chunk-TR2BAIGI.js +0 -107
  181. package/packages/core/dist/chunk-UGVVJKC6.js +0 -4877
  182. package/packages/core/dist/chunk-V2DX7YIU.js +0 -984
  183. package/packages/core/dist/chunk-W4IHYUYD.js +0 -772
  184. package/packages/core/dist/chunk-W6WBG5OY.js +0 -4877
  185. package/packages/core/dist/chunk-WN3M7O7H.js +0 -3312
  186. package/packages/core/dist/chunk-WR3NCU7U.js +0 -4877
  187. package/packages/core/dist/chunk-XC6B6L27.js +0 -82
  188. package/packages/core/dist/chunk-XNSE64ZY.js +0 -3316
  189. package/packages/core/dist/chunk-XROES2WN.js +0 -634
  190. package/packages/core/dist/chunk-XSCKNRCZ.js +0 -5020
  191. package/packages/core/dist/chunk-XVABPAUZ.js +0 -82
  192. package/packages/core/dist/chunk-YOBCB5C5.js +0 -596
  193. package/packages/core/dist/chunk-YUK6Q563.js +0 -666
  194. package/packages/core/dist/chunk-YXGL3ZEU.js +0 -1030
  195. package/packages/core/dist/chunk-ZINJ5OUX.js +0 -596
  196. package/packages/core/dist/chunk-ZPFD4BIQ.js +0 -604
  197. package/packages/core/dist/chunk-ZQZBFG6F.js +0 -4826
  198. package/packages/core/dist/chunk-ZZFRJGXM.js +0 -4877
  199. package/packages/create-krnl/dist/K_ENT_Entity-PQ5MURQY-R2OH4VXE.js +0 -14
  200. package/packages/create-krnl/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW-AZM5HF4M.js +0 -9
  201. package/packages/create-krnl/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF-X5N6SV2S.js +0 -111
  202. package/packages/create-krnl/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF-5PFHF4JU.js +0 -12
  203. package/packages/create-krnl/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X-ED33OQPH.js +0 -12
  204. package/packages/create-krnl/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW-YGQLVR4P.js +0 -9
  205. package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2-VM7CTU2L.js +0 -21
  206. package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK-Y2GQFJ7I.js +0 -21
  207. package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7-L3JQWO54.js +0 -8
  208. package/packages/create-krnl/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU-KQARASPR.js +0 -19
  209. package/packages/create-krnl/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5-OF3IGLVL.js +0 -59
  210. package/packages/create-krnl/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF-JOLHKOEX.js +0 -24
  211. package/packages/create-krnl/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG-L46LSHKQ.js +0 -10
  212. package/packages/create-krnl/dist/K_LIB_Krnl_Telemetry-77FRZ3KV-4JUPRR3X.js +0 -10
  213. package/packages/create-krnl/dist/chunk-3TRM6CYL.js +0 -152
  214. package/packages/create-krnl/dist/chunk-3URCB3QS.js +0 -127
  215. package/packages/create-krnl/dist/chunk-5JDK35TG.js +0 -3872
  216. package/packages/create-krnl/dist/chunk-A2XAXDOW.js +0 -812
  217. package/packages/create-krnl/dist/chunk-AN6TMQHG.js +0 -1033
  218. package/packages/create-krnl/dist/chunk-BOXWWXQG.js +0 -400
  219. package/packages/create-krnl/dist/chunk-BPTBREBG.js +0 -38
  220. package/packages/create-krnl/dist/chunk-FDNCADFE.js +0 -71
  221. package/packages/create-krnl/dist/chunk-JTLSTO25.js +0 -71
  222. package/packages/create-krnl/dist/chunk-M3NCUIPL.js +0 -107
  223. package/packages/create-krnl/dist/chunk-N2EONSOC.js +0 -7769
  224. package/packages/create-krnl/dist/chunk-OHVMVRBP.js +0 -117
  225. package/packages/create-krnl/dist/chunk-Q45257P6.js +0 -173
  226. package/packages/create-krnl/dist/chunk-QGM4M3NI.js +0 -37
  227. package/packages/create-krnl/dist/chunk-RJNYUXZD.js +0 -977
  228. package/packages/create-krnl/dist/chunk-SRTOPJ5W.js +0 -104
  229. package/packages/create-krnl/dist/chunk-UPBIGEC3.js +0 -666
  230. package/packages/create-krnl/dist/chunk-V2DB7UD7.js +0 -82
  231. package/packages/create-krnl/dist/chunk-WMHLIUI6.js +0 -3644
  232. package/packages/create-krnl/dist/chunk-XIRFOO3H.js +0 -589
  233. package/packages/create-krnl/dist/chunk-Y2CEEVZP.js +0 -5536
  234. package/packages/create-krnl/dist/main-DXUMPBND.js +0 -2217
  235. package/packages/create-krnl/dist/wrapper-SDF2VKX3.js +0 -31
@@ -1,634 +0,0 @@
1
- import {
2
- krnlSystemEntityBase
3
- } from "./chunk-EELAPMNV.js";
4
-
5
- // src/core/K_LIB_Krnl_System_Magnetic_Loader.ts
6
- import fs from "fs";
7
- import path from "path";
8
- import { pathToFileURL } from "url";
9
- import { AsyncLocalStorage } from "async_hooks";
10
- var magneticStorage = new AsyncLocalStorage();
11
- if (!globalThis.__krnlSubAppLocalStorage) {
12
- globalThis.__krnlSubAppLocalStorage = new AsyncLocalStorage();
13
- }
14
- var subappLocalStorage = globalThis.__krnlSubAppLocalStorage;
15
- var KrnlMagneticLoader = class _KrnlMagneticLoader {
16
- /**
17
- * Scans and dynamically loads entities, functionalities, and subapps for the given entity or system.
18
- */
19
- static async loadAll(entity, baseDir) {
20
- const entityLabel = entity.entityName || entity.id || "Entity";
21
- console.log(`[MagneticLoader] loadAll called for entity '${entityLabel}' with baseDir '${baseDir}'`);
22
- const functionalitiesDir = path.join(baseDir, "functionalities");
23
- if (fs.existsSync(functionalitiesDir)) {
24
- const funcDirs = await fs.promises.readdir(functionalitiesDir, { withFileTypes: true });
25
- for (const dirent of funcDirs) {
26
- if (dirent.isDirectory()) {
27
- await this.loadFunctionality(entity, path.join(functionalitiesDir, dirent.name), dirent.name);
28
- }
29
- }
30
- }
31
- const entitiesDir = path.join(baseDir, "entities");
32
- if (fs.existsSync(entitiesDir)) {
33
- const entDirs = await fs.promises.readdir(entitiesDir, { withFileTypes: true });
34
- for (const dirent of entDirs) {
35
- if (dirent.isDirectory()) {
36
- await this.loadEntity(entity, path.join(entitiesDir, dirent.name), dirent.name);
37
- }
38
- }
39
- }
40
- const subappsDir = path.join(baseDir, "subapps");
41
- const isSubApp = subappLocalStorage.getStore() || entity._isSubApp || entity._isIngressNetworkMember;
42
- const krnlJsonPath = path.join(baseDir, "krnl.json");
43
- let subappMetaMap = {};
44
- if (fs.existsSync(krnlJsonPath)) {
45
- try {
46
- const parsed = JSON.parse(fs.readFileSync(krnlJsonPath, "utf-8"));
47
- subappMetaMap = parsed.subapps || {};
48
- } catch (_) {
49
- }
50
- }
51
- if (Object.keys(subappMetaMap).length > 0) {
52
- if (!fs.existsSync(subappsDir)) {
53
- fs.mkdirSync(subappsDir, { recursive: true });
54
- }
55
- for (const [subappName, subMeta] of Object.entries(subappMetaMap)) {
56
- const gitUrl = subMeta.git || subMeta.repo || subMeta.repository;
57
- if (gitUrl) {
58
- const targetAppPath = path.join(subappsDir, subappName);
59
- if (!fs.existsSync(targetAppPath)) {
60
- console.log(`[MagneticLoader] Cloning sub-app '${subappName}' from git repository '${gitUrl}'...`);
61
- try {
62
- let cloneUrl = gitUrl;
63
- if (cloneUrl.startsWith("github:")) {
64
- const parts = cloneUrl.replace("github:", "").split("#");
65
- const repoPath = parts[0];
66
- const branch = parts[1];
67
- cloneUrl = `https://github.com/${repoPath}.git`;
68
- if (branch) {
69
- cloneUrl += ` -b ${branch}`;
70
- }
71
- }
72
- const { exec } = await import("child_process");
73
- const { promisify } = await import("util");
74
- const execPromise = promisify(exec);
75
- await execPromise(`git clone ${cloneUrl} "${targetAppPath}"`);
76
- console.log(`[MagneticLoader] Sub-app '${subappName}' cloned successfully from '${gitUrl}'.`);
77
- } catch (cloneErr) {
78
- console.error(`[MagneticLoader] Failed to clone sub-app '${subappName}' from '${gitUrl}':`, cloneErr.message || cloneErr);
79
- }
80
- }
81
- }
82
- }
83
- }
84
- const candidateSubappDirs = [
85
- path.join(baseDir, "subapps"),
86
- path.join(baseDir, "sub-apps"),
87
- path.join(baseDir, "src", "sub-apps")
88
- ].filter((d) => fs.existsSync(d));
89
- const loadedSubAppPaths = /* @__PURE__ */ new Set();
90
- for (const subappsDir2 of candidateSubappDirs) {
91
- await this.syncParentSubAppDependencies(baseDir, subappsDir2);
92
- const apps = await fs.promises.readdir(subappsDir2, { withFileTypes: true });
93
- const subappConfigs = [];
94
- for (const dirent of apps) {
95
- if (dirent.isDirectory()) {
96
- const appPath = path.join(subappsDir2, dirent.name);
97
- if (loadedSubAppPaths.has(appPath)) continue;
98
- loadedSubAppPaths.add(appPath);
99
- const buildOk = await this.ensureSubAppBuilt(appPath, dirent.name, entity, baseDir);
100
- if (!buildOk) {
101
- continue;
102
- }
103
- if (typeof entity.loadSubApp === "function") {
104
- const { KrnlSubAppDiscovery } = await import("./K_LIB_Krnl_SubApp_Engine-7HR5HWW2.js");
105
- const desc = await KrnlSubAppDiscovery.locateDescriptor(appPath, dirent.name);
106
- if (desc && (fs.existsSync(path.join(appPath, "subapp.json")) || fs.existsSync(desc.registrationPath))) {
107
- try {
108
- const subMeta = subappMetaMap[dirent.name] || subappMetaMap[dirent.name.toLowerCase()];
109
- const inst = await entity.loadSubApp(desc, subMeta || {});
110
- if (inst.state === "READY") {
111
- console.log(`[MagneticLoader] Loaded sub-app '${dirent.name}' using registration contract on '${entity.entityName || entity.id}'.`);
112
- continue;
113
- }
114
- } catch (loadErr) {
115
- console.warn(`[MagneticLoader] SubApp registration contract load warning for '${dirent.name}':`, loadErr.message);
116
- }
117
- }
118
- }
119
- const config = await this.detectSubApp(appPath, dirent.name);
120
- if (config) {
121
- subappConfigs.push(config);
122
- }
123
- }
124
- }
125
- if (subappConfigs.length > 0 && typeof entity.loadSubApps === "function") {
126
- for (const cfg of subappConfigs) {
127
- const subMeta = subappMetaMap[cfg.prefix] || subappMetaMap[Object.keys(subappMetaMap).find((k) => k.toLowerCase() === cfg.prefix) || ""];
128
- cfg.executionMode = subMeta?.executionMode ?? "local";
129
- }
130
- console.log(`[MagneticLoader] Loading ${subappConfigs.length} sub-app(s) on '${entity.entityName}' (no networking).`);
131
- await entity.loadSubApps(subappConfigs);
132
- }
133
- }
134
- let frontendDir = path.join(baseDir, "frontend");
135
- const oldFrontendsDir = path.join(baseDir, "frontends");
136
- if (!fs.existsSync(frontendDir) && fs.existsSync(oldFrontendsDir)) {
137
- try {
138
- fs.renameSync(oldFrontendsDir, frontendDir);
139
- console.log(`[MagneticLoader] Renamed legacy 'frontends/' directory to 'frontend/' on '${entity.entityName}'.`);
140
- } catch (err) {
141
- console.warn(`[MagneticLoader] Failed to rename 'frontends/' -> 'frontend/': ${err.message}`);
142
- }
143
- }
144
- if (entity._frontendEnabled && !fs.existsSync(frontendDir)) {
145
- try {
146
- fs.mkdirSync(frontendDir, { recursive: true });
147
- } catch (_) {
148
- }
149
- }
150
- if (fs.existsSync(frontendDir)) {
151
- if (!isSubApp) {
152
- entity.enableFrontend({ frontendDir });
153
- }
154
- const hasLocalFuncs = entity.localFunctionalities && entity.localFunctionalities.size > 0;
155
- const indexExists = fs.existsSync(path.join(frontendDir, "src", "index.tsx"));
156
- if (entity._subAppRegistry) {
157
- for (const [prefix, entry] of entity._subAppRegistry.entries()) {
158
- const subAppDir = entry.entity?._entityDataDir || entry.entity?._sourceDir;
159
- if (subAppDir) {
160
- const subFrontend = path.join(subAppDir, "frontend");
161
- if (fs.existsSync(subFrontend) && entity._frontend) {
162
- entity._frontend.registerSubAppFrontend(prefix, subFrontend);
163
- }
164
- }
165
- }
166
- }
167
- if (!isSubApp || hasLocalFuncs || !indexExists) {
168
- try {
169
- const { KrnlFrontendGenerator } = await import("./K_LIB_Krnl_Frontend_Generator-UYNRNX2X.js");
170
- await KrnlFrontendGenerator.generate(entity, frontendDir);
171
- } catch (err) {
172
- console.error(`[MagneticLoader] Frontend generator error on '${entity.entityName}':`, err.message || err);
173
- }
174
- try {
175
- const { KrnlFrontendBuilder } = await import("./K_LIB_Krnl_Frontend_Builder-2ZDUH6PF.js");
176
- await KrnlFrontendBuilder.build(frontendDir);
177
- if (process.env.NODE_ENV !== "production" && !isSubApp) {
178
- KrnlFrontendBuilder.watch(frontendDir).catch((err) => {
179
- console.warn(`[MagneticLoader] esbuild watcher error on '${entity.entityName}':`, err.message || err);
180
- });
181
- }
182
- } catch (err) {
183
- console.error(`[MagneticLoader] Frontend builder error on '${entity.entityName}':`, err.message || err);
184
- }
185
- }
186
- }
187
- const adaptersDir = path.join(baseDir, "protocol_adapters");
188
- if (fs.existsSync(adaptersDir) && typeof entity.attachAdapter === "function") {
189
- try {
190
- const adapterFiles = await fs.promises.readdir(adaptersDir);
191
- for (const file of adapterFiles) {
192
- if (file.endsWith(".js") || file.endsWith(".ts")) {
193
- const mod = await import(pathToFileURL(path.join(adaptersDir, file)).href);
194
- const AdapterClass = mod.default || mod[path.basename(file, path.extname(file))];
195
- if (AdapterClass && typeof AdapterClass === "function") {
196
- const adapterInstance = new AdapterClass();
197
- entity.attachAdapter(adapterInstance);
198
- console.log(`[MagneticLoader] Attached protocol adapter '${adapterInstance.name || file}' to entity '${entityLabel}'.`);
199
- }
200
- }
201
- }
202
- } catch (err) {
203
- console.warn(`[MagneticLoader] Error scanning protocol_adapters in '${baseDir}':`, err.message || err);
204
- }
205
- }
206
- if (entity.localFunctionalities && typeof entity.initializeAiLayer === "function") {
207
- const hasAiConfig = [...entity.localFunctionalities.values()].some((f) => f.ai?.enabled);
208
- let hasAiStore = false;
209
- const storePath = path.join(baseDir, "krnl_runtime_state.db");
210
- if (fs.existsSync(storePath)) {
211
- try {
212
- const storeContent = JSON.parse(fs.readFileSync(storePath, "utf-8"));
213
- if (storeContent?.endpointAgentProfiles && Object.keys(storeContent.endpointAgentProfiles).length > 0) {
214
- hasAiStore = true;
215
- }
216
- } catch (e) {
217
- }
218
- }
219
- if (hasAiConfig || hasAiStore) {
220
- console.log(`[MagneticLoader] Automatically initializing AI Layer on '${entityLabel}'...`);
221
- await entity.initializeAiLayer(baseDir);
222
- entity.setFlag?.("krnl:ai_layer_ready");
223
- }
224
- }
225
- for (const cand of ["libraries", "library"]) {
226
- const librariesDir = path.join(baseDir, cand);
227
- if (fs.existsSync(librariesDir)) {
228
- await this.loadLibraries(entity, librariesDir);
229
- }
230
- }
231
- entity.setFlag?.("krnl:magnetic_load_complete");
232
- }
233
- static async loadLibraries(entity, libDir) {
234
- if (!fs.existsSync(libDir)) return;
235
- entity.libraries = entity.libraries || {};
236
- const scanRecursive = async (currDir) => {
237
- const entries = await fs.promises.readdir(currDir, { withFileTypes: true });
238
- for (const entry of entries) {
239
- if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
240
- const fullPath = path.join(currDir, entry.name);
241
- if (entry.isDirectory()) {
242
- await scanRecursive(fullPath);
243
- } else if (/\.(ts|js|mjs)$/.test(entry.name) && !entry.name.endsWith(".d.ts")) {
244
- try {
245
- const raw = path.basename(entry.name, path.extname(entry.name));
246
- const mod = await import(pathToFileURL(fullPath).href);
247
- entity.libraries[raw] = mod.default || mod;
248
- console.log(`[MagneticLoader] Dynamically loaded library '${raw}' from '${fullPath}'`);
249
- } catch (e) {
250
- console.warn(`[MagneticLoader] Warning: Could not dynamically load library at '${fullPath}': ${e.message}`);
251
- }
252
- }
253
- }
254
- };
255
- await scanRecursive(libDir);
256
- }
257
- static async loadFunctionality(entity, funcDir, funcName) {
258
- const descriptorPath = path.join(funcDir, `${funcName}.js`);
259
- let atom = null;
260
- if (fs.existsSync(descriptorPath)) {
261
- const mod = await import(pathToFileURL(descriptorPath).href);
262
- atom = mod[`${funcName}Atom`] || mod.default || mod.Atom;
263
- }
264
- if (!atom) {
265
- atom = {
266
- id: funcName,
267
- visibility: "public",
268
- emitters: {}
269
- };
270
- const statePath = path.join(funcDir, "state_data", "state.js");
271
- if (fs.existsSync(statePath)) {
272
- const mod = await import(pathToFileURL(statePath).href);
273
- atom.initialState = mod[`${funcName.toLowerCase()}InitialState`] || mod.initialState || mod.default;
274
- }
275
- const logicPath = path.join(funcDir, "main_function", "logic.js");
276
- if (fs.existsSync(logicPath)) {
277
- const mod = await import(pathToFileURL(logicPath).href);
278
- atom.api = mod.main || mod.default;
279
- }
280
- const lifecyclePath = path.join(funcDir, "main_function", "lifecycle.js");
281
- if (fs.existsSync(lifecyclePath)) {
282
- const mod = await import(pathToFileURL(lifecyclePath).href);
283
- atom.onMount = mod.onMount;
284
- atom.onTeardown = mod.onTeardown;
285
- }
286
- const manifestPath = path.join(funcDir, "manifest.json");
287
- if (fs.existsSync(manifestPath)) {
288
- try {
289
- const parsedManifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
290
- atom.manifest = parsedManifest;
291
- } catch (e) {
292
- console.warn(`[MagneticLoader] Error parsing manifest.json in '${funcDir}':`, e.message);
293
- }
294
- }
295
- const eventsDir2 = path.join(funcDir, "events");
296
- if (fs.existsSync(eventsDir2)) {
297
- const eventFiles = await fs.promises.readdir(eventsDir2);
298
- for (const file of eventFiles) {
299
- if (file.endsWith(".js")) {
300
- const name = path.basename(file, ".js");
301
- atom.emitters[name] = {};
302
- }
303
- }
304
- }
305
- }
306
- if (atom && !atom.manifest) {
307
- const manifestPath = path.join(funcDir, "manifest.json");
308
- if (fs.existsSync(manifestPath)) {
309
- try {
310
- atom.manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
311
- } catch (_) {
312
- }
313
- }
314
- }
315
- const helpers = {};
316
- const helpersDir = path.join(funcDir, "helper_functions");
317
- if (fs.existsSync(helpersDir)) {
318
- const files = await fs.promises.readdir(helpersDir);
319
- for (const file of files) {
320
- if (file.endsWith(".js")) {
321
- const name = path.basename(file, ".js");
322
- const mod = await import(pathToFileURL(path.join(helpersDir, file)).href);
323
- helpers[name] = mod[name] || mod.default || mod;
324
- this.registerGlobalWrapper(name);
325
- }
326
- }
327
- }
328
- const events = {};
329
- const eventsDir = path.join(funcDir, "events");
330
- if (fs.existsSync(eventsDir)) {
331
- const files = await fs.promises.readdir(eventsDir);
332
- for (const file of files) {
333
- if (file.endsWith(".js")) {
334
- const name = path.basename(file, ".js");
335
- const mod = await import(pathToFileURL(path.join(eventsDir, file)).href);
336
- events[name] = mod[name] || mod.default || mod;
337
- this.registerGlobalWrapper(name);
338
- }
339
- }
340
- }
341
- const originalApi = atom.api;
342
- if (originalApi) {
343
- atom.api = async (input, context) => {
344
- return await magneticStorage.run({ helpers, events }, async () => {
345
- return await originalApi(input, context);
346
- });
347
- };
348
- }
349
- entity.addLocal(atom);
350
- }
351
- static async loadEntity(parent, entDir, entName) {
352
- let fileToImport = null;
353
- const candidates = [`${entName}.js`, "assembler.js", "index.js"];
354
- for (const cand of candidates) {
355
- const p = path.join(entDir, cand);
356
- if (fs.existsSync(p)) {
357
- fileToImport = p;
358
- break;
359
- }
360
- }
361
- let childInstance = null;
362
- if (fileToImport) {
363
- const mod = await import(pathToFileURL(fileToImport).href);
364
- const ClassToUse = mod[entName] || mod.default || mod.Entity;
365
- if (ClassToUse && parent.hierarchyManager) {
366
- childInstance = parent.hierarchyManager.createComponentEntity(entName, ClassToUse);
367
- console.log(`[MagneticLoader] Magnetically instantiated child entity: ${entName} under ${parent.entityName || parent.id}`);
368
- }
369
- }
370
- if (!childInstance && parent.hierarchyManager) {
371
- const { Entity } = await import("./K_ENT_Entity-TBVFSKDV.js");
372
- childInstance = parent.hierarchyManager.createComponentEntity(entName, Entity);
373
- console.log(`[MagneticLoader] Auto-created child entity container: ${entName} under ${parent.entityName || parent.id}`);
374
- }
375
- if (childInstance) {
376
- await _KrnlMagneticLoader.loadAll(childInstance, entDir);
377
- }
378
- }
379
- static async ensureSubAppBuilt(appPath, appName, entity, parentBaseDir) {
380
- const packageJsonPath = path.join(appPath, "package.json");
381
- if (!fs.existsSync(packageJsonPath)) {
382
- return true;
383
- }
384
- const subNodeModules = path.join(appPath, "node_modules");
385
- const candidateParentDirs = [
386
- parentBaseDir ? path.join(parentBaseDir, "node_modules") : null,
387
- parentBaseDir ? path.resolve(parentBaseDir, "..", "node_modules") : null,
388
- path.join(process.cwd(), "node_modules")
389
- ].filter(Boolean);
390
- const parentNodeModules = candidateParentDirs.find((d) => fs.existsSync(d));
391
- if (!fs.existsSync(subNodeModules) && parentNodeModules) {
392
- try {
393
- fs.symlinkSync(parentNodeModules, subNodeModules, "junction");
394
- console.log(`[MagneticLoader] Symlinked sub-app node_modules for '${appName}' -> '${parentNodeModules}'`);
395
- } catch (symErr) {
396
- console.warn(`[MagneticLoader] Symlinking node_modules for '${appName}' failed, falling back:`, symErr.message);
397
- }
398
- }
399
- const assemblerPath = path.join(appPath, "assembler.js");
400
- let distPath = path.join(appPath, "dist", `${appName}.js`);
401
- if (fs.existsSync(packageJsonPath)) {
402
- try {
403
- const pkgJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
404
- if (pkgJson.main) {
405
- distPath = path.resolve(appPath, pkgJson.main);
406
- }
407
- } catch (_) {
408
- }
409
- }
410
- let gitUpdated = false;
411
- const gitDir = path.join(appPath, ".git");
412
- if (fs.existsSync(gitDir)) {
413
- console.log(`[MagneticLoader] Checking for git remote updates for sub-app '${appName}'...`);
414
- try {
415
- const { exec } = await import("child_process");
416
- const { promisify } = await import("util");
417
- const execPromise = promisify(exec);
418
- await execPromise("git fetch", { cwd: appPath, timeout: 3e3 });
419
- const { stdout } = await execPromise("git status -uno", { cwd: appPath, timeout: 3e3 });
420
- if (stdout.includes("Your branch is behind") || stdout.includes("can be fast-forwarded")) {
421
- console.log(`[MagneticLoader] Remote updates found for sub-app '${appName}'. Pulling changes...`);
422
- const pullResult = await execPromise("git pull", { cwd: appPath, timeout: 5e3 });
423
- console.log(`[MagneticLoader] Git pull result for '${appName}':`, pullResult.stdout);
424
- gitUpdated = true;
425
- } else {
426
- console.log(`[MagneticLoader] Sub-app '${appName}' git repository is up to date.`);
427
- }
428
- } catch (err) {
429
- console.warn(`[MagneticLoader] Warning: git update check failed for '${appName}':`, err.message || err);
430
- }
431
- }
432
- if (!fs.existsSync(assemblerPath) || !fs.existsSync(distPath) || !fs.existsSync(path.join(appPath, "node_modules")) || gitUpdated) {
433
- console.log(`[MagneticLoader] Sub-app '${appName}' ${gitUpdated ? "was updated via git" : "is missing build artifacts"}. Initiating auto-build...`);
434
- try {
435
- const pkgJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
436
- const hasBuildScript = pkgJson.scripts && pkgJson.scripts.build;
437
- if (!hasBuildScript) {
438
- throw new Error(`package.json is missing a 'build' script.`);
439
- }
440
- const nodeModulesPath = path.join(appPath, "node_modules");
441
- if (!fs.existsSync(nodeModulesPath)) {
442
- let installCmd = "npm install --no-audit --no-fund";
443
- if (fs.existsSync(path.join(appPath, "pnpm-lock.yaml"))) {
444
- installCmd = "pnpm install";
445
- } else if (fs.existsSync(path.join(appPath, "yarn.lock"))) {
446
- installCmd = "yarn install";
447
- }
448
- console.log(`[MagneticLoader] Installing dependencies for '${appName}' using '${installCmd}'...`);
449
- const { exec: exec2 } = await import("child_process");
450
- const { promisify: promisify2 } = await import("util");
451
- const execPromise2 = promisify2(exec2);
452
- await execPromise2(installCmd, { cwd: appPath });
453
- } else {
454
- const pkgJson2 = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
455
- const hasKrnlts = pkgJson2.dependencies && pkgJson2.dependencies.krnlts || pkgJson2.devDependencies && pkgJson2.devDependencies.krnlts;
456
- if (hasKrnlts) {
457
- let updateCmd = "npm update krnlts";
458
- if (fs.existsSync(path.join(appPath, "pnpm-lock.yaml"))) {
459
- updateCmd = "pnpm update krnlts";
460
- } else if (fs.existsSync(path.join(appPath, "yarn.lock"))) {
461
- updateCmd = "yarn upgrade krnlts";
462
- }
463
- console.log(`[MagneticLoader] Automatically updating krnlts dependency for '${appName}' using '${updateCmd}'...`);
464
- try {
465
- const { exec: exec2 } = await import("child_process");
466
- const { promisify: promisify2 } = await import("util");
467
- const execPromise2 = promisify2(exec2);
468
- await execPromise2(updateCmd, { cwd: appPath });
469
- } catch (err) {
470
- console.warn(`[MagneticLoader] Warning: auto-updating krnlts for '${appName}' failed:`, err.message || err);
471
- }
472
- }
473
- }
474
- let buildCmd = "npm run build";
475
- if (fs.existsSync(path.join(appPath, "pnpm-lock.yaml"))) {
476
- buildCmd = "pnpm run build";
477
- } else if (fs.existsSync(path.join(appPath, "yarn.lock"))) {
478
- buildCmd = "yarn build";
479
- }
480
- console.log(`[MagneticLoader] Building '${appName}' using '${buildCmd}'...`);
481
- const { exec } = await import("child_process");
482
- const { promisify } = await import("util");
483
- const execPromise = promisify(exec);
484
- await execPromise(buildCmd, { cwd: appPath });
485
- if (!fs.existsSync(assemblerPath)) {
486
- console.log(`[MagneticLoader] Automatically generating assembler.js for '${appName}'...`);
487
- const code = `export { ${appName} as default } from "./dist/${appName}.js";
488
- `;
489
- fs.writeFileSync(assemblerPath, code, "utf-8");
490
- }
491
- console.log(`[MagneticLoader] Sub-app '${appName}' successfully built and prepared.`);
492
- } catch (err) {
493
- const errMsg = err.message || String(err);
494
- console.error(`[MagneticLoader] Failed to build sub-app '${appName}':`, errMsg);
495
- entity._subappErrors = entity._subappErrors || [];
496
- entity._subappErrors.push({
497
- subapp: appName,
498
- error: errMsg
499
- });
500
- return false;
501
- }
502
- }
503
- return true;
504
- }
505
- static async detectSubApp(appPath, appName) {
506
- const assemblerPath = path.join(appPath, "assembler.js");
507
- if (fs.existsSync(assemblerPath)) {
508
- const mod = await import(pathToFileURL(assemblerPath).href);
509
- const ServiceClass = mod[appName] || mod.default;
510
- if (ServiceClass) {
511
- const isKrnlSubclass = ServiceClass.prototype && (ServiceClass.prototype instanceof krnlSystemEntityBase || typeof ServiceClass.prototype.boot === "function");
512
- return {
513
- ServiceClass,
514
- prefix: appName.toLowerCase(),
515
- isKrnl: !!isKrnlSubclass,
516
- entryPath: isKrnlSubclass ? assemblerPath : appPath
517
- };
518
- }
519
- }
520
- const packageJsonPath = path.join(appPath, "package.json");
521
- if (fs.existsSync(packageJsonPath)) {
522
- if (fs.existsSync(path.join(appPath, "KrnlFrontendModule.ts"))) {
523
- return null;
524
- }
525
- return {
526
- prefix: appName.toLowerCase(),
527
- isKrnl: false,
528
- entryPath: appPath
529
- };
530
- }
531
- return null;
532
- }
533
- /**
534
- * Automatically reconciles parent application package.json when sub-apps are added or removed.
535
- * - Packages needed by new sub-apps are added to parent package.json.
536
- * - Packages no longer needed by any sub-app are removed from parent package.json.
537
- */
538
- static async syncParentSubAppDependencies(baseDir, subappsDir) {
539
- try {
540
- const candidateParentPaths = [
541
- path.join(baseDir, "package.json"),
542
- path.resolve(baseDir, "..", "package.json"),
543
- path.join(process.cwd(), "package.json")
544
- ];
545
- const parentPkgPath = candidateParentPaths.find((p) => fs.existsSync(p));
546
- if (!parentPkgPath) return;
547
- const parentDir = path.dirname(parentPkgPath);
548
- const parentKrnlJsonPath = path.join(baseDir, "krnl.json");
549
- let krnlJson = {};
550
- if (fs.existsSync(parentKrnlJsonPath)) {
551
- try {
552
- krnlJson = JSON.parse(fs.readFileSync(parentKrnlJsonPath, "utf-8"));
553
- } catch (_) {
554
- }
555
- }
556
- const previousManaged = krnlJson.managedSubAppDependencies || {};
557
- const activeSubAppDeps = {};
558
- const subEntries = await fs.promises.readdir(subappsDir, { withFileTypes: true });
559
- for (const dirent of subEntries) {
560
- if (dirent.isDirectory()) {
561
- const subPkgPath = path.join(subappsDir, dirent.name, "package.json");
562
- if (fs.existsSync(subPkgPath)) {
563
- try {
564
- const subPkg = JSON.parse(fs.readFileSync(subPkgPath, "utf-8"));
565
- const combined = { ...subPkg.dependencies, ...subPkg.devDependencies };
566
- for (const [pkgName, pkgVer] of Object.entries(combined)) {
567
- if (pkgName !== "krnlts" && pkgName !== "tsup" && !pkgName.startsWith("@types/")) {
568
- activeSubAppDeps[pkgName] = pkgVer;
569
- }
570
- }
571
- } catch (_) {
572
- }
573
- }
574
- }
575
- }
576
- const parentPkg = JSON.parse(fs.readFileSync(parentPkgPath, "utf-8"));
577
- parentPkg.dependencies = parentPkg.dependencies || {};
578
- let modified = false;
579
- for (const [pkgName, pkgVer] of Object.entries(activeSubAppDeps)) {
580
- if (!parentPkg.dependencies[pkgName]) {
581
- console.log(`[MagneticLoader] Adding new sub-app dependency '${pkgName}@${pkgVer}' to parent package.json...`);
582
- parentPkg.dependencies[pkgName] = pkgVer;
583
- previousManaged[pkgName] = pkgVer;
584
- modified = true;
585
- }
586
- }
587
- for (const [pkgName] of Object.entries(previousManaged)) {
588
- if (!activeSubAppDeps[pkgName]) {
589
- console.log(`[MagneticLoader] Removing stale sub-app dependency '${pkgName}' from parent package.json...`);
590
- delete parentPkg.dependencies[pkgName];
591
- delete previousManaged[pkgName];
592
- modified = true;
593
- }
594
- }
595
- if (modified) {
596
- fs.writeFileSync(parentPkgPath, JSON.stringify(parentPkg, null, 2) + "\n", "utf-8");
597
- krnlJson.managedSubAppDependencies = previousManaged;
598
- if (fs.existsSync(parentKrnlJsonPath)) {
599
- fs.writeFileSync(parentKrnlJsonPath, JSON.stringify(krnlJson, null, 2) + "\n", "utf-8");
600
- }
601
- console.log(`[MagneticLoader] Parent package.json dependencies updated. Running npm install...`);
602
- const { exec } = await import("child_process");
603
- const { promisify } = await import("util");
604
- const execPromise = promisify(exec);
605
- await execPromise("npm install --no-audit --no-fund", { cwd: parentDir });
606
- console.log(`[MagneticLoader] Parent dependencies synced successfully.`);
607
- }
608
- } catch (err) {
609
- console.warn(`[MagneticLoader] Sub-app dependency reconciliation warning:`, err.message || err);
610
- }
611
- }
612
- static registerGlobalWrapper(name) {
613
- if (!globalThis[name]) {
614
- Object.defineProperty(globalThis, name, {
615
- value: (...args) => {
616
- const store = magneticStorage.getStore();
617
- const fn = store?.helpers?.[name] || store?.events?.[name];
618
- if (!fn) {
619
- throw new Error(`[MagneticSystem] Dynamic asset '${name}' called outside active functionality context.`);
620
- }
621
- return fn(...args);
622
- },
623
- configurable: true,
624
- writable: true
625
- });
626
- }
627
- }
628
- };
629
-
630
- export {
631
- magneticStorage,
632
- subappLocalStorage,
633
- KrnlMagneticLoader
634
- };