dotmem 0.2.3 → 0.2.5

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/README.md CHANGED
@@ -1,456 +1,461 @@
1
- # Dotmem (.mem)
2
- ![Dotmem banner](https://raw.githubusercontent.com/passariello/container/refs/heads/main/dotmem/banner.svg)
3
-
4
- **Memory. Identity. Continuity.**
5
-
6
- **AI provides intelligence. Dotmem provides continuity.**
7
-
8
- Your memory should not belong to the model, the provider, or the platform. It should belong to you.
9
-
10
- Dotmem is an independent, local-first memory runtime for AI agents and applications. It preserves experience, context, provenance, and identity across sessions, models, providers, and machines. Every acquired claim carries evidence and an applicability scope, every write passes through policy, and retrieval is deterministic and reproducible. No embeddings, no vector store, no model dependency.
11
-
12
- ```bash
13
- npm install dotmem
14
- ```
15
-
16
- > **Retrieval is lexical and structured, not semantic.** Same store + same query = same result. See [Retrieval model](#retrieval-model).
17
-
18
- ---
19
-
20
- ## Why Dotmem
21
-
22
- A conversation ends. A session disappears. A model changes. A provider is replaced. A new host starts with no reliable understanding of what happened before. Dotmem separates intelligence from continuity: the model reasons and generates, Dotmem keeps the experience.
23
-
24
- **Change the model. Change the provider. Keep the continuity.**
25
-
26
- | You need | Dotmem gives you |
27
- |---|---|
28
- | Memory you can audit | Claims with evidence, provenance, and epistemic type |
29
- | Memory that doesn't leak into the wrong context | Applicability-scoped eligibility on retrieval |
30
- | Bounded prompts | `project()` builds context under a character/candidate budget |
31
- | Safe agent writes | Policy-gated acquisition; the MCP server is **read-only by default** |
32
- | Continuity across sessions | Snapshots, checkpoints, compaction, open loops |
33
- | Vendor independence | Works with any model, host, or client |
34
-
35
- **Dotmem is probably not what you want if** your main need is fuzzy semantic recall over large unstructured text. Use a vector/embedding store for that, optionally alongside Dotmem for the governed, auditable part.
36
-
37
- ---
38
-
39
- ## Quick Start - Coding
40
-
41
- The runtime initializes lazily on first call. No `init()` required. Requires Node.js >= 20 (also `bun add dotmem` / `pnpm add dotmem`).
42
-
43
- ```typescript
44
- import { memory } from 'dotmem'
45
-
46
- // 1. Acquire durable, evidenced experience (persists as .mem files)
47
- await memory.acquire({
48
- id: 'user.language-preference',
49
- knowledge: { language: 'TypeScript' },
50
- applicability: { area: 'language-selection' },
51
- evidence: [
52
- {
53
- id: 'conv-001',
54
- source: 'conversation',
55
- observedAt: new Date().toISOString()
56
- }
57
- ],
58
- epistemicType: 'observed'
59
- })
60
-
61
- // 2. Discover what applies to a situation
62
- const discovery = await memory.discover(
63
- 'User needs a language recommendation for a new project',
64
- { depth: 'current', maxCandidates: 10 }
65
- )
66
-
67
- // 3. Project a bounded context for your LLM prompt
68
- const projection = memory.project(discovery, {
69
- maxCandidates: 8,
70
- maxCharacters: 4000
71
- })
72
-
73
- console.info(projection.text)
74
- ```
75
-
76
- > `projection.text` is the bounded, plain-text context selected for the supplied situation. Its contents depend on the claims in the local store, their applicability, and the projection limits; an empty or new store may return no claims. No fixed output is assumed.
77
-
78
- ### Agent-namespaced memory
79
-
80
- ```typescript
81
- import { createAgentMemory } from 'dotmem/agent'
82
-
83
- const agent = createAgentMemory('support-agent')
84
-
85
- await agent.remember('greeting', 'Hello! How can I help?', {
86
- type: 'fact',
87
- confidence: 0.9,
88
- scope: 'local',
89
- tags: ['greeting']
90
- })
91
- ```
92
-
93
- > ⚠️ **Persistence differs by runtime. Read this before using `remember()`.**
94
-
95
- | API | Browser | Node.js / Bun / Deno |
96
- |---|---|---|
97
- | `memory.acquire()` | See [MEMORY.md](./MEMORY.md) | ✅ Persists as `.mem` files |
98
- | `remember()` with scope `durable` | ✅ IndexedDB | ❌ **Not persisted** (in-memory only, lost on restart) |
99
- | internal `store` / `session` layers | - | ❌ In-memory `Map`, lost on restart |
100
-
101
- > **On Node.js and Bun, use `memory.acquire()` for anything that must survive a restart.** See [MEMORY.md](./MEMORY.md) for scope details.
102
-
103
- ---
104
-
105
- ## Which API should I use?
106
-
107
- | I want to… | Use | Persists on Node/Bun? |
108
- |---|---|---|
109
- | Store a **claim with evidence** that should shape future behavior | `memory.acquire` (or `acquireStaged` to review first) | ✅ |
110
- | Find relevant claims and build a prompt context | `memory.discover` → `memory.project` | n/a (read) |
111
- | Keep a simple typed key/value entry | `memory.remember` / `recall` / `update` / `forget` / `patch` | ⚠️ Only in browser for `durable` scope |
112
- | Give each agent its own partition | `createAgentMemory` from `dotmem/agent` | See `remember` |
113
- | Keep a short-lived scratch note | `memory.note` | - |
114
- | Resume work across sessions | `continuity` (snapshots, checkpoints, open loops) | - |
115
- | Control who/what may write | `memory.policy` | - |
116
-
117
- ### Layers
118
-
119
- | Layer | Entry point | Purpose |
120
- |---|---|---|
121
- | **memory** | `dotmem` | Key/value memory, acquisition lifecycle, journal, sub-facades (`journal`, `note`, `profile`, `policy`, `brain`) |
122
- | **continuity** | `dotmem` | USER + PROJECT + TASK context composition, snapshots, open loops |
123
- | **agent** | `dotmem/agent` | Agent-facing memory with logical namespace partitioning |
124
- | **policy** | `memory.policy` | Policy definition, authority management, three-tier enforcement, privileged out-of-band overrides |
125
- | **profile** | `memory.profile.get(id)` | Read-only built-in identity/persona documents |
126
- | **note** | `memory.note` | Short-lived notes with tags and origins |
127
-
128
- Also exported: `security` and `encryption` (RBAC, audit, consent, AES-GCM and PBKDF2 helpers).
129
-
130
- **Not part of the public runtime surface:** `logic` (experimental, unverified), `knowledge` (internal), `seed` (development-only, requires `--dev`), `llm-cache` (types only, no verified runtime).
131
-
132
- ---
133
-
134
- ## Trust & Observability
135
-
136
- Dotmem makes trust claims evidence-based and auditable, lets you inspect `.mem` contents without mutation, reduces repeated startup calls, and enforces lifecycle requirements on Dotmem-owned task paths.
137
-
138
- ### Trust basis (P1)
139
-
140
- Every projected claim carries a `trustBasis` derived from actual provenance, never from the stored `epistemicType` label alone:
141
-
142
- - **declared** - caller/author assertion without independent validation (default for legacy records)
143
- - **evidenced** - evidence references exist but have not been independently resolved and validated
144
- - **mechanically-checked** - a specific reproducible check was executed and its result recorded
145
- - **externally-attested** - an external attestation exists and is validated by a trusted mechanism
146
-
147
- A URL, evidence ID, signature-like field, or legacy `verified` label never implies `externally-attested`. Legacy `epistemicType: 'verified'` claims remain readable for compatibility but derive their trust from provenance, not the label.
148
-
149
- Caller-supplied `verifiedAt`, `verifiedBy`, and verification status are rejected at untrusted acquisition/write boundaries. Only the trusted verification writer (`dotmem-verify`) persists verification metadata, and only after a supported concrete check succeeds (`regex` and `file-json` checks are implemented; no placeholder verification).
150
-
151
- ### Read-only inspection (P2)
152
-
153
- Inspect a `.mem` package without mutating the store or package:
154
-
155
- ```bash
156
- npx dotmem inspect path/to/file.mem
157
- npx dotmem inspect path/to/file.mem --format json --limit 20
158
- npx dotmem inspect path/to/file.mem --no-redact # local CLI only; redacts secrets by default
159
- npx dotmem dump # bounded store-wide dump, redacted
160
- npx dotmem diff FILE_A.mem FILE_B.mem # deterministic read-only diff
161
- ```
162
-
163
- Secret-shaped values are redacted by default. MCP inspection (`dotmem_inspect`) stays redacted with no raw-output bypass. Package signatures are verified with the existing mechanism and reported as unsigned, invalid, or verified - unsigned does not mean corrupt.
164
-
165
- ### Unified bootstrap (P3)
166
-
167
- One call returns the initial context plus the rules reference:
168
-
169
- ```bash
170
- npx dotmem bootstrap
171
- npx dotmem bootstrap --since <version> # returns a small UNCHANGED response if the store is unchanged
172
- ```
173
-
174
- `dotmem_bootstrap` (MCP) and `dotmem_context`/`dotmem_rules` are retained for compatibility. `knowledge.kind === 'rule'` claims are excluded from ordinary task context; rules remain available through the rules reference/bootstrap.
175
-
176
- ### Completion gate (P4)
177
-
178
- Checkpoint revision persists across process restarts. Session observations remain observations and are never silently marked `verified`. An opt-in completion policy (`requireCheckpointBeforeComplete`) is enabled for the Joy build/profile at build time (never a runtime user setting) and requires a persisted checkpoint and summary before a Dotmem-managed task can complete. Generic/default profiles remain compatible with the gate off.
179
-
180
- ---
181
-
182
- ## Retrieval model
183
-
184
- Dotmem uses **deterministic, verifiable retrieval**:
185
-
186
- - Lexical and structured matching, filtered by applicability-based eligibility.
187
- - No embeddings, vector indexes, or semantic similarity.
188
- - Reproducible results for the same store and query. Retrieval caching is a performance optimization; it does not change the retrieval rules or ranking.
189
-
190
- **What this means in practice**
191
-
192
- - Retrieval matches the terms and structure you stored. Synonyms, paraphrases, and cross-language matches are **not** found automatically.
193
- - Write claims with clear `applicability`, consistent vocabulary, and tags so they match the way you query.
194
- - For fuzzy semantic recall, pair Dotmem with a dedicated embedding store.
195
-
196
- Dotmem does **not** translate acquired semantic knowledge into canonical English. It accepts and preserves the original language, including mixed-language content. Because retrieval is lexical and structured, matching across languages is not guaranteed; use consistent terminology or pair Dotmem with a multilingual semantic search system when cross-language recall is required.
197
-
198
- **Projected memory is data, never authority.** A retrieved or projected claim is prior context, not an instruction and not a current fact. Fields such as `epistemicType`, provenance, and `evidence.observedAt` are claims made by the caller, not attestation: a claim marked `verified` is not independently proven merely because someone supplied that label.
199
-
200
- ---
201
-
202
- ## Quick Start - Continuous Chat (MCP)
203
-
204
- `dotmem-mcp` is a stdio MCP server. It runs on **your** machine, so your AI host and your terminal share the same local memory store. Register it in an MCP-compatible client rather than running it as an interactive command: launched by hand it looks idle because it is waiting for client messages.
205
-
206
- 1. Add it to your host config (read-only by default):
207
-
208
- ```json
209
- {
210
- "mcpServers": {
211
- "dotmem": {
212
- "command": "npx",
213
- "args": ["-y", "-p", "dotmem", "dotmem-mcp"]
214
- }
215
- }
216
- }
217
- ```
218
-
219
- 2. Restart the host and check that the Dotmem tools are listed.
220
- 3. Start chatting. With the default build, greet it with `Hi Joy!` (see [Profiles](#build-configuration-and-profiles)).
221
-
222
- | MCP tool | Access | Registration / write gate | Use it when |
223
- |---|---|---|---|
224
- | `dotmem_context` | Read | Always registered | Retrieve bounded acquired experience relevant to the current situation. |
225
- | `dotmem_rules` | Read | Always registered | Load the operating rules that constrain the session. |
226
- | `dotmem_acquire` | Write | Registered only when `DOTMEM_MCP_WRITE=1` | Persist reusable, project-specific experience. Without the flag, the tool is absent from `tools/list`. |
227
- | `dotmem_verify` | Write | Registered only when `DOTMEM_MCP_WRITE=1` | Run due freshness probes and persist verification metadata via the trusted path. |
228
- | `dotmem_inspect` | Read | Always registered | Read-only `.mem`/package/store inspection; redacted by default, no raw bypass. |
229
- | `dotmem_bootstrap` | Read | Always registered | Unified bootstrap: context plus rules reference in one call; `sinceVersion` short-circuits to `UNCHANGED`. |
230
- | `dotmem_continuity` | Read + conditional write actions | Always registered; write actions require `DOTMEM_MCP_WRITE=1` | Read status, summaries, open loops, and evaluations; with write access, create checkpoints and manage open loops. Without the flag, write actions return an authorization error. |
231
-
232
- ### Read-only by default
233
-
234
- Write access is an explicit opt-in. Enable it only if the host should be able to modify memory:
235
-
236
- ```bash
237
- DOTMEM_MCP_WRITE=1
238
- ```
239
-
240
- ### Things that commonly go wrong
241
-
242
- - **Hosted chats don't share your machine's store.** If an AI runs `npx dotmem` inside a hosted chat, it writes to that chat's sandbox, not to your terminal's storage, and that state may disappear when the session ends. Use the MCP server on your own machine for continuity across sessions.
243
- - **The server and the CLI must resolve the same storage root** if they are expected to share memory. Set `DOTMEM_STORAGE_ROOT` in the client's environment if needed.
244
- - **GUI clients often don't inherit your shell's PATH.** If a global install doesn't start, use the absolute path of the binary.
245
- - **Pin the version** (`dotmem-mcp@x.y.z`) for long-lived setups instead of pulling the latest on every launch.
246
-
247
- ### Host configurations
248
-
249
- <details>
250
- <summary><b>Claude Desktop</b></summary>
251
-
252
- ```json
253
- {
254
- "mcpServers": {
255
- "dotmem": {
256
- "command": "npx",
257
- "args": ["-y", "-p", "dotmem", "dotmem-mcp"],
258
- "env": { "DOTMEM_MCP_WRITE": "1" }
259
- }
260
- }
261
- }
262
- ```
263
-
264
- Remove the `env` line for read-only.
265
-
266
- </details>
267
-
268
- <details>
269
- <summary><b>Claude Code</b></summary>
270
-
271
- ```bash
272
- # read-only
273
- claude mcp add --transport stdio dotmem -- npx -y -p dotmem dotmem-mcp
274
-
275
- # with write access
276
- claude mcp add \
277
- --env DOTMEM_MCP_WRITE=1 \
278
- --transport stdio \
279
- dotmem -- npx -y -p dotmem dotmem-mcp
280
- ```
281
-
282
- </details>
283
-
284
- <details>
285
- <summary><b>Kilo / OpenCode</b></summary>
286
-
287
- ```jsonc
288
- {
289
- "mcp": {
290
- "dotmem": {
291
- "type": "local",
292
- "command": ["npx", "-y", "-p", "dotmem", "dotmem-mcp"],
293
- "enabled": true
294
- // For write access, add:
295
- // "environment": { "DOTMEM_MCP_WRITE": "1" }
296
- }
297
- }
298
- }
299
- ```
300
-
301
- </details>
302
-
303
- <details>
304
- <summary><b>Windows (cmd.exe)</b></summary>
305
-
306
- On Windows, `npx` may not be directly executable by an MCP host. Use `cmd /c npx`:
307
-
308
- ```json
309
- {
310
- "mcpServers": {
311
- "dotmem": {
312
- "command": "cmd",
313
- "args": ["/c", "npx", "-y", "-p", "dotmem", "dotmem-mcp"]
314
- }
315
- }
316
- }
317
- ```
318
-
319
- Add `"env": { "DOTMEM_MCP_WRITE": "1" }` for write access.
320
-
321
- </details>
322
-
323
- See [MEMORY.md](./MEMORY.md) for the complete MCP tool list and write-gating details.
324
-
325
- ---
326
-
327
- ## Memory, policy, and authority are separate
328
-
329
- | Plane | Responsibility |
330
- |---|---|
331
- | Memory | What has been learned or observed |
332
- | Policy | Which rules apply |
333
- | Authority | Who or what is allowed to authorize an operation |
334
-
335
- A retrieved memory item can inform a decision but cannot authorize it. Historical identity supports continuity but does not authenticate the current speaker. A change of model or provider must not silently redefine the identity associated with a memory.
336
-
337
- ---
338
-
339
- ## Storage and format
340
-
341
- - **Default location:** `<user-home>/.dotmem`
342
- - **Custom location:** set `DOTMEM_STORAGE_ROOT`, or run `dotmem storage relocate <path>`.
343
- - **Format:** `.mem` files are versioned, compressed ZIP archives (DEFLATE) with SHA-256 integrity manifests. They are binary and not directly human-readable. V2 writes, V1 reads.
344
- - **Concurrency:** an in-process write queue, directory locks, expected-version checks, and atomic writes with backups protect concurrent updates.
345
-
346
- Inspect a package with the read-only CLI command:
347
-
348
- ```bash
349
- npx dotmem inspect path/to/file.mem
350
- ```
351
-
352
- It validates and decodes the `.mem` package, including its integrity, structure, and knowledge claims. The JavaScript API also exposes `dotmem.inspectMem(path)`. Do not edit `.mem` files directly; they are binary packages.
353
-
354
- - **Store layout:** `user.mem` holds user-level experience, `agent.mem` holds agent operating knowledge, and `projects/<project-id>.mem` holds project experience. The project ID resolves from `DOTMEM_PROJECT_ID`, then `package.json`'s `name`, then the current directory name.
355
- - **Secret sanitization:** `memory.acquire()` sanitizes secret-looking keys and values before persistence. This is defensive sanitization, not encryption, a secret vault, or access control.
356
- - **Invalid storage root:** A configured root that is missing, inaccessible, or invalid stops resolution with an explicit error. Dotmem does not silently fall back to another path or search the filesystem.
357
-
358
- ### Limits
359
-
360
- | Limit | Value |
361
- |---|---|
362
- | Package size (compressed) | 10 MiB |
363
- | Package size (uncompressed) | 25 MiB |
364
- | Entries per package | 128 |
365
- | Maximum compression ratio | 200:1 |
366
-
367
- These are package validation limits, not performance or scalability guarantees. Context retrieval is bounded and cached; maximum numbers of claims, users, and concurrent processes have **not been benchmarked**.
368
-
369
- ---
370
-
371
- ## Security and limitations
372
-
373
- Dotmem is designed to preserve user control and make its boundaries explicit.
374
-
375
- - **No encryption at rest.** `.mem` files and vault data are stored unencrypted. The encryption helpers are not integrated with `.mem` or vault storage, and no supported option enables encryption at rest today. Do not store data that requires encryption at rest.
376
- - **Integrity is not encryption or access control.** SHA-256 manifests detect corruption; they do not keep anyone out.
377
- - **Filesystem access is governed by the operating system,** not by an independent Dotmem authorization boundary.
378
- - **Retrieval is lexical and structured,** not vector or embedding search.
379
- - **Dotmem governs context, not model behavior.** Projection is bounded, but external host behavior is outside Dotmem's enforcement boundary, and a downstream model may still misread a projected item.
380
- - **Performance and maximum store sizes** require workload-specific benchmarking.
381
-
382
- Do not treat Dotmem as a replacement for a database authorization system, a secrets manager, or an encrypted backup solution. See [SECURITY.md](./SECURITY.md) for the trust model.
383
-
384
- ---
385
-
386
- ## Design principles
387
-
388
- 1. **User-owned, local-first memory.** No provider owns it or locks it in.
389
- 2. **Provider independent and portable.** No model, host, or provider defines identity or continuity.
390
- 3. **Memory is not authority.** Retrieval never turns a claim into policy.
391
- 4. **Identity survives the carrier.** Runtime metadata never redefines canonical identity.
392
- 5. **Provenance matters, and labels are not proof.** A declared confidence level is not evidence.
393
- 6. **Memory stays correctable.** Revision, supersession, and retraction are part of the model.
394
- 7. **Honest boundaries.** The runtime says what it knows, what it checks, and what it cannot enforce.
395
-
396
- Acquired claims are corrected through explicit revision relations: `refines`, `supersedes`, and `retracts`. Historical claims are not silently overwritten. The key/value API has `forget()`; this README does not promise physical deletion of acquired claims.
397
-
398
- Dotmem is not an AI model, an autonomous reasoning engine, or a vendor-specific agent framework. It is the continuity infrastructure AI systems can use. Longer reflections live outside this README.
399
-
400
- ---
401
-
402
- ## Build configuration and profiles
403
-
404
- Dotmem core is model- and provider-independent. The assistant's identity, behavior profile, and product branding are chosen **by the product owner at build time**, embedded in the build artifact, and immutable at runtime (end users cannot change them).
405
-
406
- - The **default build** uses the **Joy** profile. Joy is a selectable profile, not a mandatory identity of the runtime. Other builds can use different names, aliases, behavior profiles, and branding on the same runtime.
407
- - Joy's identity and behavior documents live under `context/profiles/joy/`; the manifest `ai.json` defines the canonical identity, aliases, and declared documents.
408
- - The `profile` layer follows the package semver contract.
409
-
410
- See [AI.md](./context/templates/AI.md) for the assistant operating contract and profile configuration model.
411
-
412
- ---
413
-
414
- ## Documentation
415
-
416
- | Document | Description |
417
- |---|---|
418
- | [MEMORY.md](./MEMORY.md) | Memory model: acquisition contract, policy language, epistemic typing, enforcement, continuity, identity |
419
- | [AGENTS.md](./AGENTS.md) | Agent working rules, activation phrases, complete `memory.*` surface |
420
- | [SECURITY.md](./SECURITY.md) | Encryption helpers, multitenancy, key management, trust model, JHF, sandbox |
421
- | [AI.md](./context/templates/AI.md) | Assistant operating contract and profile configuration |
422
- | [PACKAGE.md](./PACKAGE.md) | Package contents, full quick start, dependency graph |
423
- | License | MIT (see `package.json`) |
424
-
425
- ---
426
-
427
- ## Compatibility
428
-
429
- | Runtime | Status |
430
- |---|---|
431
- | Node.js >= 20.0.0 | Declared in `package.json` engines; tested in CI (20.x, 22.x) |
432
- | Bun >= 1.0 | Tested in CI (1.x) |
433
- | Browser | ES2020+ with IndexedDB, localStorage, sessionStorage |
434
- | Deno | Compatible, not routinely tested |
435
-
436
- Persistence rules differ per runtime: see the [persistence warning](#agent-namespaced-memory).
437
-
438
- ---
439
-
440
- ## Project direction
441
-
442
- Dotmem is developed as an independent memory runtime. Long-term objectives: reliable cross-session continuity, portable memory across providers and environments, stronger evidence and verification workflows, transparent memory inspection and management, efficient context projection, and durable lifecycle and checkpoint management. These objectives do not imply that every capability is already implemented; current functionality and limitations are documented above and in the linked documents.
443
-
444
- **Your memory. Your continuity.**
445
-
446
- ---
447
-
448
- ## Disclaimer
449
-
450
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. Outputs of AI systems that use Dotmem can be wrong or incomplete; verify critical information independently, and do not store sensitive or confidential data in unencrypted memory.
451
-
452
- ## License
453
-
454
- MIT - Copyright (c) 2026 Dario Passariello.
455
-
456
- SPDX-License-Identifier: `MIT`
1
+ # Dotmem (.mem)
2
+ ![Dotmem banner](https://raw.githubusercontent.com/passariello/container/refs/heads/main/dotmem/banner.svg)
3
+
4
+ **Memory. Identity. Continuity.**
5
+
6
+ **AI provides intelligence. Dotmem provides continuity.**
7
+
8
+ Your memory should not belong to the model, the provider, or the platform. It should belong to you.
9
+
10
+ Dotmem is an independent, local-first memory runtime for AI agents and applications. It preserves experience, context, provenance, and identity across sessions, models, providers, and machines. Every acquired claim carries evidence and an applicability scope, every write passes through policy, and retrieval is deterministic and reproducible. No embeddings, no vector store, no model dependency.
11
+
12
+ ```bash
13
+ npm install dotmem
14
+ ```
15
+
16
+ > **Retrieval is lexical and structured, not semantic.** Same store + same query = same result. See [Retrieval model](#retrieval-model).
17
+
18
+ ---
19
+
20
+ ## Why Dotmem
21
+
22
+ A conversation ends. A session disappears. A model changes. A provider is replaced. A new host starts with no reliable understanding of what happened before. Dotmem separates intelligence from continuity: the model reasons and generates, Dotmem keeps the experience.
23
+
24
+ **Change the model. Change the provider. Keep the continuity.**
25
+
26
+ | You need | Dotmem gives you |
27
+ |---|---|
28
+ | Memory you can audit | Claims with evidence, provenance, and epistemic type |
29
+ | Memory that doesn't leak into the wrong context | Applicability-scoped eligibility on retrieval |
30
+ | Bounded prompts | `project()` builds context under a character/candidate budget |
31
+ | Safe agent writes | Policy-gated acquisition; the MCP server is **read-only by default** |
32
+ | Continuity across sessions | Snapshots, checkpoints, compaction, open loops |
33
+ | Vendor independence | Works with any model, host, or client |
34
+
35
+ **Dotmem is probably not what you want if** your main need is fuzzy semantic recall over large unstructured text. Use a vector/embedding store for that, optionally alongside Dotmem for the governed, auditable part.
36
+
37
+ ---
38
+
39
+ ## Quick Start - Coding
40
+
41
+ The runtime initializes lazily on first call. No `init()` required. Requires Node.js >= 20 (also `bun add dotmem` / `pnpm add dotmem`).
42
+
43
+ ```typescript
44
+ import { memory } from 'dotmem'
45
+
46
+ // 1. Acquire durable, evidenced experience (persists as .mem files)
47
+ await memory.acquire({
48
+ id: 'user.language-preference',
49
+ knowledge: { language: 'TypeScript' },
50
+ applicability: { area: 'language-selection' },
51
+ evidence: [
52
+ {
53
+ id: 'conv-001',
54
+ source: 'conversation',
55
+ observedAt: new Date().toISOString()
56
+ }
57
+ ],
58
+ epistemicType: 'observed'
59
+ })
60
+
61
+ // 2. Discover what applies to a situation
62
+ const discovery = await memory.discover(
63
+ 'User needs a language recommendation for a new project',
64
+ { depth: 'current', maxCandidates: 10 }
65
+ )
66
+
67
+ // 3. Project a bounded context for your LLM prompt
68
+ const projection = memory.project(discovery, {
69
+ maxCandidates: 8,
70
+ maxCharacters: 4000
71
+ })
72
+
73
+ console.info(projection.text)
74
+ ```
75
+
76
+ > `projection.text` is the bounded, plain-text context selected for the supplied situation. Its contents depend on the claims in the local store, their applicability, and the projection limits; an empty or new store may return no claims. No fixed output is assumed.
77
+
78
+ ### Agent-namespaced memory
79
+
80
+ ```typescript
81
+ import { createAgentMemory } from 'dotmem/agent'
82
+
83
+ const agent = createAgentMemory('support-agent')
84
+
85
+ await agent.remember('greeting', 'Hello! How can I help?', {
86
+ type: 'fact',
87
+ confidence: 0.9,
88
+ scope: 'local',
89
+ tags: ['greeting']
90
+ })
91
+ ```
92
+
93
+ > ⚠️ **Persistence differs by runtime. Read this before using `remember()`.**
94
+
95
+ | API | Browser | Node.js / Bun / Deno |
96
+ |---|---|---|
97
+ | `memory.acquire()` | See [MEMORY.md](./MEMORY.md) | ✅ Persists as `.mem` files |
98
+ | `remember()` with scope `durable` | ✅ IndexedDB | ✅ Persists to `.dotmem/memory.kv` (atomic writes, cross-process lock, `.bak` backup) |
99
+ | internal `store` / `session` layers | - | ❌ In-memory `Map`, lost on restart |
100
+
101
+ > **On Node.js and Bun, use `memory.acquire()` for anything that must survive a restart.** See [MEMORY.md](./MEMORY.md) for scope details.
102
+
103
+ ---
104
+
105
+ ## Which API should I use?
106
+
107
+ | I want to… | Use | Persists on Node/Bun? |
108
+ |---|---|---|
109
+ | Store a **claim with evidence** that should shape future behavior | `memory.acquire` (or `acquireStaged` to review first) | ✅ |
110
+ | Find relevant claims and build a prompt context | `memory.discover` → `memory.project` | n/a (read) |
111
+ | Keep a simple typed key/value entry | `memory.remember` / `recall` / `update` / `forget` / `patch` | ✅ On Node/Bun via durable scope; browser-only for IndexedDB |
112
+ | Give each agent its own partition | `createAgentMemory` from `dotmem/agent` | See `remember` |
113
+ | Keep a short-lived scratch note | `memory.note` | - |
114
+ | Resume work across sessions | `continuity` (snapshots, checkpoints, open loops) | - |
115
+ | Control who/what may write | `memory.policy` | - |
116
+
117
+ ### Layers
118
+
119
+ | Layer | Entry point | Purpose |
120
+ |---|---|---|
121
+ | **memory** | `dotmem` | Key/value memory, acquisition lifecycle, journal, sub-facades (`journal`, `note`, `profile`, `policy`, `brain`) |
122
+ | **continuity** | `dotmem` | USER + PROJECT + TASK context composition, snapshots, open loops |
123
+ | **agent** | `dotmem/agent` | Agent-facing memory with logical namespace partitioning |
124
+ | **policy** | `memory.policy` | Policy definition, authority management, three-tier enforcement, privileged out-of-band overrides |
125
+ | **profile** | `memory.profile.get(id)` | Read-only built-in identity/persona documents |
126
+ | **note** | `memory.note` | Short-lived notes with tags and origins |
127
+
128
+ Also exported: `security` and `encryption` (RBAC, audit, consent, AES-GCM and PBKDF2 helpers).
129
+
130
+ **Not part of the public runtime surface:** `logic` (experimental, unverified), `knowledge` (internal), `seed` (development-only, requires `--dev`), `llm-cache` (types only, no verified runtime).
131
+
132
+ ---
133
+
134
+ ## Trust & Observability
135
+
136
+ Dotmem makes trust claims evidence-based and auditable, lets you inspect `.mem` contents without mutation, reduces repeated startup calls, and enforces lifecycle requirements on Dotmem-owned task paths.
137
+
138
+ ### Trust basis (P1)
139
+
140
+ Every projected claim carries a `trustBasis` derived from actual provenance, never from the stored `epistemicType` label alone:
141
+
142
+ - **declared** - caller/author assertion without independent validation (default for legacy records)
143
+ - **evidenced** - evidence references exist but have not been independently resolved and validated
144
+ - **mechanically-checked** - a specific reproducible check was executed and its result recorded
145
+ - **externally-attested** - an external attestation exists and is validated by a trusted mechanism
146
+
147
+ A URL, evidence ID, signature-like field, or legacy `verified` label never implies `externally-attested`. Legacy `epistemicType: 'verified'` claims remain readable for compatibility but derive their trust from provenance, not the label.
148
+
149
+ Caller-supplied `verifiedAt`, `verifiedBy`, and verification status are rejected at untrusted acquisition/write boundaries. Only the trusted verification writer (`dotmem-verify`) persists verification metadata, and only after a supported concrete check succeeds (`regex` and `file-json` checks are implemented; no placeholder verification).
150
+
151
+ ### Read-only inspection (P2)
152
+
153
+ Inspect a `.mem` package without mutating the store or package:
154
+
155
+ ```bash
156
+ npx dotmem inspect path/to/file.mem
157
+ npx dotmem inspect path/to/file.mem --format json --limit 20
158
+ npx dotmem inspect path/to/file.mem --no-redact # local CLI only; redacts secrets by default
159
+ npx dotmem dump # bounded store-wide dump, redacted
160
+ npx dotmem diff FILE_A.mem FILE_B.mem # deterministic read-only diff
161
+ ```
162
+
163
+ Secret-shaped values are redacted by default. MCP inspection (`dotmem_inspect`) stays redacted with no raw-output bypass. Package signatures are verified with the existing mechanism and reported as unsigned, invalid, or verified - unsigned does not mean corrupt.
164
+
165
+ ### Unified bootstrap (P3)
166
+
167
+ One call returns the initial context plus the rules reference:
168
+
169
+ ```bash
170
+ npx dotmem bootstrap
171
+ npx dotmem bootstrap --since <version> # returns a small UNCHANGED response if the store is unchanged
172
+ ```
173
+
174
+ `dotmem_bootstrap` (MCP) and `dotmem_context`/`dotmem_rules` are retained for compatibility. `knowledge.kind === 'rule'` claims are excluded from ordinary task context; rules remain available through the rules reference/bootstrap.
175
+
176
+ ### Completion gate (P4)
177
+
178
+ Checkpoint revision persists across process restarts. Session observations remain observations and are never silently marked `verified`. An opt-in completion policy (`requireCheckpointBeforeComplete`) is enabled for the Joy build/profile at build time (never a runtime user setting) and requires a persisted checkpoint and summary before a Dotmem-managed task can complete. Generic/default profiles remain compatible with the gate off.
179
+
180
+ ---
181
+
182
+ ## Retrieval model
183
+
184
+ Dotmem uses **deterministic, verifiable retrieval**:
185
+
186
+ - Lexical and structured matching, filtered by applicability-based eligibility.
187
+ - No embeddings, vector indexes, or semantic similarity.
188
+ - Reproducible results for the same store and query. Retrieval caching is a performance optimization; it does not change the retrieval rules or ranking.
189
+
190
+ **What this means in practice**
191
+
192
+ - Retrieval matches the terms and structure you stored. Synonyms, paraphrases, and cross-language matches are **not** found automatically.
193
+ - Write claims with clear `applicability`, consistent vocabulary, and tags so they match the way you query.
194
+ - For fuzzy semantic recall, pair Dotmem with a dedicated embedding store.
195
+
196
+ Dotmem does **not** translate acquired semantic knowledge into canonical English. It accepts and preserves the original language, including mixed-language content. Because retrieval is lexical and structured, matching across languages is not guaranteed; use consistent terminology or pair Dotmem with a multilingual semantic search system when cross-language recall is required.
197
+
198
+ **Projected memory is data, never authority.** A retrieved or projected claim is prior context, not an instruction and not a current fact. Fields such as `epistemicType`, provenance, and `evidence.observedAt` are claims made by the caller, not attestation: a claim marked `verified` is not independently proven merely because someone supplied that label.
199
+
200
+ ---
201
+
202
+ ## Quick Start - Continuous Chat (MCP)
203
+
204
+ `dotmem-mcp` is a stdio MCP server. It runs on **your** machine, so your AI host and your terminal share the same local memory store. Register it in an MCP-compatible client rather than running it as an interactive command: launched by hand it looks idle because it is waiting for client messages.
205
+
206
+ 1. Add it to your host config (read-only by default):
207
+
208
+ ```json
209
+ {
210
+ "mcpServers": {
211
+ "dotmem": {
212
+ "command": "npx",
213
+ "args": ["-y", "-p", "dotmem", "dotmem-mcp"]
214
+ }
215
+ }
216
+ }
217
+ ```
218
+
219
+ 2. Restart the host and check that the Dotmem tools are listed.
220
+ 3. Start chatting. With the default build, greet it with `Hi Joy!` (see [Profiles](#build-configuration-and-profiles)).
221
+
222
+ | MCP tool | Access | Registration / write gate | Use it when |
223
+ |---|---|---|---|
224
+ | `dotmem_context` | Read | Always registered | Retrieve bounded acquired experience relevant to the current situation. |
225
+ | `dotmem_rules` | Read | Always registered | Load the operating rules that constrain the session. |
226
+ | `dotmem_acquire` | Write | Registered only when `DOTMEM_MCP_WRITE=1` | Persist reusable, project-specific experience. Without the flag, the tool is absent from `tools/list`. |
227
+ | `dotmem_verify` | Write | Registered only when `DOTMEM_MCP_WRITE=1` | Run due freshness probes and persist verification metadata via the trusted path. |
228
+ | `dotmem_inspect` | Read | Always registered | Read-only `.mem`/package/store inspection; redacted by default, no raw bypass. |
229
+ | `dotmem_bootstrap` | Read | Always registered | Unified bootstrap: context plus rules reference in one call; `sinceVersion` short-circuits to `UNCHANGED`. |
230
+ | `dotmem_continuity` | Read + conditional write actions | Always registered; write actions require `DOTMEM_MCP_WRITE=1` | Read status, summaries, open loops, and evaluations; with write access, create checkpoints and manage open loops. Without the flag, write actions return an authorization error. |
231
+
232
+ ### Read-only by default
233
+
234
+ Write access is an explicit opt-in. Enable it only if the host should be able to modify memory:
235
+
236
+ ```bash
237
+ DOTMEM_MCP_WRITE=1
238
+ ```
239
+
240
+ ### Things that commonly go wrong
241
+
242
+ - **Hosted chats don't share your machine's store.** If an AI runs `npx dotmem` inside a hosted chat, it writes to that chat's sandbox, not to your terminal's storage, and that state may disappear when the session ends. Use the MCP server on your own machine for continuity across sessions.
243
+ - **The server and the CLI must resolve the same storage root** if they are expected to share memory. Set `DOTMEM_STORAGE_ROOT` in the client's environment if needed.
244
+ - **GUI clients often don't inherit your shell's PATH.** If a global install doesn't start, use the absolute path of the binary.
245
+ - **Pin the version** (`dotmem-mcp@x.y.z`) for long-lived setups instead of pulling the latest on every launch.
246
+
247
+ ### Host configurations
248
+
249
+ <details>
250
+ <summary><b>Claude Desktop</b></summary>
251
+
252
+ ```json
253
+ {
254
+ "mcpServers": {
255
+ "dotmem": {
256
+ "command": "npx",
257
+ "args": ["-y", "-p", "dotmem", "dotmem-mcp"],
258
+ "env": { "DOTMEM_MCP_WRITE": "1" }
259
+ }
260
+ }
261
+ }
262
+ ```
263
+
264
+ Remove the `env` line for read-only.
265
+
266
+ </details>
267
+
268
+ <details>
269
+ <summary><b>Claude Code</b></summary>
270
+
271
+ ```bash
272
+ # read-only
273
+ claude mcp add --transport stdio dotmem -- npx -y -p dotmem dotmem-mcp
274
+
275
+ # with write access
276
+ claude mcp add \
277
+ --env DOTMEM_MCP_WRITE=1 \
278
+ --transport stdio \
279
+ dotmem -- npx -y -p dotmem dotmem-mcp
280
+ ```
281
+
282
+ </details>
283
+
284
+ <details>
285
+ <summary><b>Kilo / OpenCode</b></summary>
286
+
287
+ ```jsonc
288
+ {
289
+ "mcp": {
290
+ "dotmem": {
291
+ "type": "local",
292
+ "command": ["npx", "-y", "-p", "dotmem", "dotmem-mcp"],
293
+ "enabled": true
294
+ // For write access, add:
295
+ // "environment": { "DOTMEM_MCP_WRITE": "1" }
296
+ }
297
+ }
298
+ }
299
+ ```
300
+
301
+ </details>
302
+
303
+ <details>
304
+ <summary><b>Windows (cmd.exe)</b></summary>
305
+
306
+ On Windows, `npx` may not be directly executable by an MCP host. Use `cmd /c npx`:
307
+
308
+ ```json
309
+ {
310
+ "mcpServers": {
311
+ "dotmem": {
312
+ "command": "cmd",
313
+ "args": ["/c", "npx", "-y", "-p", "dotmem", "dotmem-mcp"]
314
+ }
315
+ }
316
+ }
317
+ ```
318
+
319
+ Add `"env": { "DOTMEM_MCP_WRITE": "1" }` for write access.
320
+
321
+ </details>
322
+
323
+ See [MEMORY.md](./MEMORY.md) for the complete MCP tool list and write-gating details.
324
+
325
+ ---
326
+
327
+ ## Memory, policy, and authority are separate
328
+
329
+ | Plane | Responsibility |
330
+ |---|---|
331
+ | Memory | What has been learned or observed |
332
+ | Policy | Which rules apply |
333
+ | Authority | Who or what is allowed to authorize an operation |
334
+
335
+ A retrieved memory item can inform a decision but cannot authorize it. Historical identity supports continuity but does not authenticate the current speaker. A change of model or provider must not silently redefine the identity associated with a memory.
336
+
337
+ ---
338
+
339
+ ## Storage and format
340
+
341
+ - **Default location:** `<user-home>/.dotmem`
342
+ - **Custom location:** set `DOTMEM_STORAGE_ROOT`, or run `dotmem storage relocate <path>`.
343
+ - **Format:** `.mem` files are versioned, compressed ZIP archives (DEFLATE) with SHA-256 integrity manifests. They are binary and not directly human-readable. V2 writes, V1 reads.
344
+ - **Concurrency:** an in-process write queue, directory locks, expected-version checks, and atomic writes with backups protect concurrent updates.
345
+
346
+ Inspect a package with the read-only CLI command:
347
+
348
+ ```bash
349
+ npx dotmem inspect path/to/file.mem
350
+ ```
351
+
352
+ It validates and decodes the `.mem` package, including its integrity, structure, and knowledge claims. The JavaScript API also exposes `dotmem.inspectMem(path)`. Do not edit `.mem` files directly; they are binary packages.
353
+
354
+ - **Store layout:** `user.mem` holds user-level experience, `agent.mem` holds agent operating knowledge, and `projects/<project-id>.mem` holds project experience. The project ID resolves from `DOTMEM_PROJECT_ID`, then `package.json`'s `name`, then the current directory name.
355
+ - **Secret sanitization:** `memory.acquire()` sanitizes secret-looking keys and values before persistence. This is defensive sanitization, not encryption, a secret vault, or access control.
356
+ - **Invalid storage root:** A configured root that is missing, inaccessible, or invalid stops resolution with an explicit error. Dotmem does not silently fall back to another path or search the filesystem.
357
+
358
+ ### Limits
359
+
360
+ | Limit | Value |
361
+ |---|---|
362
+ | Package size (compressed) | 10 MiB |
363
+ | Package size (uncompressed) | 25 MiB |
364
+ | Entries per package | 128 |
365
+ | Maximum compression ratio | 200:1 |
366
+
367
+ These are package validation limits, not performance or scalability guarantees. Context retrieval is bounded and cached; maximum numbers of claims, users, and concurrent processes have **not been benchmarked**.
368
+
369
+ ---
370
+
371
+ ## Archive and search
372
+
373
+ Dotmem now includes a file-backed text archive (`.arch.mem`, UUID-named ZIP) for large documents, with local BM25 search over claims and archives. Archives are text-only, checksum-protected, and do not consume `.mem` capacity. Use `npx dotmem archive ...` and `npx dotmem search ...`.
374
+
375
+ ## Security and limitations
376
+
377
+ Dotmem is designed to preserve user control and make its boundaries explicit.
378
+
379
+ - **No encryption at rest.** `.mem` files and vault data are stored unencrypted. The encryption helpers are not integrated with `.mem` or vault storage, and no supported option enables encryption at rest today. Do not store data that requires encryption at rest.
380
+ - **Integrity is not encryption or access control.** SHA-256 manifests detect corruption; they do not keep anyone out.
381
+ - **Filesystem access is governed by the operating system,** not by an independent Dotmem authorization boundary.
382
+ - **Retrieval is lexical and structured,** not vector or embedding search.
383
+ - **Dotmem governs context, not model behavior.** Projection is bounded, but external host behavior is outside Dotmem's enforcement boundary, and a downstream model may still misread a projected item.
384
+ - **Multi-process coordination** uses advisory file locks (`withStorageLock`) and in-process write queues (`withStoreQueue`) in the storage coordinator. Each agent that uses its own partitioned storage (agent-namespaced keys or separate `.mem` files) avoids contention entirely; shared stores are serialized. This is coordination, not a distributed transaction system.
385
+ - **Identity persistence SLA**: writes use `handle.sync()` + directory fsync + atomic rename + `.bak` backup. A write is durable once `remember()`/`acquire()` resolves. Crash during write leaves the previous valid version (`.bak`) recoverable. No formal uptime SLA is provided; durability depends on the host filesystem.
386
+
387
+ Do not treat Dotmem as a replacement for a database authorization system, a secrets manager, or an encrypted backup solution. See [SECURITY.md](./SECURITY.md) for the trust model.
388
+
389
+ ---
390
+
391
+ ## Design principles
392
+
393
+ 1. **User-owned, local-first memory.** No provider owns it or locks it in.
394
+ 2. **Provider independent and portable.** No model, host, or provider defines identity or continuity.
395
+ 3. **Memory is not authority.** Retrieval never turns a claim into policy.
396
+ 4. **Identity survives the carrier.** Runtime metadata never redefines canonical identity.
397
+ 5. **Provenance matters, and labels are not proof.** A declared confidence level is not evidence.
398
+ 6. **Memory stays correctable.** Revision, supersession, and retraction are part of the model.
399
+ 7. **Honest boundaries.** The runtime says what it knows, what it checks, and what it cannot enforce.
400
+
401
+ Acquired claims are corrected through explicit revision relations: `refines`, `supersedes`, and `retracts`. Historical claims are not silently overwritten. The key/value API has `forget()`; this README does not promise physical deletion of acquired claims.
402
+
403
+ Dotmem is not an AI model, an autonomous reasoning engine, or a vendor-specific agent framework. It is the continuity infrastructure AI systems can use. Longer reflections live outside this README.
404
+
405
+ ---
406
+
407
+ ## Build configuration and profiles
408
+
409
+ Dotmem core is model- and provider-independent. The assistant's identity, behavior profile, and product branding are chosen **by the product owner at build time**, embedded in the build artifact, and immutable at runtime (end users cannot change them).
410
+
411
+ - The **default build** uses the **Joy** profile. Joy is a selectable profile, not a mandatory identity of the runtime. Other builds can use different names, aliases, behavior profiles, and branding on the same runtime.
412
+ - Joy's identity and behavior documents live under `context/profiles/joy/`; the manifest `ai.json` defines the canonical identity, aliases, and declared documents.
413
+ - The `profile` layer follows the package semver contract.
414
+
415
+ See [AI.md](./context/templates/AI.md) for the assistant operating contract and profile configuration model.
416
+
417
+ ---
418
+
419
+ ## Documentation
420
+
421
+ | Document | Description |
422
+ |---|---|
423
+ | [MEMORY.md](./MEMORY.md) | Memory model: acquisition contract, policy language, epistemic typing, enforcement, continuity, identity |
424
+ | [AGENTS.md](./AGENTS.md) | Agent working rules, activation phrases, complete `memory.*` surface |
425
+ | [SECURITY.md](./SECURITY.md) | Encryption helpers, multitenancy, key management, trust model, JHF, sandbox |
426
+ | [AI.md](./context/templates/AI.md) | Assistant operating contract and profile configuration |
427
+ | [PACKAGE.md](./PACKAGE.md) | Package contents, full quick start, dependency graph |
428
+ | License | MIT (see `package.json`) |
429
+
430
+ ---
431
+
432
+ ## Compatibility
433
+
434
+ | Runtime | Status |
435
+ |---|---|
436
+ | Node.js >= 20.0.0 | Declared in `package.json` engines; tested in CI (20.x, 22.x) |
437
+ | Bun >= 1.0 | Tested in CI (1.x) |
438
+ | Browser | ES2020+ with IndexedDB, localStorage, sessionStorage |
439
+ | Deno | Compatible, not routinely tested |
440
+
441
+ Persistence rules differ per runtime: see the [persistence warning](#agent-namespaced-memory).
442
+
443
+ ---
444
+
445
+ ## Project direction
446
+
447
+ Dotmem is developed as an independent memory runtime. Long-term objectives: reliable cross-session continuity, portable memory across providers and environments, stronger evidence and verification workflows, transparent memory inspection and management, efficient context projection, and durable lifecycle and checkpoint management. These objectives do not imply that every capability is already implemented; current functionality and limitations are documented above and in the linked documents.
448
+
449
+ **Your memory. Your continuity.**
450
+
451
+ ---
452
+
453
+ ## Disclaimer
454
+
455
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. Outputs of AI systems that use Dotmem can be wrong or incomplete; verify critical information independently, and do not store sensitive or confidential data in unencrypted memory.
456
+
457
+ ## License
458
+
459
+ MIT - Copyright (c) 2026 Dario Passariello.
460
+
461
+ SPDX-License-Identifier: `MIT`