fix(opencode): fix memory-inject race condition, empty-memory ban, add turn limit
Three critical fixes to the iai-mcp-memory-inject.js plugin:
- Race condition: inflight is now a Map<sessionID, Promise> so concurrent
callers (warm-on-create event + first transform hook) await the same
fetch instead of getting empty string. First turn now gets memory.
- Empty-memory ban: fetchMemory returns {ok, text} tuple. HTTP 200 with
empty body is memoized as valid (new user, minimal mode). Only actual
network errors count against the retry budget.
- Turn-limited injection: new INJECT_MAX_TURNS (default 3) stops injecting
after N turns. Memory was already in system prompt; the model has seen
it. Controls per-turn token cost that was 50x the old approach.
Also: README now documents memory-inject.js (not session-init), and
session-init.js is marked @deprecated.
This commit is contained in:
parent
4f6b91aef8
commit
7559bac57f
3 changed files with 69 additions and 24 deletions
12
README.md
12
README.md
|
|
@ -142,13 +142,13 @@ mkdir -p ~/.config/opencode/plugins
|
|||
cp deploy/opencode/iai-mcp-capture.js ~/.config/opencode/plugins/
|
||||
```
|
||||
|
||||
**Session-init plugin** — automatically loads session background memory on every new session. The model calls `memory_session_context` before responding, so it has your identity, topic cluster, and rich club context from turn one.
|
||||
**Memory-inject plugin** — automatically loads session background memory on every new session via the daemon's HTTP adapter. Memory is injected into the model's system prompt (clean, no phantom messages, preserves session title).
|
||||
|
||||
```bash
|
||||
cp deploy/opencode/iai-mcp-session-init.js ~/.config/opencode/plugins/
|
||||
cp deploy/opencode/iai-mcp-memory-inject.js ~/.config/opencode/plugins/
|
||||
```
|
||||
|
||||
Note: a brief "INIT" message will appear in chat on the first turn. This is the mechanism that delivers the system instruction to the model.
|
||||
This plugin requires the daemon's HTTP listener. Set `IAI_DAEMON_HTTP_PORT=0` in your daemon's systemd/launchd config and restart it. The daemon writes the live port to `~/.iai-mcp/.http.port`, which the plugin reads automatically.
|
||||
|
||||
Make sure `@opencode-ai/plugin` is installed:
|
||||
|
||||
|
|
@ -163,7 +163,7 @@ Register both plugins in `~/.config/opencode/config.json`:
|
|||
{
|
||||
"plugin": [
|
||||
"~/.config/opencode/plugins/iai-mcp-capture.js",
|
||||
"~/.config/opencode/plugins/iai-mcp-session-init.js"
|
||||
"~/.config/opencode/plugins/iai-mcp-memory-inject.js"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
|
@ -176,7 +176,7 @@ Add the MCP server and plugins to `~/.config/opencode/config.json`:
|
|||
{
|
||||
"plugin": [
|
||||
"~/.config/opencode/plugins/iai-mcp-capture.js",
|
||||
"~/.config/opencode/plugins/iai-mcp-session-init.js"
|
||||
"~/.config/opencode/plugins/iai-mcp-memory-inject.js"
|
||||
],
|
||||
"mcp": {
|
||||
"iai-mcp": {
|
||||
|
|
@ -385,7 +385,7 @@ Limitations worth knowing about:
|
|||
|
||||
Claude Code is the primary host, validated in daily use.
|
||||
|
||||
OpenCode is supported via the `iai-mcp-capture.js` and `iai-mcp-session-init.js` plugins (see Install the OpenCode plugins above) and MCP server config in `~/.config/opencode/config.json`.
|
||||
OpenCode is supported via the `iai-mcp-capture.js` and `iai-mcp-memory-inject.js` plugins (see Install the OpenCode plugins above) and MCP server config in `~/.config/opencode/config.json`. The memory-inject plugin requires the daemon's HTTP listener (`IAI_DAEMON_HTTP_PORT` env var).
|
||||
|
||||
Claude Desktop should work (uses `claude_desktop_config.json` instead of `~/.claude.json`) but hasn't been tested end to end.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue