@csuwl/opencode-memory-plugin 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/README.npm.md +57 -0
- package/agents/memory-automation.md +121 -0
- package/agents/memory-consolidate.md +267 -0
- package/bin/install.js +354 -0
- package/index.js +47 -0
- package/memory/AGENTS.md +73 -0
- package/memory/BOOT.md +35 -0
- package/memory/BOOTSTRAP.md +105 -0
- package/memory/HEARTBEAT.md +26 -0
- package/memory/IDENTITY.md +28 -0
- package/memory/MEMORY.md +21 -0
- package/memory/SOUL.md +28 -0
- package/memory/TOOLS.md +91 -0
- package/memory/USER.md +37 -0
- package/package.json +45 -0
- package/scripts/docker-init.sh +154 -0
- package/scripts/init.sh +338 -0
- package/scripts/test-memory-functions.sh +131 -0
- package/tools/memory.ts +308 -0
- package/tools/vector-memory.ts +428 -0
package/memory/SOUL.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# AI Assistant Personality
|
|
2
|
+
|
|
3
|
+
## Core Identity
|
|
4
|
+
You are OpenCode Memory, an AI coding assistant with persistent memory and semantic search capabilities.
|
|
5
|
+
|
|
6
|
+
## Tone and Style
|
|
7
|
+
- Professional, friendly, and concise
|
|
8
|
+
- Prefer direct answers over long explanations
|
|
9
|
+
- Use code examples when helpful
|
|
10
|
+
- Always maintain context of previous conversations through memory
|
|
11
|
+
|
|
12
|
+
## Boundaries
|
|
13
|
+
- Always ask before making destructive changes
|
|
14
|
+
- Respect user's time and attention
|
|
15
|
+
- Admit when you don't know something
|
|
16
|
+
- Never hallucinate information - check memory first
|
|
17
|
+
|
|
18
|
+
## Memory Awareness
|
|
19
|
+
- You have access to persistent memory through the memory tools
|
|
20
|
+
- Always consult memory before answering questions
|
|
21
|
+
- Proactively save important information to memory
|
|
22
|
+
- Use semantic search to find relevant past information
|
|
23
|
+
|
|
24
|
+
## Working Principles
|
|
25
|
+
- Quality over quantity
|
|
26
|
+
- Clarity over cleverness
|
|
27
|
+
- Test your assumptions
|
|
28
|
+
- Learn from mistakes (document them in memory)
|
package/memory/TOOLS.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Tool Usage Conventions & Notes
|
|
2
|
+
|
|
3
|
+
## Memory Tools
|
|
4
|
+
|
|
5
|
+
### memory_write
|
|
6
|
+
- **Use when**: Saving preferences, successful patterns, decisions, lessons learned
|
|
7
|
+
- **Always save**: User preferences, project conventions, working patterns
|
|
8
|
+
- **Types**:
|
|
9
|
+
- `long-term`: Persistent memories (MEMORY.md)
|
|
10
|
+
- `daily`: Running context (memory/YYYY-MM-DD.md)
|
|
11
|
+
- `preference`: User preferences (PREFERENCES.md - use `preference` type)
|
|
12
|
+
- **Best practice**: Save immediately after important information is shared
|
|
13
|
+
|
|
14
|
+
### memory_read
|
|
15
|
+
- **Use when**: Retrieving saved information, checking past decisions
|
|
16
|
+
- **Types**: long-term, daily, preference, personality, context
|
|
17
|
+
- **Best practice**: Read before making decisions to maintain consistency
|
|
18
|
+
|
|
19
|
+
### memory_search
|
|
20
|
+
- **Use when**: Finding relevant past information with different wording
|
|
21
|
+
- **Scope**: all (searches everything), long-term, daily, preference
|
|
22
|
+
- **Best practice**: Use semantic search to find patterns you forgot existed
|
|
23
|
+
|
|
24
|
+
### vector_memory_search
|
|
25
|
+
- **Use when**: Semantic search across memory when exact words don't match
|
|
26
|
+
- **Returns**: Ranked results with similarity scores
|
|
27
|
+
- **Best practice**: First choice for finding relevant context
|
|
28
|
+
|
|
29
|
+
## File Tools
|
|
30
|
+
|
|
31
|
+
### read
|
|
32
|
+
- **Always use absolute paths**
|
|
33
|
+
- **Use offset/limit** for large files
|
|
34
|
+
- **Read multiple files in parallel** when possible
|
|
35
|
+
|
|
36
|
+
### write
|
|
37
|
+
- **Always read file first** before writing
|
|
38
|
+
- **Use descriptive commit messages** if applicable
|
|
39
|
+
- **Never overwrite without confirmation** for important files
|
|
40
|
+
|
|
41
|
+
### edit
|
|
42
|
+
- **Preserve exact indentation** after line numbers
|
|
43
|
+
- **Use larger context** for unique matches
|
|
44
|
+
- **Consider file structure** before editing
|
|
45
|
+
|
|
46
|
+
## Bash Tools
|
|
47
|
+
|
|
48
|
+
### Safe Commands
|
|
49
|
+
- `git status`, `git log` - Always allowed
|
|
50
|
+
- `ls`, `grep`, `find` - Safe exploration
|
|
51
|
+
- `git diff` - Always review before changes
|
|
52
|
+
|
|
53
|
+
### Ask Before
|
|
54
|
+
- `git push`, `git rebase` - Destructive operations
|
|
55
|
+
- `npm install`, `cargo build` - Dependency changes
|
|
56
|
+
- `rm`, `mv` with wildcards - Destructive file operations
|
|
57
|
+
|
|
58
|
+
### Background Processes
|
|
59
|
+
- Use `&` for long-running services
|
|
60
|
+
- Check with `ps` after starting
|
|
61
|
+
- Kill properly with `pkill` or `kill <pid>`
|
|
62
|
+
|
|
63
|
+
## Patterns
|
|
64
|
+
|
|
65
|
+
### Code Review
|
|
66
|
+
1. Read the file
|
|
67
|
+
2. Check memory for similar issues
|
|
68
|
+
3. Search for relevant past solutions
|
|
69
|
+
4. Provide specific feedback
|
|
70
|
+
5. Save any new patterns to memory
|
|
71
|
+
|
|
72
|
+
### Feature Implementation
|
|
73
|
+
1. Search memory for similar features
|
|
74
|
+
2. Check project conventions in memory
|
|
75
|
+
3. Implement following established patterns
|
|
76
|
+
4. Test thoroughly
|
|
77
|
+
5. Save successful approach to memory
|
|
78
|
+
|
|
79
|
+
### Debugging
|
|
80
|
+
1. Search memory for similar issues
|
|
81
|
+
2. Check if issue was solved before
|
|
82
|
+
3. If new, document the problem
|
|
83
|
+
4. Implement and test solution
|
|
84
|
+
5. Save the solution to memory
|
|
85
|
+
|
|
86
|
+
## Conventions
|
|
87
|
+
|
|
88
|
+
- **Code style**: Check memory first, follow existing patterns
|
|
89
|
+
- **Commit messages**: Follow project conventions
|
|
90
|
+
- **Documentation**: Always document complex logic
|
|
91
|
+
- **Testing**: Test critical paths, document edge cases
|
package/memory/USER.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# User Profile & Preferences
|
|
2
|
+
|
|
3
|
+
## User Identity
|
|
4
|
+
- Name: User
|
|
5
|
+
- Communication Style: Professional, direct, concise
|
|
6
|
+
- Language Preference: English (can be changed)
|
|
7
|
+
- Timezone: (to be configured)
|
|
8
|
+
|
|
9
|
+
## Preferred Communication
|
|
10
|
+
- Get straight to the point
|
|
11
|
+
- Show, don't just tell
|
|
12
|
+
- Use examples
|
|
13
|
+
- Summarize key takeaways
|
|
14
|
+
|
|
15
|
+
## Working Style
|
|
16
|
+
- Provide context upfront
|
|
17
|
+
- Ask clarifying questions when uncertain
|
|
18
|
+
- Prefer multiple options over single approach
|
|
19
|
+
- Want to understand "why", not just "what"
|
|
20
|
+
|
|
21
|
+
## Code Preferences
|
|
22
|
+
- Clean, readable code over clever code
|
|
23
|
+
- Proper documentation for complex logic
|
|
24
|
+
- Consistent formatting
|
|
25
|
+
- Test coverage for critical paths
|
|
26
|
+
|
|
27
|
+
## Feedback Style
|
|
28
|
+
- Be direct about issues
|
|
29
|
+
- Appreciate learning opportunities
|
|
30
|
+
- Want to understand root causes
|
|
31
|
+
- Prefer actionable next steps
|
|
32
|
+
|
|
33
|
+
## Pet Peeves
|
|
34
|
+
- Over-explaining simple concepts
|
|
35
|
+
- Making assumptions without asking
|
|
36
|
+
- Ignoring stated preferences
|
|
37
|
+
- Breaking changes without explanation
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@csuwl/opencode-memory-plugin",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "OpenClaw-style memory system for OpenCode with full automation and local vector search",
|
|
5
|
+
"author": "csuwl <1105865632@qq.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"opencode-memory-plugin": "bin/install.js"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/csuwl/opencode-memory-plugin.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"opencode",
|
|
17
|
+
"memory",
|
|
18
|
+
"plugin",
|
|
19
|
+
"ai",
|
|
20
|
+
"openclaw",
|
|
21
|
+
"vector-search",
|
|
22
|
+
"semantic-search"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@opencode-ai/plugin": "latest",
|
|
26
|
+
"better-sqlite3": "latest",
|
|
27
|
+
"sqlite-vec": "latest"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "latest",
|
|
31
|
+
"typescript": "latest"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"memory/",
|
|
35
|
+
"tools/",
|
|
36
|
+
"agents/",
|
|
37
|
+
"scripts/",
|
|
38
|
+
"bin/",
|
|
39
|
+
"index.js",
|
|
40
|
+
"README.npm.md"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"install": "node bin/install.js"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
# OpenClaw-Style Memory System for OpenCode - Docker Initialization Script
|
|
4
|
+
# This script sets up memory system inside Docker container
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
# Colors for output
|
|
9
|
+
GREEN='\033[0;32m'
|
|
10
|
+
YELLOW='\033[1;33m'
|
|
11
|
+
BLUE='\033[0;34m'
|
|
12
|
+
NC='\033[0m' # No Color
|
|
13
|
+
|
|
14
|
+
# Paths (Docker environment)
|
|
15
|
+
MEMORY_ROOT="/root/.opencode"
|
|
16
|
+
MEMORY_DIR="$MEMORY_ROOT/memory"
|
|
17
|
+
DAILY_DIR="$MEMORY_DIR/daily"
|
|
18
|
+
|
|
19
|
+
echo -e "${BLUE}══════════════════════════════════════════════════════════════${NC}"
|
|
20
|
+
echo -e "${BLUE} OpenCode Memory Plugin - Docker Initialization${NC}"
|
|
21
|
+
echo -e "${BLUE}══════════════════════════════════════════════════════════════${NC}"
|
|
22
|
+
echo ""
|
|
23
|
+
|
|
24
|
+
# Step 1: Create directory structure
|
|
25
|
+
echo -e "${YELLOW}Step 1/5: Creating memory directory structure...${NC}"
|
|
26
|
+
mkdir -p "$MEMORY_DIR"
|
|
27
|
+
mkdir -p "$DAILY_DIR"
|
|
28
|
+
mkdir -p "$MEMORY_DIR/archive/weekly"
|
|
29
|
+
mkdir -p "$MEMORY_DIR/archive/monthly"
|
|
30
|
+
echo -e "${GREEN}✓${NC} Directory structure created"
|
|
31
|
+
echo ""
|
|
32
|
+
|
|
33
|
+
# Step 2: Copy memory files
|
|
34
|
+
echo -e "${YELLOW}Step 2/5: Copying memory files...${NC}"
|
|
35
|
+
|
|
36
|
+
# Get script directory - sh compatible way
|
|
37
|
+
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
|
38
|
+
PLUGIN_DIR=$(dirname "$SCRIPT_DIR")
|
|
39
|
+
|
|
40
|
+
# Copy files if they don't exist
|
|
41
|
+
FILES="SOUL.md AGENTS.md USER.md IDENTITY.md TOOLS.md MEMORY.md HEARTBEAT.md BOOT.md BOOTSTRAP.md"
|
|
42
|
+
for file in $FILES; do
|
|
43
|
+
SOURCE="$PLUGIN_DIR/memory/$file"
|
|
44
|
+
DEST="$MEMORY_DIR/$file"
|
|
45
|
+
|
|
46
|
+
if [ ! -f "$DEST" ]; then
|
|
47
|
+
if [ -f "$SOURCE" ]; then
|
|
48
|
+
cp "$SOURCE" "$DEST"
|
|
49
|
+
echo -e " ${GREEN}✓${NC} Created: $file"
|
|
50
|
+
else
|
|
51
|
+
echo -e " ${RED}✗${NC} Missing: $SOURCE"
|
|
52
|
+
fi
|
|
53
|
+
else
|
|
54
|
+
echo -e " ${BLUE}⊙${NC} Exists: $file (skipped)"
|
|
55
|
+
fi
|
|
56
|
+
done
|
|
57
|
+
|
|
58
|
+
echo -e "${GREEN}✓${NC} Memory files copied"
|
|
59
|
+
echo ""
|
|
60
|
+
|
|
61
|
+
# Step 3: Create memory configuration
|
|
62
|
+
echo -e "${YELLOW}Step 3/5: Creating memory configuration...${NC}"
|
|
63
|
+
# Create OpenCode config directory
|
|
64
|
+
OPENCORE_CONFIG_DIR="/root/.config/opencode"
|
|
65
|
+
mkdir -p "$OPENCORE_CONFIG_DIR"
|
|
66
|
+
MEMORY_CONFIG="$OPENCORE_CONFIG_DIR/opencode.json"
|
|
67
|
+
cat > "$MEMORY_CONFIG" << 'EOF'
|
|
68
|
+
{
|
|
69
|
+
"version": "1.0.0",
|
|
70
|
+
"auto_save": true,
|
|
71
|
+
"auto_save_threshold_tokens": 1000,
|
|
72
|
+
"vector_search": {
|
|
73
|
+
"enabled": true,
|
|
74
|
+
"hybrid": true,
|
|
75
|
+
"rebuild_interval_hours": 24
|
|
76
|
+
},
|
|
77
|
+
"consolidation": {
|
|
78
|
+
"enabled": true,
|
|
79
|
+
"run_daily": true,
|
|
80
|
+
"run_hour": 23,
|
|
81
|
+
"archive_days": 30,
|
|
82
|
+
"delete_days": 90
|
|
83
|
+
},
|
|
84
|
+
"git_backup": {
|
|
85
|
+
"enabled": false,
|
|
86
|
+
"auto_commit": false,
|
|
87
|
+
"auto_push": false
|
|
88
|
+
},
|
|
89
|
+
"retention": {
|
|
90
|
+
"max_daily_files": 30,
|
|
91
|
+
"max_entries_per_file": 100,
|
|
92
|
+
"chunk_size": 400,
|
|
93
|
+
"chunk_overlap": 80
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
EOF
|
|
97
|
+
|
|
98
|
+
echo -e "${GREEN}✓${NC} Configuration created"
|
|
99
|
+
echo ""
|
|
100
|
+
|
|
101
|
+
# Step 4: Initialize daily log for today
|
|
102
|
+
echo -e "${YELLOW}Step 4/5: Initializing today's daily log...${NC}"
|
|
103
|
+
TODAY=$(date +%Y-%m-%d)
|
|
104
|
+
TODAY_FILE="$DAILY_DIR/$TODAY.md"
|
|
105
|
+
|
|
106
|
+
if [ ! -f "$TODAY_FILE" ]; then
|
|
107
|
+
cat > "$TODAY_FILE" << EOF
|
|
108
|
+
# Daily Memory Log - $TODAY
|
|
109
|
+
|
|
110
|
+
*Session starts: $(date +%Y-%m-%dT%H:%M:%S)*
|
|
111
|
+
|
|
112
|
+
## Notes
|
|
113
|
+
|
|
114
|
+
## Tasks
|
|
115
|
+
|
|
116
|
+
## Learnings
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
EOF
|
|
120
|
+
echo -e " ${GREEN}✓${NC} Created today's daily log: $TODAY.md"
|
|
121
|
+
else
|
|
122
|
+
echo -e " ${BLUE}⊙${NC} Daily log already exists: $TODAY.md"
|
|
123
|
+
fi
|
|
124
|
+
|
|
125
|
+
echo ""
|
|
126
|
+
|
|
127
|
+
# Step 5: Summary
|
|
128
|
+
echo -e "${BLUE}══════════════════════════════════════════════════════════════${NC}"
|
|
129
|
+
echo -e "${GREEN}✓${NC} Memory system initialized successfully!"
|
|
130
|
+
echo -e "${BLUE}══════════════════════════════════════════════════════════════${NC}"
|
|
131
|
+
echo ""
|
|
132
|
+
echo -e "${YELLOW}Memory System Structure:${NC}"
|
|
133
|
+
echo -e " ${BLUE}📁${NC} /root/.opencode/memory/"
|
|
134
|
+
echo -e " ├── SOUL.md ${GREEN}(personality & boundaries)${NC}"
|
|
135
|
+
echo -e " ├── AGENTS.md ${GREEN}(operating instructions)${NC}"
|
|
136
|
+
echo -e " ├── USER.md ${GREEN}(user profile)${NC}"
|
|
137
|
+
echo -e " ├── IDENTITY.md ${GREEN}(assistant identity)${NC}"
|
|
138
|
+
echo -e " ├── TOOLS.md ${GREEN}(tool conventions)${NC}"
|
|
139
|
+
echo -e " ├── MEMORY.md ${GREEN}(long-term memory)${NC}"
|
|
140
|
+
echo -e " ├── daily/ ${GREEN}(daily logs)${NC}"
|
|
141
|
+
echo -e " └── archive/ ${GREEN}(archived logs)${NC}"
|
|
142
|
+
echo ""
|
|
143
|
+
echo -e "${YELLOW}Next Steps:${NC}"
|
|
144
|
+
echo -e " 1. Start OpenCode with: ${BLUE}opencode${NC}"
|
|
145
|
+
echo -e " 2. Test memory tools:"
|
|
146
|
+
echo -e " ${BLUE}memory_write content='Test memory' type='daily'${NC}"
|
|
147
|
+
echo -e " ${BLUE}memory_search query='test'${NC}"
|
|
148
|
+
echo -e " ${BLUE}vector_memory_search query='test'${NC}"
|
|
149
|
+
echo -e " 3. Test automation agents:"
|
|
150
|
+
echo -e " ${BLUE}@memory-automation review and save important information${NC}"
|
|
151
|
+
echo -e " ${BLUE}@memory-consolidate review and consolidate recent memories${NC}"
|
|
152
|
+
echo ""
|
|
153
|
+
echo -e "${BLUE}🎉${NC} Memory system ready! 🧠"
|
|
154
|
+
echo ""
|
package/scripts/init.sh
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# OpenClaw-Style Memory System for OpenCode - Initialization Script
|
|
4
|
+
# This script sets up the complete memory system with all necessary files and configuration
|
|
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
|
+
# Paths
|
|
16
|
+
MEMORY_ROOT="$HOME/.opencode"
|
|
17
|
+
MEMORY_DIR="$MEMORY_ROOT/memory"
|
|
18
|
+
DAILY_DIR="$MEMORY_DIR/daily"
|
|
19
|
+
VECTOR_DB="$MEMORY_DIR/vector-index.db"
|
|
20
|
+
MEMORY_CONFIG="$MEMORY_DIR/memory-config.json"
|
|
21
|
+
|
|
22
|
+
# OpenCode config directory
|
|
23
|
+
OPENCODE_CONFIG_DIR="$HOME/.config/opencode"
|
|
24
|
+
OPENCODE_CONFIG="$OPENCODE_CONFIG_DIR/opencode.json"
|
|
25
|
+
|
|
26
|
+
echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
|
|
27
|
+
echo -e "${BLUE} OpenCode Memory Plugin - Initialization${NC}"
|
|
28
|
+
echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
|
|
29
|
+
echo ""
|
|
30
|
+
|
|
31
|
+
# Step 1: Create directory structure
|
|
32
|
+
echo -e "${YELLOW}Step 1/7: Creating memory directory structure...${NC}"
|
|
33
|
+
mkdir -p "$MEMORY_DIR"
|
|
34
|
+
mkdir -p "$DAILY_DIR"
|
|
35
|
+
mkdir -p "$MEMORY_DIR/archive/weekly"
|
|
36
|
+
mkdir -p "$MEMORY_DIR/archive/monthly"
|
|
37
|
+
echo -e "${GREEN}✓ Directory structure created${NC}"
|
|
38
|
+
echo ""
|
|
39
|
+
|
|
40
|
+
# Step 2: Copy memory files
|
|
41
|
+
echo -e "${YELLOW}Step 2/7: Copying memory files...${NC}"
|
|
42
|
+
|
|
43
|
+
# Get script directory
|
|
44
|
+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
45
|
+
PLUGIN_DIR="$(dirname "$SCRIPT_DIR")"
|
|
46
|
+
|
|
47
|
+
# Copy files if they don't exist
|
|
48
|
+
FILES=(
|
|
49
|
+
"SOUL.md"
|
|
50
|
+
"AGENTS.md"
|
|
51
|
+
"USER.md"
|
|
52
|
+
"IDENTITY.md"
|
|
53
|
+
"TOOLS.md"
|
|
54
|
+
"MEMORY.md"
|
|
55
|
+
"HEARTBEAT.md"
|
|
56
|
+
"BOOT.md"
|
|
57
|
+
"BOOTSTRAP.md"
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
for file in "${FILES[@]}"; do
|
|
61
|
+
SOURCE="$PLUGIN_DIR/memory/$file"
|
|
62
|
+
DEST="$MEMORY_DIR/$file"
|
|
63
|
+
|
|
64
|
+
if [ ! -f "$DEST" ]; then
|
|
65
|
+
if [ -f "$SOURCE" ]; then
|
|
66
|
+
cp "$SOURCE" "$DEST"
|
|
67
|
+
echo -e " ${GREEN}✓${NC} Created: $file"
|
|
68
|
+
else
|
|
69
|
+
echo -e " ${RED}✗${NC} Missing: $SOURCE"
|
|
70
|
+
fi
|
|
71
|
+
else
|
|
72
|
+
echo -e " ${BLUE}⊙${NC} Exists: $file (skipped)"
|
|
73
|
+
fi
|
|
74
|
+
done
|
|
75
|
+
|
|
76
|
+
echo -e "${GREEN}✓ Memory files copied${NC}"
|
|
77
|
+
echo ""
|
|
78
|
+
|
|
79
|
+
# Step 3: Create memory configuration
|
|
80
|
+
echo -e "${YELLOW}Step 3/7: Creating memory configuration...${NC}"
|
|
81
|
+
cat > "$MEMORY_CONFIG" << 'EOF'
|
|
82
|
+
{
|
|
83
|
+
"version": "1.0.0",
|
|
84
|
+
"auto_save": true,
|
|
85
|
+
"auto_save_threshold_tokens": 1000,
|
|
86
|
+
"vector_search": {
|
|
87
|
+
"enabled": true,
|
|
88
|
+
"hybrid": true,
|
|
89
|
+
"rebuild_interval_hours": 24
|
|
90
|
+
},
|
|
91
|
+
"consolidation": {
|
|
92
|
+
"enabled": true,
|
|
93
|
+
"run_daily": true,
|
|
94
|
+
"run_hour": 23,
|
|
95
|
+
"archive_days": 30,
|
|
96
|
+
"delete_days": 90
|
|
97
|
+
},
|
|
98
|
+
"git_backup": {
|
|
99
|
+
"enabled": false,
|
|
100
|
+
"auto_commit": false,
|
|
101
|
+
"auto_push": false
|
|
102
|
+
},
|
|
103
|
+
"retention": {
|
|
104
|
+
"max_daily_files": 30,
|
|
105
|
+
"max_entries_per_file": 100,
|
|
106
|
+
"chunk_size": 400,
|
|
107
|
+
"chunk_overlap": 80
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
EOF
|
|
111
|
+
|
|
112
|
+
echo -e "${GREEN}✓ Configuration created${NC}"
|
|
113
|
+
echo ""
|
|
114
|
+
|
|
115
|
+
# Step 4: Configure OpenCode to use memory
|
|
116
|
+
echo -e "${YELLOW}Step 4/7: Configuring OpenCode to use memory...${NC}"
|
|
117
|
+
|
|
118
|
+
# Ensure OpenCode config directory exists
|
|
119
|
+
mkdir -p "$OPENCODE_CONFIG_DIR"
|
|
120
|
+
|
|
121
|
+
# Backup existing config
|
|
122
|
+
if [ -f "$OPENCODE_CONFIG" ]; then
|
|
123
|
+
BACKUP="${OPENCODE_CONFIG}.backup.$(date +%Y%m%d_%H%M%S)"
|
|
124
|
+
cp "$OPENCODE_CONFIG" "$BACKUP"
|
|
125
|
+
echo -e " ${BLUE}⊙${NC} Backed up existing config to: $(basename "$BACKUP")"
|
|
126
|
+
fi
|
|
127
|
+
|
|
128
|
+
# Create or update OpenCode config
|
|
129
|
+
if [ ! -f "$OPENCODE_CONFIG" ]; then
|
|
130
|
+
# Create new config
|
|
131
|
+
cat > "$OPENCODE_CONFIG" << 'EOF'
|
|
132
|
+
{
|
|
133
|
+
"$schema": "https://opencode.ai/config.json",
|
|
134
|
+
"instructions": [
|
|
135
|
+
"~/.opencode/memory/SOUL.md",
|
|
136
|
+
"~/.opencode/memory/AGENTS.md",
|
|
137
|
+
"~/.opencode/memory/USER.md",
|
|
138
|
+
"~/.opencode/memory/IDENTITY.md",
|
|
139
|
+
"~/.opencode/memory/TOOLS.md",
|
|
140
|
+
"~/.opencode/memory/MEMORY.md"
|
|
141
|
+
],
|
|
142
|
+
"agent": {
|
|
143
|
+
"memory-automation": {
|
|
144
|
+
"description": "Automatically saves important information to memory",
|
|
145
|
+
"mode": "subagent",
|
|
146
|
+
"tools": {
|
|
147
|
+
"memory_write": true,
|
|
148
|
+
"memory_read": true,
|
|
149
|
+
"memory_search": true,
|
|
150
|
+
"vector_memory_search": true
|
|
151
|
+
},
|
|
152
|
+
"permission": {
|
|
153
|
+
"memory_write": "allow",
|
|
154
|
+
"memory_read": "allow",
|
|
155
|
+
"memory_search": "allow",
|
|
156
|
+
"vector_memory_search": "allow"
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
"memory-consolidate": {
|
|
160
|
+
"description": "Consolidates daily logs into long-term memory",
|
|
161
|
+
"mode": "subagent",
|
|
162
|
+
"tools": {
|
|
163
|
+
"memory_write": true,
|
|
164
|
+
"memory_read": true,
|
|
165
|
+
"memory_search": true,
|
|
166
|
+
"vector_memory_search": true,
|
|
167
|
+
"list_daily": true,
|
|
168
|
+
"rebuild_index": true
|
|
169
|
+
},
|
|
170
|
+
"permission": {
|
|
171
|
+
"memory_write": "allow",
|
|
172
|
+
"memory_read": "allow",
|
|
173
|
+
"memory_search": "allow",
|
|
174
|
+
"vector_memory_search": "allow",
|
|
175
|
+
"list_daily": "allow",
|
|
176
|
+
"rebuild_index": "allow"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
"permission": {
|
|
181
|
+
"bash": "ask",
|
|
182
|
+
"edit": "ask",
|
|
183
|
+
"write": "ask"
|
|
184
|
+
},
|
|
185
|
+
"tools": {
|
|
186
|
+
"memory_write": true,
|
|
187
|
+
"memory_read": true,
|
|
188
|
+
"memory_search": true,
|
|
189
|
+
"vector_memory_search": true,
|
|
190
|
+
"list_daily": true,
|
|
191
|
+
"init_daily": true,
|
|
192
|
+
"rebuild_index": true,
|
|
193
|
+
"index_status": true
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
EOF'
|
|
197
|
+
echo -e " ${GREEN}✓${NC} Created OpenCode config"
|
|
198
|
+
else
|
|
199
|
+
# Update existing config - add instructions and tools if not present
|
|
200
|
+
echo -e " ${BLUE}⊙${NC} Updating existing OpenCode config..."
|
|
201
|
+
|
|
202
|
+
# This is a simplified update - in production, we'd use jq or a proper JSON parser
|
|
203
|
+
if [ -f "$OPENCODE_CONFIG" ] && ! grep -q "instructions" "$OPENCODE_CONFIG"; then
|
|
204
|
+
# Add instructions section before the closing brace
|
|
205
|
+
TEMP_FILE=$(mktemp)
|
|
206
|
+
# Read everything except the last line (the closing })
|
|
207
|
+
head -n -1 "$OPENCODE_CONFIG" > "$TEMP_FILE"
|
|
208
|
+
|
|
209
|
+
# Add instructions and agents
|
|
210
|
+
cat >> "$TEMP_FILE" << 'EOF'
|
|
211
|
+
"instructions": [
|
|
212
|
+
"~/.opencode/memory/SOUL.md",
|
|
213
|
+
"~/.opencode/memory/AGENTS.md",
|
|
214
|
+
"~/.opencode/memory/USER.md",
|
|
215
|
+
"~/.opencode/memory/IDENTITY.md",
|
|
216
|
+
"~/.opencode/memory/TOOLS.md",
|
|
217
|
+
"~/.opencode/memory/MEMORY.md"
|
|
218
|
+
],
|
|
219
|
+
EOF'
|
|
220
|
+
|
|
221
|
+
# Add closing brace
|
|
222
|
+
echo "}" >> "$TEMP_FILE"
|
|
223
|
+
|
|
224
|
+
# Replace original file
|
|
225
|
+
mv "$TEMP_FILE" "$OPENCODE_CONFIG"
|
|
226
|
+
echo -e " ${GREEN}✓${NC} Added memory instructions"
|
|
227
|
+
else
|
|
228
|
+
echo -e " ${YELLOW}⚠${NC} Could not update config or instructions already exist"
|
|
229
|
+
fi
|
|
230
|
+
|
|
231
|
+
# Check if tools are configured
|
|
232
|
+
if ! grep -q '"memory_write"' "$OPENCODE_CONFIG"; then
|
|
233
|
+
echo -e " ${YELLOW}⚠${NC} Memory tools not fully configured. Please manually add tools to opencode.json."
|
|
234
|
+
fi
|
|
235
|
+
fi
|
|
236
|
+
|
|
237
|
+
echo -e "${GREEN}✓ OpenCode configuration updated${NC}"
|
|
238
|
+
echo ""
|
|
239
|
+
|
|
240
|
+
# Step 5: Initialize daily log for today
|
|
241
|
+
echo -e "${YELLOW}Step 5/7: Initializing today's daily log...${NC}"
|
|
242
|
+
TODAY=$(date +%Y-%m-%d)
|
|
243
|
+
TODAY_FILE="$DAILY_DIR/$TODAY.md"
|
|
244
|
+
|
|
245
|
+
if [ ! -f "$TODAY_FILE" ]; then
|
|
246
|
+
cat > "$TODAY_FILE" << EOF
|
|
247
|
+
# Daily Memory Log - $TODAY
|
|
248
|
+
|
|
249
|
+
*Session starts: $(date +%Y-%m-%dT%H:%M:%S)*
|
|
250
|
+
|
|
251
|
+
## Notes
|
|
252
|
+
|
|
253
|
+
## Tasks
|
|
254
|
+
|
|
255
|
+
## Learnings
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
EOF
|
|
259
|
+
echo -e " ${GREEN}✓${NC} Created today's daily log: $TODAY.md"
|
|
260
|
+
else
|
|
261
|
+
echo -e " ${BLUE}⊙${NC} Daily log already exists: $TODAY.md"
|
|
262
|
+
fi
|
|
263
|
+
|
|
264
|
+
echo ""
|
|
265
|
+
|
|
266
|
+
# Step 6: Install plugin dependencies
|
|
267
|
+
echo -e "${YELLOW}Step 6/7: Installing plugin dependencies...${NC}"
|
|
268
|
+
cd "$PLUGIN_DIR"
|
|
269
|
+
|
|
270
|
+
if [ -f "package.json" ]; then
|
|
271
|
+
if command -v npm &> /dev/null; then
|
|
272
|
+
npm install
|
|
273
|
+
echo -e " ${GREEN}✓${NC} Dependencies installed"
|
|
274
|
+
elif command -v pnpm &> /dev/null; then
|
|
275
|
+
pnpm install
|
|
276
|
+
echo -e " ${GREEN}✓${NC} Dependencies installed"
|
|
277
|
+
elif command -v bun &> /dev/null; then
|
|
278
|
+
bun install
|
|
279
|
+
echo -e " ${GREEN}✓${NC} Dependencies installed"
|
|
280
|
+
else
|
|
281
|
+
echo -e " ${RED}✗${NC} No package manager found (npm/pnpm/bun). Please install dependencies manually."
|
|
282
|
+
fi
|
|
283
|
+
else
|
|
284
|
+
echo -e " ${YELLOW}⚠${NC} No package.json found. Skipping dependency installation."
|
|
285
|
+
fi
|
|
286
|
+
|
|
287
|
+
echo ""
|
|
288
|
+
|
|
289
|
+
# Step 7: Final summary
|
|
290
|
+
echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
|
|
291
|
+
echo -e "${GREEN}✓ Memory system initialized successfully!${NC}"
|
|
292
|
+
echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
|
|
293
|
+
echo ""
|
|
294
|
+
echo -e "${YELLOW}Memory System Structure:${NC}"
|
|
295
|
+
echo -e " ${BLUE}📁${NC} ~/.opencode/memory/"
|
|
296
|
+
echo -e " ├── SOUL.md ${GREEN}(personality & boundaries)${NC}"
|
|
297
|
+
echo -e " ├── AGENTS.md ${GREEN}(operating instructions)${NC}"
|
|
298
|
+
echo -e " ├── USER.md ${GREEN}(user profile)${NC}"
|
|
299
|
+
echo -e " ├── IDENTITY.md ${GREEN}(assistant identity)${NC}"
|
|
300
|
+
echo -e " ├── TOOLS.md ${GREEN}(tool conventions)${NC}"
|
|
301
|
+
echo -e " ├── MEMORY.md ${GREEN}(long-term memory)${NC}"
|
|
302
|
+
echo -e " ├── HEARTBEAT.md ${GREEN}(health checklist)${NC}"
|
|
303
|
+
echo -e " ├── BOOT.md ${GREEN}(startup checklist)${NC}"
|
|
304
|
+
echo -e " ├── BOOTSTRAP.md ${GREEN}(first-run ritual)${NC}"
|
|
305
|
+
echo -e " ├── daily/ ${GREEN}(daily logs)${NC}"
|
|
306
|
+
echo -e " ├── archive/weekly/ ${GREEN}(archived weekly logs)${NC}"
|
|
307
|
+
echo -e " └── archive/monthly/ ${GREEN}(archived monthly logs)${NC}"
|
|
308
|
+
echo ""
|
|
309
|
+
echo -e "${YELLOW}Available Agents:${NC}"
|
|
310
|
+
echo -e " ${BLUE}🤖${NC} @memory-automation ${GREEN}(auto-saves important info)${NC}"
|
|
311
|
+
echo -e " ${BLUE}🤖${NC} @memory-consolidate ${GREEN}(organizes & archives)${NC}"
|
|
312
|
+
echo ""
|
|
313
|
+
echo -e "${YELLOW}Memory Tools:${NC}"
|
|
314
|
+
echo -e " ${BLUE}🔧${NC} memory_write ${GREEN}(save memories)${NC}"
|
|
315
|
+
echo -e " ${BLUE}🔧${NC} memory_read ${GREEN}(read memories)${NC}"
|
|
316
|
+
echo -e " ${BLUE}🔧${NC} memory_search ${GREEN}(keyword search)${NC}"
|
|
317
|
+
echo -e " ${BLUE}🔧${NC} vector_memory_search ${GREEN}(semantic search)${NC}"
|
|
318
|
+
echo -e " ${BLUE}🔧${NC} list_daily ${GREEN}(list daily logs)${NC}"
|
|
319
|
+
echo -e " ${BLUE}🔧${NC} init_daily ${GREEN}(init daily log)${NC}"
|
|
320
|
+
echo -e " ${BLUE}🔧${NC} rebuild_index ${GREEN}(rebuild vector index)${NC}"
|
|
321
|
+
echo -e " ${BLUE}🔧${NC} index_status ${GREEN}(check index status)${NC}"
|
|
322
|
+
echo ""
|
|
323
|
+
echo -e "${YELLOW}Next Steps:${NC}"
|
|
324
|
+
echo -e " 1. Review and personalize your memory files in: ${BLUE}$MEMORY_DIR${NC}"
|
|
325
|
+
echo -e " 2. Start OpenCode and use: ${BLUE}init_daily${NC} to initialize today's log"
|
|
326
|
+
echo -e " 3. Test memory tools: ${BLUE}memory_write content='Test memory' type='daily'${NC}"
|
|
327
|
+
echo -e " 4. Search memory: ${BLUE}vector_memory_search query='test'${NC}"
|
|
328
|
+
echo -e " 5. Run consolidation: ${BLUE}@memory-consolidate review and consolidate recent memories${NC}"
|
|
329
|
+
echo ""
|
|
330
|
+
echo -e "${YELLOW}Important Notes:${NC}"
|
|
331
|
+
echo -e " • Memory files are automatically injected into every OpenCode session"
|
|
332
|
+
echo -e " • The system automatically saves important information (fully automated)"
|
|
333
|
+
echo -e " • Daily logs are consolidated into long-term memory periodically"
|
|
334
|
+
echo -e " • Vector search provides semantic memory retrieval"
|
|
335
|
+
echo -e " • Review ${BLUE}BOOTSTRAP.md${NC} in $MEMORY_DIR for the first-run ritual"
|
|
336
|
+
echo ""
|
|
337
|
+
echo -e "${BLUE}🎉 Your OpenCode instance now has perfect memory! 🧠${NC}"
|
|
338
|
+
echo ""
|