@rlabs-inc/memory 0.3.7 → 0.3.9

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/src/core/store.ts CHANGED
@@ -19,12 +19,14 @@ import {
19
19
  projectSnapshotSchema,
20
20
  sessionSchema,
21
21
  managementLogSchema,
22
+ personalPrimerSchema,
22
23
  MEMORY_SCHEMA_VERSION,
23
24
  type MemorySchema,
24
25
  type SessionSummarySchema,
25
26
  type ProjectSnapshotSchema,
26
27
  type SessionSchema,
27
28
  type ManagementLogSchema,
29
+ type PersonalPrimerSchema,
28
30
  } from '../types/schema.ts'
29
31
 
30
32
  /**
@@ -70,6 +72,7 @@ interface GlobalDB {
70
72
  db: Database
71
73
  memories: PersistentCollection<typeof memorySchema>
72
74
  managementLogs: PersistentCollection<typeof managementLogSchema>
75
+ primer: PersistentCollection<typeof personalPrimerSchema>
73
76
  }
74
77
 
75
78
  /**
@@ -146,9 +149,17 @@ export class MemoryStore {
146
149
  watchFiles: this._config.watchFiles,
147
150
  })
148
151
 
149
- await Promise.all([memories.load(), managementLogs.load()])
152
+ // Personal primer collection (singleton - relationship context for session start)
153
+ const primer = db.collection('primer', {
154
+ schema: personalPrimerSchema,
155
+ contentColumn: 'content',
156
+ autoSave: true,
157
+ watchFiles: this._config.watchFiles,
158
+ })
159
+
160
+ await Promise.all([memories.load(), managementLogs.load(), primer.load()])
150
161
 
151
- this._global = { db, memories, managementLogs }
162
+ this._global = { db, memories, managementLogs, primer }
152
163
  return this._global
153
164
  }
154
165
 
@@ -260,50 +271,48 @@ export class MemoryStore {
260
271
  * Returns null if no primer exists yet (grows organically with personal memories)
261
272
  */
262
273
  async getPersonalPrimer(): Promise<PersonalPrimer | null> {
263
- const { memories } = await this.getGlobal()
274
+ const { primer } = await this.getGlobal()
264
275
 
265
- // Personal primer is stored as a special memory record
266
- const primer = memories.get(PERSONAL_PRIMER_ID)
267
- if (!primer) {
276
+ // Personal primer is stored in dedicated primer collection (singleton)
277
+ const record = primer.get(PERSONAL_PRIMER_ID)
278
+ if (!record) {
268
279
  return null
269
280
  }
270
281
 
271
282
  return {
272
- content: primer.content,
273
- updated: primer.updated,
283
+ content: record.content,
284
+ updated: record.updated, // fsdb auto-manages this timestamp
274
285
  }
275
286
  }
276
287
 
277
288
  /**
278
289
  * Update the personal primer
279
290
  * Creates it if it doesn't exist
291
+ * @param content - The markdown content for the primer
292
+ * @param sessionNumber - Current session number (for tracking when updated)
293
+ * @param updatedBy - Who made the update ('user' | 'manager' | 'curator')
280
294
  */
281
- async setPersonalPrimer(content: string): Promise<void> {
282
- const { memories } = await this.getGlobal()
295
+ async setPersonalPrimer(
296
+ content: string,
297
+ sessionNumber?: number,
298
+ updatedBy: 'user' | 'manager' | 'curator' = 'user'
299
+ ): Promise<void> {
300
+ const { primer } = await this.getGlobal()
283
301
 
284
- const existing = memories.get(PERSONAL_PRIMER_ID)
302
+ const existing = primer.get(PERSONAL_PRIMER_ID)
285
303
  if (existing) {
286
- memories.update(PERSONAL_PRIMER_ID, { content })
304
+ primer.update(PERSONAL_PRIMER_ID, {
305
+ content,
306
+ session_updated: sessionNumber ?? existing.session_updated,
307
+ updated_by: updatedBy,
308
+ })
287
309
  } else {
288
- // Create the primer as a special memory record
289
- memories.insert({
310
+ // Create the primer record
311
+ primer.insert({
290
312
  id: PERSONAL_PRIMER_ID,
291
313
  content,
292
- reasoning: 'Personal relationship context injected at session start',
293
- importance_weight: 1.0,
294
- confidence_score: 1.0,
295
- context_type: 'personal',
296
- temporal_relevance: 'persistent',
297
- knowledge_domain: 'personal',
298
- emotional_resonance: 'neutral',
299
- action_required: false,
300
- problem_solution_pair: false,
301
- semantic_tags: ['personal', 'primer', 'relationship'],
302
- trigger_phrases: [],
303
- question_types: [],
304
- session_id: 'system',
305
- project_id: 'global',
306
- embedding: null,
314
+ session_updated: sessionNumber ?? 0,
315
+ updated_by: updatedBy,
307
316
  })
308
317
  }
309
318
  }
@@ -154,3 +154,16 @@ export const managementLogSchema = {
154
154
  } as const satisfies SchemaDefinition
155
155
 
156
156
  export type ManagementLogSchema = typeof managementLogSchema
157
+
158
+ /**
159
+ * Personal primer schema - relationship context injected at session start
160
+ * Singleton record (only one primer exists in global database)
161
+ * Stored in dedicated 'primer' collection, not mixed with memories
162
+ */
163
+ export const personalPrimerSchema = {
164
+ content: 'string', // The markdown content (body after frontmatter)
165
+ session_updated: 'number', // Session number when last updated
166
+ updated_by: 'string', // 'user' | 'manager' | 'curator'
167
+ } as const satisfies SchemaDefinition
168
+
169
+ export type PersonalPrimerSchema = typeof personalPrimerSchema