creative-genius-engine 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/wisdom.mjs ADDED
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Wisdom Distillery
3
+ *
4
+ * Extract patterns from creative sessions.
5
+ * What worked? What didn't? Compound learning.
6
+ *
7
+ * "The creative adult is the child who survived." — Ursula K. Le Guin
8
+ */
9
+
10
+ // In-memory session storage
11
+ let sessions = [];
12
+ let patterns = [];
13
+
14
+ /**
15
+ * Record a creative session outcome
16
+ */
17
+ export function record(session) {
18
+ const entry = {
19
+ id: `wisdom-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
20
+ recordedAt: new Date().toISOString(),
21
+ challenge: session.challenge,
22
+ approach: session.approach || 'bartok',
23
+ outcome: session.outcome || 'unknown',
24
+ worked: session.worked || [],
25
+ failed: session.failed || [],
26
+ learned: session.learned || [],
27
+ wouldChange: session.wouldChange || [],
28
+ tags: session.tags || [],
29
+ };
30
+
31
+ sessions.push(entry);
32
+
33
+ // Extract potential patterns
34
+ const newPatterns = extractPatterns(entry);
35
+
36
+ return {
37
+ recorded: entry,
38
+ totalSessions: sessions.length,
39
+ patternsFound: newPatterns.length,
40
+ newPatterns,
41
+ };
42
+ }
43
+
44
+ /**
45
+ * Extract patterns from a session
46
+ */
47
+ function extractPatterns(session) {
48
+ const found = [];
49
+
50
+ // Pattern: Something that worked multiple times
51
+ session.worked.forEach(item => {
52
+ const existing = patterns.find(p =>
53
+ p.type === 'success' && similarity(p.text, item) > 0.7
54
+ );
55
+
56
+ if (existing) {
57
+ existing.count++;
58
+ existing.lastSeen = new Date().toISOString();
59
+ } else {
60
+ const pattern = {
61
+ id: `pat-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
62
+ type: 'success',
63
+ text: item,
64
+ count: 1,
65
+ firstSeen: new Date().toISOString(),
66
+ lastSeen: new Date().toISOString(),
67
+ contexts: [session.challenge],
68
+ };
69
+ patterns.push(pattern);
70
+ found.push(pattern);
71
+ }
72
+ });
73
+
74
+ // Pattern: Something that failed
75
+ session.failed.forEach(item => {
76
+ const existing = patterns.find(p =>
77
+ p.type === 'failure' && similarity(p.text, item) > 0.7
78
+ );
79
+
80
+ if (existing) {
81
+ existing.count++;
82
+ existing.lastSeen = new Date().toISOString();
83
+ } else {
84
+ const pattern = {
85
+ id: `pat-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
86
+ type: 'failure',
87
+ text: item,
88
+ count: 1,
89
+ firstSeen: new Date().toISOString(),
90
+ lastSeen: new Date().toISOString(),
91
+ contexts: [session.challenge],
92
+ };
93
+ patterns.push(pattern);
94
+ found.push(pattern);
95
+ }
96
+ });
97
+
98
+ return found;
99
+ }
100
+
101
+ /**
102
+ * Simple text similarity (word overlap)
103
+ */
104
+ function similarity(a, b) {
105
+ const wordsA = a.toLowerCase().split(/\s+/);
106
+ const wordsB = b.toLowerCase().split(/\s+/);
107
+ const intersection = wordsA.filter(w => wordsB.includes(w));
108
+ const union = [...new Set([...wordsA, ...wordsB])];
109
+ return intersection.length / union.length;
110
+ }
111
+
112
+ /**
113
+ * Get patterns sorted by count
114
+ */
115
+ export function getPatterns(type = null) {
116
+ let filtered = patterns;
117
+ if (type) {
118
+ filtered = patterns.filter(p => p.type === type);
119
+ }
120
+
121
+ return {
122
+ patterns: filtered.sort((a, b) => b.count - a.count),
123
+ total: filtered.length,
124
+ topSuccesses: patterns.filter(p => p.type === 'success').sort((a, b) => b.count - a.count).slice(0, 5),
125
+ topFailures: patterns.filter(p => p.type === 'failure').sort((a, b) => b.count - a.count).slice(0, 5),
126
+ };
127
+ }
128
+
129
+ /**
130
+ * Get advice based on patterns
131
+ */
132
+ export function advise(challenge) {
133
+ const successPatterns = patterns.filter(p => p.type === 'success' && p.count >= 2);
134
+ const failurePatterns = patterns.filter(p => p.type === 'failure' && p.count >= 2);
135
+
136
+ return {
137
+ challenge,
138
+ advice: {
139
+ try: successPatterns.length > 0
140
+ ? successPatterns.map(p => `${p.text} (worked ${p.count}x)`)
141
+ : ['No strong success patterns yet. Experiment and record!'],
142
+ avoid: failurePatterns.length > 0
143
+ ? failurePatterns.map(p => `${p.text} (failed ${p.count}x)`)
144
+ : ['No failure patterns recorded yet.'],
145
+ },
146
+ meta: "These patterns are extracted from recorded sessions. The more you record, the better the advice.",
147
+ };
148
+ }
149
+
150
+ /**
151
+ * Distill learnings into principles
152
+ */
153
+ export function distill() {
154
+ const principles = [];
155
+
156
+ // Principle from repeated successes
157
+ const topSuccesses = patterns
158
+ .filter(p => p.type === 'success' && p.count >= 3)
159
+ .sort((a, b) => b.count - a.count);
160
+
161
+ topSuccesses.forEach(p => {
162
+ principles.push({
163
+ type: 'do',
164
+ principle: p.text,
165
+ evidence: `Worked in ${p.count} sessions`,
166
+ contexts: p.contexts,
167
+ });
168
+ });
169
+
170
+ // Anti-principles from repeated failures
171
+ const topFailures = patterns
172
+ .filter(p => p.type === 'failure' && p.count >= 3)
173
+ .sort((a, b) => b.count - a.count);
174
+
175
+ topFailures.forEach(p => {
176
+ principles.push({
177
+ type: 'avoid',
178
+ principle: p.text,
179
+ evidence: `Failed in ${p.count} sessions`,
180
+ contexts: p.contexts,
181
+ });
182
+ });
183
+
184
+ return {
185
+ principles,
186
+ totalSessions: sessions.length,
187
+ totalPatterns: patterns.length,
188
+ quote: "Wisdom is knowledge plus experience, distilled.",
189
+ };
190
+ }
191
+
192
+ /**
193
+ * Export all wisdom
194
+ */
195
+ export function exportWisdom() {
196
+ return {
197
+ exportedAt: new Date().toISOString(),
198
+ sessions,
199
+ patterns,
200
+ principles: distill().principles,
201
+ version: '1.0.0',
202
+ };
203
+ }
204
+
205
+ /**
206
+ * Import wisdom
207
+ */
208
+ export function importWisdom(data) {
209
+ if (!data.sessions || !data.patterns) {
210
+ return { error: 'Invalid wisdom data' };
211
+ }
212
+ sessions = data.sessions;
213
+ patterns = data.patterns;
214
+ return {
215
+ imported: true,
216
+ sessions: sessions.length,
217
+ patterns: patterns.length,
218
+ };
219
+ }
220
+
221
+ /**
222
+ * Clear all wisdom
223
+ */
224
+ export function clear() {
225
+ const counts = { sessions: sessions.length, patterns: patterns.length };
226
+ sessions = [];
227
+ patterns = [];
228
+ return { cleared: counts };
229
+ }
230
+
231
+ export default {
232
+ record,
233
+ getPatterns,
234
+ advise,
235
+ distill,
236
+ exportWisdom,
237
+ importWisdom,
238
+ clear,
239
+ };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "creative-genius-engine",
3
+ "version": "1.0.0",
4
+ "description": "Creative thinking toolkit for AI agents, synthesized from Leonardo, Tesla, Bach, Feynman, and more",
5
+ "type": "module",
6
+ "main": "lib/index.mjs",
7
+ "bin": {
8
+ "creative-genius": "./cli.mjs"
9
+ },
10
+ "scripts": {
11
+ "test": "node tests/engine.test.mjs",
12
+ "demo": "node examples/demo.mjs"
13
+ },
14
+ "keywords": [
15
+ "creativity",
16
+ "ai",
17
+ "agents",
18
+ "thinking",
19
+ "janusian",
20
+ "feynman",
21
+ "leonardo",
22
+ "innovation"
23
+ ],
24
+ "author": "Bartok 🎻",
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/Bartok9/creative-genius-engine"
29
+ },
30
+ "homepage": "https://dist-dun-six-77.vercel.app"
31
+ }