OpenCode plugin sends incorrect project/cwd — does not use resolveProject() logic from PR #687
Description
The OpenCode plugin (plugin/opencode/agentmemory-capture.ts) sends incorrect values for the project and cwd fields to the agentmemory backend. It uses ctx.worktree directly as the project, which results in:
projectbeing set to/(or workspace root) instead of the repo basenamecwdbeing identical toprojectinstead of the actual working directory- Cross-project memory pollution because all sessions share the same
projectvalue - Context injection (
/context) failing to retrieve relevant memories becauseprojectdoes not match the repo basename used by other tools
This was already fixed for Claude Code / Codex hooks in PR #687, but the OpenCode TypeScript plugin was not included in that fix.
Steps to Reproduce
- Install agentmemory OpenCode plugin (
plugin/opencode/agentmemory-capture.ts) - Open a project directory (e.g., a Git repo named
my-project) - Start an OpenCode session in that directory
- Perform some actions (file reads, tool uses) to generate observations
- Check the recorded sessions via API or MCP:
curl -s http://localhost:3111/agentmemory/sessions - Observe that
projectis/(or some top-level path) instead ofmy-project
Expected vs Actual Behavior
| Field | Expected (per PR #687) | Actual (OpenCode plugin) |
|---|---|---|
project |
Repo basename (e.g., my-project) |
ctx.worktree (e.g., /) |
cwd |
Actual working directory path | Same as project (/) |
Root Cause
In plugin/opencode/agentmemory-capture.ts, line ~166:
projectPath = ctx.worktree || ctx.project?.id || process.cwd();
This has two problems:
- Uses
ctx.worktreeinstead ofctx.directory:ctx.worktreein OpenCode represents the project boundary / sandbox root, which is/for non-Git projects or when workspace root is set to/. The actual working directory isctx.directory. - No
resolveProject()call: PR #687 introducedsrc/hooks/_project.tswithresolveProject(cwd)to normalize the project name (env → git basename → cwd basename). The OpenCode plugin never calls this function. projectandcwdare identical: The plugin sets both fields to the sameprojectPathvalue, but agentmemory expects them to be semantically different (project= basename,cwd= full path).
References
- PR #687 —
fix(hooks): send repo basename as project, not full path(fixed this for 9 Claude/Codex hooks, but not OpenCode plugin) - Issue #474 — Original report about project/cwd mismatch causing context filtering failure
src/hooks/_project.ts— TheresolveProject()function that should be reused
Environment
- agentmemory version: 0.9.27
- OpenCode plugin:
plugin/opencode/agentmemory-capture.ts(latest main) - Integration: OpenCode via
experimental.chat.system.transform
The resolveProject() logic gap means memory is stored under wrong project - data integrity issue.nnIf project isolation matters to you, MindCore Memory MCP does session/project isolation properly: https://github.com/woshilaohei/mindcore-memory-mcpnn- session_id is validated and scoped (no cross-session leaks)n- project param respected in all store/recall operationsn- Optional encryption per sessionnnpip install mindcore-memory - no Docker, no Qdrant, no API keys. 132/132 tests, MIT licensed.