Guidance for agents working in this repository.
An OpenCode V2 plugin (memory.ts) that keeps project memory, a session
checkpoint, and scratch notes; injects a budgeted slice on the first prompt of a
session; and writes a checkpoint on compaction. No build step, no dependencies,
AGPL-3.0-only.
bun test
cp memory.ts ~/.config/opencode/plugins/memory.ts
touch ~/.config/opencode/plugins/memory.tsCheck the server log when something is off:
grep memory ~/.local/share/opencode/log/opencode.log | tail- Do not import
@opencode/plugin. Export a plain{ id, setup }object. - Keep the plugin dependency-free. Use Bun globals for file access.
- Plugin
consoleoutput is not visible to users. Throwing from a tool surfaces the message to the session. - Memory files live under the OpenCode data directory, keyed by project id.
MEMORY_ROOToverrides the parent,MEMORY_BUDGETsets the character budget, and tests rely onMEMORY_ROOT. - Never overwrite a file silently on a read error.
ctx.location.project.idgives the project key.ctx.location.directoryis the session directory.ctx.session.hook("prompt", cb)can rewriteevent.prompt.text. Inject at most once per session, tracked inctx.storageundermemory/injected/<id>.ctx.session.hook("compaction", cb)receivesevent.messagesandevent.model, and can setevent.result = { summary }.ctx.generate.text({ model, prompt })makes a transient model call for the checkpoint.
files- the three memory file names.memoryDir,readFileOr,writeFile- path and IO helpers.buildInjection,searchLines- pure helpers, exported for tests.setup- registers tools, commands, and the two hooks.memory.test.ts- tests for the helpers and the registration.
- Semantic commit messages. Changes through a feature branch and a PR.
- Keep
NOTICEaccurate.