@rlabs-inc/memory 0.3.3 → 0.3.6

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.
@@ -99,10 +99,20 @@ export interface CuratedMemory {
99
99
  prerequisite_understanding?: string[] // Concepts user should know first
100
100
  follow_up_context?: string[] // What might come next
101
101
  dependency_context?: string[] // Other memories this relates to
102
+
103
+ // ========== V2 CURATOR FIELDS (optional - get smart defaults if not provided) ==========
104
+ scope?: 'global' | 'project' // Shared across projects or project-specific
105
+ temporal_class?: 'eternal' | 'long_term' | 'medium_term' | 'short_term' | 'ephemeral'
106
+ domain?: string // Specific area (embeddings, auth, family)
107
+ feature?: string // Specific feature within domain
108
+ related_files?: string[] // Source files for technical memories
109
+ awaiting_implementation?: boolean // Planned feature not yet built
110
+ awaiting_decision?: boolean // Decision point needing resolution
102
111
  }
103
112
 
104
113
  /**
105
114
  * A stored memory with database metadata
115
+ * Includes v2 lifecycle management fields (optional for backwards compat)
106
116
  */
107
117
  export interface StoredMemory extends CuratedMemory {
108
118
  id: string // Unique identifier
@@ -112,6 +122,137 @@ export interface StoredMemory extends CuratedMemory {
112
122
  updated_at: number // Last update timestamp
113
123
  embedding?: Float32Array // Vector embedding (384 dimensions)
114
124
  stale?: boolean // Is embedding out of sync with content?
125
+
126
+ // ========== V2 LIFECYCLE FIELDS (optional for backwards compat) ==========
127
+ status?: 'active' | 'pending' | 'superseded' | 'deprecated' | 'archived'
128
+ scope?: 'global' | 'project'
129
+
130
+ // Temporal tracking
131
+ session_created?: number
132
+ session_updated?: number
133
+ last_surfaced?: number
134
+ sessions_since_surfaced?: number
135
+
136
+ // Temporal class & decay
137
+ temporal_class?: 'eternal' | 'long_term' | 'medium_term' | 'short_term' | 'ephemeral'
138
+ fade_rate?: number
139
+ expires_after_sessions?: number
140
+
141
+ // Categorization
142
+ domain?: string
143
+ feature?: string
144
+ component?: string
145
+
146
+ // Relationships
147
+ supersedes?: string
148
+ superseded_by?: string
149
+ related_to?: string[]
150
+ resolves?: string[]
151
+ resolved_by?: string
152
+ parent_id?: string
153
+ child_ids?: string[]
154
+
155
+ // Lifecycle triggers
156
+ awaiting_implementation?: boolean
157
+ awaiting_decision?: boolean
158
+ blocked_by?: string
159
+ blocks?: string[]
160
+ related_files?: string[]
161
+
162
+ // Retrieval control
163
+ retrieval_weight?: number
164
+ exclude_from_retrieval?: boolean
165
+
166
+ // Schema version
167
+ schema_version?: number
168
+ }
169
+
170
+ /**
171
+ * Default values for v2 fields based on context_type
172
+ * Used for backwards compatibility with v1 memories
173
+ */
174
+ export const V2_DEFAULTS = {
175
+ // Type-specific defaults
176
+ typeDefaults: {
177
+ personal: { scope: 'global', temporal_class: 'eternal', fade_rate: 0 },
178
+ philosophy: { scope: 'global', temporal_class: 'eternal', fade_rate: 0 },
179
+ preference: { scope: 'global', temporal_class: 'long_term', fade_rate: 0.01 },
180
+ breakthrough: { scope: 'project', temporal_class: 'eternal', fade_rate: 0 },
181
+ decision: { scope: 'project', temporal_class: 'long_term', fade_rate: 0 },
182
+ milestone: { scope: 'project', temporal_class: 'eternal', fade_rate: 0 },
183
+ technical: { scope: 'project', temporal_class: 'medium_term', fade_rate: 0.03 },
184
+ architectural: { scope: 'project', temporal_class: 'long_term', fade_rate: 0.01 },
185
+ debugging: { scope: 'project', temporal_class: 'medium_term', fade_rate: 0.03 },
186
+ unresolved: { scope: 'project', temporal_class: 'medium_term', fade_rate: 0.05 },
187
+ todo: { scope: 'project', temporal_class: 'short_term', fade_rate: 0.1 },
188
+ technical_state: { scope: 'project', temporal_class: 'short_term', fade_rate: 0.1 },
189
+ workflow: { scope: 'project', temporal_class: 'long_term', fade_rate: 0.02 },
190
+ project_context: { scope: 'project', temporal_class: 'medium_term', fade_rate: 0.03 },
191
+ } as Record<string, { scope: string; temporal_class: string; fade_rate: number }>,
192
+
193
+ // Fallback defaults
194
+ fallback: {
195
+ status: 'active' as const,
196
+ scope: 'project' as const,
197
+ temporal_class: 'medium_term' as const,
198
+ fade_rate: 0.03,
199
+ sessions_since_surfaced: 0,
200
+ awaiting_implementation: false,
201
+ awaiting_decision: false,
202
+ exclude_from_retrieval: false,
203
+ },
204
+ }
205
+
206
+ /**
207
+ * Apply v2 defaults to a memory (for backwards compatibility)
208
+ * Uses context_type to determine appropriate defaults
209
+ */
210
+ export function applyV2Defaults(memory: Partial<StoredMemory>): StoredMemory {
211
+ const contextType = memory.context_type ?? 'general'
212
+ const typeDefaults = V2_DEFAULTS.typeDefaults[contextType] ?? V2_DEFAULTS.typeDefaults.technical
213
+
214
+ return {
215
+ // Spread existing memory
216
+ ...memory,
217
+
218
+ // Apply status default
219
+ status: memory.status ?? V2_DEFAULTS.fallback.status,
220
+
221
+ // Apply scope from type defaults
222
+ scope: memory.scope ?? typeDefaults?.scope ?? V2_DEFAULTS.fallback.scope,
223
+
224
+ // Apply temporal class from type defaults
225
+ temporal_class: memory.temporal_class ?? typeDefaults?.temporal_class ?? V2_DEFAULTS.fallback.temporal_class,
226
+
227
+ // Apply fade rate from type defaults
228
+ fade_rate: memory.fade_rate ?? typeDefaults?.fade_rate ?? V2_DEFAULTS.fallback.fade_rate,
229
+
230
+ // Apply other defaults
231
+ sessions_since_surfaced: memory.sessions_since_surfaced ?? V2_DEFAULTS.fallback.sessions_since_surfaced,
232
+ awaiting_implementation: memory.awaiting_implementation ?? V2_DEFAULTS.fallback.awaiting_implementation,
233
+ awaiting_decision: memory.awaiting_decision ?? V2_DEFAULTS.fallback.awaiting_decision,
234
+ exclude_from_retrieval: memory.exclude_from_retrieval ?? V2_DEFAULTS.fallback.exclude_from_retrieval,
235
+
236
+ // Retrieval weight defaults to importance_weight
237
+ retrieval_weight: memory.retrieval_weight ?? memory.importance_weight ?? 0.5,
238
+
239
+ // Initialize empty arrays if not present
240
+ related_to: memory.related_to ?? [],
241
+ resolves: memory.resolves ?? [],
242
+ child_ids: memory.child_ids ?? [],
243
+ blocks: memory.blocks ?? [],
244
+ related_files: memory.related_files ?? [],
245
+
246
+ // Mark as current schema version
247
+ schema_version: memory.schema_version ?? 2,
248
+ } as StoredMemory
249
+ }
250
+
251
+ /**
252
+ * Check if a memory needs migration (is v1)
253
+ */
254
+ export function needsMigration(memory: Partial<StoredMemory>): boolean {
255
+ return !memory.schema_version || memory.schema_version < 2
115
256
  }
116
257
 
117
258
  /**
@@ -166,6 +307,7 @@ export interface SessionPrimer {
166
307
  temporal_context: string // "Last session: 2 days ago"
167
308
  current_datetime: string // "Monday, December 23, 2024 • 3:45 PM EST"
168
309
  session_number: number // Which session this is (1, 2, 43, etc.)
310
+ personal_context?: string // Personal primer (relationship context) - injected EVERY session
169
311
  session_summary?: string // Previous session summary
170
312
  project_status?: string // Current project state
171
313
  key_memories?: StoredMemory[] // Essential memories to surface
@@ -5,40 +5,93 @@
5
5
 
6
6
  import type { SchemaDefinition } from '@rlabs-inc/fsdb'
7
7
 
8
+ /**
9
+ * Schema version for migration tracking
10
+ * Increment this when adding new fields that require migration
11
+ */
12
+ export const MEMORY_SCHEMA_VERSION = 2
13
+
8
14
  /**
9
15
  * Memory storage schema
10
16
  * Each field becomes a parallel reactive array in FatherStateDB
17
+ *
18
+ * VERSION HISTORY:
19
+ * v1: Original schema (content, reasoning, importance_weight, etc.)
20
+ * v2: Added lifecycle management fields (status, scope, domain, relationships, etc.)
11
21
  */
12
22
  export const memorySchema = {
13
- // Core content
23
+ // ========== CORE CONTENT (v1) ==========
14
24
  content: 'string',
15
25
  reasoning: 'string',
16
26
 
17
- // Numeric scores (for sorting and filtering)
27
+ // ========== SCORES (v1) ==========
18
28
  importance_weight: 'number', // 0.0 to 1.0
19
29
  confidence_score: 'number', // 0.0 to 1.0
20
30
 
21
- // Classification (strings for flexibility)
31
+ // ========== CLASSIFICATION (v1) ==========
22
32
  context_type: 'string', // breakthrough, decision, technical, etc.
23
33
  temporal_relevance: 'string', // persistent, session, temporary, archived
24
34
  knowledge_domain: 'string', // architecture, debugging, philosophy
25
35
  emotional_resonance: 'string', // joy, frustration, discovery, gratitude
26
36
 
27
- // Flags
37
+ // ========== FLAGS (v1) ==========
28
38
  action_required: 'boolean',
29
39
  problem_solution_pair: 'boolean',
30
40
 
31
- // Arrays for semantic matching
41
+ // ========== ARRAYS (v1) ==========
32
42
  semantic_tags: 'string[]', // ["typescript", "signals", "reactivity"]
33
43
  trigger_phrases: 'string[]', // ["working on memory", "debugging curator"]
34
44
  question_types: 'string[]', // ["how", "why", "what is"]
35
45
 
36
- // Session/project tracking
46
+ // ========== SESSION/PROJECT (v1) ==========
37
47
  session_id: 'string',
38
48
  project_id: 'string',
39
49
 
40
- // Vector embedding for semantic search (384 dimensions - MiniLM)
50
+ // ========== EMBEDDING (v1) ==========
41
51
  embedding: 'vector:384',
52
+
53
+ // ========== LIFECYCLE STATUS (v2) ==========
54
+ status: 'string', // active | pending | superseded | deprecated | archived
55
+ scope: 'string', // global | project
56
+
57
+ // ========== TEMPORAL TRACKING (v2) ==========
58
+ session_created: 'number', // Session number when created
59
+ session_updated: 'number', // Session number when last updated
60
+ last_surfaced: 'number', // Session number when last retrieved
61
+ sessions_since_surfaced: 'number', // Counter for decay
62
+
63
+ // ========== TEMPORAL CLASS & DECAY (v2) ==========
64
+ temporal_class: 'string', // eternal | long_term | medium_term | short_term | ephemeral
65
+ fade_rate: 'number', // Decay rate per session
66
+ expires_after_sessions: 'number', // For ephemeral only
67
+
68
+ // ========== CATEGORIZATION (v2) ==========
69
+ domain: 'string', // embeddings, gpu, auth, family, etc.
70
+ feature: 'string', // Specific feature within domain
71
+ component: 'string', // Code component if applicable
72
+
73
+ // ========== RELATIONSHIPS (v2) ==========
74
+ supersedes: 'string', // ID of memory this replaces
75
+ superseded_by: 'string', // ID of memory that replaced this
76
+ related_to: 'string[]', // IDs of related memories
77
+ resolves: 'string[]', // IDs of unresolved/debug/todo this solved
78
+ resolved_by: 'string', // ID of solved memory that resolved this
79
+ parent_id: 'string', // For chains/sequences
80
+ child_ids: 'string[]', // Children in chain
81
+
82
+ // ========== LIFECYCLE TRIGGERS (v2) ==========
83
+ awaiting_implementation: 'boolean', // Set true for planned features
84
+ awaiting_decision: 'boolean', // Waiting on a decision
85
+ blocked_by: 'string', // ID of blocking memory
86
+ blocks: 'string[]', // IDs this memory blocks
87
+ related_files: 'string[]', // Source files for technical memories
88
+
89
+ // ========== RETRIEVAL CONTROL (v2) ==========
90
+ retrieval_weight: 'number', // Current weight (affected by decay)
91
+ exclude_from_retrieval: 'boolean', // Force exclusion
92
+
93
+ // ========== SCHEMA VERSION (v2) ==========
94
+ schema_version: 'number', // Track which schema version this record uses
42
95
  } as const satisfies SchemaDefinition
43
96
 
44
97
  export type MemorySchema = typeof memorySchema
@@ -81,3 +134,23 @@ export const sessionSchema = {
81
134
  } as const satisfies SchemaDefinition
82
135
 
83
136
  export type SessionSchema = typeof sessionSchema
137
+
138
+ /**
139
+ * Management log schema - tracks what the management agent did
140
+ */
141
+ export const managementLogSchema = {
142
+ project_id: 'string',
143
+ session_number: 'number',
144
+ memories_processed: 'number',
145
+ superseded_count: 'number',
146
+ resolved_count: 'number',
147
+ linked_count: 'number',
148
+ primer_updated: 'boolean',
149
+ success: 'boolean',
150
+ duration_ms: 'number',
151
+ summary: 'string', // Agent's summary of what it did
152
+ error: 'string', // Error message if failed
153
+ details: 'string', // JSON string with full details
154
+ } as const satisfies SchemaDefinition
155
+
156
+ export type ManagementLogSchema = typeof managementLogSchema