Skip to content

feat(store): hierarchical database path resolution with per-project support#257

Open
Acharnite wants to merge 3 commits into
rtk-ai:mainfrom
Acharnite:feat/hierarchical-db-path
Open

feat(store): hierarchical database path resolution with per-project support#257
Acharnite wants to merge 3 commits into
rtk-ai:mainfrom
Acharnite:feat/hierarchical-db-path

Conversation

@Acharnite
Copy link
Copy Markdown

Summary

Replace the simple --db-or-default path logic with a 6-level hierarchical database path resolution chain. This eliminates the need for wrapper scripts or hardcoded paths when working across multiple projects.

Resolution chain (highest priority first)

Level Source Example
1 --db CLI flag icm --db /tmp/test.db store ...
2 ICM_DB env var ICM_DB=/tmp/icm.db icm recall ...
3 Global config [store].path ~/.config/icm/config.toml
4 Project-local .icm/config.toml [store].path Git root auto-detection
5 Project-local .icm/memories.db Auto-detected at git root (if file exists)
6 Platform default data directory ~/.local/share/icm/memories.db

Key changes

crates/icm-cli/src/main.rs (+165/−19):

  • New resolve_db_path(cli_db, cfg) → PathBuf with the 6-level chain
  • New detect_project_root() → Option<PathBuf> using git rev-parse --show-toplevel
  • icm init --per-project now creates .icm/config.toml with [store] path = "memories.db"
  • icm config shows the full resolution chain with source tracing (resolved path, config path, env var, project root, .icm/ state)
  • open_store() simplified from open_store(db: Option<PathBuf>) to open_store(db: PathBuf) — resolution happens before the store is opened

config/default.toml (+11):

  • Documents the full 6-level resolution order in the config header
  • Explains icm init --per-project creates project-local config

OpenCode plugin improvements (plugins/opencode-icm.ts, +17/−10)

  • Added NOISE_TOOLS set to skip extraction for Edit/Write/Question/todowrite calls (reduces noise)
  • Increased EXTRACT_EVERY from 3 to 10 (reduces extraction frequency)
  • Added cwd parameter to all ICM subprocess calls so the plugin respects per-project databases
  • Fixed recall-project to use named flags (--project, --limit) instead of positional args

Documentation

  • docs/architecture.md: New Database Path Resolution section with the full algorithm, priority flow diagram, and icm config output example
  • docs/guide.md: Per-project setup instructions and resolution priority table
  • README.md: Already updated with --per-project setup, ICM_DB env var mention, and per-project storage section

Backward compatibility

Fully backward compatible. The existing --db flag still works at the same priority. The default platform path (level 6) is unchanged. Existing setups see no behavioral difference.

Closes the gap where users had to set --db on every invocation or write wrapper scripts to use per-project databases.

Acharnite added 3 commits May 26, 2026 16:40
Add 6-level database path resolution chain that eliminates the need for
wrapper scripts or hardcoded paths:

1. --db CLI flag (highest priority)
2. ICM_DB environment variable (new)
3. Global config [store].path (was parsed but unused — now wired up)
4. Project-local .icm/config.toml [store].path (auto-detected via git root)
5. Project-local .icm/memories.db (auto-detected via git root, if file exists)
6. Default platform data directory (unchanged fallback)

Also adds:
- detect_project_root() helper using git rev-parse --show-toplevel
- icm init --per-project now creates .icm/config.toml with project-local DB
- icm config shows full resolution chain with source tracing
- Updated config/default.toml to document resolution order
Change icm init --per-project to write [store] path = ".icm/memories.db"
instead of "memories.db", so the database lives inside .icm/ alongside
config.toml. Update README with --per-project docs.
Add comprehensive docs for the 6-level database path resolution chain:
- resolve_db_path() algorithm and priority flow
- detect_project_root() and git-aware auto-detection
- Per-project .icm/ setup
- icm config display with source tracing

Also update the user guide with per-project setup instructions
and add noise-tool filtering to the opencode plugin.
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.

1 participant