Guidance for agents working on opencode-codex-memory.
A TypeScript port of codex's memory system, packaged as a standalone opencode
plugin. Read ARCHITECTURE.md before changing memory behavior — it explains the
design and the load-bearing workarounds (D1–D6).
This plugin mirrors codex's Rust memory implementation. Alignment is tracked, not assumed:
codex-map.yaml— provenance map: each source file → its codex origin, plus the codex commit last audited (codex_ref).scripts/check-codex-drift.sh— reports moved/renamed upstream files and any changes to codex memory code sincecodex_ref.
Before changing anything in the memory pipeline:
- Find the upstream source for the file in
codex-map.yaml. - Run
CODEX_REPO=/path/to/codex ./scripts/check-codex-drift.sh. - If it reports drift, read the upstream diff and either port it intentionally or
record a deliberate divergence in that mapping's
note:. - Bump
codex_ref/codex_ref_dateonce re-audited.
Do not put alignment status in prose (it rots). Facts live in codex-map.yaml;
this file only points at the procedure.
Memory is global. Project/cwd separation exists only as a soft routing hint
inside src/templates/consolidation.md and the read-path prompt, mirroring codex.
Do not add schema-level, read-path, or job-level project partitioning unless codex
does it first. If you believe scoping is needed, confirm codex's current behavior
via the drift script before proposing structural changes.
./gradlewis not used here. Dev commands:bun install,bun test,bun run typecheck,bun run build,bun run smoke,bun run contract. Live host checks (need.envwithOPENCODE_LIVE_API_KEY/OPENCODE_LIVE_BASE_URL/OPENCODE_LIVE_MODEL, XDG-sandboxed; never copy host OpenCode credentials):bun run live:read,bun run live:e2e.- Store/DB tests use a temp root via
OPENCODE_CODEX_MEMORY_TEST_ROOT. - Templates in
src/templates/*.mdare ported from codex with deliberate platform adaptations (citation tags, memory-tool guidance, session metadata, placeholder inventory). Never byte-copy them from codex. Before syncing a template, read its mappingnote:incodex-map.yamland re-apply the listed adaptations;tests/prompts.test.tsfails on contract breaks. - Every agent shipped in
opencode.jsonmust use an allowlist:"*": "deny"first, followed only by the built-in opencode file tools it requires. Never allow shell, network, task delegation, IDE, or MCP tools; that is the sandbox (D2), andtests/agents.test.tsenforces it. - opencode2 support lives in
src/v2/and reuses the V1 pipeline via a V1-client shim (src/v2/shim.ts). User-facing controls:docs/usage.md#memory-panel. Rules: never edit V1 behavior for V2 needs (adapt insrc/v2/);opencode.jsonstays the V1agentbundle (same D2 allowlist; V2 agents are provisioned at runtime; V2 action names:editcovers write/patch;tests/v2-agents.test.tsenforces it);bun run contract:v2must pass alongsidebun run contract. The package./tuiexport issrc/tui.ts(OpenCode 1.18.29+ requiresdefault.tui()and must not import the V2 TUI SDK). The sidebar itself issrc/v2/tui.tsx(RPC insrc/v2/status-rpc.ts), lazy-loaded from that wrapper'ssetup():setup()must only claim slots (Solid-scoped APIs likekeymap.layerbelong in slot components), the TUI bundle may import only@opencode/plugin/tui+solid-js+@opentui/solid, andbun run buildcompiles the JSX viascripts/build-tui.ts.
- Runtime assets must ship inside
dist/:bun run buildcompiles and copiessrc/templates/andopencode.jsonthere. Anything the plugin reads viaimport.meta.dirnameat runtime has to exist underdist/in the published package —bun run smokeloads the built entry the way opencode does and runs automatically at prepack, gatingnpm pack/npm publish. - npm versions are immutable: fix a broken release by bumping the patch version, never by re-publishing.
- opencode installs npm plugins once into
~/.cache/opencode/packages/<spec>/and never re-resolves whilenode_modules/exists there; delete those dirs to pick up a new release. To test the packed artifact without publishing:npm pack, install the tarball into a scratch dir, and point a test config'spluginat the installed directory (file://...) — or install it into the cache dir and use the bare npm spec.
- Do not add
Co-Authored-Bytrailers. Keep messages concise and factual. - Only commit/push when explicitly asked.