@agentmemory/agentmemory 0.9.19 → 0.9.21

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.
@@ -0,0 +1,229 @@
1
+ <h1 align="center">
2
+ <img src="https://github.com/opencode-ai.png?size=80" alt="OpenCode" width="28" height="28" align="center" />
3
+ &nbsp;agentmemory for OpenCode
4
+ </h1>
5
+
6
+ <p align="center">
7
+ <strong>Your OpenCode agents remember everything. No more re-explaining.</strong><br/>
8
+ <sub>Persistent cross-session memory via <a href="https://github.com/rohitg00/agentmemory">agentmemory</a> — 95.2% retrieval accuracy on <a href="https://arxiv.org/abs/2410.10813">LongMemEval-S</a>.</sub>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <img src="https://img.shields.io/badge/MCP-53_tools-1f6feb?style=flat-square" alt="53 MCP tools" />
13
+ <img src="https://img.shields.io/badge/Plugin-22_hooks-1f6feb?style=flat-square" alt="22 hooks" />
14
+ <img src="https://img.shields.io/badge/Commands-2_slash-1f6feb?style=flat-square" alt="2 slash commands" />
15
+ <img src="https://img.shields.io/badge/R@5-95.2%25-00875f?style=flat-square" alt="95.2% R@5" />
16
+ </p>
17
+
18
+ ---
19
+
20
+ ## Quick start
21
+
22
+ ### 1. Start the agentmemory server
23
+
24
+ ```bash
25
+ npx @agentmemory/agentmemory
26
+ ```
27
+
28
+ The server starts on `http://localhost:3111`.
29
+
30
+ ### 2. Configure the MCP server
31
+
32
+ Add to `~/.config/opencode/opencode.json` or your project's `.opencode/opencode.json`:
33
+
34
+ ```json
35
+ {
36
+ "mcp": {
37
+ "agentmemory": {
38
+ "type": "local",
39
+ "command": ["npx", "-y", "@agentmemory/mcp"],
40
+ "enabled": true
41
+ }
42
+ }
43
+ }
44
+ ```
45
+
46
+ ### 3. Install the plugin
47
+
48
+ Add to `~/.config/opencode/opencode.json`:
49
+
50
+ ```json
51
+ {
52
+ "plugin": ["./plugins/agentmemory-capture.ts"]
53
+ }
54
+ ```
55
+
56
+ Copy the plugin file from this repo:
57
+
58
+ ```bash
59
+ mkdir -p ~/.config/opencode/plugins
60
+ cp plugin/opencode/agentmemory-capture.ts ~/.config/opencode/plugins/
61
+ ```
62
+
63
+ ### 4. Add the slash commands
64
+
65
+ Copy the commands into your project or global `.opencode/commands/` directory:
66
+
67
+ ```bash
68
+ mkdir -p ~/.config/opencode/commands
69
+ cp plugin/opencode/commands/recall.md ~/.config/opencode/commands/
70
+ cp plugin/opencode/commands/remember.md ~/.config/opencode/commands/
71
+ ```
72
+
73
+ Restart OpenCode or open a new session. The plugin auto-captures everything.
74
+
75
+ ## What gets captured
76
+
77
+ ### Session lifecycle
78
+
79
+ | Event | Hook | agentmemory API |
80
+ |---|---|---|
81
+ | Session start | `session.created` | POST /session/start |
82
+ | Idle → summarize | `session.idle` + `session.status` (idle) | POST /summarize |
83
+ | Status transitions | `session.status` (idle/busy/retry) | POST /observe |
84
+ | Compaction | `session.compacted` | POST /summarize + POST /observe |
85
+ | Metadata updates | `session.updated` | POST /observe |
86
+ | Code change tracking | `session.diff` | POST /observe |
87
+ | Session delete | `session.deleted` | POST /session/end |
88
+ | Session error | `session.error` | POST /observe |
89
+
90
+ ### Messages & prompts
91
+
92
+ | Event | Hook | agentmemory API |
93
+ |---|---|---|
94
+ | User prompt (rich) | `chat.message` | POST /observe |
95
+ | User prompt metadata | `message.updated` (user) | POST /observe |
96
+ | Assistant response | `message.updated` (assistant) | POST /observe |
97
+ | Message removed (undo) | `message.removed` | POST /observe |
98
+
99
+ ### Parts & steps
100
+
101
+ | Event | Hook | agentmemory API |
102
+ |---|---|---|
103
+ | Subagent start | `message.part.updated` (subtask) | POST /observe |
104
+ | Tool completed | `message.part.updated` (tool completed) | POST /observe |
105
+ | Tool error | `message.part.updated` (tool error) | POST /observe |
106
+ | Step finish (cost/tokens) | `message.part.updated` (step-finish) | POST /observe |
107
+ | Reasoning trace | `message.part.updated` (reasoning) | POST /observe |
108
+ | Patch applied | `message.part.updated` (patch) | POST /observe |
109
+ | Auto/manual compaction | `message.part.updated` (compaction) | POST /observe |
110
+ | Agent selection | `message.part.updated` (agent) | POST /observe |
111
+ | API retry | `message.part.updated` (retry) | POST /observe |
112
+
113
+ ### File enrichment pipeline
114
+
115
+ | Event | Hook | agentmemory API |
116
+ |---|---|---|
117
+ | File tool params | `tool.execute.before` → stash paths | — |
118
+ | File edited | `file.edited` → stash paths | — |
119
+ | File part attached | `message.part.updated` (file) → stash paths | — |
120
+ | Enrichment inject | `experimental.chat.system.transform` | POST /enrich → `output.system[]` |
121
+ | Memory context inject | `experimental.chat.system.transform` | POST /context → `output.system[]` |
122
+
123
+ ### Permissions
124
+
125
+ | Event | Hook | agentmemory API |
126
+ |---|---|---|
127
+ | Permission prompt | `permission.updated` | POST /observe |
128
+ | Permission reply | `permission.replied` | POST /observe |
129
+
130
+ ### Tasks & commands
131
+
132
+ | Event | Hook | agentmemory API |
133
+ |---|---|---|
134
+ | Task tracking (w/ priority) | `todo.updated` | POST /observe |
135
+ | Command executed | `command.executed` | POST /observe |
136
+
137
+ ### Model & config
138
+
139
+ | Event | Hook | agentmemory API |
140
+ |---|---|---|
141
+ | LLM parameters | `chat.params` | POST /observe |
142
+ | Config loaded | `config` | POST /observe |
143
+ | Compaction (WIP) | `experimental.session.compacting` | POST /context → `output.context[]` |
144
+
145
+ ### File enrichment + memory injection (two-layer pipeline)
146
+
147
+ `experimental.chat.system.transform` fires before every LLM call and injects two layers of context:
148
+
149
+ 1. **Memory context** (once per session): calls `/agentmemory/context` and injects project profile, recent session summaries, and important past observations into the system prompt. This is the OpenCode equivalent of Claude's MEMORY.md bridge — instead of syncing to a markdown file, context is injected directly into the system prompt.
150
+
151
+ 2. **File enrichment** (every turn with stashed files): calls `/agentmemory/enrich` with files stashed by `tool.execute.before`, `file.edited`, and `message.part.updated` (file parts). File-specific context (past observations, related bugs, semantic search) is injected into the system prompt.
152
+
153
+ ```text
154
+ System prompt = [OpenCode instructions] + [memory context] + [file enrichment] + [user message]
155
+ ^ ^
156
+ first turn only every file-touching turn
157
+ ```
158
+
159
+ **Differences from Claude's PreToolUse:**
160
+
161
+ | Dimension | Claude (PreToolUse) | OpenCode (two-hop pipeline) |
162
+ |---|---|---|
163
+ | Injection mechanism | stdout → context window | `output.system[]` → system prompt |
164
+ | Timing | Same turn (parallel with tool) | Next turn (before next LLM call) |
165
+ | File set | Per-tool (immediate) | Batched (all files since last enrichment) |
166
+ | Coverage | Edit/Write/Read/Glob/Grep only | Edit/Write/Read/Glob/Grep only |
167
+ | What gets injected | `<agentmemory-file-context>` + bug memories | Identical `/enrich` response |
168
+
169
+ ## MEMORY.md vs AGENTS.md: how context flows
170
+
171
+ Claude Code and OpenCode take fundamentally different approaches to injecting memory context into the agent's system prompt.
172
+
173
+ ### Claude Code: file-backed bridge (two-hop)
174
+
175
+ ```
176
+ agentmemory ──write──▶ MEMORY.md ──read──▶ Claude system prompt
177
+ ```
178
+
179
+ - The `claude-bridge/sync` endpoint serializes agentmemory observations into a `MEMORY.md` file in the project root
180
+ - Claude Code reads `MEMORY.md` on session start and prepends it to the system prompt
181
+ - **Sync is periodic** — sessions only get fresh context when the bridge last ran (session end, pre-compact)
182
+ - **Coupling**: memory data lives in a git-trackable file, visible to CI, team members, and other tools
183
+
184
+ ### OpenCode: direct injection (one-hop)
185
+
186
+ ```
187
+ agentmemory ──push──▶ OpenCode system prompt
188
+ ```
189
+
190
+ - `experimental.chat.system.transform` calls `/context` at runtime and pushes the response directly into `output.system[]`
191
+ - **Always current** — context is fetched at session start (once) and before file-touching turns (per-batch)
192
+ - **No file intermediary** — no stale copies, no merge conflicts, no disk I/O
193
+ - `AGENTS.md` is a static instruction file for project conventions, coding standards, and tool guidance — agentmemory does not read or write it
194
+
195
+ ### Tradeoffs
196
+
197
+ | Dimension | Claude (MEMORY.md bridge) | OpenCode (direct injection) |
198
+ |---|---|---|
199
+ | Freshness | Stale between syncs | Always current (fetched at call time) |
200
+ | Visibility | Human-readable file in repo | In-memory injection only |
201
+ | Simplicity | Two moving parts (bridge + file) | One step (API → system prompt) |
202
+ | Team sharing | File is git-trackable, CI-friendly | Memory shared via agentmemory server API |
203
+ | Integration | Any tool can read MEMORY.md | Requires OpenCode plugin SDK |
204
+
205
+ ### Why OpenCode goes direct
206
+
207
+ agentmemory already persists everything in SQLite (`data/state_store.db`). Adding an intermediate MEMORY.md file would duplicate data, introduce sync lag, and require the model to re-parse structured context from markdown. Direct injection delivers the same data with lower latency and zero staleness — the agent always sees what agentmemory knows right now.
208
+
209
+ ## Slash commands
210
+
211
+ - `/recall <query>` — Search past observations and lessons
212
+ - `/remember <text>` — Save an insight to long-term memory
213
+
214
+ ## Session instruction injection
215
+
216
+ Agentmemory usage instructions are injected into the system prompt on the first turn of every session via `experimental.chat.system.transform` (alongside memory context from `/context`). This is functionally equivalent to Claude Code's skills mechanism — the agent learns which `agentmemory_memory_*` tools to use and when, without needing separate skill invocations.
217
+
218
+ ## What's not covered (vs Claude Code plugin)
219
+
220
+ | Claude feature | Reason |
221
+ |---|---|
222
+ | SubagentStop | OpenCode's `SubtaskPart` type has no completion/result fields; subtask lifecycle ends are not exposed as distinct events in the OpenCode SDK |
223
+ | TaskCompleted | No team/teammate concept in OpenCode; `todo.updated` captures task state changes as a partial equivalent |
224
+ | Stop | `session.compacted` event handler exists; `experimental.session.compacting` injection hook defined in SDK but Go binary (v1.14.41) doesn't wire it — will auto-activate when upstream implements it |
225
+ | Skills (remember/recall/forget/session-history) | Covered by injected system instructions via `experimental.chat.system.transform` — agent receives usage guidance on first turn |
226
+ | Consolidation pipeline (crystals/auto + consolidate-pipeline) | Now called on `session.deleted` — mirrors Claude's `CONSOLIDATION_ENABLED=true` behavior |
227
+ | Claude MEMORY.md bridge | OpenCode-specific; OpenCode uses its own AGENTS.md mechanism, not Claude's MEMORY.md |
228
+
229
+ All other Claude Code hooks have direct or pipeline equivalents in this plugin. 12 of 12 Claude hook types covered.