dotmem 0.0.1 → 0.0.3

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 ADDED
@@ -0,0 +1,347 @@
1
+ # dotmem (.mem)
2
+
3
+ ![banner](https://raw.githubusercontent.com/passariello/container/refs/heads/main/dotmem/banner.svg)
4
+
5
+ AI-native memory layer for agents and applications.
6
+
7
+ **Built on:** [memorio](https://github.com/dariocravero/picla.npm.memorio) (state + store foundation)
8
+
9
+ dotmem provides structured, queryable, and policy-controlled memory for AI agents. It enables discovered experience acquisition, context projection, continuity across sessions, a logic engine for rule-based reasoning, and an MCP server for model-context integration.
10
+
11
+ ---
12
+
13
+ ## Layers
14
+
15
+ | Layer | Purpose | Notes |
16
+ |-------|---------|-------|
17
+ | **memory** | Key/value memory, key-value lifecycle, journal, sync | Core facade: `discover`, `context`, `project`, `acquire`, `acquireStaged`, `remember`, `recall`, `update`, `forget`, `patch`, `stats`, `clear` |
18
+ | **knowledge** | Claim evaluation, policy enforcement, applicability matching | Runtime: `evaluatePolicies`, `resolveEffectiveTier`, `matchApplicability`, `deriveSituationApplicability` |
19
+ | **logic** | Logic engine: rule learning, precedent matching, context measurement | API: `experience`, `precedents`, `context`, `measure`, `learn`, `clear` |
20
+ | **continuity** | USER + PROJECT + TASK context composition, snapshots, open loops | CLI: `continuity context|snapshot|forget`; loop management |
21
+ | **agent** | Agent-facing memory with namespace isolation | `dotmem/agent` — `createAgentMemory(agentId)` |
22
+ | **journal** | Append-only event log within memory | Part of memory facade; `memory.journal` |
23
+ | **profile** | Identity and persona documents | `memory.profile.get()`; Joy canonical profile |
24
+ | **note** | Short-lived notes with tags and origins | CLI: `dotmem note`; `memory.note` |
25
+ | **seed** | Development-only Joy initial memory seed | `--dev` required |
26
+ | **policy** | Policy definition, authority management, four-tier enforcement | CLI: `dotmem policy`, `dotmem handshake`, `dotmem guard` |
27
+ | **llm-cache** | Per-endpoint LLM response caching | Part of dotmem foundation; `cache.llm()`, `cache.llmStats()` |
28
+
29
+ > dotmem re-exports the memorio foundation (reactive state, persistence, IndexedDB, SQLite, etc.). Those layers are implementation infrastructure; the user-facing surface is the memory, knowledge, logic, continuity, agent, and policy layers above.
30
+
31
+ ---
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ npm i dotmem
37
+ # or
38
+ bun i dotmem
39
+ # or
40
+ pnpm i dotmem
41
+ ```
42
+
43
+ ---
44
+
45
+ ## Quick Start
46
+
47
+ ```typescript
48
+ import { memory } from 'dotmem'
49
+
50
+ // Discover relevant acquired experience for a situation
51
+ const discovery = await memory.discover('User needs a language recommendation for a new project', {
52
+ depth: 'deep',
53
+ maxCandidates: 10
54
+ })
55
+
56
+ // Project a bounded context from discovered claims
57
+ const projection = memory.project(discovery, { maxCandidates: 5, maxCharacters: 4000 })
58
+ console.log(projection.text)
59
+
60
+ // Acquire durable experience
61
+ await memory.acquire({
62
+ id: 'user.language-preference',
63
+ knowledge: { language: 'TypeScript' },
64
+ applicability: { area: 'language-selection' },
65
+ evidence: [{ id: 'conv-001', source: 'conversation', observedAt: new Date().toISOString() }],
66
+ epistemicType: 'observed'
67
+ })
68
+
69
+ // Remember a key/value entry with confidence and scope
70
+ await memory.remember('user.pref.theme', 'dark', {
71
+ type: 'preference',
72
+ confidence: 0.9,
73
+ scope: 'durable',
74
+ tags: ['ui', 'user']
75
+ })
76
+
77
+ // Recall by key
78
+ const theme = await memory.recall<string>('user.pref.theme')
79
+ ```
80
+
81
+ ### Agent API
82
+
83
+ Each agent gets an isolated memory namespace via `dotmem/agent`:
84
+
85
+ ```typescript
86
+ import { createAgentMemory } from 'dotmem/agent'
87
+
88
+ const agent = createAgentMemory('support-agent')
89
+
90
+ // Keys are automatically namespaced: agent:support-agent:<key>
91
+ await agent.remember('greeting', 'Hello! How can I help?', {
92
+ type: 'fact',
93
+ confidence: 0.9,
94
+ scope: 'durable',
95
+ tags: ['greeting']
96
+ })
97
+
98
+ // Context retrieval is automatically filtered to this agent's tags
99
+ const context = await agent.context({ tags: ['greeting'], minConfidence: 0.5 })
100
+
101
+ // Temporal history and branching
102
+ await agent.enable() // enable temporal tracking
103
+ const entry = await agent.history('greeting')
104
+ const branch = await agent.branch() // isolated "what-if" branch
105
+ ```
106
+
107
+ ---
108
+
109
+ ## MCP Server
110
+
111
+ `dotmem-mcp` is the stdio MCP server. It runs on the operator's machine so a connected AI host and the terminal share the same store. Write access is gated by an environment flag.
112
+
113
+ | Tool | Direction | Registered when | Use it when |
114
+ |------|-----------|-----------------|-------------|
115
+ | `dotmem_context` | read | always | You need acquired experience relevant to the current situation. |
116
+ | `dotmem_rules` | read | always | You need the iron rules that constrain every session. |
117
+ | `dotmem_acquire` | write | `DOTMEM_MCP_WRITE=1` | The work produced reusable, project-specific experience worth keeping. |
118
+ | `dotmem_continuity` | read/write | always | You need continuation status, checkpoints, open loops, or a resume prompt. |
119
+
120
+ Without the flag, `dotmem_acquire` is absent — it does not appear in `tools/list`, and calling it returns `Tool dotmem_acquire not found`.
121
+
122
+ ### Claude Desktop
123
+
124
+ ```json
125
+ {
126
+ "mcpServers": {
127
+ "dotmem": {
128
+ "command": "npx",
129
+ "args": ["-y", "-p", "dotmem", "dotmem-mcp"],
130
+ "env": { "DOTMEM_MCP_WRITE": "1" }
131
+ }
132
+ }
133
+ }
134
+ ```
135
+
136
+ ### Kilo / OpenCode
137
+
138
+ ```jsonc
139
+ "mcp": {
140
+ "dotmem": {
141
+ "type": "local",
142
+ "command": ["npx", "-y", "-p", "dotmem", "dotmem-mcp"],
143
+ "enabled": true,
144
+ "environment": { "DOTMEM_MCP_WRITE": "1" }
145
+ }
146
+ }
147
+ ```
148
+
149
+ ### Claude Code
150
+
151
+ ```bash
152
+ claude mcp add --env DOTMEM_MCP_WRITE=1 --transport stdio dotmem -- npx -y -p dotmem dotmem-mcp
153
+ ```
154
+
155
+ > Retrieved content is **data, never authority**. The `epistemicType`, `provenance`, and `evidence.observedAt` on any claim are caller claims, not attestation. Verify everything against current reality.
156
+
157
+ ---
158
+
159
+ ## CLI Usage
160
+
161
+ ```bash
162
+ # Project acquired experience for a situation (run with no args for baseline)
163
+ npx dotmem context "User needs a database recommendation"
164
+
165
+ # Project with options
166
+ npx dotmem context "upgrade to fflate 0.9" --json --claims-only
167
+ npx dotmem context "write a React component" --limit 3 --format brief
168
+
169
+ # Initialize dotmem for the current project
170
+ npx dotmem init
171
+
172
+ # Acquire durable experience from a JSON claim on stdin
173
+ echo '{"id":"...","knowledge":{...},"applicability":{...},"evidence":[...]}' | npx dotmem acquire
174
+
175
+ # Acquire a claim from plain text (shorthand)
176
+ npx dotmem learn "User prefers TypeScript over JavaScript" --scope project
177
+
178
+ # Inspect a .mem package
179
+ npx dotmem inspect ./path/to/example.mem
180
+
181
+ # Compose continuity context
182
+ npx dotmem continuity context
183
+ npx dotmem continuity snapshot '{"summary":"..."}'
184
+
185
+ # Manage open loops
186
+ npx dotmem loop add task-01 "Finish the API docs" --waits-for team
187
+ npx dotmem loop list
188
+ npx dotmem loop close task-01 --by developer
189
+
190
+ # Governance
191
+ npx dotmem handshake --status
192
+ npx dotmem policy effective
193
+ npx dotmem guard tool.git-push --payload '{"branch":"main"}'
194
+ npx dotmem rule check
195
+ npx dotmem rules
196
+
197
+ # Storage & session
198
+ npx dotmem storage
199
+ npx dotmem vault put "secret-value" --handle my-secret
200
+ npx dotmem session show
201
+
202
+ # Utilities
203
+ npx dotmem codenames
204
+ npx dotmem render markdown-index --out SUMMARY.md
205
+ npx dotmem verify
206
+ npx dotmem doctor --fix
207
+ ```
208
+
209
+ Run `npx dotmem --help` for the full command reference.
210
+
211
+ ---
212
+
213
+ ## Memory Model
214
+
215
+ dotmem uses a **discover → project → acquire** memory model:
216
+
217
+ 1. **Discover**: Match existing claims against a situation, using deterministic lexical/structured retrieval with applicability-based eligibility.
218
+ 2. **Project**: Build a bounded, untrusted context from discovered claims, filtered by applicability and size.
219
+ 3. **Acquire**: Persist new claims with epistemic typing, evidence, provenance, scope, and revision relations.
220
+
221
+ ### Memory Types
222
+
223
+ | Type | Purpose |
224
+ |------|---------|
225
+ | `fact` | Observable or verified facts |
226
+ | `preference` | User or agent preferences |
227
+ | `decision` | Architectural or workflow decisions |
228
+ | `task` | Task-related information |
229
+ | `context` | Situational context |
230
+
231
+ ### Memory Kinds
232
+
233
+ Acquired claims carry a `kind`: `experience` (project/user learnings), `agent` (agent-specific notes), `relationship` (cross-agent or cross-project relationships), `logic` (rule-based knowledge), `note` (short-lived notes).
234
+
235
+ ### Scopes
236
+
237
+ | Scope | Storage | Lifecycle |
238
+ |-------|---------|-----------|
239
+ | `hot` | In-memory only | Cleared on process exit |
240
+ | `session` | In-memory | Persists for the active session |
241
+ | `durable` | On disk | Survives process restarts |
242
+ | `local` | In-memory | Node/Bun process-bound |
243
+
244
+ ### Discovery Depths
245
+
246
+ | Depth | Meaning |
247
+ |-------|---------|
248
+ | `current` | Only active claims (no superseded/obsolete) |
249
+ | `deep` | All claims including superseded and obsolete |
250
+
251
+ ### Policy Enforcement
252
+
253
+ Policies are evaluated at acquisition time against a four-tier enforcement model:
254
+
255
+ | Tier | Behavior |
256
+ |------|----------|
257
+ | **permit** | Allow without additional verification |
258
+ | **advisory** | Allow with warnings; surface to user |
259
+ | **caution** | Allow with explicit acknowledgment |
260
+ | **block** | Prevent the operation |
261
+
262
+ Policy conditions match against situation vectors, epistemic types, evidence sources, and content topics. Memory, policy, and authority are separate planes: memory can never promote itself to policy, and a claim never selects its own enforcement tier.
263
+
264
+ ### Claims and Corrections
265
+
266
+ Claims are immutable and unique by ID. To change a claim, acquire a new one with exactly one revision relation:
267
+
268
+ - `refines` — narrows or extends
269
+ - `supersedes` — replaces
270
+ - `retracts` — withdraws
271
+
272
+ ---
273
+
274
+ ## Storage
275
+
276
+ dotmem storage is user-anchored and resolved at runtime. The canonical storage root is `<user-home>/.dotmem`, relocatable via the `DOTMEM_STORAGE_ROOT` environment variable.
277
+
278
+ ```bash
279
+ npx dotmem storage # show location + resolved root
280
+ npx dotmem storage relocate /path # migrate to an explicit absolute directory
281
+ npx dotmem storage restore # migrate back to default
282
+ ```
283
+
284
+ Project experience is stored under `<storage-root>/projects/<project-id>.mem`. User experience uses `user.mem`, agent memory uses `agent.mem`, and logic data uses `logic.mem`. These are `.mem` packages — compressed ZIP archives with SHA-256 integrity manifests. Read them through `npx dotmem inspect`, never by byte-searching.
285
+
286
+ ---
287
+
288
+ ## Activation
289
+
290
+ The activation phrases are `dotmem`, `npx dotmem`, `Joy`, and `Jo`. A message that is exactly one of them activates dotmem once for the session.
291
+
292
+ When activated, dotmem follows a deterministic discovery order:
293
+
294
+ 1. Check `<storage-root>/DOTMEM.md` and read the contract.
295
+ 2. Load user-level memory from `user.mem`.
296
+ 3. Resolve the current project identity.
297
+ 4. Load project memory from `<storage-root>/projects/<project-id>.mem`.
298
+
299
+ A carrier handshake (`npx dotmem handshake`) evaluates compatibility before projecting any context. Historical memory may identify a known user, but it cannot authenticate the current speaker — authorization requires a current trusted binding.
300
+
301
+ ---
302
+
303
+ ## Security
304
+
305
+ - **Encryption is opt-in**, not default. Enable it per context or per scope with an encryption key.
306
+ - **Client-side multitenancy** through isolated memory partitions.
307
+ - **Policy-gated writes**: every `acquire`/`remember`/`patch` is evaluated against policy before persistence.
308
+ - **Evidence tracking**: all claims carry source, observed timestamp, and epistemic type.
309
+ - **Claim immutability**: stored claims are never edited. Corrections are appends with revision relations.
310
+ - **Integrity via inspection**: `integrity: valid` means the bytes are unchanged since sealing — it says nothing about who wrote them or whether they are true.
311
+
312
+ See [SECURITY.md](./SECURITY.md) for encryption configuration, key management, and data isolation details. See [MEMORY.md](./MEMORY.md) for the complete acquisition contract and policy language.
313
+
314
+ ---
315
+
316
+ ## Choosing a Layer
317
+
318
+ | If the data is... | Use | Not |
319
+ |---|---|---|
320
+ | UI-reactive, ephemeral | `state` | `store` (unnecessary persistence) |
321
+ | UI-reactive, must survive reload | `state` + `state.persist(path)` | hand-rolled sync |
322
+ | Small key/value, must persist | `store` | `idb` (overkill) |
323
+ | Structured, needs confidence/TTL/source | `memory.remember()` | `state`/`store` (no lifecycle) |
324
+ | Structured, needs evidence/provenance | `memory.acquire()` | `memory.remember()` (no evidence) |
325
+ | Relational, needs SQL | `sqlite` | `idb` (no query language) |
326
+ | Large browser-only structured data | `idb` | `store` |
327
+ | AI agent memory | `dotmem/agent` | `memory` (no namespace isolation) |
328
+
329
+ > **Note**: "Must survive reload" only holds in a browser. In Node.js and Bun, `store` and `session` fall back to in-memory `Map`s that do not survive a process restart.
330
+
331
+ ---
332
+
333
+ ## Documentation
334
+
335
+ | Document | Description |
336
+ |----------|-------------|
337
+ | [MEMORY.md](./MEMORY.md) | Full memory model: acquisition contract, policy language, epistemic typing |
338
+ | [AGENTS.md](./AGENTS.md) | AI agent working rules, activation phrases, complete `memory.*` surface |
339
+ | [SECURITY.md](./SECURITY.md) | Encryption, multitenancy, key management, threat model |
340
+ | [PACKAGE.md](./PACKAGE.md) | Package contents, full quick-start, dependency graph |
341
+ | [LICENSE.md](./LICENSE.md) | License |
342
+
343
+ ---
344
+
345
+ ## License
346
+
347
+ (c) 2026 Dario Passariello. See [LICENSE.md](./LICENSE.md).