@plures/praxis 1.1.2 → 1.2.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 (49) hide show
  1. package/FRAMEWORK.md +106 -15
  2. package/README.md +275 -53
  3. package/dist/browser/adapter-TM4IS5KT.js +12 -0
  4. package/dist/browser/chunk-JQ64KMLN.js +141 -0
  5. package/dist/browser/chunk-LE2ZJYFC.js +154 -0
  6. package/dist/browser/chunk-VOMLVI6V.js +197 -0
  7. package/dist/browser/engine-YJZV4SLD.js +8 -0
  8. package/dist/browser/index.d.ts +300 -11
  9. package/dist/browser/index.js +334 -325
  10. package/dist/browser/integrations/svelte.d.ts +3 -1
  11. package/dist/browser/integrations/svelte.js +8 -0
  12. package/dist/browser/{engine-BjdqxeXG.d.ts → reactive-engine.svelte-C9OpcTHf.d.ts} +87 -1
  13. package/dist/node/adapter-K6DOX6XS.js +13 -0
  14. package/dist/node/chunk-JQ64KMLN.js +141 -0
  15. package/dist/node/chunk-LE2ZJYFC.js +154 -0
  16. package/dist/node/chunk-S54337I5.js +446 -0
  17. package/dist/node/chunk-VOMLVI6V.js +197 -0
  18. package/dist/node/cli/index.cjs +1444 -889
  19. package/dist/node/cli/index.js +9 -0
  20. package/dist/node/components/index.d.cts +2 -2
  21. package/dist/node/components/index.d.ts +2 -2
  22. package/dist/node/docs-JFNYTOJA.js +102 -0
  23. package/dist/node/engine-2DQBKBJC.js +9 -0
  24. package/dist/node/index.cjs +747 -234
  25. package/dist/node/index.d.cts +237 -15
  26. package/dist/node/index.d.ts +237 -15
  27. package/dist/node/index.js +339 -767
  28. package/dist/node/integrations/svelte.cjs +357 -2
  29. package/dist/node/integrations/svelte.d.cts +3 -1
  30. package/dist/node/integrations/svelte.d.ts +3 -1
  31. package/dist/node/integrations/svelte.js +7 -0
  32. package/dist/node/{engine-CVJobhHm.d.cts → reactive-engine.svelte-1M4m_C_v.d.cts} +87 -1
  33. package/dist/node/{engine-1iqLe6_P.d.ts → reactive-engine.svelte-ChNFn4Hj.d.ts} +87 -1
  34. package/dist/node/{terminal-adapter-XLtCjjb_.d.cts → terminal-adapter-CDzxoLKR.d.cts} +68 -1
  35. package/dist/node/{terminal-adapter-07HGftGQ.d.ts → terminal-adapter-CWka-yL8.d.ts} +68 -1
  36. package/package.json +3 -2
  37. package/src/__tests__/reactive-engine.test.ts +516 -0
  38. package/src/cli/commands/docs.ts +147 -0
  39. package/src/cli/index.ts +21 -0
  40. package/src/core/pluresdb/README.md +156 -0
  41. package/src/core/pluresdb/adapter.ts +165 -0
  42. package/src/core/pluresdb/index.ts +3 -3
  43. package/src/core/reactive-engine.svelte.ts +93 -19
  44. package/src/core/reactive-engine.ts +284 -22
  45. package/src/index.browser.ts +16 -0
  46. package/src/index.ts +16 -0
  47. package/src/integrations/pluresdb.ts +2 -2
  48. package/src/integrations/svelte.ts +8 -0
  49. package/src/integrations/unified.ts +350 -0
@@ -1,42 +1,91 @@
1
1
  import { P as PraxisState, a as PraxisEvent, b as PraxisFact } from './protocol-Qek7ebBl.cjs';
2
2
  export { g as PRAXIS_PROTOCOL_VERSION, e as PraxisDiagnostics, d as PraxisStepConfig, f as PraxisStepFn, c as PraxisStepResult } from './protocol-Qek7ebBl.cjs';
3
- import { L as LogicEngine, P as PraxisRegistry, R as RuleDescriptor, C as ConstraintDescriptor, a as RuleFn, b as ConstraintFn, c as PraxisModule } from './engine-CVJobhHm.cjs';
4
- export { e as ConstraintId, f as PraxisEngineOptions, d as RuleId, g as createPraxisEngine } from './engine-CVJobhHm.cjs';
5
- import { P as PraxisDB, U as UnsubscribeFn } from './terminal-adapter-XLtCjjb_.cjs';
6
- export { C as CommandExecutor, I as InMemoryPraxisDB, T as TerminalAdapter, d as TerminalAdapterOptions, a as TerminalExecutionResult, b as TerminalNodeState, f as createInMemoryDB, e as createMockExecutor, c as createTerminalAdapter, r as runTerminalCommand } from './terminal-adapter-XLtCjjb_.cjs';
3
+ import { L as LogicEngine, P as PraxisRegistry, b as RuleDescriptor, C as ConstraintDescriptor, d as RuleFn, e as ConstraintFn, f as PraxisModule } from './reactive-engine.svelte-1M4m_C_v.cjs';
4
+ export { h as ConstraintId, i as PraxisEngineOptions, a as ReactiveEngineOptions, R as ReactiveLogicEngine, g as RuleId, j as createPraxisEngine, c as createReactiveEngine } from './reactive-engine.svelte-1M4m_C_v.cjs';
5
+ import { P as PraxisDB, U as UnsubscribeFn$1 } from './terminal-adapter-CDzxoLKR.cjs';
6
+ export { C as CommandExecutor, I as InMemoryPraxisDB, g as PluresDBAdapterConfig, f as PluresDBInstance, i as PluresDBPraxisAdapter, T as TerminalAdapter, d as TerminalAdapterOptions, a as TerminalExecutionResult, b as TerminalNodeState, h as createInMemoryDB, e as createMockExecutor, j as createPluresDB, c as createTerminalAdapter, r as runTerminalCommand } from './terminal-adapter-CDzxoLKR.cjs';
7
7
  import { PraxisSchema, ValidationResult, ModelDefinition, FieldDefinition, ComponentDefinition, LogicDefinition } from './schema.cjs';
8
8
  export { NodeBindings, NodeDefinition, OrchestrationDefinition, TerminalNodeProps, ValidationError, createSchemaTemplate, validateSchema } from './schema.cjs';
9
9
 
10
10
  /**
11
11
  * Praxis Reactive Logic Engine
12
12
  *
13
- * A Svelte 5 native implementation of the Praxis Logic Engine.
14
- * Uses Runes ($state, $derived, $effect) for fine-grained reactivity.
13
+ * A framework-agnostic reactive implementation of the Praxis Logic Engine.
14
+ * Uses JavaScript Proxies to provide reactivity without Svelte-specific primitives.
15
+ *
16
+ * This implementation provides:
17
+ * - Proxy-based state tracking for automatic reactivity
18
+ * - Subscription-based change notifications
19
+ * - Computed/derived values support
20
+ * - Compatible API with Svelte-based implementation
15
21
  */
16
22
  interface ReactiveEngineOptions<TContext> {
17
23
  initialContext: TContext;
18
24
  initialFacts?: any[];
19
25
  initialMeta?: Record<string, unknown>;
20
26
  }
27
+ /**
28
+ * Callback type for state change subscribers
29
+ */
30
+ type StateChangeCallback<TContext> = (state: {
31
+ context: TContext;
32
+ facts: any[];
33
+ meta: Record<string, unknown>;
34
+ }) => void;
35
+ /**
36
+ * Callback type for unsubscribe function
37
+ */
38
+ type UnsubscribeFn = () => void;
39
+ /**
40
+ * Framework-agnostic reactive logic engine using JavaScript Proxies
41
+ */
21
42
  declare class ReactiveLogicEngine<TContext extends object> {
22
- state: {
43
+ private _state;
44
+ private _subscribers;
45
+ private _contextProxy;
46
+ private _factsProxy;
47
+ private _metaProxy;
48
+ private _batchDepth;
49
+ private _pendingNotification;
50
+ private _proxyCache;
51
+ private static readonly ARRAY_MUTATORS;
52
+ constructor(options: ReactiveEngineOptions<TContext>);
53
+ /**
54
+ * Create a reactive proxy that notifies subscribers on changes.
55
+ * Uses a WeakMap cache to avoid creating multiple proxies for the same object.
56
+ */
57
+ private _createReactiveProxy;
58
+ /**
59
+ * Notify all subscribers of state changes
60
+ */
61
+ private _notify;
62
+ /**
63
+ * Get the full state object
64
+ */
65
+ get state(): {
23
66
  context: TContext;
24
67
  facts: any[];
25
68
  meta: Record<string, unknown>;
26
69
  };
27
- constructor(options: ReactiveEngineOptions<TContext>);
28
70
  /**
29
- * Access the reactive context directly.
30
- * Consumers can use this in $derived() or $effect().
71
+ * Access the reactive context.
72
+ * Changes to this object will trigger subscriber notifications.
31
73
  */
32
74
  get context(): TContext;
33
75
  /**
34
76
  * Access the reactive facts list.
77
+ * Changes to this array will trigger subscriber notifications.
35
78
  */
36
79
  get facts(): any[];
80
+ /**
81
+ * Access the reactive metadata.
82
+ * Changes to this object will trigger subscriber notifications.
83
+ */
84
+ get meta(): Record<string, unknown>;
37
85
  /**
38
86
  * Apply a mutation to the state.
39
87
  * This is the "Action" or "Rule" equivalent.
88
+ * Mutations are batched - notifications only happen once per apply call.
40
89
  *
41
90
  * @param mutator A function that receives the state and modifies it.
42
91
  */
@@ -46,10 +95,54 @@ declare class ReactiveLogicEngine<TContext extends object> {
46
95
  meta: Record<string, unknown>;
47
96
  }) => void): void;
48
97
  /**
49
- * Access the reactive meta.
98
+ * Subscribe to state changes.
99
+ * Returns an unsubscribe function.
100
+ *
101
+ * @param callback Function to call when state changes
102
+ * @returns Unsubscribe function
103
+ */
104
+ subscribe(callback: StateChangeCallback<TContext>): UnsubscribeFn;
105
+ /**
106
+ * Create a derived/computed value from the state.
107
+ * The selector function will be called whenever the state changes.
108
+ *
109
+ * @param selector Function to extract derived value from state
110
+ * @returns Object with subscribe method for reactive updates
50
111
  */
51
- get meta(): Record<string, unknown>;
112
+ $derived<TDerived>(selector: (state: {
113
+ context: TContext;
114
+ facts: any[];
115
+ meta: Record<string, unknown>;
116
+ }) => TDerived): {
117
+ subscribe: (callback: (value: TDerived) => void) => UnsubscribeFn;
118
+ };
52
119
  }
120
+ /**
121
+ * Create a new reactive logic engine instance.
122
+ *
123
+ * @param options Configuration options for the reactive engine
124
+ * @returns A new ReactiveLogicEngine instance
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const engine = createReactiveEngine({
129
+ * initialContext: { count: 0 },
130
+ * initialFacts: [],
131
+ * initialMeta: {}
132
+ * });
133
+ *
134
+ * // Subscribe to changes
135
+ * engine.subscribe((state) => {
136
+ * console.log('State changed:', state);
137
+ * });
138
+ *
139
+ * // Mutate state (will trigger subscribers)
140
+ * engine.apply((state) => {
141
+ * state.context.count++;
142
+ * });
143
+ * ```
144
+ */
145
+ declare function createReactiveEngine<TContext extends object>(options: ReactiveEngineOptions<TContext>): ReactiveLogicEngine<TContext>;
53
146
 
54
147
  /**
55
148
  * Actors System
@@ -634,7 +727,7 @@ declare class PraxisDBStore<TContext = unknown> {
634
727
  * @param callback Called when facts of this type change
635
728
  * @returns Unsubscribe function
636
729
  */
637
- watchFacts(factTag: string, callback: (facts: PraxisFact[]) => void): UnsubscribeFn;
730
+ watchFacts(factTag: string, callback: (facts: PraxisFact[]) => void): UnsubscribeFn$1;
638
731
  /**
639
732
  * Check constraints against the current state with new facts
640
733
  */
@@ -997,7 +1090,7 @@ declare function createPluresDBAdapter<TContext = unknown>(options: PluresDBAdap
997
1090
  * detach();
998
1091
  * ```
999
1092
  */
1000
- declare function attachToEngine<TContext = unknown>(store: PraxisDBStore<TContext>, engine: LogicEngine<TContext>): UnsubscribeFn;
1093
+ declare function attachToEngine<TContext = unknown>(store: PraxisDBStore<TContext>, engine: LogicEngine<TContext>): UnsubscribeFn$1;
1001
1094
 
1002
1095
  /**
1003
1096
  * Unum Integration
@@ -2576,4 +2669,133 @@ declare function attachTauriToEngine<TContext>(engine: LogicEngine<TContext>, ad
2576
2669
  */
2577
2670
  declare function generateTauriConfig(config: TauriAppConfig): Record<string, unknown>;
2578
2671
 
2579
- export { type ActivityState, type Actor, ActorManager, type CanvasDocument, type CanvasEdge, type CanvasEdgeStyle, type CanvasEditorConfig, type CanvasNode, type CanvasNodeStyle, ComponentDefinition, ConstraintDescriptor, ConstraintFn, type ConstraintNode, type ConstraintSchema, type DefineConstraintOptions, type DefineModuleOptions, type DefineRuleOptions, type EventDefinition, type EventStreamEntry, type FactDefinition, type GeneratedDoc, type GeneratedPluresDBFile, type GraphEdge, type GuardianError, type GuardianResult, type GuardianWarning, type LifecycleState, type LoaderOptions, type LoaderResult, LogicDefinition, LogicEngine, ModelDefinition, PRAXIS_PATHS, type PluresDBAdapter, type PluresDBAdapterOptions, PluresDBGenerator, type PluresDBGeneratorOptions, PraxisDB, PraxisDBStore, type PraxisDBStoreOptions, PraxisEvent, PraxisFact, PraxisModule, PraxisRegistry, PraxisSchema, PraxisSchemaRegistry, PraxisState, type ReactiveEngineOptions, ReactiveLogicEngine, type RegistryGraph, RegistryIntrospector, type RegistrySchema, type RegistryStats, RuleDescriptor, RuleFn, type RuleNode, type RuleSchema, type StateDoc, type StateDocsConfig, StateDocsGenerator, type StateMachineDoc, type StoredSchema, type TauriAppConfig, type TauriBridge, type TauriCommand, type TauriEvent, type TauriFS, type TauriFileEntry, type TauriMenuItem, type TauriNotification, type TauriNotificationOptions, type TauriPlugin, type TauriPraxisAdapter, type TauriSecurityConfig, type TauriTray, type TauriUpdateConfig, type TauriUpdateInfo, type TauriWindowConfig, type TransitionDoc, UnsubscribeFn, type UnumAdapter, type UnumAdapterConfig, type UnumChannel, type UnumIdentity, type UnumMessage, type UnumStore, ValidationResult, attachTauriToEngine, attachToEngine, attachUnumToEngine, canvasToMermaid, canvasToSchema, canvasToYaml, createCanvasEditor, createIntrospector, createMockTauriBridge, createPluresDBAdapter, createPluresDBGenerator, createPraxisDBStore, createSchemaRegistry, createStateDocsGenerator, createTauriPraxisAdapter, createTimerActor, createUnumAdapter, defineConstraint, defineEvent, defineFact, defineModule, defineRule, filterEvents, filterFacts, findEvent, findFact, generateDocs, generateId, generateTauriConfig, getEventPath, getFactPath, getSchemaPath, loadSchema, loadSchemaFromFile, loadSchemaFromJson, loadSchemaFromYaml, registerSchema, schemaToCanvas, validateForGeneration, validateWithGuardian };
2672
+ /**
2673
+ * Unified Integration Helpers
2674
+ *
2675
+ * Convenience functions for setting up Praxis with all ecosystem integrations
2676
+ * (PluresDB, Unum, State-Docs, CodeCanvas) in a single call.
2677
+ */
2678
+
2679
+ /**
2680
+ * Configuration for unified Praxis application
2681
+ */
2682
+ interface UnifiedAppConfig<TContext = unknown> {
2683
+ /** Praxis registry with rules and constraints */
2684
+ registry: PraxisRegistry<TContext>;
2685
+ /** Initial context for the engine */
2686
+ initialContext: TContext;
2687
+ /** PluresDB instance (if not provided, creates in-memory DB) */
2688
+ db?: PraxisDB;
2689
+ /** Enable Unum for distributed communication */
2690
+ enableUnum?: boolean;
2691
+ /** Unum identity configuration (without id and createdAt which are auto-generated) */
2692
+ unumIdentity?: Omit<UnumIdentity, 'id' | 'createdAt'>;
2693
+ /** Enable State-Docs documentation generation */
2694
+ enableDocs?: boolean;
2695
+ /** State-Docs configuration */
2696
+ docsConfig?: {
2697
+ projectTitle: string;
2698
+ target?: string;
2699
+ };
2700
+ /** Praxis schema for CodeCanvas integration */
2701
+ schema?: PraxisSchema;
2702
+ }
2703
+ /**
2704
+ * Unified application instance with all integrations
2705
+ */
2706
+ interface UnifiedApp<TContext = unknown> {
2707
+ /** Praxis logic engine */
2708
+ engine: LogicEngine<TContext>;
2709
+ /** PluresDB adapter for persistence */
2710
+ pluresdb: PluresDBAdapter<TContext>;
2711
+ /** Unum adapter for distributed communication (if enabled) */
2712
+ unum?: UnumAdapter;
2713
+ /** Default Unum channel (if Unum enabled) */
2714
+ channel?: UnumChannel;
2715
+ /** State-Docs generator (if enabled) */
2716
+ docs?: StateDocsGenerator;
2717
+ /** CodeCanvas document (if schema provided) */
2718
+ canvas?: CanvasDocument;
2719
+ /** Generate documentation from current state */
2720
+ generateDocs?: () => GeneratedDoc[];
2721
+ /** Cleanup function to dispose all integrations */
2722
+ dispose: () => void;
2723
+ }
2724
+ /**
2725
+ * Create a unified Praxis application with all integrations
2726
+ *
2727
+ * This is a convenience function that sets up:
2728
+ * - Praxis logic engine
2729
+ * - PluresDB for persistence (auto-attaches to engine)
2730
+ * - Unum for distributed communication (optional)
2731
+ * - State-Docs for documentation generation (optional)
2732
+ * - CodeCanvas for visual schema editing (optional)
2733
+ *
2734
+ * @example
2735
+ * ```typescript
2736
+ * import { createUnifiedApp } from '@plures/praxis';
2737
+ *
2738
+ * const app = await createUnifiedApp({
2739
+ * registry: myRegistry,
2740
+ * initialContext: { count: 0 },
2741
+ * enableUnum: true,
2742
+ * unumIdentity: { name: 'node-1' },
2743
+ * enableDocs: true,
2744
+ * docsConfig: { projectTitle: 'My App' },
2745
+ * schema: mySchema,
2746
+ * });
2747
+ *
2748
+ * // Use the engine
2749
+ * app.engine.step([myEvent]);
2750
+ *
2751
+ * // Broadcast to other nodes
2752
+ * if (app.channel) {
2753
+ * await app.unum?.broadcastEvent(app.channel.id, myEvent);
2754
+ * }
2755
+ *
2756
+ * // Generate documentation
2757
+ * const docs = app.generateDocs?.();
2758
+ *
2759
+ * // Cleanup
2760
+ * app.dispose();
2761
+ * ```
2762
+ */
2763
+ declare function createUnifiedApp<TContext = unknown>(config: UnifiedAppConfig<TContext>): Promise<UnifiedApp<TContext>>;
2764
+ /**
2765
+ * Attach all available integrations to an existing Praxis engine
2766
+ *
2767
+ * This is useful when you already have an engine and want to add integrations.
2768
+ *
2769
+ * @example
2770
+ * ```typescript
2771
+ * import { createPraxisEngine, attachAllIntegrations } from '@plures/praxis';
2772
+ *
2773
+ * const engine = createPraxisEngine({ initialContext: {}, registry });
2774
+ *
2775
+ * const integrations = await attachAllIntegrations(engine, registry, {
2776
+ * enableUnum: true,
2777
+ * enableDocs: true,
2778
+ * });
2779
+ *
2780
+ * // Later cleanup
2781
+ * integrations.dispose();
2782
+ * ```
2783
+ */
2784
+ declare function attachAllIntegrations<TContext = unknown>(engine: LogicEngine<TContext>, registry: PraxisRegistry<TContext>, options?: {
2785
+ db?: PraxisDB;
2786
+ enableUnum?: boolean;
2787
+ unumIdentity?: Omit<UnumIdentity, 'id' | 'createdAt'>;
2788
+ enableDocs?: boolean;
2789
+ docsConfig?: {
2790
+ projectTitle: string;
2791
+ target?: string;
2792
+ };
2793
+ }): Promise<{
2794
+ pluresdb: PluresDBAdapter<TContext>;
2795
+ unum?: UnumAdapter;
2796
+ channel?: UnumChannel;
2797
+ docs?: StateDocsGenerator;
2798
+ dispose: () => void;
2799
+ }>;
2800
+
2801
+ export { type ActivityState, type Actor, ActorManager, type CanvasDocument, type CanvasEdge, type CanvasEdgeStyle, type CanvasEditorConfig, type CanvasNode, type CanvasNodeStyle, ComponentDefinition, ConstraintDescriptor, ConstraintFn, type ConstraintNode, type ConstraintSchema, type DefineConstraintOptions, type DefineModuleOptions, type DefineRuleOptions, type EventDefinition, type EventStreamEntry, type FactDefinition, ReactiveLogicEngine as FrameworkAgnosticReactiveEngine, type ReactiveEngineOptions as FrameworkAgnosticReactiveEngineOptions, type GeneratedDoc, type GeneratedPluresDBFile, type GraphEdge, type GuardianError, type GuardianResult, type GuardianWarning, type LifecycleState, type LoaderOptions, type LoaderResult, LogicDefinition, LogicEngine, ModelDefinition, PRAXIS_PATHS, type PluresDBAdapter, type PluresDBAdapterOptions, PluresDBGenerator, type PluresDBGeneratorOptions, PraxisDB, PraxisDBStore, type PraxisDBStoreOptions, PraxisEvent, PraxisFact, PraxisModule, PraxisRegistry, PraxisSchema, PraxisSchemaRegistry, PraxisState, type RegistryGraph, RegistryIntrospector, type RegistrySchema, type RegistryStats, RuleDescriptor, RuleFn, type RuleNode, type RuleSchema, type StateChangeCallback, type StateDoc, type StateDocsConfig, StateDocsGenerator, type StateMachineDoc, type StoredSchema, type TauriAppConfig, type TauriBridge, type TauriCommand, type TauriEvent, type TauriFS, type TauriFileEntry, type TauriMenuItem, type TauriNotification, type TauriNotificationOptions, type TauriPlugin, type TauriPraxisAdapter, type TauriSecurityConfig, type TauriTray, type TauriUpdateConfig, type TauriUpdateInfo, type TauriWindowConfig, type TransitionDoc, type UnifiedApp, type UnifiedAppConfig, UnsubscribeFn$1 as UnsubscribeFn, type UnumAdapter, type UnumAdapterConfig, type UnumChannel, type UnumIdentity, type UnumMessage, type UnumStore, ValidationResult, attachAllIntegrations, attachTauriToEngine, attachToEngine, attachUnumToEngine, canvasToMermaid, canvasToSchema, canvasToYaml, createCanvasEditor, createReactiveEngine as createFrameworkAgnosticReactiveEngine, createIntrospector, createMockTauriBridge, createPluresDBAdapter, createPluresDBGenerator, createPraxisDBStore, createSchemaRegistry, createStateDocsGenerator, createTauriPraxisAdapter, createTimerActor, createUnifiedApp, createUnumAdapter, defineConstraint, defineEvent, defineFact, defineModule, defineRule, filterEvents, filterFacts, findEvent, findFact, generateDocs, generateId, generateTauriConfig, getEventPath, getFactPath, getSchemaPath, loadSchema, loadSchemaFromFile, loadSchemaFromJson, loadSchemaFromYaml, registerSchema, schemaToCanvas, validateForGeneration, validateWithGuardian };
@@ -1,42 +1,91 @@
1
1
  import { P as PraxisState, a as PraxisEvent, b as PraxisFact } from './protocol-Qek7ebBl.js';
2
2
  export { g as PRAXIS_PROTOCOL_VERSION, e as PraxisDiagnostics, d as PraxisStepConfig, f as PraxisStepFn, c as PraxisStepResult } from './protocol-Qek7ebBl.js';
3
- import { L as LogicEngine, P as PraxisRegistry, R as RuleDescriptor, C as ConstraintDescriptor, a as RuleFn, b as ConstraintFn, c as PraxisModule } from './engine-1iqLe6_P.js';
4
- export { e as ConstraintId, f as PraxisEngineOptions, d as RuleId, g as createPraxisEngine } from './engine-1iqLe6_P.js';
5
- import { P as PraxisDB, U as UnsubscribeFn } from './terminal-adapter-07HGftGQ.js';
6
- export { C as CommandExecutor, I as InMemoryPraxisDB, T as TerminalAdapter, d as TerminalAdapterOptions, a as TerminalExecutionResult, b as TerminalNodeState, f as createInMemoryDB, e as createMockExecutor, c as createTerminalAdapter, r as runTerminalCommand } from './terminal-adapter-07HGftGQ.js';
3
+ import { L as LogicEngine, P as PraxisRegistry, b as RuleDescriptor, C as ConstraintDescriptor, d as RuleFn, e as ConstraintFn, f as PraxisModule } from './reactive-engine.svelte-ChNFn4Hj.js';
4
+ export { h as ConstraintId, i as PraxisEngineOptions, a as ReactiveEngineOptions, R as ReactiveLogicEngine, g as RuleId, j as createPraxisEngine, c as createReactiveEngine } from './reactive-engine.svelte-ChNFn4Hj.js';
5
+ import { P as PraxisDB, U as UnsubscribeFn$1 } from './terminal-adapter-CWka-yL8.js';
6
+ export { C as CommandExecutor, I as InMemoryPraxisDB, g as PluresDBAdapterConfig, f as PluresDBInstance, i as PluresDBPraxisAdapter, T as TerminalAdapter, d as TerminalAdapterOptions, a as TerminalExecutionResult, b as TerminalNodeState, h as createInMemoryDB, e as createMockExecutor, j as createPluresDB, c as createTerminalAdapter, r as runTerminalCommand } from './terminal-adapter-CWka-yL8.js';
7
7
  import { PraxisSchema, ValidationResult, ModelDefinition, FieldDefinition, ComponentDefinition, LogicDefinition } from './schema.js';
8
8
  export { NodeBindings, NodeDefinition, OrchestrationDefinition, TerminalNodeProps, ValidationError, createSchemaTemplate, validateSchema } from './schema.js';
9
9
 
10
10
  /**
11
11
  * Praxis Reactive Logic Engine
12
12
  *
13
- * A Svelte 5 native implementation of the Praxis Logic Engine.
14
- * Uses Runes ($state, $derived, $effect) for fine-grained reactivity.
13
+ * A framework-agnostic reactive implementation of the Praxis Logic Engine.
14
+ * Uses JavaScript Proxies to provide reactivity without Svelte-specific primitives.
15
+ *
16
+ * This implementation provides:
17
+ * - Proxy-based state tracking for automatic reactivity
18
+ * - Subscription-based change notifications
19
+ * - Computed/derived values support
20
+ * - Compatible API with Svelte-based implementation
15
21
  */
16
22
  interface ReactiveEngineOptions<TContext> {
17
23
  initialContext: TContext;
18
24
  initialFacts?: any[];
19
25
  initialMeta?: Record<string, unknown>;
20
26
  }
27
+ /**
28
+ * Callback type for state change subscribers
29
+ */
30
+ type StateChangeCallback<TContext> = (state: {
31
+ context: TContext;
32
+ facts: any[];
33
+ meta: Record<string, unknown>;
34
+ }) => void;
35
+ /**
36
+ * Callback type for unsubscribe function
37
+ */
38
+ type UnsubscribeFn = () => void;
39
+ /**
40
+ * Framework-agnostic reactive logic engine using JavaScript Proxies
41
+ */
21
42
  declare class ReactiveLogicEngine<TContext extends object> {
22
- state: {
43
+ private _state;
44
+ private _subscribers;
45
+ private _contextProxy;
46
+ private _factsProxy;
47
+ private _metaProxy;
48
+ private _batchDepth;
49
+ private _pendingNotification;
50
+ private _proxyCache;
51
+ private static readonly ARRAY_MUTATORS;
52
+ constructor(options: ReactiveEngineOptions<TContext>);
53
+ /**
54
+ * Create a reactive proxy that notifies subscribers on changes.
55
+ * Uses a WeakMap cache to avoid creating multiple proxies for the same object.
56
+ */
57
+ private _createReactiveProxy;
58
+ /**
59
+ * Notify all subscribers of state changes
60
+ */
61
+ private _notify;
62
+ /**
63
+ * Get the full state object
64
+ */
65
+ get state(): {
23
66
  context: TContext;
24
67
  facts: any[];
25
68
  meta: Record<string, unknown>;
26
69
  };
27
- constructor(options: ReactiveEngineOptions<TContext>);
28
70
  /**
29
- * Access the reactive context directly.
30
- * Consumers can use this in $derived() or $effect().
71
+ * Access the reactive context.
72
+ * Changes to this object will trigger subscriber notifications.
31
73
  */
32
74
  get context(): TContext;
33
75
  /**
34
76
  * Access the reactive facts list.
77
+ * Changes to this array will trigger subscriber notifications.
35
78
  */
36
79
  get facts(): any[];
80
+ /**
81
+ * Access the reactive metadata.
82
+ * Changes to this object will trigger subscriber notifications.
83
+ */
84
+ get meta(): Record<string, unknown>;
37
85
  /**
38
86
  * Apply a mutation to the state.
39
87
  * This is the "Action" or "Rule" equivalent.
88
+ * Mutations are batched - notifications only happen once per apply call.
40
89
  *
41
90
  * @param mutator A function that receives the state and modifies it.
42
91
  */
@@ -46,10 +95,54 @@ declare class ReactiveLogicEngine<TContext extends object> {
46
95
  meta: Record<string, unknown>;
47
96
  }) => void): void;
48
97
  /**
49
- * Access the reactive meta.
98
+ * Subscribe to state changes.
99
+ * Returns an unsubscribe function.
100
+ *
101
+ * @param callback Function to call when state changes
102
+ * @returns Unsubscribe function
103
+ */
104
+ subscribe(callback: StateChangeCallback<TContext>): UnsubscribeFn;
105
+ /**
106
+ * Create a derived/computed value from the state.
107
+ * The selector function will be called whenever the state changes.
108
+ *
109
+ * @param selector Function to extract derived value from state
110
+ * @returns Object with subscribe method for reactive updates
50
111
  */
51
- get meta(): Record<string, unknown>;
112
+ $derived<TDerived>(selector: (state: {
113
+ context: TContext;
114
+ facts: any[];
115
+ meta: Record<string, unknown>;
116
+ }) => TDerived): {
117
+ subscribe: (callback: (value: TDerived) => void) => UnsubscribeFn;
118
+ };
52
119
  }
120
+ /**
121
+ * Create a new reactive logic engine instance.
122
+ *
123
+ * @param options Configuration options for the reactive engine
124
+ * @returns A new ReactiveLogicEngine instance
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const engine = createReactiveEngine({
129
+ * initialContext: { count: 0 },
130
+ * initialFacts: [],
131
+ * initialMeta: {}
132
+ * });
133
+ *
134
+ * // Subscribe to changes
135
+ * engine.subscribe((state) => {
136
+ * console.log('State changed:', state);
137
+ * });
138
+ *
139
+ * // Mutate state (will trigger subscribers)
140
+ * engine.apply((state) => {
141
+ * state.context.count++;
142
+ * });
143
+ * ```
144
+ */
145
+ declare function createReactiveEngine<TContext extends object>(options: ReactiveEngineOptions<TContext>): ReactiveLogicEngine<TContext>;
53
146
 
54
147
  /**
55
148
  * Actors System
@@ -634,7 +727,7 @@ declare class PraxisDBStore<TContext = unknown> {
634
727
  * @param callback Called when facts of this type change
635
728
  * @returns Unsubscribe function
636
729
  */
637
- watchFacts(factTag: string, callback: (facts: PraxisFact[]) => void): UnsubscribeFn;
730
+ watchFacts(factTag: string, callback: (facts: PraxisFact[]) => void): UnsubscribeFn$1;
638
731
  /**
639
732
  * Check constraints against the current state with new facts
640
733
  */
@@ -997,7 +1090,7 @@ declare function createPluresDBAdapter<TContext = unknown>(options: PluresDBAdap
997
1090
  * detach();
998
1091
  * ```
999
1092
  */
1000
- declare function attachToEngine<TContext = unknown>(store: PraxisDBStore<TContext>, engine: LogicEngine<TContext>): UnsubscribeFn;
1093
+ declare function attachToEngine<TContext = unknown>(store: PraxisDBStore<TContext>, engine: LogicEngine<TContext>): UnsubscribeFn$1;
1001
1094
 
1002
1095
  /**
1003
1096
  * Unum Integration
@@ -2576,4 +2669,133 @@ declare function attachTauriToEngine<TContext>(engine: LogicEngine<TContext>, ad
2576
2669
  */
2577
2670
  declare function generateTauriConfig(config: TauriAppConfig): Record<string, unknown>;
2578
2671
 
2579
- export { type ActivityState, type Actor, ActorManager, type CanvasDocument, type CanvasEdge, type CanvasEdgeStyle, type CanvasEditorConfig, type CanvasNode, type CanvasNodeStyle, ComponentDefinition, ConstraintDescriptor, ConstraintFn, type ConstraintNode, type ConstraintSchema, type DefineConstraintOptions, type DefineModuleOptions, type DefineRuleOptions, type EventDefinition, type EventStreamEntry, type FactDefinition, type GeneratedDoc, type GeneratedPluresDBFile, type GraphEdge, type GuardianError, type GuardianResult, type GuardianWarning, type LifecycleState, type LoaderOptions, type LoaderResult, LogicDefinition, LogicEngine, ModelDefinition, PRAXIS_PATHS, type PluresDBAdapter, type PluresDBAdapterOptions, PluresDBGenerator, type PluresDBGeneratorOptions, PraxisDB, PraxisDBStore, type PraxisDBStoreOptions, PraxisEvent, PraxisFact, PraxisModule, PraxisRegistry, PraxisSchema, PraxisSchemaRegistry, PraxisState, type ReactiveEngineOptions, ReactiveLogicEngine, type RegistryGraph, RegistryIntrospector, type RegistrySchema, type RegistryStats, RuleDescriptor, RuleFn, type RuleNode, type RuleSchema, type StateDoc, type StateDocsConfig, StateDocsGenerator, type StateMachineDoc, type StoredSchema, type TauriAppConfig, type TauriBridge, type TauriCommand, type TauriEvent, type TauriFS, type TauriFileEntry, type TauriMenuItem, type TauriNotification, type TauriNotificationOptions, type TauriPlugin, type TauriPraxisAdapter, type TauriSecurityConfig, type TauriTray, type TauriUpdateConfig, type TauriUpdateInfo, type TauriWindowConfig, type TransitionDoc, UnsubscribeFn, type UnumAdapter, type UnumAdapterConfig, type UnumChannel, type UnumIdentity, type UnumMessage, type UnumStore, ValidationResult, attachTauriToEngine, attachToEngine, attachUnumToEngine, canvasToMermaid, canvasToSchema, canvasToYaml, createCanvasEditor, createIntrospector, createMockTauriBridge, createPluresDBAdapter, createPluresDBGenerator, createPraxisDBStore, createSchemaRegistry, createStateDocsGenerator, createTauriPraxisAdapter, createTimerActor, createUnumAdapter, defineConstraint, defineEvent, defineFact, defineModule, defineRule, filterEvents, filterFacts, findEvent, findFact, generateDocs, generateId, generateTauriConfig, getEventPath, getFactPath, getSchemaPath, loadSchema, loadSchemaFromFile, loadSchemaFromJson, loadSchemaFromYaml, registerSchema, schemaToCanvas, validateForGeneration, validateWithGuardian };
2672
+ /**
2673
+ * Unified Integration Helpers
2674
+ *
2675
+ * Convenience functions for setting up Praxis with all ecosystem integrations
2676
+ * (PluresDB, Unum, State-Docs, CodeCanvas) in a single call.
2677
+ */
2678
+
2679
+ /**
2680
+ * Configuration for unified Praxis application
2681
+ */
2682
+ interface UnifiedAppConfig<TContext = unknown> {
2683
+ /** Praxis registry with rules and constraints */
2684
+ registry: PraxisRegistry<TContext>;
2685
+ /** Initial context for the engine */
2686
+ initialContext: TContext;
2687
+ /** PluresDB instance (if not provided, creates in-memory DB) */
2688
+ db?: PraxisDB;
2689
+ /** Enable Unum for distributed communication */
2690
+ enableUnum?: boolean;
2691
+ /** Unum identity configuration (without id and createdAt which are auto-generated) */
2692
+ unumIdentity?: Omit<UnumIdentity, 'id' | 'createdAt'>;
2693
+ /** Enable State-Docs documentation generation */
2694
+ enableDocs?: boolean;
2695
+ /** State-Docs configuration */
2696
+ docsConfig?: {
2697
+ projectTitle: string;
2698
+ target?: string;
2699
+ };
2700
+ /** Praxis schema for CodeCanvas integration */
2701
+ schema?: PraxisSchema;
2702
+ }
2703
+ /**
2704
+ * Unified application instance with all integrations
2705
+ */
2706
+ interface UnifiedApp<TContext = unknown> {
2707
+ /** Praxis logic engine */
2708
+ engine: LogicEngine<TContext>;
2709
+ /** PluresDB adapter for persistence */
2710
+ pluresdb: PluresDBAdapter<TContext>;
2711
+ /** Unum adapter for distributed communication (if enabled) */
2712
+ unum?: UnumAdapter;
2713
+ /** Default Unum channel (if Unum enabled) */
2714
+ channel?: UnumChannel;
2715
+ /** State-Docs generator (if enabled) */
2716
+ docs?: StateDocsGenerator;
2717
+ /** CodeCanvas document (if schema provided) */
2718
+ canvas?: CanvasDocument;
2719
+ /** Generate documentation from current state */
2720
+ generateDocs?: () => GeneratedDoc[];
2721
+ /** Cleanup function to dispose all integrations */
2722
+ dispose: () => void;
2723
+ }
2724
+ /**
2725
+ * Create a unified Praxis application with all integrations
2726
+ *
2727
+ * This is a convenience function that sets up:
2728
+ * - Praxis logic engine
2729
+ * - PluresDB for persistence (auto-attaches to engine)
2730
+ * - Unum for distributed communication (optional)
2731
+ * - State-Docs for documentation generation (optional)
2732
+ * - CodeCanvas for visual schema editing (optional)
2733
+ *
2734
+ * @example
2735
+ * ```typescript
2736
+ * import { createUnifiedApp } from '@plures/praxis';
2737
+ *
2738
+ * const app = await createUnifiedApp({
2739
+ * registry: myRegistry,
2740
+ * initialContext: { count: 0 },
2741
+ * enableUnum: true,
2742
+ * unumIdentity: { name: 'node-1' },
2743
+ * enableDocs: true,
2744
+ * docsConfig: { projectTitle: 'My App' },
2745
+ * schema: mySchema,
2746
+ * });
2747
+ *
2748
+ * // Use the engine
2749
+ * app.engine.step([myEvent]);
2750
+ *
2751
+ * // Broadcast to other nodes
2752
+ * if (app.channel) {
2753
+ * await app.unum?.broadcastEvent(app.channel.id, myEvent);
2754
+ * }
2755
+ *
2756
+ * // Generate documentation
2757
+ * const docs = app.generateDocs?.();
2758
+ *
2759
+ * // Cleanup
2760
+ * app.dispose();
2761
+ * ```
2762
+ */
2763
+ declare function createUnifiedApp<TContext = unknown>(config: UnifiedAppConfig<TContext>): Promise<UnifiedApp<TContext>>;
2764
+ /**
2765
+ * Attach all available integrations to an existing Praxis engine
2766
+ *
2767
+ * This is useful when you already have an engine and want to add integrations.
2768
+ *
2769
+ * @example
2770
+ * ```typescript
2771
+ * import { createPraxisEngine, attachAllIntegrations } from '@plures/praxis';
2772
+ *
2773
+ * const engine = createPraxisEngine({ initialContext: {}, registry });
2774
+ *
2775
+ * const integrations = await attachAllIntegrations(engine, registry, {
2776
+ * enableUnum: true,
2777
+ * enableDocs: true,
2778
+ * });
2779
+ *
2780
+ * // Later cleanup
2781
+ * integrations.dispose();
2782
+ * ```
2783
+ */
2784
+ declare function attachAllIntegrations<TContext = unknown>(engine: LogicEngine<TContext>, registry: PraxisRegistry<TContext>, options?: {
2785
+ db?: PraxisDB;
2786
+ enableUnum?: boolean;
2787
+ unumIdentity?: Omit<UnumIdentity, 'id' | 'createdAt'>;
2788
+ enableDocs?: boolean;
2789
+ docsConfig?: {
2790
+ projectTitle: string;
2791
+ target?: string;
2792
+ };
2793
+ }): Promise<{
2794
+ pluresdb: PluresDBAdapter<TContext>;
2795
+ unum?: UnumAdapter;
2796
+ channel?: UnumChannel;
2797
+ docs?: StateDocsGenerator;
2798
+ dispose: () => void;
2799
+ }>;
2800
+
2801
+ export { type ActivityState, type Actor, ActorManager, type CanvasDocument, type CanvasEdge, type CanvasEdgeStyle, type CanvasEditorConfig, type CanvasNode, type CanvasNodeStyle, ComponentDefinition, ConstraintDescriptor, ConstraintFn, type ConstraintNode, type ConstraintSchema, type DefineConstraintOptions, type DefineModuleOptions, type DefineRuleOptions, type EventDefinition, type EventStreamEntry, type FactDefinition, ReactiveLogicEngine as FrameworkAgnosticReactiveEngine, type ReactiveEngineOptions as FrameworkAgnosticReactiveEngineOptions, type GeneratedDoc, type GeneratedPluresDBFile, type GraphEdge, type GuardianError, type GuardianResult, type GuardianWarning, type LifecycleState, type LoaderOptions, type LoaderResult, LogicDefinition, LogicEngine, ModelDefinition, PRAXIS_PATHS, type PluresDBAdapter, type PluresDBAdapterOptions, PluresDBGenerator, type PluresDBGeneratorOptions, PraxisDB, PraxisDBStore, type PraxisDBStoreOptions, PraxisEvent, PraxisFact, PraxisModule, PraxisRegistry, PraxisSchema, PraxisSchemaRegistry, PraxisState, type RegistryGraph, RegistryIntrospector, type RegistrySchema, type RegistryStats, RuleDescriptor, RuleFn, type RuleNode, type RuleSchema, type StateChangeCallback, type StateDoc, type StateDocsConfig, StateDocsGenerator, type StateMachineDoc, type StoredSchema, type TauriAppConfig, type TauriBridge, type TauriCommand, type TauriEvent, type TauriFS, type TauriFileEntry, type TauriMenuItem, type TauriNotification, type TauriNotificationOptions, type TauriPlugin, type TauriPraxisAdapter, type TauriSecurityConfig, type TauriTray, type TauriUpdateConfig, type TauriUpdateInfo, type TauriWindowConfig, type TransitionDoc, type UnifiedApp, type UnifiedAppConfig, UnsubscribeFn$1 as UnsubscribeFn, type UnumAdapter, type UnumAdapterConfig, type UnumChannel, type UnumIdentity, type UnumMessage, type UnumStore, ValidationResult, attachAllIntegrations, attachTauriToEngine, attachToEngine, attachUnumToEngine, canvasToMermaid, canvasToSchema, canvasToYaml, createCanvasEditor, createReactiveEngine as createFrameworkAgnosticReactiveEngine, createIntrospector, createMockTauriBridge, createPluresDBAdapter, createPluresDBGenerator, createPraxisDBStore, createSchemaRegistry, createStateDocsGenerator, createTauriPraxisAdapter, createTimerActor, createUnifiedApp, createUnumAdapter, defineConstraint, defineEvent, defineFact, defineModule, defineRule, filterEvents, filterFacts, findEvent, findFact, generateDocs, generateId, generateTauriConfig, getEventPath, getFactPath, getSchemaPath, loadSchema, loadSchemaFromFile, loadSchemaFromJson, loadSchemaFromYaml, registerSchema, schemaToCanvas, validateForGeneration, validateWithGuardian };