From dfa0e4bfa22ebd40fe66fd5c5e0bd68983ea0d5e Mon Sep 17 00:00:00 2001 From: "Dhanji R. Prasanna" Date: Tue, 27 Jan 2026 11:46:17 +1100 Subject: [PATCH] refactor(g3-core): add section markers to lib.rs for better organization Added clear section comments to organize the 3000-line lib.rs into logical groupings: - CONSTRUCTION METHODS (~line 159) - CONFIGURATION & PROVIDER RESOLUTION (~line 444) - TASK EXECUTION (~line 782) - SESSION MANAGEMENT (~line 1069) - CONTEXT WINDOW OPERATIONS (~line 1148) - STREAMING & LLM INTERACTION (~line 1563) - TOOL EXECUTION (~line 2825) This improves code navigation and provides clear boundaries for future extraction into separate modules. No behavioral changes - all 191 tests pass. Agent: fowler --- crates/g3-core/src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/g3-core/src/lib.rs b/crates/g3-core/src/lib.rs index 616a015..41d7371 100644 --- a/crates/g3-core/src/lib.rs +++ b/crates/g3-core/src/lib.rs @@ -153,6 +153,10 @@ pub struct Agent { } impl Agent { + // ========================================================================= + // CONSTRUCTION METHODS + // ========================================================================= + pub async fn new(config: Config, ui_writer: W) -> Result { Self::new_with_mode(config, ui_writer, false, false).await } @@ -436,6 +440,10 @@ impl Agent { }) } + // ========================================================================= + // CONFIGURATION & PROVIDER RESOLUTION + // ========================================================================= + /// Validate that the system prompt is the first message in the conversation history. /// This is a critical invariant that must be maintained for proper agent operation. /// @@ -772,6 +780,10 @@ impl Agent { self.session_id.as_deref() } + // ========================================================================= + // TASK EXECUTION + // ========================================================================= + pub async fn execute_task( &mut self, description: &str, @@ -1050,6 +1062,10 @@ impl Agent { Ok(task_result) } + // ========================================================================= + // SESSION MANAGEMENT + // ========================================================================= + /// Generate a session ID based on the initial prompt fn generate_session_id(&self, description: &str) -> String { session::generate_session_id(description, self.agent_name.as_deref()) @@ -1124,6 +1140,10 @@ impl Agent { } } + // ========================================================================= + // CONTEXT WINDOW OPERATIONS + // ========================================================================= + /// Manually trigger context compaction regardless of context window size /// Returns Ok(true) if compaction was successful, Ok(false) if it failed pub async fn force_compact(&mut self) -> Result { @@ -1536,6 +1556,10 @@ impl Agent { ); } + // ========================================================================= + // STREAMING & LLM INTERACTION + // ========================================================================= + /// Build the final response and prepare for return. /// /// This is the single canonical path for completing a streaming turn: @@ -2795,6 +2819,10 @@ Skip if nothing new. Be brief."#; )) } + // ========================================================================= + // TOOL EXECUTION + // ========================================================================= + pub async fn execute_tool(&mut self, tool_call: &ToolCall) -> Result { // Tool tracking is handled by execute_tool_in_dir self.execute_tool_in_dir(tool_call, None).await