feat: add memory.disable_global config option to skip global memory scope#7
Draft
Edison-A-N wants to merge 1 commit intojoshuadavidthomas:mainfrom
Draft
feat: add memory.disable_global config option to skip global memory scope#7Edison-A-N wants to merge 1 commit intojoshuadavidthomas:mainfrom
memory.disable_global config option to skip global memory scope#7Edison-A-N wants to merge 1 commit intojoshuadavidthomas:mainfrom
Conversation
…cope Add a new config option `memory.disable_global` (boolean) in agent-memory.json that, when set to true: - Skips seeding global memory blocks (human.md, persona.md) - Filters global scope from listBlocks() results - Guards getBlock/setBlock/replaceInBlock against global scope - Removes 'global' from tool schema enums so the LLM agent cannot select it This enables headless/daemon agent deployments where global memory (shared across all sessions/projects) is undesirable and only project-scoped memory should be active.
Owner
|
🎉 Thanks for the contribution! It's been a bit since I initially wrote this so my motivation is a bit fuzzy, but it was probably a mix of copying how I'm on my phone at the moment, but a quick glance at the patch it looks good. I'll leave a proper review later when I can get in front of my laptop. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new configuration option
memory.disable_global(boolean) that allows users to opt out of the global memory scope entirely. When enabled, only project-scoped memory blocks are active.Motivation
I'm running OpenCode agents as headless background daemons (not interactive TUI sessions). In this setup, each agent instance operates in its own isolated working directory and should only maintain project-scoped memory. The global memory scope (
~/.config/opencode/memory/) becomes problematic because:human.md/persona.mdis undesirable — each agent has a distinct role and context.What Changed
4 source files, +71 / -16 lines — minimal and surgical.
src/journal.ts— ExtendedConfigSchemawithmemory.disable_globalboolean option.src/memory.ts—createMemoryStore()now accepts an optionalMemoryStoreOptionsparameter:ensureSeed()skips global seed blockslistBlocks("all")excludes global scope (so system prompt injection only contains project blocks)getBlock()/setBlock()/replaceInBlock()guard against global scope accesssrc/plugin.ts— Readsconfig.memory?.disable_global, passes{ disableGlobal }to store and tool factories.src/tools.ts— Tool schemaenumvalues dynamically exclude"global"when disabled, so the LLM agent cannot even attempt to select it.Configuration
In
~/.config/opencode/agent-memory.json:{ "memory": { "disable_global": true } }Default is
false— fully backward compatible, no behavior change unless explicitly opted in.Questions for Maintainer
I'd really appreciate your guidance on a few points:
Is this the right approach? I went with a config-based opt-out rather than, say, removing global scope by directory detection or an environment variable. Would you prefer a different mechanism?
Naming: I used
memory.disable_global— would you prefer something likememory.global_enabled: false(inverted) ormemory.scopes: ["project"](allowlist)?Tool schema filtering: I chose to dynamically remove
"global"from the tool enum values so the LLM can't even see the option. An alternative would be to keep the enum but return an error message. Which feels more aligned with your design intent?Is this something you'd want upstream? If this doesn't fit the project's direction, that's totally fine — I'm happy to maintain it as a fork. But if it does, I'd love to clean this up to your standards.
Thanks for building this plugin — it's been really useful for our daemon agent setup! Looking forward to your thoughts.