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