MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / build_system_prompt

Function build_system_prompt

src/codegraphcontext/prompts.py:134–175  ·  view source on GitHub ↗

Build the complete system prompt by prepending custom prompt files. Args: project_root: Root directory of the project. If None, uses current directory. Returns: Complete system prompt with custom prompts prepended to the base prompt.

(project_root: Optional[Path] = None)

Source from the content-addressed store, hash-verified

132
133
134def build_system_prompt(project_root: Optional[Path] = None) -> str:
135 """
136 Build the complete system prompt by prepending custom prompt files.
137
138 Args:
139 project_root: Root directory of the project. If None, uses current directory.
140
141 Returns:
142 Complete system prompt with custom prompts prepended to the base prompt.
143 """
144 # Import here to avoid circular dependencies
145 try:
146 from codegraphcontext.cli.project_config import get_prompt_file_contents
147
148 # Get custom prompt contents
149 custom_prompts = get_prompt_file_contents(project_root)
150
151 if not custom_prompts:
152 # No custom prompts, return base prompt
153 return LLM_SYSTEM_PROMPT
154
155 # Build combined prompt: custom prompts first, then base prompt
156 combined_parts = []
157
158 # Add custom prompts
159 for i, custom_content in enumerate(custom_prompts, 1):
160 combined_parts.append(f"# Custom Instructions {i}\n\n{custom_content}")
161
162 # Add separator and base prompt
163 combined_parts.append("---\n")
164 combined_parts.append(LLM_SYSTEM_PROMPT)
165
166 return "\n\n".join(combined_parts)
167
168 except ImportError:
169 # If project_config is not available (shouldn't happen in normal use)
170 logger.warning("Could not import project_config module, using base prompt only")
171 return LLM_SYSTEM_PROMPT
172 except Exception as e:
173 # Log error but continue with base prompt to maintain backward compatibility
174 logger.warning(f"Error loading custom prompts: {e}. Using base prompt only.")
175 return LLM_SYSTEM_PROMPT

Callers 1

_run_loopMethod · 0.85

Calls 2

get_prompt_file_contentsFunction · 0.90
appendMethod · 0.65

Tested by

no test coverage detected