Smart Context
The smart_context tool automatically gathers relevant code context for AI agents. It analyzes your task, question, or refactoring goal and collects the most relevant files, symbols, and code patterns.
✨ New in v0.10.0
Smart Context now supports 3 modes with auto-detection of task type (explain/refactor/debug/add-feature) for optimal context gathering.
Modes
Usage
Task Mode
Provide a task description and let vibe-hnindex gather the relevant context:
smart_context(
project_name: "my-app",
task: "add rate limiting to the API"
)The server will:
- Analyze the task for impact scope
- Find relevant test files near affected code
- Discover similar code patterns for consistency
- Auto-detect task type: explain, refactor, debug, or add-feature
Question Mode
Ask a natural language question about your codebase:
smart_context(
project_name: "my-app",
question: "how does the auth flow work?"
)The server will:
- Search code related to your question
- Gather context imports and dependents
- Collect relevant symbols and their definitions
- Provide a comprehensive answer context
Refactor Mode
For full impact analysis when refactoring:
smart_context(
project_name: "my-app",
task: "refactor the user service"
)The server will:
- Perform impact analysis up to depth 3
- Find all files affected by the change
- Collect test files for verification
- Discover similar patterns for consistent refactoring
Auto-Detection
The server automatically detects the type of task and adjusts its context gathering strategy:
| Detected Type | Context Strategy |
|---|---|
| Explain | Gather definitions, callers, and documentation |
| Refactor | Deep impact analysis, test files, similar patterns |
| Debug | Error handling, log statements, test coverage |
| Add Feature | Similar implementations, interfaces, patterns |
Response Format
Smart Context returns a structured response with sections based on the detected task type:
| Section | Content | Modes |
|---|---|---|
| Task Analysis | Detected task type, keywords, relevant directories | All |
| Core Context | File content + imports + definitions for the main files | All |
| Dependents | Files that import/use the target code | Task, Refactor |
| Test Files | Related .test.ts, .spec.ts, __tests__/ | Task, Refactor, Debug |
| Similar Patterns | Files with same extension and similar code structure | Task, Add Feature |
| Impact Analysis | Up to 3 levels deep — files affected by the change | Refactor |
| Symbol Map | Exports, types, interfaces in the affected scope | All |
| Git History | Recent changes to relevant files (if git repo) | All |
How AI Agents Should Use Smart Context
- Before starting a task: Call
smart_contextwith a brief description of what you plan to do. It gathers all relevant files upfront. - Read the task analysis to understand the task type and affected areas.
- Check impact analysis (refactor mode) before touching shared utilities to avoid breaking dependents.
- Review test files to understand expected behavior and run tests after changes.
- Use similar patterns to stay consistent with existing code style.
Related Tools
project_briefing— Rule-based project briefing (README, package.json, index stats)onboarding_prompt— Single markdown blob with index freshness, briefing, statsagent_rules_stub— Short copy-paste markdown for AI agent contextfile_summary— Get imports, exports, dependents, and test files for a specific filesymbol_lookup— Look up a symbol (function, class, type) and get all referencesrecent_changes— See what files changed recently in a project