Skip to content

Commit 1b5cb45

Browse files
committed
Add MemoryLayer OpenCode plugin with initial implementation and configuration files
1 parent 1749472 commit 1b5cb45

29 files changed

Lines changed: 2369 additions & 11 deletions

File tree

.claude-plugin/marketplace.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{
1111
"name": "memorylayer",
1212
"description": "Persistent memory system designed to work seamlessly with Claude agents. MemoryLayer proactively preserves important context before compaction and allows agents to recall relevant information on demand, ensuring critical knowledge is never lost.",
13-
"version": "0.0.5",
13+
"version": "0.0.6",
1414
"author": {
1515
"name": "scitrera.ai",
1616
"email": "open-source-team@scitrera.com"

memorylayer-cc-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@scitrera/memorylayer-cc-plugin",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "Claude Code plugin for MemoryLayer.ai - persistent memory hooks",
55
"type": "module",
66
"main": "dist/src/index.js",

memorylayer-explorer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@scitrera/memorylayer-explorer",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"private": true,
55
"description": "Web UI for exploring MemoryLayer memories and graph relationships",
66
"scripts": {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
dist/
3+
*.tsbuildinfo
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# MemoryLayer OpenCode Plugin
2+
3+
Persistent memory for [OpenCode](https://github.com/sst/opencode) sessions. Gives your AI coding agent long-term memory that survives context compaction and persists across sessions.
4+
5+
## What It Does
6+
7+
This plugin integrates [MemoryLayer](https://memorylayer.ai) into OpenCode via two mechanisms:
8+
9+
1. **MCP Tools** (21 tools) — The MemoryLayer MCP server gives the LLM direct access to remember, recall, reflect, associate, and manage memories through the standard Model Context Protocol.
10+
11+
2. **Proactive Hooks** — The plugin automatically:
12+
- Injects workspace briefing and user directives at session start
13+
- Recalls relevant memories when you ask preference/convention questions
14+
- Captures tool observations (file edits, searches, commands) as working memory
15+
- Commits working memory before context compaction
16+
- Cleans up sessions on exit
17+
18+
## Quick Start
19+
20+
### 1. Install the MemoryLayer server
21+
22+
```bash
23+
pip install memorylayer-server
24+
memorylayer serve
25+
```
26+
27+
Or with Docker:
28+
29+
```bash
30+
docker run -d -p 61001:61001 -v memorylayer-data:/data scitrera/memorylayer-server
31+
```
32+
33+
### 2. Configure OpenCode
34+
35+
Add to your `opencode.json`:
36+
37+
```json
38+
{
39+
"mcp": {
40+
"memorylayer": {
41+
"type": "local",
42+
"command": ["npx", "@scitrera/memorylayer-mcp-server"],
43+
"environment": {
44+
"MEMORYLAYER_URL": "{env:MEMORYLAYER_URL}",
45+
"MEMORYLAYER_API_KEY": "{env:MEMORYLAYER_API_KEY}"
46+
},
47+
"enabled": true
48+
}
49+
},
50+
"plugin": ["@scitrera/memorylayer-opencode-plugin"]
51+
}
52+
```
53+
54+
### 3. Set environment variables (optional)
55+
56+
```bash
57+
export MEMORYLAYER_URL=http://localhost:61001 # default
58+
export MEMORYLAYER_API_KEY=your-key # optional, for authenticated servers
59+
```
60+
61+
### 4. Verify
62+
63+
Start OpenCode and run `/memorylayer-status` to check the connection.
64+
65+
## Slash Commands
66+
67+
| Command | Description |
68+
|---------|-------------|
69+
| `/memorylayer-remember <content>` | Store a memory with auto-detected type and importance |
70+
| `/memorylayer-recall <query>` | Search memories by semantic query |
71+
| `/memorylayer-status` | Check connection status and workspace info |
72+
| `/memorylayer-setup` | Guided setup and verification |
73+
74+
## How Hooks Work
75+
76+
### Session Start (`experimental.chat.system.transform`)
77+
On first interaction, loads workspace briefing, user directives, and any existing sandbox state into the system prompt.
78+
79+
### User Messages (`chat.message`)
80+
Detects 5 pattern categories in user messages and performs targeted recall:
81+
- **Preference**: "which X should we use", "what's our convention"
82+
- **Recall**: "remember", "what did we", "remind me"
83+
- **Analysis**: "review", "analyze", "status"
84+
- **Implementation**: "implement", "build", "fix"
85+
- **Error**: "error", "bug", "broken"
86+
87+
### Tool Execution (`tool.execute.before` / `tool.execute.after`)
88+
- **Before**: Injects recalled context for edit/write and task/delegation tools
89+
- **After**: Silently captures observations (files, facts, concepts, intent) as working memory
90+
91+
### Context Compaction (`experimental.session.compacting`)
92+
Commits working memory to long-term storage and checkpoints server-side sandbox state before the context window is trimmed.
93+
94+
### Shell Environment (`shell.env`)
95+
Propagates `MEMORYLAYER_URL` and `MEMORYLAYER_API_KEY` to shell commands.
96+
97+
## Configuration
98+
99+
### Environment Variables
100+
101+
| Variable | Default | Description |
102+
|----------|---------|-------------|
103+
| `MEMORYLAYER_URL` | `http://localhost:61001` | MemoryLayer server URL |
104+
| `MEMORYLAYER_API_KEY` || API key (optional for local servers) |
105+
| `MEMORYLAYER_WORKSPACE_ID` | auto-detected | Workspace identifier (auto-detected from git repo name) |
106+
107+
### Workspace Auto-Detection
108+
109+
The workspace ID is automatically detected from:
110+
1. Git remote origin repository name
111+
2. Git root directory name
112+
3. Current working directory name
113+
114+
Override with the `MEMORYLAYER_WORKSPACE_ID` environment variable.
115+
116+
## Memory Types
117+
118+
| Type | Description | Importance |
119+
|------|-------------|------------|
120+
| `semantic` | Facts, concepts, knowledge | 0.5-0.9 |
121+
| `procedural` | How-to, solutions, patterns | 0.5-0.8 |
122+
| `episodic` | Events, what happened | 0.5-0.7 |
123+
| `working` | Current task context (auto-expires) | 0.3-0.6 |
124+
125+
### Common Subtypes
126+
127+
`directive`, `decision`, `fix`, `solution`, `code_pattern`, `error`, `workflow`, `preference`, `problem`
128+
129+
## Architecture
130+
131+
```
132+
OpenCode
133+
├── MCP Server (@scitrera/memorylayer-mcp-server)
134+
│ └── 21 memory tools (remember, recall, reflect, etc.)
135+
136+
├── Plugin Hooks (@scitrera/memorylayer-opencode-plugin)
137+
│ ├── system.transform → session briefing injection
138+
│ ├── chat.message → pattern-based recall
139+
│ ├── tool.before → pre-tool context injection
140+
│ ├── tool.after → observation capture
141+
│ ├── session.compacting → working memory commit
142+
│ └── shell.env → env var propagation
143+
144+
└── MemoryLayer Server (memorylayer-server)
145+
├── Memory storage (SQLite + vector search)
146+
├── Knowledge graph (associations)
147+
├── Working memory (sessions)
148+
└── Context sandbox (Python execution)
149+
```
150+
151+
## Troubleshooting
152+
153+
### Server not reachable
154+
```bash
155+
# Check if server is running
156+
curl http://localhost:61001/health
157+
158+
# Start the server
159+
memorylayer serve
160+
161+
# Or with Docker
162+
docker run -d -p 61001:61001 -v memorylayer-data:/data scitrera/memorylayer-server
163+
```
164+
165+
### MCP tools not available
166+
Verify `opencode.json` has the `mcp.memorylayer` configuration. Restart OpenCode after configuration changes.
167+
168+
### Plugin not loading
169+
Ensure the plugin is listed in `opencode.json`:
170+
```json
171+
{
172+
"plugin": ["@scitrera/memorylayer-opencode-plugin"]
173+
}
174+
```
175+
176+
## License
177+
178+
Apache-2.0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "https://opencode.ai/config.json",
3+
"mcp": {
4+
"memorylayer": {
5+
"type": "local",
6+
"command": ["npx", "@scitrera/memorylayer-mcp-server"],
7+
"environment": {
8+
"MEMORYLAYER_URL": "{env:MEMORYLAYER_URL}",
9+
"MEMORYLAYER_API_KEY": "{env:MEMORYLAYER_API_KEY}"
10+
},
11+
"enabled": true
12+
}
13+
},
14+
"plugin": ["@scitrera/memorylayer-opencode-plugin"]
15+
}

memorylayer-opencode-plugin/package-lock.json

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "@scitrera/memorylayer-opencode-plugin",
3+
"version": "0.0.6",
4+
"description": "OpenCode plugin for MemoryLayer.ai - persistent memory hooks and context injection",
5+
"type": "module",
6+
"main": "dist/src/index.js",
7+
"types": "dist/src/index.d.ts",
8+
"scripts": {
9+
"build": "tsc",
10+
"dev": "tsc --watch",
11+
"prepublishOnly": "npm run build"
12+
},
13+
"author": "Scitrera LLC",
14+
"license": "Apache-2.0",
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/scitrera/memorylayer",
18+
"directory": "oss/memorylayer-opencode-plugin"
19+
},
20+
"homepage": "https://memorylayer.ai",
21+
"keywords": [
22+
"opencode",
23+
"memorylayer",
24+
"memory",
25+
"context",
26+
"persistence",
27+
"knowledge-graph",
28+
"recall",
29+
"agent",
30+
"llm",
31+
"ai",
32+
"mcp"
33+
],
34+
"dependencies": {
35+
"@scitrera/memorylayer-mcp-server": "file:../memorylayer-mcp-typescript"
36+
},
37+
"devDependencies": {
38+
"@types/node": "^20.0.0",
39+
"typescript": "^5.9.3"
40+
},
41+
"peerDependencies": {
42+
"@opencode-ai/plugin": ">=0.1.0"
43+
},
44+
"peerDependenciesMeta": {
45+
"@opencode-ai/plugin": {
46+
"optional": true
47+
}
48+
},
49+
"engines": {
50+
"node": ">=18.0.0"
51+
}
52+
}

0 commit comments

Comments
 (0)