dotmem 0.1.9 → 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.
@@ -3,11 +3,11 @@
3
3
  // Opt-in token-avoidance cache for LLM responses.
4
4
  ///
5
5
 
6
- export type LlmCacheScope = 'session' | 'persist'
6
+ type LlmCacheScope = 'session' | 'persist'
7
7
 
8
- export type LlmCacheMatchedBy = 'exact' | 'normalized' | 'embedding'
8
+ type LlmCacheMatchedBy = 'exact' | 'normalized' | 'embedding'
9
9
 
10
- export interface LlmCacheOptions<T = any> {
10
+ interface LlmCacheOptions<T = any> {
11
11
  key: {
12
12
  prompt: string
13
13
  model: string
@@ -27,7 +27,7 @@ export interface LlmCacheOptions<T = any> {
27
27
  estimateTokens?: (value: T) => number
28
28
  }
29
29
 
30
- export interface LlmCacheResult<T = any> {
30
+ interface LlmCacheResult<T = any> {
31
31
  value: T
32
32
  hit: boolean
33
33
  matchedBy?: LlmCacheMatchedBy
@@ -38,14 +38,14 @@ export interface LlmCacheResult<T = any> {
38
38
  provenance: 'CACHED' | 'FRESH'
39
39
  }
40
40
 
41
- export interface LlmCacheStats {
41
+ interface LlmCacheStats {
42
42
  hits: number
43
43
  misses: number
44
44
  savedTokens: number
45
45
  entries: number
46
46
  }
47
47
 
48
- export interface LlmCachePurgeSelector {
48
+ interface LlmCachePurgeSelector {
49
49
  key?: string
50
50
  model?: string
51
51
  olderThan?: string
package/types/logic.d.ts CHANGED
@@ -1,79 +1,60 @@
1
- import type {
2
- AcquiredClaim,
3
- AcquiredContext,
4
- ClaimProvenance,
5
- EpistemicType,
6
- EvidenceReference,
7
- JsonPrimitive,
8
- JsonValue
9
- } from './memory'
10
-
11
- export type LogicEpistemicType = EpistemicType
12
-
13
- export interface LogicExperienceInput {
14
- situation: JsonValue
15
- action: JsonValue
16
- outcome: JsonValue
17
- evidence: EvidenceReference[]
18
- }
19
-
20
- export interface LogicExperienceOptions extends LogicExperienceInput {
21
- id: string
22
- applicability: Record<string, JsonPrimitive>
23
- epistemicType?: LogicEpistemicType
24
- provenance?: ClaimProvenance
25
- acquiredAt?: string
26
- refines?: string | string[]
27
- supersedes?: string | string[]
28
- retracts?: string | string[]
29
- reason?: string
30
- }
31
-
32
- export interface LogicQuery {
33
- context: Record<string, JsonPrimitive>
34
- }
35
-
36
- export interface LogicMeasurement {
37
- total: number
38
- selected: number
39
- selectedIds: string[]
40
- knowledgeVersion: number
41
- temporalMutations: number
42
- }
43
-
44
- export interface LogicRule {
45
- id: string
46
- condition: JsonValue
47
- recommendation: JsonValue
48
- evidence: EvidenceReference[]
49
- confidence: number
50
- }
51
-
52
- export interface LogicStats {
53
- experiences: number
54
- version: number
55
- }
56
-
57
- export interface LogicEngineAPI {
58
- experience(opts: LogicExperienceOptions): Promise<void>
59
- precedents(query: LogicQuery): Promise<AcquiredClaim[]>
60
- context(query: LogicQuery): Promise<AcquiredContext>
61
- measure(query: LogicQuery): Promise<LogicMeasurement>
62
- learn(query: LogicQuery): Promise<LogicRule[]>
63
- clear(): Promise<void>
64
- stats(): Promise<LogicStats>
65
- }
66
-
67
- export declare class LogicEngine implements LogicEngineAPI {
68
- experience(opts: LogicExperienceOptions): Promise<void>
69
- precedents(query: LogicQuery): Promise<AcquiredClaim[]>
70
- context(query: LogicQuery): Promise<AcquiredContext>
71
- measure(query: LogicQuery): Promise<LogicMeasurement>
72
- learn(query: LogicQuery): Promise<LogicRule[]>
73
- clear(): Promise<void>
74
- stats(): Promise<LogicStats>
75
- configure(opts: { disabled?: boolean }): void
76
- }
77
-
78
- declare const logic: LogicEngine
79
- export default logic
1
+ type LogicEpistemicType = EpistemicType
2
+ interface LogicExperienceInput {
3
+ situation: JsonValue
4
+ action: JsonValue
5
+ outcome: JsonValue
6
+ evidence: EvidenceReference[]
7
+ }
8
+ interface LogicExperienceOptions extends LogicExperienceInput {
9
+ id: string
10
+ applicability: Record<string, JsonPrimitive>
11
+ epistemicType?: LogicEpistemicType
12
+ provenance?: ClaimProvenance
13
+ acquiredAt?: string
14
+ refines?: string | string[]
15
+ supersedes?: string | string[]
16
+ retracts?: string | string[]
17
+ reason?: string
18
+ }
19
+ interface LogicQuery {
20
+ context: Record<string, JsonPrimitive>
21
+ }
22
+ interface LogicMeasurement {
23
+ total: number
24
+ selected: number
25
+ selectedIds: string[]
26
+ knowledgeVersion: number
27
+ temporalMutations: number
28
+ }
29
+ interface LogicRule {
30
+ id: string
31
+ condition: JsonValue
32
+ recommendation: JsonValue
33
+ evidence: EvidenceReference[]
34
+ confidence: number
35
+ }
36
+ interface LogicStats {
37
+ experiences: number
38
+ version: number
39
+ }
40
+ interface LogicEngineAPI {
41
+ experience(opts: LogicExperienceOptions): Promise<void>
42
+ precedents(query: LogicQuery): Promise<AcquiredClaim[]>
43
+ context(query: LogicQuery): Promise<AcquiredContext>
44
+ measure(query: LogicQuery): Promise<LogicMeasurement>
45
+ learn(query: LogicQuery): Promise<LogicRule[]>
46
+ clear(): Promise<void>
47
+ stats(): Promise<LogicStats>
48
+ }
49
+ export declare class LogicEngine implements LogicEngineAPI {
50
+ experience(opts: LogicExperienceOptions): Promise<void>
51
+ precedents(query: LogicQuery): Promise<AcquiredClaim[]>
52
+ context(query: LogicQuery): Promise<AcquiredContext>
53
+ measure(query: LogicQuery): Promise<LogicMeasurement>
54
+ learn(query: LogicQuery): Promise<LogicRule[]>
55
+ clear(): Promise<void>
56
+ stats(): Promise<LogicStats>
57
+ configure(opts: { disabled?: boolean }): void
58
+ }
59
+ declare const logic: LogicEngine
60
+ export default logic
package/types/memory.d.ts CHANGED
@@ -1,40 +1,32 @@
1
- export type MemoryScope = 'hot' | 'session' | 'local' | 'durable'
2
-
3
- export type MemoryType =
1
+ type MemoryScope = 'hot' | 'session' | 'local' | 'durable'
2
+ type MemoryType =
4
3
  | 'fact'
5
4
  | 'preference'
6
5
  | 'decision'
7
6
  | 'task'
8
7
  | '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 {
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 {
17
13
  id: string
18
14
  source?: string
19
15
  observedAt?: string
20
16
  /** The bounded statement or result this evidence directly supports. */
21
17
  supports?: string
22
18
  }
23
-
24
- export type EpistemicType = 'observed' | 'inferred' | 'human-stated' | 'verified'
25
-
26
- export interface ClaimProvenance {
19
+ type EpistemicType = 'observed' | 'inferred' | 'human-stated' | 'verified'
20
+ interface ClaimProvenance {
27
21
  source: string
28
22
  detail?: string
29
23
  }
30
-
31
- export interface RevisionRelationship {
24
+ interface RevisionRelationship {
32
25
  kind: 'refines' | 'supersedes' | 'retracts'
33
26
  claimIds: string[]
34
27
  reason?: string
35
28
  }
36
-
37
- export interface AcquiredClaim {
29
+ interface AcquiredClaim {
38
30
  id: string
39
31
  knowledge: JsonValue
40
32
  applicability: Record<string, JsonPrimitive>
@@ -50,18 +42,14 @@ export interface AcquiredClaim {
50
42
  scope?: 'user' | 'project'
51
43
  kind?: MemoryKind
52
44
  }
53
-
54
- export interface AcquiredContext {
45
+ interface AcquiredContext {
55
46
  knowledgeVersion: number
56
47
  claims: AcquiredClaim[]
57
48
  }
58
-
59
- export type DiscoveryDepth = 'current' | 'deep'
60
- export type DiscoveryField = 'id' | 'knowledge' | 'applicability' | 'evidence' | 'provenance'
61
-
49
+ type DiscoveryDepth = 'current' | 'deep'
50
+ type DiscoveryField = 'id' | 'knowledge' | 'applicability' | 'evidence' | 'provenance'
62
51
  /** Outcome of one applicability dimension comparison. Never a float score. */
63
- export type ApplicabilityDimensionState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED'
64
-
52
+ type ApplicabilityDimensionState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED'
65
53
  /**
66
54
  * Whole-claim applicability outcome.
67
55
  *
@@ -70,36 +58,30 @@ export type ApplicabilityDimensionState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED'
70
58
  * - PARTIAL: some dimensions matched, others are unknown in the situation
71
59
  * - UNSPECIFIED: the claim declares nothing the situation can resolve
72
60
  */
73
- export type ApplicabilityState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED' | 'PARTIAL'
74
-
75
- export interface ApplicabilityMatch {
61
+ type ApplicabilityState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED' | 'PARTIAL'
62
+ interface ApplicabilityMatch {
76
63
  state: ApplicabilityState
77
64
  /** A MISMATCH is the only state that removes a claim from eligibility. */
78
65
  eligible: boolean
79
66
  dimensions: Record<string, ApplicabilityDimensionState>
80
67
  }
81
-
82
68
  /** Structured interpretation of a situation, using canonical applicability values. */
83
- export type SituationApplicability = Record<string, JsonPrimitive>
84
-
69
+ type SituationApplicability = Record<string, JsonPrimitive>
85
70
  /** Explicit runtime facts (command, tool call, structured intent, known API operation). */
86
- export type SituationFacts = SituationApplicability
87
-
71
+ type SituationFacts = SituationApplicability
88
72
  /** Environment facts observed from the runtime, when they can be determined. */
89
- export interface RuntimeEnvironment {
73
+ interface RuntimeEnvironment {
90
74
  platform?: string
91
75
  shell?: string
92
76
  runtime?: string
93
77
  }
94
-
95
- export interface DiscoveryOptions {
78
+ interface DiscoveryOptions {
96
79
  depth?: DiscoveryDepth
97
80
  maxCandidates?: number
98
81
  /** Explicit runtime facts that override situation-prose derivation. */
99
82
  facts?: SituationFacts
100
83
  }
101
-
102
- export interface DiscoveryExplanation {
84
+ interface DiscoveryExplanation {
103
85
  matchedTerms: string[]
104
86
  matchedFields: DiscoveryField[]
105
87
  /** Repository source identifier, when the repository exposes one. */
@@ -107,15 +89,13 @@ export interface DiscoveryExplanation {
107
89
  /** Applicability eligibility for this candidate, retained instead of a score. */
108
90
  applicability?: ApplicabilityMatch
109
91
  }
110
-
111
- export interface DiscoveryCandidate {
92
+ interface DiscoveryCandidate {
112
93
  claim: AcquiredClaim
113
94
  explanation: DiscoveryExplanation
114
95
  /** Derived currentness, so the projection renders what discovery resolved. */
115
96
  currentness?: CurrentnessState
116
97
  }
117
-
118
- export type OmissionReason =
98
+ type OmissionReason =
119
99
  | 'retracted'
120
100
  | 'superseded'
121
101
  | 'expired'
@@ -124,30 +104,26 @@ export type OmissionReason =
124
104
  | 'no-term-match'
125
105
  | 'limit'
126
106
  | 'budget'
127
-
128
- export type OmissionGate =
107
+ type OmissionGate =
129
108
  | 'revision-resolution'
130
109
  | 'scope'
131
110
  | 'freshness'
132
111
  | 'applicability'
133
112
  | 'ranking'
134
113
  | 'projection'
135
-
136
- export interface OmissionRecord {
114
+ interface OmissionRecord {
137
115
  id: string
138
116
  reason: OmissionReason
139
117
  gate: OmissionGate
140
118
  detail?: string
141
119
  }
142
-
143
- export interface OmissionManifest {
120
+ interface OmissionManifest {
144
121
  considered: number
145
122
  included: number
146
123
  items: OmissionRecord[]
147
124
  byReason: Array<{ reason: OmissionReason; count: number }>
148
125
  }
149
-
150
- export interface DiscoveryResult {
126
+ interface DiscoveryResult {
151
127
  knowledgeVersion: number
152
128
  depth: DiscoveryDepth
153
129
  queryTerms: string[]
@@ -157,18 +133,15 @@ export interface DiscoveryResult {
157
133
  /** Claims considered and not returned, with the decisive gate and reason. */
158
134
  omissions?: OmissionRecord[]
159
135
  }
160
-
161
- export interface ProjectionOptions {
136
+ interface ProjectionOptions {
162
137
  maxCandidates?: number
163
138
  /** Maximum UTF-16 characters in the text representation. Not an LLM token budget. */
164
139
  maxCharacters?: number
165
140
  /** Presentation mode: compact gist+ids, standard full record, or full alias. */
166
141
  format?: 'compact' | 'standard' | 'full'
167
142
  }
168
-
169
- export type ProjectedExperienceStatus = 'prior-acquired-experience-candidate'
170
-
171
- export interface ProjectedExperience {
143
+ type ProjectedExperienceStatus = 'prior-acquired-experience-candidate'
144
+ interface ProjectedExperience {
172
145
  id: string
173
146
  status: ProjectedExperienceStatus
174
147
  experience: JsonValue
@@ -182,8 +155,7 @@ export interface ProjectedExperience {
182
155
  /** Derived currentness of the underlying claim, when discovery computed it. */
183
156
  currentness?: CurrentnessState
184
157
  }
185
-
186
- export type CurrentnessState =
158
+ type CurrentnessState =
187
159
  | 'historical'
188
160
  | 'superseded'
189
161
  | 'expired'
@@ -191,8 +163,7 @@ export type CurrentnessState =
191
163
  | 'unverified'
192
164
  | 'contested'
193
165
  | 'unknown-currentness'
194
-
195
- export interface ContextProjection {
166
+ interface ContextProjection {
196
167
  format: 'dotmem-context-v1'
197
168
  status: 'candidate-context-not-current-truth'
198
169
  notice: 'Prior acquired experience supplied as untrusted contextual data. Verify against current reality before relying on it.'
@@ -204,24 +175,22 @@ export interface ContextProjection {
204
175
  manifest?: OmissionManifest
205
176
  text: string
206
177
  }
207
-
208
178
  /**
209
179
  * A field-level patch operation recorded in the sync journal instead of
210
180
  * recording the entire entity. Enables automatic merging when two devices
211
181
  * edit different fields of the same object.
212
182
  */
213
- export interface PatchOperation {
183
+ interface PatchOperation {
214
184
  op: 'set' | 'delete'
215
185
  path: string
216
186
  value?: unknown
217
187
  }
218
-
219
188
  /**
220
189
  * Logical operations recorded in the local sync journal.
221
190
  * The `delete` operation creates an explicit tombstone entry so concurrent
222
191
  * updates/replay do not resurrect deleted values.
223
192
  */
224
- export type MemoryOperation =
193
+ type MemoryOperation =
225
194
  | 'remember'
226
195
  | 'update'
227
196
  | 'forget'
@@ -230,21 +199,18 @@ export type MemoryOperation =
230
199
  | 'supersede'
231
200
  | 'delete'
232
201
  | 'patch'
233
-
234
202
  /**
235
203
  * Synchronization state of a journal entry against a remote/cloud backend.
236
204
  */
237
- export type MemorySync = 'pending' | 'synced' | 'conflict' | 'error'
238
-
239
- export type SyncDirection = 'up' | 'down' | 'both'
240
-
205
+ type MemorySync = 'pending' | 'synced' | 'conflict' | 'error'
206
+ type SyncDirection = 'up' | 'down' | 'both'
241
207
  /**
242
208
  * Pluggable cloud/sync transport. dotmem never ships a credential flow:
243
209
  * the application supplies a `provider` that knows how to talk to its backend
244
210
  * (REST, WebSocket, Supabase, a custom agent server, ...). dotmem owns the
245
211
  * local journal, the provider only moves operations.
246
212
  */
247
- export interface SyncProvider {
213
+ interface SyncProvider {
248
214
  /** Pushes pending local operations; returns ids that were accepted */
249
215
  push(ops: MemoryEntry[]): Promise<{ synced: string[]; conflicts?: string[]; error?: string }>
250
216
  /** Optional pull of remote operations newer than `since` (epoch ms) */
@@ -262,8 +228,7 @@ export interface SyncProvider {
262
228
  */
263
229
  resolveConflict?(local: MemoryEntry, remote: MemoryEntry): Promise<'local' | 'remote' | 'merge'>
264
230
  }
265
-
266
- export interface SyncConfig {
231
+ interface SyncConfig {
267
232
  /** Sync provider implementation (application supplied) */
268
233
  provider?: SyncProvider
269
234
  /** Which direction to sync; 'both' is the default */
@@ -274,15 +239,13 @@ export interface SyncConfig {
274
239
  * different namespaces cannot read each other's operations. */
275
240
  namespace?: string
276
241
  }
277
-
278
- export interface SyncAck {
242
+ interface SyncAck {
279
243
  synced: string[]
280
244
  conflicts?: string[]
281
245
  error?: string
282
246
  resolved?: { id: string; resolution: 'local' | 'remote' | 'merge' }[]
283
247
  }
284
-
285
- export interface MemoryEntry<T = any> {
248
+ interface MemoryEntry<T = any> {
286
249
  id: string
287
250
  key: string
288
251
  value: T
@@ -321,8 +284,7 @@ export interface MemoryEntry<T = any> {
321
284
  acquiredAt?: string
322
285
  /** Epoch ms when this entry expires and should become inactive. Not present on AcquiredClaim; see MemoryOptions. */
323
286
  }
324
-
325
- export interface RememberOptions<T = any> {
287
+ interface RememberOptions<T = any> {
326
288
  id?: string
327
289
  type?: MemoryType
328
290
  confidence?: number
@@ -331,8 +293,7 @@ export interface RememberOptions<T = any> {
331
293
  tags?: string | string[]
332
294
  source?: string
333
295
  }
334
-
335
- export interface AcquireOptions {
296
+ interface AcquireOptions {
336
297
  id?: string
337
298
  knowledge: JsonValue
338
299
  applicability: Record<string, JsonPrimitive>
@@ -351,27 +312,23 @@ export interface AcquireOptions {
351
312
  /** Bootstrap ordering metadata (P1-P5), not authority. Absence means unclassified. */
352
313
  bootstrapPriority?: 'P1' | 'P2' | 'P3' | 'P4' | 'P5' | 'unclassified'
353
314
  }
354
-
355
- export interface RecallOptions {
315
+ interface RecallOptions {
356
316
  type?: MemoryType | MemoryType[]
357
317
  tags?: string | string[]
358
318
  minConfidence?: number
359
319
  includeObsolete?: boolean
360
320
  }
361
-
362
- export interface ContextOptions {
321
+ interface ContextOptions {
363
322
  tags?: string | string[]
364
323
  types?: MemoryType | MemoryType[]
365
324
  minConfidence?: number
366
325
  maxEntries?: number
367
326
  scopes?: MemoryScope[]
368
327
  }
369
-
370
- export interface AcquiredContextOptions {
328
+ interface AcquiredContextOptions {
371
329
  acquired: Record<string, JsonPrimitive> | Record<string, JsonPrimitive>[]
372
330
  }
373
-
374
- export interface ContextEntry {
331
+ interface ContextEntry {
375
332
  key: string
376
333
  value: any
377
334
  type: MemoryType
@@ -383,8 +340,7 @@ export interface ContextEntry {
383
340
  tagBreadth: number
384
341
  lastAccessedAt: number
385
342
  }
386
-
387
- export interface MemoryStats {
343
+ interface MemoryStats {
388
344
  total: number
389
345
  byScope: Record<MemoryScope, number>
390
346
  byType: Partial<Record<MemoryType, number>>