-
-
Notifications
You must be signed in to change notification settings - Fork 2
redesign config subsystem #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Agent-Hellboy
wants to merge
3
commits into
main
Choose a base branch
from
redesign_config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ doc_ref/ | |
| # C extensions | ||
| *REDESIGN*.md | ||
| *FLOW.md | ||
| *USAGE.md | ||
| *.so | ||
| notes.md | ||
| /reports/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,72 @@ | ||
| """Public client exports.""" | ||
|
|
||
| from .base import MCPFuzzerClient | ||
| from .adapters import ConfigAdapter, config_mediator | ||
| from .constants import ( | ||
| CONTENT_TYPE_HEADER, | ||
| DEFAULT_FORCE_KILL_TIMEOUT, | ||
| DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT, | ||
| DEFAULT_HTTP_ACCEPT, | ||
| DEFAULT_MAX_TOTAL_FUZZING_TIME, | ||
| DEFAULT_MAX_TOOL_TIME, | ||
| DEFAULT_PROTOCOL_RUNS_PER_TYPE, | ||
| DEFAULT_PROTOCOL_VERSION, | ||
| DEFAULT_TIMEOUT, | ||
| DEFAULT_TOOL_RUNS, | ||
| DEFAULT_TOOL_TIMEOUT, | ||
| JSON_CONTENT_TYPE, | ||
| MCP_PROTOCOL_VERSION_HEADER, | ||
| MCP_SESSION_ID_HEADER, | ||
| PROCESS_CLEANUP_TIMEOUT, | ||
| PROCESS_FORCE_KILL_TIMEOUT, | ||
| PROCESS_TERMINATION_TIMEOUT, | ||
| PROCESS_WAIT_TIMEOUT, | ||
| SAFETY_ENV_ALLOWLIST, | ||
| SAFETY_HEADER_DENYLIST, | ||
| SAFETY_LOCAL_HOSTS, | ||
| SAFETY_NO_NETWORK_DEFAULT, | ||
| SAFETY_PROXY_ENV_DENYLIST, | ||
| SSE_CONTENT_TYPE, | ||
| WATCHDOG_DEFAULT_CHECK_INTERVAL, | ||
| WATCHDOG_EXTRA_BUFFER, | ||
| WATCHDOG_MAX_HANG_ADDITIONAL, | ||
| ) | ||
| from .ports import ConfigPort | ||
|
|
||
| UnifiedMCPFuzzerClient = MCPFuzzerClient | ||
|
|
||
| __all__ = ["MCPFuzzerClient", "UnifiedMCPFuzzerClient"] | ||
| __all__ = [ | ||
| "MCPFuzzerClient", | ||
| "UnifiedMCPFuzzerClient", | ||
| "ConfigPort", | ||
| "ConfigAdapter", | ||
| "config_mediator", | ||
| # Constants | ||
| "DEFAULT_PROTOCOL_VERSION", | ||
| "CONTENT_TYPE_HEADER", | ||
| "JSON_CONTENT_TYPE", | ||
| "SSE_CONTENT_TYPE", | ||
| "DEFAULT_HTTP_ACCEPT", | ||
| "MCP_SESSION_ID_HEADER", | ||
| "MCP_PROTOCOL_VERSION_HEADER", | ||
| "WATCHDOG_DEFAULT_CHECK_INTERVAL", | ||
| "WATCHDOG_EXTRA_BUFFER", | ||
| "WATCHDOG_MAX_HANG_ADDITIONAL", | ||
| "SAFETY_LOCAL_HOSTS", | ||
| "SAFETY_NO_NETWORK_DEFAULT", | ||
| "SAFETY_HEADER_DENYLIST", | ||
| "SAFETY_PROXY_ENV_DENYLIST", | ||
| "SAFETY_ENV_ALLOWLIST", | ||
| "DEFAULT_TOOL_RUNS", | ||
| "DEFAULT_PROTOCOL_RUNS_PER_TYPE", | ||
| "DEFAULT_TIMEOUT", | ||
| "DEFAULT_TOOL_TIMEOUT", | ||
| "DEFAULT_MAX_TOOL_TIME", | ||
| "DEFAULT_MAX_TOTAL_FUZZING_TIME", | ||
| "DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT", | ||
| "DEFAULT_FORCE_KILL_TIMEOUT", | ||
| "PROCESS_TERMINATION_TIMEOUT", | ||
| "PROCESS_FORCE_KILL_TIMEOUT", | ||
| "PROCESS_CLEANUP_TIMEOUT", | ||
| "PROCESS_WAIT_TIMEOUT", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/usr/bin/env python3 | ||
| """Adapter implementations for Port and Adapter pattern. | ||
|
|
||
| Adapters implement the ports (interfaces) by adapting external modules. | ||
| This is where the mediation between modules happens. | ||
| """ | ||
|
|
||
| from .config_adapter import ConfigAdapter, config_mediator | ||
|
|
||
| __all__ = ["ConfigAdapter", "config_mediator"] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #!/usr/bin/env python3 | ||
| """Configuration adapter implementation for Port and Adapter pattern. | ||
|
|
||
| This module implements the ConfigPort interface by adapting the config module. | ||
| This is the adapter that mediates all configuration access. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from ...config import ( | ||
| apply_config_file, | ||
| get_config_schema, | ||
| load_config_file, | ||
| ) | ||
| from ...config.core.manager import config as global_config | ||
| from ..ports.config_port import ConfigPort | ||
|
|
||
|
|
||
| class ConfigAdapter(ConfigPort): | ||
| """Adapter that implements ConfigPort by delegating to the config module. | ||
|
|
||
| This adapter acts as a mediator between other modules and the config module, | ||
| implementing the Port and Adapter (Hexagonal Architecture) pattern. | ||
| """ | ||
|
|
||
| def __init__(self, config_instance: Any = None): | ||
| """Initialize the config adapter. | ||
|
|
||
| Args: | ||
| config_instance: Optional configuration instance to use. | ||
| If None, uses the global config instance. | ||
| """ | ||
| self._config = config_instance or global_config | ||
|
|
||
| def get(self, key: str, default: Any = None) -> Any: | ||
| """Get a configuration value by key. | ||
|
|
||
| Args: | ||
| key: Configuration key | ||
| default: Default value if key not found | ||
|
|
||
| Returns: | ||
| Configuration value or default | ||
| """ | ||
| return self._config.get(key, default) | ||
|
|
||
| def set(self, key: str, value: Any) -> None: | ||
| """Set a configuration value. | ||
|
|
||
| Args: | ||
| key: Configuration key | ||
| value: Configuration value | ||
| """ | ||
| self._config.set(key, value) | ||
|
|
||
| def update(self, config_dict: dict[str, Any]) -> None: | ||
| """Update configuration with values from a dictionary. | ||
|
|
||
| Args: | ||
| config_dict: Dictionary of configuration values to update | ||
| """ | ||
| self._config.update(config_dict) | ||
|
|
||
| def load_file(self, file_path: str) -> dict[str, Any]: | ||
| """Load configuration from a file. | ||
|
|
||
| Args: | ||
| file_path: Path to configuration file | ||
|
|
||
| Returns: | ||
| Dictionary containing loaded configuration | ||
|
|
||
| Raises: | ||
| ConfigFileError: If file cannot be loaded | ||
| """ | ||
| return load_config_file(file_path) | ||
|
|
||
| def apply_file( | ||
| self, | ||
| config_path: str | None = None, | ||
| search_paths: list[str] | None = None, | ||
| file_names: list[str] | None = None, | ||
| ) -> bool: | ||
| """Load and apply configuration from a file. | ||
|
|
||
| Args: | ||
| config_path: Explicit path to config file | ||
| search_paths: List of directories to search | ||
| file_names: List of file names to search for | ||
|
|
||
| Returns: | ||
| True if configuration was loaded and applied, False otherwise | ||
| """ | ||
| return apply_config_file( | ||
| config_path=config_path, | ||
| search_paths=search_paths, | ||
| file_names=file_names, | ||
| ) | ||
|
|
||
| def get_schema(self) -> dict[str, Any]: | ||
| """Get the JSON schema for configuration validation. | ||
|
|
||
| Returns: | ||
| JSON schema dictionary | ||
| """ | ||
| return get_config_schema() | ||
|
|
||
|
|
||
| # Global instance for convenience (acts as the mediator) | ||
| config_mediator: ConfigPort = ConfigAdapter() | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential inconsistency with custom
config_instance.When
ConfigAdapteris initialized with a customconfig_instance, theapply_file()method still delegates to the module-levelapply_config_file(), which updates the global config rather thanself._config. This creates inconsistent behavior whereget/set/updateoperate on the custom instance butapply_filebypasses it.Consider injecting the config instance into the loader or documenting this as intentional behavior.
def apply_file( self, config_path: str | None = None, search_paths: list[str] | None = None, file_names: list[str] | None = None, ) -> bool: - return apply_config_file( - config_path=config_path, - search_paths=search_paths, - file_names=file_names, - ) + from ...config.loading import ConfigLoader + loader = ConfigLoader(config_instance=self._config) + return loader.apply( + config_path=config_path, + search_paths=search_paths, + file_names=file_names, + )🤖 Prompt for AI Agents