headroom/docs
Rod Boev f74d874777
fix(learn): detect the active OpenCode database (#2587)
## Description

`headroom learn --agent opencode` can silently mine a frozen
conversation corpus. `OpenCodePlugin` hardcodes
`~/.local/share/opencode/opencode.db`, but source-built OpenCode writes
`opencode-local.db` in the same directory. When both files exist, learn
still succeeds against the stale packaged DB and ignores the live
source-built corpus.

This follows the report in
https://github.com/headroomlabs-ai/headroom/issues/2581 and builds on
the existing OpenCode learn path introduced in
https://github.com/headroomlabs-ai/headroom/pull/559.

This change keeps explicit constructor paths authoritative, honors
`HEADROOM_OPENCODE_DB` when it is set, and otherwise selects the newest
existing database between `opencode.db` and `opencode-local.db`,
preferring canonical `opencode.db` on exact ties. It also updates the
OpenCode learn docs line so the documented behavior matches the landed
resolver. Closes #2581.

The branch also carries one narrow CI repair requested during review:
`headroom/cli/wrap.py` now binds the `unwrap claude` Click command back
to `unwrap_claude` instead of the leak-warning helper, which restores
the existing unwrap test surface and leaves the helper as an internal
warning function.

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)

## Changes Made

- add a private OpenCode DB resolver in
`headroom/learn/plugins/opencode.py` with precedence `db_path` then
`HEADROOM_OPENCODE_DB` then newest existing default filename then
canonical fallback
- preserve canonical `opencode.db` for exact mtime ties and for
canonical-only installs
- add focused regression coverage for newer-local, explicit-path,
canonical-only, equal-tie, missing-override, and end-to-end scanning
cases
- sync the OpenCode learn docs paragraph so it no longer claims
`opencode.db` is the only supported default path
- restore the `unwrap claude` Click command binding in
`headroom/cli/wrap.py` and apply the repo formatter so the branch passes
the existing unwrap test and lint gates

## Testing

- [x] Unit tests pass (`uv run pytest
tests/test_learn/test_opencode_scanner.py -q`)
- [x] Linting passes (`uv run ruff check
headroom/learn/plugins/opencode.py
tests/test_learn/test_opencode_scanner.py`)
- [x] Type checking passes (`uv run mypy
headroom/learn/plugins/opencode.py`)
- [x] New tests added for new functionality when applicable
- [x] Manual testing performed

### Test Output

```text
uv run pytest tests/test_learn/test_opencode_scanner.py -q -k "newer_local_database"
1 passed, 9 deselected in 0.26s

uv run pytest tests/test_learn/test_opencode_scanner.py -q
10 passed in 0.50s

uv run ruff check headroom/learn/plugins/opencode.py tests/test_learn/test_opencode_scanner.py
All checks passed!

uv run ruff format headroom/learn/plugins/opencode.py tests/test_learn/test_opencode_scanner.py --check
2 files already formatted

uv run mypy headroom/learn/plugins/opencode.py
Success: no issues found in 1 source file

rg -n "opencode-local\.db|HEADROOM_OPENCODE_DB|opencode\.db" docs/content/docs/opencode.mdx
78:`headroom learn` supports OpenCode as a scan target. It reads past sessions from the newer of `~/.local/share/opencode/opencode-local.db` and `~/.local/share/opencode/opencode.db`, or from `HEADROOM_OPENCODE_DB` when you set an explicit override, and writes corrections to your project's `AGENTS.md`.

uv run pytest tests/test_cli/test_unwrap_claude.py -q -k "removes_mcp_rtk_and_stops_proxy or preserves_user_managed_serena or removes_headroom_installed_serena or keep_flags_skip_cleanup or restores_all_base_url_modes or stops_claude_owned_persistent_deployment or reports_ambiguous_same_port_persistent_deployment or warns_about_same_port_inherited_env or ignores_malformed_inherited_env_port"
9 passed, 5 deselected in 0.40s

uv run ruff check .
All checks passed!

uv run ruff format --check .
1340 files already formatted
```

## Real Behavior Proof

- Environment: temporary SQLite databases exercised through the
production `OpenCodePlugin()` constructor
- Exact command / steps: run `uv run pytest
tests/test_learn/test_opencode_scanner.py -q -k "newer_local_database"`
against `origin/main` with the new regression test overlaid, then run
the same command and the full `uv run pytest
tests/test_learn/test_opencode_scanner.py -q` suite on the branch head
- Observed result: the base reproduction fails with `AssertionError:
assert 'Canonical' == 'Local'`, proving current main still selects the
stale canonical DB; the branch head passes the reproduction row and the
full 10-test scanner suite
- Not tested: live user OpenCode corpus

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] I have updated the CHANGELOG.md if applicable

## Additional Notes

- `CHANGELOG.md` stays untouched because Headroom generates release
notes from conventional commits.
- The automatic chooser is intentionally limited to the two known
default filenames, `opencode.db` and `opencode-local.db`. Other layouts
can use `HEADROOM_OPENCODE_DB`.
- The fix stays inside `headroom/learn/plugins/opencode.py`; no
provider-neutral learn or pipeline code changes are planned.
2026-07-26 19:50:59 -07:00
..
app docs: improve discoverability for AI agents and search crawlers 2026-05-13 17:36:06 -07:00
components docs: sync Vercel docs with current code and add in-depth proxy config (#2475) 2026-07-21 16:26:56 -07:00
content/docs fix(learn): detect the active OpenCode database (#2587) 2026-07-26 19:50:59 -07:00
lib docs: sync Vercel docs with current code and add in-depth proxy config (#2475) 2026-07-21 16:26:56 -07:00
overrides fix: repair release and docs pipelines 2026-04-16 12:53:51 -05:00
screenshots Merge pull request #147 from JerrettDavis/feat/anthropic-usage-insights 2026-04-12 10:54:22 -07:00
.gitignore new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
bun.lock fix(deps): remediate dependency CVEs and publish SBOM (#1509) 2026-06-27 15:28:12 -07:00
claude-code-bedrock-headroom.md fix(bedrock): route ARNs via converse, named AWS profiles, and au. re… (#1456) 2026-07-02 22:51:05 -05:00
next.config.mjs new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
observability.md fix(observability): G3 remediation — bound cardinality + wire dead metrics 2026-05-24 10:41:56 -07:00
package-lock.json deps: bump the npm-minor-patch group across 3 directories with 7 updates (#2276) 2026-07-21 11:21:14 -05:00
package.json deps: bump the npm-minor-patch group across 3 directories with 7 updates (#2276) 2026-07-21 11:21:14 -05:00
platform-feature-matrix.json fix: harden persistent install startup (#1851) 2026-07-10 00:40:34 -04:00
platform-stabilization.md fix: harden persistent install startup (#1851) 2026-07-10 00:40:34 -04:00
postcss.config.mjs new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
proxy.ts new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
README.md new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
rtk-architecture.md fix(observability): wire Phase G PR-G3 RTK + proxy metrics (H-blocker) 2026-05-22 13:18:42 -07:00
source.config.ts docs(ci): add CI/CD flow diagrams (#1062) 2026-06-16 23:05:15 -07:00
tsconfig.json new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
vercel.json fix: add Vercel deploy config and workflow for docs site (#1739) 2026-07-14 13:25:18 -04:00

docs

This is a Next.js application generated with Create Fumadocs.

Run development server:

npm run dev
# or
pnpm dev
# or
yarn dev

Open http://localhost:3000 with your browser to see the result.

Explore

In the project, you can see:

  • lib/source.ts: Code for content source adapter, loader() provides the interface to access your content.
  • lib/layout.shared.tsx: Shared options for layouts, optional but preferred to keep.
Route Description
app/(home) The route group for your landing page and other pages.
app/docs The documentation layout and pages.
app/api/search/route.ts The Route Handler for search.

Fumadocs MDX

A source.config.ts config file has been included, you can customise different options like frontmatter schema.

Read the Introduction for further details.

Learn More

To learn more about Next.js and Fumadocs, take a look at the following resources: