fix(plugin): add session instruction injection and consolidation pipeline (closes #233)#239
fix(plugin): add session instruction injection and consolidation pipeline (closes #233)#239cl0ckt0wer wants to merge 4 commits into
Conversation
- 22 hook handlers across session lifecycle, messages, tool lifecycle, parts, files, permissions, tasks, commands, and config - Two-layer enrichment pipeline: /context + /enrich via system.transform - Two slash commands: /recall and /remember - Full Claude Code hook parity documented with gap analysis
mem::observe checks hookType === "prompt_submit" to extract raw.userPrompt and set session.firstPrompt. The plugin was using "user_prompt_submit" which didn't match, so sessions were never named.
…line (closes rohitg00#233) Three gaps from the Claude Code plugin port sweep: - Inject agentmemory usage instructions (memory_save, memory_recall, etc.) into the system prompt on first turn via experimental.chat.system.transform, replacing the skills mechanism that OpenCode lacks - Call /crystals/auto and /consolidate-pipeline on session.deleted, mirroring Claude's CONSOLIDATION_ENABLED behavior - Document MEMORY.md vs AGENTS.md architecture comparison (two-hop file bridge vs one-hop direct injection) Gap A (SubagentStop) is unfixable — OpenCode's SubtaskPart type has no completion/result fields. Gap C (Claude MEMORY.md bridge) is intentionally skipped — OpenCode uses direct injection.
|
@cl0ckt0wer is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an OpenCode plugin (agentmemory-capture), manifest, command docs (/recall, /remember), README/ROADMAP updates, and a capture implementation that posts observations to agentmemory and injects session/file context via /context and /enrich during system transform and compaction. ChangesOpenCode Plugin for Agentmemory
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@plugin/opencode/agentmemory-capture.ts`:
- Around line 48-54: The global session state (stashedFiles, seenSubtaskIds,
seenToolCallIds, plus activeSessionId/projectPath) risks cross-session leakage;
convert these process-level Sets into session-keyed maps (e.g., Map<string,
Set<string>> keyed by sessionId) and update all accesses in this file to
read/write via the current sessionId (replace direct uses of stashedFiles,
seenSubtaskIds, seenToolCallIds with sessionScoped getters/creators and
clearers). Ensure you update all affected locations (the reads/writes/clears
referenced around lines ~371-375, ~413-418, ~521-525, ~529-557 and the
enrichment logic at line ~545) to use the session-scoped collections, and add
cleanup logic on session.deleted to remove the session key and free its Sets;
also ensure any uses of activeSessionId/projectPath are session-scoped or passed
explicitly to avoid relying on process-global state.
- Around line 19-30: The postJson function currently returns res.json() without
awaiting it, which lets JSON parse rejections escape the try/catch; update
postJson (the async function postJson) to await the JSON parsing result (i.e.,
await res.json()) so any parsing errors are caught by the existing try/catch and
the function returns null on failure, ensuring callers (those awaiting postJson)
do not receive unhandled rejections.
In `@plugin/opencode/commands/recall.md`:
- Around line 5-7: The usage code fence in the markdown snippet for the recall
command lacks a language tag; update the fenced code block that contains
"/recall [query]" in recall.md to use a language tag (e.g., add ```text at the
opening fence) so the block becomes a labeled text code fence and satisfies
markdownlint MD040.
In `@plugin/opencode/commands/remember.md`:
- Around line 5-7: The Markdown usage code fence for the /remember command is
missing a language tag; update the fenced block that contains "/remember [what
to remember]" to use a language tag (e.g., text) so the block becomes ```text
... ```, which will satisfy markdownlint MD040 and keep the docs lint-clean.
In `@plugin/opencode/README.md`:
- Around line 153-157: The three fenced code blocks containing the examples
starting with "System prompt = [OpenCode instructions]..." and the two diagram
blocks beginning "agentmemory ──write──▶ MEMORY.md..." and "agentmemory
──push──▶ OpenCode system prompt" are missing language identifiers; add a
language tag (e.g., ```text) to each opening fence so the blocks become ```text
... ``` to satisfy the MD040 lint rule and reduce markdown-lint noise.
- Around line 216-217: Update the session-instruction docs to use the correct
tool prefix: replace the incorrect `agentmemory_memory_*` with `agentmemory_*`
in the sentence that describes injection via
`experimental.chat.system.transform` (the system prompt /context memory
description), ensuring the text now reads that the agent learns which
`agentmemory_*` tools to use and when.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 237f5710-67f7-432c-a8c9-30ed80b77135
📒 Files selected for processing (7)
README.mdROADMAP.mdplugin/opencode/README.mdplugin/opencode/agentmemory-capture.tsplugin/opencode/commands/recall.mdplugin/opencode/commands/remember.mdplugin/opencode/plugin.json
…res.json(), markdown lint
|
Fixed all 6 CodeRabbit review findings:
|
|
Thanks @cl0ckt0wer — the three gaps you identified (session-instruction injection via Coordination — see also #237. Both PRs touch the exact same files ( I've asked over on #237 to either fold these gap-fixes into that PR (preferred — single OpenCode plugin PR), or land #237 first and rebase this one to be a clean diff of just the three gap fixes. Either way the underlying work lands with full attribution to you. Holding both for now until the consolidation strategy is clear. Once that's done I'll review the merged version straight through — the per-gap reasoning is well documented in the body, so once the diff isolates just those gaps it'll be a fast review. Also: I noticed the plugin badge here says "44 MCP tools" but in #237 it says "51". The current |
|
Folded into #237 per Option A. The three gap fixes are now on
Cherry-picked the unique commit onto #237's branch and resolved conflicts. Ready for consolidated review on #237. |
Summary
Three gaps from the clco→oco port sweep:
Session instruction injection — Injects agentmemory usage instructions (covering
memory_save,memory_recall,memory_smart_search,memory_file_history,memory_lesson_save/recall, etc.) into the system prompt on the first turn of every session viaexperimental.chat.system.transform. Replaces the Claude Code skills mechanism (SKILL.mdfiles) which OpenCode has no equivalent for.Consolidation pipeline on session end — Calls
/crystals/autoand/consolidate-pipelineonsession.deleted, mirroring Claude'sCONSOLIDATION_ENABLED=truebehavior. Both are best-effort with 5s timeout.MEMORY.md vs AGENTS.md docs — Detailed architecture comparison in README explaining the two-hop (agentmemory → MEMORY.md → system prompt) vs one-hop (agentmemory → system prompt) approaches.
Cannot fix
SubtaskParttype has no completion/result fieldsFiles changed
plugin/opencode/agentmemory-capture.ts— +43 lines (instruction block + consolidation calls)plugin/opencode/README.md— +49 lines (architecture comparison + updated gap table)Summary by CodeRabbit
New Features
/recallcommand to retrieve grouped session insights and lessons/remembercommand to persist insights for future recallDocumentation