From e967dffee704946f21ce1f7fcfbc426863107974 Mon Sep 17 00:00:00 2001 From: Chojan Shang Date: Thu, 17 Jul 2025 11:25:30 +0800 Subject: [PATCH 1/2] chore: add vulture to carefully review code --- .pre-commit-config.yaml | 6 ++++++ Makefile | 5 +++++ pyproject.toml | 4 ++++ src/bub/agent/core.py | 14 +++++++------- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 23d88115..ef1d3e08 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,6 +14,12 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace + - repo: https://github.com/jendrikseipp/vulture + rev: "v2.14" + hooks: + - id: vulture + stages: [manual] + - repo: https://github.com/astral-sh/ruff-pre-commit rev: "v0.11.5" hooks: diff --git a/Makefile b/Makefile index e21c3fed..bb1d96f2 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,11 @@ check: ## Run code quality tools. @echo "🚀 Static type checking: Running mypy" @uv run mypy +.PHONY: vulture +vulture: ## Run vulture to check for unused code. + @echo "🚀 Checking for unused code with vulture" + @uv run pre-commit run vulture --hook-stage manual --all-files + .PHONY: test test: ## Test the code with pytest @echo "🚀 Testing code: Running pytest" diff --git a/pyproject.toml b/pyproject.toml index 190e7d5d..ada53929 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,10 @@ build-backend = "hatchling.build" [tool.hatch.build.targets.wheel] packages = ["src/bub"] +[tool.vulture] +ignore_names = ["test_*", "Test*"] +paths = ["src"] + [tool.mypy] files = ["src"] disallow_untyped_defs = true diff --git a/src/bub/agent/core.py b/src/bub/agent/core.py index 9fb5ed78..e7207fb3 100644 --- a/src/bub/agent/core.py +++ b/src/bub/agent/core.py @@ -73,9 +73,14 @@ def __init__( # Store custom system prompt if provided self.custom_system_prompt = system_prompt - # Use ReAct principles as the main system prompt self.prompt_formatter = ReActPromptFormatter() - self.system_prompt = self.prompt_formatter.REACT_PRINCIPLES + # Use format_prompt to generate the full system prompt + if self.custom_system_prompt: + self.system_prompt = self.prompt_formatter.format_prompt(self.custom_system_prompt) + else: + # Use config default if not provided + config_prompt = self.context.get_system_prompt() + self.system_prompt = self.prompt_formatter.format_prompt(config_prompt) def reset_conversation(self) -> None: """Reset the conversation history.""" @@ -88,11 +93,6 @@ def chat(self, message: str, on_step: Optional[Callable[[str, str], None]] = Non while True: context_msg = self.context.build_context_message() - # Add system prompt to context if available - system_prompt = self.custom_system_prompt or self.context.get_system_prompt() - if system_prompt: - context_msg += f"\n\n[System Instructions]\n{system_prompt}" - messages = [ {"role": "system", "content": self.system_prompt}, {"role": "system", "content": context_msg}, From 4bb5583f0ce2ba48db9b2cd096696b45ba8345e7 Mon Sep 17 00:00:00 2001 From: Chojan Shang Date: Thu, 17 Jul 2025 12:11:05 +0800 Subject: [PATCH 2/2] chore: allow adjust timeout I used bub to carefully check the OpenDAL release vote verification process. --- src/bub/tools/run_command.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bub/tools/run_command.py b/src/bub/tools/run_command.py index 3e1046db..ce54e6b2 100644 --- a/src/bub/tools/run_command.py +++ b/src/bub/tools/run_command.py @@ -20,6 +20,7 @@ class RunCommandTool(Tool): Parameters: command: The shell command to execute (e.g., 'ls', 'cat file.txt'). cwd: Optional. The working directory to run the command in. Defaults to workspace root. + timeout: Optional. The timeout in seconds for the command to run. Defaults to 30 seconds. """ name: str = Field(default="run_command", description="The internal name of the tool") @@ -32,6 +33,9 @@ class RunCommandTool(Tool): cwd: Optional[str] = Field( default=None, description="Optional. The working directory to run the command in. Defaults to workspace root." ) + timeout: int = Field( + default=30, description="The timeout in seconds for the command to run. Defaults to 30 seconds." + ) # List of dangerous commands that should be blocked DANGEROUS_COMMANDS: ClassVar[set[str]] = { @@ -104,7 +108,7 @@ def execute(self, context: Context) -> ToolResult: cwd=working_dir, capture_output=True, text=True, - timeout=30, + timeout=self.timeout, ) return ToolResult( success=(result.returncode == 0),