@@ -17,12 +17,12 @@ use ratatui::{
1717use tokio:: sync:: oneshot;
1818
1919use crate :: commands:: Command ;
20- use crate :: config:: { AgentRuntimeConfig , Config , CODEY_DIR } ;
20+ use crate :: config:: { AgentRuntimeConfig , Config } ;
2121use crate :: ide:: { Ide , IdeEvent , Nvim } ;
2222use crate :: llm:: { Agent , AgentId , AgentRegistry , AgentStep , RequestMode } ;
2323#[ cfg( feature = "profiling" ) ]
2424use crate :: { profile_frame, profile_span} ;
25- use crate :: prompts:: { COMPACTION_PROMPT , SYSTEM_MD_FILENAME , SYSTEM_PROMPT , WELCOME_MESSAGE } ;
25+ use crate :: prompts:: { SystemPrompt , COMPACTION_PROMPT , WELCOME_MESSAGE } ;
2626use crate :: tool_filter:: ToolFilters ;
2727use crate :: tools:: {
2828 init_agent_context, update_agent_oauth, Effect , ToolCall , ToolDecision , ToolEvent ,
@@ -36,62 +36,6 @@ const MIN_FRAME_TIME: Duration = Duration::from_millis(16);
3636pub const APP_NAME : & str = "Codey" ;
3737pub const APP_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
3838
39- /// Process a SYSTEM.md file through mdsh, executing embedded shell commands.
40- ///
41- /// Returns the processed content, or the original content if processing fails.
42- fn process_mdsh ( content : & str , path : & std:: path:: Path ) -> String {
43- use mdsh:: Processor ;
44-
45- let workdir = path
46- . parent ( )
47- . map ( |p| p. as_os_str ( ) )
48- . unwrap_or_else ( || std:: ffi:: OsStr :: new ( "." ) ) ;
49-
50- let mut output = Vec :: new ( ) ;
51- let mut processor = mdsh:: executor:: TheProcessor :: new ( workdir, & mut output) ;
52-
53- if let Err ( e) = processor. process ( content, & mdsh:: cli:: FileArg :: StdHandle ) {
54- tracing:: warn!( "Failed to process mdsh content from {:?}: {}" , path, e) ;
55- return content. to_string ( ) ;
56- }
57-
58- String :: from_utf8 ( output) . unwrap_or_else ( |_| content. to_string ( ) )
59- }
60-
61- /// Build the complete system prompt by appending content from SYSTEM.md files.
62- ///
63- /// SYSTEM.md files are processed through mdsh, which executes embedded shell commands.
64- /// This allows dynamic content like `$ git branch --show-current` to be included.
65- ///
66- /// Checks (in order):
67- /// 1. User config: ~/.config/codey/SYSTEM.md
68- /// 2. Project: .codey/SYSTEM.md
69- fn build_system_prompt ( ) -> String {
70- let mut prompt = SYSTEM_PROMPT . to_string ( ) ;
71-
72- // Check user config directory: ~/.config/codey/SYSTEM.md
73- if let Some ( config_dir) = Config :: config_dir ( ) {
74- let user_system_md = config_dir. join ( SYSTEM_MD_FILENAME ) ;
75- if let Ok ( content) = std:: fs:: read_to_string ( & user_system_md) {
76- tracing:: debug!( "Appending user SYSTEM.md from {:?}" , user_system_md) ;
77- let processed = process_mdsh ( & content, & user_system_md) ;
78- prompt. push_str ( "\n \n " ) ;
79- prompt. push_str ( & processed) ;
80- }
81- }
82-
83- // Check project directory: .codey/SYSTEM.md
84- let project_system_md = std:: path:: Path :: new ( CODEY_DIR ) . join ( SYSTEM_MD_FILENAME ) ;
85- if let Ok ( content) = std:: fs:: read_to_string ( & project_system_md) {
86- tracing:: debug!( "Appending project SYSTEM.md from {:?}" , project_system_md) ;
87- let processed = process_mdsh ( & content, & project_system_md) ;
88- prompt. push_str ( "\n \n " ) ;
89- prompt. push_str ( & processed) ;
90- }
91-
92- prompt
93- }
94-
9539/// Result of handling an action
9640enum ActionResult {
9741 NoOp ,
@@ -374,9 +318,10 @@ impl App {
374318 ) ;
375319
376320 // Use dynamic prompt builder so mdsh commands are re-executed on each LLM call
321+ let system_prompt = SystemPrompt :: new ( ) ;
377322 let mut agent = Agent :: with_dynamic_prompt (
378323 AgentRuntimeConfig :: foreground ( & self . config ) ,
379- Box :: new ( build_system_prompt ) ,
324+ Box :: new ( move || system_prompt . build ( ) ) ,
380325 self . oauth . clone ( ) ,
381326 self . tool_executor . tools ( ) . clone ( ) ,
382327 ) ;
0 commit comments