true-mem 1.0.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/LICENSE +21 -0
- package/README.md +217 -0
- package/dist/adapters/opencode/index.d.ts +11 -0
- package/dist/adapters/opencode/index.d.ts.map +1 -0
- package/dist/adapters/opencode/index.js +676 -0
- package/dist/adapters/opencode/index.js.map +1 -0
- package/dist/adapters/opencode/injection.d.ts +52 -0
- package/dist/adapters/opencode/injection.d.ts.map +1 -0
- package/dist/adapters/opencode/injection.js +93 -0
- package/dist/adapters/opencode/injection.js.map +1 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +61 -0
- package/dist/config.js.map +1 -0
- package/dist/extraction/queue.d.ts +35 -0
- package/dist/extraction/queue.d.ts.map +1 -0
- package/dist/extraction/queue.js +75 -0
- package/dist/extraction/queue.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2900 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +6 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +30 -0
- package/dist/logger.js.map +1 -0
- package/dist/memory/classifier.d.ts +78 -0
- package/dist/memory/classifier.d.ts.map +1 -0
- package/dist/memory/classifier.js +363 -0
- package/dist/memory/classifier.js.map +1 -0
- package/dist/memory/embeddings.d.ts +41 -0
- package/dist/memory/embeddings.d.ts.map +1 -0
- package/dist/memory/embeddings.js +98 -0
- package/dist/memory/embeddings.js.map +1 -0
- package/dist/memory/negative-patterns.d.ts +32 -0
- package/dist/memory/negative-patterns.d.ts.map +1 -0
- package/dist/memory/negative-patterns.js +71 -0
- package/dist/memory/negative-patterns.js.map +1 -0
- package/dist/memory/patterns.d.ts +110 -0
- package/dist/memory/patterns.d.ts.map +1 -0
- package/dist/memory/patterns.js +623 -0
- package/dist/memory/patterns.js.map +1 -0
- package/dist/memory/reconsolidate.d.ts +57 -0
- package/dist/memory/reconsolidate.d.ts.map +1 -0
- package/dist/memory/reconsolidate.js +96 -0
- package/dist/memory/reconsolidate.js.map +1 -0
- package/dist/memory/role-patterns.d.ts +50 -0
- package/dist/memory/role-patterns.d.ts.map +1 -0
- package/dist/memory/role-patterns.js +188 -0
- package/dist/memory/role-patterns.js.map +1 -0
- package/dist/shutdown.d.ts +31 -0
- package/dist/shutdown.d.ts.map +1 -0
- package/dist/shutdown.js +120 -0
- package/dist/shutdown.js.map +1 -0
- package/dist/storage/database.d.ts +77 -0
- package/dist/storage/database.d.ts.map +1 -0
- package/dist/storage/database.js +590 -0
- package/dist/storage/database.js.map +1 -0
- package/dist/storage/sqlite-adapter.d.ts +35 -0
- package/dist/storage/sqlite-adapter.d.ts.map +1 -0
- package/dist/storage/sqlite-adapter.js +99 -0
- package/dist/storage/sqlite-adapter.js.map +1 -0
- package/dist/types.d.ts +266 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +63 -0
- package/dist/types.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 rizal72
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# True-Mem
|
|
2
|
+
|
|
3
|
+
> A persistent memory plugin for OpenCode with cognitive psychology-based memory management.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Overview](#overview)
|
|
10
|
+
- [The Problem](#the-problem)
|
|
11
|
+
- [The Solution](#the-solution)
|
|
12
|
+
- [The Psychology Behind It](#the-psychology-behind-it)
|
|
13
|
+
- [Key Features](#key-features)
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Usage](#usage)
|
|
16
|
+
- [Architecture](#architecture)
|
|
17
|
+
- [Memory Classifications](#memory-classifications)
|
|
18
|
+
- [Technical Details](#technical-details)
|
|
19
|
+
- [Inspiration](#inspiration)
|
|
20
|
+
- [Debug](#debug)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Overview
|
|
25
|
+
|
|
26
|
+
**True-Mem** is a production-ready memory plugin for OpenCode that enables AI coding agents to remember information across sessions and projects. It doesn't just store information - it manages memory like a human mind would.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## The Problem
|
|
31
|
+
|
|
32
|
+
If you've ever had to repeat your preferences to your AI assistant every time you start a new session, you know the pain. "I prefer TypeScript over JavaScript", "Never use `var`", "Always run tests before committing" - things you've already said, but the AI forgot.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## The Solution
|
|
37
|
+
|
|
38
|
+
True-Mem automatically extracts and stores memories from your conversations:
|
|
39
|
+
|
|
40
|
+
- **Preferences**: "I prefer functional style over OOP"
|
|
41
|
+
- **Constraints**: "Never use `var` keyword"
|
|
42
|
+
- **Decisions**: "We decided to use SQLite instead of Postgres for this project"
|
|
43
|
+
- **Bugfixes**: "Fixed the auth timeout issue"
|
|
44
|
+
- **Learning**: "Learned that bun:sqlite is built-in"
|
|
45
|
+
|
|
46
|
+
Next time you open OpenCode, it remembers. No more repeating yourself.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## The Psychology Behind It
|
|
51
|
+
|
|
52
|
+
What makes True-Mem different from a simple database? It's modeled after how human memory actually works:
|
|
53
|
+
|
|
54
|
+
**Ebbinghaus Forgetting Curve** - Episodic memories fade over time (7-day default), while preferences and decisions stay permanent. Just like your brain forgets what you had for lunch last Tuesday but remembers your favorite color.
|
|
55
|
+
|
|
56
|
+
**7-Feature Scoring Model** - Every memory is scored using Recency, Frequency, Importance, Utility, Novelty, Confidence, and Interference. This determines which memories surface when you need them.
|
|
57
|
+
|
|
58
|
+
**Dual-Store Architecture (STM/LTM)** - Short-term and long-term memory stores with automatic promotion. High-strength memories get promoted to LTM; weak ones stay in STM or decay.
|
|
59
|
+
|
|
60
|
+
**Four-Layer Defense System** - Prevents false positives with Negative Pattern filtering (including AI meta-talk detection), Multi-Keyword Scoring, Confidence Thresholds, and Role Validation (only Human messages for user-level preferences).
|
|
61
|
+
|
|
62
|
+
**Reconsolidation** - When new information conflicts with existing memories, the system detects similarity and handles it intelligently (merge duplicates, keep both complements, or resolve conflicts).
|
|
63
|
+
|
|
64
|
+
**Jaccard Similarity Search** - Fast, lightweight semantic retrieval without heavy ML dependencies.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Key Features
|
|
69
|
+
|
|
70
|
+
| Feature | Description |
|
|
71
|
+
|---------|-------------|
|
|
72
|
+
| **Dual-Scope Memory** | Global (follows you across projects) + Project-specific |
|
|
73
|
+
| **Non-Blocking** | Async extraction, no UI freezes or QUEUED states |
|
|
74
|
+
| **Multilingual** | Full support for Italian, Spanish, French, German, and 11 more languages |
|
|
75
|
+
| **Smart Decay** | Only episodic memories fade; preferences and decisions stay forever |
|
|
76
|
+
| **Zero Native Dependencies** | Works on Bun and Node 22+ with built-in SQLite |
|
|
77
|
+
| **Production-Ready** | Tested and stable |
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Installation
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
npm install true-mem
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Then add to your `~/.config/opencode/opencode.jsonc`:
|
|
88
|
+
|
|
89
|
+
```jsonc
|
|
90
|
+
{
|
|
91
|
+
"plugin": [
|
|
92
|
+
"true-mem"
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Usage
|
|
100
|
+
|
|
101
|
+
### Automatic Extraction
|
|
102
|
+
|
|
103
|
+
Just have conversations with OpenCode. True-Mem extracts relevant info in the background.
|
|
104
|
+
|
|
105
|
+
**What gets stored**:
|
|
106
|
+
- User preferences: "I prefer TypeScript over JavaScript"
|
|
107
|
+
- Constraints: "Never use var keyword"
|
|
108
|
+
- Decisions: "We decided to use SQLite instead of Postgres"
|
|
109
|
+
- Bugfixes: "Fixed null pointer in auth module"
|
|
110
|
+
- Learning: "I learned that bun:sqlite is built-in"
|
|
111
|
+
|
|
112
|
+
### Explicit Memory Storage
|
|
113
|
+
|
|
114
|
+
Use phrases like "Remember this:" or "Ricorda questo:" to force storage:
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
"Ricorda questo: preferisco sempre usare TypeScript per i miei progetti"
|
|
118
|
+
"Remember this: never commit without running tests first"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Architecture
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
true-mem/
|
|
127
|
+
├── src/
|
|
128
|
+
│ ├── index.ts # Entry point with fire-and-forget init
|
|
129
|
+
│ ├── storage/
|
|
130
|
+
│ │ ├── sqlite-adapter.ts # bun:sqlite + node:sqlite runtime adapter
|
|
131
|
+
│ │ └── database.ts # MemoryDatabase class
|
|
132
|
+
│ ├── memory/
|
|
133
|
+
│ │ ├── patterns.ts # Multilingual patterns (15 languages)
|
|
134
|
+
│ │ ├── negative-patterns.ts # False positive prevention
|
|
135
|
+
│ │ ├── role-patterns.ts # Role-aware extraction (Human vs Assistant)
|
|
136
|
+
│ │ ├── classifier.ts # Four-layer defense + role validation
|
|
137
|
+
│ │ ├── embeddings.ts # Jaccard similarity
|
|
138
|
+
│ │ └── reconsolidate.ts # Conflict resolution
|
|
139
|
+
│ ├── extraction/
|
|
140
|
+
│ │ └── queue.ts # Fire-and-forget extraction queue
|
|
141
|
+
│ └── adapters/
|
|
142
|
+
│ └── opencode/
|
|
143
|
+
│ └── index.ts # Full extraction + injection
|
|
144
|
+
└── dist/
|
|
145
|
+
└── index.js # Bundle (~92KB)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Memory Classifications
|
|
151
|
+
|
|
152
|
+
| Type | Decay | Store | Scope | Example |
|
|
153
|
+
|------|-------|-------|-------|---------|
|
|
154
|
+
| **constraint** | Never | STM | Global | "Never use `var`" |
|
|
155
|
+
| **preference** | Never | STM | Global | "Prefers functional style" |
|
|
156
|
+
| **learning** | Never | LTM | Global | "Learned bun:sqlite API" |
|
|
157
|
+
| **procedural** | Never | STM | Global | "Run tests before commit" |
|
|
158
|
+
| **decision** | Never | LTM | Project | "Decided SQLite over Postgres" |
|
|
159
|
+
| **bugfix** | Never | LTM | Project | "Fixed null pointer in auth" |
|
|
160
|
+
| **semantic** | Never | STM | Project | "API uses REST, not GraphQL" |
|
|
161
|
+
| **episodic** | Yes (7d) | STM | Project | "Yesterday we refactored auth" |
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Technical Details
|
|
166
|
+
|
|
167
|
+
### 7-Feature Scoring Model
|
|
168
|
+
|
|
169
|
+
| Feature | Weight | Description |
|
|
170
|
+
|---------|--------|-------------|
|
|
171
|
+
| Recency | 0.20 | Time since creation (0 = recent, 1 = old) |
|
|
172
|
+
| Frequency | 0.15 | Number of accesses (log scale) |
|
|
173
|
+
| Importance | 0.25 | Combination of signals (diminishing returns) |
|
|
174
|
+
| Utility | 0.20 | Usefulness for current task |
|
|
175
|
+
| Novelty | 0.10 | Distance from existing memories |
|
|
176
|
+
| Confidence | 0.10 | Consensus of extraction evidence |
|
|
177
|
+
| Interference | -0.10 | Penalty for conflicts |
|
|
178
|
+
|
|
179
|
+
**Strength Formula**: `Strength = Sum(weight_i * feature_i)` clamped to [0, 1]
|
|
180
|
+
|
|
181
|
+
### Four-Layer False Positive Prevention
|
|
182
|
+
|
|
183
|
+
| Layer | Purpose |
|
|
184
|
+
|-------|---------|
|
|
185
|
+
| 1. Negative Patterns | Filter known false positives |
|
|
186
|
+
| 2. Multi-Keyword Scoring | Require 2+ signals |
|
|
187
|
+
| 3. Confidence Threshold | Store only if score >= 0.6 |
|
|
188
|
+
| 4. Role Validation | Human-only for user-level memories |
|
|
189
|
+
|
|
190
|
+
### Decay Strategy
|
|
191
|
+
|
|
192
|
+
- **Episodic memories**: Decay using Ebbinghaus formula (lambda = 0.05 STM, 0.01 LTM)
|
|
193
|
+
- **All other types**: Permanent (no decay)
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Inspiration
|
|
198
|
+
|
|
199
|
+
This project was inspired by [PsychMem](https://github.com/muratg98/psychmem) - a pioneering plugin for persistent memory in OpenCode. True-Mem builds on those ideas with a focus on cognitive psychology models and production stability.
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Debug
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# View logs
|
|
207
|
+
tail -f ~/.true-mem/plugin-debug.log
|
|
208
|
+
|
|
209
|
+
# Query database
|
|
210
|
+
sqlite3 ~/.true-mem/memory.db "SELECT classification, summary, strength FROM memory_units WHERE status = 'active' ORDER BY strength DESC LIMIT 10;"
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
**Version**: 1.0.0
|
|
216
|
+
**License**: MIT
|
|
217
|
+
**Status**: Production-ready, actively maintained
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True-Mem OpenCode Adapter
|
|
3
|
+
*/
|
|
4
|
+
import type { PluginInput, Hooks } from '../../types.js';
|
|
5
|
+
import type { PsychMemConfig } from '../../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Create OpenCode plugin hooks
|
|
8
|
+
*/
|
|
9
|
+
export declare function createTrueMemoryPlugin(ctx: PluginInput, configOverrides?: Partial<PsychMemConfig>): Promise<Hooks>;
|
|
10
|
+
export default createTrueMemoryPlugin;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/opencode/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAwB,MAAM,gBAAgB,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAA4D,MAAM,gBAAgB,CAAC;AA0E/G;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,WAAW,EAChB,eAAe,GAAE,OAAO,CAAC,cAAc,CAAM,GAC5C,OAAO,CAAC,KAAK,CAAC,CAwKhB;AAolBD,eAAe,sBAAsB,CAAC"}
|