@csuwl/opencode-memory-plugin 1.0.0 → 1.1.1
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.npm.md +93 -4
- package/bin/install.js +70 -12
- package/package.json +7 -6
- package/scripts/uninstall.sh +171 -0
- package/tools/config.ts +356 -0
- package/tools/search-modes.ts +456 -0
- package/tools/vector-memory.ts +135 -17
package/README.npm.md
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
# @csuwl/opencode-memory-plugin
|
|
2
2
|
|
|
3
|
-
> OpenClaw-style persistent memory system for OpenCode with
|
|
3
|
+
> OpenClaw-style persistent memory system for OpenCode with **flexible configuration** for embedding models and search modes
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
+
# Install latest version
|
|
8
9
|
npm install @csuwl/opencode-memory-plugin -g
|
|
10
|
+
|
|
11
|
+
# Or install a specific version
|
|
12
|
+
npm install -g @csuwl/opencode-memory-plugin@1.1.0
|
|
13
|
+
|
|
14
|
+
# Or install locally without -g
|
|
15
|
+
npm install @csuwl/opencode-memory-plugin
|
|
9
16
|
```
|
|
10
17
|
|
|
11
18
|
The plugin will be automatically configured for you!
|
|
@@ -16,7 +23,74 @@ The plugin will be automatically configured for you!
|
|
|
16
23
|
- 8 memory tools (write, read, search, vector search)
|
|
17
24
|
- 2 automation agents (auto-save, auto-consolidate)
|
|
18
25
|
- Daily memory logs with automatic consolidation
|
|
19
|
-
-
|
|
26
|
+
- **Configurable semantic search** using @huggingface/transformers
|
|
27
|
+
- **Multiple search modes**: hybrid, vector-only, bm25-only, hash-only
|
|
28
|
+
- **Multiple embedding models**: all-MiniLM-L6-v2, bge-small-en-v1.5, bge-base-en-v1.5, and more
|
|
29
|
+
- **100% local** - No API calls, models auto-download on first use
|
|
30
|
+
|
|
31
|
+
## Configuration
|
|
32
|
+
|
|
33
|
+
The plugin supports flexible configuration via `~/.opencode/memory/memory-config.json`.
|
|
34
|
+
|
|
35
|
+
### Quick Configuration Examples
|
|
36
|
+
|
|
37
|
+
**Default (Balanced)** - Works out of the box:
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"search": { "mode": "hybrid" },
|
|
41
|
+
"embedding": {
|
|
42
|
+
"model": "Xenova/bge-small-en-v1.5"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Fast Search** (No model, keywords only):
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"search": { "mode": "bm25" },
|
|
51
|
+
"embedding": { "enabled": false }
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**High Quality** (Best model):
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"search": { "mode": "vector" },
|
|
59
|
+
"embedding": {
|
|
60
|
+
"model": "Xenova/bge-base-en-v1.5"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Resource-Constrained** (Smallest model):
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"search": { "mode": "vector" },
|
|
69
|
+
"embedding": {
|
|
70
|
+
"model": "Xenova/all-MiniLM-L6-v2"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Available Search Modes
|
|
76
|
+
|
|
77
|
+
| Mode | Description | Speed | Quality | Model Required |
|
|
78
|
+
|------|-------------|-------|---------|----------------|
|
|
79
|
+
| `hybrid` | Vector + BM25 (best) | Medium | ⭐⭐⭐⭐ | Yes |
|
|
80
|
+
| `vector` | Vector-only | Medium | ⭐⭐⭐ | Yes |
|
|
81
|
+
| `bm25` | Keywords only | Fast | ⭐⭐ | No |
|
|
82
|
+
| `hash` | Hash fallback | Fast | ⭐ | No |
|
|
83
|
+
|
|
84
|
+
### Available Embedding Models
|
|
85
|
+
|
|
86
|
+
| Model | Size | Quality | Speed | Best For |
|
|
87
|
+
|-------|------|---------|-------|----------|
|
|
88
|
+
| `Xenova/all-MiniLM-L6-v2` | 80MB | Good | ⚡⚡⚡ | Baseline |
|
|
89
|
+
| `Xenova/bge-small-en-v1.5` ⭐ | 130MB | Excellent | ⚡⚡ | **Best balance** |
|
|
90
|
+
| `Xenova/bge-base-en-v1.5` | 400MB | Best | ⚡⚡ | High quality |
|
|
91
|
+
| `Xenova/gte-small` | 70MB | Very Good | ⚡⚡⚡ | Small + fast |
|
|
92
|
+
|
|
93
|
+
See [CONFIGURATION.md](https://github.com/csuwl/opencode-memory-plugin/blob/main/CONFIGURATION.md) for details.
|
|
20
94
|
|
|
21
95
|
## Usage
|
|
22
96
|
|
|
@@ -29,13 +103,26 @@ memory_write content="User prefers TypeScript" type="long-term"
|
|
|
29
103
|
# Search memory
|
|
30
104
|
memory_search query="typescript"
|
|
31
105
|
|
|
32
|
-
# Semantic search
|
|
106
|
+
# Semantic search (respects your config)
|
|
33
107
|
vector_memory_search query="how to handle errors"
|
|
34
108
|
|
|
35
109
|
# List daily logs
|
|
36
110
|
list_daily days=7
|
|
37
111
|
```
|
|
38
112
|
|
|
113
|
+
## What's New in v1.1.0
|
|
114
|
+
|
|
115
|
+
✨ **Flexible Configuration System**
|
|
116
|
+
- Choose from 5 embedding models (small to large)
|
|
117
|
+
- 4 search modes (hybrid, vector, bm25, hash)
|
|
118
|
+
- Configurable quality vs speed tradeoffs
|
|
119
|
+
- Easy fallback to keyword-only search
|
|
120
|
+
|
|
121
|
+
✨ **True Semantic Search**
|
|
122
|
+
- Real vector embeddings using Transformers.js
|
|
123
|
+
- Understands meaning, not just keywords
|
|
124
|
+
- Works 100% offline after model download
|
|
125
|
+
|
|
39
126
|
## Configuration
|
|
40
127
|
|
|
41
128
|
Memory files are located at `~/.opencode/memory/`:
|
|
@@ -46,11 +133,13 @@ Memory files are located at `~/.opencode/memory/`:
|
|
|
46
133
|
- `IDENTITY.md` - Assistant identity
|
|
47
134
|
- `TOOLS.md` - Tool usage conventions
|
|
48
135
|
- `MEMORY.md` - Long-term memory
|
|
136
|
+
- `memory-config.json` - **Plugin configuration**
|
|
49
137
|
- And more...
|
|
50
138
|
|
|
51
139
|
## Documentation
|
|
52
140
|
|
|
53
|
-
|
|
141
|
+
- **[CONFIGURATION.md](https://github.com/csuwl/opencode-memory-plugin/blob/main/CONFIGURATION.md)** - Complete configuration guide
|
|
142
|
+
- [Full Documentation](https://github.com/csuwl/opencode-memory-plugin) - Project README
|
|
54
143
|
|
|
55
144
|
## License
|
|
56
145
|
|
package/bin/install.js
CHANGED
|
@@ -90,14 +90,77 @@ function createMemoryConfig() {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const config = {
|
|
93
|
-
version: '
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
version: '2.0',
|
|
94
|
+
search: {
|
|
95
|
+
mode: 'hybrid',
|
|
96
|
+
options: {
|
|
97
|
+
hybrid: {
|
|
98
|
+
vectorWeight: 0.7,
|
|
99
|
+
bm25Weight: 0.3
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
embedding: {
|
|
97
104
|
enabled: true,
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
provider: 'transformers',
|
|
106
|
+
model: 'Xenova/all-MiniLM-L6-v2',
|
|
107
|
+
fallbackMode: 'hash',
|
|
108
|
+
cache: {
|
|
109
|
+
enabled: true,
|
|
110
|
+
directory: path.join(HOME, '.cache', 'huggingface')
|
|
111
|
+
}
|
|
100
112
|
},
|
|
113
|
+
models: {
|
|
114
|
+
available: {
|
|
115
|
+
'Xenova/all-MiniLM-L6-v2': {
|
|
116
|
+
dimensions: 384,
|
|
117
|
+
size: '80MB',
|
|
118
|
+
language: 'en',
|
|
119
|
+
useCase: 'general',
|
|
120
|
+
quality: 'good',
|
|
121
|
+
speed: 'fast'
|
|
122
|
+
},
|
|
123
|
+
'Xenova/bge-small-en-v1.5': {
|
|
124
|
+
dimensions: 384,
|
|
125
|
+
size: '130MB',
|
|
126
|
+
language: 'en',
|
|
127
|
+
useCase: 'high-quality',
|
|
128
|
+
quality: 'excellent',
|
|
129
|
+
speed: 'medium'
|
|
130
|
+
},
|
|
131
|
+
'Xenova/bge-base-en-v1.5': {
|
|
132
|
+
dimensions: 768,
|
|
133
|
+
size: '400MB',
|
|
134
|
+
language: 'en',
|
|
135
|
+
useCase: 'best-quality',
|
|
136
|
+
quality: 'best',
|
|
137
|
+
speed: 'slow'
|
|
138
|
+
},
|
|
139
|
+
'Xenova/e5-small-v2': {
|
|
140
|
+
dimensions: 384,
|
|
141
|
+
size: '130MB',
|
|
142
|
+
language: 'en',
|
|
143
|
+
useCase: 'question-answer',
|
|
144
|
+
quality: 'good',
|
|
145
|
+
speed: 'medium'
|
|
146
|
+
},
|
|
147
|
+
'Xenova/nomic-embed-text-v1.5': {
|
|
148
|
+
dimensions: 768,
|
|
149
|
+
size: '270MB',
|
|
150
|
+
language: 'en',
|
|
151
|
+
useCase: 'long-documents',
|
|
152
|
+
quality: 'excellent',
|
|
153
|
+
speed: 'medium'
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
indexing: {
|
|
158
|
+
chunkSize: 400,
|
|
159
|
+
chunkOverlap: 80,
|
|
160
|
+
autoRebuild: true
|
|
161
|
+
},
|
|
162
|
+
// Legacy v1.0 fields (for backward compatibility)
|
|
163
|
+
auto_save: true,
|
|
101
164
|
consolidation: {
|
|
102
165
|
enabled: true,
|
|
103
166
|
run_daily: true,
|
|
@@ -105,11 +168,6 @@ function createMemoryConfig() {
|
|
|
105
168
|
archive_days: 30,
|
|
106
169
|
delete_days: 90
|
|
107
170
|
},
|
|
108
|
-
git_backup: {
|
|
109
|
-
enabled: false,
|
|
110
|
-
auto_commit: false,
|
|
111
|
-
auto_push: false
|
|
112
|
-
},
|
|
113
171
|
retention: {
|
|
114
172
|
max_daily_files: 30,
|
|
115
173
|
max_entries_per_file: 100,
|
|
@@ -119,7 +177,7 @@ function createMemoryConfig() {
|
|
|
119
177
|
};
|
|
120
178
|
|
|
121
179
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
122
|
-
log(' ✓ Configuration created', 'green');
|
|
180
|
+
log(' ✓ Configuration created (v2.0)', 'green');
|
|
123
181
|
}
|
|
124
182
|
|
|
125
183
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csuwl/opencode-memory-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "OpenClaw-style memory system for OpenCode with full automation and local vector search",
|
|
5
5
|
"author": "csuwl <1105865632@qq.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,13 +22,14 @@
|
|
|
22
22
|
"semantic-search"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@opencode-ai/plugin": "
|
|
26
|
-
"
|
|
27
|
-
"
|
|
25
|
+
"@opencode-ai/plugin": "^1.0.0",
|
|
26
|
+
"@huggingface/transformers": "^3.8.1",
|
|
27
|
+
"better-sqlite3": "^11.7.0",
|
|
28
|
+
"sqlite-vec": "^0.1.1"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"@types/node": "
|
|
31
|
-
"typescript": "
|
|
31
|
+
"@types/node": "^22.10.5",
|
|
32
|
+
"typescript": "^5.7.3"
|
|
32
33
|
},
|
|
33
34
|
"files": [
|
|
34
35
|
"memory/",
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# OpenCode Memory Plugin - Uninstallation Script
|
|
4
|
+
# This script removes all installed components
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
# Colors for output
|
|
9
|
+
RED='\033[0;31m'
|
|
10
|
+
GREEN='\033[0;32m'
|
|
11
|
+
YELLOW='\033[1;33m'
|
|
12
|
+
BLUE='\033[0;34m'
|
|
13
|
+
NC='\033[0m' # No Color
|
|
14
|
+
|
|
15
|
+
function log() {
|
|
16
|
+
echo -e "${2}$1${NC}"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getHomeDir() {
|
|
20
|
+
echo "$HOME"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
# Paths
|
|
24
|
+
HOME=$(getHomeDir)
|
|
25
|
+
MEMORY_ROOT="$HOME/.opencode"
|
|
26
|
+
MEMORY_DIR="$MEMORY_ROOT/memory"
|
|
27
|
+
OPENCODE_CONFIG_DIR="$HOME/.config/opencode"
|
|
28
|
+
OPENCODE_CONFIG="$OPENCODE_CONFIG_DIR/opencode.json"
|
|
29
|
+
BACKUP_DIR="$HOME/opencode-memory-backup-$(date +%Y%m%d_%H%M%S)"
|
|
30
|
+
|
|
31
|
+
log '' ''
|
|
32
|
+
log '═════════════════════════════════════════════════════════════════' "$BLUE"
|
|
33
|
+
log ' OpenCode Memory Plugin - Uninstallation' "$BLUE"
|
|
34
|
+
log '═════════════════════════════════════════════════════════════════' "$BLUE"
|
|
35
|
+
log '' ''
|
|
36
|
+
|
|
37
|
+
# Ask for confirmation
|
|
38
|
+
log 'This will uninstall the OpenCode Memory Plugin.' "$YELLOW"
|
|
39
|
+
log '' ''
|
|
40
|
+
log 'The following will be removed:' "$YELLOW"
|
|
41
|
+
log " - Memory files in: $MEMORY_DIR" "$NC"
|
|
42
|
+
log " - OpenCode configuration entries" "$NC"
|
|
43
|
+
log '' ''
|
|
44
|
+
log 'Your memory files will be backed up to:' "$GREEN"
|
|
45
|
+
log " $BACKUP_DIR" "$BLUE"
|
|
46
|
+
log '' ''
|
|
47
|
+
|
|
48
|
+
read -p "Do you want to continue? (yes/no): " -r
|
|
49
|
+
echo
|
|
50
|
+
|
|
51
|
+
if [[ ! $REPLY =~ ^[Yy][Ee][Ss]$ ]]; then
|
|
52
|
+
log 'Uninstallation cancelled.' "$YELLOW"
|
|
53
|
+
exit 0
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
log '' ''
|
|
57
|
+
log 'Step 1/4: Creating backup...' "$YELLOW"
|
|
58
|
+
|
|
59
|
+
# Create backup directory
|
|
60
|
+
mkdir -p "$BACKUP_DIR"
|
|
61
|
+
|
|
62
|
+
# Backup memory files if they exist
|
|
63
|
+
if [ -d "$MEMORY_DIR" ]; then
|
|
64
|
+
cp -r "$MEMORY_DIR" "$BACKUP_DIR/"
|
|
65
|
+
log " ✓ Backed up memory files" "$GREEN"
|
|
66
|
+
else
|
|
67
|
+
log " ⊙ No memory files to backup" "$BLUE"
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
# Backup OpenCode config
|
|
71
|
+
if [ -f "$OPENCODE_CONFIG" ]; then
|
|
72
|
+
cp "$OPENCODE_CONFIG" "$BACKUP_DIR/"
|
|
73
|
+
log " ✓ Backed up OpenCode config" "$GREEN"
|
|
74
|
+
else
|
|
75
|
+
log " ⊙ No OpenCode config to backup" "$BLUE"
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
log '' ''
|
|
79
|
+
log 'Step 2/4: Removing OpenCode configuration...' "$YELLOW"
|
|
80
|
+
|
|
81
|
+
# Remove OpenCode configuration entries
|
|
82
|
+
if [ -f "$OPENCODE_CONFIG" ]; then
|
|
83
|
+
# Use Node.js to safely modify JSON
|
|
84
|
+
node -e "
|
|
85
|
+
const fs = require('fs');
|
|
86
|
+
const path = '$OPENCODE_CONFIG';
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
if (fs.existsSync(path)) {
|
|
90
|
+
let config = JSON.parse(fs.readFileSync(path, 'utf8'));
|
|
91
|
+
|
|
92
|
+
// Remove memory instructions
|
|
93
|
+
if (config.instructions) {
|
|
94
|
+
config.instructions = config.instructions.filter(
|
|
95
|
+
instr => !instr.includes('.opencode/memory/')
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Remove memory agents
|
|
100
|
+
if (config.agent) {
|
|
101
|
+
delete config.agent['memory-automation'];
|
|
102
|
+
delete config.agent['memory-consolidate'];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Remove memory tools
|
|
106
|
+
if (config.tools) {
|
|
107
|
+
delete config.tools.memory_write;
|
|
108
|
+
delete config.tools.memory_read;
|
|
109
|
+
delete config.tools.memory_search;
|
|
110
|
+
delete config.tools.vector_memory_search;
|
|
111
|
+
delete config.tools.list_daily;
|
|
112
|
+
delete config.tools.init_daily;
|
|
113
|
+
delete config.tools.rebuild_index;
|
|
114
|
+
delete config.tools.index_status;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fs.writeFileSync(path, JSON.stringify(config, null, 2));
|
|
118
|
+
console.log(' ✓ Removed memory configuration from OpenCode');
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error(' ✗ Error modifying config:', error.message);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
" 2>/dev/null || {
|
|
125
|
+
log " ⚠ Could not modify OpenCode config (manual cleanup may be needed)" "$YELLOW"
|
|
126
|
+
}
|
|
127
|
+
else
|
|
128
|
+
log " ⊙ No OpenCode config found" "$BLUE"
|
|
129
|
+
fi
|
|
130
|
+
|
|
131
|
+
log '' ''
|
|
132
|
+
log 'Step 3/4: Removing memory directory...' "$YELLOW"
|
|
133
|
+
|
|
134
|
+
# Remove memory directory
|
|
135
|
+
if [ -d "$MEMORY_DIR" ]; then
|
|
136
|
+
rm -rf "$MEMORY_DIR"
|
|
137
|
+
log " ✓ Removed memory directory" "$GREEN"
|
|
138
|
+
else
|
|
139
|
+
log " ⊙ No memory directory found" "$BLUE"
|
|
140
|
+
fi
|
|
141
|
+
|
|
142
|
+
log '' ''
|
|
143
|
+
log 'Step 4/4: Cleaning up...' "$YELLOW"
|
|
144
|
+
|
|
145
|
+
# Remove vector database cache
|
|
146
|
+
VECTOR_CACHE="$HOME/.cache/huggingface"
|
|
147
|
+
if [ -d "$VECTOR_CACHE" ]; then
|
|
148
|
+
log " ⊙ HuggingFace cache preserved at: $VECTOR_CACHE" "$BLUE"
|
|
149
|
+
log " (You can safely delete this to save ~80MB)" "$NC"
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
# Summary
|
|
153
|
+
log '' ''
|
|
154
|
+
log '═════════════════════════════════════════════════════════════════' "$BLUE"
|
|
155
|
+
log ' ✓ Uninstallation completed!' "$GREEN"
|
|
156
|
+
log '═════════════════════════════════════════════════════════════════' "$BLUE"
|
|
157
|
+
log '' ''
|
|
158
|
+
log 'Backup location:' "$GREEN"
|
|
159
|
+
log " $BACKUP_DIR" "$BLUE"
|
|
160
|
+
log '' '
|
|
161
|
+
log 'To restore your memory files:' "$YELLOW"
|
|
162
|
+
log ' cp -r '$BACKUP_DIR'/memory ~/.opencode/' "$BLUE"
|
|
163
|
+
log '' '
|
|
164
|
+
log 'To completely remove the backup:' "$YELLOW"
|
|
165
|
+
log ' rm -rf '$BACKUP_DIR "$BLUE"
|
|
166
|
+
log '' '
|
|
167
|
+
log 'To remove HuggingFace model cache (~80MB):' "$YELLOW"
|
|
168
|
+
log ' rm -rf ~/.cache/huggingface' "$BLUE"
|
|
169
|
+
log '' '
|
|
170
|
+
log 'Thank you for using OpenCode Memory Plugin!' "$GREEN"
|
|
171
|
+
log '' ''
|