genesis-ai-cli 7.4.5

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 (227) hide show
  1. package/.env.example +78 -0
  2. package/README.md +282 -0
  3. package/dist/src/active-inference/actions.d.ts +75 -0
  4. package/dist/src/active-inference/actions.js +250 -0
  5. package/dist/src/active-inference/autonomous-loop.d.ts +103 -0
  6. package/dist/src/active-inference/autonomous-loop.js +289 -0
  7. package/dist/src/active-inference/core.d.ts +85 -0
  8. package/dist/src/active-inference/core.js +555 -0
  9. package/dist/src/active-inference/demo-autonomous-loop.d.ts +8 -0
  10. package/dist/src/active-inference/demo-autonomous-loop.js +338 -0
  11. package/dist/src/active-inference/demo-value-integration.d.ts +8 -0
  12. package/dist/src/active-inference/demo-value-integration.js +174 -0
  13. package/dist/src/active-inference/index.d.ts +32 -0
  14. package/dist/src/active-inference/index.js +88 -0
  15. package/dist/src/active-inference/integration.d.ts +114 -0
  16. package/dist/src/active-inference/integration.js +698 -0
  17. package/dist/src/active-inference/memory-integration.d.ts +51 -0
  18. package/dist/src/active-inference/memory-integration.js +232 -0
  19. package/dist/src/active-inference/observations.d.ts +67 -0
  20. package/dist/src/active-inference/observations.js +147 -0
  21. package/dist/src/active-inference/test-active-inference.d.ts +8 -0
  22. package/dist/src/active-inference/test-active-inference.js +320 -0
  23. package/dist/src/active-inference/test-value-integration.d.ts +6 -0
  24. package/dist/src/active-inference/test-value-integration.js +168 -0
  25. package/dist/src/active-inference/types.d.ts +150 -0
  26. package/dist/src/active-inference/types.js +59 -0
  27. package/dist/src/active-inference/value-integration.d.ts +164 -0
  28. package/dist/src/active-inference/value-integration.js +459 -0
  29. package/dist/src/agents/base-agent.d.ts +53 -0
  30. package/dist/src/agents/base-agent.js +178 -0
  31. package/dist/src/agents/builder.d.ts +67 -0
  32. package/dist/src/agents/builder.js +537 -0
  33. package/dist/src/agents/critic.d.ts +35 -0
  34. package/dist/src/agents/critic.js +322 -0
  35. package/dist/src/agents/ethicist.d.ts +54 -0
  36. package/dist/src/agents/ethicist.js +393 -0
  37. package/dist/src/agents/explorer.d.ts +26 -0
  38. package/dist/src/agents/explorer.js +216 -0
  39. package/dist/src/agents/feeling.d.ts +41 -0
  40. package/dist/src/agents/feeling.js +320 -0
  41. package/dist/src/agents/index.d.ts +111 -0
  42. package/dist/src/agents/index.js +222 -0
  43. package/dist/src/agents/memory.d.ts +69 -0
  44. package/dist/src/agents/memory.js +404 -0
  45. package/dist/src/agents/message-bus.d.ts +88 -0
  46. package/dist/src/agents/message-bus.js +267 -0
  47. package/dist/src/agents/narrator.d.ts +90 -0
  48. package/dist/src/agents/narrator.js +473 -0
  49. package/dist/src/agents/planner.d.ts +38 -0
  50. package/dist/src/agents/planner.js +341 -0
  51. package/dist/src/agents/predictor.d.ts +73 -0
  52. package/dist/src/agents/predictor.js +506 -0
  53. package/dist/src/agents/sensor.d.ts +88 -0
  54. package/dist/src/agents/sensor.js +377 -0
  55. package/dist/src/agents/test-agents.d.ts +6 -0
  56. package/dist/src/agents/test-agents.js +73 -0
  57. package/dist/src/agents/types.d.ts +194 -0
  58. package/dist/src/agents/types.js +7 -0
  59. package/dist/src/brain/index.d.ts +185 -0
  60. package/dist/src/brain/index.js +843 -0
  61. package/dist/src/brain/trace.d.ts +91 -0
  62. package/dist/src/brain/trace.js +327 -0
  63. package/dist/src/brain/types.d.ts +165 -0
  64. package/dist/src/brain/types.js +51 -0
  65. package/dist/src/cli/chat.d.ts +237 -0
  66. package/dist/src/cli/chat.js +1959 -0
  67. package/dist/src/cli/dispatcher.d.ts +182 -0
  68. package/dist/src/cli/dispatcher.js +718 -0
  69. package/dist/src/cli/human-loop.d.ts +170 -0
  70. package/dist/src/cli/human-loop.js +543 -0
  71. package/dist/src/cli/index.d.ts +12 -0
  72. package/dist/src/cli/index.js +28 -0
  73. package/dist/src/cli/interactive.d.ts +141 -0
  74. package/dist/src/cli/interactive.js +757 -0
  75. package/dist/src/cli/ui.d.ts +205 -0
  76. package/dist/src/cli/ui.js +632 -0
  77. package/dist/src/consciousness/attention-schema.d.ts +154 -0
  78. package/dist/src/consciousness/attention-schema.js +432 -0
  79. package/dist/src/consciousness/global-workspace.d.ts +149 -0
  80. package/dist/src/consciousness/global-workspace.js +422 -0
  81. package/dist/src/consciousness/index.d.ts +186 -0
  82. package/dist/src/consciousness/index.js +476 -0
  83. package/dist/src/consciousness/phi-calculator.d.ts +119 -0
  84. package/dist/src/consciousness/phi-calculator.js +445 -0
  85. package/dist/src/consciousness/phi-decisions.d.ts +169 -0
  86. package/dist/src/consciousness/phi-decisions.js +383 -0
  87. package/dist/src/consciousness/phi-monitor.d.ts +153 -0
  88. package/dist/src/consciousness/phi-monitor.js +465 -0
  89. package/dist/src/consciousness/types.d.ts +260 -0
  90. package/dist/src/consciousness/types.js +44 -0
  91. package/dist/src/daemon/dream-mode.d.ts +115 -0
  92. package/dist/src/daemon/dream-mode.js +470 -0
  93. package/dist/src/daemon/index.d.ts +162 -0
  94. package/dist/src/daemon/index.js +542 -0
  95. package/dist/src/daemon/maintenance.d.ts +139 -0
  96. package/dist/src/daemon/maintenance.js +549 -0
  97. package/dist/src/daemon/process.d.ts +82 -0
  98. package/dist/src/daemon/process.js +442 -0
  99. package/dist/src/daemon/scheduler.d.ts +90 -0
  100. package/dist/src/daemon/scheduler.js +494 -0
  101. package/dist/src/daemon/types.d.ts +213 -0
  102. package/dist/src/daemon/types.js +50 -0
  103. package/dist/src/epistemic/index.d.ts +74 -0
  104. package/dist/src/epistemic/index.js +225 -0
  105. package/dist/src/grounding/epistemic-stack.d.ts +100 -0
  106. package/dist/src/grounding/epistemic-stack.js +408 -0
  107. package/dist/src/grounding/feedback.d.ts +98 -0
  108. package/dist/src/grounding/feedback.js +276 -0
  109. package/dist/src/grounding/index.d.ts +123 -0
  110. package/dist/src/grounding/index.js +224 -0
  111. package/dist/src/grounding/verifier.d.ts +149 -0
  112. package/dist/src/grounding/verifier.js +484 -0
  113. package/dist/src/healing/detector.d.ts +110 -0
  114. package/dist/src/healing/detector.js +436 -0
  115. package/dist/src/healing/fixer.d.ts +138 -0
  116. package/dist/src/healing/fixer.js +572 -0
  117. package/dist/src/healing/index.d.ts +23 -0
  118. package/dist/src/healing/index.js +43 -0
  119. package/dist/src/hooks/index.d.ts +135 -0
  120. package/dist/src/hooks/index.js +317 -0
  121. package/dist/src/index.d.ts +23 -0
  122. package/dist/src/index.js +1266 -0
  123. package/dist/src/kernel/index.d.ts +155 -0
  124. package/dist/src/kernel/index.js +795 -0
  125. package/dist/src/kernel/invariants.d.ts +153 -0
  126. package/dist/src/kernel/invariants.js +355 -0
  127. package/dist/src/kernel/test-kernel.d.ts +6 -0
  128. package/dist/src/kernel/test-kernel.js +108 -0
  129. package/dist/src/kernel/test-real-mcp.d.ts +10 -0
  130. package/dist/src/kernel/test-real-mcp.js +295 -0
  131. package/dist/src/llm/index.d.ts +146 -0
  132. package/dist/src/llm/index.js +428 -0
  133. package/dist/src/llm/router.d.ts +136 -0
  134. package/dist/src/llm/router.js +510 -0
  135. package/dist/src/mcp/index.d.ts +85 -0
  136. package/dist/src/mcp/index.js +657 -0
  137. package/dist/src/mcp/resilient.d.ts +139 -0
  138. package/dist/src/mcp/resilient.js +417 -0
  139. package/dist/src/memory/cache.d.ts +118 -0
  140. package/dist/src/memory/cache.js +356 -0
  141. package/dist/src/memory/cognitive-workspace.d.ts +231 -0
  142. package/dist/src/memory/cognitive-workspace.js +521 -0
  143. package/dist/src/memory/consolidation.d.ts +99 -0
  144. package/dist/src/memory/consolidation.js +443 -0
  145. package/dist/src/memory/episodic.d.ts +114 -0
  146. package/dist/src/memory/episodic.js +394 -0
  147. package/dist/src/memory/forgetting.d.ts +134 -0
  148. package/dist/src/memory/forgetting.js +324 -0
  149. package/dist/src/memory/index.d.ts +211 -0
  150. package/dist/src/memory/index.js +367 -0
  151. package/dist/src/memory/indexer.d.ts +123 -0
  152. package/dist/src/memory/indexer.js +479 -0
  153. package/dist/src/memory/procedural.d.ts +136 -0
  154. package/dist/src/memory/procedural.js +479 -0
  155. package/dist/src/memory/semantic.d.ts +132 -0
  156. package/dist/src/memory/semantic.js +497 -0
  157. package/dist/src/memory/types.d.ts +193 -0
  158. package/dist/src/memory/types.js +15 -0
  159. package/dist/src/orchestrator.d.ts +65 -0
  160. package/dist/src/orchestrator.js +317 -0
  161. package/dist/src/persistence/index.d.ts +257 -0
  162. package/dist/src/persistence/index.js +763 -0
  163. package/dist/src/pipeline/executor.d.ts +51 -0
  164. package/dist/src/pipeline/executor.js +695 -0
  165. package/dist/src/pipeline/index.d.ts +7 -0
  166. package/dist/src/pipeline/index.js +11 -0
  167. package/dist/src/self-production.d.ts +67 -0
  168. package/dist/src/self-production.js +205 -0
  169. package/dist/src/subagents/executor.d.ts +58 -0
  170. package/dist/src/subagents/executor.js +283 -0
  171. package/dist/src/subagents/index.d.ts +37 -0
  172. package/dist/src/subagents/index.js +53 -0
  173. package/dist/src/subagents/registry.d.ts +23 -0
  174. package/dist/src/subagents/registry.js +167 -0
  175. package/dist/src/subagents/types.d.ts +79 -0
  176. package/dist/src/subagents/types.js +14 -0
  177. package/dist/src/tools/bash.d.ts +139 -0
  178. package/dist/src/tools/bash.js +583 -0
  179. package/dist/src/tools/edit.d.ts +125 -0
  180. package/dist/src/tools/edit.js +424 -0
  181. package/dist/src/tools/git.d.ts +179 -0
  182. package/dist/src/tools/git.js +504 -0
  183. package/dist/src/tools/index.d.ts +21 -0
  184. package/dist/src/tools/index.js +163 -0
  185. package/dist/src/types.d.ts +145 -0
  186. package/dist/src/types.js +7 -0
  187. package/dist/src/world-model/decoder.d.ts +163 -0
  188. package/dist/src/world-model/decoder.js +517 -0
  189. package/dist/src/world-model/digital-twin.d.ts +219 -0
  190. package/dist/src/world-model/digital-twin.js +695 -0
  191. package/dist/src/world-model/encoder.d.ts +141 -0
  192. package/dist/src/world-model/encoder.js +564 -0
  193. package/dist/src/world-model/index.d.ts +221 -0
  194. package/dist/src/world-model/index.js +772 -0
  195. package/dist/src/world-model/predictor.d.ts +161 -0
  196. package/dist/src/world-model/predictor.js +681 -0
  197. package/dist/src/world-model/test-value-jepa.d.ts +8 -0
  198. package/dist/src/world-model/test-value-jepa.js +430 -0
  199. package/dist/src/world-model/types.d.ts +341 -0
  200. package/dist/src/world-model/types.js +69 -0
  201. package/dist/src/world-model/value-jepa.d.ts +247 -0
  202. package/dist/src/world-model/value-jepa.js +622 -0
  203. package/dist/test/brain.test.d.ts +11 -0
  204. package/dist/test/brain.test.js +358 -0
  205. package/dist/test/cli/dispatcher.test.d.ts +4 -0
  206. package/dist/test/cli/dispatcher.test.js +332 -0
  207. package/dist/test/cli/human-loop.test.d.ts +4 -0
  208. package/dist/test/cli/human-loop.test.js +270 -0
  209. package/dist/test/grounding/feedback.test.d.ts +4 -0
  210. package/dist/test/grounding/feedback.test.js +462 -0
  211. package/dist/test/grounding/verifier.test.d.ts +4 -0
  212. package/dist/test/grounding/verifier.test.js +442 -0
  213. package/dist/test/grounding.test.d.ts +6 -0
  214. package/dist/test/grounding.test.js +246 -0
  215. package/dist/test/healing/detector.test.d.ts +4 -0
  216. package/dist/test/healing/detector.test.js +266 -0
  217. package/dist/test/healing/fixer.test.d.ts +4 -0
  218. package/dist/test/healing/fixer.test.js +369 -0
  219. package/dist/test/integration.test.d.ts +5 -0
  220. package/dist/test/integration.test.js +290 -0
  221. package/dist/test/tools/bash.test.d.ts +4 -0
  222. package/dist/test/tools/bash.test.js +348 -0
  223. package/dist/test/tools/edit.test.d.ts +4 -0
  224. package/dist/test/tools/edit.test.js +350 -0
  225. package/dist/test/tools/git.test.d.ts +4 -0
  226. package/dist/test/tools/git.test.js +350 -0
  227. package/package.json +60 -0
@@ -0,0 +1,479 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis 6.0 - Procedural Memory Store
4
+ *
5
+ * Stores skills and workflows - know-how.
6
+ * "How to do things"
7
+ *
8
+ * Key features:
9
+ * - Step-by-step procedures
10
+ * - Success rate tracking
11
+ * - Skill improvement over time
12
+ * - Prerequisites and dependencies
13
+ *
14
+ * Reference: Anderson, J. R. (1982). Acquisition of cognitive skill.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ProceduralStore = void 0;
18
+ exports.createProceduralStore = createProceduralStore;
19
+ const crypto_1 = require("crypto");
20
+ const forgetting_js_1 = require("./forgetting.js");
21
+ // ============================================================================
22
+ // Procedural Store
23
+ // ============================================================================
24
+ class ProceduralStore {
25
+ memories = new Map();
26
+ config;
27
+ // Indexes
28
+ byName = new Map(); // name -> id
29
+ byTag = new Map();
30
+ dependencies = new Map(); // skill -> skills that require it
31
+ constructor(config = {}) {
32
+ this.config = {
33
+ maxSize: 5000,
34
+ autoForget: true,
35
+ forgetThreshold: forgetting_js_1.FORGETTING_THRESHOLDS.FORGET,
36
+ minSuccessRate: 0.2,
37
+ ...config,
38
+ };
39
+ }
40
+ // ============================================================================
41
+ // Store
42
+ // ============================================================================
43
+ store(input) {
44
+ const now = new Date();
45
+ const id = (0, crypto_1.randomUUID)();
46
+ const memory = {
47
+ ...input,
48
+ id,
49
+ created: now,
50
+ lastAccessed: now,
51
+ accessCount: 1,
52
+ };
53
+ // Check for existing skill
54
+ const existingId = this.byName.get(memory.content.name.toLowerCase());
55
+ if (existingId) {
56
+ // Update existing skill
57
+ return this.improveSkill(existingId, memory);
58
+ }
59
+ this.memories.set(id, memory);
60
+ this.updateIndexes(memory);
61
+ this.maintainSize();
62
+ return memory;
63
+ }
64
+ /**
65
+ * Convenience method to create a procedural memory from options
66
+ */
67
+ createSkill(options) {
68
+ const now = new Date();
69
+ const params = (0, forgetting_js_1.calculateInitialParams)({
70
+ importance: options.importance,
71
+ complexity: Math.min(1, options.steps.length / 10), // More steps = more complex
72
+ });
73
+ // Skills have higher base stability (muscle memory)
74
+ params.S = 7; // 1 week base stability
75
+ const steps = options.steps.map((s, i) => ({
76
+ order: i + 1,
77
+ action: s.action,
78
+ params: s.params,
79
+ condition: s.condition,
80
+ fallback: s.fallback,
81
+ }));
82
+ return this.store({
83
+ type: 'procedural',
84
+ content: {
85
+ name: options.name,
86
+ description: options.description,
87
+ steps,
88
+ },
89
+ requires: options.requires || [],
90
+ inputs: options.inputs || [],
91
+ outputs: options.outputs || [],
92
+ successRate: 0.5, // Initial neutral rate
93
+ avgDuration: 0,
94
+ executionCount: 0,
95
+ version: 1,
96
+ improvements: [],
97
+ R0: params.R0,
98
+ S: params.S,
99
+ importance: options.importance || 0.5,
100
+ emotionalValence: 0,
101
+ associations: options.associations || [],
102
+ tags: options.tags || [],
103
+ consolidated: true, // Procedural memories are already consolidated
104
+ source: options.source,
105
+ });
106
+ }
107
+ /**
108
+ * Improve an existing skill with new information
109
+ */
110
+ improveSkill(existingId, newMemory) {
111
+ const existing = this.memories.get(existingId);
112
+ if (!existing) {
113
+ return newMemory;
114
+ }
115
+ // Compare steps and merge improvements
116
+ if (newMemory.content.steps.length !== existing.content.steps.length) {
117
+ // Steps changed - this is a new version
118
+ existing.version++;
119
+ existing.improvements.push(`v${existing.version}: Steps updated from ${existing.content.steps.length} to ${newMemory.content.steps.length}`);
120
+ existing.content.steps = newMemory.content.steps;
121
+ }
122
+ // Merge prerequisites
123
+ existing.requires = [...new Set([...existing.requires, ...newMemory.requires])];
124
+ // Update description if better
125
+ if (newMemory.content.description.length > existing.content.description.length) {
126
+ existing.content.description = newMemory.content.description;
127
+ }
128
+ // Strengthen memory
129
+ existing.S = (0, forgetting_js_1.updateStabilityOnRecall)(existing, true);
130
+ existing.lastAccessed = new Date();
131
+ return existing;
132
+ }
133
+ // ============================================================================
134
+ // Get / Update / Delete
135
+ // ============================================================================
136
+ get(id) {
137
+ const memory = this.memories.get(id);
138
+ if (memory) {
139
+ this.accessMemory(memory);
140
+ }
141
+ return memory;
142
+ }
143
+ /**
144
+ * Get by skill name
145
+ */
146
+ getByName(name) {
147
+ const id = this.byName.get(name.toLowerCase());
148
+ if (id) {
149
+ return this.get(id);
150
+ }
151
+ return undefined;
152
+ }
153
+ /**
154
+ * Get without updating access (for internal use)
155
+ */
156
+ peek(id) {
157
+ return this.memories.get(id);
158
+ }
159
+ update(id, updates) {
160
+ const memory = this.memories.get(id);
161
+ if (!memory)
162
+ return undefined;
163
+ // Remove from indexes before update
164
+ this.removeFromIndexes(memory);
165
+ // Apply updates
166
+ Object.assign(memory, updates);
167
+ // Re-add to indexes
168
+ this.updateIndexes(memory);
169
+ return memory;
170
+ }
171
+ delete(id) {
172
+ const memory = this.memories.get(id);
173
+ if (!memory)
174
+ return false;
175
+ this.removeFromIndexes(memory);
176
+ this.memories.delete(id);
177
+ return true;
178
+ }
179
+ // ============================================================================
180
+ // Query
181
+ // ============================================================================
182
+ query(filter) {
183
+ let results = this.getAll();
184
+ if (filter.minImportance !== undefined) {
185
+ results = results.filter((m) => m.importance >= filter.minImportance);
186
+ }
187
+ if (filter.maxAge !== undefined) {
188
+ const cutoff = Date.now() - filter.maxAge * 24 * 60 * 60 * 1000;
189
+ results = results.filter((m) => m.created.getTime() >= cutoff);
190
+ }
191
+ if (filter.minRetention !== undefined) {
192
+ results = results.filter((m) => {
193
+ const retention = (0, forgetting_js_1.calculateRetention)({ R0: m.R0, S: m.S }, m.lastAccessed.getTime());
194
+ return retention >= filter.minRetention;
195
+ });
196
+ }
197
+ if (filter.tags && filter.tags.length > 0) {
198
+ results = results.filter((m) => filter.tags.some((t) => m.tags.includes(t)));
199
+ }
200
+ if (filter.custom) {
201
+ results = results.filter(filter.custom);
202
+ }
203
+ return results;
204
+ }
205
+ /**
206
+ * Search by keyword in name and description
207
+ */
208
+ search(queryStr, limit = 10) {
209
+ const keywords = queryStr.toLowerCase().split(/\s+/);
210
+ const results = this.getAll().filter((m) => {
211
+ const searchable = [
212
+ m.content.name,
213
+ m.content.description,
214
+ ...m.tags,
215
+ ].join(' ').toLowerCase();
216
+ return keywords.some((k) => searchable.includes(k));
217
+ });
218
+ // Sort by success rate * retention
219
+ results.sort((a, b) => {
220
+ const scoreA = a.successRate * (0, forgetting_js_1.calculateRetention)({ R0: a.R0, S: a.S }, a.lastAccessed.getTime());
221
+ const scoreB = b.successRate * (0, forgetting_js_1.calculateRetention)({ R0: b.R0, S: b.S }, b.lastAccessed.getTime());
222
+ return scoreB - scoreA;
223
+ });
224
+ return results.slice(0, limit);
225
+ }
226
+ // ============================================================================
227
+ // Execution Tracking
228
+ // ============================================================================
229
+ /**
230
+ * Record execution of a skill
231
+ */
232
+ recordExecution(id, result) {
233
+ const memory = this.memories.get(id);
234
+ if (!memory)
235
+ return;
236
+ memory.executionCount++;
237
+ // Update success rate (exponential moving average)
238
+ const alpha = 0.2;
239
+ memory.successRate = alpha * (result.success ? 1 : 0) + (1 - alpha) * memory.successRate;
240
+ // Update average duration
241
+ if (result.duration > 0) {
242
+ if (memory.avgDuration === 0) {
243
+ memory.avgDuration = result.duration;
244
+ }
245
+ else {
246
+ memory.avgDuration = alpha * result.duration + (1 - alpha) * memory.avgDuration;
247
+ }
248
+ }
249
+ // Update stability based on success
250
+ memory.S = (0, forgetting_js_1.updateStabilityOnRecall)(memory, result.success);
251
+ memory.lastAccessed = new Date();
252
+ // Track improvements
253
+ if (result.success && memory.successRate > 0.8 && !memory.improvements.includes('Mastered')) {
254
+ memory.improvements.push('Mastered');
255
+ }
256
+ }
257
+ /**
258
+ * Get skills that need practice (low success rate or retention)
259
+ */
260
+ getSkillsNeedingPractice() {
261
+ return this.getAll().filter((m) => {
262
+ const retention = (0, forgetting_js_1.calculateRetention)({ R0: m.R0, S: m.S }, m.lastAccessed.getTime());
263
+ return (m.successRate < 0.7 || retention < 0.5) &&
264
+ retention >= forgetting_js_1.FORGETTING_THRESHOLDS.FORGET;
265
+ });
266
+ }
267
+ /**
268
+ * Get mastered skills (high success rate and retention)
269
+ */
270
+ getMasteredSkills() {
271
+ return this.getAll().filter((m) => {
272
+ const retention = (0, forgetting_js_1.calculateRetention)({ R0: m.R0, S: m.S }, m.lastAccessed.getTime());
273
+ return m.successRate >= 0.9 && retention >= 0.8;
274
+ });
275
+ }
276
+ // ============================================================================
277
+ // Dependency Queries
278
+ // ============================================================================
279
+ /**
280
+ * Get prerequisites for a skill
281
+ */
282
+ getPrerequisites(id) {
283
+ const memory = this.memories.get(id);
284
+ if (!memory)
285
+ return [];
286
+ return memory.requires
287
+ .map((name) => this.getByName(name))
288
+ .filter((m) => m !== undefined);
289
+ }
290
+ /**
291
+ * Get skills that depend on this skill
292
+ */
293
+ getDependents(id) {
294
+ const memory = this.memories.get(id);
295
+ if (!memory)
296
+ return [];
297
+ const dependentIds = this.dependencies.get(memory.content.name.toLowerCase());
298
+ if (!dependentIds)
299
+ return [];
300
+ return Array.from(dependentIds)
301
+ .map((depId) => this.memories.get(depId))
302
+ .filter((m) => m !== undefined);
303
+ }
304
+ /**
305
+ * Check if all prerequisites are met for a skill
306
+ */
307
+ canExecute(id, minSuccessRate = 0.5) {
308
+ const prerequisites = this.getPrerequisites(id);
309
+ return prerequisites.every((p) => p.successRate >= minSuccessRate);
310
+ }
311
+ // ============================================================================
312
+ // Bulk Operations
313
+ // ============================================================================
314
+ getAll() {
315
+ return Array.from(this.memories.values());
316
+ }
317
+ clear() {
318
+ this.memories.clear();
319
+ this.byName.clear();
320
+ this.byTag.clear();
321
+ this.dependencies.clear();
322
+ }
323
+ count() {
324
+ return this.memories.size;
325
+ }
326
+ // ============================================================================
327
+ // Stats
328
+ // ============================================================================
329
+ stats() {
330
+ const all = this.getAll();
331
+ let totalRetention = 0;
332
+ let totalImportance = 0;
333
+ let consolidated = 0;
334
+ let oldest;
335
+ let newest;
336
+ for (const memory of all) {
337
+ totalRetention += (0, forgetting_js_1.calculateRetention)({ R0: memory.R0, S: memory.S }, memory.lastAccessed.getTime());
338
+ totalImportance += memory.importance;
339
+ if (memory.consolidated)
340
+ consolidated++;
341
+ if (!oldest || memory.created < oldest)
342
+ oldest = memory.created;
343
+ if (!newest || memory.created > newest)
344
+ newest = memory.created;
345
+ }
346
+ return {
347
+ total: all.length,
348
+ byType: {
349
+ episodic: 0,
350
+ semantic: 0,
351
+ procedural: all.length,
352
+ },
353
+ consolidated,
354
+ avgRetention: all.length > 0 ? totalRetention / all.length : 0,
355
+ avgImportance: all.length > 0 ? totalImportance / all.length : 0,
356
+ oldestMemory: oldest,
357
+ newestMemory: newest,
358
+ };
359
+ }
360
+ /**
361
+ * Get additional procedural-specific stats
362
+ */
363
+ proceduralStats() {
364
+ const all = this.getAll();
365
+ let totalSuccessRate = 0;
366
+ let totalExecutions = 0;
367
+ for (const m of all) {
368
+ totalSuccessRate += m.successRate;
369
+ totalExecutions += m.executionCount;
370
+ }
371
+ const mastered = this.getMasteredSkills().length;
372
+ const needsPractice = this.getSkillsNeedingPractice().length;
373
+ const mostUsed = [...all]
374
+ .sort((a, b) => b.executionCount - a.executionCount)
375
+ .slice(0, 10);
376
+ return {
377
+ totalSkills: all.length,
378
+ mastered,
379
+ needsPractice,
380
+ avgSuccessRate: all.length > 0 ? totalSuccessRate / all.length : 0,
381
+ avgExecutions: all.length > 0 ? totalExecutions / all.length : 0,
382
+ mostUsed,
383
+ };
384
+ }
385
+ // ============================================================================
386
+ // Forgetting Integration
387
+ // ============================================================================
388
+ /**
389
+ * Get skills that should be forgotten (low retention AND low success)
390
+ */
391
+ getForgotten() {
392
+ return this.getAll().filter((m) => {
393
+ const retention = (0, forgetting_js_1.calculateRetention)({ R0: m.R0, S: m.S }, m.lastAccessed.getTime());
394
+ return retention < this.config.forgetThreshold &&
395
+ m.successRate < this.config.minSuccessRate;
396
+ });
397
+ }
398
+ /**
399
+ * Run forgetting cycle
400
+ */
401
+ runForgetting() {
402
+ const toForget = this.getForgotten();
403
+ const ids = toForget.map((m) => m.id);
404
+ for (const id of ids) {
405
+ this.delete(id);
406
+ }
407
+ return { forgotten: ids.length, ids };
408
+ }
409
+ // ============================================================================
410
+ // Private Methods
411
+ // ============================================================================
412
+ accessMemory(memory) {
413
+ memory.lastAccessed = new Date();
414
+ memory.accessCount++;
415
+ memory.S = (0, forgetting_js_1.updateStabilityOnRecall)(memory, true);
416
+ }
417
+ updateIndexes(memory) {
418
+ // Name index
419
+ this.byName.set(memory.content.name.toLowerCase(), memory.id);
420
+ // Tag index
421
+ for (const tag of memory.tags) {
422
+ if (!this.byTag.has(tag)) {
423
+ this.byTag.set(tag, new Set());
424
+ }
425
+ this.byTag.get(tag).add(memory.id);
426
+ }
427
+ // Dependency index
428
+ for (const req of memory.requires) {
429
+ const reqLower = req.toLowerCase();
430
+ if (!this.dependencies.has(reqLower)) {
431
+ this.dependencies.set(reqLower, new Set());
432
+ }
433
+ this.dependencies.get(reqLower).add(memory.id);
434
+ }
435
+ }
436
+ removeFromIndexes(memory) {
437
+ this.byName.delete(memory.content.name.toLowerCase());
438
+ for (const tag of memory.tags) {
439
+ this.byTag.get(tag)?.delete(memory.id);
440
+ }
441
+ for (const req of memory.requires) {
442
+ this.dependencies.get(req.toLowerCase())?.delete(memory.id);
443
+ }
444
+ }
445
+ maintainSize() {
446
+ if (!this.config.autoForget)
447
+ return;
448
+ if (this.memories.size <= this.config.maxSize)
449
+ return;
450
+ // First, forget low-performance skills
451
+ this.runForgetting();
452
+ // If still over limit, remove lowest scoring skills
453
+ while (this.memories.size > this.config.maxSize) {
454
+ let weakest = null;
455
+ let weakestScore = Infinity;
456
+ for (const memory of this.memories.values()) {
457
+ const retention = (0, forgetting_js_1.calculateRetention)({ R0: memory.R0, S: memory.S }, memory.lastAccessed.getTime());
458
+ const score = memory.successRate * retention;
459
+ if (score < weakestScore) {
460
+ weakestScore = score;
461
+ weakest = memory;
462
+ }
463
+ }
464
+ if (weakest) {
465
+ this.delete(weakest.id);
466
+ }
467
+ else {
468
+ break;
469
+ }
470
+ }
471
+ }
472
+ }
473
+ exports.ProceduralStore = ProceduralStore;
474
+ // ============================================================================
475
+ // Factory
476
+ // ============================================================================
477
+ function createProceduralStore(config) {
478
+ return new ProceduralStore(config);
479
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Genesis 6.0 - Semantic Memory Store
3
+ *
4
+ * Stores facts and concepts - encyclopedic knowledge.
5
+ * "What things mean, general knowledge"
6
+ *
7
+ * Key features:
8
+ * - Concept hierarchy (superordinates, subordinates)
9
+ * - Category-based organization
10
+ * - Confidence tracking
11
+ * - Contradiction detection
12
+ *
13
+ * Reference: Tulving, E. (1972). Episodic and semantic memory.
14
+ */
15
+ import { SemanticMemory, IMemoryStore, MemoryFilter, StoreStats } from './types.js';
16
+ export interface SemanticStoreConfig {
17
+ maxSize: number;
18
+ autoForget: boolean;
19
+ forgetThreshold: number;
20
+ defaultStability: number;
21
+ minConfidence: number;
22
+ }
23
+ export interface CreateSemanticOptions {
24
+ concept: string;
25
+ definition?: string;
26
+ properties?: Record<string, any>;
27
+ category: string;
28
+ superordinates?: string[];
29
+ subordinates?: string[];
30
+ related?: string[];
31
+ confidence?: number;
32
+ sources?: string[];
33
+ importance?: number;
34
+ tags?: string[];
35
+ associations?: string[];
36
+ }
37
+ export declare class SemanticStore implements IMemoryStore<SemanticMemory> {
38
+ private memories;
39
+ private config;
40
+ private byConcept;
41
+ private byCategory;
42
+ private byTag;
43
+ private hierarchy;
44
+ constructor(config?: Partial<SemanticStoreConfig>);
45
+ store(input: Omit<SemanticMemory, 'id' | 'created' | 'lastAccessed' | 'accessCount'>): SemanticMemory;
46
+ /**
47
+ * Convenience method to create a semantic memory from options
48
+ */
49
+ createFact(options: CreateSemanticOptions): SemanticMemory;
50
+ /**
51
+ * Merge new information with existing concept
52
+ */
53
+ private mergeWith;
54
+ get(id: string): SemanticMemory | undefined;
55
+ /**
56
+ * Get by concept name
57
+ */
58
+ getByConcept(concept: string): SemanticMemory | undefined;
59
+ /**
60
+ * Get without updating access (for internal use)
61
+ */
62
+ peek(id: string): SemanticMemory | undefined;
63
+ update(id: string, updates: Partial<SemanticMemory>): SemanticMemory | undefined;
64
+ delete(id: string): boolean;
65
+ query(filter: MemoryFilter<SemanticMemory>): SemanticMemory[];
66
+ /**
67
+ * Search by keyword in concept and definition
68
+ */
69
+ search(queryStr: string, limit?: number): SemanticMemory[];
70
+ /**
71
+ * Get all facts in a category
72
+ */
73
+ getByCategory(category: string): SemanticMemory[];
74
+ /**
75
+ * Get all categories
76
+ */
77
+ getCategories(): string[];
78
+ /**
79
+ * Get superordinate concepts (more general)
80
+ */
81
+ getSuperordinates(id: string): SemanticMemory[];
82
+ /**
83
+ * Get subordinate concepts (more specific)
84
+ */
85
+ getSubordinates(id: string): SemanticMemory[];
86
+ /**
87
+ * Get related concepts
88
+ */
89
+ getRelated(id: string): SemanticMemory[];
90
+ /**
91
+ * Check if a new fact contradicts existing knowledge
92
+ */
93
+ findContradictions(concept: string, properties: Record<string, any>): SemanticMemory[];
94
+ /**
95
+ * Get all facts with contradictions
96
+ */
97
+ getContradictedFacts(): SemanticMemory[];
98
+ /**
99
+ * Record a contradiction
100
+ */
101
+ addContradiction(id: string, contradictingId: string): void;
102
+ getAll(): SemanticMemory[];
103
+ clear(): void;
104
+ count(): number;
105
+ stats(): StoreStats;
106
+ /**
107
+ * Get additional semantic-specific stats
108
+ */
109
+ semanticStats(): {
110
+ totalFacts: number;
111
+ categories: number;
112
+ avgConfidence: number;
113
+ contradictions: number;
114
+ mostUsed: SemanticMemory[];
115
+ };
116
+ /**
117
+ * Get facts that should be forgotten (low retention AND low confidence)
118
+ */
119
+ getForgotten(): SemanticMemory[];
120
+ /**
121
+ * Run forgetting cycle
122
+ */
123
+ runForgetting(): {
124
+ forgotten: number;
125
+ ids: string[];
126
+ };
127
+ private accessMemory;
128
+ private updateIndexes;
129
+ private removeFromIndexes;
130
+ private maintainSize;
131
+ }
132
+ export declare function createSemanticStore(config?: Partial<SemanticStoreConfig>): SemanticStore;