From f654e1fe25d71886fba85314d4f07a9ad14a068f Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Wed, 16 Jul 2025 14:43:53 +0200 Subject: [PATCH] Add print-system-prompt command to output InitialInstructionsTool result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This command creates a SerenaAgent instance for a project and uses the InitialInstructionsTool to output the system prompt/initial instructions. It follows the same pattern as the existing index-project command and can be run with: uv run print-system-prompt [project_path] 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- pyproject.toml | 1 + src/serena/agent.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 24ba0412..c0c4c813 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,7 @@ dependencies = [ [project.scripts] serena-mcp-server = "serena.mcp:start_mcp_server" index-project = "serena.agent:index_project" +print-system-prompt = "serena.agent:print_system_prompt" [project.license] text = "MIT" diff --git a/src/serena/agent.py b/src/serena/agent.py index 454986f4..1fa85e90 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -124,6 +124,33 @@ def index_project(project: str, log_level: str = "INFO") -> None: print(f"Symbols saved to {ls.cache_path}") +@click.command() +@click.argument("project", type=click.Path(exists=True), required=False, default=os.getcwd()) +@click.option("--log-level", type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]), default="WARNING") +def print_system_prompt(project: str, log_level: str = "WARNING") -> None: + """ + Print the system prompt (initial instructions) for a project. + + :param project: the project to get the system prompt for. By default, the current working directory is used. + """ + log_level_int = logging.getLevelNamesMapping()[log_level.upper()] + logging.configure(level=log_level_int) + + # Create a SerenaAgent instance + agent = SerenaAgent(project=os.path.abspath(project)) + + # Get the InitialInstructionsTool instance + from serena.tools.workflow_tools import InitialInstructionsTool + + initial_instructions_tool = agent.get_tool(InitialInstructionsTool) + + # Apply the tool to get the system prompt + system_prompt = initial_instructions_tool.apply() + + # Print the system prompt + print(system_prompt) + + class SerenaAgent: def __init__( self,