Skip to content

fix(opencode): support custom data dir and DB prefix#620

Open
ozymandiashh wants to merge 1 commit into
mainfrom
fix/issue-617-opencode-data-dir
Open

fix(opencode): support custom data dir and DB prefix#620
ozymandiashh wants to merge 1 commit into
mainfrom
fix/issue-617-opencode-data-dir

Conversation

@ozymandiashh

Copy link
Copy Markdown
Collaborator

Summary

Fixes #617 by teaching the OpenCode provider how to read renamed or forked OpenCode-compatible installs without changing the default OpenCode behavior.

Root cause

The provider always derived the OpenCode data root as:

$XDG_DATA_HOME/opencode
~/.local/share/opencode

and only discovered SQLite files matching:

opencode*.db

That works for upstream OpenCode, but forks such as MiMoCode can keep the same storage schema while writing to a different data directory and DB prefix, for example:

~/.local/share/mimocode/mimicode.db

In that case CodeBurn silently reported zero OpenCode usage because neither the directory nor the DB filename matched the hard-coded defaults.

What changed

  • Added OPENCODE_DATA_DIR as an exact OpenCode-compatible data directory override.
  • Added OPENCODE_DB_PREFIX for SQLite discovery, so forks can expose files such as mimocode.db or mimocode-channel.db.
  • Kept default discovery unchanged when the new env vars are unset:
    • $XDG_DATA_HOME/opencode
    • ~/.local/share/opencode
    • opencode*.db
  • Applied the same custom data root to file-based OpenCode storage under storage/.
  • Added the new OpenCode env vars to the session cache fingerprint so changing the directory or DB prefix does not serve stale cached results.
  • Added the new vars to test env isolation.
  • Documented both vars in the provider docs and README.

Behavior

# Default upstream OpenCode behavior stays the same
codeburn report --provider opencode

# Renamed/forked install with a different root and DB prefix
OPENCODE_DATA_DIR="$HOME/.local/share/mimocode" \
OPENCODE_DB_PREFIX="mimocode" \
codeburn report --provider opencode

OPENCODE_DATA_DIR is treated as the exact data directory. CodeBurn does not append an opencode suffix to it.

OPENCODE_DB_PREFIX only affects SQLite discovery. File-based storage is still discovered from <OPENCODE_DATA_DIR>/storage/.

One edge case is handled intentionally: an empty OPENCODE_DB_PREFIX falls back to the default opencode prefix. Without that guard, an empty prefix would match every .db file in the data directory.

Compatibility and safety

  • Existing OpenCode users keep the same default discovery path and DB prefix.
  • Existing createOpenCodeProvider(tmpDir) test fixtures keep working because that explicit test seam still appends opencode.
  • OpenCode cache entries may rebuild once after upgrade because the provider env fingerprint now includes the new variables. Other providers are not affected.
  • No public API exports were added.

Testing

Passed:

./node_modules/.bin/vitest run tests/providers/opencode.test.ts tests/providers/opencode-file.test.ts
# 56 passed

./node_modules/.bin/vitest run tests/session-cache.test.ts tests/provider-registry.test.ts
# 68 passed

./node_modules/.bin/tsc --noEmit
npm run build
git diff --check

env -u PYTHONPATH -u VIRTUAL_ENV -u PYTHONHOME semgrep --config .semgrep/rules/no-bracket-assign-hot-paths.yml --strict --json src/providers/ src/parser.ts
# 0 findings

Also ran a held-out smoke test that creates both a fork-style mimocode/mimicode.db and a default opencode/opencode.db store, then verifies both discovery modes. It printed:

PASS env override smoke

Full suite note:

./node_modules/.bin/vitest run

The full suite still has unrelated failures in tests/cli-proxy-path.test.ts and tests/cli-status-menubar.test.ts. I reproduced the same failure classes on main before this change, so they are not introduced by this PR.

@ozymandiashh ozymandiashh requested a review from iamtoruk July 4, 2026 19:58
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.

OpenCode provider: add configurable data directory (for renamed/forked builds)

1 participant