feat: add OpenCode auto-plugin for zero-config MemPalace integration - #297
feat: add OpenCode auto-plugin for zero-config MemPalace integration#297Milofax wants to merge 4 commits into
Conversation
Adds an OpenCode plugin that automatically initializes MemPalace and
injects the Memory Protocol into every agent session. No per-project
config needed — drop the plugin file into ~/.config/opencode/plugins/
and every git-tracked project gets MemPalace automatically.
Plugin hooks:
- event: runs 'mempalace init --yes' + 'mempalace mine' on first
session event (background, detached, idempotent)
- experimental.chat.system.transform: injects the MemPalace Memory
Protocol into the system prompt so agents know when/how to save
Includes setup guide matching the existing integration doc style
(cf. gemini_cli_setup.md, mcp_setup.md).
PR Review: feat: add OpenCode auto-plugin for zero-config MemPalace integrationExecutive Summary
Affected Areas: Business Impact: Lowers barrier to MemPalace adoption for OpenCode users; wrong tool names will cause failed tool calls and erode agent trust in the protocol. Flow Changes: No changes to existing code — both files are net-new additions under Ratings
PR Health
High Priority Issues🐛 #1: Protocol advertises 19 tools — 5 don't exist in the MCP serverLocation: The hardcoded Ghost tools (not registered in MCP server):
Actual 14 tools: - ### Available Tools (19 total)
- - Palace read: `mempalace_status`, `mempalace_search`, `mempalace_list_wings`, `mempalace_list_rooms`, `mempalace_get_taxonomy`, `mempalace_check_duplicate`, `mempalace_get_aaak_spec`
- - Palace write: `mempalace_add_drawer`, `mempalace_delete_drawer`
- - Knowledge Graph: `mempalace_kg_query`, `mempalace_kg_add`, `mempalace_kg_invalidate`, `mempalace_kg_timeline`, `mempalace_kg_stats`
- - Navigation: `mempalace_traverse`, `mempalace_find_tunnels`, `mempalace_graph_stats`
- - Diary: `mempalace_diary_write`, `mempalace_diary_read`
+ ### Available Tools (14 total)
+ - Palace read: `mempalace_status`, `mempalace_browse`, `mempalace_search`
+ - Palace write: `mempalace_add_drawer`, `mempalace_delete_drawer`
+ - Knowledge Graph: `mempalace_kg_query`, `mempalace_kg_add`, `mempalace_kg_invalidate`, `mempalace_kg_timeline`, `mempalace_kg_stats`
+ - Navigation: `mempalace_traverse`, `mempalace_find_tunnels`
+ - Diary: `mempalace_diary_write`, `mempalace_diary_read`Medium Priority Issues🐛 #2: File descriptor leak in
|
Close parent file descriptors after spawning detached mempalace
processes to avoid leaking FDs across projects.
Track in-flight initialization separately from completed projects so
failed init runs can retry on later events without spawning duplicate
concurrent init processes.
Also fix the setup guide's stale timestamp and replace the invalid
verification command with
=======================================================
MemPalace Status — 10000 drawers
=======================================================
WING: captains_deck
ROOM: general 6352 drawers
ROOM: backend 1082 drawers
ROOM: frontend 1069 drawers
ROOM: testing 537 drawers
ROOM: configuration 513 drawers
ROOM: scripts 301 drawers
ROOM: design 101 drawers
ROOM: documentation 45 drawers
=======================================================.
Retryable init failures in the OpenCode auto-plugin could leave a project stuck in the initializing set if the child errors before exit, preventing later events from re-running mempalace init. Finalize initialization on error, exit, or close and keep the docs aligned with the per-project process semantics.
|
Addressed the reliability issue. Fix
Verification
Thanks — this one was real. |
|
Correcting my previous comment — the shell ate some backticked text. Addressed the reliability issue. Fix
Verification
Thanks — this one was real. |
A project was previously marked initialized immediately after mempalace init succeeded, even if the background mine step failed. That could leave the repo permanently unmined for the rest of the opencode process. Track mine-in-flight state separately and only mark the project initialized after mempalace mine exits successfully. Failed mine runs now clear the in-flight state so later events retry automatically. Also correct the setup guide's security notes to mention the git root probe and that the plugin log captures mempalace stdout/stderr.
First-party OpenCode plugin for MemPalace lifetime memory system. Integrates into OpenCode's lifecycle via three hooks: - experimental.session.compacting: Pre-compaction memory rescue - experimental.chat.system.transform: L0/L1 wake-up injection - chat.message: Message-count-triggered background mining Key advantages over existing PR MemPalace#297 (opencode_auto_plugin.js): - Modular TypeScript architecture (not a single-file script) - Pre-Compact rescue hook (not just system.transform) - Structured L0/L1 memory injection (not hardcoded protocol string) - Message-count threshold trigger for auto-save (not per-chat injection) - Debounced mining with lock to prevent concurrent saves - Idle/crash auto-save via session.idle and process signal handlers Closes MemPalace#342
First-party OpenCode plugin for MemPalace lifetime memory system. Integrates into OpenCode's lifecycle via three hooks: - experimental.session.compacting: Pre-compaction memory rescue - experimental.chat.system.transform: L0/L1 wake-up injection - chat.message: Message-count-triggered background mining Key advantages over existing PR MemPalace#297 (opencode_auto_plugin.js): - Modular TypeScript architecture (not a single-file script) - Pre-Compact rescue hook (not just system.transform) - Structured L0/L1 memory injection (not hardcoded protocol string) - Message-count threshold trigger for auto-save (not per-chat injection) - Debounced mining with lock to prevent concurrent saves - Idle/crash auto-save via session.idle and process signal handlers Closes MemPalace#342
web3guru888
left a comment
There was a problem hiding this comment.
Well-structured plugin — the auto-init + auto-mine on first event per project is a clever pattern, and the system prompt injection via experimental.chat.system.transform keeps it non-invasive.
Good design decisions:
- Per-process dedup via in-memory Set prevents redundant init/mine
- Skipping non-git directories is the right default
- Detached spawns keep the plugin non-blocking
- Log file at
/tmp/mempalace-auto.loghelps debugging
The protocol injection string is comprehensive (all 19 tools listed) — might be worth noting that tool availability depends on the MCP server being configured separately, so agents don't hallucinate tool calls that aren't actually wired up.
Nice addition to the examples.
🔭 Reviewed as part of the MemPalace-AGI integration project — autonomous research with perfect memory. Community interaction updates are posted regularly on the dashboard.
First-party OpenCode plugin for MemPalace lifetime memory system. Integrates into OpenCode's lifecycle via three hooks: - experimental.session.compacting: Pre-compaction memory rescue - experimental.chat.system.transform: L0/L1 wake-up injection - chat.message: Message-count-triggered background mining Key advantages over existing PR MemPalace#297 (opencode_auto_plugin.js): - Modular TypeScript architecture (not a single-file script) - Pre-Compact rescue hook (not just system.transform) - Structured L0/L1 memory injection (not hardcoded protocol string) - Message-count threshold trigger for auto-save (not per-chat injection) - Debounced mining with lock to prevent concurrent saves - Idle/crash auto-save via session.idle and process signal handlers Closes MemPalace#342
First-party OpenCode plugin for MemPalace lifetime memory system. Integrates into OpenCode's lifecycle via three hooks: - experimental.session.compacting: Pre-compaction memory rescue - experimental.chat.system.transform: L0/L1 wake-up injection - chat.message: Message-count-triggered background mining Key advantages over existing PR MemPalace#297 (opencode_auto_plugin.js): - Modular TypeScript architecture (not a single-file script) - Pre-Compact rescue hook (not just system.transform) - Structured L0/L1 memory injection (not hardcoded protocol string) - Message-count threshold trigger for auto-save (not per-chat injection) - Debounced mining with lock to prevent concurrent saves - Idle/crash auto-save via session.idle and process signal handlers Closes MemPalace#342
…alace#297) ChromaDB 1.0.8 running at chroma.theshellnet.com (LAN-only via allow-home@file middleware, TLS via Traefik + Let's Encrypt). Token stored in Vault at mempalace/chroma#token (resolved at deploy time, never in compose file or git history). Key lessons from deploy: - Must join traefik-network (external) for Traefik to reach container — without it, stack gets 502 Bad Gateway - container_name: explicit (required for Traefik backend URL resolution) - ChromaDB 1.x uses /api/v2/ not /api/v1/ — healthcheck updated accordingly - No ${VAR:-} syntax, no build:, minimal compose = no Portainer parser issues Verified: GET /api/v2/heartbeat → 200 {"nanosecond heartbeat": ...} GET /api/v2/.../collections → 200 [] Usage: MEMPALACE_CHROMA_URL=http://chroma.theshellnet.com (or direct LAN IP) MEMPALACE_CHROMA_TOKEN=dd2ce14310fea886854ab4174eeafcc5ad15c958 python3 -m mempalace status Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
examples/opencode_auto_plugin.js— a drop-in OpenCode plugin that auto-initializes MemPalace in every git-tracked projectexamples/opencode_auto_plugin_setup.md— full setup guide matching the existing docs style (cf.gemini_cli_setup.md,mcp_setup.md)What the Plugin Does
mempalace init --yes <root>in backgroundmempalace mine --limit 200 <root>in backgroundexperimental.chat.system.transformZero per-project config needed. Drop the file into
~/.config/opencode/plugins/and restart OpenCode.Key Design Decisions
~,/tmp, etc.mempalace initruns at most once per project per process/tmp/mempalace-auto.logComplementary to PR #268
PR #268 adds the manual
opencode_setup.mdintegration guide. This plugin automates what that guide describes — users install it once and MemPalace works in every project automatically.Verification
node --check examples/opencode_auto_plugin.js✅