-
Notifications
You must be signed in to change notification settings - Fork 1
feat(tools): wire RootConfig.git_clone to GitCloneTool instantiation #519
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0cf208f
feat(tools): add tool factory wiring RootConfig.git_clone to GitClone…
Aureliolo e91a62b
refactor(tools): address review findings from 11 agents
Aureliolo 1706e1e
refactor(tools): address review findings from local agents, CodeRabbi…
Aureliolo e7a7132
refactor(tools): use dedicated TOOL_FACTORY_CONFIG_ENTRY event for en…
Aureliolo 33cbd57
Merge branch 'main' into feat/wire-git-clone-config
Aureliolo 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
Some comments aren't visible on the classic Files Changed page.
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
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 |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| """Tool factory — instantiate built-in workspace tools with config-driven parameters. | ||
|
|
||
| Provides ``build_default_tools`` (core factory) and | ||
| ``build_default_tools_from_config`` (convenience wrapper that | ||
| extracts parameters from a ``RootConfig``). Both return | ||
| ``tuple[BaseTool, ...]`` so callers can extend before wrapping | ||
| in a ``ToolRegistry``. | ||
| """ | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from synthorg.observability import get_logger | ||
| from synthorg.observability.events.tool import TOOL_FACTORY_BUILT | ||
| from synthorg.tools.file_system import ( | ||
| DeleteFileTool, | ||
| EditFileTool, | ||
| ListDirectoryTool, | ||
| ReadFileTool, | ||
| WriteFileTool, | ||
| ) | ||
| from synthorg.tools.git_tools import ( | ||
| GitBranchTool, | ||
| GitCloneTool, | ||
| GitCommitTool, | ||
| GitDiffTool, | ||
| GitLogTool, | ||
| GitStatusTool, | ||
| ) | ||
|
|
||
| if TYPE_CHECKING: | ||
| from pathlib import Path | ||
|
|
||
| from synthorg.config.schema import RootConfig | ||
| from synthorg.tools.base import BaseTool | ||
| from synthorg.tools.git_url_validator import GitCloneNetworkPolicy | ||
| from synthorg.tools.sandbox.protocol import SandboxBackend | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| def build_default_tools( | ||
| *, | ||
| workspace: Path, | ||
| git_clone_policy: GitCloneNetworkPolicy | None = None, | ||
| sandbox: SandboxBackend | None = None, | ||
| ) -> tuple[BaseTool, ...]: | ||
| """Instantiate all built-in workspace tools. | ||
|
|
||
| Returns a sorted tuple of tool instances ready for use or | ||
| extension before wrapping in a ``ToolRegistry``. | ||
|
|
||
| Args: | ||
| workspace: Absolute path to the agent workspace root. | ||
| git_clone_policy: Network policy for git clone SSRF | ||
| prevention. ``None`` uses the default (block all | ||
| private IPs, empty hostname allowlist). | ||
| sandbox: Optional sandbox backend for git subprocess | ||
| isolation. | ||
|
|
||
| Returns: | ||
| Tuple of ``BaseTool`` instances sorted by name. | ||
| """ | ||
| fs_tools: list[BaseTool] = [ | ||
| ReadFileTool(workspace_root=workspace), | ||
| WriteFileTool(workspace_root=workspace), | ||
| EditFileTool(workspace_root=workspace), | ||
| ListDirectoryTool(workspace_root=workspace), | ||
| DeleteFileTool(workspace_root=workspace), | ||
| ] | ||
|
|
||
| git_tools: list[BaseTool] = [ | ||
| GitStatusTool(workspace=workspace, sandbox=sandbox), | ||
| GitLogTool(workspace=workspace, sandbox=sandbox), | ||
| GitDiffTool(workspace=workspace, sandbox=sandbox), | ||
| GitBranchTool(workspace=workspace, sandbox=sandbox), | ||
| GitCommitTool(workspace=workspace, sandbox=sandbox), | ||
| GitCloneTool( | ||
| workspace=workspace, | ||
| sandbox=sandbox, | ||
| network_policy=git_clone_policy, | ||
| ), | ||
| ] | ||
|
|
||
| result = tuple(sorted(fs_tools + git_tools, key=lambda t: t.name)) | ||
|
|
||
| logger.info( | ||
| TOOL_FACTORY_BUILT, | ||
| tool_count=len(result), | ||
| tools=tuple(t.name for t in result), | ||
| ) | ||
|
|
||
| return result | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def build_default_tools_from_config( | ||
| *, | ||
| workspace: Path, | ||
| config: RootConfig, | ||
| sandbox: SandboxBackend | None = None, | ||
| ) -> tuple[BaseTool, ...]: | ||
| """Build default tools using parameters from a ``RootConfig``. | ||
|
|
||
| Convenience wrapper that extracts ``config.git_clone`` and | ||
| delegates to :func:`build_default_tools`. | ||
|
|
||
| Args: | ||
| workspace: Absolute path to the agent workspace root. | ||
| config: Validated root configuration. | ||
| sandbox: Optional sandbox backend for git subprocess | ||
| isolation. | ||
|
|
||
| Returns: | ||
| Tuple of ``BaseTool`` instances sorted by name. | ||
| """ | ||
| return build_default_tools( | ||
| workspace=workspace, | ||
| git_clone_policy=config.git_clone, | ||
| sandbox=sandbox, | ||
| ) | ||
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.
This list of example event constants is becoming very long and is difficult to navigate. To improve readability and make it easier to check if an event is already listed, please consider sorting the constants alphabetically within the
e.g., (...)block.