@plures/praxis 1.0.2 → 1.1.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 (518) hide show
  1. package/FRAMEWORK.md +55 -5
  2. package/LICENSE +21 -21
  3. package/README.md +162 -375
  4. package/core/codegen/docs-generator.ts +5 -2
  5. package/core/codegen/index.ts +1 -1
  6. package/core/codegen/ts-generator.ts +15 -15
  7. package/core/db-adapter/index.ts +2 -2
  8. package/core/db-adapter/sync-engine.ts +17 -6
  9. package/core/logic-engine/engine.ts +1 -1
  10. package/core/logic-engine/index.ts +2 -2
  11. package/core/logic-engine/protocol.ts +1 -1
  12. package/core/logic-engine/psf-adapter.ts +8 -4
  13. package/core/logic-engine/rules.ts +1 -1
  14. package/core/schema-engine/compiler.ts +53 -11
  15. package/core/schema-engine/generator.ts +17 -7
  16. package/core/schema-engine/index.ts +2 -2
  17. package/core/schema-engine/psf.ts +12 -3
  18. package/core/schema-engine/types.ts +3 -11
  19. package/core/schema-engine/validator.ts +112 -22
  20. package/dist/browser/engine-BjdqxeXG.d.ts +333 -0
  21. package/dist/browser/index.d.ts +3004 -0
  22. package/dist/browser/index.js +2892 -0
  23. package/dist/{src → browser}/integrations/svelte.d.ts +19 -17
  24. package/dist/browser/integrations/svelte.js +298 -0
  25. package/dist/node/auth-STARLY7I.js +207 -0
  26. package/dist/node/build-Y7OT5VBF.js +144 -0
  27. package/dist/node/canvas-UERZHJYW.js +362 -0
  28. package/dist/node/chunk-DSDC2JWZ.js +256 -0
  29. package/dist/node/chunk-FXQZXAWF.js +175 -0
  30. package/dist/node/chunk-N5Y37EUV.js +202 -0
  31. package/dist/node/chunk-QGM4M3NI.js +37 -0
  32. package/dist/node/chunk-RJMWCNHR.js +175 -0
  33. package/dist/node/chunk-SRM3OPPM.js +404 -0
  34. package/dist/node/chunk-UATVJBNV.js +175 -0
  35. package/dist/node/chunk-UY7YEBE2.js +159 -0
  36. package/dist/node/chunk-XCY2VIFX.js +143 -0
  37. package/dist/node/chunk-YXH4Y7ZZ.js +349 -0
  38. package/dist/node/cli/index.cjs +217418 -0
  39. package/dist/node/cli/index.d.cts +1 -0
  40. package/dist/node/cli/index.d.ts +1 -0
  41. package/dist/node/cli/index.js +690 -0
  42. package/dist/node/cloud/index.cjs +1043 -0
  43. package/dist/node/cloud/index.d.cts +864 -0
  44. package/dist/node/cloud/index.d.ts +864 -0
  45. package/dist/node/cloud/index.js +456 -0
  46. package/dist/node/cloud-AXOK4PSN.js +212 -0
  47. package/dist/node/component.cjs +374 -0
  48. package/dist/node/component.d.cts +125 -0
  49. package/dist/{src/core/component/generator.d.ts → node/component.d.ts} +11 -8
  50. package/dist/node/component.js +9 -0
  51. package/dist/node/components/index.cjs +216 -0
  52. package/dist/node/components/index.d.cts +43 -0
  53. package/dist/{src → node}/components/index.d.ts +8 -8
  54. package/dist/node/components/index.js +7 -0
  55. package/dist/node/create-TRLSVCNQ.js +584 -0
  56. package/dist/node/dev-PMJZUYGE.js +65 -0
  57. package/dist/node/engine-1iqLe6_P.d.ts +214 -0
  58. package/dist/node/engine-CVJobhHm.d.cts +214 -0
  59. package/dist/node/index.cjs +3247 -0
  60. package/dist/node/index.d.cts +2579 -0
  61. package/dist/node/index.d.ts +2579 -0
  62. package/dist/node/index.js +2098 -0
  63. package/dist/node/integrations/svelte.cjs +330 -0
  64. package/dist/node/integrations/svelte.d.cts +309 -0
  65. package/dist/node/integrations/svelte.d.ts +309 -0
  66. package/dist/node/integrations/svelte.js +300 -0
  67. package/dist/node/orchestrate-737TCL5H.js +127 -0
  68. package/dist/{src/core/protocol.d.ts → node/protocol-Qek7ebBl.d.cts} +11 -10
  69. package/dist/node/protocol-Qek7ebBl.d.ts +122 -0
  70. package/dist/node/schema.cjs +200 -0
  71. package/dist/{src/core/schema/types.d.ts → node/schema.d.cts} +30 -29
  72. package/dist/node/schema.d.ts +371 -0
  73. package/dist/node/schema.js +9 -0
  74. package/dist/{src/runtime/terminal-adapter.d.ts → node/terminal-adapter-07HGftGQ.d.ts} +86 -11
  75. package/dist/node/terminal-adapter-XLtCjjb_.d.cts +231 -0
  76. package/dist/node/verify-YBZ7W24H.js +213239 -0
  77. package/docs/MONETIZATION.md +21 -16
  78. package/docs/REACTIVE_REDESIGN.md +132 -0
  79. package/docs/README.md +47 -36
  80. package/docs/SVELTE_INTEGRATION_STRATEGY.md +68 -0
  81. package/docs/TERMINAL_NODE.md +27 -24
  82. package/docs/core/building-extensions.md +58 -61
  83. package/docs/core/cli-usage.md +59 -59
  84. package/docs/core/code-canvas-sync.md +28 -16
  85. package/docs/core/logic-engine.md +77 -82
  86. package/docs/core/pluresdb-integration.md +29 -39
  87. package/docs/core/schema-model.md +66 -52
  88. package/docs/core/ui-generation.md +57 -49
  89. package/docs/core/what-is-praxis.md +32 -15
  90. package/docs/guides/canvas.md +21 -5
  91. package/docs/guides/getting-started.md +13 -7
  92. package/docs/guides/history-state-pattern.md +65 -51
  93. package/docs/guides/orchestration.md +46 -32
  94. package/docs/guides/parallel-state-pattern.md +56 -72
  95. package/docs/guides/svelte-integration.md +45 -53
  96. package/docs/tutorials/README.md +16 -0
  97. package/docs/tutorials/ecommerce-cart.md +177 -95
  98. package/docs/tutorials/first-app.md +26 -41
  99. package/docs/tutorials/form-builder.md +191 -138
  100. package/docs/tutorials/todo-pluresdb.md +71 -69
  101. package/package.json +132 -96
  102. package/src/__tests__/actors.test.ts +68 -68
  103. package/src/__tests__/billing.test.ts +32 -32
  104. package/src/__tests__/canvas-components.test.ts +94 -73
  105. package/src/__tests__/cli-create.test.ts +28 -28
  106. package/src/__tests__/cloud.test.ts +36 -36
  107. package/src/__tests__/code-canvas-integration.test.ts +132 -141
  108. package/src/__tests__/docs-generator.test.ts +3 -9
  109. package/src/__tests__/dsl.test.ts +58 -64
  110. package/src/__tests__/edge-cases.test.ts +106 -108
  111. package/src/__tests__/engine.test.ts +51 -25
  112. package/src/__tests__/generators.test.ts +42 -44
  113. package/src/__tests__/introspection.test.ts +104 -114
  114. package/src/__tests__/pluresdb.test.ts +189 -187
  115. package/src/__tests__/protocol.test.ts +15 -15
  116. package/src/__tests__/provisioning.test.ts +61 -61
  117. package/src/__tests__/schema.test.ts +7 -11
  118. package/src/__tests__/state-docs-integration.test.ts +162 -145
  119. package/src/__tests__/svelte-integration.test.ts +16 -19
  120. package/src/__tests__/tauri-integration.test.ts +149 -147
  121. package/src/__tests__/terminal-node.test.ts +12 -7
  122. package/src/__tests__/unum-integration.test.ts +68 -68
  123. package/src/adapters/cli.ts +21 -15
  124. package/src/cli/commands/auth.ts +82 -78
  125. package/src/cli/commands/build.ts +29 -27
  126. package/src/cli/commands/canvas.ts +338 -127
  127. package/src/cli/commands/cloud.ts +47 -47
  128. package/src/cli/commands/create.ts +59 -47
  129. package/src/cli/commands/dev.ts +12 -12
  130. package/src/cli/commands/generate.ts +29 -40
  131. package/src/cli/commands/orchestrate.ts +24 -24
  132. package/src/cli/commands/verify.ts +49 -0
  133. package/src/cli/index.ts +21 -2
  134. package/src/cloud/README.md +28 -15
  135. package/src/cloud/auth.ts +55 -70
  136. package/src/cloud/billing.ts +59 -58
  137. package/src/cloud/client.ts +29 -35
  138. package/src/cloud/index.ts +19 -40
  139. package/src/cloud/marketplace.ts +69 -78
  140. package/src/cloud/provisioning.ts +42 -51
  141. package/src/cloud/relay/endpoints.ts +30 -34
  142. package/src/cloud/relay/health/index.ts +1 -1
  143. package/src/cloud/relay/stats/index.ts +1 -1
  144. package/src/cloud/relay/sync/index.ts +1 -1
  145. package/src/cloud/relay/usage/index.ts +1 -1
  146. package/src/cloud/sponsors.ts +31 -34
  147. package/src/cloud/types.ts +4 -4
  148. package/src/components/README.md +1 -0
  149. package/src/components/TerminalNode.svelte +457 -457
  150. package/src/components/index.ts +3 -4
  151. package/src/core/actors.ts +7 -7
  152. package/src/core/component/generator.ts +10 -28
  153. package/src/core/engine.ts +51 -24
  154. package/src/core/introspection.ts +37 -35
  155. package/src/core/logic/generator.ts +62 -62
  156. package/src/core/pluresdb/adapter.ts +8 -8
  157. package/src/core/pluresdb/generator.ts +39 -35
  158. package/src/core/pluresdb/index.ts +9 -12
  159. package/src/core/pluresdb/schema-registry.ts +22 -25
  160. package/src/core/pluresdb/store.ts +57 -57
  161. package/src/core/protocol.ts +14 -14
  162. package/src/core/reactive-engine.svelte.ts +65 -0
  163. package/src/core/reactive-engine.ts +67 -0
  164. package/src/core/rules.ts +4 -4
  165. package/src/core/schema/loader.common.ts +150 -0
  166. package/src/core/schema/loader.ts +19 -149
  167. package/src/core/schema/normalize.ts +34 -51
  168. package/src/core/schema/types.ts +47 -11
  169. package/src/dsl/index.ts +8 -8
  170. package/src/dsl.ts +11 -17
  171. package/src/examples/advanced-todo/App.svelte +506 -506
  172. package/src/examples/advanced-todo/README.md +58 -40
  173. package/src/examples/advanced-todo/index.ts +3 -3
  174. package/src/examples/auth-basic/index.ts +30 -30
  175. package/src/examples/cart/index.ts +50 -50
  176. package/src/examples/hero-ecommerce/index.ts +130 -157
  177. package/src/examples/svelte-counter/index.ts +22 -26
  178. package/src/flows.ts +6 -17
  179. package/src/index.browser.ts +204 -0
  180. package/src/index.ts +37 -42
  181. package/src/integrations/code-canvas.ts +237 -193
  182. package/src/integrations/pluresdb.ts +55 -35
  183. package/src/integrations/state-docs.ts +104 -104
  184. package/src/integrations/svelte.ts +35 -35
  185. package/src/integrations/tauri.ts +75 -73
  186. package/src/integrations/unum.ts +68 -61
  187. package/src/registry.ts +7 -14
  188. package/src/runtime/terminal-adapter.ts +31 -26
  189. package/src/step.ts +10 -16
  190. package/src/types.ts +1 -1
  191. package/templates/basic-app/README.md +6 -9
  192. package/templates/fullstack-app/README.md +10 -0
  193. package/dist/core/codegen/docs-generator.d.ts +0 -123
  194. package/dist/core/codegen/docs-generator.d.ts.map +0 -1
  195. package/dist/core/codegen/docs-generator.js +0 -674
  196. package/dist/core/codegen/docs-generator.js.map +0 -1
  197. package/dist/core/codegen/index.d.ts +0 -11
  198. package/dist/core/codegen/index.d.ts.map +0 -1
  199. package/dist/core/codegen/index.js +0 -13
  200. package/dist/core/codegen/index.js.map +0 -1
  201. package/dist/core/codegen/ts-generator.d.ts +0 -8
  202. package/dist/core/codegen/ts-generator.d.ts.map +0 -1
  203. package/dist/core/codegen/ts-generator.js +0 -8
  204. package/dist/core/codegen/ts-generator.js.map +0 -1
  205. package/dist/core/db-adapter/index.d.ts +0 -18
  206. package/dist/core/db-adapter/index.d.ts.map +0 -1
  207. package/dist/core/db-adapter/index.js +0 -23
  208. package/dist/core/db-adapter/index.js.map +0 -1
  209. package/dist/core/db-adapter/sync-engine.d.ts +0 -180
  210. package/dist/core/db-adapter/sync-engine.d.ts.map +0 -1
  211. package/dist/core/db-adapter/sync-engine.js +0 -342
  212. package/dist/core/db-adapter/sync-engine.js.map +0 -1
  213. package/dist/core/logic-engine/engine.d.ts +0 -8
  214. package/dist/core/logic-engine/engine.d.ts.map +0 -1
  215. package/dist/core/logic-engine/engine.js +0 -8
  216. package/dist/core/logic-engine/engine.js.map +0 -1
  217. package/dist/core/logic-engine/index.d.ts +0 -16
  218. package/dist/core/logic-engine/index.d.ts.map +0 -1
  219. package/dist/core/logic-engine/index.js +0 -16
  220. package/dist/core/logic-engine/index.js.map +0 -1
  221. package/dist/core/logic-engine/protocol.d.ts +0 -7
  222. package/dist/core/logic-engine/protocol.d.ts.map +0 -1
  223. package/dist/core/logic-engine/protocol.js +0 -7
  224. package/dist/core/logic-engine/protocol.js.map +0 -1
  225. package/dist/core/logic-engine/psf-adapter.d.ts +0 -88
  226. package/dist/core/logic-engine/psf-adapter.d.ts.map +0 -1
  227. package/dist/core/logic-engine/psf-adapter.js +0 -207
  228. package/dist/core/logic-engine/psf-adapter.js.map +0 -1
  229. package/dist/core/logic-engine/rules.d.ts +0 -7
  230. package/dist/core/logic-engine/rules.d.ts.map +0 -1
  231. package/dist/core/logic-engine/rules.js +0 -7
  232. package/dist/core/logic-engine/rules.js.map +0 -1
  233. package/dist/core/schema-engine/compiler.d.ts +0 -198
  234. package/dist/core/schema-engine/compiler.d.ts.map +0 -1
  235. package/dist/core/schema-engine/compiler.js +0 -262
  236. package/dist/core/schema-engine/compiler.js.map +0 -1
  237. package/dist/core/schema-engine/generator.d.ts +0 -115
  238. package/dist/core/schema-engine/generator.d.ts.map +0 -1
  239. package/dist/core/schema-engine/generator.js +0 -506
  240. package/dist/core/schema-engine/generator.js.map +0 -1
  241. package/dist/core/schema-engine/index.d.ts +0 -18
  242. package/dist/core/schema-engine/index.d.ts.map +0 -1
  243. package/dist/core/schema-engine/index.js +0 -18
  244. package/dist/core/schema-engine/index.js.map +0 -1
  245. package/dist/core/schema-engine/psf.d.ts +0 -612
  246. package/dist/core/schema-engine/psf.d.ts.map +0 -1
  247. package/dist/core/schema-engine/psf.js +0 -45
  248. package/dist/core/schema-engine/psf.js.map +0 -1
  249. package/dist/core/schema-engine/types.d.ts +0 -10
  250. package/dist/core/schema-engine/types.d.ts.map +0 -1
  251. package/dist/core/schema-engine/types.js +0 -7
  252. package/dist/core/schema-engine/types.js.map +0 -1
  253. package/dist/core/schema-engine/validator.d.ts +0 -140
  254. package/dist/core/schema-engine/validator.d.ts.map +0 -1
  255. package/dist/core/schema-engine/validator.js +0 -407
  256. package/dist/core/schema-engine/validator.js.map +0 -1
  257. package/dist/src/adapters/cli.d.ts +0 -43
  258. package/dist/src/adapters/cli.d.ts.map +0 -1
  259. package/dist/src/adapters/cli.js +0 -126
  260. package/dist/src/adapters/cli.js.map +0 -1
  261. package/dist/src/cli/commands/auth.d.ts +0 -26
  262. package/dist/src/cli/commands/auth.d.ts.map +0 -1
  263. package/dist/src/cli/commands/auth.js +0 -233
  264. package/dist/src/cli/commands/auth.js.map +0 -1
  265. package/dist/src/cli/commands/build.d.ts +0 -23
  266. package/dist/src/cli/commands/build.d.ts.map +0 -1
  267. package/dist/src/cli/commands/build.js +0 -162
  268. package/dist/src/cli/commands/build.js.map +0 -1
  269. package/dist/src/cli/commands/canvas.d.ts +0 -23
  270. package/dist/src/cli/commands/canvas.d.ts.map +0 -1
  271. package/dist/src/cli/commands/canvas.js +0 -215
  272. package/dist/src/cli/commands/canvas.js.map +0 -1
  273. package/dist/src/cli/commands/cloud.d.ts +0 -27
  274. package/dist/src/cli/commands/cloud.d.ts.map +0 -1
  275. package/dist/src/cli/commands/cloud.js +0 -232
  276. package/dist/src/cli/commands/cloud.js.map +0 -1
  277. package/dist/src/cli/commands/create.d.ts +0 -21
  278. package/dist/src/cli/commands/create.d.ts.map +0 -1
  279. package/dist/src/cli/commands/create.js +0 -621
  280. package/dist/src/cli/commands/create.js.map +0 -1
  281. package/dist/src/cli/commands/dev.d.ts +0 -21
  282. package/dist/src/cli/commands/dev.d.ts.map +0 -1
  283. package/dist/src/cli/commands/dev.js +0 -71
  284. package/dist/src/cli/commands/dev.js.map +0 -1
  285. package/dist/src/cli/commands/generate.d.ts +0 -25
  286. package/dist/src/cli/commands/generate.d.ts.map +0 -1
  287. package/dist/src/cli/commands/generate.js +0 -168
  288. package/dist/src/cli/commands/generate.js.map +0 -1
  289. package/dist/src/cli/commands/orchestrate.d.ts +0 -44
  290. package/dist/src/cli/commands/orchestrate.d.ts.map +0 -1
  291. package/dist/src/cli/commands/orchestrate.js +0 -150
  292. package/dist/src/cli/commands/orchestrate.js.map +0 -1
  293. package/dist/src/cli/index.d.ts +0 -8
  294. package/dist/src/cli/index.d.ts.map +0 -1
  295. package/dist/src/cli/index.js +0 -211
  296. package/dist/src/cli/index.js.map +0 -1
  297. package/dist/src/cloud/auth.d.ts +0 -51
  298. package/dist/src/cloud/auth.d.ts.map +0 -1
  299. package/dist/src/cloud/auth.js +0 -194
  300. package/dist/src/cloud/auth.js.map +0 -1
  301. package/dist/src/cloud/billing.d.ts +0 -184
  302. package/dist/src/cloud/billing.d.ts.map +0 -1
  303. package/dist/src/cloud/billing.js +0 -179
  304. package/dist/src/cloud/billing.js.map +0 -1
  305. package/dist/src/cloud/client.d.ts +0 -39
  306. package/dist/src/cloud/client.d.ts.map +0 -1
  307. package/dist/src/cloud/client.js +0 -176
  308. package/dist/src/cloud/client.js.map +0 -1
  309. package/dist/src/cloud/index.d.ts +0 -44
  310. package/dist/src/cloud/index.d.ts.map +0 -1
  311. package/dist/src/cloud/index.js +0 -44
  312. package/dist/src/cloud/index.js.map +0 -1
  313. package/dist/src/cloud/marketplace.d.ts +0 -166
  314. package/dist/src/cloud/marketplace.d.ts.map +0 -1
  315. package/dist/src/cloud/marketplace.js +0 -159
  316. package/dist/src/cloud/marketplace.js.map +0 -1
  317. package/dist/src/cloud/provisioning.d.ts +0 -110
  318. package/dist/src/cloud/provisioning.d.ts.map +0 -1
  319. package/dist/src/cloud/provisioning.js +0 -148
  320. package/dist/src/cloud/provisioning.js.map +0 -1
  321. package/dist/src/cloud/relay/endpoints.d.ts +0 -62
  322. package/dist/src/cloud/relay/endpoints.d.ts.map +0 -1
  323. package/dist/src/cloud/relay/endpoints.js +0 -217
  324. package/dist/src/cloud/relay/endpoints.js.map +0 -1
  325. package/dist/src/cloud/relay/health/index.d.ts +0 -5
  326. package/dist/src/cloud/relay/health/index.d.ts.map +0 -1
  327. package/dist/src/cloud/relay/health/index.js +0 -9
  328. package/dist/src/cloud/relay/health/index.js.map +0 -1
  329. package/dist/src/cloud/relay/stats/index.d.ts +0 -5
  330. package/dist/src/cloud/relay/stats/index.d.ts.map +0 -1
  331. package/dist/src/cloud/relay/stats/index.js +0 -9
  332. package/dist/src/cloud/relay/stats/index.js.map +0 -1
  333. package/dist/src/cloud/relay/sync/index.d.ts +0 -5
  334. package/dist/src/cloud/relay/sync/index.d.ts.map +0 -1
  335. package/dist/src/cloud/relay/sync/index.js +0 -9
  336. package/dist/src/cloud/relay/sync/index.js.map +0 -1
  337. package/dist/src/cloud/relay/usage/index.d.ts +0 -5
  338. package/dist/src/cloud/relay/usage/index.d.ts.map +0 -1
  339. package/dist/src/cloud/relay/usage/index.js +0 -9
  340. package/dist/src/cloud/relay/usage/index.js.map +0 -1
  341. package/dist/src/cloud/sponsors.d.ts +0 -81
  342. package/dist/src/cloud/sponsors.d.ts.map +0 -1
  343. package/dist/src/cloud/sponsors.js +0 -130
  344. package/dist/src/cloud/sponsors.js.map +0 -1
  345. package/dist/src/cloud/types.d.ts +0 -169
  346. package/dist/src/cloud/types.d.ts.map +0 -1
  347. package/dist/src/cloud/types.js +0 -7
  348. package/dist/src/cloud/types.js.map +0 -1
  349. package/dist/src/components/index.d.ts.map +0 -1
  350. package/dist/src/components/index.js +0 -17
  351. package/dist/src/components/index.js.map +0 -1
  352. package/dist/src/core/actors.d.ts +0 -95
  353. package/dist/src/core/actors.d.ts.map +0 -1
  354. package/dist/src/core/actors.js +0 -158
  355. package/dist/src/core/actors.js.map +0 -1
  356. package/dist/src/core/component/generator.d.ts.map +0 -1
  357. package/dist/src/core/component/generator.js +0 -349
  358. package/dist/src/core/component/generator.js.map +0 -1
  359. package/dist/src/core/engine.d.ts +0 -92
  360. package/dist/src/core/engine.d.ts.map +0 -1
  361. package/dist/src/core/engine.js +0 -199
  362. package/dist/src/core/engine.js.map +0 -1
  363. package/dist/src/core/introspection.d.ts +0 -141
  364. package/dist/src/core/introspection.d.ts.map +0 -1
  365. package/dist/src/core/introspection.js +0 -208
  366. package/dist/src/core/introspection.js.map +0 -1
  367. package/dist/src/core/logic/generator.d.ts +0 -76
  368. package/dist/src/core/logic/generator.d.ts.map +0 -1
  369. package/dist/src/core/logic/generator.js +0 -370
  370. package/dist/src/core/logic/generator.js.map +0 -1
  371. package/dist/src/core/pluresdb/adapter.d.ts +0 -72
  372. package/dist/src/core/pluresdb/adapter.d.ts.map +0 -1
  373. package/dist/src/core/pluresdb/adapter.js +0 -73
  374. package/dist/src/core/pluresdb/adapter.js.map +0 -1
  375. package/dist/src/core/pluresdb/generator.d.ts +0 -58
  376. package/dist/src/core/pluresdb/generator.d.ts.map +0 -1
  377. package/dist/src/core/pluresdb/generator.js +0 -191
  378. package/dist/src/core/pluresdb/generator.js.map +0 -1
  379. package/dist/src/core/pluresdb/index.d.ts +0 -15
  380. package/dist/src/core/pluresdb/index.d.ts.map +0 -1
  381. package/dist/src/core/pluresdb/index.js +0 -11
  382. package/dist/src/core/pluresdb/index.js.map +0 -1
  383. package/dist/src/core/pluresdb/schema-registry.d.ts +0 -104
  384. package/dist/src/core/pluresdb/schema-registry.d.ts.map +0 -1
  385. package/dist/src/core/pluresdb/schema-registry.js +0 -130
  386. package/dist/src/core/pluresdb/schema-registry.js.map +0 -1
  387. package/dist/src/core/pluresdb/store.d.ts +0 -199
  388. package/dist/src/core/pluresdb/store.d.ts.map +0 -1
  389. package/dist/src/core/pluresdb/store.js +0 -344
  390. package/dist/src/core/pluresdb/store.js.map +0 -1
  391. package/dist/src/core/protocol.d.ts.map +0 -1
  392. package/dist/src/core/protocol.js +0 -46
  393. package/dist/src/core/protocol.js.map +0 -1
  394. package/dist/src/core/rules.d.ts +0 -120
  395. package/dist/src/core/rules.d.ts.map +0 -1
  396. package/dist/src/core/rules.js +0 -81
  397. package/dist/src/core/rules.js.map +0 -1
  398. package/dist/src/core/schema/loader.d.ts +0 -47
  399. package/dist/src/core/schema/loader.d.ts.map +0 -1
  400. package/dist/src/core/schema/loader.js +0 -189
  401. package/dist/src/core/schema/loader.js.map +0 -1
  402. package/dist/src/core/schema/normalize.d.ts +0 -72
  403. package/dist/src/core/schema/normalize.d.ts.map +0 -1
  404. package/dist/src/core/schema/normalize.js +0 -190
  405. package/dist/src/core/schema/normalize.js.map +0 -1
  406. package/dist/src/core/schema/types.d.ts.map +0 -1
  407. package/dist/src/core/schema/types.js +0 -161
  408. package/dist/src/core/schema/types.js.map +0 -1
  409. package/dist/src/dsl/index.d.ts +0 -152
  410. package/dist/src/dsl/index.d.ts.map +0 -1
  411. package/dist/src/dsl/index.js +0 -132
  412. package/dist/src/dsl/index.js.map +0 -1
  413. package/dist/src/dsl.d.ts +0 -124
  414. package/dist/src/dsl.d.ts.map +0 -1
  415. package/dist/src/dsl.js +0 -130
  416. package/dist/src/dsl.js.map +0 -1
  417. package/dist/src/examples/advanced-todo/index.d.ts +0 -55
  418. package/dist/src/examples/advanced-todo/index.d.ts.map +0 -1
  419. package/dist/src/examples/advanced-todo/index.js +0 -222
  420. package/dist/src/examples/advanced-todo/index.js.map +0 -1
  421. package/dist/src/examples/auth-basic/index.d.ts +0 -17
  422. package/dist/src/examples/auth-basic/index.d.ts.map +0 -1
  423. package/dist/src/examples/auth-basic/index.js +0 -122
  424. package/dist/src/examples/auth-basic/index.js.map +0 -1
  425. package/dist/src/examples/cart/index.d.ts +0 -19
  426. package/dist/src/examples/cart/index.d.ts.map +0 -1
  427. package/dist/src/examples/cart/index.js +0 -202
  428. package/dist/src/examples/cart/index.js.map +0 -1
  429. package/dist/src/examples/hero-ecommerce/index.d.ts +0 -39
  430. package/dist/src/examples/hero-ecommerce/index.d.ts.map +0 -1
  431. package/dist/src/examples/hero-ecommerce/index.js +0 -506
  432. package/dist/src/examples/hero-ecommerce/index.js.map +0 -1
  433. package/dist/src/examples/svelte-counter/index.d.ts +0 -31
  434. package/dist/src/examples/svelte-counter/index.d.ts.map +0 -1
  435. package/dist/src/examples/svelte-counter/index.js +0 -123
  436. package/dist/src/examples/svelte-counter/index.js.map +0 -1
  437. package/dist/src/flows.d.ts +0 -125
  438. package/dist/src/flows.d.ts.map +0 -1
  439. package/dist/src/flows.js +0 -160
  440. package/dist/src/flows.js.map +0 -1
  441. package/dist/src/index.d.ts +0 -77
  442. package/dist/src/index.d.ts.map +0 -1
  443. package/dist/src/index.js +0 -64
  444. package/dist/src/index.js.map +0 -1
  445. package/dist/src/integrations/code-canvas.d.ts +0 -265
  446. package/dist/src/integrations/code-canvas.d.ts.map +0 -1
  447. package/dist/src/integrations/code-canvas.js +0 -451
  448. package/dist/src/integrations/code-canvas.js.map +0 -1
  449. package/dist/src/integrations/pluresdb.d.ts +0 -117
  450. package/dist/src/integrations/pluresdb.d.ts.map +0 -1
  451. package/dist/src/integrations/pluresdb.js +0 -117
  452. package/dist/src/integrations/pluresdb.js.map +0 -1
  453. package/dist/src/integrations/state-docs.d.ts +0 -191
  454. package/dist/src/integrations/state-docs.d.ts.map +0 -1
  455. package/dist/src/integrations/state-docs.js +0 -515
  456. package/dist/src/integrations/state-docs.js.map +0 -1
  457. package/dist/src/integrations/svelte.d.ts.map +0 -1
  458. package/dist/src/integrations/svelte.js +0 -447
  459. package/dist/src/integrations/svelte.js.map +0 -1
  460. package/dist/src/integrations/tauri.d.ts +0 -360
  461. package/dist/src/integrations/tauri.d.ts.map +0 -1
  462. package/dist/src/integrations/tauri.js +0 -278
  463. package/dist/src/integrations/tauri.js.map +0 -1
  464. package/dist/src/integrations/unum.d.ts +0 -159
  465. package/dist/src/integrations/unum.d.ts.map +0 -1
  466. package/dist/src/integrations/unum.js +0 -240
  467. package/dist/src/integrations/unum.js.map +0 -1
  468. package/dist/src/registry.d.ts +0 -94
  469. package/dist/src/registry.d.ts.map +0 -1
  470. package/dist/src/registry.js +0 -181
  471. package/dist/src/registry.js.map +0 -1
  472. package/dist/src/runtime/terminal-adapter.d.ts.map +0 -1
  473. package/dist/src/runtime/terminal-adapter.js +0 -239
  474. package/dist/src/runtime/terminal-adapter.js.map +0 -1
  475. package/dist/src/step.d.ts +0 -34
  476. package/dist/src/step.d.ts.map +0 -1
  477. package/dist/src/step.js +0 -111
  478. package/dist/src/step.js.map +0 -1
  479. package/dist/src/types.d.ts +0 -63
  480. package/dist/src/types.d.ts.map +0 -1
  481. package/dist/src/types.js +0 -6
  482. package/dist/src/types.js.map +0 -1
  483. package/dist/tools/cli/commands/index.d.ts +0 -7
  484. package/dist/tools/cli/commands/index.d.ts.map +0 -1
  485. package/dist/tools/cli/commands/index.js +0 -7
  486. package/dist/tools/cli/commands/index.js.map +0 -1
  487. package/dist/tools/cli/index.d.ts +0 -8
  488. package/dist/tools/cli/index.d.ts.map +0 -1
  489. package/dist/tools/cli/index.js +0 -9
  490. package/dist/tools/cli/index.js.map +0 -1
  491. package/dist/tools/watcher/index.d.ts +0 -105
  492. package/dist/tools/watcher/index.d.ts.map +0 -1
  493. package/dist/tools/watcher/index.js +0 -213
  494. package/dist/tools/watcher/index.js.map +0 -1
  495. package/dist/ui/canvas/canvas-projection.d.ts +0 -78
  496. package/dist/ui/canvas/canvas-projection.d.ts.map +0 -1
  497. package/dist/ui/canvas/canvas-projection.js +0 -416
  498. package/dist/ui/canvas/canvas-projection.js.map +0 -1
  499. package/dist/ui/canvas/canvas-state.d.ts +0 -200
  500. package/dist/ui/canvas/canvas-state.d.ts.map +0 -1
  501. package/dist/ui/canvas/canvas-state.js +0 -464
  502. package/dist/ui/canvas/canvas-state.js.map +0 -1
  503. package/dist/ui/canvas/components/index.d.ts +0 -95
  504. package/dist/ui/canvas/components/index.d.ts.map +0 -1
  505. package/dist/ui/canvas/components/index.js +0 -19
  506. package/dist/ui/canvas/components/index.js.map +0 -1
  507. package/dist/ui/canvas/index.d.ts +0 -32
  508. package/dist/ui/canvas/index.d.ts.map +0 -1
  509. package/dist/ui/canvas/index.js +0 -32
  510. package/dist/ui/canvas/index.js.map +0 -1
  511. package/dist/ui/svelte-generator/index.d.ts +0 -9
  512. package/dist/ui/svelte-generator/index.d.ts.map +0 -1
  513. package/dist/ui/svelte-generator/index.js +0 -11
  514. package/dist/ui/svelte-generator/index.js.map +0 -1
  515. package/dist/ui/svelte-generator/psf-generator.d.ts +0 -128
  516. package/dist/ui/svelte-generator/psf-generator.d.ts.map +0 -1
  517. package/dist/ui/svelte-generator/psf-generator.js +0 -506
  518. package/dist/ui/svelte-generator/psf-generator.js.map +0 -1
@@ -0,0 +1,3247 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ ActorManager: () => ActorManager,
34
+ InMemoryPraxisDB: () => InMemoryPraxisDB,
35
+ LogicEngine: () => LogicEngine,
36
+ PRAXIS_PATHS: () => PRAXIS_PATHS,
37
+ PRAXIS_PROTOCOL_VERSION: () => PRAXIS_PROTOCOL_VERSION,
38
+ PluresDBGenerator: () => PluresDBGenerator,
39
+ PraxisDBStore: () => PraxisDBStore,
40
+ PraxisRegistry: () => PraxisRegistry,
41
+ PraxisSchemaRegistry: () => PraxisSchemaRegistry,
42
+ ReactiveLogicEngine: () => ReactiveLogicEngine,
43
+ RegistryIntrospector: () => RegistryIntrospector,
44
+ StateDocsGenerator: () => StateDocsGenerator,
45
+ TerminalAdapter: () => TerminalAdapter,
46
+ attachTauriToEngine: () => attachTauriToEngine,
47
+ attachToEngine: () => attachToEngine,
48
+ attachUnumToEngine: () => attachUnumToEngine,
49
+ canvasToMermaid: () => canvasToMermaid,
50
+ canvasToSchema: () => canvasToSchema,
51
+ canvasToYaml: () => canvasToYaml,
52
+ createCanvasEditor: () => createCanvasEditor,
53
+ createInMemoryDB: () => createInMemoryDB,
54
+ createIntrospector: () => createIntrospector,
55
+ createMockExecutor: () => createMockExecutor,
56
+ createMockTauriBridge: () => createMockTauriBridge,
57
+ createPluresDBAdapter: () => createPluresDBAdapter,
58
+ createPluresDBGenerator: () => createPluresDBGenerator,
59
+ createPraxisDBStore: () => createPraxisDBStore,
60
+ createPraxisEngine: () => createPraxisEngine,
61
+ createSchemaRegistry: () => createSchemaRegistry,
62
+ createSchemaTemplate: () => createSchemaTemplate,
63
+ createStateDocsGenerator: () => createStateDocsGenerator,
64
+ createTauriPraxisAdapter: () => createTauriPraxisAdapter,
65
+ createTerminalAdapter: () => createTerminalAdapter,
66
+ createTimerActor: () => createTimerActor,
67
+ createUnumAdapter: () => createUnumAdapter,
68
+ defineConstraint: () => defineConstraint,
69
+ defineEvent: () => defineEvent,
70
+ defineFact: () => defineFact,
71
+ defineModule: () => defineModule,
72
+ defineRule: () => defineRule,
73
+ filterEvents: () => filterEvents,
74
+ filterFacts: () => filterFacts,
75
+ findEvent: () => findEvent,
76
+ findFact: () => findFact,
77
+ generateDocs: () => generateDocs,
78
+ generateId: () => generateId,
79
+ generateTauriConfig: () => generateTauriConfig,
80
+ getEventPath: () => getEventPath,
81
+ getFactPath: () => getFactPath,
82
+ getSchemaPath: () => getSchemaPath,
83
+ loadSchema: () => loadSchema,
84
+ loadSchemaFromFile: () => loadSchemaFromFile,
85
+ loadSchemaFromJson: () => loadSchemaFromJson,
86
+ loadSchemaFromYaml: () => loadSchemaFromYaml,
87
+ registerSchema: () => registerSchema,
88
+ runTerminalCommand: () => runTerminalCommand,
89
+ schemaToCanvas: () => schemaToCanvas,
90
+ validateForGeneration: () => validateForGeneration,
91
+ validateSchema: () => validateSchema,
92
+ validateWithGuardian: () => validateWithGuardian
93
+ });
94
+ module.exports = __toCommonJS(src_exports);
95
+
96
+ // src/core/protocol.ts
97
+ var PRAXIS_PROTOCOL_VERSION = "1.0.0";
98
+
99
+ // src/core/rules.ts
100
+ var PraxisRegistry = class {
101
+ rules = /* @__PURE__ */ new Map();
102
+ constraints = /* @__PURE__ */ new Map();
103
+ /**
104
+ * Register a rule
105
+ */
106
+ registerRule(descriptor) {
107
+ if (this.rules.has(descriptor.id)) {
108
+ throw new Error(`Rule with id "${descriptor.id}" already registered`);
109
+ }
110
+ this.rules.set(descriptor.id, descriptor);
111
+ }
112
+ /**
113
+ * Register a constraint
114
+ */
115
+ registerConstraint(descriptor) {
116
+ if (this.constraints.has(descriptor.id)) {
117
+ throw new Error(`Constraint with id "${descriptor.id}" already registered`);
118
+ }
119
+ this.constraints.set(descriptor.id, descriptor);
120
+ }
121
+ /**
122
+ * Register a module (all its rules and constraints)
123
+ */
124
+ registerModule(module2) {
125
+ for (const rule of module2.rules) {
126
+ this.registerRule(rule);
127
+ }
128
+ for (const constraint of module2.constraints) {
129
+ this.registerConstraint(constraint);
130
+ }
131
+ }
132
+ /**
133
+ * Get a rule by ID
134
+ */
135
+ getRule(id) {
136
+ return this.rules.get(id);
137
+ }
138
+ /**
139
+ * Get a constraint by ID
140
+ */
141
+ getConstraint(id) {
142
+ return this.constraints.get(id);
143
+ }
144
+ /**
145
+ * Get all registered rule IDs
146
+ */
147
+ getRuleIds() {
148
+ return Array.from(this.rules.keys());
149
+ }
150
+ /**
151
+ * Get all registered constraint IDs
152
+ */
153
+ getConstraintIds() {
154
+ return Array.from(this.constraints.keys());
155
+ }
156
+ /**
157
+ * Get all rules
158
+ */
159
+ getAllRules() {
160
+ return Array.from(this.rules.values());
161
+ }
162
+ /**
163
+ * Get all constraints
164
+ */
165
+ getAllConstraints() {
166
+ return Array.from(this.constraints.values());
167
+ }
168
+ };
169
+
170
+ // src/core/engine.ts
171
+ function safeClone(value) {
172
+ if (value === null || typeof value !== "object") {
173
+ return value;
174
+ }
175
+ if (typeof globalThis.structuredClone === "function") {
176
+ try {
177
+ return globalThis.structuredClone(value);
178
+ } catch {
179
+ }
180
+ }
181
+ if (Array.isArray(value)) {
182
+ return [...value];
183
+ }
184
+ return { ...value };
185
+ }
186
+ var LogicEngine = class {
187
+ state;
188
+ registry;
189
+ constructor(options) {
190
+ this.registry = options.registry;
191
+ this.state = {
192
+ context: options.initialContext,
193
+ facts: options.initialFacts ?? [],
194
+ meta: options.initialMeta ?? {},
195
+ protocolVersion: PRAXIS_PROTOCOL_VERSION
196
+ };
197
+ }
198
+ /**
199
+ * Get the current state (immutable copy)
200
+ */
201
+ getState() {
202
+ return {
203
+ context: safeClone(this.state.context),
204
+ facts: [...this.state.facts],
205
+ meta: this.state.meta ? safeClone(this.state.meta) : void 0,
206
+ protocolVersion: this.state.protocolVersion
207
+ };
208
+ }
209
+ /**
210
+ * Get the current context
211
+ */
212
+ getContext() {
213
+ return safeClone(this.state.context);
214
+ }
215
+ /**
216
+ * Get current facts
217
+ */
218
+ getFacts() {
219
+ return [...this.state.facts];
220
+ }
221
+ /**
222
+ * Process events through the engine.
223
+ * Applies all registered rules and checks all registered constraints.
224
+ *
225
+ * @param events Events to process
226
+ * @returns Result with new state and diagnostics
227
+ */
228
+ step(events) {
229
+ const config = {
230
+ ruleIds: this.registry.getRuleIds(),
231
+ constraintIds: this.registry.getConstraintIds()
232
+ };
233
+ return this.stepWithConfig(events, config);
234
+ }
235
+ /**
236
+ * Process events with specific rule and constraint configuration.
237
+ *
238
+ * @param events Events to process
239
+ * @param config Step configuration
240
+ * @returns Result with new state and diagnostics
241
+ */
242
+ stepWithConfig(events, config) {
243
+ const diagnostics = [];
244
+ let newState = { ...this.state };
245
+ const newFacts = [];
246
+ for (const ruleId of config.ruleIds) {
247
+ const rule = this.registry.getRule(ruleId);
248
+ if (!rule) {
249
+ diagnostics.push({
250
+ kind: "rule-error",
251
+ message: `Rule "${ruleId}" not found in registry`,
252
+ data: { ruleId }
253
+ });
254
+ continue;
255
+ }
256
+ try {
257
+ const ruleFacts = rule.impl(newState, events);
258
+ newFacts.push(...ruleFacts);
259
+ } catch (error) {
260
+ diagnostics.push({
261
+ kind: "rule-error",
262
+ message: `Error executing rule "${ruleId}": ${error instanceof Error ? error.message : String(error)}`,
263
+ data: { ruleId, error }
264
+ });
265
+ }
266
+ }
267
+ newState = {
268
+ ...newState,
269
+ facts: [...newState.facts, ...newFacts]
270
+ };
271
+ for (const constraintId of config.constraintIds) {
272
+ const constraint = this.registry.getConstraint(constraintId);
273
+ if (!constraint) {
274
+ diagnostics.push({
275
+ kind: "constraint-violation",
276
+ message: `Constraint "${constraintId}" not found in registry`,
277
+ data: { constraintId }
278
+ });
279
+ continue;
280
+ }
281
+ try {
282
+ const result = constraint.impl(newState);
283
+ if (result === false) {
284
+ diagnostics.push({
285
+ kind: "constraint-violation",
286
+ message: `Constraint "${constraintId}" violated`,
287
+ data: { constraintId, description: constraint.description }
288
+ });
289
+ } else if (typeof result === "string") {
290
+ diagnostics.push({
291
+ kind: "constraint-violation",
292
+ message: result,
293
+ data: { constraintId, description: constraint.description }
294
+ });
295
+ }
296
+ } catch (error) {
297
+ diagnostics.push({
298
+ kind: "constraint-violation",
299
+ message: `Error checking constraint "${constraintId}": ${error instanceof Error ? error.message : String(error)}`,
300
+ data: { constraintId, error }
301
+ });
302
+ }
303
+ }
304
+ this.state = newState;
305
+ return {
306
+ state: newState,
307
+ diagnostics
308
+ };
309
+ }
310
+ /**
311
+ * Update the context directly (for exceptional cases).
312
+ * Generally, context should be updated through rules.
313
+ *
314
+ * @param updater Function that produces new context from old context
315
+ */
316
+ updateContext(updater) {
317
+ this.state = {
318
+ ...this.state,
319
+ context: updater(this.state.context)
320
+ };
321
+ }
322
+ /**
323
+ * Add facts directly (for exceptional cases).
324
+ * Generally, facts should be added through rules.
325
+ *
326
+ * @param facts Facts to add
327
+ */
328
+ addFacts(facts) {
329
+ this.state = {
330
+ ...this.state,
331
+ facts: [...this.state.facts, ...facts]
332
+ };
333
+ }
334
+ /**
335
+ * Clear all facts
336
+ */
337
+ clearFacts() {
338
+ this.state = {
339
+ ...this.state,
340
+ facts: []
341
+ };
342
+ }
343
+ /**
344
+ * Reset the engine to initial state
345
+ */
346
+ reset(options) {
347
+ this.state = {
348
+ context: options.initialContext,
349
+ facts: options.initialFacts ?? [],
350
+ meta: options.initialMeta ?? {},
351
+ protocolVersion: PRAXIS_PROTOCOL_VERSION
352
+ };
353
+ }
354
+ };
355
+ function createPraxisEngine(options) {
356
+ return new LogicEngine(options);
357
+ }
358
+
359
+ // src/core/reactive-engine.svelte.ts
360
+ var $ = __toESM(require("svelte/internal/client"), 1);
361
+ var ReactiveLogicEngine = class {
362
+ #state = (
363
+ // The single source of truth, reactive by default
364
+ // We use $state.raw for things that shouldn't be deeply reactive if needed,
365
+ // but for context we usually want deep reactivity.
366
+ $.state($.proxy({ context: {}, facts: [], meta: {} }))
367
+ );
368
+ get state() {
369
+ return $.get(this.#state);
370
+ }
371
+ set state(value) {
372
+ $.set(this.#state, value, true);
373
+ }
374
+ constructor(options) {
375
+ this.state.context = options.initialContext;
376
+ this.state.facts = options.initialFacts ?? [];
377
+ this.state.meta = options.initialMeta ?? {};
378
+ }
379
+ /**
380
+ * Access the reactive context directly.
381
+ * Consumers can use this in $derived() or $effect().
382
+ */
383
+ get context() {
384
+ return this.state.context;
385
+ }
386
+ /**
387
+ * Access the reactive facts list.
388
+ */
389
+ get facts() {
390
+ return this.state.facts;
391
+ }
392
+ /**
393
+ * Apply a mutation to the state.
394
+ * This is the "Action" or "Rule" equivalent.
395
+ *
396
+ * @param mutator A function that receives the state and modifies it.
397
+ */
398
+ apply(mutator) {
399
+ mutator(this.state);
400
+ }
401
+ /**
402
+ * Access the reactive meta.
403
+ */
404
+ get meta() {
405
+ return this.state.meta;
406
+ }
407
+ };
408
+
409
+ // src/core/actors.ts
410
+ var ActorManager = class {
411
+ actors = /* @__PURE__ */ new Map();
412
+ activeActors = /* @__PURE__ */ new Set();
413
+ engine = null;
414
+ /**
415
+ * Register an actor
416
+ */
417
+ register(actor) {
418
+ if (this.actors.has(actor.id)) {
419
+ throw new Error(`Actor with id "${actor.id}" already registered`);
420
+ }
421
+ this.actors.set(actor.id, actor);
422
+ }
423
+ /**
424
+ * Unregister an actor
425
+ */
426
+ unregister(actorId) {
427
+ if (this.activeActors.has(actorId)) {
428
+ throw new Error(`Cannot unregister active actor "${actorId}". Stop it first.`);
429
+ }
430
+ this.actors.delete(actorId);
431
+ }
432
+ /**
433
+ * Attach the actor manager to an engine
434
+ */
435
+ attachEngine(engine) {
436
+ this.engine = engine;
437
+ }
438
+ /**
439
+ * Start an actor
440
+ */
441
+ async start(actorId) {
442
+ const actor = this.actors.get(actorId);
443
+ if (!actor) {
444
+ throw new Error(`Actor "${actorId}" not found`);
445
+ }
446
+ if (this.activeActors.has(actorId)) {
447
+ throw new Error(`Actor "${actorId}" is already started`);
448
+ }
449
+ if (!this.engine) {
450
+ throw new Error("Actor manager not attached to an engine");
451
+ }
452
+ this.activeActors.add(actorId);
453
+ if (actor.onStart) {
454
+ await actor.onStart(this.engine);
455
+ }
456
+ }
457
+ /**
458
+ * Stop an actor
459
+ */
460
+ async stop(actorId) {
461
+ const actor = this.actors.get(actorId);
462
+ if (!actor) {
463
+ throw new Error(`Actor "${actorId}" not found`);
464
+ }
465
+ if (!this.activeActors.has(actorId)) {
466
+ return;
467
+ }
468
+ this.activeActors.delete(actorId);
469
+ if (actor.onStop) {
470
+ await actor.onStop();
471
+ }
472
+ }
473
+ /**
474
+ * Start all registered actors
475
+ */
476
+ async startAll() {
477
+ const actorIds = Array.from(this.actors.keys());
478
+ for (const actorId of actorIds) {
479
+ if (!this.activeActors.has(actorId)) {
480
+ await this.start(actorId);
481
+ }
482
+ }
483
+ }
484
+ /**
485
+ * Stop all active actors
486
+ */
487
+ async stopAll() {
488
+ const activeIds = Array.from(this.activeActors);
489
+ for (const actorId of activeIds) {
490
+ await this.stop(actorId);
491
+ }
492
+ }
493
+ /**
494
+ * Notify active actors of a state change
495
+ */
496
+ async notifyStateChange(state2) {
497
+ if (!this.engine) {
498
+ return;
499
+ }
500
+ const promises = [];
501
+ for (const actorId of this.activeActors) {
502
+ const actor = this.actors.get(actorId);
503
+ if (actor?.onStateChange) {
504
+ const result = actor.onStateChange(state2, this.engine);
505
+ if (result instanceof Promise) {
506
+ promises.push(result);
507
+ }
508
+ }
509
+ }
510
+ await Promise.all(promises);
511
+ }
512
+ /**
513
+ * Get all registered actor IDs
514
+ */
515
+ getActorIds() {
516
+ return Array.from(this.actors.keys());
517
+ }
518
+ /**
519
+ * Get all active actor IDs
520
+ */
521
+ getActiveActorIds() {
522
+ return Array.from(this.activeActors);
523
+ }
524
+ /**
525
+ * Check if an actor is active
526
+ */
527
+ isActive(actorId) {
528
+ return this.activeActors.has(actorId);
529
+ }
530
+ };
531
+ function createTimerActor(id, intervalMs, createEvent) {
532
+ let timerId = null;
533
+ return {
534
+ id,
535
+ description: `Timer actor (${intervalMs}ms) - ${id}`,
536
+ onStart: (engine) => {
537
+ timerId = setInterval(() => {
538
+ engine.step([createEvent()]);
539
+ }, intervalMs);
540
+ },
541
+ onStop: () => {
542
+ if (timerId) {
543
+ clearInterval(timerId);
544
+ timerId = null;
545
+ }
546
+ }
547
+ };
548
+ }
549
+
550
+ // src/core/introspection.ts
551
+ var RegistryIntrospector = class {
552
+ constructor(registry) {
553
+ this.registry = registry;
554
+ }
555
+ /**
556
+ * Get basic statistics about the registry
557
+ */
558
+ getStats() {
559
+ return {
560
+ ruleCount: this.registry.getRuleIds().length,
561
+ constraintCount: this.registry.getConstraintIds().length,
562
+ moduleCount: 0,
563
+ // Modules are flattened in registry
564
+ rulesById: this.registry.getRuleIds(),
565
+ constraintsById: this.registry.getConstraintIds()
566
+ };
567
+ }
568
+ /**
569
+ * Generate a JSON schema representation of the registry
570
+ */
571
+ generateSchema(protocolVersion) {
572
+ const rules = this.registry.getAllRules().map((rule) => ({
573
+ id: rule.id,
574
+ description: rule.description,
575
+ type: "rule",
576
+ meta: rule.meta
577
+ }));
578
+ const constraints = this.registry.getAllConstraints().map((constraint) => ({
579
+ id: constraint.id,
580
+ description: constraint.description,
581
+ type: "constraint",
582
+ meta: constraint.meta
583
+ }));
584
+ return {
585
+ protocolVersion,
586
+ rules,
587
+ constraints,
588
+ meta: {
589
+ ruleCount: rules.length,
590
+ constraintCount: constraints.length
591
+ }
592
+ };
593
+ }
594
+ /**
595
+ * Generate a graph representation of the registry
596
+ *
597
+ * This creates nodes for rules and constraints.
598
+ * Edges can be inferred from metadata if rules/constraints
599
+ * document their dependencies.
600
+ */
601
+ generateGraph() {
602
+ const nodes = [];
603
+ const edges = [];
604
+ for (const rule of this.registry.getAllRules()) {
605
+ nodes.push({
606
+ id: rule.id,
607
+ type: "rule",
608
+ description: rule.description,
609
+ meta: rule.meta
610
+ });
611
+ if (rule.meta?.dependsOn) {
612
+ const deps = Array.isArray(rule.meta.dependsOn) ? rule.meta.dependsOn : [rule.meta.dependsOn];
613
+ for (const dep of deps) {
614
+ edges.push({
615
+ from: String(dep),
616
+ to: rule.id,
617
+ type: "depends-on"
618
+ });
619
+ }
620
+ }
621
+ }
622
+ for (const constraint of this.registry.getAllConstraints()) {
623
+ nodes.push({
624
+ id: constraint.id,
625
+ type: "constraint",
626
+ description: constraint.description,
627
+ meta: constraint.meta
628
+ });
629
+ if (constraint.meta?.constrains) {
630
+ const targets = Array.isArray(constraint.meta.constrains) ? constraint.meta.constrains : [constraint.meta.constrains];
631
+ for (const target of targets) {
632
+ edges.push({
633
+ from: constraint.id,
634
+ to: String(target),
635
+ type: "constrains"
636
+ });
637
+ }
638
+ }
639
+ }
640
+ return {
641
+ nodes,
642
+ edges,
643
+ meta: {
644
+ nodeCount: nodes.length,
645
+ ruleCount: nodes.filter((n) => n.type === "rule").length,
646
+ constraintCount: nodes.filter((n) => n.type === "constraint").length
647
+ }
648
+ };
649
+ }
650
+ /**
651
+ * Export graph in DOT format (Graphviz)
652
+ *
653
+ * This can be rendered with Graphviz tools or online services.
654
+ */
655
+ exportDOT() {
656
+ const graph = this.generateGraph();
657
+ const lines = [];
658
+ lines.push("digraph PraxisRegistry {");
659
+ lines.push(" rankdir=TB;");
660
+ lines.push(" node [shape=box, style=rounded];");
661
+ lines.push("");
662
+ for (const node of graph.nodes) {
663
+ const shape = node.type === "rule" ? "box" : "diamond";
664
+ const color = node.type === "rule" ? "lightblue" : "lightcoral";
665
+ const label = `${node.id}\\n${node.description}`;
666
+ lines.push(
667
+ ` "${node.id}" [label="${label}", shape=${shape}, style=filled, fillcolor=${color}];`
668
+ );
669
+ }
670
+ lines.push("");
671
+ for (const edge of graph.edges) {
672
+ const style = edge.type === "constrains" ? "dashed" : "solid";
673
+ lines.push(` "${edge.from}" -> "${edge.to}" [label="${edge.type}", style=${style}];`);
674
+ }
675
+ lines.push("}");
676
+ return lines.join("\n");
677
+ }
678
+ /**
679
+ * Export graph in Mermaid format
680
+ *
681
+ * Mermaid is a markdown-friendly diagramming language.
682
+ */
683
+ exportMermaid() {
684
+ const graph = this.generateGraph();
685
+ const lines = [];
686
+ lines.push("graph TB");
687
+ for (const node of graph.nodes) {
688
+ const shape = node.type === "rule" ? "[" : "{";
689
+ const endShape = node.type === "rule" ? "]" : "}";
690
+ const label = `${node.id}<br/>${node.description}`;
691
+ lines.push(` ${node.id}${shape}"${label}"${endShape}`);
692
+ }
693
+ lines.push("");
694
+ for (const edge of graph.edges) {
695
+ const arrow = edge.type === "constrains" ? "-.->|constrains|" : "-->|" + edge.type + "|";
696
+ lines.push(` ${edge.from} ${arrow} ${edge.to}`);
697
+ }
698
+ return lines.join("\n");
699
+ }
700
+ /**
701
+ * Get detailed information about a specific rule
702
+ */
703
+ getRuleInfo(ruleId) {
704
+ return this.registry.getRule(ruleId);
705
+ }
706
+ /**
707
+ * Get detailed information about a specific constraint
708
+ */
709
+ getConstraintInfo(constraintId) {
710
+ return this.registry.getConstraint(constraintId);
711
+ }
712
+ /**
713
+ * Search for rules by description text
714
+ */
715
+ searchRules(query) {
716
+ const lowerQuery = query.toLowerCase();
717
+ return this.registry.getAllRules().filter(
718
+ (rule) => rule.id.toLowerCase().includes(lowerQuery) || rule.description.toLowerCase().includes(lowerQuery)
719
+ );
720
+ }
721
+ /**
722
+ * Search for constraints by description text
723
+ */
724
+ searchConstraints(query) {
725
+ const lowerQuery = query.toLowerCase();
726
+ return this.registry.getAllConstraints().filter(
727
+ (constraint) => constraint.id.toLowerCase().includes(lowerQuery) || constraint.description.toLowerCase().includes(lowerQuery)
728
+ );
729
+ }
730
+ };
731
+ function createIntrospector(registry) {
732
+ return new RegistryIntrospector(registry);
733
+ }
734
+
735
+ // src/dsl/index.ts
736
+ function defineFact(tag) {
737
+ return {
738
+ tag,
739
+ create(payload) {
740
+ return { tag, payload };
741
+ },
742
+ is(fact) {
743
+ return fact.tag === tag;
744
+ }
745
+ };
746
+ }
747
+ function defineEvent(tag) {
748
+ return {
749
+ tag,
750
+ create(payload) {
751
+ return { tag, payload };
752
+ },
753
+ is(event) {
754
+ return event.tag === tag;
755
+ }
756
+ };
757
+ }
758
+ function defineRule(options) {
759
+ return {
760
+ id: options.id,
761
+ description: options.description,
762
+ impl: options.impl,
763
+ meta: options.meta
764
+ };
765
+ }
766
+ function defineConstraint(options) {
767
+ return {
768
+ id: options.id,
769
+ description: options.description,
770
+ impl: options.impl,
771
+ meta: options.meta
772
+ };
773
+ }
774
+ function defineModule(options) {
775
+ return {
776
+ rules: options.rules ?? [],
777
+ constraints: options.constraints ?? [],
778
+ meta: options.meta
779
+ };
780
+ }
781
+ function filterEvents(events, definition) {
782
+ return events.filter(definition.is);
783
+ }
784
+ function filterFacts(facts, definition) {
785
+ return facts.filter(definition.is);
786
+ }
787
+ function findEvent(events, definition) {
788
+ return events.find(definition.is);
789
+ }
790
+ function findFact(facts, definition) {
791
+ return facts.find(definition.is);
792
+ }
793
+
794
+ // src/runtime/terminal-adapter.ts
795
+ async function defaultExecutor(command, options) {
796
+ try {
797
+ const { exec } = await import("child_process");
798
+ const { promisify } = await import("util");
799
+ const execAsync = promisify(exec);
800
+ const processEnv = typeof process !== "undefined" ? process.env : {};
801
+ const result = await execAsync(command, {
802
+ cwd: options.cwd,
803
+ env: { ...processEnv, ...options.env },
804
+ maxBuffer: 10 * 1024 * 1024,
805
+ // 10MB buffer
806
+ timeout: 6e4
807
+ // 60 second timeout
808
+ });
809
+ return {
810
+ output: result.stdout + (result.stderr ? `
811
+ ${result.stderr}` : ""),
812
+ exitCode: 0
813
+ };
814
+ } catch (error) {
815
+ const execError = error;
816
+ return {
817
+ output: (execError.stdout || "") + (execError.stderr || ""),
818
+ exitCode: execError.code || 1,
819
+ error: execError.message || "Command execution failed"
820
+ };
821
+ }
822
+ }
823
+ var TerminalAdapter = class {
824
+ state;
825
+ inputPath;
826
+ outputPath;
827
+ db;
828
+ executor;
829
+ constructor(options) {
830
+ this.state = {
831
+ nodeId: options.nodeId,
832
+ inputMode: options.props?.inputMode || "text",
833
+ history: options.props?.history || [],
834
+ lastOutput: options.props?.lastOutput || null,
835
+ cwd: options.cwd,
836
+ env: options.env
837
+ };
838
+ this.inputPath = options.inputPath;
839
+ this.outputPath = options.outputPath;
840
+ this.db = options.db;
841
+ this.executor = options.executor || defaultExecutor;
842
+ }
843
+ /**
844
+ * Execute a terminal command
845
+ *
846
+ * @param command - Command to execute
847
+ * @returns Execution result
848
+ */
849
+ async executeCommand(command) {
850
+ this.state.history.push(command);
851
+ const timestamp = Date.now();
852
+ const { output, exitCode, error } = await this.executor(command, {
853
+ cwd: this.state.cwd,
854
+ env: this.state.env
855
+ });
856
+ const result = {
857
+ command,
858
+ output,
859
+ exitCode,
860
+ timestamp,
861
+ error
862
+ };
863
+ this.state.lastOutput = output;
864
+ if (this.db && this.outputPath) {
865
+ await this.syncToPluresDB(this.outputPath, result);
866
+ }
867
+ return result;
868
+ }
869
+ /**
870
+ * Get current terminal state
871
+ */
872
+ getState() {
873
+ return { ...this.state };
874
+ }
875
+ /**
876
+ * Update terminal props
877
+ */
878
+ updateProps(props) {
879
+ this.state = {
880
+ ...this.state,
881
+ ...props
882
+ };
883
+ }
884
+ /**
885
+ * Set working directory
886
+ */
887
+ setCwd(cwd) {
888
+ this.state.cwd = cwd;
889
+ }
890
+ /**
891
+ * Set environment variables
892
+ */
893
+ setEnv(env) {
894
+ this.state.env = { ...this.state.env, ...env };
895
+ }
896
+ /**
897
+ * Clear command history
898
+ */
899
+ clearHistory() {
900
+ this.state.history = [];
901
+ }
902
+ /**
903
+ * Get command history
904
+ */
905
+ getHistory() {
906
+ return [...this.state.history];
907
+ }
908
+ /**
909
+ * Sync state to PluresDB
910
+ *
911
+ * @param path - PluresDB path for storing results
912
+ * @param data - Data to sync
913
+ */
914
+ async syncToPluresDB(path, data) {
915
+ if (!this.db) return;
916
+ try {
917
+ await this.db.set(path, {
918
+ ...data,
919
+ nodeId: this.state.nodeId,
920
+ syncedAt: Date.now()
921
+ });
922
+ const historyPath = `${path}/history`;
923
+ const historyKey = `${historyPath}/${data.timestamp}`;
924
+ await this.db.set(historyKey, data);
925
+ } catch (error) {
926
+ console.warn("Failed to sync to PluresDB:", error);
927
+ }
928
+ }
929
+ /**
930
+ * Load state from PluresDB
931
+ */
932
+ async loadFromPluresDB() {
933
+ if (!this.db || !this.inputPath) return;
934
+ try {
935
+ const data = await this.db.get(this.inputPath);
936
+ if (data && typeof data === "object") {
937
+ const savedState = data;
938
+ if (savedState.history) {
939
+ this.state.history = savedState.history;
940
+ }
941
+ if (savedState.lastOutput !== void 0) {
942
+ this.state.lastOutput = savedState.lastOutput;
943
+ }
944
+ if (savedState.cwd) {
945
+ this.state.cwd = savedState.cwd;
946
+ }
947
+ if (savedState.env) {
948
+ this.state.env = savedState.env;
949
+ }
950
+ }
951
+ } catch (error) {
952
+ console.warn("Failed to load from PluresDB:", error);
953
+ }
954
+ }
955
+ /**
956
+ * Subscribe to input changes from PluresDB
957
+ */
958
+ watchInput(callback) {
959
+ if (!this.db || !this.inputPath) return null;
960
+ return this.db.watch(this.inputPath, (data) => {
961
+ if (data && typeof data === "object" && "command" in data) {
962
+ callback(data.command);
963
+ }
964
+ });
965
+ }
966
+ };
967
+ function createTerminalAdapter(options) {
968
+ return new TerminalAdapter(options);
969
+ }
970
+ async function runTerminalCommand(nodeId, command, options) {
971
+ const adapter = createTerminalAdapter({
972
+ nodeId,
973
+ cwd: options?.cwd,
974
+ env: options?.env,
975
+ db: options?.db,
976
+ executor: options?.executor
977
+ });
978
+ return adapter.executeCommand(command);
979
+ }
980
+ function createMockExecutor(responses) {
981
+ return async (command) => {
982
+ const response = responses[command] || responses["*"] || {
983
+ output: `Mock output for: ${command}`,
984
+ exitCode: 0
985
+ };
986
+ return response;
987
+ };
988
+ }
989
+
990
+ // src/core/schema/types.ts
991
+ function validateSchema(schema) {
992
+ const errors = [];
993
+ if (!schema.version) {
994
+ errors.push({ path: "version", message: "Schema version is required" });
995
+ }
996
+ if (!schema.name) {
997
+ errors.push({ path: "name", message: "Schema name is required" });
998
+ }
999
+ if (schema.models) {
1000
+ schema.models.forEach((model, index) => {
1001
+ if (!model.name) {
1002
+ errors.push({
1003
+ path: `models[${index}].name`,
1004
+ message: "Model name is required"
1005
+ });
1006
+ }
1007
+ if (!model.fields || model.fields.length === 0) {
1008
+ errors.push({
1009
+ path: `models[${index}].fields`,
1010
+ message: "Model must have at least one field"
1011
+ });
1012
+ }
1013
+ });
1014
+ }
1015
+ if (schema.components) {
1016
+ schema.components.forEach((component, index) => {
1017
+ if (!component.name) {
1018
+ errors.push({
1019
+ path: `components[${index}].name`,
1020
+ message: "Component name is required"
1021
+ });
1022
+ }
1023
+ if (!component.type) {
1024
+ errors.push({
1025
+ path: `components[${index}].type`,
1026
+ message: "Component type is required"
1027
+ });
1028
+ }
1029
+ });
1030
+ }
1031
+ if (schema.logic) {
1032
+ schema.logic.forEach((logic, logicIndex) => {
1033
+ if (logic.facts) {
1034
+ logic.facts.forEach((fact, factIndex) => {
1035
+ if (!fact.tag) {
1036
+ errors.push({
1037
+ path: `logic[${logicIndex}].facts[${factIndex}].tag`,
1038
+ message: "Fact tag is required"
1039
+ });
1040
+ } else if (!isValidIdentifier(fact.tag)) {
1041
+ errors.push({
1042
+ path: `logic[${logicIndex}].facts[${factIndex}].tag`,
1043
+ message: `Fact tag "${fact.tag}" is not a valid JavaScript identifier. Use only letters, numbers, underscores, and dollar signs, and do not start with a number.`
1044
+ });
1045
+ }
1046
+ });
1047
+ }
1048
+ if (logic.events) {
1049
+ logic.events.forEach((event, eventIndex) => {
1050
+ if (!event.tag) {
1051
+ errors.push({
1052
+ path: `logic[${logicIndex}].events[${eventIndex}].tag`,
1053
+ message: "Event tag is required"
1054
+ });
1055
+ } else if (!isValidIdentifier(event.tag)) {
1056
+ errors.push({
1057
+ path: `logic[${logicIndex}].events[${eventIndex}].tag`,
1058
+ message: `Event tag "${event.tag}" is not a valid JavaScript identifier. Use only letters, numbers, underscores, and dollar signs, and do not start with a number.`
1059
+ });
1060
+ }
1061
+ });
1062
+ }
1063
+ });
1064
+ }
1065
+ if (schema.orchestration?.nodes) {
1066
+ schema.orchestration.nodes.forEach((node, index) => {
1067
+ if (!node.id) {
1068
+ errors.push({
1069
+ path: `orchestration.nodes[${index}].id`,
1070
+ message: "Node id is required"
1071
+ });
1072
+ }
1073
+ if (!node.type) {
1074
+ errors.push({
1075
+ path: `orchestration.nodes[${index}].type`,
1076
+ message: "Node type is required"
1077
+ });
1078
+ }
1079
+ if (node.type === "terminal" && node.props) {
1080
+ const props = node.props;
1081
+ if (props.inputMode && !["text", "widget"].includes(props.inputMode)) {
1082
+ errors.push({
1083
+ path: `orchestration.nodes[${index}].props.inputMode`,
1084
+ message: 'Terminal node inputMode must be "text" or "widget"'
1085
+ });
1086
+ }
1087
+ if (props.history && !Array.isArray(props.history)) {
1088
+ errors.push({
1089
+ path: `orchestration.nodes[${index}].props.history`,
1090
+ message: "Terminal node history must be an array"
1091
+ });
1092
+ }
1093
+ }
1094
+ });
1095
+ }
1096
+ return {
1097
+ valid: errors.length === 0,
1098
+ errors
1099
+ };
1100
+ }
1101
+ function isValidIdentifier(str) {
1102
+ const identifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
1103
+ const reservedKeywords = [
1104
+ "break",
1105
+ "case",
1106
+ "catch",
1107
+ "class",
1108
+ "const",
1109
+ "continue",
1110
+ "debugger",
1111
+ "default",
1112
+ "delete",
1113
+ "do",
1114
+ "else",
1115
+ "export",
1116
+ "extends",
1117
+ "finally",
1118
+ "for",
1119
+ "function",
1120
+ "if",
1121
+ "import",
1122
+ "in",
1123
+ "instanceof",
1124
+ "new",
1125
+ "return",
1126
+ "super",
1127
+ "switch",
1128
+ "this",
1129
+ "throw",
1130
+ "try",
1131
+ "typeof",
1132
+ "var",
1133
+ "void",
1134
+ "while",
1135
+ "with",
1136
+ "yield",
1137
+ "let",
1138
+ "static",
1139
+ "enum",
1140
+ "await",
1141
+ "implements",
1142
+ "interface",
1143
+ "package",
1144
+ "private",
1145
+ "protected",
1146
+ "public"
1147
+ ];
1148
+ return identifierRegex.test(str) && !reservedKeywords.includes(str);
1149
+ }
1150
+ function createSchemaTemplate(name) {
1151
+ return {
1152
+ version: "1.0.0",
1153
+ name,
1154
+ description: `Schema for ${name}`,
1155
+ models: [],
1156
+ components: [],
1157
+ logic: []
1158
+ };
1159
+ }
1160
+
1161
+ // src/core/schema/loader.ts
1162
+ var import_promises = require("fs/promises");
1163
+ var import_node_url = require("url");
1164
+
1165
+ // src/core/schema/loader.common.ts
1166
+ var import_js_yaml = require("js-yaml");
1167
+ function loadSchemaFromJson(json, options = {}) {
1168
+ const errors = [];
1169
+ try {
1170
+ const schema = JSON.parse(json);
1171
+ let validation;
1172
+ if (options.validate !== false) {
1173
+ validation = validateSchema(schema);
1174
+ if (!validation.valid) {
1175
+ errors.push("Schema validation failed:");
1176
+ validation.errors.forEach((error) => {
1177
+ errors.push(` ${error.path}: ${error.message}`);
1178
+ });
1179
+ }
1180
+ }
1181
+ return {
1182
+ schema,
1183
+ validation,
1184
+ errors
1185
+ };
1186
+ } catch (error) {
1187
+ if (error instanceof Error) {
1188
+ errors.push(`Failed to parse JSON: ${error.message}`);
1189
+ } else {
1190
+ errors.push("Failed to parse JSON: Unknown error");
1191
+ }
1192
+ return { errors };
1193
+ }
1194
+ }
1195
+ function loadSchemaFromYaml(yaml, options = {}) {
1196
+ const errors = [];
1197
+ try {
1198
+ const schema = (0, import_js_yaml.load)(yaml);
1199
+ let validation;
1200
+ if (options.validate !== false) {
1201
+ validation = validateSchema(schema);
1202
+ if (!validation.valid) {
1203
+ errors.push("Schema validation failed:");
1204
+ validation.errors.forEach((error) => {
1205
+ errors.push(` ${error.path}: ${error.message}`);
1206
+ });
1207
+ }
1208
+ }
1209
+ return {
1210
+ schema,
1211
+ validation,
1212
+ errors
1213
+ };
1214
+ } catch (error) {
1215
+ if (error instanceof Error) {
1216
+ errors.push(`Failed to parse YAML: ${error.message}`);
1217
+ } else {
1218
+ errors.push("Failed to parse YAML: Unknown error");
1219
+ }
1220
+ return { errors };
1221
+ }
1222
+ }
1223
+ function validateForGeneration(schema) {
1224
+ const errors = [];
1225
+ if (!schema.models || schema.models.length === 0) {
1226
+ errors.push("Schema must define at least one model for generation");
1227
+ }
1228
+ schema.models?.forEach((model, index) => {
1229
+ if (!model.fields || model.fields.length === 0) {
1230
+ errors.push(`Model "${model.name}" at index ${index} must have at least one field`);
1231
+ }
1232
+ model.fields?.forEach((field, fieldIndex) => {
1233
+ if (!field.name) {
1234
+ errors.push(`Field at index ${fieldIndex} in model "${model.name}" must have a name`);
1235
+ }
1236
+ if (!field.type) {
1237
+ errors.push(`Field "${field.name}" in model "${model.name}" must have a type`);
1238
+ }
1239
+ });
1240
+ });
1241
+ return {
1242
+ valid: errors.length === 0,
1243
+ errors: errors.map((message) => ({ path: "schema", message }))
1244
+ };
1245
+ }
1246
+
1247
+ // src/core/schema/loader.ts
1248
+ async function loadSchema(filePath, options = {}) {
1249
+ const errors = [];
1250
+ try {
1251
+ let fileUrl = (0, import_node_url.pathToFileURL)(filePath).href;
1252
+ const module2 = await import(fileUrl);
1253
+ let schema;
1254
+ if (module2.default) {
1255
+ schema = module2.default;
1256
+ } else if (module2.schema) {
1257
+ schema = module2.schema;
1258
+ } else if (module2.appSchema) {
1259
+ schema = module2.appSchema;
1260
+ } else {
1261
+ const exports2 = Object.values(module2);
1262
+ const possibleSchema = exports2.find(
1263
+ (exp) => typeof exp === "object" && exp !== null && "version" in exp && "name" in exp
1264
+ );
1265
+ if (possibleSchema) {
1266
+ schema = possibleSchema;
1267
+ }
1268
+ }
1269
+ if (!schema) {
1270
+ errors.push(
1271
+ "Schema file must export a PraxisSchema object (as default, schema, or appSchema)"
1272
+ );
1273
+ return { errors };
1274
+ }
1275
+ let validation;
1276
+ if (options.validate !== false) {
1277
+ validation = validateSchema(schema);
1278
+ if (!validation.valid) {
1279
+ errors.push("Schema validation failed:");
1280
+ validation.errors.forEach((error) => {
1281
+ errors.push(` ${error.path}: ${error.message}`);
1282
+ });
1283
+ }
1284
+ }
1285
+ return {
1286
+ schema,
1287
+ validation,
1288
+ errors
1289
+ };
1290
+ } catch (error) {
1291
+ if (error instanceof Error) {
1292
+ errors.push(`Failed to load schema: ${error.message}`);
1293
+ } else {
1294
+ errors.push("Failed to load schema: Unknown error");
1295
+ }
1296
+ return { errors };
1297
+ }
1298
+ }
1299
+ async function loadSchemaFromFile(filePath, options = {}) {
1300
+ if (filePath.endsWith(".json")) {
1301
+ const content = await (0, import_promises.readFile)(filePath, "utf-8");
1302
+ return loadSchemaFromJson(content, options);
1303
+ } else if (filePath.endsWith(".yaml") || filePath.endsWith(".yml")) {
1304
+ const content = await (0, import_promises.readFile)(filePath, "utf-8");
1305
+ return loadSchemaFromYaml(content, options);
1306
+ } else {
1307
+ return loadSchema(filePath, options);
1308
+ }
1309
+ }
1310
+
1311
+ // src/core/pluresdb/store.ts
1312
+ var PRAXIS_PATHS = {
1313
+ /** Base path for all Praxis data */
1314
+ BASE: "/_praxis",
1315
+ /** Path for facts storage */
1316
+ FACTS: "/_praxis/facts",
1317
+ /** Path for events storage */
1318
+ EVENTS: "/_praxis/events",
1319
+ /** Path for schema registry */
1320
+ SCHEMAS: "/_praxis/schemas"
1321
+ };
1322
+ function getFactPath(factTag, id) {
1323
+ if (id) {
1324
+ return `${PRAXIS_PATHS.FACTS}/${factTag}/${id}`;
1325
+ }
1326
+ return `${PRAXIS_PATHS.FACTS}/${factTag}`;
1327
+ }
1328
+ function getEventPath(eventTag) {
1329
+ return `${PRAXIS_PATHS.EVENTS}/${eventTag}`;
1330
+ }
1331
+ function generateId() {
1332
+ return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
1333
+ }
1334
+ var defaultErrorHandler = (ruleId, error) => {
1335
+ if (typeof process !== "undefined" && process.env?.NODE_ENV === "development") {
1336
+ console.error(`Error executing rule "${ruleId}":`, error);
1337
+ }
1338
+ };
1339
+ var PraxisDBStore = class {
1340
+ db;
1341
+ registry;
1342
+ context;
1343
+ subscriptions = [];
1344
+ factWatchers = /* @__PURE__ */ new Map();
1345
+ onRuleError;
1346
+ constructor(options) {
1347
+ this.db = options.db;
1348
+ this.registry = options.registry;
1349
+ this.context = options.initialContext ?? {};
1350
+ this.onRuleError = options.onRuleError ?? defaultErrorHandler;
1351
+ }
1352
+ /**
1353
+ * Store a fact in PluresDB
1354
+ *
1355
+ * Facts are stored under `/_praxis/facts/<factTag>/<id>`
1356
+ * If no id is provided in the payload, a timestamp-based id is used.
1357
+ *
1358
+ * @param fact The fact to store
1359
+ * @returns Promise that resolves when the fact is stored
1360
+ */
1361
+ async storeFact(fact) {
1362
+ const constraintResult = await this.checkConstraints([fact]);
1363
+ if (!constraintResult.valid) {
1364
+ throw new Error(`Constraint violation: ${constraintResult.errors.join(", ")}`);
1365
+ }
1366
+ await this.persistFact(fact);
1367
+ await this.triggerRules([fact]);
1368
+ }
1369
+ /**
1370
+ * Store multiple facts in PluresDB
1371
+ *
1372
+ * @param facts The facts to store
1373
+ */
1374
+ async storeFacts(facts) {
1375
+ const constraintResult = await this.checkConstraints(facts);
1376
+ if (!constraintResult.valid) {
1377
+ throw new Error(`Constraint violation: ${constraintResult.errors.join(", ")}`);
1378
+ }
1379
+ for (const fact of facts) {
1380
+ await this.persistFact(fact);
1381
+ }
1382
+ await this.triggerRules(facts);
1383
+ }
1384
+ /**
1385
+ * Internal method to persist a fact without constraint checking
1386
+ * Used by both storeFact and derived fact storage
1387
+ */
1388
+ async persistFact(fact) {
1389
+ const payload = fact.payload;
1390
+ const id = payload?.id ?? generateId();
1391
+ const path = getFactPath(fact.tag, id);
1392
+ await this.db.set(path, fact);
1393
+ }
1394
+ /**
1395
+ * Get a fact by tag and id
1396
+ *
1397
+ * @param factTag The fact type tag
1398
+ * @param id The fact id
1399
+ * @returns The fact or undefined if not found
1400
+ */
1401
+ async getFact(factTag, id) {
1402
+ const path = getFactPath(factTag, id);
1403
+ return this.db.get(path);
1404
+ }
1405
+ /**
1406
+ * Append an event to the event stream
1407
+ *
1408
+ * Events are stored as append-only streams under `/_praxis/events/<eventTag>`
1409
+ *
1410
+ * @param event The event to append
1411
+ */
1412
+ async appendEvent(event) {
1413
+ const path = getEventPath(event.tag);
1414
+ const existingEvents = await this.db.get(path) ?? [];
1415
+ const entry = {
1416
+ event,
1417
+ timestamp: Date.now(),
1418
+ sequence: existingEvents.length
1419
+ };
1420
+ const newEvents = [...existingEvents, entry];
1421
+ await this.db.set(path, newEvents);
1422
+ await this.triggerRulesForEvents([event]);
1423
+ }
1424
+ /**
1425
+ * Append multiple events to their respective streams
1426
+ *
1427
+ * @param events The events to append
1428
+ */
1429
+ async appendEvents(events) {
1430
+ const eventsByTag = /* @__PURE__ */ new Map();
1431
+ for (const event of events) {
1432
+ const existing = eventsByTag.get(event.tag) ?? [];
1433
+ eventsByTag.set(event.tag, [...existing, event]);
1434
+ }
1435
+ for (const [tag, tagEvents] of eventsByTag) {
1436
+ const path = getEventPath(tag);
1437
+ const existingEvents = await this.db.get(path) ?? [];
1438
+ let sequence = existingEvents.length;
1439
+ const newEntries = tagEvents.map((event) => ({
1440
+ event,
1441
+ timestamp: Date.now(),
1442
+ sequence: sequence++
1443
+ }));
1444
+ await this.db.set(path, [...existingEvents, ...newEntries]);
1445
+ }
1446
+ await this.triggerRulesForEvents(events);
1447
+ }
1448
+ /**
1449
+ * Get events from a stream
1450
+ *
1451
+ * @param eventTag The event type tag
1452
+ * @param options Query options
1453
+ * @returns Array of event stream entries
1454
+ */
1455
+ async getEvents(eventTag, options) {
1456
+ const path = getEventPath(eventTag);
1457
+ const events = await this.db.get(path) ?? [];
1458
+ let result = events;
1459
+ if (options?.since !== void 0) {
1460
+ const sinceTimestamp = options.since;
1461
+ result = result.filter((e) => e.timestamp > sinceTimestamp);
1462
+ }
1463
+ if (options?.limit !== void 0) {
1464
+ result = result.slice(-options.limit);
1465
+ }
1466
+ return result;
1467
+ }
1468
+ /**
1469
+ * Watch a fact path for changes
1470
+ *
1471
+ * @param factTag The fact type tag to watch
1472
+ * @param callback Called when facts of this type change
1473
+ * @returns Unsubscribe function
1474
+ */
1475
+ watchFacts(factTag, callback) {
1476
+ const path = getFactPath(factTag);
1477
+ if (!this.factWatchers.has(factTag)) {
1478
+ this.factWatchers.set(factTag, /* @__PURE__ */ new Set());
1479
+ }
1480
+ const watchers = this.factWatchers.get(factTag);
1481
+ if (watchers) {
1482
+ watchers.add(callback);
1483
+ }
1484
+ const unsubscribe = this.db.watch(path, (fact) => {
1485
+ callback([fact]);
1486
+ });
1487
+ this.subscriptions.push(unsubscribe);
1488
+ return () => {
1489
+ unsubscribe();
1490
+ this.factWatchers.get(factTag)?.delete(callback);
1491
+ };
1492
+ }
1493
+ /**
1494
+ * Check constraints against the current state with new facts
1495
+ */
1496
+ async checkConstraints(newFacts) {
1497
+ const constraints = this.registry.getAllConstraints();
1498
+ const errors = [];
1499
+ const state2 = {
1500
+ context: this.context,
1501
+ facts: newFacts,
1502
+ meta: {}
1503
+ };
1504
+ for (const constraint of constraints) {
1505
+ try {
1506
+ const result = constraint.impl(state2);
1507
+ if (result === false) {
1508
+ errors.push(`Constraint "${constraint.id}" violated`);
1509
+ } else if (typeof result === "string") {
1510
+ errors.push(result);
1511
+ }
1512
+ } catch (error) {
1513
+ errors.push(
1514
+ `Error checking constraint "${constraint.id}": ${error instanceof Error ? error.message : String(error)}`
1515
+ );
1516
+ }
1517
+ }
1518
+ return {
1519
+ valid: errors.length === 0,
1520
+ errors
1521
+ };
1522
+ }
1523
+ /**
1524
+ * Trigger rules when new facts are added
1525
+ *
1526
+ * This method is called after facts are stored. It can be extended
1527
+ * for derived fact computation where rules generate new facts based
1528
+ * on existing facts. Currently implemented as a hook point for future
1529
+ * enhancements.
1530
+ *
1531
+ * @param _newFacts The newly stored facts (unused in current implementation)
1532
+ */
1533
+ async triggerRules(_newFacts) {
1534
+ }
1535
+ /**
1536
+ * Trigger rules when events are appended
1537
+ */
1538
+ async triggerRulesForEvents(events) {
1539
+ const rules = this.registry.getAllRules();
1540
+ const state2 = {
1541
+ context: this.context,
1542
+ facts: [],
1543
+ meta: {}
1544
+ };
1545
+ const derivedFacts = [];
1546
+ for (const rule of rules) {
1547
+ try {
1548
+ const facts = rule.impl(state2, events);
1549
+ derivedFacts.push(...facts);
1550
+ } catch (error) {
1551
+ this.onRuleError(rule.id, error);
1552
+ }
1553
+ }
1554
+ if (derivedFacts.length > 0) {
1555
+ const constraintResult = await this.checkConstraints(derivedFacts);
1556
+ if (constraintResult.valid) {
1557
+ for (const fact of derivedFacts) {
1558
+ await this.persistFact(fact);
1559
+ }
1560
+ }
1561
+ }
1562
+ }
1563
+ /**
1564
+ * Update the context
1565
+ */
1566
+ updateContext(context) {
1567
+ this.context = context;
1568
+ }
1569
+ /**
1570
+ * Get the current context
1571
+ */
1572
+ getContext() {
1573
+ return this.context;
1574
+ }
1575
+ /**
1576
+ * Dispose of all subscriptions
1577
+ */
1578
+ dispose() {
1579
+ for (const unsubscribe of this.subscriptions) {
1580
+ unsubscribe();
1581
+ }
1582
+ this.subscriptions = [];
1583
+ this.factWatchers.clear();
1584
+ }
1585
+ };
1586
+ function createPraxisDBStore(db, registry, initialContext, onRuleError) {
1587
+ return new PraxisDBStore({ db, registry, initialContext, onRuleError });
1588
+ }
1589
+
1590
+ // src/core/pluresdb/adapter.ts
1591
+ var InMemoryPraxisDB = class {
1592
+ store = /* @__PURE__ */ new Map();
1593
+ watchers = /* @__PURE__ */ new Map();
1594
+ async get(key) {
1595
+ return this.store.get(key);
1596
+ }
1597
+ async set(key, value) {
1598
+ this.store.set(key, value);
1599
+ const keyWatchers = this.watchers.get(key);
1600
+ if (keyWatchers) {
1601
+ for (const callback of keyWatchers) {
1602
+ callback(value);
1603
+ }
1604
+ }
1605
+ }
1606
+ watch(key, callback) {
1607
+ if (!this.watchers.has(key)) {
1608
+ this.watchers.set(key, /* @__PURE__ */ new Set());
1609
+ }
1610
+ const watchers = this.watchers.get(key);
1611
+ const wrappedCallback = (val) => callback(val);
1612
+ watchers.add(wrappedCallback);
1613
+ return () => {
1614
+ watchers.delete(wrappedCallback);
1615
+ if (watchers.size === 0) {
1616
+ this.watchers.delete(key);
1617
+ }
1618
+ };
1619
+ }
1620
+ /**
1621
+ * Get all keys (for testing/debugging)
1622
+ */
1623
+ keys() {
1624
+ return Array.from(this.store.keys());
1625
+ }
1626
+ /**
1627
+ * Clear all data (for testing)
1628
+ */
1629
+ clear() {
1630
+ this.store.clear();
1631
+ this.watchers.clear();
1632
+ }
1633
+ };
1634
+ function createInMemoryDB() {
1635
+ return new InMemoryPraxisDB();
1636
+ }
1637
+
1638
+ // src/core/pluresdb/schema-registry.ts
1639
+ function getSchemaPath(schemaName) {
1640
+ return `${PRAXIS_PATHS.SCHEMAS}/${schemaName}`;
1641
+ }
1642
+ var PraxisSchemaRegistry = class {
1643
+ db;
1644
+ constructor(db) {
1645
+ this.db = db;
1646
+ }
1647
+ /**
1648
+ * Register a schema in PluresDB
1649
+ *
1650
+ * @param schema The schema to register
1651
+ */
1652
+ async register(schema) {
1653
+ const path = getSchemaPath(schema.name);
1654
+ const storedSchema = {
1655
+ schema,
1656
+ registeredAt: Date.now(),
1657
+ version: schema.version
1658
+ };
1659
+ await this.db.set(path, storedSchema);
1660
+ }
1661
+ /**
1662
+ * Get a schema by name
1663
+ *
1664
+ * @param schemaName The schema name
1665
+ * @returns The stored schema or undefined if not found
1666
+ */
1667
+ async get(schemaName) {
1668
+ const path = getSchemaPath(schemaName);
1669
+ return this.db.get(path);
1670
+ }
1671
+ /**
1672
+ * Check if a schema is registered
1673
+ *
1674
+ * @param schemaName The schema name
1675
+ * @returns True if the schema exists
1676
+ */
1677
+ async exists(schemaName) {
1678
+ const stored = await this.get(schemaName);
1679
+ return stored !== void 0;
1680
+ }
1681
+ /**
1682
+ * Update a schema (replaces existing)
1683
+ *
1684
+ * @param schema The updated schema
1685
+ */
1686
+ async update(schema) {
1687
+ await this.register(schema);
1688
+ }
1689
+ /**
1690
+ * List all registered schema names
1691
+ *
1692
+ * Implementation note: This method uses an index stored at `/_praxis/schemas/_index`.
1693
+ * When using InMemoryPraxisDB, schemas must be registered using `registerWithIndex()`
1694
+ * for them to appear in this listing. When using a full PluresDB implementation,
1695
+ * native listing capabilities should be used instead.
1696
+ *
1697
+ * @returns Array of registered schema names
1698
+ */
1699
+ async list() {
1700
+ const indexPath = `${PRAXIS_PATHS.SCHEMAS}/_index`;
1701
+ const index = await this.db.get(indexPath);
1702
+ return index ?? [];
1703
+ }
1704
+ /**
1705
+ * Register a schema and update the index
1706
+ *
1707
+ * @param schema The schema to register
1708
+ */
1709
+ async registerWithIndex(schema) {
1710
+ await this.register(schema);
1711
+ const indexPath = `${PRAXIS_PATHS.SCHEMAS}/_index`;
1712
+ const existingIndex = await this.db.get(indexPath) ?? [];
1713
+ if (!existingIndex.includes(schema.name)) {
1714
+ await this.db.set(indexPath, [...existingIndex, schema.name]);
1715
+ }
1716
+ }
1717
+ };
1718
+ async function registerSchema(db, schema) {
1719
+ const registry = new PraxisSchemaRegistry(db);
1720
+ await registry.registerWithIndex(schema);
1721
+ }
1722
+ function createSchemaRegistry(db) {
1723
+ return new PraxisSchemaRegistry(db);
1724
+ }
1725
+
1726
+ // src/core/pluresdb/generator.ts
1727
+ var PluresDBGenerator = class {
1728
+ options;
1729
+ constructor(options) {
1730
+ this.options = {
1731
+ dbVersion: 1,
1732
+ enableSync: false,
1733
+ autoIndex: "all",
1734
+ // Default to indexing all fields for backward compatibility
1735
+ ...options
1736
+ };
1737
+ }
1738
+ /**
1739
+ * Generate PluresDB configuration from schema
1740
+ */
1741
+ generateConfig(schema) {
1742
+ const files = [];
1743
+ files.push(this.generateConfigFile(schema));
1744
+ return files;
1745
+ }
1746
+ /**
1747
+ * Generate pluresdb-config.ts file
1748
+ */
1749
+ generateConfigFile(schema) {
1750
+ const lines = [];
1751
+ const dbName = this.options.dbName || schema.name.toLowerCase();
1752
+ lines.push("/**");
1753
+ lines.push(` * PluresDB Configuration for ${schema.name}`);
1754
+ lines.push(" * Generated from Praxis schema");
1755
+ lines.push(" */");
1756
+ lines.push("");
1757
+ lines.push("// import { createPluresDB } from '@plures/pluresdb';");
1758
+ lines.push("");
1759
+ lines.push("/**");
1760
+ lines.push(" * Database store configuration");
1761
+ lines.push(" * ");
1762
+ const autoIndexStrategy = this.options.autoIndex || "all";
1763
+ if (autoIndexStrategy === "all") {
1764
+ lines.push(" * Indexing: All string, number, and date fields are auto-indexed by default.");
1765
+ lines.push(' * For large datasets, consider using autoIndex: "explicit" to only index');
1766
+ lines.push(" * fields explicitly defined in the schema.");
1767
+ } else if (autoIndexStrategy === "explicit") {
1768
+ lines.push(" * Indexing: Only fields explicitly defined in schema indexes are indexed.");
1769
+ } else if (autoIndexStrategy === "none") {
1770
+ lines.push(" * Indexing: Auto-indexing disabled. Only explicit schema indexes are used.");
1771
+ }
1772
+ lines.push(" */");
1773
+ lines.push("export const stores = {");
1774
+ if (schema.models && schema.models.length > 0) {
1775
+ for (const model of schema.models) {
1776
+ const storeName = model.name.toLowerCase() + "s";
1777
+ const storeConfig = this.generateStoreConfig(model);
1778
+ lines.push(` ${storeName}: {`);
1779
+ lines.push(` keyPath: '${storeConfig.keyPath}',`);
1780
+ if (storeConfig.indexes.length > 0) {
1781
+ lines.push(` indexes: [${storeConfig.indexes.map((idx) => `'${idx}'`).join(", ")}],`);
1782
+ }
1783
+ lines.push(" },");
1784
+ }
1785
+ } else {
1786
+ lines.push(" // No models defined in schema");
1787
+ }
1788
+ lines.push("};");
1789
+ lines.push("");
1790
+ lines.push("/**");
1791
+ lines.push(" * Database configuration");
1792
+ lines.push(" */");
1793
+ lines.push("export const dbConfig = {");
1794
+ lines.push(` name: '${dbName}',`);
1795
+ lines.push(` version: ${this.options.dbVersion},`);
1796
+ lines.push(" stores,");
1797
+ if (this.options.enableSync) {
1798
+ lines.push(" sync: {");
1799
+ lines.push(" enabled: true,");
1800
+ if (this.options.syncEndpoint) {
1801
+ lines.push(` endpoint: '${this.options.syncEndpoint}',`);
1802
+ } else {
1803
+ lines.push(" endpoint: 'ws://localhost:8080/sync',");
1804
+ }
1805
+ lines.push(" conflictResolution: 'last-write-wins',");
1806
+ lines.push(" },");
1807
+ }
1808
+ lines.push("};");
1809
+ lines.push("");
1810
+ lines.push("/**");
1811
+ lines.push(" * Initialize PluresDB");
1812
+ lines.push(" * @returns Configured PluresDB instance");
1813
+ lines.push(" */");
1814
+ lines.push("export function initDB() {");
1815
+ lines.push(" // Create and configure PluresDB instance");
1816
+ lines.push(" const db = createInMemoryDB();");
1817
+ lines.push(" ");
1818
+ lines.push(" // Initialize stores based on configuration");
1819
+ lines.push(" for (const storeDef of dbConfig.stores) {");
1820
+ lines.push(" // Pre-create store paths");
1821
+ lines.push(" db.set(`stores/${storeDef.name}/_meta`, {");
1822
+ lines.push(" keyPath: storeDef.keyPath,");
1823
+ lines.push(" indexes: storeDef.indexes,");
1824
+ lines.push(" createdAt: Date.now(),");
1825
+ lines.push(" });");
1826
+ lines.push(" }");
1827
+ lines.push(" ");
1828
+ lines.push(" console.log(`PluresDB initialized: ${dbConfig.name}`);");
1829
+ lines.push(" return db;");
1830
+ lines.push("}");
1831
+ lines.push("");
1832
+ lines.push("/**");
1833
+ lines.push(" * Get store by name");
1834
+ lines.push(" */");
1835
+ lines.push(
1836
+ "export function getStore(db: ReturnType<typeof createInMemoryDB>, storeName: string) {"
1837
+ );
1838
+ lines.push(" const storeDef = dbConfig.stores.find(s => s.name === storeName);");
1839
+ lines.push(" if (!storeDef) {");
1840
+ lines.push(' throw new Error(`Store "${storeName}" not found in configuration`);');
1841
+ lines.push(" }");
1842
+ lines.push(" return {");
1843
+ lines.push(" get: (key: string) => db.get(`stores/${storeName}/${key}`),");
1844
+ lines.push(
1845
+ " set: (key: string, value: unknown) => db.set(`stores/${storeName}/${key}`, value),"
1846
+ );
1847
+ lines.push(" delete: (key: string) => db.delete(`stores/${storeName}/${key}`),");
1848
+ lines.push(" watch: (key: string, callback: (data: unknown) => void) => ");
1849
+ lines.push(" db.watch(`stores/${storeName}/${key}`, callback),");
1850
+ lines.push(" };");
1851
+ lines.push("}");
1852
+ return {
1853
+ path: `${this.options.outputDir}/pluresdb-config.ts`,
1854
+ content: lines.join("\n"),
1855
+ type: "config"
1856
+ };
1857
+ }
1858
+ /**
1859
+ * Generate store configuration for a model
1860
+ */
1861
+ generateStoreConfig(model) {
1862
+ const idField = model.fields.find((f) => f.name === "id" || f.name === "_id");
1863
+ const keyPath = idField ? idField.name : "id";
1864
+ const indexes = [];
1865
+ const autoIndexStrategy = this.options.autoIndex || "all";
1866
+ if (autoIndexStrategy === "all") {
1867
+ for (const field of model.fields) {
1868
+ if (field.name !== keyPath) {
1869
+ if (field.type === "string" || field.type === "number" || field.type === "date") {
1870
+ indexes.push(field.name);
1871
+ }
1872
+ }
1873
+ }
1874
+ }
1875
+ if (model.indexes) {
1876
+ for (const indexDef of model.indexes) {
1877
+ for (const fieldName of indexDef.fields) {
1878
+ if (!indexes.includes(fieldName) && fieldName !== keyPath) {
1879
+ indexes.push(fieldName);
1880
+ }
1881
+ }
1882
+ }
1883
+ }
1884
+ return {
1885
+ keyPath,
1886
+ indexes
1887
+ };
1888
+ }
1889
+ };
1890
+ function createPluresDBGenerator(outputDir, options) {
1891
+ return new PluresDBGenerator({
1892
+ outputDir,
1893
+ ...options
1894
+ });
1895
+ }
1896
+
1897
+ // src/integrations/pluresdb.ts
1898
+ function createPluresDBAdapter(options) {
1899
+ const store = createPraxisDBStore(options.db, options.registry, options.initialContext);
1900
+ const subscriptions = [];
1901
+ return {
1902
+ async persistEvents(events) {
1903
+ await store.appendEvents(events);
1904
+ },
1905
+ async persistFacts(facts) {
1906
+ await store.storeFacts(facts);
1907
+ },
1908
+ async loadEvents(query) {
1909
+ if (!query?.tag) {
1910
+ return [];
1911
+ }
1912
+ const entries = await store.getEvents(query.tag, {
1913
+ since: query.since,
1914
+ limit: query.limit
1915
+ });
1916
+ return entries.map((e) => e.event);
1917
+ },
1918
+ subscribeToEvents(callback, query) {
1919
+ if (!query?.tag) {
1920
+ return () => {
1921
+ };
1922
+ }
1923
+ const unsubscribe = store.watchFacts(query.tag, (facts) => {
1924
+ const events = facts.map((f) => ({
1925
+ tag: f.tag,
1926
+ payload: f.payload
1927
+ }));
1928
+ callback(events);
1929
+ });
1930
+ subscriptions.push(unsubscribe);
1931
+ return unsubscribe;
1932
+ },
1933
+ attachEngine(engine) {
1934
+ store.updateContext(engine.getContext());
1935
+ },
1936
+ dispose() {
1937
+ for (const unsub of subscriptions) {
1938
+ unsub();
1939
+ }
1940
+ subscriptions.length = 0;
1941
+ store.dispose();
1942
+ }
1943
+ };
1944
+ }
1945
+ function attachToEngine(store, engine) {
1946
+ store.updateContext(engine.getContext());
1947
+ return () => {
1948
+ store.dispose();
1949
+ };
1950
+ }
1951
+
1952
+ // src/integrations/unum.ts
1953
+ async function createUnumAdapter(config) {
1954
+ const { db, realtime = true } = config;
1955
+ let currentIdentity = null;
1956
+ const channels = /* @__PURE__ */ new Map();
1957
+ const subscriptions = /* @__PURE__ */ new Set();
1958
+ if (config.identity) {
1959
+ currentIdentity = {
1960
+ ...config.identity,
1961
+ id: config.identity.id || generateId2(),
1962
+ createdAt: Date.now()
1963
+ };
1964
+ await db.set(`unum/identities/${currentIdentity.id}`, currentIdentity);
1965
+ }
1966
+ async function setIdentity(identity) {
1967
+ currentIdentity = {
1968
+ ...identity,
1969
+ id: generateId2(),
1970
+ createdAt: Date.now()
1971
+ };
1972
+ await db.set(`unum/identities/${currentIdentity.id}`, currentIdentity);
1973
+ return currentIdentity;
1974
+ }
1975
+ async function getIdentity(id) {
1976
+ return await db.get(`unum/identities/${id}`);
1977
+ }
1978
+ async function createChannel(name, members) {
1979
+ const channelId = generateId2();
1980
+ const channelData = {
1981
+ id: channelId,
1982
+ name,
1983
+ members: members || [],
1984
+ createdAt: Date.now(),
1985
+ createdBy: currentIdentity?.id
1986
+ };
1987
+ await db.set(`unum/channels/${channelId}`, channelData);
1988
+ const channel = createChannelInstance(channelId, name);
1989
+ channels.set(channelId, channel);
1990
+ return channel;
1991
+ }
1992
+ async function joinChannel(channelId) {
1993
+ const existing = channels.get(channelId);
1994
+ if (existing) return existing;
1995
+ const channelData = await db.get(`unum/channels/${channelId}`);
1996
+ if (!channelData) {
1997
+ throw new Error(`Channel ${channelId} not found`);
1998
+ }
1999
+ const channel = createChannelInstance(channelData.id, channelData.name);
2000
+ channels.set(channelId, channel);
2001
+ return channel;
2002
+ }
2003
+ async function listChannels() {
2004
+ return Array.from(channels.values());
2005
+ }
2006
+ function createChannelInstance(id, name) {
2007
+ const handlers = /* @__PURE__ */ new Set();
2008
+ return {
2009
+ id,
2010
+ name,
2011
+ subscribe(handler) {
2012
+ handlers.add(handler);
2013
+ if (realtime) {
2014
+ const unsub = db.watch(`unum/channels/${id}/messages`, (data) => {
2015
+ if (data) {
2016
+ handler(data);
2017
+ }
2018
+ });
2019
+ subscriptions.add(unsub);
2020
+ }
2021
+ return () => {
2022
+ handlers.delete(handler);
2023
+ };
2024
+ },
2025
+ async publish(message) {
2026
+ const fullMessage = {
2027
+ ...message,
2028
+ id: message.id || generateId2(),
2029
+ channelId: id,
2030
+ timestamp: Date.now()
2031
+ };
2032
+ await db.set(`unum/channels/${id}/messages/${fullMessage.id}`, fullMessage);
2033
+ handlers.forEach((h) => h(fullMessage));
2034
+ },
2035
+ async getMembers() {
2036
+ const channelData = await db.get(`unum/channels/${id}`);
2037
+ if (!channelData?.members) return [];
2038
+ const members = [];
2039
+ for (const memberId of channelData.members) {
2040
+ const identity = await getIdentity(memberId);
2041
+ if (identity) members.push(identity);
2042
+ }
2043
+ return members;
2044
+ },
2045
+ async leave() {
2046
+ channels.delete(id);
2047
+ }
2048
+ };
2049
+ }
2050
+ async function broadcastEvent(channelId, event) {
2051
+ const channel = channels.get(channelId);
2052
+ if (!channel) {
2053
+ throw new Error(`Not joined to channel ${channelId}`);
2054
+ }
2055
+ await channel.publish({
2056
+ id: generateId2(),
2057
+ sender: currentIdentity || { id: "anonymous", createdAt: Date.now() },
2058
+ content: event,
2059
+ type: "event"
2060
+ });
2061
+ }
2062
+ async function broadcastFact(channelId, fact) {
2063
+ const channel = channels.get(channelId);
2064
+ if (!channel) {
2065
+ throw new Error(`Not joined to channel ${channelId}`);
2066
+ }
2067
+ await channel.publish({
2068
+ id: generateId2(),
2069
+ sender: currentIdentity || { id: "anonymous", createdAt: Date.now() },
2070
+ content: fact,
2071
+ type: "fact"
2072
+ });
2073
+ }
2074
+ function subscribeToEvents(channelId, handler) {
2075
+ const channel = channels.get(channelId);
2076
+ if (!channel) {
2077
+ throw new Error(`Not joined to channel ${channelId}`);
2078
+ }
2079
+ return channel.subscribe((message) => {
2080
+ if (message.type === "event") {
2081
+ handler(message.content);
2082
+ }
2083
+ });
2084
+ }
2085
+ function subscribeToFacts(channelId, handler) {
2086
+ const channel = channels.get(channelId);
2087
+ if (!channel) {
2088
+ throw new Error(`Not joined to channel ${channelId}`);
2089
+ }
2090
+ return channel.subscribe((message) => {
2091
+ if (message.type === "fact") {
2092
+ handler(message.content);
2093
+ }
2094
+ });
2095
+ }
2096
+ async function disconnect() {
2097
+ subscriptions.forEach((unsub) => unsub());
2098
+ subscriptions.clear();
2099
+ for (const channel of channels.values()) {
2100
+ await channel.leave();
2101
+ }
2102
+ channels.clear();
2103
+ currentIdentity = null;
2104
+ }
2105
+ return {
2106
+ get identity() {
2107
+ return currentIdentity;
2108
+ },
2109
+ setIdentity,
2110
+ getIdentity,
2111
+ createChannel,
2112
+ joinChannel,
2113
+ listChannels,
2114
+ broadcastEvent,
2115
+ broadcastFact,
2116
+ subscribeToEvents,
2117
+ subscribeToFacts,
2118
+ disconnect
2119
+ };
2120
+ }
2121
+ function generateId2() {
2122
+ return `${Date.now().toString(36)}-${Math.random().toString(36).substr(2, 9)}`;
2123
+ }
2124
+ function attachUnumToEngine(_engine, _adapter, _channelId) {
2125
+ return () => {
2126
+ };
2127
+ }
2128
+
2129
+ // src/integrations/code-canvas.ts
2130
+ function schemaToCanvas(schema, _options = {}) {
2131
+ const nodes = [];
2132
+ const edges = [];
2133
+ let nodeId = 0;
2134
+ let yOffset = 0;
2135
+ const xSpacing = 200;
2136
+ const ySpacing = 100;
2137
+ if (schema.models) {
2138
+ schema.models.forEach((model, index) => {
2139
+ const pos = model.position && (model.position.x !== 0 || model.position.y !== 0) ? model.position : { x: 50, y: yOffset + index * ySpacing };
2140
+ const node = {
2141
+ id: model.id || `model-${nodeId++}`,
2142
+ type: "model",
2143
+ label: model.name,
2144
+ x: pos.x,
2145
+ y: pos.y,
2146
+ width: 150,
2147
+ height: 60,
2148
+ data: model,
2149
+ style: {
2150
+ backgroundColor: "#e3f2fd",
2151
+ borderColor: "#1976d2"
2152
+ }
2153
+ };
2154
+ nodes.push(node);
2155
+ });
2156
+ yOffset += schema.models.length * ySpacing + 50;
2157
+ }
2158
+ if (schema.components) {
2159
+ schema.components.forEach((component, index) => {
2160
+ const pos = component.position && (component.position.x !== 0 || component.position.y !== 0) ? component.position : { x: 50 + xSpacing, y: yOffset + index * ySpacing };
2161
+ const node = {
2162
+ id: component.id || `component-${nodeId++}`,
2163
+ type: "component",
2164
+ label: component.name,
2165
+ x: pos.x,
2166
+ y: pos.y,
2167
+ width: 150,
2168
+ height: 60,
2169
+ data: component,
2170
+ style: {
2171
+ backgroundColor: "#e8f5e9",
2172
+ borderColor: "#388e3c"
2173
+ }
2174
+ };
2175
+ nodes.push(node);
2176
+ if (component.model) {
2177
+ const modelNode = nodes.find((n) => n.type === "model" && n.label === component.model);
2178
+ if (modelNode) {
2179
+ edges.push({
2180
+ id: `edge-${edges.length}`,
2181
+ source: node.id,
2182
+ target: modelNode.id,
2183
+ type: "reference",
2184
+ label: "uses"
2185
+ });
2186
+ }
2187
+ }
2188
+ });
2189
+ yOffset += schema.components.length * ySpacing + 50;
2190
+ }
2191
+ if (schema.events) {
2192
+ schema.events.forEach((event, index) => {
2193
+ const pos = event.position && (event.position.x !== 0 || event.position.y !== 0) ? event.position : { x: 50 + xSpacing * 2, y: yOffset + index * ySpacing };
2194
+ const node = {
2195
+ id: event.id || `event-${nodeId++}`,
2196
+ type: "event",
2197
+ label: event.tag,
2198
+ x: pos.x,
2199
+ y: pos.y,
2200
+ width: 150,
2201
+ height: 50,
2202
+ data: event,
2203
+ style: {
2204
+ backgroundColor: "#fff3e0",
2205
+ borderColor: "#f57c00"
2206
+ }
2207
+ };
2208
+ nodes.push(node);
2209
+ });
2210
+ yOffset += schema.events.length * ySpacing + 30;
2211
+ }
2212
+ if (schema.facts) {
2213
+ schema.facts.forEach((fact, index) => {
2214
+ const pos = fact.position && (fact.position.x !== 0 || fact.position.y !== 0) ? fact.position : { x: 50 + xSpacing * 3, y: yOffset + index * ySpacing };
2215
+ const node = {
2216
+ id: fact.id || `fact-${nodeId++}`,
2217
+ type: "fact",
2218
+ label: fact.tag,
2219
+ x: pos.x,
2220
+ y: pos.y,
2221
+ width: 150,
2222
+ height: 50,
2223
+ data: fact,
2224
+ style: {
2225
+ backgroundColor: "#fce4ec",
2226
+ borderColor: "#c2185b"
2227
+ }
2228
+ };
2229
+ nodes.push(node);
2230
+ });
2231
+ yOffset += schema.facts.length * ySpacing + 30;
2232
+ }
2233
+ if (schema.rules) {
2234
+ schema.rules.forEach((rule, index) => {
2235
+ const pos = rule.position && (rule.position.x !== 0 || rule.position.y !== 0) ? rule.position : { x: 50 + xSpacing * 4, y: yOffset + index * ySpacing };
2236
+ const node = {
2237
+ id: rule.id || `rule-${nodeId++}`,
2238
+ type: "rule",
2239
+ label: rule.id,
2240
+ x: pos.x,
2241
+ y: pos.y,
2242
+ width: 150,
2243
+ height: 50,
2244
+ data: rule,
2245
+ style: {
2246
+ backgroundColor: "#e1f5fe",
2247
+ borderColor: "#0288d1"
2248
+ }
2249
+ };
2250
+ nodes.push(node);
2251
+ if (rule.triggers) {
2252
+ rule.triggers.forEach((trigger) => {
2253
+ const eventNode = nodes.find((n) => n.type === "event" && n.label === trigger);
2254
+ if (eventNode) {
2255
+ edges.push({
2256
+ id: `edge-${edges.length}`,
2257
+ source: eventNode.id,
2258
+ target: node.id,
2259
+ type: "event",
2260
+ label: "triggers"
2261
+ });
2262
+ }
2263
+ });
2264
+ }
2265
+ });
2266
+ yOffset += schema.rules.length * ySpacing + 30;
2267
+ }
2268
+ if (schema.constraints) {
2269
+ schema.constraints.forEach((constraint, index) => {
2270
+ const pos = constraint.position && (constraint.position.x !== 0 || constraint.position.y !== 0) ? constraint.position : { x: 50 + xSpacing * 5, y: yOffset + index * ySpacing };
2271
+ const node = {
2272
+ id: constraint.id || `constraint-${nodeId++}`,
2273
+ type: "constraint",
2274
+ label: constraint.id,
2275
+ x: pos.x,
2276
+ y: pos.y,
2277
+ width: 150,
2278
+ height: 50,
2279
+ data: constraint,
2280
+ style: {
2281
+ backgroundColor: "#ffebee",
2282
+ borderColor: "#c62828"
2283
+ }
2284
+ };
2285
+ nodes.push(node);
2286
+ });
2287
+ }
2288
+ return {
2289
+ id: `canvas-${Date.now()}`,
2290
+ name: schema.name || "Praxis Schema",
2291
+ version: schema.$version || "1.0.0",
2292
+ nodes,
2293
+ edges,
2294
+ flows: schema.flows || [],
2295
+ metadata: {
2296
+ created: Date.now(),
2297
+ modified: Date.now(),
2298
+ description: schema.description
2299
+ },
2300
+ viewport: { x: 0, y: 0, zoom: 1 }
2301
+ };
2302
+ }
2303
+ function canvasToSchema(canvas) {
2304
+ const models = [];
2305
+ const components = [];
2306
+ const events = [];
2307
+ const facts = [];
2308
+ const rules = [];
2309
+ const constraints = [];
2310
+ for (const node of canvas.nodes) {
2311
+ const position = { x: node.x, y: node.y };
2312
+ switch (node.type) {
2313
+ case "model":
2314
+ if (node.data) {
2315
+ models.push({ ...node.data, position });
2316
+ }
2317
+ break;
2318
+ case "component":
2319
+ if (node.data) {
2320
+ components.push({ ...node.data, position });
2321
+ }
2322
+ break;
2323
+ case "event":
2324
+ if (node.data) {
2325
+ events.push({ ...node.data, position });
2326
+ }
2327
+ break;
2328
+ case "fact":
2329
+ if (node.data) {
2330
+ facts.push({ ...node.data, position });
2331
+ }
2332
+ break;
2333
+ case "rule":
2334
+ if (node.data) {
2335
+ rules.push({ ...node.data, position });
2336
+ }
2337
+ break;
2338
+ case "constraint":
2339
+ if (node.data) {
2340
+ constraints.push({ ...node.data, position });
2341
+ }
2342
+ break;
2343
+ }
2344
+ }
2345
+ return {
2346
+ $version: "1.0.0",
2347
+ id: canvas.id,
2348
+ name: canvas.name,
2349
+ description: canvas.metadata?.description,
2350
+ models,
2351
+ components,
2352
+ events,
2353
+ facts,
2354
+ rules,
2355
+ constraints,
2356
+ flows: canvas.flows || [],
2357
+ metadata: canvas.metadata
2358
+ };
2359
+ }
2360
+ function canvasToYaml(canvas) {
2361
+ const lines = [
2362
+ `# ${canvas.name}`,
2363
+ `# Generated by Praxis CodeCanvas Integration`,
2364
+ `# Version: ${canvas.version}`,
2365
+ "",
2366
+ "nodes:"
2367
+ ];
2368
+ for (const node of canvas.nodes) {
2369
+ lines.push(` - id: "${node.id}"`);
2370
+ lines.push(` type: "${node.type}"`);
2371
+ lines.push(` label: "${node.label}"`);
2372
+ lines.push(` x: ${node.x}`);
2373
+ lines.push(` y: ${node.y}`);
2374
+ lines.push(` width: ${node.width}`);
2375
+ lines.push(` height: ${node.height}`);
2376
+ if (node.fsmState) {
2377
+ lines.push(` fsmState: "${node.fsmState}"`);
2378
+ }
2379
+ lines.push("");
2380
+ }
2381
+ lines.push("edges:");
2382
+ for (const edge of canvas.edges) {
2383
+ lines.push(` - id: "${edge.id}"`);
2384
+ lines.push(` source: "${edge.source}"`);
2385
+ lines.push(` target: "${edge.target}"`);
2386
+ if (edge.label) {
2387
+ lines.push(` label: "${edge.label}"`);
2388
+ }
2389
+ if (edge.type) {
2390
+ lines.push(` type: "${edge.type}"`);
2391
+ }
2392
+ lines.push("");
2393
+ }
2394
+ return lines.join("\n");
2395
+ }
2396
+ function canvasToMermaid(canvas) {
2397
+ const lines = ["graph TD"];
2398
+ for (const node of canvas.nodes) {
2399
+ let shape;
2400
+ switch (node.type) {
2401
+ case "model":
2402
+ shape = `[${node.label}]`;
2403
+ break;
2404
+ case "component":
2405
+ shape = `(${node.label})`;
2406
+ break;
2407
+ case "event":
2408
+ shape = `{{${node.label}}}`;
2409
+ break;
2410
+ case "fact":
2411
+ shape = `((${node.label}))`;
2412
+ break;
2413
+ case "rule":
2414
+ shape = `[/${node.label}/]`;
2415
+ break;
2416
+ case "constraint":
2417
+ shape = `[\\${node.label}\\]`;
2418
+ break;
2419
+ default:
2420
+ shape = `[${node.label}]`;
2421
+ }
2422
+ lines.push(` ${node.id}${shape}`);
2423
+ }
2424
+ lines.push("");
2425
+ for (const edge of canvas.edges) {
2426
+ const label = edge.label ? `|${edge.label}|` : "";
2427
+ lines.push(` ${edge.source} -->${label} ${edge.target}`);
2428
+ }
2429
+ return lines.join("\n");
2430
+ }
2431
+ function validateWithGuardian(files, activity, lifecycle) {
2432
+ const errors = [];
2433
+ const warnings = [];
2434
+ const currentState = lifecycle.find((s) => s.id === activity.activity);
2435
+ if (!currentState) {
2436
+ errors.push({
2437
+ code: "INVALID_ACTIVITY",
2438
+ message: `Activity "${activity.activity}" is not a valid lifecycle state`,
2439
+ rule: "lifecycle-state"
2440
+ });
2441
+ }
2442
+ if (activity.allowedPaths) {
2443
+ for (const file of files) {
2444
+ const allowed = activity.allowedPaths.some((pattern) => {
2445
+ const regex = new RegExp("^" + pattern.replace(/\*/g, ".*") + "$");
2446
+ return regex.test(file);
2447
+ });
2448
+ if (!allowed) {
2449
+ errors.push({
2450
+ code: "PATH_NOT_ALLOWED",
2451
+ message: `File "${file}" is not allowed during "${activity.activity}" activity`,
2452
+ file,
2453
+ rule: "allowed-paths"
2454
+ });
2455
+ }
2456
+ }
2457
+ }
2458
+ return {
2459
+ valid: errors.length === 0,
2460
+ errors,
2461
+ warnings,
2462
+ filesChecked: files,
2463
+ activity
2464
+ };
2465
+ }
2466
+ function createCanvasEditor(config) {
2467
+ const document = config.document || (config.schema ? schemaToCanvas(config.schema, { layout: config.layout }) : {
2468
+ id: `canvas-${Date.now()}`,
2469
+ name: "New Canvas",
2470
+ version: "1.0.0",
2471
+ nodes: [],
2472
+ edges: [],
2473
+ metadata: { created: Date.now(), modified: Date.now() },
2474
+ viewport: { x: 0, y: 0, zoom: 1 }
2475
+ });
2476
+ let nodeIdCounter = document.nodes.length;
2477
+ let edgeIdCounter = document.edges.length;
2478
+ return {
2479
+ document,
2480
+ addNode(node) {
2481
+ const fullNode = {
2482
+ ...node,
2483
+ id: `node-${nodeIdCounter++}`
2484
+ };
2485
+ document.nodes.push(fullNode);
2486
+ document.metadata.modified = Date.now();
2487
+ return fullNode;
2488
+ },
2489
+ removeNode(id) {
2490
+ const index = document.nodes.findIndex((n) => n.id === id);
2491
+ if (index !== -1) {
2492
+ document.nodes.splice(index, 1);
2493
+ document.edges = document.edges.filter((e) => e.source !== id && e.target !== id);
2494
+ document.metadata.modified = Date.now();
2495
+ }
2496
+ },
2497
+ addEdge(edge) {
2498
+ const fullEdge = {
2499
+ ...edge,
2500
+ id: `edge-${edgeIdCounter++}`
2501
+ };
2502
+ document.edges.push(fullEdge);
2503
+ document.metadata.modified = Date.now();
2504
+ return fullEdge;
2505
+ },
2506
+ removeEdge(id) {
2507
+ const index = document.edges.findIndex((e) => e.id === id);
2508
+ if (index !== -1) {
2509
+ document.edges.splice(index, 1);
2510
+ document.metadata.modified = Date.now();
2511
+ }
2512
+ },
2513
+ toSchema() {
2514
+ return canvasToSchema(document);
2515
+ },
2516
+ toYaml() {
2517
+ return canvasToYaml(document);
2518
+ },
2519
+ toMermaid() {
2520
+ return canvasToMermaid(document);
2521
+ }
2522
+ };
2523
+ }
2524
+
2525
+ // src/integrations/state-docs.ts
2526
+ var StateDocsGenerator = class {
2527
+ config;
2528
+ constructor(config) {
2529
+ this.config = {
2530
+ target: "./docs",
2531
+ globs: ["**/*.ts", "**/*.js"],
2532
+ visualization: {
2533
+ format: "mermaid",
2534
+ exportPng: false,
2535
+ theme: "default"
2536
+ },
2537
+ template: {
2538
+ toc: true,
2539
+ timestamp: true
2540
+ },
2541
+ ...config
2542
+ };
2543
+ }
2544
+ /**
2545
+ * Generate documentation from a Praxis schema
2546
+ */
2547
+ generateFromSchema(schema) {
2548
+ const docs = [];
2549
+ docs.push(this.generateSchemaReadme(schema));
2550
+ if (schema.models && schema.models.length > 0) {
2551
+ docs.push(this.generateModelsDoc(schema));
2552
+ }
2553
+ if (schema.components && schema.components.length > 0) {
2554
+ docs.push(this.generateComponentsDoc(schema));
2555
+ }
2556
+ if (schema.logic && schema.logic.length > 0) {
2557
+ for (const logic of schema.logic) {
2558
+ docs.push(this.generateLogicDoc(logic));
2559
+ docs.push(this.generateLogicDiagram(logic));
2560
+ }
2561
+ }
2562
+ return docs;
2563
+ }
2564
+ /**
2565
+ * Generate documentation from a Praxis registry
2566
+ */
2567
+ generateFromModule(module2) {
2568
+ const docs = [];
2569
+ const rules = module2.rules;
2570
+ const constraints = module2.constraints;
2571
+ docs.push(this.generateRulesDoc(rules));
2572
+ docs.push(this.generateConstraintsDoc(constraints));
2573
+ docs.push(this.generateRegistryDiagram(rules, constraints));
2574
+ return docs;
2575
+ }
2576
+ /**
2577
+ * Generate the main schema README
2578
+ */
2579
+ generateSchemaReadme(schema) {
2580
+ const lines = [];
2581
+ if (this.config.template?.header) {
2582
+ lines.push(this.config.template.header);
2583
+ lines.push("");
2584
+ }
2585
+ lines.push(`# ${schema.name || this.config.projectTitle}`);
2586
+ lines.push("");
2587
+ if (schema.description) {
2588
+ lines.push(schema.description);
2589
+ lines.push("");
2590
+ }
2591
+ if (this.config.template?.toc) {
2592
+ lines.push("## Table of Contents");
2593
+ lines.push("");
2594
+ lines.push("- [Overview](#overview)");
2595
+ if (schema.models && schema.models.length > 0) {
2596
+ lines.push("- [Models](#models)");
2597
+ }
2598
+ if (schema.components && schema.components.length > 0) {
2599
+ lines.push("- [Components](#components)");
2600
+ }
2601
+ if (schema.logic && schema.logic.length > 0) {
2602
+ lines.push("- [Logic](#logic)");
2603
+ }
2604
+ lines.push("");
2605
+ }
2606
+ lines.push("## Overview");
2607
+ lines.push("");
2608
+ lines.push(`**Version:** ${schema.version}`);
2609
+ lines.push("");
2610
+ lines.push("### Statistics");
2611
+ lines.push("");
2612
+ lines.push("| Category | Count |");
2613
+ lines.push("|----------|-------|");
2614
+ lines.push(`| Models | ${schema.models?.length || 0} |`);
2615
+ lines.push(`| Components | ${schema.components?.length || 0} |`);
2616
+ lines.push(`| Logic Modules | ${schema.logic?.length || 0} |`);
2617
+ lines.push("");
2618
+ if (schema.models && schema.models.length > 0) {
2619
+ lines.push("## Models");
2620
+ lines.push("");
2621
+ for (const model of schema.models) {
2622
+ lines.push(`### ${model.name}`);
2623
+ lines.push("");
2624
+ if (model.description) {
2625
+ lines.push(model.description);
2626
+ lines.push("");
2627
+ }
2628
+ lines.push("**Fields:**");
2629
+ lines.push("");
2630
+ lines.push("| Name | Type | Required |");
2631
+ lines.push("|------|------|----------|");
2632
+ for (const field of model.fields) {
2633
+ const required = field.optional ? "No" : "Yes";
2634
+ lines.push(`| ${field.name} | ${field.type} | ${required} |`);
2635
+ }
2636
+ lines.push("");
2637
+ }
2638
+ }
2639
+ if (schema.components && schema.components.length > 0) {
2640
+ lines.push("## Components");
2641
+ lines.push("");
2642
+ for (const component of schema.components) {
2643
+ lines.push(`### ${component.name}`);
2644
+ lines.push("");
2645
+ lines.push(`**Type:** ${component.type}`);
2646
+ lines.push("");
2647
+ if (component.description) {
2648
+ lines.push(component.description);
2649
+ lines.push("");
2650
+ }
2651
+ if (component.model) {
2652
+ lines.push(`**Model:** ${component.model}`);
2653
+ lines.push("");
2654
+ }
2655
+ }
2656
+ }
2657
+ if (schema.logic && schema.logic.length > 0) {
2658
+ lines.push("## Logic");
2659
+ lines.push("");
2660
+ for (const logic of schema.logic) {
2661
+ lines.push(`### ${logic.id}`);
2662
+ lines.push("");
2663
+ if (logic.description) {
2664
+ lines.push(logic.description);
2665
+ lines.push("");
2666
+ }
2667
+ if (logic.events && logic.events.length > 0) {
2668
+ lines.push("**Events:**");
2669
+ lines.push("");
2670
+ for (const event of logic.events) {
2671
+ lines.push(`- \`${event.tag}\`: ${event.description || ""}`);
2672
+ }
2673
+ lines.push("");
2674
+ }
2675
+ if (logic.facts && logic.facts.length > 0) {
2676
+ lines.push("**Facts:**");
2677
+ lines.push("");
2678
+ for (const fact of logic.facts) {
2679
+ lines.push(`- \`${fact.tag}\`: ${fact.description || ""}`);
2680
+ }
2681
+ lines.push("");
2682
+ }
2683
+ if (logic.rules && logic.rules.length > 0) {
2684
+ lines.push("**Rules:**");
2685
+ lines.push("");
2686
+ for (const rule of logic.rules) {
2687
+ lines.push(`- \`${rule.id}\`: ${rule.description || ""}`);
2688
+ }
2689
+ lines.push("");
2690
+ }
2691
+ }
2692
+ }
2693
+ if (this.config.template?.timestamp) {
2694
+ lines.push("---");
2695
+ lines.push("");
2696
+ lines.push(`*Generated on ${(/* @__PURE__ */ new Date()).toISOString()} by State-Docs*`);
2697
+ }
2698
+ if (this.config.template?.footer) {
2699
+ lines.push("");
2700
+ lines.push(this.config.template.footer);
2701
+ }
2702
+ return {
2703
+ path: `${this.config.target}/README.md`,
2704
+ content: lines.join("\n"),
2705
+ type: "markdown"
2706
+ };
2707
+ }
2708
+ /**
2709
+ * Generate models documentation
2710
+ */
2711
+ generateModelsDoc(schema) {
2712
+ const lines = [
2713
+ "# Models",
2714
+ "",
2715
+ "This document describes all data models defined in the schema.",
2716
+ ""
2717
+ ];
2718
+ if (schema.models) {
2719
+ for (const model of schema.models) {
2720
+ lines.push(`## ${model.name}`);
2721
+ lines.push("");
2722
+ if (model.description) {
2723
+ lines.push(model.description);
2724
+ lines.push("");
2725
+ }
2726
+ lines.push("### Fields");
2727
+ lines.push("");
2728
+ lines.push("| Name | Type | Required | Description |");
2729
+ lines.push("|------|------|----------|-------------|");
2730
+ for (const field of model.fields) {
2731
+ const required = field.optional ? "No" : "Yes";
2732
+ const description = field.description || "-";
2733
+ lines.push(`| ${field.name} | \`${field.type}\` | ${required} | ${description} |`);
2734
+ }
2735
+ lines.push("");
2736
+ if (model.indexes && model.indexes.length > 0) {
2737
+ lines.push("### Indexes");
2738
+ lines.push("");
2739
+ for (const index of model.indexes) {
2740
+ lines.push(`- **${index.name}**: \`${index.fields.join(", ")}\``);
2741
+ }
2742
+ lines.push("");
2743
+ }
2744
+ }
2745
+ }
2746
+ return {
2747
+ path: `${this.config.target}/models.md`,
2748
+ content: lines.join("\n"),
2749
+ type: "markdown"
2750
+ };
2751
+ }
2752
+ /**
2753
+ * Generate components documentation
2754
+ */
2755
+ generateComponentsDoc(schema) {
2756
+ const lines = [
2757
+ "# Components",
2758
+ "",
2759
+ "This document describes all UI components defined in the schema.",
2760
+ ""
2761
+ ];
2762
+ if (schema.components) {
2763
+ for (const component of schema.components) {
2764
+ lines.push(`## ${component.name}`);
2765
+ lines.push("");
2766
+ lines.push(`**Type:** ${component.type}`);
2767
+ lines.push("");
2768
+ if (component.description) {
2769
+ lines.push(component.description);
2770
+ lines.push("");
2771
+ }
2772
+ if (component.model) {
2773
+ lines.push(
2774
+ `**Associated Model:** [${component.model}](./models.md#${component.model.toLowerCase()})`
2775
+ );
2776
+ lines.push("");
2777
+ }
2778
+ }
2779
+ }
2780
+ return {
2781
+ path: `${this.config.target}/components.md`,
2782
+ content: lines.join("\n"),
2783
+ type: "markdown"
2784
+ };
2785
+ }
2786
+ /**
2787
+ * Generate logic documentation
2788
+ */
2789
+ generateLogicDoc(logic) {
2790
+ const lines = [`# ${logic.id}`, ""];
2791
+ if (logic.description) {
2792
+ lines.push(logic.description);
2793
+ lines.push("");
2794
+ }
2795
+ if (logic.events && logic.events.length > 0) {
2796
+ lines.push("## Events");
2797
+ lines.push("");
2798
+ lines.push("| Event | Description | Payload |");
2799
+ lines.push("|-------|-------------|---------|");
2800
+ for (const event of logic.events) {
2801
+ const payload = event.payload ? Object.entries(event.payload).map(([k, v]) => `${k}: ${v}`).join(", ") : "-";
2802
+ lines.push(`| \`${event.tag}\` | ${event.description || "-"} | ${payload} |`);
2803
+ }
2804
+ lines.push("");
2805
+ }
2806
+ if (logic.facts && logic.facts.length > 0) {
2807
+ lines.push("## Facts");
2808
+ lines.push("");
2809
+ lines.push("| Fact | Description | Payload |");
2810
+ lines.push("|------|-------------|---------|");
2811
+ for (const fact of logic.facts) {
2812
+ const payload = fact.payload ? Object.entries(fact.payload).map(([k, v]) => `${k}: ${v}`).join(", ") : "-";
2813
+ lines.push(`| \`${fact.tag}\` | ${fact.description || "-"} | ${payload} |`);
2814
+ }
2815
+ lines.push("");
2816
+ }
2817
+ if (logic.rules && logic.rules.length > 0) {
2818
+ lines.push("## Rules");
2819
+ lines.push("");
2820
+ for (const rule of logic.rules) {
2821
+ lines.push(`### ${rule.id}`);
2822
+ lines.push("");
2823
+ if (rule.description) {
2824
+ lines.push(rule.description);
2825
+ lines.push("");
2826
+ }
2827
+ if (rule.priority !== void 0) {
2828
+ lines.push(`**Priority:** ${rule.priority}`);
2829
+ lines.push("");
2830
+ }
2831
+ }
2832
+ }
2833
+ if (logic.constraints && logic.constraints.length > 0) {
2834
+ lines.push("## Constraints");
2835
+ lines.push("");
2836
+ for (const constraint of logic.constraints) {
2837
+ lines.push(`### ${constraint.id}`);
2838
+ lines.push("");
2839
+ if (constraint.description) {
2840
+ lines.push(constraint.description);
2841
+ lines.push("");
2842
+ }
2843
+ if (constraint.message) {
2844
+ lines.push(`**Error Message:** ${constraint.message}`);
2845
+ lines.push("");
2846
+ }
2847
+ }
2848
+ }
2849
+ return {
2850
+ path: `${this.config.target}/logic/${logic.id}.md`,
2851
+ content: lines.join("\n"),
2852
+ type: "markdown"
2853
+ };
2854
+ }
2855
+ /**
2856
+ * Generate Mermaid diagram for logic
2857
+ */
2858
+ generateLogicDiagram(logic) {
2859
+ const lines = ["stateDiagram-v2"];
2860
+ if (logic.events && logic.facts) {
2861
+ lines.push(" [*] --> Processing");
2862
+ for (const event of logic.events) {
2863
+ lines.push(` Processing --> ${event.tag.replace(/[^a-zA-Z0-9]/g, "")}: ${event.tag}`);
2864
+ }
2865
+ for (const fact of logic.facts) {
2866
+ lines.push(` ${fact.tag.replace(/[^a-zA-Z0-9]/g, "")} --> [*]`);
2867
+ }
2868
+ }
2869
+ return {
2870
+ path: `${this.config.target}/logic/${logic.id}.mmd`,
2871
+ content: lines.join("\n"),
2872
+ type: "mermaid"
2873
+ };
2874
+ }
2875
+ /**
2876
+ * Generate rules documentation
2877
+ */
2878
+ generateRulesDoc(rules) {
2879
+ const lines = [
2880
+ "# Rules",
2881
+ "",
2882
+ "This document describes all rules registered in the Praxis engine.",
2883
+ ""
2884
+ ];
2885
+ for (const rule of rules) {
2886
+ lines.push(`## ${rule.id}`);
2887
+ lines.push("");
2888
+ if (rule.description) {
2889
+ lines.push(rule.description);
2890
+ lines.push("");
2891
+ }
2892
+ if (rule.meta?.eventType) {
2893
+ lines.push(`**Triggers on:** \`${rule.meta.eventType}\``);
2894
+ lines.push("");
2895
+ }
2896
+ if (rule.meta?.priority !== void 0) {
2897
+ lines.push(`**Priority:** ${rule.meta.priority}`);
2898
+ lines.push("");
2899
+ }
2900
+ }
2901
+ return {
2902
+ path: `${this.config.target}/rules.md`,
2903
+ content: lines.join("\n"),
2904
+ type: "markdown"
2905
+ };
2906
+ }
2907
+ /**
2908
+ * Generate constraints documentation
2909
+ */
2910
+ generateConstraintsDoc(constraints) {
2911
+ const lines = [
2912
+ "# Constraints",
2913
+ "",
2914
+ "This document describes all constraints (invariants) registered in the Praxis engine.",
2915
+ ""
2916
+ ];
2917
+ for (const constraint of constraints) {
2918
+ lines.push(`## ${constraint.id}`);
2919
+ lines.push("");
2920
+ if (constraint.description) {
2921
+ lines.push(constraint.description);
2922
+ lines.push("");
2923
+ }
2924
+ if (constraint.meta?.errorMessage) {
2925
+ lines.push(`**Error Message:** ${constraint.meta.errorMessage}`);
2926
+ lines.push("");
2927
+ }
2928
+ }
2929
+ return {
2930
+ path: `${this.config.target}/constraints.md`,
2931
+ content: lines.join("\n"),
2932
+ type: "markdown"
2933
+ };
2934
+ }
2935
+ /**
2936
+ * Generate state diagram from registry
2937
+ */
2938
+ generateRegistryDiagram(rules, constraints) {
2939
+ const lines = ["graph TD", " subgraph Rules"];
2940
+ for (const rule of rules) {
2941
+ const id = rule.id.replace(/[^a-zA-Z0-9]/g, "_");
2942
+ lines.push(` ${id}["${rule.id}"]`);
2943
+ }
2944
+ lines.push(" end");
2945
+ lines.push(" subgraph Constraints");
2946
+ for (const constraint of constraints) {
2947
+ const id = constraint.id.replace(/[^a-zA-Z0-9]/g, "_");
2948
+ lines.push(` ${id}["${constraint.id}"]`);
2949
+ }
2950
+ lines.push(" end");
2951
+ return {
2952
+ path: `${this.config.target}/state-diagram.mmd`,
2953
+ content: lines.join("\n"),
2954
+ type: "mermaid"
2955
+ };
2956
+ }
2957
+ };
2958
+ function createStateDocsGenerator(config) {
2959
+ return new StateDocsGenerator(config);
2960
+ }
2961
+ function generateDocs(schema, config) {
2962
+ const generator = createStateDocsGenerator(config);
2963
+ return generator.generateFromSchema(schema);
2964
+ }
2965
+
2966
+ // src/integrations/tauri.ts
2967
+ function createMockTauriBridge() {
2968
+ const eventHandlers = /* @__PURE__ */ new Map();
2969
+ const storage = /* @__PURE__ */ new Map();
2970
+ return {
2971
+ app: {
2972
+ name: "Mock App",
2973
+ version: "0.0.0",
2974
+ tauriVersion: "mock"
2975
+ },
2976
+ fs: {
2977
+ async readFile(path) {
2978
+ const data = storage.get(path);
2979
+ if (data instanceof Uint8Array) return data;
2980
+ throw new Error(`File not found: ${path}`);
2981
+ },
2982
+ async readTextFile(path) {
2983
+ const data = storage.get(path);
2984
+ if (typeof data === "string") return data;
2985
+ throw new Error(`File not found: ${path}`);
2986
+ },
2987
+ async writeFile(path, data) {
2988
+ storage.set(path, data);
2989
+ },
2990
+ async writeTextFile(path, data) {
2991
+ storage.set(path, data);
2992
+ },
2993
+ async exists(path) {
2994
+ return storage.has(path);
2995
+ },
2996
+ async mkdir(_path, _options) {
2997
+ },
2998
+ async remove(path, _options) {
2999
+ storage.delete(path);
3000
+ },
3001
+ async rename(oldPath, newPath) {
3002
+ const data = storage.get(oldPath);
3003
+ if (data !== void 0) {
3004
+ storage.set(newPath, data);
3005
+ storage.delete(oldPath);
3006
+ }
3007
+ },
3008
+ async readDir(_path) {
3009
+ return [];
3010
+ }
3011
+ },
3012
+ tray: {
3013
+ async setIcon(_icon) {
3014
+ },
3015
+ async setTooltip(_tooltip) {
3016
+ },
3017
+ async setMenu(_menu) {
3018
+ },
3019
+ async show() {
3020
+ },
3021
+ async hide() {
3022
+ }
3023
+ },
3024
+ notification: {
3025
+ async send(options) {
3026
+ console.log("Mock notification:", options.title, options.body);
3027
+ },
3028
+ async requestPermission() {
3029
+ return "granted";
3030
+ },
3031
+ async checkPermission() {
3032
+ return "granted";
3033
+ }
3034
+ },
3035
+ async invoke(cmd, payload) {
3036
+ console.log("Mock invoke:", cmd, payload);
3037
+ return null;
3038
+ },
3039
+ async listen(event, handler) {
3040
+ if (!eventHandlers.has(event)) {
3041
+ eventHandlers.set(event, /* @__PURE__ */ new Set());
3042
+ }
3043
+ eventHandlers.get(event).add(handler);
3044
+ return () => {
3045
+ eventHandlers.get(event)?.delete(handler);
3046
+ };
3047
+ },
3048
+ async emit(event, payload) {
3049
+ const handlers = eventHandlers.get(event);
3050
+ if (handlers) {
3051
+ const tauriEvent = { event, payload };
3052
+ handlers.forEach((h) => h(tauriEvent));
3053
+ }
3054
+ },
3055
+ window: {
3056
+ async minimize() {
3057
+ },
3058
+ async maximize() {
3059
+ },
3060
+ async unmaximize() {
3061
+ },
3062
+ async close() {
3063
+ },
3064
+ async toggleFullscreen() {
3065
+ },
3066
+ async setTitle(_title) {
3067
+ },
3068
+ async show() {
3069
+ },
3070
+ async hide() {
3071
+ },
3072
+ async focus() {
3073
+ }
3074
+ },
3075
+ async checkForUpdates() {
3076
+ return null;
3077
+ },
3078
+ async installUpdate() {
3079
+ }
3080
+ };
3081
+ }
3082
+ function createTauriPraxisAdapter(options) {
3083
+ const { bridge, statePath = "praxis-state.json", eventsPath = "praxis-events.json" } = options;
3084
+ return {
3085
+ async saveState(state2) {
3086
+ const json = JSON.stringify(state2, null, 2);
3087
+ await bridge.fs.writeTextFile(statePath, json);
3088
+ },
3089
+ async loadState() {
3090
+ try {
3091
+ const exists = await bridge.fs.exists(statePath);
3092
+ if (!exists) return null;
3093
+ const json = await bridge.fs.readTextFile(statePath);
3094
+ return JSON.parse(json);
3095
+ } catch {
3096
+ return null;
3097
+ }
3098
+ },
3099
+ async saveEvents(events) {
3100
+ const json = JSON.stringify(events, null, 2);
3101
+ await bridge.fs.writeTextFile(eventsPath, json);
3102
+ },
3103
+ async loadEvents() {
3104
+ try {
3105
+ const exists = await bridge.fs.exists(eventsPath);
3106
+ if (!exists) return [];
3107
+ const json = await bridge.fs.readTextFile(eventsPath);
3108
+ return JSON.parse(json);
3109
+ } catch {
3110
+ return [];
3111
+ }
3112
+ },
3113
+ async watchStateFile(_handler) {
3114
+ console.log("File watching not implemented in mock");
3115
+ return () => {
3116
+ };
3117
+ },
3118
+ getStatePath() {
3119
+ return statePath;
3120
+ },
3121
+ getEventsPath() {
3122
+ return eventsPath;
3123
+ }
3124
+ };
3125
+ }
3126
+ function attachTauriToEngine(engine, adapter, options = {}) {
3127
+ const { autoSave = true, saveInterval = 5e3 } = options;
3128
+ const cleanupFns = [];
3129
+ if (autoSave) {
3130
+ let saveTimer = null;
3131
+ let pendingSave = false;
3132
+ const debouncedSave = async () => {
3133
+ pendingSave = true;
3134
+ if (saveTimer) clearTimeout(saveTimer);
3135
+ saveTimer = setTimeout(async () => {
3136
+ if (pendingSave) {
3137
+ await adapter.saveState(engine.getContext());
3138
+ pendingSave = false;
3139
+ }
3140
+ }, saveInterval);
3141
+ };
3142
+ cleanupFns.push(() => {
3143
+ if (saveTimer) clearTimeout(saveTimer);
3144
+ });
3145
+ void debouncedSave;
3146
+ }
3147
+ return () => {
3148
+ cleanupFns.forEach((fn) => fn());
3149
+ };
3150
+ }
3151
+ function generateTauriConfig(config) {
3152
+ return {
3153
+ $schema: "https://raw.githubusercontent.com/tauri-apps/tauri/tauri-v2.0.0/core/tauri-config-schema/schema.json",
3154
+ productName: config.name,
3155
+ version: config.version,
3156
+ identifier: config.identifier,
3157
+ app: {
3158
+ windows: [
3159
+ {
3160
+ title: config.window?.title || config.name,
3161
+ width: config.window?.width || 800,
3162
+ height: config.window?.height || 600,
3163
+ minWidth: config.window?.minWidth,
3164
+ minHeight: config.window?.minHeight,
3165
+ resizable: config.window?.resizable ?? true,
3166
+ fullscreen: config.window?.fullscreen ?? false,
3167
+ decorations: config.window?.decorations ?? true,
3168
+ transparent: config.window?.transparent ?? false,
3169
+ alwaysOnTop: config.window?.alwaysOnTop ?? false,
3170
+ center: config.window?.center ?? true
3171
+ }
3172
+ ],
3173
+ security: {
3174
+ csp: config.security?.csp || "default-src 'self'",
3175
+ devtools: config.security?.devTools ?? false
3176
+ }
3177
+ },
3178
+ build: {
3179
+ devUrl: "http://localhost:5173",
3180
+ frontendDist: "../dist"
3181
+ },
3182
+ plugins: Object.fromEntries((config.plugins || []).map((p) => [p.name, p.config || {}]))
3183
+ };
3184
+ }
3185
+ // Annotate the CommonJS export names for ESM import in node:
3186
+ 0 && (module.exports = {
3187
+ ActorManager,
3188
+ InMemoryPraxisDB,
3189
+ LogicEngine,
3190
+ PRAXIS_PATHS,
3191
+ PRAXIS_PROTOCOL_VERSION,
3192
+ PluresDBGenerator,
3193
+ PraxisDBStore,
3194
+ PraxisRegistry,
3195
+ PraxisSchemaRegistry,
3196
+ ReactiveLogicEngine,
3197
+ RegistryIntrospector,
3198
+ StateDocsGenerator,
3199
+ TerminalAdapter,
3200
+ attachTauriToEngine,
3201
+ attachToEngine,
3202
+ attachUnumToEngine,
3203
+ canvasToMermaid,
3204
+ canvasToSchema,
3205
+ canvasToYaml,
3206
+ createCanvasEditor,
3207
+ createInMemoryDB,
3208
+ createIntrospector,
3209
+ createMockExecutor,
3210
+ createMockTauriBridge,
3211
+ createPluresDBAdapter,
3212
+ createPluresDBGenerator,
3213
+ createPraxisDBStore,
3214
+ createPraxisEngine,
3215
+ createSchemaRegistry,
3216
+ createSchemaTemplate,
3217
+ createStateDocsGenerator,
3218
+ createTauriPraxisAdapter,
3219
+ createTerminalAdapter,
3220
+ createTimerActor,
3221
+ createUnumAdapter,
3222
+ defineConstraint,
3223
+ defineEvent,
3224
+ defineFact,
3225
+ defineModule,
3226
+ defineRule,
3227
+ filterEvents,
3228
+ filterFacts,
3229
+ findEvent,
3230
+ findFact,
3231
+ generateDocs,
3232
+ generateId,
3233
+ generateTauriConfig,
3234
+ getEventPath,
3235
+ getFactPath,
3236
+ getSchemaPath,
3237
+ loadSchema,
3238
+ loadSchemaFromFile,
3239
+ loadSchemaFromJson,
3240
+ loadSchemaFromYaml,
3241
+ registerSchema,
3242
+ runTerminalCommand,
3243
+ schemaToCanvas,
3244
+ validateForGeneration,
3245
+ validateSchema,
3246
+ validateWithGuardian
3247
+ });