feat: current_context MCP tool — lightweight session awareness#7
feat: current_context MCP tool — lightweight session awareness#7
Conversation
Adds brainlayer_current_context — a fast, no-embedding tool that returns recent sessions, active projects, branches, files, and active plan. Designed for voice assistants and quick context injection at conversation start. - CurrentContext dataclass with format() method in engine.py - current_context() queries session_context + file interactions - 12th MCP tool, read-only annotations - 5 unit tests, tool count tests updated to 12 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. 📜 Recent review detailsConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughA new Changes
Sequence Diagram(s)sequenceDiagram
participant Client as MCP Client
participant MCP as brainlayer.mcp
participant Engine as brainlayer.engine
participant Store as VectorStore
Client->>MCP: call_tool("brainlayer_current_context", hours=24)
MCP->>Engine: current_context(store, hours=24)
Engine->>Store: sessions(store, days=...)
Store-->>Engine: [SessionInfo, ...]
Engine->>Store: file_interactions(past 24 hours)
Store-->>Engine: [FileInteraction, ...]
Engine->>Engine: aggregate projects, branches, plan
Engine->>Engine: format() -> markdown string
Engine-->>MCP: CurrentContext
MCP-->>Client: [TextContent with formatted context]
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| result = CurrentContext() | ||
|
|
||
| # Get recent sessions | ||
| recent = sessions(store, days=max(1, hours // 24) or 1, limit=10) |
There was a problem hiding this comment.
Floor division truncates hours-to-days conversion
Medium Severity
The hours // 24 floor division truncates partial days, causing the sessions query window to be narrower than intended. For example, hours=25 yields days=1 (24 hours), so sessions between 24–25 hours ago are missed, even though the file_interactions query on line 472 correctly uses timedelta(hours=25). The fix would be ceiling division (e.g., (hours + 23) // 24) to ensure the sessions window fully covers the requested hours range. Also, or 1 is redundant since max(1, ...) already guarantees a value ≥ 1.
| """, | ||
| (date_from,), | ||
| ) | ||
| ) |
There was a problem hiding this comment.
DISTINCT query with ORDER BY non-selected column
Medium Severity
The query uses SELECT DISTINCT file_path ... ORDER BY timestamp DESC, but timestamp is not in the SELECT list. SQLite does not allow ORDER BY on a column outside the DISTINCT select list — it will either error or silently ignore the ordering. This means recent_files won't be ordered by most recent interaction as intended. A GROUP BY file_path with MAX(timestamp) or a subquery would achieve the desired recency ordering.
| for f in self.recent_files[:10]: | ||
| # Show just the filename, not full path | ||
| name = f.rsplit("/", 1)[-1] if "/" in f else f | ||
| parts.append(f"- {name}") |
There was a problem hiding this comment.
File count header mismatches actual displayed items
Low Severity
The header displays len(self.recent_files) (up to 20 from the SQL query) but only the first 10 files are listed via self.recent_files[:10]. When there are more than 10 files, the output says something like "Recent files (15):" but only shows 10 entries, creating a confusing mismatch for the user. The count in the parentheses doesn't reflect what's actually rendered.
) Adds brainlayer_current_context — a fast, no-embedding tool that returns recent sessions, active projects, branches, files, and active plan. Designed for voice assistants and quick context injection at conversation start. - CurrentContext dataclass with format() method in engine.py - current_context() queries session_context + file interactions - 12th MCP tool, read-only annotations - 5 unit tests, tool count tests updated to 12 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>


Summary
brainlayer_current_context— 12th MCP tool, fast (no embedding needed)CurrentContextdataclass inengine.pywithformat()methodTest plan
🤖 Generated with Claude Code
Note
Medium Risk
Adds a new MCP tool and DB-backed query path (via
file_interactionsandsession_context) which could impact performance or fail on unexpected DB schemas/data, but changes are read-only and additive.Overview
Adds a new lightweight
current_context()capability inengine.py, including aCurrentContextdataclass with a concise markdownformat()and a DB query for recent distinctfile_interactionswithin a configurablehourswindow.Exposes this via a new read-only MCP tool
brainlayer_current_context(tool count now 12), wiring it throughcall_toolto_current_context, and adds unit/integration test coverage for formatting and MCP registration/annotations.Written by Cursor Bugbot for commit a0540a5. This will update automatically on new commits. Configure here.
Summary by CodeRabbit
Release Notes
New Features
Tests