agentmemory icon indicating copy to clipboard operation
agentmemory copied to clipboard

OpenCode plugin sends incorrect project/cwd — does not use resolveProject() logic from PR #687

Open sad-apple opened this issue 5 months ago • 1 comments

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:

  1. project being set to / (or workspace root) instead of the repo basename
  2. cwd being identical to project instead of the actual working directory
  3. Cross-project memory pollution because all sessions share the same project value
  4. Context injection (/context) failing to retrieve relevant memories because project does 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

  1. Install agentmemory OpenCode plugin (plugin/opencode/agentmemory-capture.ts)
  2. Open a project directory (e.g., a Git repo named my-project)
  3. Start an OpenCode session in that directory
  4. Perform some actions (file reads, tool uses) to generate observations
  5. Check the recorded sessions via API or MCP:
    curl -s http://localhost:3111/agentmemory/sessions
    
  6. Observe that project is / (or some top-level path) instead of my-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:

  1. Uses ctx.worktree instead of ctx.directory: ctx.worktree in OpenCode represents the project boundary / sandbox root, which is / for non-Git projects or when workspace root is set to /. The actual working directory is ctx.directory.
  2. No resolveProject() call: PR #687 introduced src/hooks/_project.ts with resolveProject(cwd) to normalize the project name (env → git basename → cwd basename). The OpenCode plugin never calls this function.
  3. project and cwd are identical: The plugin sets both fields to the same projectPath value, 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 — The resolveProject() 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

sad-apple avatar Jun 11 '26 10:06 sad-apple

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.

woshilaohei avatar Jun 14 '26 22:06 woshilaohei