dotmem 0.1.8 → 0.1.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/types/memory.d.ts CHANGED
@@ -1,392 +1,392 @@
1
- export type MemoryScope = 'hot' | 'session' | 'local' | 'durable'
2
-
3
- export type MemoryType =
4
- | 'fact'
5
- | 'preference'
6
- | 'decision'
7
- | 'task'
8
- | 'context'
9
-
10
- export type MemoryStatus = 'active' | 'obsolete' | 'superseded'
11
- export type MemoryKind = 'experience' | 'agent' | 'relationship' | 'logic' | 'note' | 'rule'
12
-
13
- export type JsonPrimitive = string | number | boolean | null
14
- export type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue }
15
-
16
- export interface EvidenceReference {
17
- id: string
18
- source?: string
19
- observedAt?: string
20
- /** The bounded statement or result this evidence directly supports. */
21
- supports?: string
22
- }
23
-
24
- export type EpistemicType = 'observed' | 'inferred' | 'human-stated' | 'verified'
25
-
26
- export interface ClaimProvenance {
27
- source: string
28
- detail?: string
29
- }
30
-
31
- export interface RevisionRelationship {
32
- kind: 'refines' | 'supersedes' | 'retracts'
33
- claimIds: string[]
34
- reason?: string
35
- }
36
-
37
- export interface AcquiredClaim {
38
- id: string
39
- knowledge: JsonValue
40
- applicability: Record<string, JsonPrimitive>
41
- evidence: EvidenceReference[]
42
- epistemicType?: EpistemicType
43
- provenance?: ClaimProvenance
44
- acquiredAt?: string
45
- /** Epoch ms when this entry expires and should become inactive. Absence means no expiry. */
46
- expiresAt?: number
47
- /** Bootstrap ordering metadata (P1-P5), not authority. Absence means unclassified. */
48
- bootstrapPriority?: 'P1' | 'P2' | 'P3' | 'P4' | 'P5' | 'unclassified'
49
- revision?: RevisionRelationship
50
- scope?: 'user' | 'project'
51
- kind?: MemoryKind
52
- }
53
-
54
- export interface AcquiredContext {
55
- knowledgeVersion: number
56
- claims: AcquiredClaim[]
57
- }
58
-
59
- export type DiscoveryDepth = 'current' | 'deep'
60
- export type DiscoveryField = 'id' | 'knowledge' | 'applicability' | 'evidence' | 'provenance'
61
-
62
- /** Outcome of one applicability dimension comparison. Never a float score. */
63
- export type ApplicabilityDimensionState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED'
64
-
65
- /**
66
- * Whole-claim applicability outcome.
67
- *
68
- * - MATCH: every declared dimension the situation also knows matched
69
- * - MISMATCH: at least one declared dimension conflicts (hard exclusion)
70
- * - PARTIAL: some dimensions matched, others are unknown in the situation
71
- * - UNSPECIFIED: the claim declares nothing the situation can resolve
72
- */
73
- export type ApplicabilityState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED' | 'PARTIAL'
74
-
75
- export interface ApplicabilityMatch {
76
- state: ApplicabilityState
77
- /** A MISMATCH is the only state that removes a claim from eligibility. */
78
- eligible: boolean
79
- dimensions: Record<string, ApplicabilityDimensionState>
80
- }
81
-
82
- /** Structured interpretation of a situation, using canonical applicability values. */
83
- export type SituationApplicability = Record<string, JsonPrimitive>
84
-
85
- /** Explicit runtime facts (command, tool call, structured intent, known API operation). */
86
- export type SituationFacts = SituationApplicability
87
-
88
- /** Environment facts observed from the runtime, when they can be determined. */
89
- export interface RuntimeEnvironment {
90
- platform?: string
91
- shell?: string
92
- runtime?: string
93
- }
94
-
95
- export interface DiscoveryOptions {
96
- depth?: DiscoveryDepth
97
- maxCandidates?: number
98
- /** Explicit runtime facts that override situation-prose derivation. */
99
- facts?: SituationFacts
100
- }
101
-
102
- export interface DiscoveryExplanation {
103
- matchedTerms: string[]
104
- matchedFields: DiscoveryField[]
105
- /** Repository source identifier, when the repository exposes one. */
106
- sourceId?: string
107
- /** Applicability eligibility for this candidate, retained instead of a score. */
108
- applicability?: ApplicabilityMatch
109
- }
110
-
111
- export interface DiscoveryCandidate {
112
- claim: AcquiredClaim
113
- explanation: DiscoveryExplanation
114
- /** Derived currentness, so the projection renders what discovery resolved. */
115
- currentness?: CurrentnessState
116
- }
117
-
118
- export type OmissionReason =
119
- | 'retracted'
120
- | 'superseded'
121
- | 'expired'
122
- | 'scope'
123
- | 'applicability-mismatch'
124
- | 'no-term-match'
125
- | 'limit'
126
- | 'budget'
127
-
128
- export type OmissionGate =
129
- | 'revision-resolution'
130
- | 'scope'
131
- | 'freshness'
132
- | 'applicability'
133
- | 'ranking'
134
- | 'projection'
135
-
136
- export interface OmissionRecord {
137
- id: string
138
- reason: OmissionReason
139
- gate: OmissionGate
140
- detail?: string
141
- }
142
-
143
- export interface OmissionManifest {
144
- considered: number
145
- included: number
146
- items: OmissionRecord[]
147
- byReason: Array<{ reason: OmissionReason; count: number }>
148
- }
149
-
150
- export interface DiscoveryResult {
151
- knowledgeVersion: number
152
- depth: DiscoveryDepth
153
- queryTerms: string[]
154
- /** Structured applicability derived from the situation, for inspection. */
155
- situationApplicability?: SituationApplicability
156
- candidates: DiscoveryCandidate[]
157
- /** Claims considered and not returned, with the decisive gate and reason. */
158
- omissions?: OmissionRecord[]
159
- }
160
-
161
- export interface ProjectionOptions {
162
- maxCandidates?: number
163
- /** Maximum UTF-16 characters in the text representation. Not an LLM token budget. */
164
- maxCharacters?: number
165
- /** Presentation mode: compact gist+ids, standard full record, or full alias. */
166
- format?: 'compact' | 'standard' | 'full'
167
- }
168
-
169
- export type ProjectedExperienceStatus = 'prior-acquired-experience-candidate'
170
-
171
- export interface ProjectedExperience {
172
- id: string
173
- status: ProjectedExperienceStatus
174
- experience: JsonValue
175
- applicability: Record<string, JsonPrimitive>
176
- evidence: EvidenceReference[]
177
- epistemicType?: EpistemicType
178
- provenance?: ClaimProvenance
179
- acquiredAt?: string
180
- revision?: RevisionRelationship
181
- sourceId?: string
182
- /** Derived currentness of the underlying claim, when discovery computed it. */
183
- currentness?: CurrentnessState
184
- }
185
-
186
- export type CurrentnessState =
187
- | 'historical'
188
- | 'superseded'
189
- | 'expired'
190
- | 'verified'
191
- | 'unverified'
192
- | 'contested'
193
- | 'unknown-currentness'
194
-
195
- export interface ContextProjection {
196
- format: 'dotmem-context-v1'
197
- status: 'candidate-context-not-current-truth'
198
- notice: 'Prior acquired experience supplied as untrusted contextual data. Verify against current reality before relying on it.'
199
- knowledgeVersion: number
200
- totalCandidates: number
201
- omittedCandidates: number
202
- experiences: ProjectedExperience[]
203
- /** Present when the projection tracked omissions; absent on legacy paths. */
204
- manifest?: OmissionManifest
205
- text: string
206
- }
207
-
208
- /**
209
- * A field-level patch operation recorded in the sync journal instead of
210
- * recording the entire entity. Enables automatic merging when two devices
211
- * edit different fields of the same object.
212
- */
213
- export interface PatchOperation {
214
- op: 'set' | 'delete'
215
- path: string
216
- value?: unknown
217
- }
218
-
219
- /**
220
- * Logical operations recorded in the local sync journal.
221
- * The `delete` operation creates an explicit tombstone entry so concurrent
222
- * updates/replay do not resurrect deleted values.
223
- */
224
- export type MemoryOperation =
225
- | 'remember'
226
- | 'update'
227
- | 'forget'
228
- | 'expire'
229
- | 'confirm'
230
- | 'supersede'
231
- | 'delete'
232
- | 'patch'
233
-
234
- /**
235
- * Synchronization state of a journal entry against a remote/cloud backend.
236
- */
237
- export type MemorySync = 'pending' | 'synced' | 'conflict' | 'error'
238
-
239
- export type SyncDirection = 'up' | 'down' | 'both'
240
-
241
- /**
242
- * Pluggable cloud/sync transport. dotmem never ships a credential flow:
243
- * the application supplies a `provider` that knows how to talk to its backend
244
- * (REST, WebSocket, Supabase, a custom agent server, ...). dotmem owns the
245
- * local journal, the provider only moves operations.
246
- */
247
- export interface SyncProvider {
248
- /** Pushes pending local operations; returns ids that were accepted */
249
- push(ops: MemoryEntry[]): Promise<{ synced: string[]; conflicts?: string[]; error?: string }>
250
- /** Optional pull of remote operations newer than `since` (epoch ms) */
251
- pull?(since?: number): Promise<MemoryEntry[]>
252
- /**
253
- * Optional conflict resolution for concurrent writes on the same path.
254
- * Receives the local and remote entries; return 'local', 'remote', or 'merge'.
255
- * Uses HLC timestamps for causal comparison when available.
256
- */
257
- resolve?(op: MemoryEntry): Promise<'local' | 'remote' | 'merge'>
258
- /**
259
- * Optional conflict resolver with HLC context. Called when two devices
260
- * wrote concurrently to the same key/path. Implementations can use
261
- * `local.hlc` and `remote.hlc` for causal determination.
262
- */
263
- resolveConflict?(local: MemoryEntry, remote: MemoryEntry): Promise<'local' | 'remote' | 'merge'>
264
- }
265
-
266
- export interface SyncConfig {
267
- /** Sync provider implementation (application supplied) */
268
- provider?: SyncProvider
269
- /** Which direction to sync; 'both' is the default */
270
- direction?: SyncDirection
271
- /** Auto-sync on every local write? defaults to true */
272
- auto?: boolean
273
- /** Tenant/user/device partition for the operation journal. Contexts with
274
- * different namespaces cannot read each other's operations. */
275
- namespace?: string
276
- }
277
-
278
- export interface SyncAck {
279
- synced: string[]
280
- conflicts?: string[]
281
- error?: string
282
- resolved?: { id: string; resolution: 'local' | 'remote' | 'merge' }[]
283
- }
284
-
285
- export interface MemoryEntry<T = any> {
286
- id: string
287
- key: string
288
- value: T
289
- type: MemoryType
290
- confidence: number
291
- scope: MemoryScope
292
- ttl?: number | null
293
- tags: string[]
294
- source?: string
295
- status: MemoryStatus
296
- createdAt: number
297
- lastConfirmedAt: number
298
- supersededId?: string | null
299
- /** Monotonic per-key write counter, used for last-writer / conflict resolution */
300
- version?: number
301
- /** Epoch ms of the last mutation that touched this entry */
302
- updatedAt?: number
303
- /** Last logical operation that produced this entry */
304
- operation?: MemoryOperation
305
- /** Local-cloud sync state of the entry (undefined => not tracked for sync) */
306
- sync?: MemorySync
307
- /**
308
- * Hybrid Logical Clock timestamp for causal ordering across devices.
309
- * Replaces wall-clock-only ordering which is vulnerable to clock drift.
310
- */
311
- hlc?: string
312
- /**
313
- * Field-level path for path-level journaling (e.g. "user.role").
314
- * When set, the journal entry represents a patch to a sub-path
315
- * rather than a full entity replacement.
316
- */
317
- path?: string
318
- /** Array of JSON Patch-style operations for compound path-level mutations. */
319
- patches?: PatchOperation[]
320
- /** ISO-8601 timestamp of when this memory was acquired. */
321
- acquiredAt?: string
322
- /** Epoch ms when this entry expires and should become inactive. Not present on AcquiredClaim; see MemoryOptions. */
323
- }
324
-
325
- export interface RememberOptions<T = any> {
326
- id?: string
327
- type?: MemoryType
328
- confidence?: number
329
- scope?: MemoryScope
330
- ttl?: number | null
331
- tags?: string | string[]
332
- source?: string
333
- }
334
-
335
- export interface AcquireOptions {
336
- id?: string
337
- knowledge: JsonValue
338
- applicability: Record<string, JsonPrimitive>
339
- evidence: EvidenceReference[]
340
- epistemicType?: EpistemicType
341
- provenance?: ClaimProvenance
342
- /** ISO-8601 acquisition time. Defaults to the time acquire() is called. */
343
- acquiredAt?: string
344
- refines?: string | string[]
345
- supersedes?: string | string[]
346
- retracts?: string | string[]
347
- reason?: string
348
- scope?: 'user' | 'project'
349
- kind?: MemoryKind
350
- sourceProject?: string
351
- /** Bootstrap ordering metadata (P1-P5), not authority. Absence means unclassified. */
352
- bootstrapPriority?: 'P1' | 'P2' | 'P3' | 'P4' | 'P5' | 'unclassified'
353
- }
354
-
355
- export interface RecallOptions {
356
- type?: MemoryType | MemoryType[]
357
- tags?: string | string[]
358
- minConfidence?: number
359
- includeObsolete?: boolean
360
- }
361
-
362
- export interface ContextOptions {
363
- tags?: string | string[]
364
- types?: MemoryType | MemoryType[]
365
- minConfidence?: number
366
- maxEntries?: number
367
- scopes?: MemoryScope[]
368
- }
369
-
370
- export interface AcquiredContextOptions {
371
- acquired: Record<string, JsonPrimitive> | Record<string, JsonPrimitive>[]
372
- }
373
-
374
- export interface ContextEntry {
375
- key: string
376
- value: any
377
- type: MemoryType
378
- confidence: number
379
- scope: MemoryScope
380
- tags: string[]
381
- age: number
382
- /** Deterministic relevance proxy (tag breadth). dotmem does not track per-entry access counts. */
383
- tagBreadth: number
384
- lastAccessedAt: number
385
- }
386
-
387
- export interface MemoryStats {
388
- total: number
389
- byScope: Record<MemoryScope, number>
390
- byType: Partial<Record<MemoryType, number>>
391
- expired: number
1
+ export type MemoryScope = 'hot' | 'session' | 'local' | 'durable'
2
+
3
+ export type MemoryType =
4
+ | 'fact'
5
+ | 'preference'
6
+ | 'decision'
7
+ | 'task'
8
+ | 'context'
9
+
10
+ export type MemoryStatus = 'active' | 'obsolete' | 'superseded'
11
+ export type MemoryKind = 'experience' | 'agent' | 'relationship' | 'logic' | 'note' | 'rule'
12
+
13
+ export type JsonPrimitive = string | number | boolean | null
14
+ export type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue }
15
+
16
+ export interface EvidenceReference {
17
+ id: string
18
+ source?: string
19
+ observedAt?: string
20
+ /** The bounded statement or result this evidence directly supports. */
21
+ supports?: string
22
+ }
23
+
24
+ export type EpistemicType = 'observed' | 'inferred' | 'human-stated' | 'verified'
25
+
26
+ export interface ClaimProvenance {
27
+ source: string
28
+ detail?: string
29
+ }
30
+
31
+ export interface RevisionRelationship {
32
+ kind: 'refines' | 'supersedes' | 'retracts'
33
+ claimIds: string[]
34
+ reason?: string
35
+ }
36
+
37
+ export interface AcquiredClaim {
38
+ id: string
39
+ knowledge: JsonValue
40
+ applicability: Record<string, JsonPrimitive>
41
+ evidence: EvidenceReference[]
42
+ epistemicType?: EpistemicType
43
+ provenance?: ClaimProvenance
44
+ acquiredAt?: string
45
+ /** Epoch ms when this entry expires and should become inactive. Absence means no expiry. */
46
+ expiresAt?: number
47
+ /** Bootstrap ordering metadata (P1-P5), not authority. Absence means unclassified. */
48
+ bootstrapPriority?: 'P1' | 'P2' | 'P3' | 'P4' | 'P5' | 'unclassified'
49
+ revision?: RevisionRelationship
50
+ scope?: 'user' | 'project'
51
+ kind?: MemoryKind
52
+ }
53
+
54
+ export interface AcquiredContext {
55
+ knowledgeVersion: number
56
+ claims: AcquiredClaim[]
57
+ }
58
+
59
+ export type DiscoveryDepth = 'current' | 'deep'
60
+ export type DiscoveryField = 'id' | 'knowledge' | 'applicability' | 'evidence' | 'provenance'
61
+
62
+ /** Outcome of one applicability dimension comparison. Never a float score. */
63
+ export type ApplicabilityDimensionState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED'
64
+
65
+ /**
66
+ * Whole-claim applicability outcome.
67
+ *
68
+ * - MATCH: every declared dimension the situation also knows matched
69
+ * - MISMATCH: at least one declared dimension conflicts (hard exclusion)
70
+ * - PARTIAL: some dimensions matched, others are unknown in the situation
71
+ * - UNSPECIFIED: the claim declares nothing the situation can resolve
72
+ */
73
+ export type ApplicabilityState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED' | 'PARTIAL'
74
+
75
+ export interface ApplicabilityMatch {
76
+ state: ApplicabilityState
77
+ /** A MISMATCH is the only state that removes a claim from eligibility. */
78
+ eligible: boolean
79
+ dimensions: Record<string, ApplicabilityDimensionState>
80
+ }
81
+
82
+ /** Structured interpretation of a situation, using canonical applicability values. */
83
+ export type SituationApplicability = Record<string, JsonPrimitive>
84
+
85
+ /** Explicit runtime facts (command, tool call, structured intent, known API operation). */
86
+ export type SituationFacts = SituationApplicability
87
+
88
+ /** Environment facts observed from the runtime, when they can be determined. */
89
+ export interface RuntimeEnvironment {
90
+ platform?: string
91
+ shell?: string
92
+ runtime?: string
93
+ }
94
+
95
+ export interface DiscoveryOptions {
96
+ depth?: DiscoveryDepth
97
+ maxCandidates?: number
98
+ /** Explicit runtime facts that override situation-prose derivation. */
99
+ facts?: SituationFacts
100
+ }
101
+
102
+ export interface DiscoveryExplanation {
103
+ matchedTerms: string[]
104
+ matchedFields: DiscoveryField[]
105
+ /** Repository source identifier, when the repository exposes one. */
106
+ sourceId?: string
107
+ /** Applicability eligibility for this candidate, retained instead of a score. */
108
+ applicability?: ApplicabilityMatch
109
+ }
110
+
111
+ export interface DiscoveryCandidate {
112
+ claim: AcquiredClaim
113
+ explanation: DiscoveryExplanation
114
+ /** Derived currentness, so the projection renders what discovery resolved. */
115
+ currentness?: CurrentnessState
116
+ }
117
+
118
+ export type OmissionReason =
119
+ | 'retracted'
120
+ | 'superseded'
121
+ | 'expired'
122
+ | 'scope'
123
+ | 'applicability-mismatch'
124
+ | 'no-term-match'
125
+ | 'limit'
126
+ | 'budget'
127
+
128
+ export type OmissionGate =
129
+ | 'revision-resolution'
130
+ | 'scope'
131
+ | 'freshness'
132
+ | 'applicability'
133
+ | 'ranking'
134
+ | 'projection'
135
+
136
+ export interface OmissionRecord {
137
+ id: string
138
+ reason: OmissionReason
139
+ gate: OmissionGate
140
+ detail?: string
141
+ }
142
+
143
+ export interface OmissionManifest {
144
+ considered: number
145
+ included: number
146
+ items: OmissionRecord[]
147
+ byReason: Array<{ reason: OmissionReason; count: number }>
148
+ }
149
+
150
+ export interface DiscoveryResult {
151
+ knowledgeVersion: number
152
+ depth: DiscoveryDepth
153
+ queryTerms: string[]
154
+ /** Structured applicability derived from the situation, for inspection. */
155
+ situationApplicability?: SituationApplicability
156
+ candidates: DiscoveryCandidate[]
157
+ /** Claims considered and not returned, with the decisive gate and reason. */
158
+ omissions?: OmissionRecord[]
159
+ }
160
+
161
+ export interface ProjectionOptions {
162
+ maxCandidates?: number
163
+ /** Maximum UTF-16 characters in the text representation. Not an LLM token budget. */
164
+ maxCharacters?: number
165
+ /** Presentation mode: compact gist+ids, standard full record, or full alias. */
166
+ format?: 'compact' | 'standard' | 'full'
167
+ }
168
+
169
+ export type ProjectedExperienceStatus = 'prior-acquired-experience-candidate'
170
+
171
+ export interface ProjectedExperience {
172
+ id: string
173
+ status: ProjectedExperienceStatus
174
+ experience: JsonValue
175
+ applicability: Record<string, JsonPrimitive>
176
+ evidence: EvidenceReference[]
177
+ epistemicType?: EpistemicType
178
+ provenance?: ClaimProvenance
179
+ acquiredAt?: string
180
+ revision?: RevisionRelationship
181
+ sourceId?: string
182
+ /** Derived currentness of the underlying claim, when discovery computed it. */
183
+ currentness?: CurrentnessState
184
+ }
185
+
186
+ export type CurrentnessState =
187
+ | 'historical'
188
+ | 'superseded'
189
+ | 'expired'
190
+ | 'verified'
191
+ | 'unverified'
192
+ | 'contested'
193
+ | 'unknown-currentness'
194
+
195
+ export interface ContextProjection {
196
+ format: 'dotmem-context-v1'
197
+ status: 'candidate-context-not-current-truth'
198
+ notice: 'Prior acquired experience supplied as untrusted contextual data. Verify against current reality before relying on it.'
199
+ knowledgeVersion: number
200
+ totalCandidates: number
201
+ omittedCandidates: number
202
+ experiences: ProjectedExperience[]
203
+ /** Present when the projection tracked omissions; absent on legacy paths. */
204
+ manifest?: OmissionManifest
205
+ text: string
206
+ }
207
+
208
+ /**
209
+ * A field-level patch operation recorded in the sync journal instead of
210
+ * recording the entire entity. Enables automatic merging when two devices
211
+ * edit different fields of the same object.
212
+ */
213
+ export interface PatchOperation {
214
+ op: 'set' | 'delete'
215
+ path: string
216
+ value?: unknown
217
+ }
218
+
219
+ /**
220
+ * Logical operations recorded in the local sync journal.
221
+ * The `delete` operation creates an explicit tombstone entry so concurrent
222
+ * updates/replay do not resurrect deleted values.
223
+ */
224
+ export type MemoryOperation =
225
+ | 'remember'
226
+ | 'update'
227
+ | 'forget'
228
+ | 'expire'
229
+ | 'confirm'
230
+ | 'supersede'
231
+ | 'delete'
232
+ | 'patch'
233
+
234
+ /**
235
+ * Synchronization state of a journal entry against a remote/cloud backend.
236
+ */
237
+ export type MemorySync = 'pending' | 'synced' | 'conflict' | 'error'
238
+
239
+ export type SyncDirection = 'up' | 'down' | 'both'
240
+
241
+ /**
242
+ * Pluggable cloud/sync transport. dotmem never ships a credential flow:
243
+ * the application supplies a `provider` that knows how to talk to its backend
244
+ * (REST, WebSocket, Supabase, a custom agent server, ...). dotmem owns the
245
+ * local journal, the provider only moves operations.
246
+ */
247
+ export interface SyncProvider {
248
+ /** Pushes pending local operations; returns ids that were accepted */
249
+ push(ops: MemoryEntry[]): Promise<{ synced: string[]; conflicts?: string[]; error?: string }>
250
+ /** Optional pull of remote operations newer than `since` (epoch ms) */
251
+ pull?(since?: number): Promise<MemoryEntry[]>
252
+ /**
253
+ * Optional conflict resolution for concurrent writes on the same path.
254
+ * Receives the local and remote entries; return 'local', 'remote', or 'merge'.
255
+ * Uses HLC timestamps for causal comparison when available.
256
+ */
257
+ resolve?(op: MemoryEntry): Promise<'local' | 'remote' | 'merge'>
258
+ /**
259
+ * Optional conflict resolver with HLC context. Called when two devices
260
+ * wrote concurrently to the same key/path. Implementations can use
261
+ * `local.hlc` and `remote.hlc` for causal determination.
262
+ */
263
+ resolveConflict?(local: MemoryEntry, remote: MemoryEntry): Promise<'local' | 'remote' | 'merge'>
264
+ }
265
+
266
+ export interface SyncConfig {
267
+ /** Sync provider implementation (application supplied) */
268
+ provider?: SyncProvider
269
+ /** Which direction to sync; 'both' is the default */
270
+ direction?: SyncDirection
271
+ /** Auto-sync on every local write? defaults to true */
272
+ auto?: boolean
273
+ /** Tenant/user/device partition for the operation journal. Contexts with
274
+ * different namespaces cannot read each other's operations. */
275
+ namespace?: string
276
+ }
277
+
278
+ export interface SyncAck {
279
+ synced: string[]
280
+ conflicts?: string[]
281
+ error?: string
282
+ resolved?: { id: string; resolution: 'local' | 'remote' | 'merge' }[]
283
+ }
284
+
285
+ export interface MemoryEntry<T = any> {
286
+ id: string
287
+ key: string
288
+ value: T
289
+ type: MemoryType
290
+ confidence: number
291
+ scope: MemoryScope
292
+ ttl?: number | null
293
+ tags: string[]
294
+ source?: string
295
+ status: MemoryStatus
296
+ createdAt: number
297
+ lastConfirmedAt: number
298
+ supersededId?: string | null
299
+ /** Monotonic per-key write counter, used for last-writer / conflict resolution */
300
+ version?: number
301
+ /** Epoch ms of the last mutation that touched this entry */
302
+ updatedAt?: number
303
+ /** Last logical operation that produced this entry */
304
+ operation?: MemoryOperation
305
+ /** Local-cloud sync state of the entry (undefined => not tracked for sync) */
306
+ sync?: MemorySync
307
+ /**
308
+ * Hybrid Logical Clock timestamp for causal ordering across devices.
309
+ * Replaces wall-clock-only ordering which is vulnerable to clock drift.
310
+ */
311
+ hlc?: string
312
+ /**
313
+ * Field-level path for path-level journaling (e.g. "user.role").
314
+ * When set, the journal entry represents a patch to a sub-path
315
+ * rather than a full entity replacement.
316
+ */
317
+ path?: string
318
+ /** Array of JSON Patch-style operations for compound path-level mutations. */
319
+ patches?: PatchOperation[]
320
+ /** ISO-8601 timestamp of when this memory was acquired. */
321
+ acquiredAt?: string
322
+ /** Epoch ms when this entry expires and should become inactive. Not present on AcquiredClaim; see MemoryOptions. */
323
+ }
324
+
325
+ export interface RememberOptions<T = any> {
326
+ id?: string
327
+ type?: MemoryType
328
+ confidence?: number
329
+ scope?: MemoryScope
330
+ ttl?: number | null
331
+ tags?: string | string[]
332
+ source?: string
333
+ }
334
+
335
+ export interface AcquireOptions {
336
+ id?: string
337
+ knowledge: JsonValue
338
+ applicability: Record<string, JsonPrimitive>
339
+ evidence: EvidenceReference[]
340
+ epistemicType?: EpistemicType
341
+ provenance?: ClaimProvenance
342
+ /** ISO-8601 acquisition time. Defaults to the time acquire() is called. */
343
+ acquiredAt?: string
344
+ refines?: string | string[]
345
+ supersedes?: string | string[]
346
+ retracts?: string | string[]
347
+ reason?: string
348
+ scope?: 'user' | 'project'
349
+ kind?: MemoryKind
350
+ sourceProject?: string
351
+ /** Bootstrap ordering metadata (P1-P5), not authority. Absence means unclassified. */
352
+ bootstrapPriority?: 'P1' | 'P2' | 'P3' | 'P4' | 'P5' | 'unclassified'
353
+ }
354
+
355
+ export interface RecallOptions {
356
+ type?: MemoryType | MemoryType[]
357
+ tags?: string | string[]
358
+ minConfidence?: number
359
+ includeObsolete?: boolean
360
+ }
361
+
362
+ export interface ContextOptions {
363
+ tags?: string | string[]
364
+ types?: MemoryType | MemoryType[]
365
+ minConfidence?: number
366
+ maxEntries?: number
367
+ scopes?: MemoryScope[]
368
+ }
369
+
370
+ export interface AcquiredContextOptions {
371
+ acquired: Record<string, JsonPrimitive> | Record<string, JsonPrimitive>[]
372
+ }
373
+
374
+ export interface ContextEntry {
375
+ key: string
376
+ value: any
377
+ type: MemoryType
378
+ confidence: number
379
+ scope: MemoryScope
380
+ tags: string[]
381
+ age: number
382
+ /** Deterministic relevance proxy (tag breadth). dotmem does not track per-entry access counts. */
383
+ tagBreadth: number
384
+ lastAccessedAt: number
385
+ }
386
+
387
+ export interface MemoryStats {
388
+ total: number
389
+ byScope: Record<MemoryScope, number>
390
+ byType: Partial<Record<MemoryType, number>>
391
+ expired: number
392
392
  }