stellar-memory 0.5.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/LICENSE +21 -0
- package/README.md +362 -0
- package/dist/api/routes/analytics.d.ts +15 -0
- package/dist/api/routes/analytics.js +131 -0
- package/dist/api/routes/analytics.js.map +1 -0
- package/dist/api/routes/conflicts.d.ts +12 -0
- package/dist/api/routes/conflicts.js +67 -0
- package/dist/api/routes/conflicts.js.map +1 -0
- package/dist/api/routes/consolidation.d.ts +11 -0
- package/dist/api/routes/consolidation.js +63 -0
- package/dist/api/routes/consolidation.js.map +1 -0
- package/dist/api/routes/constellation.d.ts +4 -0
- package/dist/api/routes/constellation.js +84 -0
- package/dist/api/routes/constellation.js.map +1 -0
- package/dist/api/routes/memories.d.ts +4 -0
- package/dist/api/routes/memories.js +219 -0
- package/dist/api/routes/memories.js.map +1 -0
- package/dist/api/routes/observations.d.ts +10 -0
- package/dist/api/routes/observations.js +42 -0
- package/dist/api/routes/observations.js.map +1 -0
- package/dist/api/routes/orbit.d.ts +4 -0
- package/dist/api/routes/orbit.js +71 -0
- package/dist/api/routes/orbit.js.map +1 -0
- package/dist/api/routes/projects.d.ts +15 -0
- package/dist/api/routes/projects.js +121 -0
- package/dist/api/routes/projects.js.map +1 -0
- package/dist/api/routes/scan.d.ts +4 -0
- package/dist/api/routes/scan.js +403 -0
- package/dist/api/routes/scan.js.map +1 -0
- package/dist/api/routes/sun.d.ts +4 -0
- package/dist/api/routes/sun.js +43 -0
- package/dist/api/routes/sun.js.map +1 -0
- package/dist/api/routes/system.d.ts +4 -0
- package/dist/api/routes/system.js +70 -0
- package/dist/api/routes/system.js.map +1 -0
- package/dist/api/routes/temporal.d.ts +13 -0
- package/dist/api/routes/temporal.js +82 -0
- package/dist/api/routes/temporal.js.map +1 -0
- package/dist/api/server.d.ts +2 -0
- package/dist/api/server.js +99 -0
- package/dist/api/server.js.map +1 -0
- package/dist/api/websocket.d.ts +53 -0
- package/dist/api/websocket.js +168 -0
- package/dist/api/websocket.js.map +1 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.js +35 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +10 -0
- package/dist/cli/init.js +163 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/engine/analytics.d.ts +93 -0
- package/dist/engine/analytics.js +437 -0
- package/dist/engine/analytics.js.map +1 -0
- package/dist/engine/conflict.d.ts +54 -0
- package/dist/engine/conflict.js +322 -0
- package/dist/engine/conflict.js.map +1 -0
- package/dist/engine/consolidation.d.ts +83 -0
- package/dist/engine/consolidation.js +368 -0
- package/dist/engine/consolidation.js.map +1 -0
- package/dist/engine/constellation.d.ts +66 -0
- package/dist/engine/constellation.js +382 -0
- package/dist/engine/constellation.js.map +1 -0
- package/dist/engine/corona.d.ts +53 -0
- package/dist/engine/corona.js +181 -0
- package/dist/engine/corona.js.map +1 -0
- package/dist/engine/embedding.d.ts +44 -0
- package/dist/engine/embedding.js +168 -0
- package/dist/engine/embedding.js.map +1 -0
- package/dist/engine/gravity.d.ts +63 -0
- package/dist/engine/gravity.js +121 -0
- package/dist/engine/gravity.js.map +1 -0
- package/dist/engine/multiproject.d.ts +75 -0
- package/dist/engine/multiproject.js +241 -0
- package/dist/engine/multiproject.js.map +1 -0
- package/dist/engine/observation.d.ts +82 -0
- package/dist/engine/observation.js +357 -0
- package/dist/engine/observation.js.map +1 -0
- package/dist/engine/orbit.d.ts +91 -0
- package/dist/engine/orbit.js +249 -0
- package/dist/engine/orbit.js.map +1 -0
- package/dist/engine/planet.d.ts +64 -0
- package/dist/engine/planet.js +432 -0
- package/dist/engine/planet.js.map +1 -0
- package/dist/engine/procedural.d.ts +71 -0
- package/dist/engine/procedural.js +259 -0
- package/dist/engine/procedural.js.map +1 -0
- package/dist/engine/quality.d.ts +48 -0
- package/dist/engine/quality.js +245 -0
- package/dist/engine/quality.js.map +1 -0
- package/dist/engine/repository.d.ts +79 -0
- package/dist/engine/repository.js +13 -0
- package/dist/engine/repository.js.map +1 -0
- package/dist/engine/sun.d.ts +61 -0
- package/dist/engine/sun.js +240 -0
- package/dist/engine/sun.js.map +1 -0
- package/dist/engine/temporal.d.ts +67 -0
- package/dist/engine/temporal.js +283 -0
- package/dist/engine/temporal.js.map +1 -0
- package/dist/engine/types.d.ts +179 -0
- package/dist/engine/types.js +27 -0
- package/dist/engine/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/connector-registry.d.ts +20 -0
- package/dist/mcp/connector-registry.js +35 -0
- package/dist/mcp/connector-registry.js.map +1 -0
- package/dist/mcp/server.d.ts +13 -0
- package/dist/mcp/server.js +242 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/daemon-tool.d.ts +16 -0
- package/dist/mcp/tools/daemon-tool.js +58 -0
- package/dist/mcp/tools/daemon-tool.js.map +1 -0
- package/dist/mcp/tools/ingestion-tools.d.ts +20 -0
- package/dist/mcp/tools/ingestion-tools.js +34 -0
- package/dist/mcp/tools/ingestion-tools.js.map +1 -0
- package/dist/mcp/tools/memory-tools.d.ts +122 -0
- package/dist/mcp/tools/memory-tools.js +1037 -0
- package/dist/mcp/tools/memory-tools.js.map +1 -0
- package/dist/scanner/cloud/github.d.ts +34 -0
- package/dist/scanner/cloud/github.js +260 -0
- package/dist/scanner/cloud/github.js.map +1 -0
- package/dist/scanner/cloud/google-drive.d.ts +30 -0
- package/dist/scanner/cloud/google-drive.js +289 -0
- package/dist/scanner/cloud/google-drive.js.map +1 -0
- package/dist/scanner/cloud/notion.d.ts +33 -0
- package/dist/scanner/cloud/notion.js +231 -0
- package/dist/scanner/cloud/notion.js.map +1 -0
- package/dist/scanner/cloud/slack.d.ts +38 -0
- package/dist/scanner/cloud/slack.js +282 -0
- package/dist/scanner/cloud/slack.js.map +1 -0
- package/dist/scanner/cloud/types.d.ts +73 -0
- package/dist/scanner/cloud/types.js +9 -0
- package/dist/scanner/cloud/types.js.map +1 -0
- package/dist/scanner/index.d.ts +35 -0
- package/dist/scanner/index.js +420 -0
- package/dist/scanner/index.js.map +1 -0
- package/dist/scanner/local/filesystem.d.ts +33 -0
- package/dist/scanner/local/filesystem.js +203 -0
- package/dist/scanner/local/filesystem.js.map +1 -0
- package/dist/scanner/local/git.d.ts +24 -0
- package/dist/scanner/local/git.js +161 -0
- package/dist/scanner/local/git.js.map +1 -0
- package/dist/scanner/local/parsers/code.d.ts +3 -0
- package/dist/scanner/local/parsers/code.js +127 -0
- package/dist/scanner/local/parsers/code.js.map +1 -0
- package/dist/scanner/local/parsers/index.d.ts +11 -0
- package/dist/scanner/local/parsers/index.js +24 -0
- package/dist/scanner/local/parsers/index.js.map +1 -0
- package/dist/scanner/local/parsers/json-parser.d.ts +3 -0
- package/dist/scanner/local/parsers/json-parser.js +117 -0
- package/dist/scanner/local/parsers/json-parser.js.map +1 -0
- package/dist/scanner/local/parsers/markdown.d.ts +3 -0
- package/dist/scanner/local/parsers/markdown.js +120 -0
- package/dist/scanner/local/parsers/markdown.js.map +1 -0
- package/dist/scanner/local/parsers/text.d.ts +3 -0
- package/dist/scanner/local/parsers/text.js +41 -0
- package/dist/scanner/local/parsers/text.js.map +1 -0
- package/dist/scanner/metadata-scanner.d.ts +67 -0
- package/dist/scanner/metadata-scanner.js +356 -0
- package/dist/scanner/metadata-scanner.js.map +1 -0
- package/dist/scanner/types.d.ts +47 -0
- package/dist/scanner/types.js +19 -0
- package/dist/scanner/types.js.map +1 -0
- package/dist/service/daemon.d.ts +23 -0
- package/dist/service/daemon.js +105 -0
- package/dist/service/daemon.js.map +1 -0
- package/dist/service/scheduler.d.ts +73 -0
- package/dist/service/scheduler.js +281 -0
- package/dist/service/scheduler.js.map +1 -0
- package/dist/storage/database.d.ts +10 -0
- package/dist/storage/database.js +265 -0
- package/dist/storage/database.js.map +1 -0
- package/dist/storage/queries.d.ts +85 -0
- package/dist/storage/queries.js +865 -0
- package/dist/storage/queries.js.map +1 -0
- package/dist/storage/sqlite-repository.d.ts +32 -0
- package/dist/storage/sqlite-repository.js +68 -0
- package/dist/storage/sqlite-repository.js.map +1 -0
- package/dist/storage/vec.d.ts +62 -0
- package/dist/storage/vec.js +111 -0
- package/dist/storage/vec.js.map +1 -0
- package/dist/utils/config.d.ts +5 -0
- package/dist/utils/config.js +60 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/logger.d.ts +36 -0
- package/dist/utils/logger.js +86 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/time.d.ts +21 -0
- package/dist/utils/time.js +42 -0
- package/dist/utils/time.js.map +1 -0
- package/dist/utils/tokenizer.d.ts +13 -0
- package/dist/utils/tokenizer.js +46 -0
- package/dist/utils/tokenizer.js.map +1 -0
- package/package.json +77 -0
- package/scripts/check-node.mjs +36 -0
- package/scripts/setup.mjs +157 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* temporal.ts — Temporal Awareness engine
|
|
3
|
+
*
|
|
4
|
+
* Tracks when facts become valid/invalid over time. Memories can have
|
|
5
|
+
* temporal bounds (valid_from, valid_until) and can supersede each other
|
|
6
|
+
* when a concept evolves (e.g., "Chose Redis" → "Switched to Valkey").
|
|
7
|
+
*
|
|
8
|
+
* All functions are pure (no classes), following the project style.
|
|
9
|
+
*/
|
|
10
|
+
import { getDatabase } from '../storage/database.js';
|
|
11
|
+
import { getMemoriesAtTime, supersedMemory as queriesSupersedMemory, getSupersessionChain, } from '../storage/queries.js';
|
|
12
|
+
import { createLogger } from '../utils/logger.js';
|
|
13
|
+
const log = createLogger('temporal');
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Temporal bounds
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
/**
|
|
18
|
+
* Set temporal validity bounds on a memory.
|
|
19
|
+
*
|
|
20
|
+
* - validFrom: ISO date string. If omitted, the memory is valid from creation.
|
|
21
|
+
* - validUntil: ISO date string. Setting this marks the fact as no longer current.
|
|
22
|
+
*/
|
|
23
|
+
export function setTemporalBounds(memoryId, validFrom, validUntil) {
|
|
24
|
+
const db = getDatabase();
|
|
25
|
+
const now = new Date().toISOString();
|
|
26
|
+
const sets = ['updated_at = ?'];
|
|
27
|
+
const values = [now];
|
|
28
|
+
if (validFrom !== undefined) {
|
|
29
|
+
sets.push('valid_from = ?');
|
|
30
|
+
values.push(validFrom);
|
|
31
|
+
}
|
|
32
|
+
if (validUntil !== undefined) {
|
|
33
|
+
sets.push('valid_until = ?');
|
|
34
|
+
values.push(validUntil);
|
|
35
|
+
}
|
|
36
|
+
values.push(memoryId);
|
|
37
|
+
db.prepare(`UPDATE memories SET ${sets.join(', ')} WHERE id = ?`).run(...values);
|
|
38
|
+
log.debug('Temporal bounds set', { memoryId, validFrom, validUntil });
|
|
39
|
+
}
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// Supersession
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
/**
|
|
44
|
+
* Mark oldMemoryId as superseded by newMemoryId.
|
|
45
|
+
*
|
|
46
|
+
* Sets the old memory's valid_until to now and records superseded_by.
|
|
47
|
+
* Uses the existing queries.supersedMemory() helper.
|
|
48
|
+
*/
|
|
49
|
+
export function supersedeMemory(oldMemoryId, newMemoryId) {
|
|
50
|
+
queriesSupersedMemory(oldMemoryId, newMemoryId);
|
|
51
|
+
log.debug('Memory superseded', { oldMemoryId, newMemoryId });
|
|
52
|
+
}
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Point-in-time context
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
/**
|
|
57
|
+
* Return the set of memories that were active at the given timestamp.
|
|
58
|
+
*
|
|
59
|
+
* A memory is active if:
|
|
60
|
+
* valid_from IS NULL OR valid_from <= timestamp
|
|
61
|
+
* AND (valid_until IS NULL OR valid_until > timestamp)
|
|
62
|
+
*
|
|
63
|
+
* Results are sorted by importance descending.
|
|
64
|
+
*/
|
|
65
|
+
export function getContextAtTime(project, timestamp) {
|
|
66
|
+
const memories = getMemoriesAtTime(project, timestamp);
|
|
67
|
+
return memories.sort((a, b) => b.importance - a.importance);
|
|
68
|
+
}
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// Evolution chain
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
/**
|
|
73
|
+
* Follow the superseded_by chain forward from memoryId and also walk
|
|
74
|
+
* backward to find the earliest ancestor.
|
|
75
|
+
*
|
|
76
|
+
* Returns the full lineage in chronological order (oldest first).
|
|
77
|
+
*/
|
|
78
|
+
export function getEvolutionChain(memoryId) {
|
|
79
|
+
// First find the root (walk backward via content search is not feasible —
|
|
80
|
+
// we look for any memory whose superseded_by points to our target, recursively).
|
|
81
|
+
const root = findChainRoot(memoryId);
|
|
82
|
+
// Now walk forward from root using getSupersessionChain (follows superseded_by).
|
|
83
|
+
const chain = getSupersessionChain(root);
|
|
84
|
+
// Sort chronologically by created_at
|
|
85
|
+
return chain.sort((a, b) => a.created_at.localeCompare(b.created_at));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Walk backward to find the oldest ancestor in the supersession chain.
|
|
89
|
+
* A memory is a root if no other non-deleted memory has superseded_by = its id.
|
|
90
|
+
*/
|
|
91
|
+
function findChainRoot(memoryId) {
|
|
92
|
+
const db = getDatabase();
|
|
93
|
+
let currentId = memoryId;
|
|
94
|
+
for (let depth = 0; depth < 50; depth++) {
|
|
95
|
+
const row = db.prepare(`
|
|
96
|
+
SELECT id FROM memories
|
|
97
|
+
WHERE superseded_by = ? AND deleted_at IS NULL
|
|
98
|
+
LIMIT 1
|
|
99
|
+
`).get(currentId);
|
|
100
|
+
if (!row)
|
|
101
|
+
break;
|
|
102
|
+
currentId = row.id;
|
|
103
|
+
}
|
|
104
|
+
return currentId;
|
|
105
|
+
}
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
// Auto-detect supersession
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
/**
|
|
110
|
+
* Detect whether newMemory should supersede an existing memory.
|
|
111
|
+
*
|
|
112
|
+
* Heuristics (no LLM required):
|
|
113
|
+
* 1. Same memory type (especially 'decision')
|
|
114
|
+
* 2. High keyword overlap (>70% shared key terms)
|
|
115
|
+
* 3. Content contains a "switch" signal ("switched from", "replaced", "instead of", etc.)
|
|
116
|
+
* 4. Existing memory has not already been superseded
|
|
117
|
+
*
|
|
118
|
+
* Returns the memory that should be superseded, or null.
|
|
119
|
+
*/
|
|
120
|
+
export function detectSupersession(newMemory, existingMemories) {
|
|
121
|
+
const newTerms = extractKeyTerms(newMemory.content.toLowerCase());
|
|
122
|
+
const newLower = newMemory.content.toLowerCase();
|
|
123
|
+
// Detect switch signals in the new memory content
|
|
124
|
+
const SWITCH_PATTERNS = [
|
|
125
|
+
/switched?\s+from\s+(\w+)/i,
|
|
126
|
+
/replaced?\s+(\w+)/i,
|
|
127
|
+
/instead\s+of\s+(\w+)/i,
|
|
128
|
+
/moving?\s+(?:away\s+)?from\s+(\w+)/i,
|
|
129
|
+
/migrat\w+\s+from\s+(\w+)/i,
|
|
130
|
+
/no\s+longer\s+us\w+\s+(\w+)/i,
|
|
131
|
+
];
|
|
132
|
+
for (const existing of existingMemories) {
|
|
133
|
+
// Skip already-superseded memories
|
|
134
|
+
if (existing.superseded_by)
|
|
135
|
+
continue;
|
|
136
|
+
// Skip self
|
|
137
|
+
if (existing.id === newMemory.id)
|
|
138
|
+
continue;
|
|
139
|
+
const existingLower = existing.content.toLowerCase();
|
|
140
|
+
const existingTerms = extractKeyTerms(existingLower);
|
|
141
|
+
const overlap = termOverlap(newTerms, existingTerms);
|
|
142
|
+
// Require minimum shared context
|
|
143
|
+
if (overlap < 0.4)
|
|
144
|
+
continue;
|
|
145
|
+
// Same type (especially decision) + high overlap → likely supersession
|
|
146
|
+
if (existing.type === newMemory.type && existing.type === 'decision' && overlap >= 0.7) {
|
|
147
|
+
log.debug('Supersession candidate found (decision type + high overlap)', {
|
|
148
|
+
existingId: existing.id,
|
|
149
|
+
overlap,
|
|
150
|
+
});
|
|
151
|
+
return existing;
|
|
152
|
+
}
|
|
153
|
+
// Switch signal: new memory explicitly references a transition away from something
|
|
154
|
+
for (const pattern of SWITCH_PATTERNS) {
|
|
155
|
+
const match = newLower.match(pattern);
|
|
156
|
+
if (match) {
|
|
157
|
+
const switchedFrom = match[1];
|
|
158
|
+
if (existingLower.includes(switchedFrom)) {
|
|
159
|
+
log.debug('Supersession candidate found (switch pattern)', {
|
|
160
|
+
existingId: existing.id,
|
|
161
|
+
pattern: pattern.toString(),
|
|
162
|
+
switchedFrom,
|
|
163
|
+
});
|
|
164
|
+
return existing;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// High overlap + different conclusion signals
|
|
169
|
+
if (overlap >= 0.7 && hasOppositeSignal(newLower, existingLower)) {
|
|
170
|
+
log.debug('Supersession candidate found (opposite signal)', {
|
|
171
|
+
existingId: existing.id,
|
|
172
|
+
overlap,
|
|
173
|
+
});
|
|
174
|
+
return existing;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
// Temporal summary for sun context
|
|
181
|
+
// ---------------------------------------------------------------------------
|
|
182
|
+
/**
|
|
183
|
+
* Build a concise textual summary of temporal state for the sun resource.
|
|
184
|
+
*
|
|
185
|
+
* Includes:
|
|
186
|
+
* - Count of active vs superseded memories
|
|
187
|
+
* - Recent supersession events (last 5)
|
|
188
|
+
*/
|
|
189
|
+
export function getTemporalSummary(project) {
|
|
190
|
+
const db = getDatabase();
|
|
191
|
+
const now = new Date().toISOString();
|
|
192
|
+
// Active: not deleted, valid_from ≤ now, valid_until IS NULL or > now
|
|
193
|
+
const activeRow = db.prepare(`
|
|
194
|
+
SELECT COUNT(*) as count FROM memories
|
|
195
|
+
WHERE project = ?
|
|
196
|
+
AND deleted_at IS NULL
|
|
197
|
+
AND (valid_from IS NULL OR valid_from <= ?)
|
|
198
|
+
AND (valid_until IS NULL OR valid_until > ?)
|
|
199
|
+
`).get(project, now, now);
|
|
200
|
+
// Superseded: has superseded_by set
|
|
201
|
+
const supersededRow = db.prepare(`
|
|
202
|
+
SELECT COUNT(*) as count FROM memories
|
|
203
|
+
WHERE project = ? AND deleted_at IS NULL AND superseded_by IS NOT NULL
|
|
204
|
+
`).get(project);
|
|
205
|
+
// Recent supersessions
|
|
206
|
+
const recentRows = db.prepare(`
|
|
207
|
+
SELECT id, summary, superseded_by, updated_at FROM memories
|
|
208
|
+
WHERE project = ?
|
|
209
|
+
AND deleted_at IS NULL
|
|
210
|
+
AND superseded_by IS NOT NULL
|
|
211
|
+
ORDER BY updated_at DESC
|
|
212
|
+
LIMIT 5
|
|
213
|
+
`).all(project);
|
|
214
|
+
const lines = [
|
|
215
|
+
`Temporal: ${activeRow.count} active, ${supersededRow.count} superseded`,
|
|
216
|
+
];
|
|
217
|
+
if (recentRows.length > 0) {
|
|
218
|
+
lines.push('Recent supersessions:');
|
|
219
|
+
for (const row of recentRows) {
|
|
220
|
+
const date = row.updated_at.slice(0, 10);
|
|
221
|
+
lines.push(` [${date}] "${row.summary}" → superseded by ${row.superseded_by.slice(0, 8)}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return lines.join('\n');
|
|
225
|
+
}
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
// Internal helpers
|
|
228
|
+
// ---------------------------------------------------------------------------
|
|
229
|
+
/**
|
|
230
|
+
* Extract meaningful key terms from lowercased text.
|
|
231
|
+
* Filters out common stop words and short tokens.
|
|
232
|
+
*/
|
|
233
|
+
export function extractKeyTerms(text) {
|
|
234
|
+
const STOP_WORDS = new Set([
|
|
235
|
+
'the', 'a', 'an', 'is', 'are', 'was', 'were', 'be', 'been', 'being',
|
|
236
|
+
'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could',
|
|
237
|
+
'should', 'may', 'might', 'shall', 'can', 'to', 'of', 'in', 'for',
|
|
238
|
+
'on', 'with', 'at', 'by', 'from', 'as', 'into', 'through', 'during',
|
|
239
|
+
'this', 'that', 'these', 'those', 'i', 'we', 'our', 'it', 'its',
|
|
240
|
+
'and', 'or', 'but', 'not', 'no', 'so', 'if', 'then', 'than', 'also',
|
|
241
|
+
]);
|
|
242
|
+
const terms = new Set();
|
|
243
|
+
const tokens = text.match(/[a-z0-9_\-\.]+/g) ?? [];
|
|
244
|
+
for (const token of tokens) {
|
|
245
|
+
if (token.length >= 3 && !STOP_WORDS.has(token)) {
|
|
246
|
+
terms.add(token);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return terms;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Compute Jaccard-like overlap between two term sets.
|
|
253
|
+
* Returns a value in [0, 1].
|
|
254
|
+
*/
|
|
255
|
+
function termOverlap(a, b) {
|
|
256
|
+
if (a.size === 0 || b.size === 0)
|
|
257
|
+
return 0;
|
|
258
|
+
let shared = 0;
|
|
259
|
+
for (const term of a) {
|
|
260
|
+
if (b.has(term))
|
|
261
|
+
shared++;
|
|
262
|
+
}
|
|
263
|
+
const union = new Set([...a, ...b]).size;
|
|
264
|
+
return shared / union;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Check if the two texts contain opposing action signals around shared terms.
|
|
268
|
+
* E.g., "use X" in old vs "not use X" or "avoid X" in new.
|
|
269
|
+
*/
|
|
270
|
+
function hasOppositeSignal(newText, existingText) {
|
|
271
|
+
const NEGATION_PREFIXES = ['not ', "don't ", 'avoid ', 'remove ', 'disable ', 'stop using '];
|
|
272
|
+
const ACTION_VERBS = ['use', 'enable', 'add', 'adopt', 'choose', 'select', 'implement'];
|
|
273
|
+
for (const verb of ACTION_VERBS) {
|
|
274
|
+
const existingHasVerb = existingText.includes(verb);
|
|
275
|
+
if (!existingHasVerb)
|
|
276
|
+
continue;
|
|
277
|
+
const newNegatesVerb = NEGATION_PREFIXES.some(neg => newText.includes(neg + verb));
|
|
278
|
+
if (newNegatesVerb)
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=temporal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporal.js","sourceRoot":"","sources":["../../src/engine/temporal.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAEL,iBAAiB,EACjB,cAAc,IAAI,qBAAqB,EACvC,oBAAoB,GAErB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,GAAG,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;AAErC,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,QAAgB,EAChB,SAAkB,EAClB,UAAmB;IAEnB,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;IACzB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAErC,MAAM,IAAI,GAAa,CAAC,gBAAgB,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAsB,CAAC,GAAG,CAAC,CAAC;IAExC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,IAAI,CAA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AI,CAAC,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,CAAC,EAAE,CAAC;QACrB,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,MAAM,EAAE,CAAC;IAC5B,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACzC,OAAO,MAAM,GAAG,KAAK,CAAC;AACxB,CAAC;AAED;;;GAGG;AACH,SAAS,iBAAiB,CAAC,OAAe,EAAE,YAAoB;IAC9D,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;IAC7F,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;IAExF,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,MAAM,eAAe,GAAG,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,eAAe;YAAE,SAAS;QAE/B,MAAM,cAAc,GAAG,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC;QACnF,IAAI,cAAc;YAAE,OAAO,IAAI,CAAC;IAClC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
export type MemoryType = 'decision' | 'observation' | 'task' | 'context' | 'error' | 'milestone' | 'procedural';
|
|
2
|
+
export declare const ORBIT_ZONES: {
|
|
3
|
+
readonly core: {
|
|
4
|
+
readonly min: 0.1;
|
|
5
|
+
readonly max: 1;
|
|
6
|
+
readonly label: "Core Memory";
|
|
7
|
+
};
|
|
8
|
+
readonly near: {
|
|
9
|
+
readonly min: 1;
|
|
10
|
+
readonly max: 5;
|
|
11
|
+
readonly label: "Recent Memory";
|
|
12
|
+
};
|
|
13
|
+
readonly active: {
|
|
14
|
+
readonly min: 5;
|
|
15
|
+
readonly max: 15;
|
|
16
|
+
readonly label: "Active Memory";
|
|
17
|
+
};
|
|
18
|
+
readonly archive: {
|
|
19
|
+
readonly min: 15;
|
|
20
|
+
readonly max: 40;
|
|
21
|
+
readonly label: "Stored Memory";
|
|
22
|
+
};
|
|
23
|
+
readonly fading: {
|
|
24
|
+
readonly min: 40;
|
|
25
|
+
readonly max: 70;
|
|
26
|
+
readonly label: "Fading Memory";
|
|
27
|
+
};
|
|
28
|
+
readonly forgotten: {
|
|
29
|
+
readonly min: 70;
|
|
30
|
+
readonly max: 100;
|
|
31
|
+
readonly label: "Forgotten Memory";
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export type OrbitZone = keyof typeof ORBIT_ZONES;
|
|
35
|
+
export declare const IMPACT_DEFAULTS: Record<MemoryType, number>;
|
|
36
|
+
export declare const DEFAULT_WEIGHTS: {
|
|
37
|
+
readonly recency: 0.3;
|
|
38
|
+
readonly frequency: 0.2;
|
|
39
|
+
readonly impact: 0.3;
|
|
40
|
+
readonly relevance: 0.2;
|
|
41
|
+
};
|
|
42
|
+
export interface Memory {
|
|
43
|
+
id: string;
|
|
44
|
+
project: string;
|
|
45
|
+
content: string;
|
|
46
|
+
summary: string;
|
|
47
|
+
type: MemoryType;
|
|
48
|
+
tags: string[];
|
|
49
|
+
distance: number;
|
|
50
|
+
importance: number;
|
|
51
|
+
velocity: number;
|
|
52
|
+
impact: number;
|
|
53
|
+
access_count: number;
|
|
54
|
+
last_accessed_at: string | null;
|
|
55
|
+
metadata: Record<string, unknown>;
|
|
56
|
+
source: string | null;
|
|
57
|
+
source_path: string | null;
|
|
58
|
+
source_hash: string | null;
|
|
59
|
+
content_hash: string | null;
|
|
60
|
+
created_at: string;
|
|
61
|
+
updated_at: string;
|
|
62
|
+
deleted_at: string | null;
|
|
63
|
+
embedding?: Float32Array;
|
|
64
|
+
valid_from?: string;
|
|
65
|
+
valid_until?: string;
|
|
66
|
+
superseded_by?: string;
|
|
67
|
+
consolidated_into?: string;
|
|
68
|
+
quality_score?: number;
|
|
69
|
+
is_universal?: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface VectorSearchResult {
|
|
72
|
+
memoryId: string;
|
|
73
|
+
distance: number;
|
|
74
|
+
}
|
|
75
|
+
export interface SunState {
|
|
76
|
+
project: string;
|
|
77
|
+
content: string;
|
|
78
|
+
current_work: string;
|
|
79
|
+
recent_decisions: string[];
|
|
80
|
+
next_steps: string[];
|
|
81
|
+
active_errors: string[];
|
|
82
|
+
project_context: string;
|
|
83
|
+
token_count: number;
|
|
84
|
+
last_commit_at: string | null;
|
|
85
|
+
updated_at: string;
|
|
86
|
+
}
|
|
87
|
+
export interface OrbitChange {
|
|
88
|
+
memory_id: string;
|
|
89
|
+
project: string;
|
|
90
|
+
old_distance: number;
|
|
91
|
+
new_distance: number;
|
|
92
|
+
old_importance: number;
|
|
93
|
+
new_importance: number;
|
|
94
|
+
trigger: 'decay' | 'access' | 'commit' | 'manual' | 'gravity' | 'forget';
|
|
95
|
+
}
|
|
96
|
+
export interface ImportanceComponents {
|
|
97
|
+
recency: number;
|
|
98
|
+
frequency: number;
|
|
99
|
+
impact: number;
|
|
100
|
+
relevance: number;
|
|
101
|
+
total: number;
|
|
102
|
+
}
|
|
103
|
+
export type RelationType = 'uses' | 'caused_by' | 'part_of' | 'contradicts' | 'supersedes' | 'related_to' | 'depends_on' | 'derived_from';
|
|
104
|
+
export interface ConstellationEdge {
|
|
105
|
+
id: string;
|
|
106
|
+
source_id: string;
|
|
107
|
+
target_id: string;
|
|
108
|
+
relation: RelationType;
|
|
109
|
+
weight: number;
|
|
110
|
+
project: string;
|
|
111
|
+
created_at: string;
|
|
112
|
+
metadata?: Record<string, unknown>;
|
|
113
|
+
}
|
|
114
|
+
export interface TemporalInfo {
|
|
115
|
+
valid_from?: string;
|
|
116
|
+
valid_until?: string;
|
|
117
|
+
superseded_by?: string;
|
|
118
|
+
}
|
|
119
|
+
export interface MemoryConflict {
|
|
120
|
+
id: string;
|
|
121
|
+
memory_id: string;
|
|
122
|
+
conflicting_memory_id: string;
|
|
123
|
+
severity: 'high' | 'medium' | 'low';
|
|
124
|
+
description: string;
|
|
125
|
+
status: 'open' | 'resolved' | 'dismissed';
|
|
126
|
+
resolution?: string;
|
|
127
|
+
project: string;
|
|
128
|
+
created_at: string;
|
|
129
|
+
resolved_at?: string;
|
|
130
|
+
}
|
|
131
|
+
export interface QualityScore {
|
|
132
|
+
overall: number;
|
|
133
|
+
specificity: number;
|
|
134
|
+
actionability: number;
|
|
135
|
+
uniqueness: number;
|
|
136
|
+
freshness: number;
|
|
137
|
+
}
|
|
138
|
+
export interface MemoryAnalytics {
|
|
139
|
+
total_memories: number;
|
|
140
|
+
zone_distribution: Record<string, number>;
|
|
141
|
+
type_distribution: Record<string, number>;
|
|
142
|
+
avg_quality: number;
|
|
143
|
+
avg_importance: number;
|
|
144
|
+
recall_success_rate: number;
|
|
145
|
+
consolidation_count: number;
|
|
146
|
+
conflict_count: number;
|
|
147
|
+
top_tags: Array<{
|
|
148
|
+
tag: string;
|
|
149
|
+
count: number;
|
|
150
|
+
}>;
|
|
151
|
+
activity_timeline: Array<{
|
|
152
|
+
date: string;
|
|
153
|
+
created: number;
|
|
154
|
+
accessed: number;
|
|
155
|
+
forgotten: number;
|
|
156
|
+
}>;
|
|
157
|
+
}
|
|
158
|
+
export interface ObservationEntry {
|
|
159
|
+
id: string;
|
|
160
|
+
content: string;
|
|
161
|
+
extracted_memories: string[];
|
|
162
|
+
source: 'conversation' | 'reflection';
|
|
163
|
+
project: string;
|
|
164
|
+
created_at: string;
|
|
165
|
+
}
|
|
166
|
+
export interface StellarConfig {
|
|
167
|
+
dbPath: string;
|
|
168
|
+
defaultProject: string;
|
|
169
|
+
sunTokenBudget: number;
|
|
170
|
+
decayHalfLifeHours: number;
|
|
171
|
+
frequencySaturationPoint: number;
|
|
172
|
+
weights: {
|
|
173
|
+
recency: number;
|
|
174
|
+
frequency: number;
|
|
175
|
+
impact: number;
|
|
176
|
+
relevance: number;
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Orbit zones
|
|
2
|
+
export const ORBIT_ZONES = {
|
|
3
|
+
core: { min: 0.1, max: 1.0, label: 'Core Memory' },
|
|
4
|
+
near: { min: 1.0, max: 5.0, label: 'Recent Memory' },
|
|
5
|
+
active: { min: 5.0, max: 15.0, label: 'Active Memory' },
|
|
6
|
+
archive: { min: 15.0, max: 40.0, label: 'Stored Memory' },
|
|
7
|
+
fading: { min: 40.0, max: 70.0, label: 'Fading Memory' },
|
|
8
|
+
forgotten: { min: 70.0, max: 100.0, label: 'Forgotten Memory' },
|
|
9
|
+
};
|
|
10
|
+
// Default impact by memory type
|
|
11
|
+
export const IMPACT_DEFAULTS = {
|
|
12
|
+
decision: 0.8,
|
|
13
|
+
milestone: 0.7,
|
|
14
|
+
error: 0.6,
|
|
15
|
+
task: 0.5,
|
|
16
|
+
context: 0.4,
|
|
17
|
+
observation: 0.3,
|
|
18
|
+
procedural: 0.5,
|
|
19
|
+
};
|
|
20
|
+
// Importance weights
|
|
21
|
+
export const DEFAULT_WEIGHTS = {
|
|
22
|
+
recency: 0.30,
|
|
23
|
+
frequency: 0.20,
|
|
24
|
+
impact: 0.30,
|
|
25
|
+
relevance: 0.20,
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/engine/types.ts"],"names":[],"mappings":"AAGA,cAAc;AACd,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAO,EAAE,GAAG,EAAE,GAAG,EAAG,GAAG,EAAE,GAAG,EAAG,KAAK,EAAE,aAAa,EAAE;IACzD,IAAI,EAAO,EAAE,GAAG,EAAE,GAAG,EAAG,GAAG,EAAE,GAAG,EAAG,KAAK,EAAE,eAAe,EAAE;IAC3D,MAAM,EAAK,EAAE,GAAG,EAAE,GAAG,EAAG,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,eAAe,EAAE;IAC3D,OAAO,EAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,eAAe,EAAE;IAC3D,MAAM,EAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,eAAe,EAAE;IAC3D,SAAS,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE;CACvD,CAAC;AAIX,gCAAgC;AAChC,MAAM,CAAC,MAAM,eAAe,GAA+B;IACzD,QAAQ,EAAK,GAAG;IAChB,SAAS,EAAI,GAAG;IAChB,KAAK,EAAQ,GAAG;IAChB,IAAI,EAAS,GAAG;IAChB,OAAO,EAAM,GAAG;IAChB,WAAW,EAAE,GAAG;IAChB,UAAU,EAAG,GAAG;CACjB,CAAC;AAEF,qBAAqB;AACrB,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,OAAO,EAAI,IAAI;IACf,SAAS,EAAE,IAAI;IACf,MAAM,EAAK,IAAI;IACf,SAAS,EAAE,IAAI;CACP,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
2
|
+
import { createStellarServer } from './mcp/server.js';
|
|
3
|
+
import { initDatabase } from './storage/database.js';
|
|
4
|
+
import { getConfig } from './utils/config.js';
|
|
5
|
+
import { autoCommitOnClose } from './engine/sun.js';
|
|
6
|
+
/**
|
|
7
|
+
* Validate that the runtime environment meets Stellar Memory's requirements.
|
|
8
|
+
* Exits with a human-readable error message if anything is missing.
|
|
9
|
+
*/
|
|
10
|
+
function validateEnvironment() {
|
|
11
|
+
// Check Node.js version (requires 22+ for node:sqlite)
|
|
12
|
+
const [major] = process.versions.node.split('.').map(Number);
|
|
13
|
+
if (major < 22) {
|
|
14
|
+
console.error(`[stellar-memory] ERROR: Node.js 22 or higher is required.\n` +
|
|
15
|
+
` Detected: Node.js ${process.versions.node}\n` +
|
|
16
|
+
` Upgrade: nvm install 22 && nvm use 22\n` +
|
|
17
|
+
` or visit https://nodejs.org/en/download`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
// node:sqlite is available since Node 22.5.0 — check the minor version.
|
|
21
|
+
const nodeVersion = process.versions.node.split('.').map(Number);
|
|
22
|
+
const [, minor] = nodeVersion;
|
|
23
|
+
if (major === 22 && minor < 5) {
|
|
24
|
+
console.error(`[stellar-memory] ERROR: Node.js 22.5.0 or higher is required for node:sqlite.\n` +
|
|
25
|
+
` Detected: Node.js ${process.versions.node}\n` +
|
|
26
|
+
` Upgrade: nvm install 22 && nvm use 22`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function main() {
|
|
31
|
+
validateEnvironment();
|
|
32
|
+
const config = getConfig();
|
|
33
|
+
// Initialize SQLite database (creates schema on first run)
|
|
34
|
+
initDatabase(config.dbPath);
|
|
35
|
+
// Create MCP server with all tools and resources registered
|
|
36
|
+
const server = createStellarServer();
|
|
37
|
+
// ── Shutdown handlers ────────────────────────────────────────────────────
|
|
38
|
+
// Auto-commit sun state so the next session resumes with full context.
|
|
39
|
+
let shutdownDone = false;
|
|
40
|
+
const onShutdown = () => {
|
|
41
|
+
if (shutdownDone)
|
|
42
|
+
return;
|
|
43
|
+
shutdownDone = true;
|
|
44
|
+
autoCommitOnClose(config.defaultProject);
|
|
45
|
+
};
|
|
46
|
+
process.on('exit', onShutdown);
|
|
47
|
+
process.on('SIGTERM', () => { onShutdown(); process.exit(0); });
|
|
48
|
+
process.on('SIGINT', () => { onShutdown(); process.exit(0); });
|
|
49
|
+
// Connect via stdio transport (used by Claude Code / Claude Desktop)
|
|
50
|
+
const transport = new StdioServerTransport();
|
|
51
|
+
await server.connect(transport);
|
|
52
|
+
console.error('[stellar-memory] Server started');
|
|
53
|
+
console.error(`[stellar-memory] Project: ${config.defaultProject}`);
|
|
54
|
+
console.error(`[stellar-memory] DB: ${config.dbPath}`);
|
|
55
|
+
}
|
|
56
|
+
main().catch((err) => {
|
|
57
|
+
console.error('[stellar-memory] Fatal error:', err);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;GAGG;AACH,SAAS,mBAAmB;IAC1B,uDAAuD;IACvD,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7D,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CACX,6DAA6D;YAC7D,uBAAuB,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI;YAChD,4CAA4C;YA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E,GAAG,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE/D,qEAAqE;IACrE,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhC,OAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACjD,OAAO,CAAC,KAAK,CAAC,6BAA6B,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;IACpE,OAAO,CAAC,KAAK,CAAC,wBAAwB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AACzD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAC;IACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mcp/connector-registry.ts — Class-based registry for cloud connectors.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the module-level `connectorRegistry` Map in the original server.ts.
|
|
5
|
+
* A class instance is passed around explicitly, making dependencies visible,
|
|
6
|
+
* enabling per-test isolation, and removing hidden global state.
|
|
7
|
+
*/
|
|
8
|
+
import type { CloudConnector } from '../scanner/cloud/types.js';
|
|
9
|
+
export declare class ConnectorRegistry {
|
|
10
|
+
private readonly registry;
|
|
11
|
+
set(type: string, connector: CloudConnector): void;
|
|
12
|
+
get(type: string): CloudConnector | undefined;
|
|
13
|
+
has(type: string): boolean;
|
|
14
|
+
get size(): number;
|
|
15
|
+
keys(): string[];
|
|
16
|
+
values(): CloudConnector[];
|
|
17
|
+
delete(type: string): boolean;
|
|
18
|
+
clear(): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=connector-registry.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mcp/connector-registry.ts — Class-based registry for cloud connectors.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the module-level `connectorRegistry` Map in the original server.ts.
|
|
5
|
+
* A class instance is passed around explicitly, making dependencies visible,
|
|
6
|
+
* enabling per-test isolation, and removing hidden global state.
|
|
7
|
+
*/
|
|
8
|
+
export class ConnectorRegistry {
|
|
9
|
+
registry = new Map();
|
|
10
|
+
set(type, connector) {
|
|
11
|
+
this.registry.set(type, connector);
|
|
12
|
+
}
|
|
13
|
+
get(type) {
|
|
14
|
+
return this.registry.get(type);
|
|
15
|
+
}
|
|
16
|
+
has(type) {
|
|
17
|
+
return this.registry.has(type);
|
|
18
|
+
}
|
|
19
|
+
get size() {
|
|
20
|
+
return this.registry.size;
|
|
21
|
+
}
|
|
22
|
+
keys() {
|
|
23
|
+
return [...this.registry.keys()];
|
|
24
|
+
}
|
|
25
|
+
values() {
|
|
26
|
+
return [...this.registry.values()];
|
|
27
|
+
}
|
|
28
|
+
delete(type) {
|
|
29
|
+
return this.registry.delete(type);
|
|
30
|
+
}
|
|
31
|
+
clear() {
|
|
32
|
+
this.registry.clear();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=connector-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector-registry.js","sourceRoot":"","sources":["../../src/mcp/connector-registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,OAAO,iBAAiB;IACX,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;IAE9D,GAAG,CAAC,IAAY,EAAE,SAAyB;QACzC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACrC,CAAC;IAED,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED,IAAI;QACF,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACnC,CAAC;IAED,MAAM;QACJ,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,IAAY;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mcp/server.ts — Thin factory that wires tool handlers to the MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* 1. Instantiate McpServer.
|
|
6
|
+
* 2. Register the stellar://sun resource.
|
|
7
|
+
* 3. Register each tool, forwarding parsed args to the appropriate handler.
|
|
8
|
+
*
|
|
9
|
+
* Business logic lives in mcp/tools/. This file contains no logic beyond wiring.
|
|
10
|
+
*/
|
|
11
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
12
|
+
export declare function createStellarServer(): McpServer;
|
|
13
|
+
//# sourceMappingURL=server.d.ts.map
|