@ultrst-armada/krnl 0.0.0-stage → 1.0.0

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 +84 -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 +757 -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 +704 -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,772 @@
1
+ import {
2
+ krnlEntityBase,
3
+ krnlLocalFunctionality
4
+ } from "./chunk-MPYVXHKO.js";
5
+ import {
6
+ ObjectKit
7
+ } from "./chunk-MLVWARD4.js";
8
+ import {
9
+ KrnlSubAppDiscovery,
10
+ KrnlSubAppLifecycle,
11
+ KrnlSubAppValidator
12
+ } from "./chunk-OEINUDSE.js";
13
+
14
+ // src/core/K_LIB_Krnl_Flow.ts
15
+ var KrnlFlowBuilder = class _KrnlFlowBuilder {
16
+ entity;
17
+ id;
18
+ steps = [];
19
+ constructor(entity, id) {
20
+ this.entity = entity;
21
+ this.id = id;
22
+ }
23
+ /** Sequential: output of previous step is passed as input to fid */
24
+ then(fid) {
25
+ this.steps.push({ type: "seq", fid });
26
+ return this;
27
+ }
28
+ /** Branch: predicate on current output routes to trueFid or falseFid */
29
+ branch(pred, trueFid, falseFid) {
30
+ this.steps.push({ type: "branch", pred, trueFid, falseFid });
31
+ return this;
32
+ }
33
+ /** Parallel: run all fids concurrently with current input, collect results as array */
34
+ parallel(...fids) {
35
+ this.steps.push({ type: "parallel", fids });
36
+ return this;
37
+ }
38
+ /**
39
+ * Register this flow as a krnlLocalFunctionality on the host entity.
40
+ * The Flow becomes a first-class capability on the entity.
41
+ */
42
+ register(opts) {
43
+ const steps = [...this.steps];
44
+ const entity = this.entity;
45
+ const flowId = this.id;
46
+ return entity.addLocal({
47
+ id: flowId,
48
+ visibility: opts?.visibility ?? "public",
49
+ description: opts?.description || `Flow [${flowId}] composing [${steps.map((s) => s.fid || (s.fids ? s.fids.join(",") : "branch")).join(" \u2192 ")}]`,
50
+ uiSpec: opts?.uiSpec,
51
+ intelligenceSpec: opts?.intelligenceSpec,
52
+ manifest: opts?.manifest,
53
+ api: async (input) => _KrnlFlowBuilder._execute(entity, steps, input)
54
+ });
55
+ }
56
+ /** Execute the flow directly without registering as a functionality */
57
+ async run(input) {
58
+ return _KrnlFlowBuilder._execute(this.entity, this.steps, input);
59
+ }
60
+ /**
61
+ * Internal step executor walking the entity's functionalities via `entity.call(fid, input)`.
62
+ */
63
+ static async _execute(entity, steps, input) {
64
+ let current = input;
65
+ for (const step of steps) {
66
+ if (step.type === "seq") {
67
+ current = await entity.call(step.fid, current);
68
+ } else if (step.type === "branch") {
69
+ const matches = step.pred ? step.pred(current) : Boolean(current);
70
+ const targetFid = matches ? step.trueFid : step.falseFid;
71
+ if (targetFid) {
72
+ current = await entity.call(targetFid, current);
73
+ }
74
+ } else if (step.type === "parallel") {
75
+ const fids = step.fids || [];
76
+ current = await Promise.all(fids.map((fid) => entity.call(fid, current)));
77
+ }
78
+ }
79
+ return current;
80
+ }
81
+ };
82
+
83
+ // src/core/K_ENT_Entity.ts
84
+ var Entity = class _Entity extends krnlEntityBase {
85
+ /** Strongly-typed reactive entity state */
86
+ state;
87
+ /** True while this entity occupies root position and actively self-hosts protocol adapters */
88
+ _selfHosting = false;
89
+ /** Protocol adapters attached to this entity. Operational only in root position. */
90
+ _protocolAdapters = /* @__PURE__ */ new Map();
91
+ /** Sub-Apps registered directly under this entity */
92
+ _subApps = /* @__PURE__ */ new Map();
93
+ /** Reservation state for access control and mutual exclusion */
94
+ reservation = {
95
+ busy: false,
96
+ reservedBy: null,
97
+ reservedAt: null
98
+ };
99
+ /** Discoverability state for network beacons / registries */
100
+ discoverable = true;
101
+ constructor(name, owner = null, options = {}) {
102
+ super(name, owner, options);
103
+ this.systemType = "Entity";
104
+ this.state = options.initialState ?? {};
105
+ }
106
+ /**
107
+ * Get an immutable, read-only snapshot of current entity state.
108
+ */
109
+ getState() {
110
+ return Object.freeze(ObjectKit.deepClone(this.state));
111
+ }
112
+ /**
113
+ * Mutates the entity state via deep-merge and emits a reactive state:changed event.
114
+ */
115
+ setState(mutation) {
116
+ this.state = ObjectKit.deepMerge(this.state, mutation);
117
+ this.emit("state:changed", {
118
+ entity: this.entityName,
119
+ delta: mutation,
120
+ state: this.getState()
121
+ });
122
+ }
123
+ /**
124
+ * Resets entity state to a new or initial baseline.
125
+ */
126
+ resetState(newState) {
127
+ this.state = newState ?? {};
128
+ this.emit("state:reset", {
129
+ entity: this.entityName,
130
+ state: this.getState()
131
+ });
132
+ }
133
+ /** Private cache mapping event names to krnlEmitters */
134
+ _eventEmitterMap = /* @__PURE__ */ new Map();
135
+ /**
136
+ * Subscribes a listener to a domain event on this entity.
137
+ */
138
+ on(event, handler) {
139
+ let emitter = this._eventEmitterMap.get(event);
140
+ if (!emitter) {
141
+ emitter = this.interface.createEmitter(event);
142
+ this._eventEmitterMap.set(event, emitter);
143
+ }
144
+ return emitter.subscribe((msg) => handler(msg.data));
145
+ }
146
+ /**
147
+ * Emits an event with a data payload to all subscribers.
148
+ */
149
+ emit(event, payload) {
150
+ let emitter = this._eventEmitterMap.get(event);
151
+ if (!emitter) {
152
+ emitter = this.interface.createEmitter(event);
153
+ this._eventEmitterMap.set(event, emitter);
154
+ }
155
+ emitter.pushDataStreamToEmitter(payload);
156
+ }
157
+ /**
158
+ * Dispatches a strongly-typed domain event.
159
+ */
160
+ emitEvent(event, payload) {
161
+ this.emit(String(event), payload);
162
+ }
163
+ /**
164
+ * System flags representing discoverability and reservation status.
165
+ */
166
+ getSystemFlags() {
167
+ return {
168
+ discoverable: this.discoverable,
169
+ busy: this.reservation.busy,
170
+ reservedBy: this.reservation.reservedBy,
171
+ reservedAt: this.reservation.reservedAt
172
+ };
173
+ }
174
+ /**
175
+ * Set discoverability status.
176
+ */
177
+ setDiscoverable(value) {
178
+ this.discoverable = Boolean(value);
179
+ return this.getSystemFlags();
180
+ }
181
+ /**
182
+ * Reserve this entity for exclusive access by serviceName.
183
+ */
184
+ reserveFor(serviceName = "unknown") {
185
+ this.reservation = {
186
+ busy: true,
187
+ reservedBy: serviceName,
188
+ reservedAt: Date.now()
189
+ };
190
+ return this.getSystemFlags();
191
+ }
192
+ /**
193
+ * Release reservation held by serviceName.
194
+ */
195
+ releaseReservation(serviceName = null) {
196
+ if (serviceName && this.reservation.reservedBy && this.reservation.reservedBy !== serviceName) {
197
+ throw new Error(
198
+ `[${this.entityName}] Reservation owned by ${this.reservation.reservedBy}; cannot release as ${serviceName}.`
199
+ );
200
+ }
201
+ this.reservation = {
202
+ busy: false,
203
+ reservedBy: null,
204
+ reservedAt: null
205
+ };
206
+ return this.getSystemFlags();
207
+ }
208
+ /**
209
+ * Guard checking if entity is available for remote caller.
210
+ */
211
+ _assertAvailableForRemoteAccess(requester = null) {
212
+ if (!this.reservation.busy) return;
213
+ if (requester && requester === this.reservation.reservedBy) return;
214
+ const by = this.reservation.reservedBy || "another service";
215
+ throw new Error(`[${this.entityName}] Entity is busy/reserved by ${by}.`);
216
+ }
217
+ /**
218
+ * Get dynamic manifest of all capabilities, flags, and endpoints.
219
+ */
220
+ getManifest() {
221
+ const apiNames = [];
222
+ const eventsNames = [];
223
+ const api = {};
224
+ for (const [id, f] of this.localFunctionalities) {
225
+ apiNames.push(id);
226
+ api[id] = {
227
+ id,
228
+ type: "local",
229
+ visibility: f.visibility || "public",
230
+ manifest: f.manifest || null,
231
+ schema: f.schema || null
232
+ };
233
+ }
234
+ for (const [id, f] of this.remoteFunctionalities) {
235
+ apiNames.push(id);
236
+ api[id] = {
237
+ id,
238
+ type: "remote",
239
+ visibility: f.visibility || "public",
240
+ schema: f.schema || null
241
+ };
242
+ }
243
+ return {
244
+ entity: this.entityName,
245
+ entityName: this.entityName,
246
+ type: this.systemType,
247
+ flags: this.getSystemFlags(),
248
+ apiNames,
249
+ eventsNames,
250
+ api,
251
+ inputs: {
252
+ api
253
+ }
254
+ };
255
+ }
256
+ /**
257
+ * Generates a structured 404 response payload for unmatched routes.
258
+ */
259
+ getNotFoundResponse(reqPath) {
260
+ return {
261
+ status: "error",
262
+ message: `Route not found: ${reqPath}`,
263
+ entity: this.entityName,
264
+ availableRoutes: [
265
+ "/call/:fid",
266
+ "/mcp",
267
+ "/acp",
268
+ "/manifest",
269
+ "/health",
270
+ "/events/:fid"
271
+ ]
272
+ };
273
+ }
274
+ // ── Protocol Adapter Management ──────────────────────────────────────────
275
+ /**
276
+ * Attach a protocol adapter to this entity (declarative step during discovery/construction).
277
+ * Does NOT start the server. Servers are started only during `finalize()` if this entity is root.
278
+ */
279
+ attachAdapter(adapter) {
280
+ if (!adapter || !adapter.name) {
281
+ throw new Error(`[Entity:${this.id}] Invalid protocol adapter provided.`);
282
+ }
283
+ this._protocolAdapters.set(adapter.name, adapter);
284
+ }
285
+ /**
286
+ * Return all attached protocol adapters.
287
+ */
288
+ getAdapters() {
289
+ return Array.from(this._protocolAdapters.values());
290
+ }
291
+ /**
292
+ * Get a specific protocol adapter by name (e.g. 'https', 'wss').
293
+ */
294
+ getAdapter(name) {
295
+ return this._protocolAdapters.get(name);
296
+ }
297
+ /**
298
+ * Access the WebSocket commComponent adapter if attached.
299
+ */
300
+ get commComponent() {
301
+ return this._protocolAdapters.get("wss");
302
+ }
303
+ /**
304
+ * Access the Unified HTTP adapter if attached.
305
+ */
306
+ get unifiedHttpAdapter() {
307
+ return this._protocolAdapters.get("https");
308
+ }
309
+ /**
310
+ * Port of active listening adapter.
311
+ */
312
+ get commPort() {
313
+ const http = this._protocolAdapters.get("https");
314
+ if (http && typeof http.port === "number") return http.port;
315
+ const wss = this._protocolAdapters.get("wss");
316
+ if (wss && typeof wss.listenPort === "number") return wss.listenPort;
317
+ return 10099;
318
+ }
319
+ // ── Activation / Finalize Lifecycle ──────────────────────────────────────
320
+ /**
321
+ * Finalizes construction and activates the entity if it occupies root position.
322
+ * Called after tree construction and Shell materialization.
323
+ */
324
+ async finalize(options = {}) {
325
+ const hasParent = Boolean(this.hierarchyManager.getOwnerEntity());
326
+ if (!hasParent && this._protocolAdapters.size > 0 && !this._selfHosting) {
327
+ await this._startHosting(options);
328
+ }
329
+ }
330
+ /**
331
+ * Starts all attached protocol adapters.
332
+ */
333
+ async _startHosting(options = {}) {
334
+ if (this._selfHosting) return;
335
+ for (const adapter of this._protocolAdapters.values()) {
336
+ try {
337
+ await adapter.start(this, options);
338
+ } catch (err) {
339
+ console.error(`[Entity:${this.id}] Error starting adapter '${adapter.name}':`, err.message || err);
340
+ throw err;
341
+ }
342
+ }
343
+ this._selfHosting = true;
344
+ }
345
+ /**
346
+ * Stops all self-hosted protocol adapters gracefully.
347
+ */
348
+ async stopHosting() {
349
+ if (!this._selfHosting) return;
350
+ for (const adapter of this._protocolAdapters.values()) {
351
+ try {
352
+ await adapter.stop();
353
+ } catch (err) {
354
+ console.warn(`[Entity:${this.id}] Warning stopping adapter '${adapter.name}':`, err.message || err);
355
+ }
356
+ }
357
+ this._selfHosting = false;
358
+ }
359
+ // ── Root / Child Bidirectional State Machine ─────────────────────────────
360
+ /**
361
+ * Lifecycle hook: called when this entity is adopted as a child component by a parent entity.
362
+ * Action: Relinquish root position duties by stopping any self-hosted servers.
363
+ * Note: Capability bubbling is handled automatically by the hierarchy manager.
364
+ */
365
+ async _onAdoptedByParent() {
366
+ if (this._selfHosting) {
367
+ this._selfHosting = false;
368
+ await this.stopHosting();
369
+ }
370
+ }
371
+ /**
372
+ * Lifecycle hook: called when this entity is detached or promoted to root position.
373
+ * Action: If no parent and adapters exist, activate self-hosting.
374
+ */
375
+ async _onPromotedToRoot(options = {}) {
376
+ const hasParent = Boolean(this.hierarchyManager.getOwnerEntity());
377
+ if (!hasParent && this._protocolAdapters.size > 0 && !this._selfHosting) {
378
+ await this._startHosting(options);
379
+ }
380
+ }
381
+ // ── Capability Surface & Bubbling Integration ────────────────────────────
382
+ /**
383
+ * Overrides component functionality addition to notify active protocol adapters.
384
+ */
385
+ _onComponentFunctionalityAdded(component, functionality) {
386
+ super._onComponentFunctionalityAdded(component, functionality);
387
+ if (this._selfHosting) {
388
+ this._notifyAdaptersOfSurfaceChange();
389
+ }
390
+ }
391
+ /**
392
+ * Notifies all attached protocol adapters that the exposed capability surface has changed.
393
+ * Idempotent: adapters diff and reconcile their route mappings.
394
+ */
395
+ _notifyAdaptersOfSurfaceChange() {
396
+ for (const adapter of this._protocolAdapters.values()) {
397
+ try {
398
+ adapter.onCapabilitySurfaceChanged(this);
399
+ } catch (err) {
400
+ console.warn(`[Entity:${this.id}] Adapter '${adapter.name}' surface change notification error:`, err.message || err);
401
+ }
402
+ }
403
+ }
404
+ // ── Qualified Capability Projections & Resolution ────────────────────────
405
+ /**
406
+ * Computes the hierarchical qualified ID for a local functionality ID.
407
+ * e.g. "Root.OrderService.settings"
408
+ */
409
+ getQualifiedId(fid) {
410
+ const parent = this.hierarchyManager.getOwnerEntity();
411
+ if (parent && typeof parent.getQualifiedId === "function") {
412
+ return `${parent.getQualifiedId(this.id)}.${fid}`;
413
+ }
414
+ return `${this.id}.${fid}`;
415
+ }
416
+ /**
417
+ * Resolves an external qualified capability ID to the owning Entity instance and local fid.
418
+ * The caller/adapter invokes:
419
+ * const res = root.resolveCapability("Root.OrderService.settings");
420
+ * return await res.owner.call(res.fid, input);
421
+ */
422
+ resolveCapability(qualifiedId) {
423
+ return this._resolveCapabilityRecursive(qualifiedId);
424
+ }
425
+ _resolveCapabilityRecursive(qualifiedId) {
426
+ for (const [fid, func] of this.localFunctionalities) {
427
+ if (func.visibility === "public" || func.visibility === "protected" || !func.visibility) {
428
+ if (this.getQualifiedId(fid) === qualifiedId || fid === qualifiedId) {
429
+ return { owner: this, fid };
430
+ }
431
+ }
432
+ }
433
+ for (const child of this.hierarchyManager.getAllOwnedComponentEntities()) {
434
+ if (typeof child._resolveCapabilityRecursive === "function") {
435
+ const res = child._resolveCapabilityRecursive(qualifiedId);
436
+ if (res) return res;
437
+ }
438
+ }
439
+ return void 0;
440
+ }
441
+ // ── Sub-App Integration & Lifecycle ───────────────────────────────────────
442
+ /**
443
+ * Discovers sub-apps in the specified directory (or default 'subapps/').
444
+ */
445
+ async discoverSubApps(searchPath) {
446
+ const targetDir = searchPath || "subapps";
447
+ return await KrnlSubAppDiscovery.discoverSubApps(targetDir);
448
+ }
449
+ /**
450
+ * Loads, validates, registers, and initializes a sub-app onto this entity.
451
+ */
452
+ async loadSubApp(descriptorOrPath, config = {}) {
453
+ let descriptor = null;
454
+ if (typeof descriptorOrPath === "string") {
455
+ descriptor = await KrnlSubAppDiscovery.locateDescriptor(descriptorOrPath);
456
+ if (!descriptor) {
457
+ throw new Error(`[Entity:${this.id}] Could not locate a valid sub-app descriptor at '${descriptorOrPath}'.`);
458
+ }
459
+ } else {
460
+ descriptor = descriptorOrPath;
461
+ }
462
+ const instance = await KrnlSubAppLifecycle.loadAndRegister(this, descriptor, config);
463
+ if (instance.state === "READY") {
464
+ this._registerSubAppInstance(instance);
465
+ } else if (instance.state === "ERROR") {
466
+ console.warn(`[Entity:${this.id}] Sub-app '${instance.id}' failed registration:`, instance.error?.message);
467
+ }
468
+ this._subApps.set(instance.id, instance);
469
+ return instance;
470
+ }
471
+ /**
472
+ * Programmatically registers a sub-app registration object.
473
+ */
474
+ async registerSubApp(registration, descriptor) {
475
+ const subAppId = registration.name || descriptor?.id || `subapp_${Date.now()}`;
476
+ const desc = descriptor || {
477
+ id: subAppId,
478
+ path: "",
479
+ registrationPath: "",
480
+ manifest: { name: subAppId, version: "1.0.0" }
481
+ };
482
+ const instance = {
483
+ id: subAppId,
484
+ state: "VALIDATING",
485
+ manifest: desc.manifest || { name: subAppId, version: "1.0.0" },
486
+ descriptor: desc,
487
+ operations: /* @__PURE__ */ new Map(),
488
+ error: null,
489
+ errorDetails: [],
490
+ loadedAt: Date.now()
491
+ };
492
+ const existingCaps = /* @__PURE__ */ new Set();
493
+ for (const k of this.localFunctionalities.keys()) existingCaps.add(k);
494
+ for (const k of this.remoteFunctionalities.keys()) existingCaps.add(k);
495
+ const check = KrnlSubAppValidator.validateRegistration(registration, existingCaps, subAppId);
496
+ if (!check.valid) {
497
+ instance.state = "ERROR";
498
+ instance.errorDetails = check.errors;
499
+ instance.error = new Error(`[SubApp:${subAppId}] Registration validation failed: ${check.errors.map((e) => e.message).join(", ")}`);
500
+ this._subApps.set(subAppId, instance);
501
+ return instance;
502
+ }
503
+ instance.state = "REGISTERED";
504
+ instance.registration = registration;
505
+ for (const op of registration.operations) {
506
+ instance.operations.set(op.name, op);
507
+ }
508
+ this._registerSubAppInstance(instance);
509
+ if (typeof registration.onInitialize === "function") {
510
+ instance.state = "INITIALIZING";
511
+ const regContext = {
512
+ entity: this,
513
+ services: this._serviceContainer || { get: () => void 0, has: () => false, register: () => {
514
+ }, list: () => [] },
515
+ operations: {
516
+ register: (op) => this.registerSubAppOperations(subAppId, [op]),
517
+ registerBatch: (ops) => this.registerSubAppOperations(subAppId, ops),
518
+ get: (name) => instance.operations.get(name),
519
+ list: () => Array.from(instance.operations.values())
520
+ },
521
+ events: {
522
+ emit: (event, data) => this.interface?.getEmitter(event)?.pushDataStreamToEmitter(data),
523
+ on: (event, listener) => this.interface?.getEmitter(event)?.subscribe((m) => listener(m.data || m)) || (() => {
524
+ })
525
+ },
526
+ config: {},
527
+ logger: this.logger || console
528
+ };
529
+ await registration.onInitialize(regContext);
530
+ }
531
+ instance.state = "READY";
532
+ instance.readyAt = Date.now();
533
+ this._subApps.set(subAppId, instance);
534
+ return instance;
535
+ }
536
+ /**
537
+ * Internal helper: wraps sub-app operations into first-class Entity functionalities.
538
+ */
539
+ _registerSubAppInstance(instance) {
540
+ if (!instance.operations) return;
541
+ for (const op of instance.operations.values()) {
542
+ this._wrapAndAddSubAppOperation(instance.id, op);
543
+ }
544
+ if (this._selfHosting) {
545
+ this._notifyAdaptersOfSurfaceChange();
546
+ }
547
+ }
548
+ /**
549
+ * Wraps a single operation definition into a krnlLocalFunctionality and binds to this Entity.
550
+ */
551
+ _wrapAndAddSubAppOperation(subAppId, op) {
552
+ const qualifiedFid = `${subAppId}.${op.name}`;
553
+ const atomConfig = {
554
+ id: qualifiedFid,
555
+ visibility: op.visibility || "public",
556
+ description: op.description || "",
557
+ method: op.method || "POST",
558
+ schema: {
559
+ input: op.input || null,
560
+ output: op.output || null
561
+ },
562
+ metadata: op.metadata || {},
563
+ api: async (input, ctx) => {
564
+ return await op.handler(input, {
565
+ caller: ctx?.caller,
566
+ callerPort: ctx?.callerPort,
567
+ accessKey: ctx?.accessKey,
568
+ entity: this,
569
+ metadata: op.metadata
570
+ });
571
+ }
572
+ };
573
+ const localAtom = new krnlLocalFunctionality(atomConfig);
574
+ this.addLocal(localAtom);
575
+ if (!this.localFunctionalities.has(op.name) && !this.remoteFunctionalities.has(op.name)) {
576
+ const aliasAtom = new krnlLocalFunctionality({
577
+ ...atomConfig,
578
+ id: op.name
579
+ });
580
+ this.addLocal(aliasAtom);
581
+ }
582
+ }
583
+ /**
584
+ * Registers additional operations under an existing sub-app.
585
+ */
586
+ registerSubAppOperations(subAppId, operations) {
587
+ const instance = this._subApps.get(subAppId);
588
+ for (const op of operations) {
589
+ if (instance) {
590
+ instance.operations.set(op.name, op);
591
+ }
592
+ this._wrapAndAddSubAppOperation(subAppId, op);
593
+ }
594
+ if (this._selfHosting) {
595
+ this._notifyAdaptersOfSurfaceChange();
596
+ }
597
+ }
598
+ /**
599
+ * Unregisters and disposes a sub-app from this entity.
600
+ */
601
+ async unregisterSubApp(subAppId) {
602
+ const instance = this._subApps.get(subAppId);
603
+ if (!instance) return;
604
+ for (const opName of instance.operations.keys()) {
605
+ const qualifiedFid = `${subAppId}.${opName}`;
606
+ if (this.localFunctionalities.has(qualifiedFid)) {
607
+ const func = this.localFunctionalities.get(qualifiedFid);
608
+ if (func && typeof func._unregisterFromInterface === "function") {
609
+ func._unregisterFromInterface();
610
+ }
611
+ this.localFunctionalities.delete(qualifiedFid);
612
+ }
613
+ if (this.localFunctionalities.has(opName)) {
614
+ const func = this.localFunctionalities.get(opName);
615
+ if (func && typeof func._unregisterFromInterface === "function") {
616
+ func._unregisterFromInterface();
617
+ }
618
+ this.localFunctionalities.delete(opName);
619
+ }
620
+ }
621
+ await KrnlSubAppLifecycle.dispose(instance);
622
+ this._subApps.delete(subAppId);
623
+ if (this._selfHosting) {
624
+ this._notifyAdaptersOfSurfaceChange();
625
+ }
626
+ }
627
+ /**
628
+ * Retrieve a registered sub-app instance by ID.
629
+ */
630
+ getSubApp(subAppId) {
631
+ return this._subApps.get(subAppId);
632
+ }
633
+ /**
634
+ * Returns all sub-app instances registered under this entity.
635
+ */
636
+ getSubApps() {
637
+ return Array.from(this._subApps.values());
638
+ }
639
+ // ── Manifest Aggregation (Kernel Declares → Shell Materializes) ──────────
640
+ /**
641
+ * Aggregates dependency manifests from all local functionalities, sub-apps, and descendant entities.
642
+ * Returns a consolidated workspace requirements document.
643
+ */
644
+ getWorkspaceRequirements() {
645
+ const reqs = {
646
+ dependencies: {},
647
+ devDependencies: {},
648
+ buildRequirements: [],
649
+ resources: [],
650
+ conflicts: []
651
+ };
652
+ this._aggregateManifestInto(reqs);
653
+ return reqs;
654
+ }
655
+ _aggregateManifestInto(reqs) {
656
+ this.localFunctionalities.forEach((func) => {
657
+ if (func.manifest) {
658
+ _Entity._mergeManifestRequirements(reqs, func.manifest, `${this.id}:${func.id}`);
659
+ }
660
+ });
661
+ this._subApps.forEach((subApp) => {
662
+ if (subApp.manifest) {
663
+ _Entity._mergeManifestRequirements(reqs, subApp.manifest, `${this.id}:${subApp.id}`);
664
+ }
665
+ });
666
+ this.hierarchyManager.getAllOwnedComponentEntities().forEach((child) => {
667
+ if (typeof child._aggregateManifestInto === "function") {
668
+ child._aggregateManifestInto(reqs);
669
+ }
670
+ });
671
+ }
672
+ static _mergeManifestRequirements(target, manifest, sourceId) {
673
+ if (manifest.dependencies) {
674
+ for (const [pkg, ver] of Object.entries(manifest.dependencies)) {
675
+ if (target.dependencies[pkg] && target.dependencies[pkg] !== ver) {
676
+ target.conflicts = target.conflicts || [];
677
+ target.conflicts.push({
678
+ package: pkg,
679
+ versionA: target.dependencies[pkg],
680
+ versionB: ver,
681
+ sources: [sourceId]
682
+ });
683
+ } else {
684
+ target.dependencies[pkg] = ver;
685
+ }
686
+ }
687
+ }
688
+ if (manifest.devDependencies) {
689
+ for (const [pkg, ver] of Object.entries(manifest.devDependencies)) {
690
+ target.devDependencies[pkg] = ver;
691
+ }
692
+ }
693
+ if (manifest.buildRequirements) {
694
+ for (const req of manifest.buildRequirements) {
695
+ if (!target.buildRequirements.includes(req)) {
696
+ target.buildRequirements.push(req);
697
+ }
698
+ }
699
+ }
700
+ if (manifest.resources) {
701
+ for (const res of manifest.resources) {
702
+ target.resources.push(res);
703
+ }
704
+ }
705
+ }
706
+ // ── UI Spec Recursive Aggregation ────────────────────────────────────────
707
+ /**
708
+ * Aggregates UI specifications from all functionalities and sub-apps across the entity tree.
709
+ * Qualified IDs ensure namespace stability and avoid collisions.
710
+ */
711
+ aggregateUI() {
712
+ const list = [];
713
+ this.localFunctionalities.forEach((func, fid) => {
714
+ if (func.uiSpec) {
715
+ list.push({
716
+ qualifiedId: this.getQualifiedId(fid),
717
+ uiSpec: func.uiSpec,
718
+ source: this
719
+ });
720
+ }
721
+ });
722
+ this._subApps.forEach((subApp) => {
723
+ const uiConfig = subApp.registration?.ui || subApp.manifest?.ui;
724
+ if (uiConfig) {
725
+ list.push({
726
+ qualifiedId: this.getQualifiedId(subApp.id),
727
+ uiSpec: typeof uiConfig === "string" ? { entry: uiConfig } : uiConfig,
728
+ source: this
729
+ });
730
+ }
731
+ });
732
+ this.hierarchyManager.getAllOwnedComponentEntities().forEach((child) => {
733
+ if (typeof child.aggregateUI === "function") {
734
+ list.push(...child.aggregateUI());
735
+ }
736
+ });
737
+ return list;
738
+ }
739
+ // ── Flow Factory ─────────────────────────────────────────────────────────
740
+ /**
741
+ * Create a FlowBuilder instance bound to this entity.
742
+ */
743
+ flow(id) {
744
+ return new KrnlFlowBuilder(this, id);
745
+ }
746
+ /**
747
+ * Clean disposal of all entity resources, sub-apps, child components, and adapters.
748
+ */
749
+ dispose() {
750
+ if (this._selfHosting) {
751
+ this.stopHosting().catch(() => {
752
+ });
753
+ }
754
+ for (const subApp of this._subApps.values()) {
755
+ KrnlSubAppLifecycle.dispose(subApp).catch(() => {
756
+ });
757
+ }
758
+ this._subApps.clear();
759
+ for (const adapter of this._protocolAdapters.values()) {
760
+ if (typeof adapter.dispose === "function") {
761
+ adapter.dispose();
762
+ }
763
+ }
764
+ this._protocolAdapters.clear();
765
+ super.dispose();
766
+ }
767
+ };
768
+
769
+ export {
770
+ KrnlFlowBuilder,
771
+ Entity
772
+ };