Skip to content

Commit 59465de

Browse files
Add CLI export/import and bundled agents to memory plugin
1 parent 60d999f commit 59465de

6 files changed

Lines changed: 1312 additions & 2 deletions

File tree

packages/memory/CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.0.6] - 2026-02-24
9+
10+
### Added
11+
12+
- Core memory tools: `memory-read`, `memory-write`, `memory-edit`, `memory-delete`, `memory-health`
13+
- Planning state tools: `memory-planning-update` and `memory-planning-get` for tracking session objectives, phases, findings, and errors
14+
- `memory-plan-execute` tool for creating new Code sessions with approved implementation plans
15+
- Three embedding providers: local (`all-MiniLM-L6-v2`), OpenAI (`text-embedding-3-small/large`, `ada-002`), and Voyage (`voyage-code-3`, `voyage-2`)
16+
- Bundled Code agent (`ocm-code`) with memory-aware coding workflows
17+
- Bundled Architect agent (`ocm-architect`) for read-only planning with automatic plan handoff
18+
- Bundled Memory agent (`ocm-memory`) for expert knowledge curation and post-compaction extraction
19+
- Compaction context injection with custom prompt, planning state, conventions, and decisions
20+
- Configurable compaction settings: custom prompt, inline planning, token budget, snapshot storage
21+
- CLI export/import for backing up and migrating memories as JSON or Markdown
22+
- Embedding cache with SHA-256 keying and 24-hour TTL
23+
- Embedding sync service with batch processing and retry logic
24+
- Session state KV store with TTL management (7-day planning, 24-hour snapshots)
25+
- Automatic deduplication via exact match and semantic similarity detection
26+
- Dimension mismatch detection on startup with guided recovery via reindex
27+
- Build-time version injection displayed in `memory-health` output
28+
- Automatic model download via `postinstall` script
29+
- Auto-copy of bundled config on first run
30+
- SQLite storage with `sqlite-vec` for vector similarity search

packages/memory/README.md

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ Memory management plugin for OpenCode that enables semantic search and persisten
66

77
- **Semantic Memory Search** - Store and retrieve project memories using vector embeddings
88
- **Multiple Memory Scopes** - Categorize memories as convention, decision, or context
9-
- **Automatic Deduplication** - Prevents duplicate memories from being stored
10-
- **Session Context** - Tracks session state and injects relevant memories during compaction
9+
- **Automatic Deduplication** - Prevents duplicates via exact match and semantic similarity detection
10+
- **Compaction Context Injection** - Injects planning state, conventions, and decisions into session compaction for seamless continuity
11+
- **Bundled Agents** - Ships with Code, Architect, and Memory agents preconfigured for memory-aware workflows
12+
- **CLI Export/Import** - Export and import memories as JSON or Markdown for backup and migration
13+
- **Dimension Mismatch Detection** - Detects embedding model changes and guides recovery via reindex
14+
- **Session Planning** - Tracks objectives, phases, findings, and errors across sessions with automatic TTL cleanup
1115

1216
## Tools
1317

@@ -20,9 +24,76 @@ Memory management plugin for OpenCode that enables semantic search and persisten
2024
| `memory-health` | Health check or full reindex of the memory store |
2125
| `memory-planning-update` | Update session planning state (phases, objectives, progress) |
2226
| `memory-planning-get` | Get the current planning state for a session |
27+
| `memory-plan-execute` | Create a new Code session and send an approved plan as the first prompt |
2328

2429
Planning state differs from memories: it stores temporary session data (objectives, phase progress, findings, errors) with a 7-day TTL, while memories are persisted indefinitely and retrieved via semantic search.
2530

31+
## Agents
32+
33+
The plugin bundles three agents that integrate with the memory system:
34+
35+
| Agent | ID | Mode | Description |
36+
|-------|----|------|-------------|
37+
| **Code** | `ocm-code` | primary | Primary coding agent with memory awareness. Checks memory before unfamiliar code, stores architectural decisions and conventions as it works. |
38+
| **Architect** | `ocm-architect` | primary | Read-only planning agent. Researches the codebase, checks memory for conventions and decisions, designs implementation plans, then hands off to Code via `memory-plan-execute`. |
39+
| **Memory** | `ocm-memory` | subagent | Expert agent for storing, retrieving, and curating project knowledge. Handles post-compaction memory extraction and contradiction resolution. |
40+
41+
The Architect agent operates in read-only mode (`temperature: 0.0`, all edits denied). After the user approves a plan, it calls `memory-plan-execute` to create a new Code session with the full plan as context.
42+
43+
## CLI
44+
45+
Export and import memories using the bundled CLI tool. The CLI auto-detects the project ID from git and resolves the database path automatically.
46+
47+
### Export
48+
49+
```bash
50+
# Export all memories as JSON (stdout)
51+
bun run src/cli/export.ts export
52+
53+
# Export as Markdown to file
54+
bun run src/cli/export.ts export --format markdown --output memories.md
55+
56+
# Export with project and scope filter
57+
bun run src/cli/export.ts export --project my-project --scope convention
58+
59+
# Limit and paginate results
60+
bun run src/cli/export.ts export --limit 50 --offset 100
61+
```
62+
63+
**Export options:**
64+
65+
| Flag | Description |
66+
|------|-------------|
67+
| `--format, -f` | Output format: `json` or `markdown` (default: `json`) |
68+
| `--output, -o` | Output file path (prints to stdout if omitted) |
69+
| `--project, -p` | Project ID filter (auto-detected from git) |
70+
| `--scope, -s` | Filter by scope: `convention`, `decision`, or `context` |
71+
| `--limit, -l` | Max number of memories (default: `1000`) |
72+
| `--offset` | Pagination offset (default: `0`) |
73+
| `--db-path` | Custom database file path |
74+
75+
### Import
76+
77+
```bash
78+
# Import from JSON
79+
bun run src/cli/export.ts import memories.json --project my-project
80+
81+
# Import from Markdown (format auto-detected from extension)
82+
bun run src/cli/export.ts import memories.md --project my-project
83+
84+
# Skip duplicate detection
85+
bun run src/cli/export.ts import memories.json --project my-project --force
86+
```
87+
88+
**Import options:**
89+
90+
| Flag | Description |
91+
|------|-------------|
92+
| `--format, -f` | Input format: `json` or `markdown` (auto-detected from extension) |
93+
| `--project, -p` | Project ID to assign memories to (auto-detected from git) |
94+
| `--force` | Skip duplicate detection and import all |
95+
| `--db-path` | Custom database file path |
96+
2697
## Installation
2798

2899
Install the package from npm:
@@ -63,6 +134,12 @@ You can edit this file to customize settings. The file is created only if it doe
63134
"logging": {
64135
"enabled": false,
65136
"file": "~/.local/share/opencode/memory/logs/memory.log"
137+
},
138+
"compaction": {
139+
"customPrompt": true,
140+
"inlinePlanning": true,
141+
"maxContextTokens": 4000,
142+
"snapshotToKV": true
66143
}
67144
}
68145
```
@@ -101,6 +178,12 @@ For API-based embeddings:
101178

102179
When enabled, logs are written to the specified file with timestamps. The log file has a 10MB size limit with automatic rotation.
103180

181+
#### Compaction
182+
- `compaction.customPrompt` - Use a custom compaction prompt optimized for session continuity (default: `true`)
183+
- `compaction.inlinePlanning` - Inject planning state (phases, objectives, progress) into compaction context (default: `true`)
184+
- `compaction.maxContextTokens` - Token budget for injected memory context with priority-based trimming (default: `4000`)
185+
- `compaction.snapshotToKV` - Store compaction snapshots in the session KV store for recovery (default: `true`)
186+
104187
## Development
105188

106189
```bash

packages/memory/src/agents/code.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export const codeAgent: AgentDefinition = {
66
displayName: 'Code',
77
description: 'Primary coding agent with awareness of project memory and conventions',
88
mode: 'primary',
9+
tools: {
10+
exclude: ['memory-plan-execute'],
11+
},
912
systemPrompt: `You are a coding agent with access to a persistent memory system that stores project conventions, architectural decisions, and contextual knowledge across sessions.
1013
1114
## Memory Integration

packages/memory/src/agents/memory.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export const memoryAgent: AgentDefinition = {
66
displayName: 'Memory',
77
description: 'Expert agent for managing project memory - storing and retrieving conventions, decisions, and context',
88
mode: 'subagent',
9+
tools: {
10+
exclude: ['memory-plan-execute'],
11+
},
912
systemPrompt: `You are the project's institutional memory. Your purpose is to capture, organize, and retrieve knowledge that persists across sessions.
1013
1114
## Your Role

0 commit comments

Comments
 (0)