@ultrst-armada/krnl 0.0.0-stage → 1.0.1

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 (236) hide show
  1. package/README.md +95 -2
  2. package/package.json +75 -4
  3. package/packages/cli/dist/K_ENT_Entity-PQ5MURQY-ZG6FZXXX.js +13 -0
  4. package/packages/cli/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW-K4CRQYA5.js +8 -0
  5. package/packages/cli/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF-LNPXZYOE.js +110 -0
  6. package/packages/cli/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF-3ALZPNX4.js +11 -0
  7. package/packages/cli/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X-PJTICYSW.js +11 -0
  8. package/packages/cli/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW-M5TYU55O.js +8 -0
  9. package/packages/cli/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2-H6STOXRK.js +20 -0
  10. package/packages/cli/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK-XPJXSF7D.js +19 -0
  11. package/packages/cli/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7-CUYGTWOW.js +7 -0
  12. package/packages/cli/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU-VR6T4N6J.js +17 -0
  13. package/packages/cli/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5-RLJ4QWDP.js +58 -0
  14. package/packages/cli/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF-BOQGUASC.js +22 -0
  15. package/packages/cli/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG-XJI7KIT5.js +8 -0
  16. package/packages/cli/dist/K_LIB_Krnl_Telemetry-77FRZ3KV-K5VCWAFW.js +9 -0
  17. package/packages/cli/dist/bin/krnl.cjs +9758 -0
  18. package/packages/cli/dist/bin/krnl.d.cts +1 -0
  19. package/packages/cli/dist/bin/krnl.d.ts +1 -0
  20. package/packages/cli/dist/bin/krnl.js +2006 -0
  21. package/packages/cli/dist/chunk-3TRM6CYL.js +152 -0
  22. package/packages/cli/dist/chunk-5JDK35TG.js +3872 -0
  23. package/packages/cli/dist/chunk-63PTK33I.js +997 -0
  24. package/packages/cli/dist/chunk-6NIKAMUZ.js +82 -0
  25. package/packages/cli/dist/chunk-BOXWWXQG.js +400 -0
  26. package/packages/cli/dist/chunk-EEKLK7QJ.js +565 -0
  27. package/packages/cli/dist/chunk-EG7T2IAD.js +107 -0
  28. package/packages/cli/dist/chunk-F5EHXE2O.js +1036 -0
  29. package/packages/cli/dist/chunk-F65ANSQG.js +269 -0
  30. package/packages/cli/dist/chunk-FDNCADFE.js +71 -0
  31. package/packages/cli/dist/chunk-GDLRMDAN.js +127 -0
  32. package/packages/cli/dist/chunk-HWMTCMOS.js +656 -0
  33. package/packages/cli/dist/chunk-I74QIQOD.js +5536 -0
  34. package/packages/cli/dist/chunk-JTLSTO25.js +71 -0
  35. package/packages/cli/dist/chunk-JULBBJ27.js +1033 -0
  36. package/packages/cli/dist/chunk-OHVMVRBP.js +117 -0
  37. package/packages/cli/dist/chunk-P2PCLEKX.js +666 -0
  38. package/packages/cli/dist/chunk-PJQIUOX2.js +7767 -0
  39. package/packages/cli/dist/chunk-PPOF3DJW.js +471 -0
  40. package/packages/cli/dist/chunk-Q45257P6.js +173 -0
  41. package/packages/cli/dist/chunk-QNROWGBI.js +1036 -0
  42. package/packages/cli/dist/chunk-RJNYUXZD.js +977 -0
  43. package/packages/cli/dist/chunk-SRTOPJ5W.js +104 -0
  44. package/packages/cli/dist/chunk-TCEX3MPS.js +702 -0
  45. package/packages/cli/dist/chunk-TNOAJO2J.js +675 -0
  46. package/packages/cli/dist/chunk-UR2SUCSF.js +701 -0
  47. package/packages/cli/dist/chunk-X5LOIFM7.js +68 -0
  48. package/packages/cli/dist/chunk-XIRFOO3H.js +589 -0
  49. package/packages/cli/dist/chunk-ZAAV3JXQ.js +809 -0
  50. package/packages/cli/dist/index.cjs +7798 -0
  51. package/packages/cli/dist/index.d.cts +7 -0
  52. package/packages/cli/dist/index.d.ts +7 -0
  53. package/packages/cli/dist/index.js +29 -0
  54. package/packages/cli/package.json +34 -0
  55. package/packages/core/dist/K_ENT_Entity-4MB7CU4A.js +12 -0
  56. package/packages/core/dist/K_ENT_Entity-DEJGIDGH.js +12 -0
  57. package/packages/core/dist/K_ENT_Entity-FXZO5UZ2.js +12 -0
  58. package/packages/core/dist/K_ENT_Entity-HDSCXC5F.js +12 -0
  59. package/packages/core/dist/K_ENT_Entity-JILABHLW.js +12 -0
  60. package/packages/core/dist/K_ENT_Entity-PQ5MURQY.js +13 -0
  61. package/packages/core/dist/K_ENT_Entity-ROAKDIHW.js +12 -0
  62. package/packages/core/dist/K_ENT_Entity-TBVFSKDV.js +12 -0
  63. package/packages/core/dist/K_ENT_Entity-ZFLKG3JO.js +12 -0
  64. package/packages/core/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW.js +8 -0
  65. package/packages/core/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF.js +110 -0
  66. package/packages/core/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF.js +9 -0
  67. package/packages/core/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X.js +9 -0
  68. package/packages/core/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW.js +8 -0
  69. package/packages/core/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2.js +20 -0
  70. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-4C6GBQAG.js +18 -0
  71. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-6V23A6F6.js +18 -0
  72. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK.js +19 -0
  73. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-DYLLC5G2.js +18 -0
  74. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-F4FOFAUP.js +18 -0
  75. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-FBOXXMI3.js +18 -0
  76. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-Q73BWLNP.js +18 -0
  77. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-QM2C4MVA.js +18 -0
  78. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-QUGI6SMP.js +18 -0
  79. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-RGMTBHNP.js +18 -0
  80. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-RWR7UNDW.js +18 -0
  81. package/packages/core/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7.js +7 -0
  82. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-32MFJJ5Z.js +17 -0
  83. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-4J4CEWRY.js +17 -0
  84. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-A366YHF2.js +17 -0
  85. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-LK4LYJHI.js +17 -0
  86. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU.js +17 -0
  87. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-NW3K63II.js +17 -0
  88. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-QDHTI5ZV.js +17 -0
  89. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-VHCT6VIW.js +17 -0
  90. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-WBRKF24R.js +17 -0
  91. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-XKYQYT6Q.js +17 -0
  92. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-Z2PWZYDZ.js +17 -0
  93. package/packages/core/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5.js +58 -0
  94. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-2EZU7QF4.js +21 -0
  95. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-6G3AQNAV.js +21 -0
  96. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-B2NZMQUG.js +21 -0
  97. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-C2RABMZP.js +21 -0
  98. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-HHE3NZ4F.js +21 -0
  99. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-LHFGR6WK.js +21 -0
  100. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-M74BLM3N.js +21 -0
  101. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-PT6ZA6EA.js +21 -0
  102. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-SP52V3CX.js +21 -0
  103. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF.js +22 -0
  104. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-YNSEUHJJ.js +21 -0
  105. package/packages/core/dist/K_LIB_Krnl_System_Unified_Http_Adapter-M6SBHIVA.js +8 -0
  106. package/packages/core/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG.js +8 -0
  107. package/packages/core/dist/K_LIB_Krnl_Telemetry-77FRZ3KV.js +9 -0
  108. package/packages/core/dist/chunk-33L2J7V7.js +82 -0
  109. package/packages/core/dist/chunk-3ES4K2ZP.js +817 -0
  110. package/packages/core/dist/chunk-3SMHVVLL.js +82 -0
  111. package/packages/core/dist/chunk-3UEZ7JQA.js +4877 -0
  112. package/packages/core/dist/chunk-3XIE6KBD.js +4877 -0
  113. package/packages/core/dist/chunk-46ZLCML6.js +107 -0
  114. package/packages/core/dist/chunk-4UEL3DWJ.js +107 -0
  115. package/packages/core/dist/chunk-54GWZ5PC.js +82 -0
  116. package/packages/core/dist/chunk-6QCYRS5L.js +127 -0
  117. package/packages/core/dist/chunk-6ULMHNXR.js +104 -0
  118. package/packages/core/dist/chunk-7WUETJEV.js +117 -0
  119. package/packages/core/dist/chunk-A5KRAYDB.js +107 -0
  120. package/packages/core/dist/chunk-ANEAZ3PO.js +107 -0
  121. package/packages/core/dist/chunk-BE76RL6F.js +82 -0
  122. package/packages/core/dist/chunk-CIARVYDO.js +107 -0
  123. package/packages/core/dist/chunk-CR2ANE62.js +107 -0
  124. package/packages/core/dist/chunk-DI27MOR7.js +173 -0
  125. package/packages/core/dist/chunk-E6RLFHM5.js +596 -0
  126. package/packages/core/dist/chunk-EELAPMNV.js +4877 -0
  127. package/packages/core/dist/chunk-ENZ2RQVJ.js +107 -0
  128. package/packages/core/dist/chunk-F2U6CX4F.js +4877 -0
  129. package/packages/core/dist/chunk-FKG64OHL.js +82 -0
  130. package/packages/core/dist/chunk-FYAZJYM5.js +772 -0
  131. package/packages/core/dist/chunk-G4NP4RDQ.js +82 -0
  132. package/packages/core/dist/chunk-GADIRLRS.js +473 -0
  133. package/packages/core/dist/chunk-GR6CSLQJ.js +772 -0
  134. package/packages/core/dist/chunk-HDS7AT6O.js +772 -0
  135. package/packages/core/dist/chunk-HIMEZUU2.js +71 -0
  136. package/packages/core/dist/chunk-IB4UHG5I.js +596 -0
  137. package/packages/core/dist/chunk-J7ZYNVRS.js +772 -0
  138. package/packages/core/dist/chunk-JVLZU4K7.js +604 -0
  139. package/packages/core/dist/chunk-JYXXI7Q3.js +82 -0
  140. package/packages/core/dist/chunk-K54K2KZW.js +192 -0
  141. package/packages/core/dist/chunk-K6VHLBNH.js +3316 -0
  142. package/packages/core/dist/chunk-KCBP7ZYA.js +596 -0
  143. package/packages/core/dist/chunk-KFQGP6VL.js +33 -0
  144. package/packages/core/dist/chunk-KIUEUI7K.js +82 -0
  145. package/packages/core/dist/chunk-LB67NIZP.js +949 -0
  146. package/packages/core/dist/chunk-LDTYFUNW.js +596 -0
  147. package/packages/core/dist/chunk-MLVWARD4.js +596 -0
  148. package/packages/core/dist/chunk-MPYVXHKO.js +2777 -0
  149. package/packages/core/dist/chunk-MRQ3MITU.js +772 -0
  150. package/packages/core/dist/chunk-MVUN7I7O.js +107 -0
  151. package/packages/core/dist/chunk-NDDOIRW7.js +596 -0
  152. package/packages/core/dist/chunk-O3KDB5MH.js +3330 -0
  153. package/packages/core/dist/chunk-OEINUDSE.js +400 -0
  154. package/packages/core/dist/chunk-OPDENPT4.js +4877 -0
  155. package/packages/core/dist/chunk-P6XEM2LA.js +429 -0
  156. package/packages/core/dist/chunk-QKMRSQV4.js +82 -0
  157. package/packages/core/dist/chunk-R6CCWALL.js +4877 -0
  158. package/packages/core/dist/chunk-RAMMOO73.js +774 -0
  159. package/packages/core/dist/chunk-S3FTZFG6.js +772 -0
  160. package/packages/core/dist/chunk-T2ZVN434.js +4877 -0
  161. package/packages/core/dist/chunk-TFHLDMIA.js +107 -0
  162. package/packages/core/dist/chunk-TI3QUCIJ.js +107 -0
  163. package/packages/core/dist/chunk-TR2BAIGI.js +107 -0
  164. package/packages/core/dist/chunk-UGVVJKC6.js +4877 -0
  165. package/packages/core/dist/chunk-V2DX7YIU.js +984 -0
  166. package/packages/core/dist/chunk-W4IHYUYD.js +772 -0
  167. package/packages/core/dist/chunk-W6WBG5OY.js +4877 -0
  168. package/packages/core/dist/chunk-WN3M7O7H.js +3312 -0
  169. package/packages/core/dist/chunk-WR3NCU7U.js +4877 -0
  170. package/packages/core/dist/chunk-XC6B6L27.js +82 -0
  171. package/packages/core/dist/chunk-XNSE64ZY.js +3316 -0
  172. package/packages/core/dist/chunk-XROES2WN.js +634 -0
  173. package/packages/core/dist/chunk-XSCKNRCZ.js +5020 -0
  174. package/packages/core/dist/chunk-XVABPAUZ.js +82 -0
  175. package/packages/core/dist/chunk-YOBCB5C5.js +596 -0
  176. package/packages/core/dist/chunk-YUK6Q563.js +666 -0
  177. package/packages/core/dist/chunk-YXGL3ZEU.js +1030 -0
  178. package/packages/core/dist/chunk-ZINJ5OUX.js +596 -0
  179. package/packages/core/dist/chunk-ZPFD4BIQ.js +604 -0
  180. package/packages/core/dist/chunk-ZQZBFG6F.js +4826 -0
  181. package/packages/core/dist/chunk-ZZFRJGXM.js +4877 -0
  182. package/packages/core/dist/index.cjs +760 -0
  183. package/packages/core/dist/index.d.cts +360 -0
  184. package/packages/core/dist/index.d.ts +360 -0
  185. package/packages/core/dist/index.js +707 -0
  186. package/packages/core/package.json +34 -0
  187. package/packages/create-krnl/dist/K_ENT_Entity-PQ5MURQY-R2OH4VXE.js +14 -0
  188. package/packages/create-krnl/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW-AZM5HF4M.js +9 -0
  189. package/packages/create-krnl/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF-X5N6SV2S.js +111 -0
  190. package/packages/create-krnl/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF-5PFHF4JU.js +12 -0
  191. package/packages/create-krnl/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X-ED33OQPH.js +12 -0
  192. package/packages/create-krnl/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW-YGQLVR4P.js +9 -0
  193. package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2-VM7CTU2L.js +21 -0
  194. package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK-Y2GQFJ7I.js +21 -0
  195. package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7-L3JQWO54.js +8 -0
  196. package/packages/create-krnl/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU-KQARASPR.js +19 -0
  197. package/packages/create-krnl/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5-OF3IGLVL.js +59 -0
  198. package/packages/create-krnl/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF-JOLHKOEX.js +24 -0
  199. package/packages/create-krnl/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG-L46LSHKQ.js +10 -0
  200. package/packages/create-krnl/dist/K_LIB_Krnl_Telemetry-77FRZ3KV-4JUPRR3X.js +10 -0
  201. package/packages/create-krnl/dist/chunk-3TRM6CYL.js +152 -0
  202. package/packages/create-krnl/dist/chunk-3URCB3QS.js +127 -0
  203. package/packages/create-krnl/dist/chunk-5JDK35TG.js +3872 -0
  204. package/packages/create-krnl/dist/chunk-A2XAXDOW.js +812 -0
  205. package/packages/create-krnl/dist/chunk-AN6TMQHG.js +1033 -0
  206. package/packages/create-krnl/dist/chunk-BOXWWXQG.js +400 -0
  207. package/packages/create-krnl/dist/chunk-BPTBREBG.js +38 -0
  208. package/packages/create-krnl/dist/chunk-FDNCADFE.js +71 -0
  209. package/packages/create-krnl/dist/chunk-JTLSTO25.js +71 -0
  210. package/packages/create-krnl/dist/chunk-M3NCUIPL.js +107 -0
  211. package/packages/create-krnl/dist/chunk-N2EONSOC.js +7769 -0
  212. package/packages/create-krnl/dist/chunk-OHVMVRBP.js +117 -0
  213. package/packages/create-krnl/dist/chunk-Q45257P6.js +173 -0
  214. package/packages/create-krnl/dist/chunk-QGM4M3NI.js +37 -0
  215. package/packages/create-krnl/dist/chunk-RJNYUXZD.js +977 -0
  216. package/packages/create-krnl/dist/chunk-SRTOPJ5W.js +104 -0
  217. package/packages/create-krnl/dist/chunk-UPBIGEC3.js +666 -0
  218. package/packages/create-krnl/dist/chunk-V2DB7UD7.js +82 -0
  219. package/packages/create-krnl/dist/chunk-WMHLIUI6.js +3644 -0
  220. package/packages/create-krnl/dist/chunk-XIRFOO3H.js +589 -0
  221. package/packages/create-krnl/dist/chunk-Y2CEEVZP.js +5536 -0
  222. package/packages/create-krnl/dist/index.cjs +395 -0
  223. package/packages/create-krnl/dist/index.js +372 -0
  224. package/packages/create-krnl/dist/main-DXUMPBND.js +2217 -0
  225. package/packages/create-krnl/dist/wrapper-SDF2VKX3.js +31 -0
  226. package/packages/create-krnl/package.json +23 -0
  227. package/packages/eslint-plugin/dist/index.cjs +439 -0
  228. package/packages/eslint-plugin/dist/index.d.cts +336 -0
  229. package/packages/eslint-plugin/dist/index.d.ts +336 -0
  230. package/packages/eslint-plugin/dist/index.js +416 -0
  231. package/packages/eslint-plugin/package.json +24 -0
  232. package/packages/validate/dist/index.cjs +499 -0
  233. package/packages/validate/dist/index.d.cts +49 -0
  234. package/packages/validate/dist/index.d.ts +49 -0
  235. package/packages/validate/dist/index.js +462 -0
  236. package/packages/validate/package.json +27 -0
@@ -0,0 +1,701 @@
1
+ // ../validate/dist/index.js
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+ import { Project, SyntaxKind, Node } from "ts-morph";
5
+ var KrnlValidatorEngine = class {
6
+ project;
7
+ projectRoot;
8
+ maxFileLineLimit;
9
+ maxMainLogicLimit;
10
+ maxHelperLineLimit;
11
+ constructor(options) {
12
+ this.projectRoot = path.resolve(options.projectRoot);
13
+ this.maxFileLineLimit = options.maxFileLineLimit ?? 200;
14
+ this.maxMainLogicLimit = options.maxMainLogicLimit ?? 20;
15
+ this.maxHelperLineLimit = options.maxHelperLineLimit ?? 30;
16
+ const tsConfigPath = path.join(this.projectRoot, "tsconfig.json");
17
+ if (fs.existsSync(tsConfigPath)) {
18
+ this.project = new Project({ tsConfigFilePath: tsConfigPath, skipAddingFilesFromTsConfig: true });
19
+ } else {
20
+ this.project = new Project({ compilerOptions: {
21
+ target: 99
22
+ /* ESNext */
23
+ } });
24
+ }
25
+ }
26
+ /**
27
+ * Scans and validates all source files in the project.
28
+ */
29
+ validateAll() {
30
+ const files = this.collectSourceFiles(this.projectRoot);
31
+ const errors = [];
32
+ const warnings = [];
33
+ this.validateWorkspaceLayout(errors);
34
+ for (const f of files) {
35
+ const sf = this.project.addSourceFileAtPath(f);
36
+ const fileReport = this.validateSourceFile(sf);
37
+ errors.push(...fileReport.errors);
38
+ warnings.push(...fileReport.warnings);
39
+ }
40
+ return {
41
+ valid: errors.length === 0,
42
+ totalFiles: files.length,
43
+ errors,
44
+ warnings
45
+ };
46
+ }
47
+ /**
48
+ * Validates a single SourceFile.
49
+ */
50
+ validateSourceFile(sf) {
51
+ const errors = [];
52
+ const warnings = [];
53
+ const filePath = sf.getFilePath();
54
+ const sourceText = sf.getText();
55
+ const baseName = path.basename(filePath);
56
+ if (baseName.includes("_pb.") || baseName.endsWith(".d.ts")) {
57
+ return { errors, warnings };
58
+ }
59
+ const lines = sourceText.split("\n");
60
+ if (lines.length > this.maxFileLineLimit) {
61
+ errors.push({
62
+ ruleId: "krnl/file-line-limit",
63
+ filePath,
64
+ message: `File exceeds maximum length of ${this.maxFileLineLimit} lines (currently ${lines.length} lines). Decompose into sub-components, custom hooks, quad-units, or concept libraries.`,
65
+ severity: "error"
66
+ });
67
+ }
68
+ for (const decl of sf.getImportDeclarations()) {
69
+ const moduleSpec = decl.getModuleSpecifierValue();
70
+ if (moduleSpec.startsWith(".") && !moduleSpec.endsWith(".js") && !moduleSpec.endsWith(".json")) {
71
+ const line = decl.getStartLineNumber();
72
+ errors.push({
73
+ ruleId: "krnl/import-suffix",
74
+ filePath,
75
+ line,
76
+ message: `Relative import '${moduleSpec}' must end with '.js' for NodeNext module resolution.`,
77
+ severity: "error"
78
+ });
79
+ }
80
+ }
81
+ const isUiTopLevel = /^(App|main|index|_app|root)\.(tsx|jsx)$/i.test(baseName);
82
+ const isBackendTopLevel = /^(server|app)\.(ts|js)$/i.test(baseName) && (!filePath.includes("/components/") && !filePath.includes("/entities/") && !filePath.includes("/libraries/"));
83
+ if (isUiTopLevel) {
84
+ const jsxElements = sf.getDescendantsOfKind(SyntaxKind.JsxOpeningElement);
85
+ const jsxSelfClosing = sf.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement);
86
+ const allJsxTags = [...jsxElements, ...jsxSelfClosing];
87
+ for (const jsx of allJsxTags) {
88
+ const tagName = jsx.getTagNameNode().getText();
89
+ if (/^[a-z]/.test(tagName)) {
90
+ errors.push({
91
+ ruleId: "krnl/top-level-purity",
92
+ filePath,
93
+ line: jsx.getStartLineNumber(),
94
+ message: `Top-level file '${baseName}' violates Top-Level Purity Law. Raw JSX/HTML element '<${tagName}>' is strictly forbidden. Top-level files must ONLY import and compose React components.`,
95
+ severity: "error"
96
+ });
97
+ }
98
+ }
99
+ const calls2 = sf.getDescendantsOfKind(SyntaxKind.CallExpression);
100
+ for (const call of calls2) {
101
+ const exprText = call.getExpression().getText();
102
+ if (["useState", "useEffect", "useRef", "useMemo", "useCallback", "useReducer", "useContext", "useLayoutEffect"].includes(exprText) || /^use[A-Z]/.test(exprText) && exprText !== "use") {
103
+ errors.push({
104
+ ruleId: "krnl/top-level-purity",
105
+ filePath,
106
+ line: call.getStartLineNumber(),
107
+ message: `Top-level file '${baseName}' violates Top-Level Purity Law. React hook '${exprText}' is forbidden in top-level files. Encapsulate state and effects inside dedicated component files.`,
108
+ severity: "error"
109
+ });
110
+ }
111
+ }
112
+ }
113
+ if (isBackendTopLevel) {
114
+ const calls2 = sf.getDescendantsOfKind(SyntaxKind.CallExpression);
115
+ for (const call of calls2) {
116
+ const exprText = call.getExpression().getText();
117
+ if (/^(app|router|server)\.(get|post|put|delete|patch|options|head)$/.test(exprText)) {
118
+ errors.push({
119
+ ruleId: "krnl/top-level-purity",
120
+ filePath,
121
+ line: call.getStartLineNumber(),
122
+ message: `Backend entry file '${baseName}' violates Entry Purity Law. Inline route definition '${exprText}' is forbidden. Delegate to dedicated route/controller modules.`,
123
+ severity: "error"
124
+ });
125
+ }
126
+ }
127
+ }
128
+ if (filePath.endsWith(".tsx") || filePath.endsWith(".jsx")) {
129
+ const componentNames = [];
130
+ for (const fn of sf.getFunctions()) {
131
+ const name = fn.getName();
132
+ if (name && /^[A-Z]/.test(name)) {
133
+ const hasJsx = fn.getDescendantsOfKind(SyntaxKind.JsxElement).length > 0 || fn.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement).length > 0 || fn.getDescendantsOfKind(SyntaxKind.JsxFragment).length > 0;
134
+ if (hasJsx) {
135
+ componentNames.push(name);
136
+ }
137
+ }
138
+ }
139
+ for (const stmt of sf.getVariableStatements()) {
140
+ for (const decl of stmt.getDeclarations()) {
141
+ const name = decl.getName();
142
+ if (/^[A-Z]/.test(name)) {
143
+ const typeText = decl.getTypeNode()?.getText() || "";
144
+ const isFcType = typeText.includes("FC") || typeText.includes("FunctionComponent") || typeText.includes("ComponentType");
145
+ const init = decl.getInitializer();
146
+ if (init) {
147
+ const hasJsx = init.getDescendantsOfKind(SyntaxKind.JsxElement).length > 0 || init.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement).length > 0 || init.getDescendantsOfKind(SyntaxKind.JsxFragment).length > 0;
148
+ if (isFcType || hasJsx) {
149
+ if (!componentNames.includes(name)) {
150
+ componentNames.push(name);
151
+ }
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
157
+ for (const cls of sf.getClasses()) {
158
+ const name = cls.getName();
159
+ const ext = cls.getExtends()?.getText() || "";
160
+ if (name && (ext.includes("Component") || ext.includes("PureComponent"))) {
161
+ if (!componentNames.includes(name)) {
162
+ componentNames.push(name);
163
+ }
164
+ }
165
+ }
166
+ if (componentNames.length > 1) {
167
+ errors.push({
168
+ ruleId: "krnl/one-component-per-file",
169
+ filePath,
170
+ message: `File '${baseName}' defines multiple React components (${componentNames.join(", ")}). Krnl strictly enforces ONE component per file. Decompose into sub-component files.`,
171
+ severity: "error"
172
+ });
173
+ }
174
+ }
175
+ const isHelper = filePath.includes("helper_functions") || filePath.includes("/helpers/") || filePath.includes("\\helpers\\");
176
+ const isMainLogic = filePath.endsWith("logic.ts") || filePath.endsWith("logic.js");
177
+ const isRootConcept = filePath.includes("libraries/") || filePath.includes("Concepts.ts");
178
+ if (isHelper) {
179
+ for (const decl of sf.getImportDeclarations()) {
180
+ const spec = decl.getModuleSpecifierValue();
181
+ if (["fs", "node:fs", "http", "node:http", "ws"].includes(spec)) {
182
+ errors.push({
183
+ ruleId: "krnl/helper-purity",
184
+ filePath,
185
+ line: decl.getStartLineNumber(),
186
+ message: `Helper functions (Layer 1) cannot directly import I/O modules ('${spec}'). Delegate to Layer 0 libraries or Entity context.`,
187
+ severity: "error"
188
+ });
189
+ }
190
+ }
191
+ for (const fn of sf.getFunctions()) {
192
+ const fnLines = fn.getText().split("\n").length;
193
+ if (fnLines > this.maxHelperLineLimit && !sourceText.includes("Concepts.")) {
194
+ errors.push({
195
+ ruleId: "krnl/helper-line-limit",
196
+ filePath,
197
+ line: fn.getStartLineNumber(),
198
+ message: `Helper function '${fn.getName() || "anonymous"}' exceeds ${this.maxHelperLineLimit} lines (${fnLines} lines). Must delegate to a root libraries/{Domain}Concepts.ts library.`,
199
+ severity: "error"
200
+ });
201
+ }
202
+ }
203
+ }
204
+ if (isMainLogic) {
205
+ const substantiveLines = lines.filter((l) => {
206
+ const trimmed = l.trim();
207
+ return trimmed.length > 0 && !trimmed.startsWith("//") && !trimmed.startsWith("/*") && !trimmed.startsWith("*");
208
+ });
209
+ if (substantiveLines.length > this.maxMainLogicLimit && !sourceText.includes("helpers") && !sourceText.includes("Concepts") && !sourceText.includes("state")) {
210
+ errors.push({
211
+ ruleId: "krnl/main-delegation",
212
+ filePath,
213
+ message: `Main logic function has ${substantiveLines.length} substantive lines without delegating to Layer 1 helper functions or Layer 0 libraries.`,
214
+ severity: "error"
215
+ });
216
+ }
217
+ }
218
+ if (sourceText.includes("main = async") || sourceText.includes("export const main = async")) {
219
+ const match = sourceText.match(/main\s*=\s*async\s*\([^,]+,\s*\{([^}]*)\}\s*\)/);
220
+ if (match) {
221
+ const destructured = match[1];
222
+ if (/\bsystem\b/.test(destructured) && !/\bentity\b/.test(destructured)) {
223
+ errors.push({
224
+ ruleId: "krnl/context-destructuring",
225
+ filePath,
226
+ message: `Functionality context parameter destructures 'system'. Functionality passes { state, entity }. Always destructure 'entity'.`,
227
+ severity: "error"
228
+ });
229
+ }
230
+ }
231
+ }
232
+ const calls = sf.getDescendantsOfKind(SyntaxKind.CallExpression);
233
+ for (const call of calls) {
234
+ const exprText = call.getExpression().getText();
235
+ if (exprText === "setInterval" || exprText === "window.setInterval") {
236
+ errors.push({
237
+ ruleId: "krnl/no-polling",
238
+ filePath,
239
+ line: call.getStartLineNumber(),
240
+ message: `Prohibited use of 'setInterval'. Krnl applications must use reactive event streams (entity.emitEvent / entity.on).`,
241
+ severity: "error"
242
+ });
243
+ }
244
+ }
245
+ const isEntityClass = sf.getClasses().some((c) => {
246
+ const ext = c.getExtends();
247
+ return ext && (ext.getText().includes("Entity") || ext.getText().includes("krnlEntityBase"));
248
+ });
249
+ if (isEntityClass) {
250
+ for (const decl of sf.getImportDeclarations()) {
251
+ const spec = decl.getModuleSpecifierValue();
252
+ if (spec.includes("libraries/") || spec.includes("Concepts")) {
253
+ errors.push({
254
+ ruleId: "krnl/entity-no-libraries",
255
+ filePath,
256
+ line: decl.getStartLineNumber(),
257
+ message: `Entity class violates Library Calling Invariant. Entities must not call or import libraries directly ('${spec}'). Only functionalities in 'src/functionalities/' are permitted to call shared libraries.`,
258
+ severity: "error"
259
+ });
260
+ }
261
+ }
262
+ let loadAllLine = -1;
263
+ const addLocalLines = [];
264
+ for (const call of calls) {
265
+ const txt = call.getText();
266
+ if (txt.includes("MagneticLoader.loadAll") || txt.includes("KrnlMagneticLoader.loadAll")) {
267
+ loadAllLine = call.getStartLineNumber();
268
+ } else if (txt.startsWith("this.addLocal(")) {
269
+ const hasUiSpec = txt.includes("uiSpec");
270
+ const idMatch = txt.match(/id\s*:\s*["']([^"']+)["']/);
271
+ addLocalLines.push({
272
+ line: call.getStartLineNumber(),
273
+ hasUiSpec,
274
+ id: idMatch ? idMatch[1] : "unknown"
275
+ });
276
+ }
277
+ }
278
+ if (loadAllLine !== -1) {
279
+ for (const al of addLocalLines) {
280
+ if (al.hasUiSpec && al.line > loadAllLine) {
281
+ errors.push({
282
+ ruleId: "krnl/boot-order",
283
+ filePath,
284
+ line: al.line,
285
+ message: `addLocal('${al.id}') with uiSpec at line ${al.line} appears AFTER loadAll() at line ${loadAllLine}. All addLocal() with UI must precede loadAll().`,
286
+ severity: "error"
287
+ });
288
+ }
289
+ }
290
+ }
291
+ for (const cls of sf.getClasses()) {
292
+ const ext = cls.getExtends();
293
+ if (ext && (ext.getText().includes("Entity") || ext.getText().includes("krnlEntityBase"))) {
294
+ const loops = [
295
+ ...cls.getDescendantsOfKind(SyntaxKind.ForStatement),
296
+ ...cls.getDescendantsOfKind(SyntaxKind.ForOfStatement),
297
+ ...cls.getDescendantsOfKind(SyntaxKind.ForInStatement),
298
+ ...cls.getDescendantsOfKind(SyntaxKind.WhileStatement),
299
+ ...cls.getDescendantsOfKind(SyntaxKind.DoStatement)
300
+ ];
301
+ for (const loop of loops) {
302
+ errors.push({
303
+ ruleId: "krnl/entity-purity",
304
+ filePath,
305
+ line: loop.getStartLineNumber(),
306
+ message: `Entity '${cls.getName() || "Anonymous"}' violates Entity Purity Law. Loops and procedural algorithms are prohibited inside entities. Move logic to a functionality or a global library function.`,
307
+ severity: "error"
308
+ });
309
+ }
310
+ for (const method of cls.getMethods()) {
311
+ const methodName = method.getName();
312
+ if (!["boot", "init", "dispose"].includes(methodName)) {
313
+ errors.push({
314
+ ruleId: "krnl/entity-purity",
315
+ filePath,
316
+ line: method.getStartLineNumber(),
317
+ message: `Entity '${cls.getName() || "Anonymous"}' defines custom method '${methodName}'. Entities are purely declarative compositors/orchestrators. Define capabilities as functionalities or global library functions.`,
318
+ severity: "error"
319
+ });
320
+ }
321
+ }
322
+ }
323
+ }
324
+ for (const call of calls) {
325
+ const callText = call.getText();
326
+ if (callText.startsWith("this.orchestration(") || callText.startsWith("this.flow(")) {
327
+ let currentExpr = call;
328
+ const chainCalls = [];
329
+ while (currentExpr && Node.isCallExpression(currentExpr)) {
330
+ const propAccess = currentExpr.getExpression();
331
+ if (Node.isPropertyAccessExpression(propAccess)) {
332
+ const methodName = propAccess.getName();
333
+ const args = currentExpr.getArguments();
334
+ const argText = args.length > 0 ? args[0].getText() : void 0;
335
+ chainCalls.unshift({ name: methodName, node: currentExpr, argText });
336
+ currentExpr = propAccess.getExpression();
337
+ } else {
338
+ break;
339
+ }
340
+ }
341
+ let consecutiveFunctions = 0;
342
+ let chainId = "orchestration";
343
+ for (const step of chainCalls) {
344
+ if (step.name === "orchestration" || step.name === "flow") {
345
+ chainId = step.argText ? step.argText.replace(/['"]/g, "") : "orchestration";
346
+ } else if (step.name === "thenFunctionality" || step.name === "then") {
347
+ consecutiveFunctions = 0;
348
+ } else if (step.name === "thenEntityOrchestration" || step.name === "thenEntity") {
349
+ consecutiveFunctions = 0;
350
+ } else if (step.name === "thenFunction") {
351
+ errors.push({
352
+ ruleId: "krnl/entity-no-direct-library-calls",
353
+ filePath,
354
+ line: step.node.getStartLineNumber(),
355
+ message: `Orchestration chain '${chainId}' violates Entity Purity Law. Entities cannot chain direct library functions via thenFunction(). Entities must only orchestrate functionalities (thenFunctionality) and orchestrations from other entities (thenEntityOrchestration).`,
356
+ severity: "error"
357
+ });
358
+ }
359
+ }
360
+ }
361
+ }
362
+ }
363
+ return { errors, warnings };
364
+ }
365
+ /**
366
+ * Validates workspace layout invariants for flat multi-entity architecture.
367
+ */
368
+ validateWorkspaceLayout(errors) {
369
+ const srcDir = path.join(this.projectRoot, "src");
370
+ if (!fs.existsSync(srcDir)) return;
371
+ const entitiesDir = path.join(srcDir, "entities");
372
+ if (fs.existsSync(entitiesDir)) {
373
+ errors.push({
374
+ ruleId: "krnl/flat-multi-entity",
375
+ filePath: entitiesDir,
376
+ message: `Nested 'src/entities/' directory detected. Krnl enforces a flat multi-entity architecture where all entities are placed directly inside 'src/' at the same level.`,
377
+ severity: "error"
378
+ });
379
+ }
380
+ const entries = fs.readdirSync(srcDir, { withFileTypes: true });
381
+ for (const entry of entries) {
382
+ if (!entry.isDirectory()) continue;
383
+ if (["functionalities", "libraries", "protocol_adapters", "node_modules", "dist", ".git", "subapps"].includes(entry.name)) continue;
384
+ const subDir = path.join(srcDir, entry.name);
385
+ const nestedEntities = path.join(subDir, "entities");
386
+ if (fs.existsSync(nestedEntities)) {
387
+ errors.push({
388
+ ruleId: "krnl/flat-multi-entity",
389
+ filePath: nestedEntities,
390
+ message: `Directory '${entry.name}' contains a nested 'entities/' folder. Nested component entities are prohibited. Place all entities directly inside 'src/' at the same level.`,
391
+ severity: "error"
392
+ });
393
+ }
394
+ const nestedFuncs = path.join(subDir, "functionalities");
395
+ if (fs.existsSync(nestedFuncs)) {
396
+ errors.push({
397
+ ruleId: "krnl/shared-functionalities",
398
+ filePath: nestedFuncs,
399
+ message: `Directory '${entry.name}' contains a nested 'functionalities/' folder. All functionalities must reside in the shared 'src/functionalities/<FunctionalityName>/' directory.`,
400
+ severity: "error"
401
+ });
402
+ }
403
+ }
404
+ }
405
+ collectSourceFiles(dir, collected = []) {
406
+ if (!fs.existsSync(dir)) return collected;
407
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
408
+ for (const entry of entries) {
409
+ if (entry.name === "node_modules" || entry.name === "dist" || entry.name === ".git") continue;
410
+ const full = path.join(dir, entry.name);
411
+ if (entry.isDirectory()) {
412
+ this.collectSourceFiles(full, collected);
413
+ } else if (entry.isFile() && (entry.name.endsWith(".ts") || entry.name.endsWith(".js") || entry.name.endsWith(".tsx") || entry.name.endsWith(".jsx"))) {
414
+ collected.push(full);
415
+ }
416
+ }
417
+ return collected;
418
+ }
419
+ };
420
+
421
+ // src/commands/validate.ts
422
+ async function runValidate(projectRoot = process.cwd()) {
423
+ console.log(`
424
+ \u{1F50D} [Krnl Validate] Scanning project at: ${projectRoot}
425
+ `);
426
+ const validator = new KrnlValidatorEngine({ projectRoot });
427
+ const report = validator.validateAll();
428
+ if (report.warnings.length > 0) {
429
+ console.warn(`\u26A0\uFE0F [WARNINGS] Found ${report.warnings.length} warning(s):`);
430
+ for (const w of report.warnings) {
431
+ console.warn(` - [${w.ruleId}] ${w.filePath}${w.line ? `:${w.line}` : ""}: ${w.message}`);
432
+ }
433
+ }
434
+ if (!report.valid) {
435
+ console.error(`
436
+ \u274C [VALIDATION FAILED] Found ${report.errors.length} error(s):
437
+ `);
438
+ for (const err of report.errors) {
439
+ console.error(` \u274C [${err.ruleId}] ${err.filePath}${err.line ? `:${err.line}` : ""}`);
440
+ console.error(` ${err.message}
441
+ `);
442
+ }
443
+ return false;
444
+ }
445
+ console.log(`\u2705 [VALIDATION PASSED] ${report.totalFiles} source files verified clean against Krnl paradigms.
446
+ `);
447
+ return true;
448
+ }
449
+
450
+ // src/commands/generate.ts
451
+ import * as fs2 from "fs";
452
+ import * as path2 from "path";
453
+ async function runGenerate(type, name, _parentEntity, projectRoot = process.cwd()) {
454
+ if (!name) {
455
+ console.error("\u274C Error: Resource name is required. Usage: krnl generate <entity|functionality|library|subapp> <Name>");
456
+ process.exit(1);
457
+ }
458
+ switch (type.toLowerCase()) {
459
+ case "entity":
460
+ generateEntity(name, projectRoot);
461
+ break;
462
+ case "functionality":
463
+ generateFunctionality(name, projectRoot);
464
+ break;
465
+ case "library":
466
+ generateLibrary(name, projectRoot);
467
+ break;
468
+ case "subapp":
469
+ generateSubApp(name, projectRoot);
470
+ break;
471
+ default:
472
+ console.error(`\u274C Unknown resource type '${type}'. Valid types: entity, functionality, library, subapp`);
473
+ process.exit(1);
474
+ }
475
+ }
476
+ function generateEntity(name, projectRoot) {
477
+ const srcDir = path2.join(projectRoot, "src");
478
+ fs2.mkdirSync(srcDir, { recursive: true });
479
+ const entityFile = path2.join(srcDir, `${name}.ts`);
480
+ const content = `import { Entity, KrnlMagneticLoader } from '@dinilmusick/krnl-core';
481
+
482
+ export class ${name} extends Entity {
483
+ constructor() {
484
+ super({
485
+ id: '${name}',
486
+ version: '1.0.0',
487
+ description: '${name} entity'
488
+ });
489
+ }
490
+
491
+ async boot(): Promise<void> {
492
+ // Magnetic auto-discovery of shared functionalities and protocol adapters
493
+ await KrnlMagneticLoader.loadAll(this, import.meta.url);
494
+ }
495
+ }
496
+
497
+ export default ${name};
498
+ `;
499
+ fs2.writeFileSync(entityFile, content);
500
+ console.log(`\u2705 Created Flat Entity: src/${name}.ts`);
501
+ }
502
+ function generateFunctionality(name, projectRoot) {
503
+ const funcDir = path2.join(projectRoot, "src", "functionalities", name);
504
+ fs2.mkdirSync(path2.join(funcDir, "main_function"), { recursive: true });
505
+ fs2.mkdirSync(path2.join(funcDir, "state_data"), { recursive: true });
506
+ fs2.mkdirSync(path2.join(funcDir, "helper_functions"), { recursive: true });
507
+ fs2.mkdirSync(path2.join(funcDir, "events"), { recursive: true });
508
+ fs2.writeFileSync(path2.join(funcDir, `${name}Atom.ts`), `export interface ${name}Input {
509
+ message?: string;
510
+ }
511
+
512
+ export interface ${name}Output {
513
+ success: boolean;
514
+ timestamp: number;
515
+ }
516
+ `);
517
+ fs2.writeFileSync(path2.join(funcDir, "main_function", "logic.ts"), `import { ${name}Input, ${name}Output } from '../${name}Atom.js';
518
+ import { formatTimestamp } from '../helper_functions/formatTimestamp.js';
519
+
520
+ export const main = async (input: ${name}Input, { state, entity }: any): Promise<${name}Output> => {
521
+ const timestamp = formatTimestamp();
522
+ return {
523
+ success: true,
524
+ timestamp
525
+ };
526
+ };
527
+ `);
528
+ fs2.writeFileSync(path2.join(funcDir, "state_data", "state.ts"), `export interface ${name}State {
529
+ executionCount: number;
530
+ }
531
+
532
+ export const initialState: ${name}State = {
533
+ executionCount: 0
534
+ };
535
+ `);
536
+ fs2.writeFileSync(path2.join(funcDir, "helper_functions", "formatTimestamp.ts"), `export function formatTimestamp(): number {
537
+ return Date.now();
538
+ }
539
+ `);
540
+ console.log(`\u2705 Created Shared Quad-Unit Functionality: src/functionalities/${name}/`);
541
+ }
542
+ function generateLibrary(name, projectRoot) {
543
+ const libDir = path2.join(projectRoot, "src", "libraries");
544
+ fs2.mkdirSync(libDir, { recursive: true });
545
+ const fileName = `${name}Concepts.ts`;
546
+ fs2.writeFileSync(path2.join(libDir, fileName), `/**
547
+ * @file ${fileName}
548
+ * @role component
549
+ * @description Layer 0 pure domain concept library for ${name}.
550
+ */
551
+
552
+ export class ${name}Concepts {
553
+ static pureTransform<T>(data: T): T {
554
+ return data;
555
+ }
556
+ }
557
+ `);
558
+ console.log(`\u2705 Created Domain Concept Library: src/libraries/${fileName}`);
559
+ }
560
+ function generateSubApp(name, projectRoot) {
561
+ const subappDir = path2.join(projectRoot, "src", "subapps", name);
562
+ fs2.mkdirSync(subappDir, { recursive: true });
563
+ fs2.writeFileSync(path2.join(subappDir, "subapp.json"), JSON.stringify({
564
+ name,
565
+ version: "1.0.0",
566
+ description: `${name} self-contained sub-app`,
567
+ registrationEntry: "./register.js"
568
+ }, null, 2));
569
+ fs2.writeFileSync(path2.join(subappDir, "register.ts"), `export function register(context: any) {
570
+ context.logger.log('Registering ${name} sub-app');
571
+ return {
572
+ name: '${name}',
573
+ operations: []
574
+ };
575
+ }
576
+ export default register;
577
+ `);
578
+ console.log(`\u2705 Created Sub-App: src/subapps/${name}/`);
579
+ }
580
+
581
+ // src/commands/watch.ts
582
+ import * as fs3 from "fs";
583
+ import * as path3 from "path";
584
+ function generateMagneticDeclarations(projectRoot = process.cwd()) {
585
+ const { results: functionalities, libDirs } = scanDirectory(projectRoot);
586
+ let dtsContent = `// Automatically generated by Krnl Magnetic Watcher. Do not edit manually.
587
+
588
+ `;
589
+ dtsContent += `import { Entity } from '@dinilmusick/krnl-core';
590
+
591
+ `;
592
+ const globalDeclarations = [];
593
+ for (const func of functionalities) {
594
+ const helpersDir = path3.join(func.funcPath, "helper_functions");
595
+ if (fs3.existsSync(helpersDir)) {
596
+ const files = fs3.readdirSync(helpersDir);
597
+ for (const file of files) {
598
+ if (file.endsWith(".js") || file.endsWith(".ts")) {
599
+ const filePath = path3.join(helpersDir, file);
600
+ const baseName = path3.basename(file, path3.extname(file));
601
+ const importPath = `./${path3.relative(projectRoot, filePath).replace(/\\/g, "/")}`;
602
+ const { named, hasDefault } = parseExports(filePath, baseName);
603
+ if (hasDefault) {
604
+ globalDeclarations.push(` const ${baseName}: typeof import('${importPath}')['default'];`);
605
+ }
606
+ for (const name of named) {
607
+ globalDeclarations.push(` const ${name}: typeof import('${importPath}')['${name}'];`);
608
+ }
609
+ }
610
+ }
611
+ }
612
+ const eventsDir = path3.join(func.funcPath, "events");
613
+ if (fs3.existsSync(eventsDir)) {
614
+ const files = fs3.readdirSync(eventsDir);
615
+ for (const file of files) {
616
+ if (file.endsWith(".js") || file.endsWith(".ts")) {
617
+ const filePath = path3.join(eventsDir, file);
618
+ const baseName = path3.basename(file, path3.extname(file));
619
+ const importPath = `./${path3.relative(projectRoot, filePath).replace(/\\/g, "/")}`;
620
+ const { named, hasDefault } = parseExports(filePath, baseName);
621
+ if (hasDefault) {
622
+ globalDeclarations.push(` const ${baseName}: typeof import('${importPath}')['default'];`);
623
+ }
624
+ for (const name of named) {
625
+ globalDeclarations.push(` const ${name}: typeof import('${importPath}')['${name}'];`);
626
+ }
627
+ }
628
+ }
629
+ }
630
+ }
631
+ for (const libPath of libDirs) {
632
+ scanLibFiles(libPath, projectRoot, globalDeclarations);
633
+ }
634
+ if (globalDeclarations.length > 0) {
635
+ dtsContent += `declare global {
636
+ ${Array.from(new Set(globalDeclarations)).join("\n")}
637
+ }
638
+ `;
639
+ }
640
+ const outPath = path3.join(projectRoot, "krnl-magnetic.d.ts");
641
+ fs3.writeFileSync(outPath, dtsContent);
642
+ console.log(`[Krnl Watch] Updated ambient declarations: ${outPath}`);
643
+ }
644
+ function scanLibFiles(dir, projectRoot, decls) {
645
+ if (!fs3.existsSync(dir)) return;
646
+ for (const entry of fs3.readdirSync(dir, { withFileTypes: true })) {
647
+ if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
648
+ const full = path3.join(dir, entry.name);
649
+ if (entry.isDirectory()) {
650
+ scanLibFiles(full, projectRoot, decls);
651
+ } else if ((entry.name.endsWith(".ts") || entry.name.endsWith(".js")) && !entry.name.endsWith(".d.ts")) {
652
+ const baseName = path3.basename(entry.name, path3.extname(entry.name));
653
+ const importPath = `./${path3.relative(projectRoot, full).replace(/\\/g, "/")}`;
654
+ const { named, hasDefault } = parseExports(full, baseName);
655
+ if (hasDefault) decls.push(` const ${baseName}: typeof import('${importPath}')['default'];`);
656
+ for (const n of named) decls.push(` const ${n}: typeof import('${importPath}')['${n}'];`);
657
+ }
658
+ }
659
+ }
660
+ function scanDirectory(dir, results = [], libDirs = []) {
661
+ if (!fs3.existsSync(dir)) return { results, libDirs };
662
+ const list = fs3.readdirSync(dir, { withFileTypes: true });
663
+ for (const entry of list) {
664
+ if (entry.isDirectory()) {
665
+ if (entry.name === "node_modules" || entry.name === "dist" || entry.name === ".git") continue;
666
+ const fullPath = path3.join(dir, entry.name);
667
+ if (entry.name === "functionalities") {
668
+ const funcs = fs3.readdirSync(fullPath, { withFileTypes: true });
669
+ for (const f of funcs) {
670
+ if (f.isDirectory()) results.push({ funcPath: path3.join(fullPath, f.name), funcName: f.name });
671
+ }
672
+ } else if (entry.name === "libraries" || entry.name === "library") {
673
+ libDirs.push(fullPath);
674
+ } else {
675
+ scanDirectory(fullPath, results, libDirs);
676
+ }
677
+ }
678
+ }
679
+ return { results, libDirs };
680
+ }
681
+ function parseExports(filePath, defaultName) {
682
+ const content = fs3.readFileSync(filePath, "utf8");
683
+ const named = [];
684
+ let hasDefault = false;
685
+ const namedRegex = /export\s+(?:const|let|var|function|class|async\s+function)\s+([a-zA-Z0-9_$]+)/g;
686
+ let match;
687
+ while ((match = namedRegex.exec(content)) !== null) {
688
+ if (match[1]) named.push(match[1]);
689
+ }
690
+ if (content.includes("export default")) {
691
+ hasDefault = true;
692
+ }
693
+ return { named, hasDefault };
694
+ }
695
+
696
+ export {
697
+ KrnlValidatorEngine,
698
+ runValidate,
699
+ runGenerate,
700
+ generateMagneticDeclarations
701
+ };