atlas-mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.env.example +32 -0
  2. package/README.md +282 -0
  3. package/package.json +72 -0
  4. package/public/app/assets/app-CxbS1w9p.js +3981 -0
  5. package/public/app/assets/index-BA6nxCuI.css +1 -0
  6. package/public/app/assets/index-BXmIRrQH.js +177 -0
  7. package/public/app/index.html +27 -0
  8. package/public/assets/brain-atlas.LICENSE.txt +16 -0
  9. package/public/assets/brain-atlas.glb +0 -0
  10. package/public/assets/brain.obj +27282 -0
  11. package/public/fonts/DepartureMono-Regular.woff +0 -0
  12. package/public/fonts/DepartureMono-Regular.woff2 +0 -0
  13. package/scripts/sync-memory-vectors.js +46 -0
  14. package/src/audit.js +9 -0
  15. package/src/cli/args.js +87 -0
  16. package/src/cli/commands/add.js +103 -0
  17. package/src/cli/commands/config.js +228 -0
  18. package/src/cli/commands/delete.js +75 -0
  19. package/src/cli/commands/entities.js +39 -0
  20. package/src/cli/commands/entity.js +47 -0
  21. package/src/cli/commands/get.js +46 -0
  22. package/src/cli/commands/list.js +53 -0
  23. package/src/cli/commands/related.js +56 -0
  24. package/src/cli/commands/search.js +68 -0
  25. package/src/cli/commands/update.js +58 -0
  26. package/src/cli/deps.js +114 -0
  27. package/src/cli/env-file.js +44 -0
  28. package/src/cli/format.js +246 -0
  29. package/src/cli.js +187 -0
  30. package/src/cognitive-worker.js +381 -0
  31. package/src/db.js +2674 -0
  32. package/src/extraction-context.js +31 -0
  33. package/src/ingestion-service.js +387 -0
  34. package/src/ingestion-worker.js +225 -0
  35. package/src/llm-config.js +31 -0
  36. package/src/llm.js +789 -0
  37. package/src/logger.js +51 -0
  38. package/src/mcp-server.js +577 -0
  39. package/src/memory-comparison.js +421 -0
  40. package/src/related-memories.js +232 -0
  41. package/src/run-cognitive-worker.js +12 -0
  42. package/src/run-ingestion-worker.js +13 -0
  43. package/src/run-vector-worker.js +12 -0
  44. package/src/schemas.js +413 -0
  45. package/src/semantic-validation.js +430 -0
  46. package/src/server.js +827 -0
  47. package/src/shared/brain-regions.js +61 -0
  48. package/src/shared/entity-lens.js +249 -0
  49. package/src/shared/memory-placement.js +171 -0
  50. package/src/shared/memory-search.js +55 -0
  51. package/src/shared/region-anchors.js +112 -0
  52. package/src/shared/region-mapper.js +247 -0
  53. package/src/vector-store.js +546 -0
  54. package/src/vector-worker.js +71 -0
@@ -0,0 +1,247 @@
1
+ export const REGION_MAPPING_VERSION = 2;
2
+
3
+ export const REGION_NAMES = Object.freeze([
4
+ "hippocampus",
5
+ "prefrontal",
6
+ "associationCortex",
7
+ "temporalCortex",
8
+ "basalGanglia",
9
+ "cerebellum",
10
+ "motorCortex",
11
+ "amygdala",
12
+ "insula",
13
+ "entorhinal",
14
+ "parietalCortex",
15
+ ]);
16
+
17
+ const REGION_RULES = Object.freeze({
18
+ episodic: {
19
+ hippocampus: 0.65,
20
+ prefrontal: 0.2,
21
+ associationCortex: 0.15,
22
+ },
23
+ semantic: {
24
+ temporalCortex: 0.55,
25
+ associationCortex: 0.35,
26
+ prefrontal: 0.1,
27
+ },
28
+ procedural: {
29
+ basalGanglia: 0.45,
30
+ cerebellum: 0.35,
31
+ motorCortex: 0.2,
32
+ },
33
+ emotional: {
34
+ amygdala: 0.5,
35
+ insula: 0.25,
36
+ prefrontal: 0.15,
37
+ hippocampus: 0.1,
38
+ },
39
+ spatial: {
40
+ hippocampus: 0.4,
41
+ entorhinal: 0.3,
42
+ parietalCortex: 0.3,
43
+ },
44
+ working: {
45
+ prefrontal: 0.6,
46
+ parietalCortex: 0.4,
47
+ },
48
+ });
49
+
50
+ // Contributions below this level do not produce a useful visible activation.
51
+ export const MIN_REGION_ACTIVATION = 0.01;
52
+
53
+ const EMOTION_REGION_RULE = Object.freeze({
54
+ amygdala: 0.65,
55
+ insula: 0.35,
56
+ });
57
+ const MOTOR_ACTION_ACTIVATION = 0.2;
58
+ const PHYSICAL_ACTION_PATTERN =
59
+ /\b(?:climb|climbed|climbing|crawl|crawled|crawling|dance|danced|dancing|drive|drove|driving|exercise|exercised|exercising|grab|grabbed|grabbing|jump|jumped|jumping|kick|kicked|kicking|lift|lifted|lifting|move|moved|moving|play|played|playing|pull|pulled|pulling|push|pushed|pushing|ride|rode|riding|run|ran|running|swim|swam|swimming|throw|threw|throwing|walk|walked|walking|write|wrote|writing)\b/i;
60
+
61
+ function finiteUnit(value) {
62
+ const number = Number(value);
63
+ if (!Number.isFinite(number)) return 0;
64
+ return Math.max(0, Math.min(1, number));
65
+ }
66
+
67
+ function normalizeSemanticExtraction(extraction = {}) {
68
+ return {
69
+ ...extraction,
70
+ types: Array.isArray(extraction.types) ? extraction.types : [],
71
+ actions: Array.isArray(extraction.actions) ? extraction.actions : [],
72
+ };
73
+ }
74
+
75
+ export function mergeSemanticAndCognitive(semantic = {}, cognitive = {}) {
76
+ const normalized = normalizeSemanticExtraction(semantic);
77
+ return {
78
+ ...normalized,
79
+ emotions: Array.isArray(cognitive.emotions) ? cognitive.emotions : [],
80
+ contentCues: Array.isArray(cognitive.contentCues)
81
+ ? cognitive.contentCues
82
+ : [],
83
+ salience: finiteUnit(cognitive.salience),
84
+ };
85
+ }
86
+
87
+ function normalizeMappingInput(extraction = {}) {
88
+ return {
89
+ ...normalizeSemanticExtraction(extraction),
90
+ emotions: Array.isArray(extraction.emotions) ? extraction.emotions : [],
91
+ contentCues: Array.isArray(extraction.contentCues)
92
+ ? extraction.contentCues
93
+ : [],
94
+ };
95
+ }
96
+
97
+ function addContribution(totals, region, amount) {
98
+ if (Number.isFinite(amount) && amount > 0) {
99
+ totals.set(region, (totals.get(region) || 0) + amount);
100
+ }
101
+ }
102
+
103
+ function maxSignal(items) {
104
+ return items.reduce((maximum, value) => Math.max(maximum, value), 0);
105
+ }
106
+
107
+ export function getHippocampalLaterality(extraction) {
108
+ const normalized = normalizeMappingInput(extraction);
109
+ const activeCues = normalized.contentCues.filter(
110
+ ({ weight, confidence }) =>
111
+ finiteUnit(weight) > 0 && finiteUnit(confidence) > 0,
112
+ );
113
+ const verbalCues = activeCues.filter(({ kind }) => kind === "verbal");
114
+ const spatialCues = activeCues.filter(({ kind }) => kind === "spatial");
115
+ const verbalSignal = maxSignal(
116
+ verbalCues.map(
117
+ ({ weight, confidence }) => finiteUnit(weight) * finiteUnit(confidence),
118
+ ),
119
+ );
120
+ const spatialTypeSignal = maxSignal(
121
+ normalized.types
122
+ .filter(({ type }) => type === "spatial")
123
+ .map(({ weight }) => finiteUnit(weight)),
124
+ );
125
+ const spatialCueSignal = maxSignal(
126
+ spatialCues.map(
127
+ ({ weight, confidence }) => finiteUnit(weight) * finiteUnit(confidence),
128
+ ),
129
+ );
130
+ const spatialSignal = Math.max(spatialTypeSignal, spatialCueSignal);
131
+ const bias = Math.max(
132
+ -0.15,
133
+ Math.min(0.15, 0.15 * (spatialSignal - verbalSignal)),
134
+ );
135
+
136
+ return {
137
+ leftShare: 0.5 - bias,
138
+ rightShare: 0.5 + bias,
139
+ verbalSignal,
140
+ spatialSignal,
141
+ cues: [...verbalCues, ...spatialCues],
142
+ };
143
+ }
144
+
145
+ export function getRegionContributions(extraction) {
146
+ const normalized = normalizeMappingInput(extraction);
147
+ const contributions = [];
148
+
149
+ for (const { type, weight: rawWeight } of normalized.types) {
150
+ const rule = REGION_RULES[type];
151
+ const weight = finiteUnit(rawWeight);
152
+ if (!rule || weight <= 0) continue;
153
+
154
+ for (const [region, regionWeight] of Object.entries(rule)) {
155
+ contributions.push({
156
+ region,
157
+ source: "type",
158
+ type,
159
+ typeWeight: weight,
160
+ ruleWeight: regionWeight,
161
+ amount: weight * regionWeight,
162
+ });
163
+ }
164
+ }
165
+
166
+ for (const emotion of normalized.emotions) {
167
+ const intensity = finiteUnit(emotion.intensity);
168
+ const arousal = finiteUnit(emotion.arousal);
169
+ const emotionActivation = intensity * arousal;
170
+ if (emotionActivation <= 0) continue;
171
+
172
+ for (const [region, regionWeight] of Object.entries(EMOTION_REGION_RULE)) {
173
+ contributions.push({
174
+ region,
175
+ source: "emotion",
176
+ label: emotion.label,
177
+ intensity,
178
+ arousal,
179
+ confidence: emotion.confidence,
180
+ ruleWeight: regionWeight,
181
+ amount: emotionActivation * regionWeight,
182
+ });
183
+ }
184
+ }
185
+
186
+ const physicalAction = normalized.actions.find(
187
+ (action) =>
188
+ typeof action === "string" && PHYSICAL_ACTION_PATTERN.test(action),
189
+ );
190
+ if (physicalAction) {
191
+ contributions.push({
192
+ region: "motorCortex",
193
+ source: "action",
194
+ action: physicalAction,
195
+ amount: MOTOR_ACTION_ACTIVATION,
196
+ });
197
+ }
198
+
199
+ return contributions;
200
+ }
201
+
202
+ export function mapExtractionToRegions(extraction) {
203
+ const normalized = normalizeMappingInput(extraction);
204
+ const totals = new Map();
205
+
206
+ for (const { region, amount } of getRegionContributions(normalized)) {
207
+ addContribution(totals, region, amount);
208
+ }
209
+
210
+ const significant = [...totals.entries()].filter(
211
+ ([, weight]) => weight >= MIN_REGION_ACTIVATION,
212
+ );
213
+ const totalWeight = significant.reduce((sum, [, weight]) => sum + weight, 0);
214
+
215
+ if (totalWeight === 0) return [];
216
+
217
+ const laterality = getHippocampalLaterality(normalized);
218
+
219
+ return significant
220
+ .map(([region, weight]) => {
221
+ const normalizedWeight = weight / totalWeight;
222
+ if (region !== "hippocampus") {
223
+ return { region, weight: normalizedWeight };
224
+ }
225
+
226
+ const left = normalizedWeight * laterality.leftShare;
227
+ return {
228
+ region,
229
+ weight: normalizedWeight,
230
+ hemispheres: {
231
+ left,
232
+ right: normalizedWeight - left,
233
+ },
234
+ };
235
+ })
236
+ .sort((a, b) => b.weight - a.weight || a.region.localeCompare(b.region));
237
+ }
238
+
239
+ export function mapSemanticToRegions(semantic) {
240
+ return mapExtractionToRegions(normalizeSemanticExtraction(semantic));
241
+ }
242
+
243
+ export function mapSemanticAndCognitiveToRegions(semantic, cognitive) {
244
+ return mapExtractionToRegions(
245
+ mergeSemanticAndCognitive(semantic, cognitive),
246
+ );
247
+ }