gthinking 1.3.0 → 2.1.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 (271) hide show
  1. package/.eslintrc.js +34 -0
  2. package/ANALYSIS_SUMMARY.md +363 -0
  3. package/README.md +230 -250
  4. package/dist/analysis/analysis-engine.d.ts +63 -0
  5. package/dist/analysis/analysis-engine.d.ts.map +1 -0
  6. package/dist/analysis/analysis-engine.js +322 -0
  7. package/dist/analysis/analysis-engine.js.map +1 -0
  8. package/dist/core/config.d.ts +1419 -0
  9. package/dist/core/config.d.ts.map +1 -0
  10. package/dist/core/config.js +361 -0
  11. package/dist/core/config.js.map +1 -0
  12. package/dist/core/engine.d.ts +176 -0
  13. package/dist/core/engine.d.ts.map +1 -0
  14. package/dist/core/engine.js +604 -0
  15. package/dist/core/engine.js.map +1 -0
  16. package/dist/core/errors.d.ts +153 -0
  17. package/dist/core/errors.d.ts.map +1 -0
  18. package/dist/core/errors.js +287 -0
  19. package/dist/core/errors.js.map +1 -0
  20. package/dist/core/index.d.ts +7 -0
  21. package/dist/core/index.d.ts.map +1 -0
  22. package/dist/{types.js → core/index.js} +8 -4
  23. package/dist/core/index.js.map +1 -0
  24. package/dist/core/pipeline.d.ts +121 -0
  25. package/dist/core/pipeline.d.ts.map +1 -0
  26. package/dist/core/pipeline.js +289 -0
  27. package/dist/core/pipeline.js.map +1 -0
  28. package/dist/core/rate-limiter.d.ts +58 -0
  29. package/dist/core/rate-limiter.d.ts.map +1 -0
  30. package/dist/core/rate-limiter.js +133 -0
  31. package/dist/core/rate-limiter.js.map +1 -0
  32. package/dist/core/session-manager.d.ts +96 -0
  33. package/dist/core/session-manager.d.ts.map +1 -0
  34. package/dist/core/session-manager.js +223 -0
  35. package/dist/core/session-manager.js.map +1 -0
  36. package/dist/creativity/creativity-engine.d.ts +6 -0
  37. package/dist/creativity/creativity-engine.d.ts.map +1 -0
  38. package/dist/creativity/creativity-engine.js +17 -0
  39. package/dist/creativity/creativity-engine.js.map +1 -0
  40. package/dist/index.d.ts +24 -32
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +130 -104
  43. package/dist/index.js.map +1 -1
  44. package/dist/learning/learning-engine.d.ts +6 -0
  45. package/dist/learning/learning-engine.d.ts.map +1 -0
  46. package/dist/learning/learning-engine.js +17 -0
  47. package/dist/learning/learning-engine.js.map +1 -0
  48. package/dist/llm/index.d.ts +10 -0
  49. package/dist/llm/index.d.ts.map +1 -0
  50. package/dist/llm/index.js +26 -0
  51. package/dist/llm/index.js.map +1 -0
  52. package/dist/llm/llm-service.d.ts +109 -0
  53. package/dist/llm/llm-service.d.ts.map +1 -0
  54. package/dist/llm/llm-service.js +224 -0
  55. package/dist/llm/llm-service.js.map +1 -0
  56. package/dist/llm/providers/base.d.ts +85 -0
  57. package/dist/llm/providers/base.d.ts.map +1 -0
  58. package/dist/llm/providers/base.js +57 -0
  59. package/dist/llm/providers/base.js.map +1 -0
  60. package/dist/llm/providers/cli.d.ts +23 -0
  61. package/dist/llm/providers/cli.d.ts.map +1 -0
  62. package/dist/llm/providers/cli.js +158 -0
  63. package/dist/llm/providers/cli.js.map +1 -0
  64. package/dist/llm/providers/gemini.d.ts +30 -0
  65. package/dist/llm/providers/gemini.d.ts.map +1 -0
  66. package/dist/llm/providers/gemini.js +168 -0
  67. package/dist/llm/providers/gemini.js.map +1 -0
  68. package/dist/llm/sanitization.d.ts +50 -0
  69. package/dist/llm/sanitization.d.ts.map +1 -0
  70. package/dist/llm/sanitization.js +149 -0
  71. package/dist/llm/sanitization.js.map +1 -0
  72. package/dist/{server.d.ts.map → mcp/server.d.ts.map} +1 -1
  73. package/dist/mcp/server.js +108 -0
  74. package/dist/mcp/server.js.map +1 -0
  75. package/dist/planning/planning-engine.d.ts +6 -0
  76. package/dist/planning/planning-engine.d.ts.map +1 -0
  77. package/dist/planning/planning-engine.js +17 -0
  78. package/dist/planning/planning-engine.js.map +1 -0
  79. package/dist/reasoning/reasoning-engine.d.ts +6 -0
  80. package/dist/reasoning/reasoning-engine.d.ts.map +1 -0
  81. package/dist/reasoning/reasoning-engine.js +17 -0
  82. package/dist/reasoning/reasoning-engine.js.map +1 -0
  83. package/dist/search/search-engine.d.ts +99 -0
  84. package/dist/search/search-engine.d.ts.map +1 -0
  85. package/dist/search/search-engine.js +271 -0
  86. package/dist/search/search-engine.js.map +1 -0
  87. package/dist/synthesis/synthesis-engine.d.ts +6 -0
  88. package/dist/synthesis/synthesis-engine.d.ts.map +1 -0
  89. package/dist/synthesis/synthesis-engine.js +17 -0
  90. package/dist/synthesis/synthesis-engine.js.map +1 -0
  91. package/dist/types/analysis.d.ts +1534 -49
  92. package/dist/types/analysis.d.ts.map +1 -1
  93. package/dist/types/analysis.js +250 -0
  94. package/dist/types/analysis.js.map +1 -1
  95. package/dist/types/core.d.ts +257 -30
  96. package/dist/types/core.d.ts.map +1 -1
  97. package/dist/types/core.js +148 -18
  98. package/dist/types/core.js.map +1 -1
  99. package/dist/types/creativity.d.ts +2871 -56
  100. package/dist/types/creativity.d.ts.map +1 -1
  101. package/dist/types/creativity.js +195 -0
  102. package/dist/types/creativity.js.map +1 -1
  103. package/dist/types/index.d.ts +6 -2
  104. package/dist/types/index.d.ts.map +1 -1
  105. package/dist/types/index.js +17 -2
  106. package/dist/types/index.js.map +1 -1
  107. package/dist/types/learning.d.ts +851 -61
  108. package/dist/types/learning.d.ts.map +1 -1
  109. package/dist/types/learning.js +155 -0
  110. package/dist/types/learning.js.map +1 -1
  111. package/dist/types/planning.d.ts +2223 -71
  112. package/dist/types/planning.d.ts.map +1 -1
  113. package/dist/types/planning.js +190 -0
  114. package/dist/types/planning.js.map +1 -1
  115. package/dist/types/reasoning.d.ts +2209 -72
  116. package/dist/types/reasoning.d.ts.map +1 -1
  117. package/dist/types/reasoning.js +200 -1
  118. package/dist/types/reasoning.js.map +1 -1
  119. package/dist/types/search.d.ts +981 -53
  120. package/dist/types/search.d.ts.map +1 -1
  121. package/dist/types/search.js +137 -0
  122. package/dist/types/search.js.map +1 -1
  123. package/dist/types/synthesis.d.ts +583 -38
  124. package/dist/types/synthesis.d.ts.map +1 -1
  125. package/dist/types/synthesis.js +138 -0
  126. package/dist/types/synthesis.js.map +1 -1
  127. package/dist/utils/cache.d.ts +144 -0
  128. package/dist/utils/cache.d.ts.map +1 -0
  129. package/dist/utils/cache.js +288 -0
  130. package/dist/utils/cache.js.map +1 -0
  131. package/dist/utils/id-generator.d.ts +89 -0
  132. package/dist/utils/id-generator.d.ts.map +1 -0
  133. package/dist/utils/id-generator.js +132 -0
  134. package/dist/utils/id-generator.js.map +1 -0
  135. package/dist/utils/index.d.ts +11 -0
  136. package/dist/utils/index.d.ts.map +1 -0
  137. package/dist/utils/index.js +33 -0
  138. package/dist/utils/index.js.map +1 -0
  139. package/dist/utils/logger.d.ts +142 -0
  140. package/dist/utils/logger.d.ts.map +1 -0
  141. package/dist/utils/logger.js +248 -0
  142. package/dist/utils/logger.js.map +1 -0
  143. package/dist/utils/metrics.d.ts +149 -0
  144. package/dist/utils/metrics.d.ts.map +1 -0
  145. package/dist/utils/metrics.js +296 -0
  146. package/dist/utils/metrics.js.map +1 -0
  147. package/dist/utils/timer.d.ts +7 -0
  148. package/dist/utils/timer.d.ts.map +1 -0
  149. package/dist/utils/timer.js +17 -0
  150. package/dist/utils/timer.js.map +1 -0
  151. package/dist/utils/validation.d.ts +147 -0
  152. package/dist/utils/validation.d.ts.map +1 -0
  153. package/dist/utils/validation.js +275 -0
  154. package/dist/utils/validation.js.map +1 -0
  155. package/docs/API.md +411 -0
  156. package/docs/ARCHITECTURE.md +271 -0
  157. package/docs/CHANGELOG.md +283 -0
  158. package/jest.config.js +28 -0
  159. package/package.json +43 -30
  160. package/src/analysis/analysis-engine.ts +383 -0
  161. package/src/core/config.ts +406 -0
  162. package/src/core/engine.ts +785 -0
  163. package/src/core/errors.ts +349 -0
  164. package/src/core/index.ts +12 -0
  165. package/src/core/pipeline.ts +424 -0
  166. package/src/core/rate-limiter.ts +155 -0
  167. package/src/core/session-manager.ts +269 -0
  168. package/src/creativity/creativity-engine.ts +14 -0
  169. package/src/index.ts +178 -0
  170. package/src/learning/learning-engine.ts +14 -0
  171. package/src/llm/index.ts +10 -0
  172. package/src/llm/llm-service.ts +285 -0
  173. package/src/llm/providers/base.ts +146 -0
  174. package/src/llm/providers/cli.ts +186 -0
  175. package/src/llm/providers/gemini.ts +201 -0
  176. package/src/llm/sanitization.ts +178 -0
  177. package/src/mcp/server.ts +117 -0
  178. package/src/planning/planning-engine.ts +14 -0
  179. package/src/reasoning/reasoning-engine.ts +14 -0
  180. package/src/search/search-engine.ts +333 -0
  181. package/src/synthesis/synthesis-engine.ts +14 -0
  182. package/src/types/analysis.ts +337 -0
  183. package/src/types/core.ts +342 -0
  184. package/src/types/creativity.ts +268 -0
  185. package/src/types/index.ts +31 -0
  186. package/src/types/learning.ts +215 -0
  187. package/src/types/planning.ts +251 -0
  188. package/src/types/reasoning.ts +288 -0
  189. package/src/types/search.ts +192 -0
  190. package/src/types/synthesis.ts +187 -0
  191. package/src/utils/cache.ts +363 -0
  192. package/src/utils/id-generator.ts +135 -0
  193. package/src/utils/index.ts +22 -0
  194. package/src/utils/logger.ts +290 -0
  195. package/src/utils/metrics.ts +380 -0
  196. package/src/utils/timer.ts +15 -0
  197. package/src/utils/validation.ts +297 -0
  198. package/tests/setup.ts +22 -0
  199. package/tests/unit/cache.test.ts +189 -0
  200. package/tests/unit/engine.test.ts +179 -0
  201. package/tests/unit/validation.test.ts +218 -0
  202. package/tsconfig.json +17 -12
  203. package/GEMINI.md +0 -68
  204. package/analysis.ts +0 -1063
  205. package/creativity.ts +0 -1055
  206. package/dist/analysis.d.ts +0 -54
  207. package/dist/analysis.d.ts.map +0 -1
  208. package/dist/analysis.js +0 -866
  209. package/dist/analysis.js.map +0 -1
  210. package/dist/creativity.d.ts +0 -81
  211. package/dist/creativity.d.ts.map +0 -1
  212. package/dist/creativity.js +0 -828
  213. package/dist/creativity.js.map +0 -1
  214. package/dist/engine.d.ts +0 -90
  215. package/dist/engine.d.ts.map +0 -1
  216. package/dist/engine.js +0 -720
  217. package/dist/engine.js.map +0 -1
  218. package/dist/examples.d.ts +0 -7
  219. package/dist/examples.d.ts.map +0 -1
  220. package/dist/examples.js +0 -506
  221. package/dist/examples.js.map +0 -1
  222. package/dist/learning.d.ts +0 -72
  223. package/dist/learning.d.ts.map +0 -1
  224. package/dist/learning.js +0 -615
  225. package/dist/learning.js.map +0 -1
  226. package/dist/llm-service.d.ts +0 -21
  227. package/dist/llm-service.d.ts.map +0 -1
  228. package/dist/llm-service.js +0 -100
  229. package/dist/llm-service.js.map +0 -1
  230. package/dist/planning.d.ts +0 -62
  231. package/dist/planning.d.ts.map +0 -1
  232. package/dist/planning.js +0 -886
  233. package/dist/planning.js.map +0 -1
  234. package/dist/reasoning.d.ts +0 -73
  235. package/dist/reasoning.d.ts.map +0 -1
  236. package/dist/reasoning.js +0 -845
  237. package/dist/reasoning.js.map +0 -1
  238. package/dist/search-discovery.d.ts +0 -73
  239. package/dist/search-discovery.d.ts.map +0 -1
  240. package/dist/search-discovery.js +0 -548
  241. package/dist/search-discovery.js.map +0 -1
  242. package/dist/server.js +0 -113
  243. package/dist/server.js.map +0 -1
  244. package/dist/types/engine.d.ts +0 -55
  245. package/dist/types/engine.d.ts.map +0 -1
  246. package/dist/types/engine.js +0 -3
  247. package/dist/types/engine.js.map +0 -1
  248. package/dist/types.d.ts +0 -6
  249. package/dist/types.d.ts.map +0 -1
  250. package/dist/types.js.map +0 -1
  251. package/engine.ts +0 -1009
  252. package/examples.ts +0 -717
  253. package/index.ts +0 -106
  254. package/learning.ts +0 -779
  255. package/llm-service.ts +0 -120
  256. package/planning.ts +0 -1101
  257. package/reasoning.ts +0 -1079
  258. package/search-discovery.ts +0 -700
  259. package/server.ts +0 -115
  260. package/types/analysis.ts +0 -69
  261. package/types/core.ts +0 -90
  262. package/types/creativity.ts +0 -72
  263. package/types/engine.ts +0 -60
  264. package/types/index.ts +0 -9
  265. package/types/learning.ts +0 -69
  266. package/types/planning.ts +0 -85
  267. package/types/reasoning.ts +0 -92
  268. package/types/search.ts +0 -58
  269. package/types/synthesis.ts +0 -43
  270. package/types.ts +0 -6
  271. /package/dist/{server.d.ts → mcp/server.d.ts} +0 -0
@@ -1,828 +0,0 @@
1
- "use strict";
2
- /**
3
- * Creativity Module
4
- * Out-of-the-box thinking, idea generation, and concept connection
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.creativityEngine = exports.CreativityEngine = void 0;
8
- const types_1 = require("./types");
9
- const events_1 = require("events");
10
- const llm_service_1 = require("./llm-service");
11
- // ============================================================================
12
- // BRAINSTORMING ENGINE
13
- // ============================================================================
14
- class BrainstormingEngine {
15
- constructor() {
16
- this.ideaSeeds = new Map([
17
- ['technology', ['AI', 'blockchain', 'IoT', 'cloud', 'quantum', 'biotech', 'nanotech']],
18
- ['business', ['subscription', 'freemium', 'marketplace', 'platform', 'ecosystem']],
19
- ['social', ['community', 'collaboration', 'sharing', 'crowdsourcing', 'network']],
20
- ['design', ['minimalist', 'responsive', 'adaptive', 'personalized', 'immersive']]
21
- ]);
22
- }
23
- generateIdeas(prompt, count = 10) {
24
- const ideas = [];
25
- const domains = this.identifyDomains(prompt);
26
- // Generate ideas using different approaches
27
- for (let i = 0; i < count; i++) {
28
- const technique = this.selectTechnique(i);
29
- const idea = this.createIdea(prompt, technique, domains, i);
30
- ideas.push(idea);
31
- }
32
- return ideas;
33
- }
34
- identifyDomains(prompt) {
35
- const domains = [];
36
- const promptLower = prompt.toLowerCase();
37
- this.ideaSeeds.forEach((_, domain) => {
38
- if (promptLower.includes(domain)) {
39
- domains.push(domain);
40
- }
41
- });
42
- return domains.length > 0 ? domains : ['general'];
43
- }
44
- selectTechnique(index) {
45
- const techniques = [
46
- 'brainstorming',
47
- 'analogy',
48
- 'reverse_thinking',
49
- 'random_stimulus',
50
- 'lateral_thinking'
51
- ];
52
- return techniques[index % techniques.length];
53
- }
54
- createIdea(prompt, technique, domains, index) {
55
- const content = this.generateIdeaContent(prompt, technique, domains, index);
56
- return {
57
- id: `idea_${Date.now()}_${index}`,
58
- content,
59
- technique,
60
- novelty: this.calculateNovelity(content),
61
- feasibility: this.calculateFeasibility(content),
62
- impact: this.calculateImpact(content),
63
- relatedIdeas: [],
64
- tags: this.extractTags(content),
65
- generatedAt: new Date()
66
- };
67
- }
68
- generateIdeaContent(prompt, technique, domains, index) {
69
- switch (technique) {
70
- case 'brainstorming':
71
- return this.brainstorm(prompt, domains, index);
72
- case 'analogy':
73
- return this.useAnalogy(prompt, domains, index);
74
- case 'reverse_thinking':
75
- return this.reverseThink(prompt);
76
- case 'random_stimulus':
77
- return this.randomStimulus(prompt, domains);
78
- case 'lateral_thinking':
79
- return this.lateralThink(prompt, index);
80
- default:
81
- return `Idea ${index + 1}: ${prompt}`;
82
- }
83
- }
84
- brainstorm(prompt, domains, index) {
85
- const domain = domains[index % domains.length];
86
- const seeds = this.ideaSeeds.get(domain) || ['innovation'];
87
- const seed = seeds[index % seeds.length];
88
- return `Combine ${prompt} with ${seed} to create a ${domain} solution`;
89
- }
90
- useAnalogy(prompt, domains, index) {
91
- const analogies = [
92
- 'like a nervous system for information flow',
93
- 'like an immune system for security',
94
- 'like an ecosystem for sustainability',
95
- 'like a language for communication',
96
- 'like a market for resource allocation'
97
- ];
98
- return `Approach ${prompt} ${analogies[index % analogies.length]}`;
99
- }
100
- reverseThink(prompt) {
101
- return `Instead of ${prompt}, what if we did the opposite? ` +
102
- `Consider: How could we achieve the inverse outcome?`;
103
- }
104
- randomStimulus(prompt, domains) {
105
- const stimuli = ['nature', 'art', 'music', 'sports', 'cooking', 'architecture'];
106
- const stimulus = stimuli[Math.floor(Math.random() * stimuli.length)];
107
- return `Apply principles from ${stimulus} to ${prompt}`;
108
- }
109
- lateralThink(prompt, index) {
110
- const perspectives = [
111
- 'from a child\'s perspective',
112
- 'from a future perspective (10 years ahead)',
113
- 'from a resource-constrained perspective',
114
- 'from a luxury perspective',
115
- 'from a minimalist perspective'
116
- ];
117
- return `View ${prompt} ${perspectives[index % perspectives.length]}`;
118
- }
119
- calculateNovelity(content) {
120
- // Higher novelty for more unique combinations
121
- const uniqueTerms = new Set(content.toLowerCase().split(/\s+/)).size;
122
- const totalTerms = content.split(/\s+/).length;
123
- return Math.min(0.95, uniqueTerms / totalTerms + 0.3);
124
- }
125
- calculateFeasibility(content) {
126
- // Lower feasibility for very abstract ideas
127
- const abstractTerms = ['quantum', 'neural', 'blockchain', 'revolutionary', 'paradigm'];
128
- const abstractCount = abstractTerms.filter(term => content.toLowerCase().includes(term)).length;
129
- return Math.max(0.3, 0.9 - abstractCount * 0.1);
130
- }
131
- calculateImpact(content) {
132
- // Higher impact for ideas addressing broad audiences or major problems
133
- const impactIndicators = ['global', 'scalable', 'transform', 'revolutionary', 'fundamental'];
134
- const matches = impactIndicators.filter(ind => content.toLowerCase().includes(ind)).length;
135
- return Math.min(0.95, 0.5 + matches * 0.1);
136
- }
137
- extractTags(content) {
138
- return content
139
- .toLowerCase()
140
- .match(/\b\w{5,}\b/g)
141
- ?.filter((w, i, arr) => arr.indexOf(w) === i)
142
- ?.slice(0, 5) || [];
143
- }
144
- }
145
- class MindMappingEngine {
146
- createMindMap(centerConcept, depth = 3) {
147
- const root = {
148
- id: 'root',
149
- label: centerConcept,
150
- children: [],
151
- connections: []
152
- };
153
- this.expandNode(root, depth, 0);
154
- return root;
155
- }
156
- expandNode(node, maxDepth, currentDepth) {
157
- if (currentDepth >= maxDepth)
158
- return;
159
- const branches = this.generateBranches(node.label, currentDepth);
160
- branches.forEach(branchLabel => {
161
- const child = {
162
- id: `node_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`,
163
- label: branchLabel,
164
- children: [],
165
- connections: []
166
- };
167
- node.children.push(child);
168
- this.expandNode(child, maxDepth, currentDepth + 1);
169
- });
170
- }
171
- generateBranches(concept, depth) {
172
- const branchTypes = {
173
- 0: [['What', 'Why', 'How', 'When', 'Where']],
174
- 1: [['Components', 'Features', 'Benefits', 'Challenges']],
175
- 2: [['Examples', 'Alternatives', 'Applications', 'Implications']]
176
- };
177
- const branches = branchTypes[depth] || [['Details', 'Related', 'Future']];
178
- const selectedBranch = branches[0];
179
- return selectedBranch.map(b => `${b} of ${concept}`);
180
- }
181
- findConnections(node1, node2) {
182
- const connections = [];
183
- const concepts1 = this.extractAllConcepts(node1);
184
- const concepts2 = this.extractAllConcepts(node2);
185
- concepts1.forEach(c1 => {
186
- concepts2.forEach(c2 => {
187
- const similarity = this.calculateConceptSimilarity(c1, c2);
188
- if (similarity > 0.5) {
189
- connections.push(`Connection: ${c1} ↔ ${c2}`);
190
- }
191
- });
192
- });
193
- return connections;
194
- }
195
- extractAllConcepts(node) {
196
- const concepts = [node.label];
197
- node.children.forEach(child => {
198
- concepts.push(...this.extractAllConcepts(child));
199
- });
200
- return concepts;
201
- }
202
- calculateConceptSimilarity(c1, c2) {
203
- const words1 = c1.toLowerCase().split(/\s+/);
204
- const words2 = c2.toLowerCase().split(/\s+/);
205
- const intersection = words1.filter(w => words2.includes(w));
206
- return intersection.length / Math.max(words1.length, words2.length);
207
- }
208
- }
209
- class ScamperEngine {
210
- constructor() {
211
- this.scamperPrompts = [
212
- { letter: 'S', action: 'Substitute', prompt: 'What can be substituted?' },
213
- { letter: 'C', action: 'Combine', prompt: 'What can be combined?' },
214
- { letter: 'A', action: 'Adapt', prompt: 'What can be adapted?' },
215
- { letter: 'M', action: 'Modify', prompt: 'What can be modified?' },
216
- { letter: 'P', action: 'Put to other uses', prompt: 'What other uses are possible?' },
217
- { letter: 'E', action: 'Eliminate', prompt: 'What can be eliminated?' },
218
- { letter: 'R', action: 'Reverse/Rearrange', prompt: 'What can be reversed or rearranged?' }
219
- ];
220
- }
221
- apply(problem) {
222
- return this.scamperPrompts.map(prompt => ({
223
- technique: `${prompt.letter} - ${prompt.action}`,
224
- question: prompt.prompt,
225
- idea: this.generateScamperIdea(problem, prompt)
226
- }));
227
- }
228
- generateScamperIdea(problem, prompt) {
229
- const ideaTemplates = {
230
- 'Substitute': [
231
- `Replace a key component of ${problem} with something unexpected`,
232
- `Use alternative materials or methods for ${problem}`
233
- ],
234
- 'Combine': [
235
- `Merge ${problem} with a completely different concept`,
236
- `Integrate multiple versions of ${problem}`
237
- ],
238
- 'Adapt': [
239
- `Apply ${problem} in a different context`,
240
- `Borrow ideas from other fields for ${problem}`
241
- ],
242
- 'Modify': [
243
- `Change the scale or magnitude of ${problem}`,
244
- `Alter the attributes of ${problem}`
245
- ],
246
- 'Put to other uses': [
247
- `How else could ${problem} be used?`,
248
- `Who else could benefit from ${problem}?`
249
- ],
250
- 'Eliminate': [
251
- `Remove unnecessary parts of ${problem}`,
252
- `Simplify ${problem} to its essence`
253
- ],
254
- 'Reverse/Rearrange': [
255
- `Do the opposite of ${problem}`,
256
- `Change the order of steps in ${problem}`
257
- ]
258
- };
259
- const templates = ideaTemplates[prompt.action] || ['Consider a new approach'];
260
- return templates[Math.floor(Math.random() * templates.length)];
261
- }
262
- }
263
- class SixThinkingHatsEngine {
264
- constructor() {
265
- this.hats = [
266
- { color: 'White', perspective: 'Objective', focus: 'facts and data' },
267
- { color: 'Red', perspective: 'Emotional', focus: 'feelings and intuition' },
268
- { color: 'Black', perspective: 'Critical', focus: 'risks and problems' },
269
- { color: 'Yellow', perspective: 'Optimistic', focus: 'benefits and value' },
270
- { color: 'Green', perspective: 'Creative', focus: 'new ideas and alternatives' },
271
- { color: 'Blue', perspective: 'Process', focus: 'overview and control' }
272
- ];
273
- }
274
- analyze(topic) {
275
- return this.hats.map(hat => ({
276
- hat: hat.color,
277
- perspective: hat.perspective,
278
- insights: this.generateInsights(topic, hat)
279
- }));
280
- }
281
- generateInsights(topic, hat) {
282
- const insights = [];
283
- switch (hat.color) {
284
- case 'White':
285
- insights.push(`What data do we have about ${topic}?`, `What information is missing about ${topic}?`, `What are the verifiable facts?`);
286
- break;
287
- case 'Red':
288
- insights.push(`What is my gut feeling about ${topic}?`, `What emotions does ${topic} evoke?`, `What is my intuitive reaction?`);
289
- break;
290
- case 'Black':
291
- insights.push(`What are the risks with ${topic}?`, `What could go wrong with ${topic}?`, `What are the potential problems?`);
292
- break;
293
- case 'Yellow':
294
- insights.push(`What are the benefits of ${topic}?`, `What value does ${topic} provide?`, `What are the opportunities?`);
295
- break;
296
- case 'Green':
297
- insights.push(`What creative alternatives exist for ${topic}?`, `What new ideas can we generate?`, `How can we think differently about this?`);
298
- break;
299
- case 'Blue':
300
- insights.push(`What is our process for addressing ${topic}?`, `How should we organize our thinking?`, `What is the big picture?`);
301
- break;
302
- }
303
- return insights;
304
- }
305
- }
306
- // ============================================================================
307
- // CONCEPT CONNECTOR
308
- // ============================================================================
309
- class ConceptConnector {
310
- constructor() {
311
- this.conceptDatabase = new Map([
312
- ['innovation', ['change', 'progress', 'novelty', 'improvement', 'disruption']],
313
- ['technology', ['tools', 'systems', 'automation', 'digital', 'advancement']],
314
- ['design', ['aesthetics', 'function', 'user', 'experience', 'form']],
315
- ['business', ['value', 'profit', 'market', 'customers', 'growth']],
316
- ['sustainability', ['environment', 'future', 'resources', 'balance', 'responsibility']]
317
- ]);
318
- }
319
- findConnections(concepts) {
320
- const connections = [];
321
- for (let i = 0; i < concepts.length; i++) {
322
- for (let j = i + 1; j < concepts.length; j++) {
323
- const connection = this.analyzeConnection(concepts[i], concepts[j]);
324
- if (connection.strength > 0.3) {
325
- connections.push(connection);
326
- }
327
- }
328
- }
329
- return connections.sort((a, b) => b.strength - a.strength);
330
- }
331
- analyzeConnection(concept1, concept2) {
332
- const attributes1 = this.getConceptAttributes(concept1);
333
- const attributes2 = this.getConceptAttributes(concept2);
334
- // Find common attributes
335
- const common = attributes1.filter(a => attributes2.includes(a));
336
- const all = [...new Set([...attributes1, ...attributes2])];
337
- const strength = common.length / all.length;
338
- // Determine connection type
339
- let connectionType = 'similarity';
340
- if (strength > 0.7) {
341
- connectionType = 'similarity';
342
- }
343
- else if (strength < 0.3) {
344
- connectionType = 'contrast';
345
- }
346
- else {
347
- connectionType = 'combination';
348
- }
349
- return {
350
- id: `conn_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`,
351
- from: concept1,
352
- to: concept2,
353
- connectionType,
354
- strength,
355
- insight: this.generateInsight(concept1, concept2, common, connectionType)
356
- };
357
- }
358
- getConceptAttributes(concept) {
359
- const lowerConcept = concept.toLowerCase();
360
- for (const [key, attributes] of this.conceptDatabase.entries()) {
361
- if (lowerConcept.includes(key) || key.includes(lowerConcept)) {
362
- return attributes;
363
- }
364
- }
365
- // Generate attributes from concept itself
366
- return concept.toLowerCase().split(/\s+/).filter(w => w.length > 3);
367
- }
368
- generateInsight(c1, c2, common, type) {
369
- switch (type) {
370
- case 'similarity':
371
- return `${c1} and ${c2} share ${common.length > 0 ? `common ground in ${common.join(', ')}` : 'fundamental similarities'}`;
372
- case 'contrast':
373
- return `${c1} and ${c2} represent different approaches that could complement each other`;
374
- case 'combination':
375
- return `Combining ${c1} with ${c2} could create something unique`;
376
- default:
377
- return `Interesting relationship between ${c1} and ${c2}`;
378
- }
379
- }
380
- generateNovelCombinations(concepts, count = 3) {
381
- const combinations = [];
382
- for (let i = 0; i < count; i++) {
383
- const c1 = concepts[Math.floor(Math.random() * concepts.length)];
384
- const c2 = concepts[Math.floor(Math.random() * concepts.length)];
385
- if (c1 !== c2) {
386
- combinations.push(`Combine ${c1} with ${c2} to create: ${this.generateCombinationName(c1, c2)}`);
387
- }
388
- }
389
- return combinations;
390
- }
391
- generateCombinationName(c1, c2) {
392
- const prefixes = ['Smart', 'Dynamic', 'Integrated', 'Adaptive', 'Holistic'];
393
- const prefix = prefixes[Math.floor(Math.random() * prefixes.length)];
394
- return `${prefix} ${c1.split(' ')[0]}-${c2.split(' ')[0]} Solution`;
395
- }
396
- }
397
- // ============================================================================
398
- // OUT-OF-BOX THINKING ENGINE
399
- // ============================================================================
400
- class OutOfBoxEngine {
401
- constructor() {
402
- this.perspectives = [
403
- 'Beginner\'s mind - forget what you know',
404
- 'Child\'s perspective - simple and curious',
405
- 'Alien perspective - no assumptions',
406
- 'Future perspective - 50 years ahead',
407
- 'Resource-constrained - extreme limitations',
408
- 'Opposite approach - do the reverse',
409
- 'Nature-inspired - biomimicry',
410
- 'Artistic perspective - beauty and emotion'
411
- ];
412
- }
413
- reframe(problem) {
414
- const reframedProblems = [];
415
- this.perspectives.forEach((perspective, index) => {
416
- const reframed = this.reframeFromPerspective(problem, perspective);
417
- reframedProblems.push({
418
- id: `reframe_${Date.now()}_${index}`,
419
- perspective,
420
- reframedStatement: reframed.statement,
421
- assumptionsChallenged: reframed.assumptions,
422
- newPossibilities: reframed.possibilities
423
- });
424
- });
425
- const unconventionalApproaches = this.generateUnconventionalApproaches(problem);
426
- const breakthroughPotential = this.calculateBreakthroughPotential(reframedProblems);
427
- return {
428
- id: `ootb_${Date.now()}`,
429
- originalProblem: problem,
430
- reframedProblems,
431
- unconventionalApproaches,
432
- breakthroughPotential
433
- };
434
- }
435
- reframeFromPerspective(problem, perspective) {
436
- const reframes = {
437
- 'Beginner\'s mind': {
438
- statement: `If you knew nothing about this, how would you approach: ${problem}?`,
439
- assumptions: ['Expert knowledge is necessary', 'Current methods are optimal'],
440
- possibilities: ['Fresh approaches', 'Questioning fundamentals']
441
- },
442
- 'Child\'s perspective': {
443
- statement: `How would a 5-year-old solve: ${problem}?`,
444
- assumptions: ['Complexity is required', 'Adult approaches are better'],
445
- possibilities: ['Simple solutions', 'Playful approaches']
446
- },
447
- 'Alien perspective': {
448
- statement: `How would beings from another planet view: ${problem}?`,
449
- assumptions: ['Human perspective is universal', 'Our constraints are absolute'],
450
- possibilities: ['Radically different approaches', 'Question all assumptions']
451
- },
452
- 'Future perspective': {
453
- statement: `How will people in 2074 solve: ${problem}?`,
454
- assumptions: ['Current technology limits', 'Present constraints are permanent'],
455
- possibilities: ['Future technologies', 'Long-term thinking']
456
- },
457
- 'Resource-constrained': {
458
- statement: `How would you solve ${problem} with 1% of current resources?`,
459
- assumptions: ['Adequate resources are needed', 'Scale is important'],
460
- possibilities: ['Minimalist solutions', 'Extreme efficiency']
461
- },
462
- 'Opposite approach': {
463
- statement: `What if the solution to ${problem} is the exact opposite of what we think?`,
464
- assumptions: ['Our direction is correct', 'Conventional wisdom applies'],
465
- possibilities: ['Counter-intuitive solutions', 'Paradigm shifts']
466
- },
467
- 'Nature-inspired': {
468
- statement: `How does nature solve problems similar to ${problem}?`,
469
- assumptions: ['Human-designed solutions are superior', 'Technology is the answer'],
470
- possibilities: ['Biomimicry', 'Natural patterns']
471
- },
472
- 'Artistic perspective': {
473
- statement: `How would an artist approach ${problem}?`,
474
- assumptions: ['Technical solutions only', 'Function over form'],
475
- possibilities: ['Aesthetic solutions', 'Emotional design']
476
- }
477
- };
478
- return reframes[perspective] || {
479
- statement: `Reframe: ${problem}`,
480
- assumptions: ['Standard approach'],
481
- possibilities: ['Alternative approaches']
482
- };
483
- }
484
- generateUnconventionalApproaches(problem) {
485
- return [
486
- `What if ${problem} is actually an opportunity in disguise?`,
487
- `How can ${problem} be made worse, then reverse that?`,
488
- `What would make ${problem} solve itself?`,
489
- `Who benefits from ${problem} existing?`,
490
- `What if the problem and solution are the same thing?`
491
- ];
492
- }
493
- calculateBreakthroughPotential(reframedProblems) {
494
- const totalAssumptions = reframedProblems.reduce((sum, rp) => sum + rp.assumptionsChallenged.length, 0);
495
- const totalPossibilities = reframedProblems.reduce((sum, rp) => sum + rp.newPossibilities.length, 0);
496
- return Math.min(0.95, (totalAssumptions * 0.05 + totalPossibilities * 0.1));
497
- }
498
- }
499
- // ============================================================================
500
- // MAIN CREATIVITY ENGINE
501
- // ============================================================================
502
- class CreativityEngine extends events_1.EventEmitter {
503
- constructor() {
504
- super();
505
- this.sessions = new Map();
506
- this.brainstormingEngine = new BrainstormingEngine();
507
- this.mindMappingEngine = new MindMappingEngine();
508
- this.scamperEngine = new ScamperEngine();
509
- this.sixHatsEngine = new SixThinkingHatsEngine();
510
- this.conceptConnector = new ConceptConnector();
511
- this.outOfBoxEngine = new OutOfBoxEngine();
512
- }
513
- /**
514
- * Start a creative session
515
- */
516
- async startSession(prompt, options = {}) {
517
- const { techniques = ['brainstorming', 'analogy', 'scamper'], ideaCount = 15, duration = 30 } = options;
518
- const sessionId = this.generateId();
519
- const startTime = Date.now();
520
- this.emit('creativity_start', {
521
- id: sessionId,
522
- stage: types_1.ThinkingStage.CREATIVITY,
523
- timestamp: new Date(),
524
- data: { prompt, techniques }
525
- });
526
- // Generate ideas
527
- let ideas = [];
528
- try {
529
- ideas = await this.generateIdeasWithLLM(prompt, techniques, ideaCount);
530
- }
531
- catch (error) {
532
- console.warn('LLM creativity failed, falling back to internal engine', error);
533
- }
534
- if (ideas.length === 0) {
535
- techniques.forEach(technique => {
536
- const techniqueIdeas = this.generateIdeasWithTechnique(prompt, technique, Math.ceil(ideaCount / techniques.length));
537
- ideas.push(...techniqueIdeas);
538
- });
539
- }
540
- // Find connections between ideas
541
- const connections = this.findConnections(ideas);
542
- // Divergent phase
543
- const divergentPhase = {
544
- startTime: new Date(startTime),
545
- endTime: new Date(),
546
- ideaCount: ideas.length,
547
- explorationBreadth: techniques.length
548
- };
549
- // Convergent phase - select best ideas
550
- const selectedIdeas = this.selectBestIdeas(ideas, 5);
551
- const synthesis = this.synthesizeIdeas(selectedIdeas);
552
- const convergentPhase = {
553
- startTime: new Date(),
554
- endTime: new Date(),
555
- selectedIdeas: selectedIdeas.map(i => i.id),
556
- synthesis,
557
- actionItems: this.generateActionItems(selectedIdeas)
558
- };
559
- const session = {
560
- id: sessionId,
561
- prompt,
562
- techniques,
563
- ideas,
564
- connections,
565
- sessionDuration: Date.now() - startTime,
566
- divergentPhase,
567
- convergentPhase
568
- };
569
- this.sessions.set(sessionId, session);
570
- this.emit('creativity_complete', {
571
- id: sessionId,
572
- stage: types_1.ThinkingStage.CREATIVITY,
573
- timestamp: new Date(),
574
- data: {
575
- ideaCount: ideas.length,
576
- connectionCount: connections.length,
577
- topIdeas: selectedIdeas.map(i => i.content.substring(0, 50))
578
- }
579
- });
580
- return session;
581
- }
582
- async generateIdeasWithLLM(prompt, techniques, count) {
583
- const promptText = `
584
- You are a creativity engine.
585
- Prompt: "${prompt}"
586
- Techniques to use: ${techniques.join(', ')}
587
- Target count: ${count} ideas
588
-
589
- Return strictly JSON with structure:
590
- {
591
- "ideas": [
592
- {
593
- "content": "string (the idea description)",
594
- "technique": "string (which technique was used)",
595
- "novelty": number (0-1),
596
- "feasibility": number (0-1),
597
- "impact": number (0-1),
598
- "tags": ["string"]
599
- }
600
- ]
601
- }
602
- `;
603
- const response = await llm_service_1.llmService.generateText({ prompt: promptText });
604
- const jsonMatch = response.match(/\{[\s\S]*\}/);
605
- if (jsonMatch) {
606
- const result = JSON.parse(jsonMatch[0]);
607
- if (Array.isArray(result.ideas)) {
608
- return result.ideas.map((item, index) => ({
609
- id: `idea_llm_${Date.now()}_${index}`,
610
- content: item.content,
611
- technique: item.technique,
612
- novelty: item.novelty || 0.7,
613
- feasibility: item.feasibility || 0.7,
614
- impact: item.impact || 0.7,
615
- relatedIdeas: [],
616
- tags: item.tags || [],
617
- generatedAt: new Date()
618
- }));
619
- }
620
- }
621
- return [];
622
- }
623
- /**
624
- * Generate ideas using a specific technique
625
- */
626
- generateIdeasWithTechnique(prompt, technique, count) {
627
- switch (technique) {
628
- case 'brainstorming':
629
- case 'analogy':
630
- case 'reverse_thinking':
631
- case 'random_stimulus':
632
- case 'lateral_thinking':
633
- return this.brainstormingEngine.generateIdeas(prompt, count);
634
- case 'scamper':
635
- return this.applyScamperInternal(prompt);
636
- case 'mind_mapping':
637
- return this.generateFromMindMap(prompt, count);
638
- case 'six_thinking_hats':
639
- return this.applySixHatsInternal(prompt);
640
- default:
641
- return this.brainstormingEngine.generateIdeas(prompt, count);
642
- }
643
- }
644
- applyScamperInternal(prompt) {
645
- const scamperResults = this.scamperEngine.apply(prompt);
646
- return scamperResults.map((result, index) => ({
647
- id: `idea_scamper_${Date.now()}_${index}`,
648
- content: `${result.technique}: ${result.idea}`,
649
- technique: 'scamper',
650
- novelty: 0.7,
651
- feasibility: 0.6,
652
- impact: 0.65,
653
- relatedIdeas: [],
654
- tags: ['scamper', result.technique.toLowerCase()],
655
- generatedAt: new Date()
656
- }));
657
- }
658
- generateFromMindMap(prompt, count) {
659
- const mindMap = this.mindMappingEngine.createMindMap(prompt, 2);
660
- const ideas = [];
661
- const extractIdeas = (node, depth) => {
662
- if (ideas.length >= count)
663
- return;
664
- ideas.push({
665
- id: `idea_mindmap_${Date.now()}_${ideas.length}`,
666
- content: `Explore: ${node.label}`,
667
- technique: 'mind_mapping',
668
- novelty: 0.6 + depth * 0.1,
669
- feasibility: 0.7,
670
- impact: 0.6,
671
- relatedIdeas: [],
672
- tags: ['mindmap', `level_${depth}`],
673
- generatedAt: new Date()
674
- });
675
- node.children.forEach((child) => extractIdeas(child, depth + 1));
676
- };
677
- extractIdeas(mindMap, 0);
678
- return ideas.slice(0, count);
679
- }
680
- applySixHatsInternal(prompt) {
681
- const hatsResults = this.sixHatsEngine.analyze(prompt);
682
- return hatsResults.map((result, index) => ({
683
- id: `idea_hat_${Date.now()}_${index}`,
684
- content: `${result.hat} Hat perspective: ${result.insights[0]}`,
685
- technique: 'six_thinking_hats',
686
- novelty: 0.65,
687
- feasibility: 0.75,
688
- impact: 0.7,
689
- relatedIdeas: [],
690
- tags: ['six_hats', result.hat.toLowerCase()],
691
- generatedAt: new Date()
692
- }));
693
- }
694
- /**
695
- * Find connections between ideas
696
- */
697
- findConnections(ideas) {
698
- const concepts = ideas.map(i => i.content);
699
- return this.conceptConnector.findConnections(concepts);
700
- }
701
- /**
702
- * Select best ideas based on multiple criteria
703
- */
704
- selectBestIdeas(ideas, count) {
705
- return ideas
706
- .map(idea => ({
707
- idea,
708
- score: idea.novelty * 0.3 + idea.feasibility * 0.4 + idea.impact * 0.3
709
- }))
710
- .sort((a, b) => b.score - a.score)
711
- .slice(0, count)
712
- .map(({ idea }) => idea);
713
- }
714
- /**
715
- * Synthesize selected ideas into coherent concept
716
- */
717
- synthesizeIdeas(ideas) {
718
- const themes = this.extractCommonThemes(ideas);
719
- return `Synthesis: Combining ${ideas.length} ideas reveals ${themes.length} key themes: ` +
720
- `${themes.join(', ')}. The integrated solution leverages the strengths of each approach.`;
721
- }
722
- extractCommonThemes(ideas) {
723
- const allTags = ideas.flatMap(i => i.tags);
724
- const tagFreq = new Map();
725
- allTags.forEach(tag => {
726
- tagFreq.set(tag, (tagFreq.get(tag) || 0) + 1);
727
- });
728
- return Array.from(tagFreq.entries())
729
- .sort((a, b) => b[1] - a[1])
730
- .slice(0, 3)
731
- .map(([tag]) => tag);
732
- }
733
- generateActionItems(ideas) {
734
- return ideas.slice(0, 3).map((idea, index) => `${index + 1}. Explore: ${idea.content.substring(0, 50)}...`);
735
- }
736
- /**
737
- * Apply out-of-box thinking to a problem
738
- */
739
- thinkOutOfBox(problem) {
740
- return this.outOfBoxEngine.reframe(problem);
741
- }
742
- /**
743
- * Generate novel combinations of concepts
744
- */
745
- generateCombinations(concepts, count) {
746
- return this.conceptConnector.generateNovelCombinations(concepts, count);
747
- }
748
- /**
749
- * Create mind map
750
- */
751
- createMindMap(centerConcept, depth) {
752
- return this.mindMappingEngine.createMindMap(centerConcept, depth);
753
- }
754
- /**
755
- * Apply SCAMPER technique
756
- */
757
- applyScamper(problem) {
758
- return this.scamperEngine.apply(problem);
759
- }
760
- /**
761
- * Apply Six Thinking Hats
762
- */
763
- applySixHats(topic) {
764
- return this.sixHatsEngine.analyze(topic);
765
- }
766
- /**
767
- * Get creative session
768
- */
769
- getSession(sessionId) {
770
- return this.sessions.get(sessionId);
771
- }
772
- generateId() {
773
- return `creative_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
774
- }
775
- }
776
- exports.CreativityEngine = CreativityEngine;
777
- // ============================================================================
778
- // EXPORT SINGLETON INSTANCE
779
- // ============================================================================
780
- exports.creativityEngine = new CreativityEngine();
781
- // ============================================================================
782
- // EXAMPLE USAGE
783
- // ============================================================================
784
- /*
785
- // Start a creative session
786
- const session = creativityEngine.startSession(
787
- 'How can we improve remote team collaboration?',
788
- {
789
- techniques: ['brainstorming', 'scamper', 'six_thinking_hats'],
790
- ideaCount: 20
791
- }
792
- );
793
-
794
- // Out-of-box thinking
795
- const outOfBox = creativityEngine.thinkOutOfBox(
796
- 'Our product has low user engagement'
797
- );
798
-
799
- // Generate combinations
800
- const combinations = creativityEngine.generateCombinations(
801
- ['AI', 'collaboration', 'gamification', 'VR'],
802
- 5
803
- );
804
-
805
- // Create mind map
806
- const mindMap = creativityEngine.createMindMap('Innovation Strategy', 3);
807
-
808
- // Apply SCAMPER
809
- const scamperResults = creativityEngine.applyScamper(
810
- 'Traditional education system'
811
- );
812
-
813
- // Apply Six Thinking Hats
814
- const hatsAnalysis = creativityEngine.applySixHats(
815
- 'Implementing AI in healthcare'
816
- );
817
-
818
- // Access generated ideas
819
- const topIdeas = session.ideas
820
- .sort((a, b) => (b.novelty + b.feasibility + b.impact) - (a.novelty + a.feasibility + a.impact))
821
- .slice(0, 5);
822
-
823
- // Get connections between ideas
824
- const connections = session.connections
825
- .filter(c => c.strength > 0.5)
826
- .slice(0, 3);
827
- */
828
- //# sourceMappingURL=creativity.js.map