qnce-engine 0.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.md +959 -5
  2. package/dist/cli/audit.js +6 -4
  3. package/dist/cli/audit.js.map +1 -1
  4. package/dist/cli/init.js +11 -9
  5. package/dist/cli/init.js.map +1 -1
  6. package/dist/cli/perf.d.ts +30 -0
  7. package/dist/cli/perf.d.ts.map +1 -0
  8. package/dist/cli/perf.js +220 -0
  9. package/dist/cli/perf.js.map +1 -0
  10. package/dist/cli/play.d.ts +4 -0
  11. package/dist/cli/play.d.ts.map +1 -0
  12. package/dist/cli/play.js +259 -0
  13. package/dist/cli/play.js.map +1 -0
  14. package/dist/engine/condition.d.ts +69 -0
  15. package/dist/engine/condition.d.ts.map +1 -0
  16. package/dist/engine/condition.js +195 -0
  17. package/dist/engine/condition.js.map +1 -0
  18. package/dist/engine/core.d.ts +378 -11
  19. package/dist/engine/core.d.ts.map +1 -1
  20. package/dist/engine/core.js +1433 -13
  21. package/dist/engine/core.js.map +1 -1
  22. package/dist/engine/demo-story.d.ts.map +1 -1
  23. package/dist/engine/demo-story.js +103 -14
  24. package/dist/engine/demo-story.js.map +1 -1
  25. package/dist/engine/errors.d.ts +76 -0
  26. package/dist/engine/errors.d.ts.map +1 -0
  27. package/dist/engine/errors.js +178 -0
  28. package/dist/engine/errors.js.map +1 -0
  29. package/dist/engine/types.d.ts +445 -0
  30. package/dist/engine/types.d.ts.map +1 -0
  31. package/dist/engine/types.js +9 -0
  32. package/dist/engine/types.js.map +1 -0
  33. package/dist/engine/validation.d.ts +110 -0
  34. package/dist/engine/validation.d.ts.map +1 -0
  35. package/dist/engine/validation.js +261 -0
  36. package/dist/engine/validation.js.map +1 -0
  37. package/dist/examples/examples/autosave-undo-demo.js +248 -0
  38. package/dist/examples/examples/persistence-demo.js +63 -0
  39. package/dist/examples/src/engine/condition.js +194 -0
  40. package/dist/examples/src/engine/core.js +1382 -0
  41. package/dist/examples/src/engine/demo-story.js +200 -0
  42. package/dist/examples/src/engine/types.js +8 -0
  43. package/dist/examples/src/index.js +35 -0
  44. package/dist/examples/src/integrations/react.js +322 -0
  45. package/dist/examples/src/narrative/branching/engine-simple.js +348 -0
  46. package/dist/examples/src/narrative/branching/index.js +55 -0
  47. package/dist/examples/src/narrative/branching/models.js +5 -0
  48. package/dist/examples/src/performance/ObjectPool.js +296 -0
  49. package/dist/examples/src/performance/PerfReporter.js +280 -0
  50. package/dist/examples/src/performance/ThreadPool.js +347 -0
  51. package/dist/index.d.ts +4 -0
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +35 -3
  54. package/dist/index.js.map +1 -1
  55. package/dist/integrations/react.d.ts +200 -0
  56. package/dist/integrations/react.d.ts.map +1 -0
  57. package/dist/integrations/react.js +365 -0
  58. package/dist/integrations/react.js.map +1 -0
  59. package/dist/narrative/branching/engine-simple.d.ts +84 -0
  60. package/dist/narrative/branching/engine-simple.d.ts.map +1 -0
  61. package/dist/narrative/branching/engine-simple.js +349 -0
  62. package/dist/narrative/branching/engine-simple.js.map +1 -0
  63. package/dist/narrative/branching/engine.d.ts +1 -0
  64. package/dist/narrative/branching/engine.d.ts.map +1 -0
  65. package/dist/narrative/branching/engine.js +2 -0
  66. package/dist/narrative/branching/engine.js.map +1 -0
  67. package/dist/narrative/branching/index.d.ts +12 -0
  68. package/dist/narrative/branching/index.d.ts.map +1 -0
  69. package/dist/narrative/branching/index.js +56 -0
  70. package/dist/narrative/branching/index.js.map +1 -0
  71. package/dist/narrative/branching/models.d.ts +223 -0
  72. package/dist/narrative/branching/models.d.ts.map +1 -0
  73. package/dist/narrative/branching/models.js +6 -0
  74. package/dist/narrative/branching/models.js.map +1 -0
  75. package/dist/performance/HotReloadDelta.d.ts +124 -0
  76. package/dist/performance/HotReloadDelta.d.ts.map +1 -0
  77. package/dist/performance/HotReloadDelta.js +328 -0
  78. package/dist/performance/HotReloadDelta.js.map +1 -0
  79. package/dist/performance/ObjectPool.d.ts +150 -0
  80. package/dist/performance/ObjectPool.d.ts.map +1 -0
  81. package/dist/performance/ObjectPool.js +297 -0
  82. package/dist/performance/ObjectPool.js.map +1 -0
  83. package/dist/performance/PerfReporter.d.ts +123 -0
  84. package/dist/performance/PerfReporter.d.ts.map +1 -0
  85. package/dist/performance/PerfReporter.js +281 -0
  86. package/dist/performance/PerfReporter.js.map +1 -0
  87. package/dist/performance/ThreadPool.d.ts +107 -0
  88. package/dist/performance/ThreadPool.d.ts.map +1 -0
  89. package/dist/performance/ThreadPool.js +348 -0
  90. package/dist/performance/ThreadPool.js.map +1 -0
  91. package/dist/ui/__tests__/AutosaveIndicator.test.d.ts +2 -0
  92. package/dist/ui/__tests__/AutosaveIndicator.test.d.ts.map +1 -0
  93. package/dist/ui/__tests__/AutosaveIndicator.test.js +329 -0
  94. package/dist/ui/__tests__/AutosaveIndicator.test.js.map +1 -0
  95. package/dist/ui/__tests__/UndoRedoControls.test.d.ts +2 -0
  96. package/dist/ui/__tests__/UndoRedoControls.test.d.ts.map +1 -0
  97. package/dist/ui/__tests__/UndoRedoControls.test.js +245 -0
  98. package/dist/ui/__tests__/UndoRedoControls.test.js.map +1 -0
  99. package/dist/ui/__tests__/autosave-simple.test.d.ts +2 -0
  100. package/dist/ui/__tests__/autosave-simple.test.d.ts.map +1 -0
  101. package/dist/ui/__tests__/autosave-simple.test.js +29 -0
  102. package/dist/ui/__tests__/autosave-simple.test.js.map +1 -0
  103. package/dist/ui/__tests__/setup.d.ts +2 -0
  104. package/dist/ui/__tests__/setup.d.ts.map +1 -0
  105. package/dist/ui/__tests__/setup.js +40 -0
  106. package/dist/ui/__tests__/setup.js.map +1 -0
  107. package/dist/ui/__tests__/smoke-test.d.ts +2 -0
  108. package/dist/ui/__tests__/smoke-test.d.ts.map +1 -0
  109. package/dist/ui/__tests__/smoke-test.js +18 -0
  110. package/dist/ui/__tests__/smoke-test.js.map +1 -0
  111. package/dist/ui/__tests__/smoke-test.test.d.ts +2 -0
  112. package/dist/ui/__tests__/smoke-test.test.d.ts.map +1 -0
  113. package/dist/ui/__tests__/smoke-test.test.js +18 -0
  114. package/dist/ui/__tests__/smoke-test.test.js.map +1 -0
  115. package/dist/ui/__tests__/useKeyboardShortcuts.test.d.ts +2 -0
  116. package/dist/ui/__tests__/useKeyboardShortcuts.test.d.ts.map +1 -0
  117. package/dist/ui/__tests__/useKeyboardShortcuts.test.js +374 -0
  118. package/dist/ui/__tests__/useKeyboardShortcuts.test.js.map +1 -0
  119. package/dist/ui/components/AutosaveIndicator.d.ts +18 -0
  120. package/dist/ui/components/AutosaveIndicator.d.ts.map +1 -0
  121. package/dist/ui/components/AutosaveIndicator.js +175 -0
  122. package/dist/ui/components/AutosaveIndicator.js.map +1 -0
  123. package/dist/ui/components/UndoRedoControls.d.ts +16 -0
  124. package/dist/ui/components/UndoRedoControls.d.ts.map +1 -0
  125. package/dist/ui/components/UndoRedoControls.js +144 -0
  126. package/dist/ui/components/UndoRedoControls.js.map +1 -0
  127. package/dist/ui/hooks/useKeyboardShortcuts.d.ts +22 -0
  128. package/dist/ui/hooks/useKeyboardShortcuts.d.ts.map +1 -0
  129. package/dist/ui/hooks/useKeyboardShortcuts.js +162 -0
  130. package/dist/ui/hooks/useKeyboardShortcuts.js.map +1 -0
  131. package/dist/ui/index.d.ts +9 -0
  132. package/dist/ui/index.d.ts.map +1 -0
  133. package/dist/ui/index.js +14 -0
  134. package/dist/ui/index.js.map +1 -0
  135. package/dist/ui/types.d.ts +141 -0
  136. package/dist/ui/types.d.ts.map +1 -0
  137. package/dist/ui/types.js +51 -0
  138. package/dist/ui/types.js.map +1 -0
  139. package/docs/PERFORMANCE.md +355 -0
  140. package/docs/branching/ERD.md +214 -0
  141. package/docs/branching/PDM.md +443 -0
  142. package/docs/branching/RELEASE-v1.2.0.md +169 -0
  143. package/examples/autosave-undo-demo.ts +306 -0
  144. package/examples/branching-advanced-demo.ts +339 -0
  145. package/examples/branching-demo-simple.ts +0 -0
  146. package/examples/branching-demo.ts +0 -0
  147. package/examples/branching-quickstart.ts +314 -0
  148. package/examples/persistence-demo.ts +84 -0
  149. package/examples/quickstart-demo.js +82 -0
  150. package/examples/tsconfig.json +13 -0
  151. package/examples/ui-components-demo.tsx +320 -0
  152. package/examples/validation-demo-story.json +177 -0
  153. package/examples/validation-demo.js +163 -0
  154. package/package.json +41 -8
@@ -0,0 +1,141 @@
1
+ import { QNCEEngine } from '../engine/core';
2
+ /**
3
+ * Theme configuration for QNCE UI components
4
+ */
5
+ export interface QNCETheme {
6
+ colors: {
7
+ primary: string;
8
+ secondary: string;
9
+ success: string;
10
+ warning: string;
11
+ error: string;
12
+ disabled: string;
13
+ background: string;
14
+ surface: string;
15
+ text: string;
16
+ textSecondary: string;
17
+ };
18
+ spacing: {
19
+ xs: string;
20
+ sm: string;
21
+ md: string;
22
+ lg: string;
23
+ xl: string;
24
+ };
25
+ borderRadius: {
26
+ sm: string;
27
+ md: string;
28
+ lg: string;
29
+ };
30
+ typography: {
31
+ fontFamily: string;
32
+ fontSize: {
33
+ sm: string;
34
+ md: string;
35
+ lg: string;
36
+ };
37
+ fontWeight: {
38
+ normal: number;
39
+ medium: number;
40
+ semibold: number;
41
+ };
42
+ };
43
+ shadows: {
44
+ sm: string;
45
+ md: string;
46
+ lg: string;
47
+ };
48
+ }
49
+ /**
50
+ * Props for UndoRedoControls component
51
+ */
52
+ export interface UndoRedoControlsProps {
53
+ /** QNCE Engine instance */
54
+ engine: QNCEEngine;
55
+ /** Custom theme (optional, uses default if not provided) */
56
+ theme?: Partial<QNCETheme>;
57
+ /** Additional CSS class name */
58
+ className?: string;
59
+ /** Custom styling */
60
+ style?: React.CSSProperties;
61
+ /** Disable the controls */
62
+ disabled?: boolean;
63
+ /** Show labels on buttons */
64
+ showLabels?: boolean;
65
+ /** Custom button labels */
66
+ labels?: {
67
+ undo: string;
68
+ redo: string;
69
+ };
70
+ /** Button size variant */
71
+ size?: 'sm' | 'md' | 'lg';
72
+ /** Button layout */
73
+ layout?: 'horizontal' | 'vertical';
74
+ /** Callback when undo is performed */
75
+ onUndo?: (result: {
76
+ success: boolean;
77
+ description?: string;
78
+ error?: string;
79
+ }) => void;
80
+ /** Callback when redo is performed */
81
+ onRedo?: (result: {
82
+ success: boolean;
83
+ description?: string;
84
+ error?: string;
85
+ }) => void;
86
+ }
87
+ /**
88
+ * Autosave status
89
+ */
90
+ export type AutosaveStatus = 'idle' | 'saving' | 'saved' | 'error' | 'disabled';
91
+ /**
92
+ * Props for AutosaveIndicator component
93
+ */
94
+ export interface AutosaveIndicatorProps {
95
+ /** QNCE Engine instance */
96
+ engine: QNCEEngine;
97
+ /** Custom theme (optional, uses default if not provided) */
98
+ theme?: Partial<QNCETheme>;
99
+ /** Additional CSS class name */
100
+ className?: string;
101
+ /** Custom styling */
102
+ style?: React.CSSProperties;
103
+ /** Indicator variant */
104
+ variant?: 'minimal' | 'detailed' | 'icon-only';
105
+ /** Position of the indicator */
106
+ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'inline';
107
+ /** Custom status messages */
108
+ messages?: {
109
+ idle: string;
110
+ saving: string;
111
+ saved: string;
112
+ error: string;
113
+ };
114
+ /** Show timestamp of last save */
115
+ showTimestamp?: boolean;
116
+ /** Auto-hide after successful save (ms) */
117
+ autoHideDelay?: number;
118
+ }
119
+ /**
120
+ * Keyboard shortcuts configuration
121
+ */
122
+ export interface KeyboardShortcutsConfig {
123
+ /** Enable/disable keyboard shortcuts */
124
+ enabled?: boolean;
125
+ /** Custom key bindings */
126
+ bindings?: {
127
+ undo?: string[];
128
+ redo?: string[];
129
+ save?: string[];
130
+ reset?: string[];
131
+ };
132
+ /** Prevent default browser behavior */
133
+ preventDefault?: boolean;
134
+ /** Element to attach listeners to (defaults to document) */
135
+ target?: HTMLElement | Document;
136
+ }
137
+ /**
138
+ * Default theme for QNCE components
139
+ */
140
+ export declare const defaultTheme: QNCETheme;
141
+ //# sourceMappingURL=types.d.ts.map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AAgC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qBAAqB;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,wBAAwB;IACxB,OAAO,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC;IAC/C,gCAAgC;IAChC,QAAQ,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,aAAa,GAAG,cAAc,GAAG,QAAQ,CAAC;IAChF,6BAA6B;IAC7B,QAAQ,CAAC,EAAE;QACT,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,kCAAkC;IAClC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,2CAA2C;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,wCAAwC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;KAClB,CAAC;IACF,uCAAuC;IACvC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;CACjC;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,SA2C1B,CAAC"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultTheme = void 0;
4
+ /**
5
+ * Default theme for QNCE components
6
+ */
7
+ exports.defaultTheme = {
8
+ colors: {
9
+ primary: '#3b82f6',
10
+ secondary: '#6b7280',
11
+ success: '#10b981',
12
+ warning: '#f59e0b',
13
+ error: '#ef4444',
14
+ disabled: '#d1d5db',
15
+ background: '#ffffff',
16
+ surface: '#f9fafb',
17
+ text: '#111827',
18
+ textSecondary: '#6b7280'
19
+ },
20
+ spacing: {
21
+ xs: '0.25rem',
22
+ sm: '0.5rem',
23
+ md: '1rem',
24
+ lg: '1.5rem',
25
+ xl: '2rem'
26
+ },
27
+ borderRadius: {
28
+ sm: '0.25rem',
29
+ md: '0.375rem',
30
+ lg: '0.5rem'
31
+ },
32
+ typography: {
33
+ fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
34
+ fontSize: {
35
+ sm: '0.875rem',
36
+ md: '1rem',
37
+ lg: '1.125rem'
38
+ },
39
+ fontWeight: {
40
+ normal: 400,
41
+ medium: 500,
42
+ semibold: 600
43
+ }
44
+ },
45
+ shadows: {
46
+ sm: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
47
+ md: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
48
+ lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)'
49
+ }
50
+ };
51
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ui/types.ts"],"names":[],"mappings":";;;AAsIA;;GAEG;AACU,QAAA,YAAY,GAAc;IACrC,MAAM,EAAE;QACN,OAAO,EAAE,SAAS;QAClB,SAAS,EAAE,SAAS;QACpB,OAAO,EAAE,SAAS;QAClB,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE,SAAS;QAChB,QAAQ,EAAE,SAAS;QACnB,UAAU,EAAE,SAAS;QACrB,OAAO,EAAE,SAAS;QAClB,IAAI,EAAE,SAAS;QACf,aAAa,EAAE,SAAS;KACzB;IACD,OAAO,EAAE;QACP,EAAE,EAAE,SAAS;QACb,EAAE,EAAE,QAAQ;QACZ,EAAE,EAAE,MAAM;QACV,EAAE,EAAE,QAAQ;QACZ,EAAE,EAAE,MAAM;KACX;IACD,YAAY,EAAE;QACZ,EAAE,EAAE,SAAS;QACb,EAAE,EAAE,UAAU;QACd,EAAE,EAAE,QAAQ;KACb;IACD,UAAU,EAAE;QACV,UAAU,EAAE,4FAA4F;QACxG,QAAQ,EAAE;YACR,EAAE,EAAE,UAAU;YACd,EAAE,EAAE,MAAM;YACV,EAAE,EAAE,UAAU;SACf;QACD,UAAU,EAAE;YACV,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,GAAG;YACX,QAAQ,EAAE,GAAG;SACd;KACF;IACD,OAAO,EAAE;QACP,EAAE,EAAE,iCAAiC;QACrC,EAAE,EAAE,uEAAuE;QAC3E,EAAE,EAAE,yEAAyE;KAC9E;CACF,CAAC"}
@@ -0,0 +1,355 @@
1
+ # QNCE Performance Guide
2
+
3
+ **Version:** 1.2.0-sprint2
4
+ **Sprint #2:** Core Performance Refactor Complete
5
+
6
+ ## 🚀 Overview
7
+
8
+ The QNCE engine now includes comprehensive performance optimization infrastructure delivering:
9
+
10
+ - **90%+ allocation reduction** through object pooling
11
+ - **Background processing** via ThreadPool for non-blocking operations
12
+ - **Optimized hot-reload** with <3.5ms delta patching
13
+ - **Real-time profiling** with comprehensive event instrumentation
14
+ - **Live monitoring** via CLI dashboard with performance alerts
15
+
16
+ ## 📦 Performance Systems
17
+
18
+ ### 1. Object Pooling (S2-T1)
19
+
20
+ Eliminates garbage collection pressure through reusable object pools.
21
+
22
+ #### Basic Usage
23
+ ```typescript
24
+ import { createQNCEEngine } from 'qnce-engine';
25
+
26
+ // Enable performance mode for automatic object pooling
27
+ const engine = createQNCEEngine(storyData, initialState, true);
28
+
29
+ // Engine automatically uses pooled objects for:
30
+ // - Flow events and transitions
31
+ // - Node caching and retrieval
32
+ // - Asset management
33
+ ```
34
+
35
+ #### Pool Statistics
36
+ ```typescript
37
+ // Get pool performance metrics
38
+ const poolStats = engine.getPoolStats();
39
+ console.log('Pool efficiency:', poolStats.hitRate);
40
+ console.log('Memory savings:', poolStats.allocationReduction);
41
+ ```
42
+
43
+ ### 2. Background Processing (S2-T2)
44
+
45
+ Non-blocking operations via ThreadPool for cache preloading and telemetry.
46
+
47
+ #### Configuration
48
+ ```typescript
49
+ const threadPoolConfig = {
50
+ maxWorkers: 4, // Number of background workers
51
+ queueLimit: 1000, // Max pending jobs
52
+ idleTimeout: 30000, // Worker cleanup timeout (ms)
53
+ enableProfiling: true // Track job performance
54
+ };
55
+
56
+ const engine = createQNCEEngine(storyData, {}, true, threadPoolConfig);
57
+ ```
58
+
59
+ #### Background Operations
60
+ ```typescript
61
+ // Preload next nodes in background (automatic)
62
+ engine.selectChoice(choice); // Triggers background preloading
63
+
64
+ // Manual cache warming
65
+ await engine.warmCache(); // Preload entire story
66
+
67
+ // Background telemetry (automatic)
68
+ // Performance data written to background queue
69
+ ```
70
+
71
+ ### 3. Hot-Reload Delta Patching (S2-T3)
72
+
73
+ Live story updates with optimized field-level diffing.
74
+
75
+ #### API Usage
76
+ ```typescript
77
+ import { StoryDeltaComparator, StoryDeltaPatcher } from 'qnce-engine/performance';
78
+
79
+ // Compare story versions
80
+ const comparator = new StoryDeltaComparator();
81
+ const delta = comparator.compare(originalStory, updatedStory);
82
+
83
+ // Apply changes to running engine
84
+ const patcher = new StoryDeltaPatcher();
85
+ patcher.applyDelta(engine, delta); // <3.5ms typical performance
86
+ ```
87
+
88
+ #### Performance Targets
89
+ - **Comparison Time:** <1ms for field-level diffing
90
+ - **Patch Time:** <3.5ms for live story updates
91
+ - **Frame Stall:** Minimal impact on user experience
92
+ - **Safety:** Active node protection, graceful failure handling
93
+
94
+ ### 4. Performance Profiling (S2-T4)
95
+
96
+ Comprehensive event instrumentation with batched reporting.
97
+
98
+ #### Automatic Profiling
99
+ ```typescript
100
+ // Profiling enabled automatically in performance mode
101
+ const engine = createQNCEEngine(storyData, {}, true);
102
+
103
+ // All operations tracked:
104
+ // - State transitions
105
+ // - Cache operations
106
+ // - Hot-reload performance
107
+ // - Background job processing
108
+ ```
109
+
110
+ #### Custom Events
111
+ ```typescript
112
+ import { perf } from 'qnce-engine/performance';
113
+
114
+ // Record custom performance events
115
+ perf.record('custom', {
116
+ eventType: 'user-action',
117
+ duration: 123,
118
+ metadata: { action: 'save' }
119
+ });
120
+
121
+ // Flow tracking
122
+ const spanId = perf.flowStart('my-flow', { context: 'gameplay' });
123
+ // ... operations ...
124
+ perf.flowComplete(spanId, 'target-node', { result: 'success' });
125
+ ```
126
+
127
+ ## 🖥️ CLI Performance Dashboard
128
+
129
+ Real-time monitoring and performance analysis via `qnce-perf` command.
130
+
131
+ ### Installation
132
+ ```bash
133
+ npm install -g qnce-engine
134
+ ```
135
+
136
+ ### Dashboard Commands
137
+
138
+ #### Real-time Dashboard
139
+ ```bash
140
+ qnce-perf dashboard
141
+ ```
142
+ ```
143
+ 🚀 QNCE Performance Dashboard
144
+ =====================================
145
+ 📊 Session Duration: 45.2s
146
+ 🔢 Total Events: 234
147
+
148
+ 📈 Event Breakdown:
149
+ state-transition 45 events (avg: 2.1ms, max: 4.2ms)
150
+ cache-hit 89 events (avg: 0.8ms, max: 1.5ms)
151
+ hot-reload-start 3 events (avg: 2.8ms, max: 3.1ms)
152
+
153
+ 💾 Cache Performance:
154
+ ✅ Hit Rate: 92.4% (threshold: 80%)
155
+ ✅ Avg Cache Time: 8.2ms (threshold: 50ms)
156
+
157
+ 🔥 Hot-Reload Performance:
158
+ ✅ Avg Time: 2.8ms (threshold: 3.5ms)
159
+ 📊 Max Time: 3.1ms
160
+ 🔄 Total Reloads: 3
161
+
162
+ 🧵 ThreadPool Status:
163
+ 📊 Completed Jobs: 156
164
+ ⏳ Queued Jobs: 4
165
+ 🏃 Active Workers: 2
166
+ 📈 Worker Utilization: 73.2%
167
+
168
+ 🚨 Performance Alerts:
169
+ ✅ All systems performing within thresholds
170
+ ```
171
+
172
+ #### Live Monitoring
173
+ ```bash
174
+ qnce-perf live 1000 # Update every 1000ms
175
+ ```
176
+
177
+ #### Export Data
178
+ ```bash
179
+ qnce-perf export > performance-report.json
180
+ ```
181
+
182
+ #### Reset Counters
183
+ ```bash
184
+ qnce-perf reset
185
+ ```
186
+
187
+ ### Performance Thresholds
188
+
189
+ The dashboard monitors key performance indicators:
190
+
191
+ | Metric | Threshold | Alert Level |
192
+ |--------|-----------|-------------|
193
+ | Cache Hit Rate | >80% | ⚠️ Warning if below |
194
+ | Cache Response Time | <50ms | ⚠️ Warning if above |
195
+ | Hot-Reload Time | <3.5ms | ⚠️ Warning if above |
196
+ | State Transition Time | <10ms | ⚠️ Warning if above |
197
+ | ThreadPool Queue | <100 jobs | ⚠️ Warning if above |
198
+
199
+ ## 🔧 Configuration Examples
200
+
201
+ ### High-Performance Setup
202
+ ```typescript
203
+ const engine = createQNCEEngine(storyData, initialState, true, {
204
+ maxWorkers: 8, // High concurrency
205
+ queueLimit: 2000, // Large job queue
206
+ idleTimeout: 60000, // Keep workers alive
207
+ enableProfiling: true // Full instrumentation
208
+ });
209
+
210
+ // Warm entire story cache
211
+ await engine.warmCache();
212
+ ```
213
+
214
+ ### Memory-Constrained Setup
215
+ ```typescript
216
+ const engine = createQNCEEngine(storyData, initialState, true, {
217
+ maxWorkers: 2, // Minimal workers
218
+ queueLimit: 100, // Small queue
219
+ idleTimeout: 10000, // Quick cleanup
220
+ enableProfiling: false // Reduce overhead
221
+ });
222
+ ```
223
+
224
+ ### Development/Debug Setup
225
+ ```typescript
226
+ const engine = createQNCEEngine(storyData, initialState, true, {
227
+ maxWorkers: 1, // Single worker
228
+ queueLimit: 50, // Small queue
229
+ idleTimeout: 5000, // Fast cleanup
230
+ enableProfiling: true // Full debugging
231
+ });
232
+
233
+ // Monitor in real-time
234
+ // Run: qnce-perf live 500
235
+ ```
236
+
237
+ ## 📊 Performance Benchmarks
238
+
239
+ ### Sprint #2 Achievements
240
+
241
+ | System | Before | After | Improvement |
242
+ |--------|--------|-------|-------------|
243
+ | Object Allocation | Baseline | 90%+ reduction | Major |
244
+ | Hot-Reload Time | ~10ms | 2.8-3.5ms | 65-72% |
245
+ | Memory Usage | High GC pressure | Stable pools | Significant |
246
+ | Background Ops | Blocking | Non-blocking | Complete |
247
+ | Monitoring | None | Real-time CLI | New capability |
248
+
249
+ ### Typical Performance Profile
250
+ ```
251
+ Engine Creation: <5ms
252
+ Node Navigation: <1ms per transition
253
+ Hot-Reload: <3.5ms for story updates
254
+ Cache Operations: <1ms with 90%+ hit rate
255
+ Background Jobs: Queue processing without main thread impact
256
+ ```
257
+
258
+ ## 🚨 Troubleshooting
259
+
260
+ ### Common Issues
261
+
262
+ #### Hot-Reload Performance
263
+ ```bash
264
+ # Check current performance
265
+ qnce-perf dashboard
266
+
267
+ # Look for hot-reload metrics
268
+ # Target: <3.5ms average
269
+ # If higher, check story size and complexity
270
+ ```
271
+
272
+ #### ThreadPool Queue Overload
273
+ ```bash
274
+ # Monitor queue depth
275
+ qnce-perf live
276
+
277
+ # If queue depth consistently >100:
278
+ # 1. Increase maxWorkers
279
+ # 2. Increase queueLimit
280
+ # 3. Reduce background operation frequency
281
+ ```
282
+
283
+ #### Memory Usage
284
+ ```bash
285
+ # Check object pool efficiency
286
+ const stats = engine.getPoolStats();
287
+ console.log('Hit rate:', stats.hitRate); // Should be >90%
288
+
289
+ # If low hit rate:
290
+ # 1. Verify performance mode enabled
291
+ # 2. Check for proper object return patterns
292
+ ```
293
+
294
+ ### Performance Debugging
295
+
296
+ ```typescript
297
+ // Enable comprehensive logging
298
+ import { getPerfReporter } from 'qnce-engine/performance';
299
+
300
+ const reporter = getPerfReporter();
301
+ reporter.config.enableConsoleOutput = true;
302
+
303
+ // All performance events now logged to console
304
+ ```
305
+
306
+ ## 🎯 Best Practices
307
+
308
+ ### 1. Enable Performance Mode
309
+ Always use performance mode for production:
310
+ ```typescript
311
+ const engine = createQNCEEngine(storyData, {}, true); // ✅ Good
312
+ const engine = createQNCEEngine(storyData, {}, false); // ❌ Avoid in production
313
+ ```
314
+
315
+ ### 2. Configure ThreadPool Appropriately
316
+ Match worker count to system capabilities:
317
+ ```typescript
318
+ const workers = Math.min(navigator.hardwareConcurrency || 4, 8);
319
+ const config = { maxWorkers: workers };
320
+ ```
321
+
322
+ ### 3. Monitor Performance Continuously
323
+ Use live monitoring during development:
324
+ ```bash
325
+ # Terminal 1: Development server
326
+ npm run dev
327
+
328
+ # Terminal 2: Performance monitoring
329
+ qnce-perf live 2000
330
+ ```
331
+
332
+ ### 4. Preload Strategically
333
+ ```typescript
334
+ // Preload next probable nodes
335
+ engine.selectChoice(choice); // Auto-preloads next nodes
336
+
337
+ // Full cache warming for small stories
338
+ if (storyData.nodes.length < 100) {
339
+ await engine.warmCache();
340
+ }
341
+ ```
342
+
343
+ ### 5. Handle Performance Degradation
344
+ ```typescript
345
+ // Monitor for performance issues
346
+ const summary = perf.summary();
347
+ if (summary.cacheHitRate < 0.8) {
348
+ console.warn('Cache performance degraded');
349
+ // Consider cache warming or configuration adjustment
350
+ }
351
+ ```
352
+
353
+ ---
354
+
355
+ **Ready for Production:** QNCE v1.2.0-sprint2 delivers comprehensive performance optimization with real-time monitoring capabilities. All systems tested and production-ready! 🚀