326 Commits

Author SHA1 Message Date
Fahad
5199dd6ead Include custom models in model discovery for auto mode too 2025-06-18 06:40:35 +04:00
Fahad
b56993a42f Refactor 2025-06-18 06:24:24 +04:00
Fahad
a509730dca New Planner tool to help you break down complex ideas, problems, and projects into multiple manageable steps. This is a self-prompt generation tool whose output can then be fed into another tool and model as required 2025-06-17 20:49:53 +04:00
Fahad
77da7b17e6 Fixes bug pointed out by @dsaluja (https://github.com/dsaluja)
Fixes other providers not fixed by https://github.com/BeehiveInnovations/zen-mcp-server/pull/66
New regression tests
2025-06-17 11:29:45 +04:00
Fahad
be7d80d7aa Advertise prompts, fixes https://github.com/BeehiveInnovations/zen-mcp-server/issues/63 2025-06-17 11:17:19 +04:00
Beehive Innovations
95556ba9ea Add Consensus Tool for Multi-Model Perspective Gathering (#67)
* WIP
Refactor resolving mode_names, should be done once at MCP call boundary
Pass around model context instead
Consensus tool allows one to get a consensus from multiple models, optionally assigning one a 'for' or 'against' stance to find nuanced responses.

* Deduplication of model resolution, model_context should be available before reaching deeper parts of the code
Improved abstraction when building conversations
Throw programmer errors early

* Guardrails
Support for `model:option` format at MCP boundary so future tools can use additional options if needed instead of handling this only for consensus
Model name now supports an optional ":option" for future use

* Simplified async flow

* Improved model for request to support natural language
Simplified async flow

* Improved model for request to support natural language
Simplified async flow

* Fix consensus tool async/sync patterns to match codebase standards

CRITICAL FIXES:
- Converted _get_consensus_responses from async to sync (matches other tools)
- Converted store_conversation_turn from async to sync (add_turn is synchronous)
- Removed unnecessary asyncio imports and sleep calls
- Fixed ClosedResourceError in MCP protocol during long consensus operations

PATTERN ALIGNMENT:
- Consensus tool now follows same sync patterns as all other tools
- Only execute() and prepare_prompt() are async (base class requirement)
- All internal operations are synchronous like analyze, chat, debug, etc.

TESTING:
- MCP simulation test now passes: consensus_stance 
- Two-model consensus works correctly in ~35 seconds
- Unknown stance handling defaults to neutral with warnings
- All 9 unit tests pass (100% success rate)

The consensus tool async patterns were anomalous in the codebase.
This fix aligns it with the established synchronous patterns used
by all other tools while maintaining full functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fixed call order and added new test

* Cleanup dead comments
Docs for the new tool
Improved tests

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-06-17 10:53:17 +04:00
Fahad
9b98df650b Fixes O3-Pro connection https://github.com/BeehiveInnovations/zen-mcp-server/issues/56
New tests for O3-pro
Improved prompts for shorthand input
2025-06-16 20:00:08 +04:00
Fahad
b528598360 Add regression tests for Gemini parameter order bug
Adds two comprehensive tests to prevent future regression of the parameter
order bug in `restriction_service.is_allowed()` calls:

1. `test_gemini_parameter_order_regression_protection` - Tests edge case
   where only alias is allowed, ensuring correct parameter order
2. `test_gemini_parameter_order_edge_case_full_name_only` - Tests reverse
   scenario where only full model name is allowed

These tests specifically catch the subtle bug where parameters were
incorrectly passed as (provider, user_input, resolved_name) instead of
(provider, resolved_name, user_input). The bug was masked by OR logic
in most cases but could cause issues in edge scenarios.

All 498 tests pass, including the new regression protection tests.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-16 19:13:47 +04:00
Fahad
70b64adff3 Schema now lists all models including locally available models
New tool to list all models `listmodels`
Integration test to for all the different combinations of API keys
Tweaks to codereview prompt for a better quality input from Claude
Fixed missing 'low' severity in codereview
2025-06-16 19:07:35 +04:00
Fahad
65c3840f7e Fix image support integration tests to use real provider resolution pattern
Following the established testing patterns from other tool tests:
- Removed mocking of providers and capabilities
- Use real provider resolution with dummy API keys
- Expect proper validation behavior or provider-not-found errors
- Applied proper Redis mocking for conversation memory tests
- Simplified validation tests to focus on core functionality
- All 473 tests now pass 100% including 13 image support tests

This ensures CI/CD compatibility and follows the proven testing approach
used throughout the codebase for tool integration testing.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-16 16:37:34 +04:00
Fahad
ed386375be Complete Redis mocking fixes for image support integration tests
- Properly mock Redis client operations to support add_turn functionality
- Set up initial thread contexts so add_turn can find existing threads
- Mock Redis set operations to return success
- Ensure all Redis-dependent tests use proper mock patterns
- All 473 unit tests now pass 100% with proper isolation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-16 16:26:23 +04:00
Fahad
a65c63c8da Fix Redis mocking in image support integration tests
- Add proper Redis client mocking to prevent connection attempts during CI
- Apply @patch("utils.conversation_memory.get_redis_client") decorators to all methods using Redis
- Mock thread contexts for get_thread calls to ensure tests work without Redis
- Fixes GitHub Actions failures: ConnectionRefusedError when connecting to localhost:6379
- Maintains test isolation and proper mock patterns used throughout test suite

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-16 16:20:14 +04:00
Fahad
0143140c34 Fix line length violations and code quality improvements
- Fixed worst flake8 violations (300-600+ character lines) in tools directory
- Applied consistent multi-line string formatting for better readability
- Removed incompatible test files from main branch merge
- All 473 tests passing, all code quality checks pass

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-16 13:21:17 +04:00
Fahad
061fb8691d Merge main into feature/images - resolve conflicts favoring our approach
- Kept version 4.8.0 for new features
- Preserved our _is_builtin_custom_models_config approach over main's ALLOWED_INTERNAL_PATHS
- Our targeted solution is cleaner than the general whitelist approach
2025-06-16 13:19:08 +04:00
Fahad
97fa6781cf Vision support via images / pdfs etc that can be passed on to other models as part of analysis, additional context etc.
Image processing pipeline added
OpenAI GPT-4.1 support
Chat tool prompt enhancement
Lint and code quality improvements
2025-06-16 13:14:53 +04:00
Fahad
d6d7bf8cac Fixed internal file path translation into docker 2025-06-16 11:30:02 +04:00
Fahad
5a49d196c8 More integration tests 2025-06-16 07:07:38 +04:00
Fahad
35f37fb92e Fixed integration test for auto mode 2025-06-16 07:00:27 +04:00
Fahad
c643970ffb Fixed integration test for auto mode 2025-06-16 06:57:06 +04:00
Fahad
903aabd311 Fixed imports and lint 2025-06-16 06:24:33 +04:00
Fahad
2cfe0b163a Fix all failing tests and pytest collection warnings
Fixed MagicMock comparison errors across multiple test suites by:
- Adding proper ModelCapabilities mocks with real values instead of MagicMock objects
- Updating test_auto_mode.py with correct provider mocking for model availability tests
- Updating test_thinking_modes.py with proper capabilities mocking in all thinking mode tests
- Updating test_tools.py with proper capabilities mocking for CodeReview and Analyze tools
- Fixing test_large_prompt_handling.py by adding proper provider mocking to prevent errors before large prompt detection

Fixed pytest collection warnings by:
- Renaming TestGenRequest to TestGenerationRequest to avoid pytest collecting it as a test class
- Renaming TestGenTool to TestGenerationTool to avoid pytest collecting it as a test class
- Updated all imports and references across server.py, tools/__init__.py, and test files

All 459 tests now pass without warnings or MagicMock comparison errors.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-16 06:02:12 +04:00
Fahad
91077e3810 Performance improvements when embedding files:
- Exit early at MCP boundary if files won't fit within given context of chosen model
- Encourage claude to re-run with better context
- Check file sizes before embedding
- Drop files from older conversations when building continuations and give priority to newer files
- List and mention excluded files to Claude on return
- Improved tests
- Improved precommit prompt
- Added a new Low severity to precommit
- Improved documentation of file embedding strategy
- Refactor
2025-06-16 05:51:52 +04:00
Fahad
ad6cff4498 Lint, bump 2025-06-15 18:43:37 +04:00
Fahad
dfed6f0cbd New tool: "tracer" helps with static analysis / call-flow generation. Does NOT use external models. Used as a quick prompt generator to aid in call-flow / dependency-chart generation. Can be used as an input into another tool / model for extended analysis and deeper thought.
Faster docker restarts
2025-06-15 18:42:10 +04:00
Fahad
6f8d3059a1 Merge branch 'main' into feature/tracer
# Conflicts:
#	tools/base.py
#	tools/debug.py
#	tools/thinkdeep.py
2025-06-15 16:09:54 +04:00
Fahad
f3720ad8e9 Use mock-reddis 2025-06-15 16:09:07 +04:00
Fahad
07a078b4f2 Updated tests and additional tests for folder expansion during conversation tracking 2025-06-15 16:03:43 +04:00
Fahad
86728a1442 WIP 2025-06-15 15:32:41 +04:00
Fahad
9b8ea72280 Fixed for git actions 2025-06-15 14:14:15 +04:00
Fahad
3bc7956239 Implement TracePath tool for static call path analysis
Add comprehensive TracePath tool that predicts and explains full call paths
and control flow without executing code. Features include:

**Core Functionality:**
- Static call path prediction with confidence levels (🟢🟡🔴)
- Multi-language support (Python, JavaScript, TypeScript, C#, Java)
- Value-driven flow analysis based on parameter combinations
- Side effects identification (database, network, filesystem)
- Polymorphism and dynamic dispatch analysis
- Entry point parsing for multiple syntax patterns

**Technical Implementation:**
- Hybrid AI-first architecture (Phase 1: pure AI, Phase 2: AST enhancement)
- Export formats: Markdown, JSON, PlantUML
- Confidence threshold filtering for speculative branches
- Integration with existing tool ecosystem and conversation threading
- Comprehensive error handling and token management

**Files Added:**
- tools/tracepath.py - Main tool implementation
- systemprompts/tracepath_prompt.py - System prompt for analysis
- tests/test_tracepath.py - Comprehensive unit tests (32 tests)

**Files Modified:**
- server.py - Tool registration
- tools/__init__.py - Tool exports
- systemprompts/__init__.py - Prompt exports

**Quality Assurance:**
- All 449 unit tests pass including 32 new TracePath tests
- Full linting and formatting compliance
- Follows established project patterns and conventions
- Multi-model validation with O3 and Gemini Pro insights

**Usage Examples:**
- "Use zen tracepath to analyze BookingManager::finalizeInvoice(invoiceId: 123)"
- "Trace payment.process_payment() with confidence levels and side effects"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-15 14:07:23 +04:00
Fahad
6304b7af6b Native support for xAI Grok3
Model shorthand mapping related fixes
Comprehensive auto-mode related tests
2025-06-15 12:21:44 +04:00
Fahad
4becd70a82 Perform prompt size checks only at the MCP boundary
New test to confirm history build-up and system prompt does not affect prompt size checks
Also check for large prompts in focus_on
Fixed .env.example incorrectly did not comment out CUSTOM_API causing the run-server script to think at least one key exists
2025-06-15 10:37:08 +04:00
Fahad
8364170881 Merge remote-tracking branch 'origin/main' 2025-06-15 09:25:58 +04:00
Fahad
c7835e7eef Easier access to logs at startup with -f on the run script
Improved prompt for immediate action
Additional logging of tool names
Updated documentation
Context aware decomposition system prompt
New script to run code quality checks
2025-06-15 09:25:52 +04:00
Fahad
99fab3e83d Docs added to show how a new provider is added
Docs added to show how a new tool is created
All tools should add numbers to code for models to be able to reference if needed
Enabled line numbering for code for all tools to use
Additional tests to validate line numbering is not added to git diffs
2025-06-15 07:02:27 +04:00
Fahad
b5004b91fc Major new addition: refactor tool
Supports decomposing large components and files, finding codesmells, finding modernizing opportunities as well as code organization opportunities. Fix this mega-classes today!
Line numbers added to embedded code for better references from model -> claude
2025-06-15 06:00:01 +04:00
Nikolai Ugelvik
0eeea3dd67 Apply black formatting to test_openrouter_provider.py 2025-06-14 19:33:20 +02:00
Nikolai Ugelvik
be2612752a Fix auto mode when only OpenRouter is configured
The get_available_models method in ModelProviderRegistry was only checking
for providers with SUPPORTED_MODELS attribute, which OpenRouter doesn't have.
This caused auto mode to fail with "No models available" error when only
OpenRouter API key was configured.

Added special handling for OpenRouter provider to check its _registry
for available models, ensuring auto mode works correctly with OpenRouter.

Added comprehensive tests to verify:
- Auto mode works with only OpenRouter configured
- Model restrictions are respected
- Graceful handling when no providers are available
- No crashes when OpenRouter lacks _registry attribute
2025-06-14 19:21:14 +02:00
Beehive Innovations
9f973b90e5 Merge pull request #36 from lox/add-o3-pro-support
feat: Add o3-pro model support
2025-06-14 19:44:14 +04:00
Fahad
f1ad06c529 Fixed lint, tests after recent fix
Updated readme
2025-06-14 19:31:31 +04:00
Fahad
a4f9e22256 Renamed version tool 2025-06-14 18:54:53 +04:00
Fahad
442decba70 Improved model response handling to handle additional response statuses in future
Improved testgen; encourages follow-ups with less work in between and less token generation to avoid surpassing the 25K barrier
Improved coderevew tool to request a focused code review instead where a single-pass code review is too large or complex
2025-06-14 18:43:56 +04:00
Fahad
d0d0a171dc Ensure duplicate file references are gracefully handled
Improved prompt to encourage immediate action
2025-06-14 16:37:02 +04:00
Fahad
acbfa1c94e Improved prompt for next steps 2025-06-14 15:51:04 +04:00
Fahad
4086306c58 New tool: testgen
Generates unit tests and encourages model to auto-detect framework and testing style from existing sample (if available)
2025-06-14 15:41:47 +04:00
Lachlan Donald
40aa1eaeb6 Format test_auto_mode.py with black
Fix code formatting to comply with black style requirements.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-14 21:09:47 +10:00
Fahad
7d33aafcab Configurable conversation limit now set to 10 exchanges. This helps when you want to manually continue a thread of thought across different models manually. 2025-06-14 14:00:13 +04:00
Fahad
bc3f98a291 Make conversation timeout configuration (so that you're able to resume a discussion manually with another model with a gap of several hours in case you stepped away) 2025-06-14 13:27:19 +04:00
Fahad
e0a05b86f1 Add encouraging message about powerful models to schema in case it's not on Opus 4 or above
OPENROUTER_ALLOWED_MODELS environment variable support to further limit the models to allow from within Claude. This will put a limit on top of even the ones listed in custom_models.json
2025-06-14 11:34:17 +04:00
Fahad
23353734cd Support for allowed model restrictions per provider
Tool escalation added to `analyze` to a graceful switch over to codereview is made when absolutely necessary
2025-06-14 10:56:53 +04:00