Skip to content

feat(opencode): allow AGENTMEMORY_PROJECT_NAME to override project name - #1125

Merged
rohitg00 merged 2 commits into
rohitg00:mainfrom
aqeelat:feat/opencode-project-name-env
Aug 2, 2026
Merged

feat(opencode): allow AGENTMEMORY_PROJECT_NAME to override project name#1125
rohitg00 merged 2 commits into
rohitg00:mainfrom
aqeelat:feat/opencode-project-name-env

Conversation

@aqeelat

@aqeelat aqeelat commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

What it does

The OpenCode capture plugin now consults AGENTMEMORY_PROJECT_NAME before falling back to its existing resolution (ctx.worktree || ctx.project?.id || process.cwd()). When the env var is set to a non-empty value, that value is used as the project on every observe/session-start call; otherwise behavior is unchanged.

Why

  1. No override existed. The OpenCode plugin resolved the project from the OpenCode context only — a user couldn't pin a stable project name (across machines, monorepo subdirs, or containerized setups where cwd differs).

  2. Cross-client consistency. The Claude hooks already resolve the project via AGENTMEMORY_PROJECT_NAME → git toplevel basename → cwd basename (src/hooks/_project.ts). The OpenCode plugin was the only client that ignored this env var and sent a full filesystem path as the project. Since the daemon filters memory strictly by the project string (s.project === projectName), an OpenCode session (/Users/.../myrepo) and a Claude session (myrepo) on the same repo never shared memory. Setting AGENTMEMORY_PROJECT_NAME=myrepo on both now aligns them.

Same env var name the hooks use — one knob across both plugin ecosystems, no new variable to learn.

How to verify

  • npm test — 1432 passing, 1 skipped.
  • Structural assertion in test/opencode-auto-context.test.ts confirms the plugin source checks AGENTMEMORY_PROJECT_NAME and that it precedes the ctx.worktree fallback.
  • Manual: set AGENTMEMORY_PROJECT_NAME=test-proj, run a session, confirm /session/start and /observe calls carry project: "test-proj". Unset it and confirm the previous behavior (ctx/cwd path) resumes.

Scope

One-line behavior change in plugin/opencode/agentmemory-capture.ts. No daemon changes — the server already stores/filters by whatever project string it receives. Reuses the existing AGENTMEMORY_PROJECT_NAME the hooks already document; no new env var introduced.

Summary by CodeRabbit

  • New Features

    • Added support for overriding the project name using the AGENTMEMORY_PROJECT_NAME environment variable, including trimming surrounding whitespace.
    • Preserved existing project-name detection as the fallback when the variable is unset or blank.
  • Tests

    • Added coverage for environment-based project name selection and fallback precedence across available project context.

@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

@aqeelat is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: dcd91e17-d0dc-4330-aba7-52863a312e9d

📥 Commits

Reviewing files that changed from the base of the PR and between 27b78ed and 7e39b74.

📒 Files selected for processing (2)
  • plugin/opencode/agentmemory-capture.ts
  • test/opencode-auto-context.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/opencode-auto-context.test.ts
  • plugin/opencode/agentmemory-capture.ts

📝 Walkthrough

Walkthrough

The OpenCode capture plugin uses a trimmed AGENTMEMORY_PROJECT_NAME value before its existing fallback chain. Tests verify the environment-variable override and fallback precedence.

Changes

OpenCode project name selection

Layer / File(s) Summary
Project name override and validation
plugin/opencode/agentmemory-capture.ts, test/opencode-auto-context.test.ts
projectPath prioritizes the trimmed AGENTMEMORY_PROJECT_NAME value while preserving the worktree, project ID, and current-directory fallbacks. Tests verify each precedence path.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: allowing AGENTMEMORY_PROJECT_NAME to override the OpenCode project name.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
test/opencode-auto-context.test.ts (1)

38-51: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Test the runtime behavior instead of matching source text.

This assertion can pass even when .trim() or the actual project-selection behavior is broken. Exercise the plugin with a whitespace-padded environment value and verify the /session/start payload, then cover the documented fallback cases.

🤖 Prompt for 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.

In `@test/opencode-auto-context.test.ts` around lines 38 - 51, Replace the
source-text assertions in the “OpenCode plugin project name override” test with
runtime tests that execute the plugin using a whitespace-padded
AGENTMEMORY_PROJECT_NAME and verify the /session/start payload contains the
correctly selected project name. Add coverage for the documented fallback order
through ctx.worktree, ctx.project?.id, and process.cwd() when the environment
value is absent or unusable.
🤖 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.

Nitpick comments:
In `@test/opencode-auto-context.test.ts`:
- Around line 38-51: Replace the source-text assertions in the “OpenCode plugin
project name override” test with runtime tests that execute the plugin using a
whitespace-padded AGENTMEMORY_PROJECT_NAME and verify the /session/start payload
contains the correctly selected project name. Add coverage for the documented
fallback order through ctx.worktree, ctx.project?.id, and process.cwd() when the
environment value is absent or unusable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ed5a3425-0287-49bf-9081-9f31fec90311

📥 Commits

Reviewing files that changed from the base of the PR and between 8c90741 and f6a018f.

📒 Files selected for processing (2)
  • plugin/opencode/agentmemory-capture.ts
  • test/opencode-auto-context.test.ts

aqeelat added 2 commits August 2, 2026 17:13
The OpenCode capture plugin resolved the project as ctx.worktree ||
ctx.project?.id || process.cwd() (a full path) with no way to override
it. It now consults AGENTMEMORY_PROJECT_NAME first — the same env var the
Claude hooks use in resolveProject() — falling back to the existing
resolution when unset.

This lets users pin a stable project name and aligns the two plugin
ecosystems so OpenCode and Claude sessions can share memory when the env
var is set to the same value.

Signed-off-by: Abdullah Alaqeel <abdullah.t.aqeel@gmail.com>
…ame tests

Execute the plugin end-to-end, fire a session.created event, and assert
the /session/start payload's project field. Covers whitespace trimming
of AGENTMEMORY_PROJECT_NAME and the documented fallback chain
(ctx.worktree -> ctx.project.id -> process.cwd).

Signed-off-by: Abdullah Alaqeel <abdullah.t.aqeel@gmail.com>
@aqeelat
aqeelat force-pushed the feat/opencode-project-name-env branch from 27b78ed to 7e39b74 Compare August 2, 2026 14:13
@rohitg00

rohitg00 commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Verified against main and this is correct: the hooks resolve project via AGENTMEMORY_PROJECT_NAME in src/hooks/_project.ts, and the OpenCode plugin never reads it, so the override silently does nothing there. The runtime tests asserting the actual /session/start payload are the right shape too. This is good to go as-is.

While confirming it I swept every other capture surface, and the same problem exists in four more places. Since you clearly get this bug class, would you want to take the rest as a follow-up PR? @aqeelat

  • integrations/hermes/__init__.py:191 sends raw cwd as both project and cwd (this is open issue Hermes Agent Python plugin sends raw cwd path as project, not git basename (PR #687 gap) #1135)
  • integrations/pi/index.ts:123 and :235 send raw process.cwd() as project
  • integrations/filesystem-watcher/watcher.mjs:322 reads AGENTMEMORY_PROJECT, a divergent env name; it should accept AGENTMEMORY_PROJECT_NAME with the old name kept as an alias
  • src/replay/jsonl-parser.ts:27 deriveProject takes the last path segment instead of the git-toplevel basename, and its split("/") means a Windows cwd becomes the whole raw path

The target semantics are exactly what resolveProject() in src/hooks/_project.ts does: env override, then git toplevel basename, then cwd basename. OpenCode itself is excluded from that list because #1122 covers its canonicalization; if you pick this up it would be worth coordinating there on the env name so we do not end up with three variants.

@rohitg00
rohitg00 merged commit 9be3d27 into rohitg00:main Aug 2, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants