Skip to content

feat: add search learnings MCP tool#126

Open
yyiilluu wants to merge 2 commits into
mainfrom
feat/search-learnings-mcp
Open

feat: add search learnings MCP tool#126
yyiilluu wants to merge 2 commits into
mainfrom
feat/search-learnings-mcp

Conversation

@yyiilluu

@yyiilluu yyiilluu commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace implicit PreToolUse-driven search with a model-callable search_learnings MCP tool.
  • Make the tool usable from both Claude Code and Codex by installing MCP manifests, launcher scripts, and host guidance into the plugin bundle.
  • Harden installation so same-version local reinstalls refresh prepared host caches and Claude Code gets a durable user-scope MCP registration.
  • Require explicit absolute cwd for learning search so results are scoped to the project the model is answering for.

Changes

  • Adds search_learnings MCP server plumbing, learned-state search adapter, and MCP manifests for Claude Code/Codex.
  • Removes the old PreToolUse query-composition path and updates hook behavior/docs around explicit model tool calls.
  • Updates installer/package logic for Claude Code cache refresh, Codex cache contents, MCP launcher fallback, and install logging.
  • Adds focused tests for MCP search behavior, explicit cwd validation, package contents, cache refresh, durable registration, and launcher fallback.

Test Plan

  • node --check bin/claude-smart.js
  • bash -n plugin/scripts/mcp-server.sh
  • git diff --check origin/main...HEAD
  • uv run --project plugin pytest tests/test_install_scripts.py -q -k 'npm_pack_ignore_scripts_includes_learnings_mcp_files or node_install_refreshes_claude_cache_and_registers_learnings_mcp or node_update_retries_install_after_uninstall or mcp_server_redirects_unprepared_root_to_prepared_cache'
  • uv run --project plugin pytest tests/test_mcp_server.py tests/test_learnings_search.py -q
  • npm pack --ignore-scripts --dry-run --json and verified MCP files are included while generated coverage artifacts are excluded.
  • Locally packed, installed, and updated claude-smart for Claude Code and Codex; verified direct MCP tools/list/tools/call from global, Claude cache, and Codex cache roots with an explicit absolute cwd.
  • Ran host-level Claude Code and Codex E2E prompts proving the model discovered search_learnings, called it, and received relevant learning content.

Summary by CodeRabbit

  • New Features
    • Added a read-only “search learnings” capability for Claude Code and Codex via an MCP tool to surface relevant project knowledge mid-task.
    • Updated installers to register/remove the learnings MCP tool automatically and ship the required MCP components in packaged builds.
  • Bug Fixes
    • Updated hook behavior to remove the previous pre-tool injection path and align retrieval with user-prompt handling.
    • Improved learnings search robustness and messaging (absolute-path cwd validation, clearer empty/error vs unavailable handling).

Follow-ups

  • Hardened native Windows MCP startup: prepared Claude Code/Codex cache MCP configs now use the installer-resolved Git Bash executable instead of plain bash, skip System32/WSL bash stubs, preserve that executable through launcher re-exec, and read ~/.reflexio/plugin-root.txt as a fallback when symlink/junction metadata is unavailable.
  • Added focused coverage for Windows Git Bash selection, patched cache MCP configs, and plugin-root.txt launcher fallback.
  • Merge order unchanged: merge claude-smart first, then re-pin the enterprise submodule pointer to the merged claude-smart main commit before merging enterprise.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a search_learnings MCP tool, removes the PreToolUse hook path, and updates manifests, installer behavior, documentation, and tests to use the new learnings flow.

Changes

Learnings MCP Feature

Layer / File(s) Summary
Manifests and docs
ARCHITECTURE.md, package.json, plugin/.claude-plugin/plugin.json, plugin/.codex-plugin/plugin.json, plugin/.mcp.json, plugin/hooks/hooks.json, plugin/README.md, plugin/skills/claude-smart/SKILL.md, plugin/src/README.md
Updates hook descriptions, MCP manifest wiring, packaging exclusions, and user-facing docs for the learnings tool and the reduced hook set.
MCP server and search path
plugin/src/claude_smart/context_format.py, plugin/src/claude_smart/learnings_search.py, plugin/src/claude_smart/mcp_server.py, plugin/src/claude_smart/reflexio_adapter.py, plugin/pyproject.toml
Adds the learnings search function, plain markdown rendering, MCP server entry point, adapter read-error tracking, and the MCP dependency required by the server code.
PreToolUse removal
plugin/src/claude_smart/events/pre_tool.py, plugin/src/claude_smart/hook.py, plugin/src/claude_smart/context_inject.py, plugin/src/claude_smart/cs_cite.py, plugin/src/claude_smart/events/user_prompt.py, plugin/src/claude_smart/query_compose.py
Removes the pre-tool handler and query composition module, unregisters the event route, and updates related docstrings to refer to UserPromptSubmit only.
Installer and MCP cache wiring
bin/claude-smart.js, plugin/scripts/_lib.sh, plugin/scripts/mcp-server.sh
Adds install logging, versioned Claude Code cache handling, learnings MCP registration/removal, MCP launcher fallback logic, and updated bash re-exec behavior.
Test coverage
tests/test_codex_support.py, tests/test_events.py, tests/test_learnings_search.py, tests/test_mcp_server.py, tests/test_install_scripts.py, tests/test_query_compose.py
Adds and updates tests for the new learnings tool, MCP wiring, installer behavior, packaging contents, and session_end handling while removing obsolete pre-tool and query composition tests.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • ReflexioAI/claude-smart#18: Both PRs modify the pre-tool hook path in plugin/src/claude_smart/events/pre_tool.py and related dispatch behavior.
  • ReflexioAI/claude-smart#46: Both PRs touch plugin/src/claude_smart/reflexio_adapter.py, including read-error handling paths.
  • ReflexioAI/claude-smart#71: Both PRs update the plugin/src/README.md code map to reflect hook and module layout changes.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.58% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the primary change: adding the search_learnings MCP tool.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/search-learnings-mcp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
plugin/scripts/mcp-server.sh (1)

17-29: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Unquoted command substitution in for loop risks word-splitting on spaced $HOME.

Line 19 uses unquoted $(ls -dt ...) inside the for loop. If $HOME contains spaces, each path segment would be iterated separately, breaking the fallback search. This is a pre-existing pattern from _lib.sh, so the risk is low and consistent with the codebase, but quoting the expansion (e.g., via mapfile/read -ra) would make it robust.

The shellcheck SC2093 warning on line 27 (exec inside a loop) is a false positive — the exec is an intentional process replacement for the redirect, not a loop continuation concern.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugin/scripts/mcp-server.sh` around lines 17 - 29, The fallback search in
mcp-server.sh is vulnerable to word-splitting because the candidate list in the
for loop is built from an unquoted command substitution, so paths with spaces in
$HOME can break the scan. Update the loop setup around current_real,
candidate_real, and claude_smart_plugin_python to iterate over a safely parsed
list of candidate paths (for example by reading the ls output into an array
before looping) while keeping the existing redirect logic and exec-based handoff
unchanged.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@plugin/scripts/mcp-server.sh`:
- Around line 17-29: The fallback search in mcp-server.sh is vulnerable to
word-splitting because the candidate list in the for loop is built from an
unquoted command substitution, so paths with spaces in $HOME can break the scan.
Update the loop setup around current_real, candidate_real, and
claude_smart_plugin_python to iterate over a safely parsed list of candidate
paths (for example by reading the ls output into an array before looping) while
keeping the existing redirect logic and exec-based handoff unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 85830657-869e-4520-b2d4-8cc4af0a1104

📥 Commits

Reviewing files that changed from the base of the PR and between eddd100 and bfc5ade.

⛔ Files ignored due to path filters (1)
  • plugin/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (29)
  • ARCHITECTURE.md
  • bin/claude-smart.js
  • package.json
  • plugin/.claude-plugin/plugin.json
  • plugin/.codex-plugin/plugin.json
  • plugin/.mcp.json
  • plugin/README.md
  • plugin/hooks/codex-mcp.json
  • plugin/hooks/hooks.json
  • plugin/pyproject.toml
  • plugin/scripts/mcp-server.sh
  • plugin/skills/claude-smart/SKILL.md
  • plugin/src/README.md
  • plugin/src/claude_smart/context_format.py
  • plugin/src/claude_smart/context_inject.py
  • plugin/src/claude_smart/cs_cite.py
  • plugin/src/claude_smart/events/pre_tool.py
  • plugin/src/claude_smart/events/user_prompt.py
  • plugin/src/claude_smart/hook.py
  • plugin/src/claude_smart/learnings_search.py
  • plugin/src/claude_smart/mcp_server.py
  • plugin/src/claude_smart/query_compose.py
  • plugin/src/claude_smart/reflexio_adapter.py
  • tests/test_codex_support.py
  • tests/test_events.py
  • tests/test_install_scripts.py
  • tests/test_learnings_search.py
  • tests/test_mcp_server.py
  • tests/test_query_compose.py
💤 Files with no reviewable changes (6)
  • plugin/src/claude_smart/events/pre_tool.py
  • tests/test_query_compose.py
  • plugin/hooks/hooks.json
  • plugin/src/claude_smart/hook.py
  • plugin/src/claude_smart/query_compose.py
  • tests/test_events.py

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