@rlabs-inc/memory 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.
@@ -0,0 +1,208 @@
1
+ // ============================================================================
2
+ // LOGGER - Beautiful console output for the memory system
3
+ // ============================================================================
4
+
5
+ /**
6
+ * Color codes for terminal output
7
+ */
8
+ const colors = {
9
+ reset: '\x1b[0m',
10
+ bright: '\x1b[1m',
11
+ dim: '\x1b[2m',
12
+
13
+ // Foreground
14
+ black: '\x1b[30m',
15
+ red: '\x1b[31m',
16
+ green: '\x1b[32m',
17
+ yellow: '\x1b[33m',
18
+ blue: '\x1b[34m',
19
+ magenta: '\x1b[35m',
20
+ cyan: '\x1b[36m',
21
+ white: '\x1b[37m',
22
+
23
+ // Background
24
+ bgBlack: '\x1b[40m',
25
+ bgRed: '\x1b[41m',
26
+ bgGreen: '\x1b[42m',
27
+ bgYellow: '\x1b[43m',
28
+ bgBlue: '\x1b[44m',
29
+ bgMagenta: '\x1b[45m',
30
+ bgCyan: '\x1b[46m',
31
+ bgWhite: '\x1b[47m',
32
+ }
33
+
34
+ /**
35
+ * Format a timestamp
36
+ */
37
+ function timestamp(): string {
38
+ return new Date().toISOString().replace('T', ' ').slice(11, 19)
39
+ }
40
+
41
+ /**
42
+ * Logger with beautiful colored output
43
+ */
44
+ export const logger = {
45
+ /**
46
+ * Info message (cyan)
47
+ */
48
+ info(message: string, ...args: any[]) {
49
+ console.log(
50
+ `${colors.dim}${timestamp()}${colors.reset} ${colors.cyan}โ„น${colors.reset} ${message}`,
51
+ ...args
52
+ )
53
+ },
54
+
55
+ /**
56
+ * Success message (green)
57
+ */
58
+ success(message: string, ...args: any[]) {
59
+ console.log(
60
+ `${colors.dim}${timestamp()}${colors.reset} ${colors.green}โœ“${colors.reset} ${message}`,
61
+ ...args
62
+ )
63
+ },
64
+
65
+ /**
66
+ * Warning message (yellow)
67
+ */
68
+ warn(message: string, ...args: any[]) {
69
+ console.log(
70
+ `${colors.dim}${timestamp()}${colors.reset} ${colors.yellow}โš ${colors.reset} ${message}`,
71
+ ...args
72
+ )
73
+ },
74
+
75
+ /**
76
+ * Error message (red)
77
+ */
78
+ error(message: string, ...args: any[]) {
79
+ console.error(
80
+ `${colors.dim}${timestamp()}${colors.reset} ${colors.red}โœ–${colors.reset} ${message}`,
81
+ ...args
82
+ )
83
+ },
84
+
85
+ /**
86
+ * Memory-specific: Memory curated (brain emoji)
87
+ */
88
+ memory(message: string, ...args: any[]) {
89
+ console.log(
90
+ `${colors.dim}${timestamp()}${colors.reset} ${colors.magenta}๐Ÿง ${colors.reset} ${message}`,
91
+ ...args
92
+ )
93
+ },
94
+
95
+ /**
96
+ * Memory-specific: Memory injected (sparkles)
97
+ */
98
+ inject(message: string, ...args: any[]) {
99
+ console.log(
100
+ `${colors.dim}${timestamp()}${colors.reset} ${colors.cyan}โœจ${colors.reset} ${message}`,
101
+ ...args
102
+ )
103
+ },
104
+
105
+ /**
106
+ * Memory-specific: Session event (calendar)
107
+ */
108
+ session(message: string, ...args: any[]) {
109
+ console.log(
110
+ `${colors.dim}${timestamp()}${colors.reset} ${colors.blue}๐Ÿ“…${colors.reset} ${message}`,
111
+ ...args
112
+ )
113
+ },
114
+
115
+ /**
116
+ * Memory-specific: Primer shown (book)
117
+ */
118
+ primer(message: string, ...args: any[]) {
119
+ console.log(
120
+ `${colors.dim}${timestamp()}${colors.reset} ${colors.yellow}๐Ÿ“–${colors.reset} ${message}`,
121
+ ...args
122
+ )
123
+ },
124
+
125
+ /**
126
+ * Log a divider line
127
+ */
128
+ divider() {
129
+ console.log(`${colors.dim}${'โ”€'.repeat(60)}${colors.reset}`)
130
+ },
131
+
132
+ /**
133
+ * Log curated memories in a beautiful format
134
+ */
135
+ logCuratedMemories(memories: Array<{
136
+ content: string
137
+ importance_weight: number
138
+ context_type: string
139
+ semantic_tags: string[]
140
+ emotional_resonance?: string
141
+ action_required?: boolean
142
+ }>) {
143
+ this.divider()
144
+ this.memory(`${colors.bright}CURATED MEMORIES (${memories.length})${colors.reset}`)
145
+ this.divider()
146
+
147
+ memories.forEach((m, i) => {
148
+ const importance = `${colors.yellow}${(m.importance_weight * 100).toFixed(0)}%${colors.reset}`
149
+ const type = `${colors.cyan}${m.context_type.toUpperCase()}${colors.reset}`
150
+ const tags = m.semantic_tags.slice(0, 3).join(', ')
151
+
152
+ console.log(`${colors.dim}${i + 1}.${colors.reset} [${type}] ${importance}`)
153
+ console.log(` ${colors.bright}${m.content.slice(0, 80)}${m.content.length > 80 ? '...' : ''}${colors.reset}`)
154
+ console.log(` ${colors.dim}Tags: ${tags}${colors.reset}`)
155
+
156
+ if (m.action_required) {
157
+ console.log(` ${colors.red}๐Ÿ”ด ACTION REQUIRED${colors.reset}`)
158
+ }
159
+ if (m.emotional_resonance) {
160
+ console.log(` ${colors.dim}Emotion: ${m.emotional_resonance}${colors.reset}`)
161
+ }
162
+ console.log()
163
+ })
164
+
165
+ this.divider()
166
+ },
167
+
168
+ /**
169
+ * Log retrieved memories
170
+ */
171
+ logRetrievedMemories(memories: Array<{
172
+ content: string
173
+ score: number
174
+ context_type: string
175
+ }>, query: string) {
176
+ this.inject(`Retrieved ${memories.length} memories for: "${query.slice(0, 50)}${query.length > 50 ? '...' : ''}"`)
177
+
178
+ if (memories.length === 0) {
179
+ console.log(` ${colors.dim}(no relevant memories found)${colors.reset}`)
180
+ return
181
+ }
182
+
183
+ memories.forEach((m, i) => {
184
+ const score = `${colors.green}${(m.score * 100).toFixed(0)}%${colors.reset}`
185
+ const type = `${colors.cyan}${m.context_type}${colors.reset}`
186
+ console.log(` ${i + 1}. [${score}] ${type}: ${m.content.slice(0, 60)}...`)
187
+ })
188
+ },
189
+
190
+ /**
191
+ * Log server startup
192
+ */
193
+ startup(port: number, host: string, mode: string) {
194
+ console.log()
195
+ console.log(`${colors.bright}${colors.magenta}โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—${colors.reset}`)
196
+ console.log(`${colors.bright}${colors.magenta}โ•‘${colors.reset} ${colors.bright}๐Ÿง  MEMORY SERVER${colors.reset} ${colors.bright}${colors.magenta}โ•‘${colors.reset}`)
197
+ console.log(`${colors.bright}${colors.magenta}โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•${colors.reset}`)
198
+ console.log()
199
+ console.log(` ${colors.dim}URL:${colors.reset} http://${host}:${port}`)
200
+ console.log(` ${colors.dim}Storage:${colors.reset} ${mode}`)
201
+ console.log(` ${colors.dim}Engine:${colors.reset} TypeScript + FatherStateDB`)
202
+ console.log()
203
+ this.divider()
204
+ this.info('Waiting for connections...')
205
+ },
206
+ }
207
+
208
+ export default logger
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Quick test to isolate FatherStateDB retrieval
4
+ * Tests if data loads correctly from disk
5
+ */
6
+
7
+ import { createDatabase } from 'fatherstatedb'
8
+ import { sessionSummarySchema, memorySchema } from './src/types/schema.ts'
9
+ import { homedir } from 'os'
10
+ import { join } from 'path'
11
+
12
+ const basePath = join(homedir(), '.local', 'share', 'memory', 'memory-ts')
13
+
14
+ console.log('๐Ÿงช Testing FatherStateDB Retrieval')
15
+ console.log('=' .repeat(60))
16
+ console.log(`๐Ÿ“‚ Base path: ${basePath}`)
17
+
18
+ // Test 1: Load summaries
19
+ console.log('\n๐Ÿ“‹ Test 1: Loading summaries database...')
20
+ const summaries = await createDatabase({
21
+ path: join(basePath, 'summaries'),
22
+ schema: sessionSummarySchema,
23
+ contentColumn: 'summary',
24
+ autoSave: true,
25
+ })
26
+
27
+ const allSummaries = summaries.all()
28
+ console.log(` Found ${allSummaries.length} summaries`)
29
+
30
+ if (allSummaries.length > 0) {
31
+ console.log('\n Latest summary:')
32
+ const latest = allSummaries.sort((a, b) => b.created - a.created)[0]
33
+ console.log(` - ID: ${latest.id}`)
34
+ console.log(` - Session: ${latest.session_id}`)
35
+ console.log(` - Created (raw): ${latest.created}`)
36
+ console.log(` - All keys: ${Object.keys(latest).join(', ')}`)
37
+ console.log(` - Summary: ${latest.summary.slice(0, 100)}...`)
38
+ } else {
39
+ console.log(' โŒ No summaries found!')
40
+ }
41
+
42
+ // Test 2: Load memories
43
+ console.log('\n๐Ÿ“‹ Test 2: Loading memories database...')
44
+ const memories = await createDatabase({
45
+ path: join(basePath, 'memories'),
46
+ schema: memorySchema,
47
+ contentColumn: 'content',
48
+ autoSave: true,
49
+ })
50
+
51
+ const allMemories = memories.all()
52
+ console.log(` Found ${allMemories.length} memories`)
53
+
54
+ if (allMemories.length > 0) {
55
+ console.log('\n First 3 memories:')
56
+ for (const mem of allMemories.slice(0, 3)) {
57
+ console.log(` - [${mem.context_type}] ${mem.content.slice(0, 60)}...`)
58
+ }
59
+ } else {
60
+ console.log(' โŒ No memories found!')
61
+ }
62
+
63
+ // Test 3: Insert and retrieve
64
+ console.log('\n๐Ÿ“‹ Test 3: Insert and immediate retrieve...')
65
+ const testId = await summaries.insert({
66
+ session_id: 'test-session',
67
+ project_id: 'test-project',
68
+ summary: 'Test summary for retrieval verification',
69
+ interaction_tone: 'testing',
70
+ })
71
+ console.log(` Inserted with ID: ${testId}`)
72
+
73
+ const afterInsert = summaries.all()
74
+ console.log(` Summaries after insert: ${afterInsert.length}`)
75
+
76
+ const found = summaries.get(testId)
77
+ console.log(` Retrieved by ID: ${found ? 'YES' : 'NO'}`)
78
+ if (found) {
79
+ console.log(` - Summary: ${found.summary}`)
80
+ }
81
+
82
+ // Cleanup test record
83
+ await summaries.delete(testId)
84
+ console.log(` Cleaned up test record`)
85
+
86
+ console.log('\n' + '=' .repeat(60))
87
+ console.log('๐Ÿงช Test complete!')
88
+
89
+ // Close databases
90
+ summaries.close()
91
+ memories.close()
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ESNext"],
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "noEmit": true,
11
+ "allowImportingTsExtensions": true,
12
+ "types": ["bun-types"]
13
+ },
14
+ "include": ["src/**/*"],
15
+ "exclude": ["node_modules", "dist"]
16
+ }