From 0ad60b946fcc2cde38de447208468b7c213d93b0 Mon Sep 17 00:00:00 2001 From: JegernOUTT Date: Mon, 21 Apr 2025 16:53:35 +0930 Subject: [PATCH 1/9] Better compression prompt --- .../engine/src/agentic/compress_trajectory.rs | 136 +++++++++--------- 1 file changed, 69 insertions(+), 67 deletions(-) diff --git a/refact-agent/engine/src/agentic/compress_trajectory.rs b/refact-agent/engine/src/agentic/compress_trajectory.rs index e5dd5b93d..9a65d8f10 100644 --- a/refact-agent/engine/src/agentic/compress_trajectory.rs +++ b/refact-agent/engine/src/agentic/compress_trajectory.rs @@ -2,69 +2,78 @@ use crate::at_commands::at_commands::AtCommandsContext; use crate::call_validation::{ChatContent, ChatMessage}; use crate::global_context::{try_load_caps_quickly_if_not_present, GlobalContext}; use crate::subchat::subchat_single; -use crate::agentic::generate_commit_message::remove_fencing; use std::sync::Arc; use tokio::sync::Mutex as AMutex; use tokio::sync::RwLock as ARwLock; -use tracing::warn; use crate::caps::strip_model_from_finetune; -const COMPRESSION_MESSAGE: &str = r#" -Compress the chat above. - -Guidelines: - -1. Always prefer specifics over generic phrases. Write file names, symbol names, folder names, actions, facts, user attitude -towards entities in the project. If something is junk according to the user, that's the first priority to remember. -2. The first message in the chat is the goal. Summarize it up to 15 words, always prefer specifics. -3. The most important part is decision making by assistant. What new information assistant has learned? Skip the plans, -fluff, explanations for the user. Write one sentense: the evidence (specifics and facts), the thought process, motivated decision. -4. Each tool call should be a separate record. Write all the parameters. Summarize facts about output of a tool, especially the facts -useful for the goal, what the assistant learned, what was surprising to see? -5. Skip unsuccesful calls that are later corrected. Keep the corrected one. -6. When writing paths to files, only output short relative paths from the project dir. -7. The last line is the outcome, pick SUCCESS/FAIL/PROGRESS - -Output format is list of tuples, each tuple is has: -EITHER (1) call with all parameters, maybe shortened, but all parameters, (2) explanation of significance of tool output -OR (1) goal/thinking/coding/outcome (2) string according to the guidelines - -Example: -[ -["goal", "Rename my_function1 to my_function2"], -["thinking", "There are definition(), search(), regex_search() and locate() tools, all can be used to find my_function1, system prompt says I need to start with locate()."], -["locate(problem_statement=\"Rename my_function1 to my_function2\")", "The file my_script.py (1337 lines) has my_function1 on line 42."], -["thinking", "I can rewrite my_function1 inside my_script.py, so I'll do that."], -["update_textdoc(path=\"my_script\", old_str=\"...\", replacement=\"...\", multiple=false)", "The output of update_textdoc() has 15 lines_add and 15 lines_remove, confirming the operation."], -["outcome", "SUCCESS"] -] - -Write only the json and nothing else. -"#; -const TEMPERATURE: f32 = 0.0; +const COMPRESSION_MESSAGE: &str = r#"Your task is to create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions. +This summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing development work without losing context. -fn parse_goal(trajectory: &String) -> Option { - let traj_message_parsed: Vec<(String, String)> = match serde_json::from_str(trajectory.as_str()) { - Ok(data) => data, - Err(e) => { - warn!("Error while parsing: {}\nTrajectory:\n{}", e, trajectory); - return None; - } - }; - let (name, content) = match traj_message_parsed.first() { - Some(data) => data, - None => { - warn!("Empty trajectory:\n{}", trajectory); - return None; - } - }; - if name != "goal" { - warn!("Trajectory does not have a goal message"); - None - } else { - Some(content.clone()) - } -} +Before providing your final summary, wrap your analysis in tags to organize your thoughts and ensure you've covered all necessary points. In your analysis process: + +1. Chronologically analyze each message and section of the conversation. For each section thoroughly identify: + - The user's explicit requests and intents + - Your approach to addressing the user's requests + - Key decisions, technical concepts and code patterns + - Specific details like file names, full code snippets, function signatures, file edits, etc +2. Double-check for technical accuracy and completeness, addressing each required element thoroughly. + +Your summary should include the following sections: + +1. Primary Request and Intent: Capture all of the user's explicit requests and intents in detail +2. Key Technical Concepts: List all important technical concepts, technologies, and frameworks discussed. +3. Files and Code Sections: Enumerate specific files and code sections examined, modified, or created. Pay special attention to the most recent messages and include full code snippets where applicable and include a summary of why this file read or edit is important. +4. Problem Solving: Document problems solved and any ongoing troubleshooting efforts. +5. Pending Tasks: Outline any pending tasks that you have explicitly been asked to work on. +6. Current Work: Describe in detail precisely what was being worked on immediately before this summary request, paying special attention to the most recent messages from both user and assistant. Include file names and code snippets where applicable. +7. Optional Next Step: List the next step that you will take that is related to the most recent work you were doing. IMPORTANT: ensure that this step is DIRECTLY in line with the user's explicit requests, and the task you were working on immediately before this summary request. If your last task was concluded, then only list next steps if they are explicitly in line with the users request. Do not start on tangential requests without confirming with the user first. +8. If there is a next step, include direct quotes from the most recent conversation showing exactly what task you were working on and where you left off. This should be verbatim to ensure there's no drift in task interpretation. + +Here's an example of how your output should be structured: + + + +[Your thought process, ensuring all points are covered thoroughly and accurately] + + + +1. Primary Request and Intent: + [Detailed description] + +2. Key Technical Concepts: + - [Concept 1] + - [Concept 2] + - [...] + +3. Files and Code Sections: + - [File Name 1] + - [Summary of why this file is important] + - [Summary of the changes made to this file, if any] + - [Important Code Snippet] + - [File Name 2] + - [Important Code Snippet] + - [...] + +4. Problem Solving: + [Description of solved problems and ongoing troubleshooting]` + +5. Pending Tasks: + - [Task 1] + - [Task 2] + - [...] + +6. Current Work: + [Precise description of current work] + +7. Optional Next Step: + [Optional Next step to take] + + + + +Please provide your summary based on the conversation so far, following this structure and ensuring precision and thoroughness in your response."#; +const TEMPERATURE: f32 = 0.0; fn gather_used_tools(messages: &Vec) -> Vec { let mut tools: Vec = Vec::new(); @@ -92,12 +101,12 @@ pub async fn compress_trajectory( let (model_id, n_ctx) = match try_load_caps_quickly_if_not_present(gcx.clone(), 0).await { Ok(caps) => { let model_id = caps.defaults.chat_default_model.clone(); - if let Some(model_rec) = caps.completion_models.get(&strip_model_from_finetune(&model_id)) { + if let Some(model_rec) = caps.code_chat_models.get(&strip_model_from_finetune(&model_id)) { Ok((model_id, model_rec.base.n_ctx)) } else { Err(format!( "Model '{}' not found, server has these models: {:?}", - model_id, caps.completion_models.keys() + model_id, caps.code_chat_models.keys() )) } }, @@ -151,12 +160,5 @@ pub async fn compress_trajectory( .flatten() .flatten() .ok_or("No traj message was generated".to_string())?; - let code_blocks = remove_fencing(&content); - let trajectory = if !code_blocks.is_empty() { - code_blocks[0].clone() - } else { - content.clone() - }; - let goal = parse_goal(&trajectory).unwrap_or("".to_string()); - Ok((goal, trajectory)) + Ok(("".to_string(), content)) } From c13bd36c7ab805300023aeca56fdca1b8aeceafe Mon Sep 17 00:00:00 2001 From: JegernOUTT Date: Thu, 10 Apr 2025 15:31:53 +0930 Subject: [PATCH 2/9] Enhance 'multiple' argument handling to accept string booleans --- .../engine/src/tools/file_edit/tool_update_textdoc.rs | 7 +++++++ .../src/tools/file_edit/tool_update_textdoc_regex.rs | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/refact-agent/engine/src/tools/file_edit/tool_update_textdoc.rs b/refact-agent/engine/src/tools/file_edit/tool_update_textdoc.rs index 3dfbdac1b..369658d8d 100644 --- a/refact-agent/engine/src/tools/file_edit/tool_update_textdoc.rs +++ b/refact-agent/engine/src/tools/file_edit/tool_update_textdoc.rs @@ -65,6 +65,13 @@ async fn parse_args( }; let multiple = match args.get("multiple") { Some(Value::Bool(b)) => b.clone(), + Some(Value::String(v)) => match v.to_lowercase().as_str() { + "false" => false, + "true" => true, + _ => { + return Err(format!("argument 'multiple' should be a boolean: {:?}", v)) + } + }, Some(v) => return Err(format!("Error: The 'multiple' argument must be a boolean (true/false) indicating whether to replace all occurrences, but received: {:?}", v)), None => return Err("Error: The 'multiple' argument is required. Please specify true to replace all occurrences or false to replace only the first occurrence.".to_string()) }; diff --git a/refact-agent/engine/src/tools/file_edit/tool_update_textdoc_regex.rs b/refact-agent/engine/src/tools/file_edit/tool_update_textdoc_regex.rs index 8e4a5903b..24e60c2a8 100644 --- a/refact-agent/engine/src/tools/file_edit/tool_update_textdoc_regex.rs +++ b/refact-agent/engine/src/tools/file_edit/tool_update_textdoc_regex.rs @@ -73,8 +73,15 @@ async fn parse_args( }; let multiple = match args.get("multiple") { Some(Value::Bool(b)) => b.clone(), - Some(v) => return Err(format!("argument 'multiple' should be a boolean: {:?}", v)), - None => return Err("argument 'multiple' is required".to_string()) + Some(Value::String(v)) => match v.to_lowercase().as_str() { + "false" => false, + "true" => true, + _ => { + return Err(format!("argument 'multiple' should be a boolean: {:?}", v)) + } + }, + Some(v) => return Err(format!("Error: The 'multiple' argument must be a boolean (true/false) indicating whether to replace all occurrences, but received: {:?}", v)), + None => return Err("Error: The 'multiple' argument is required. Please specify true to replace all occurrences or false to replace only the first occurrence.".to_string()) }; Ok(ToolUpdateTextDocRegexArgs { From 9dc23c3c07427a08be8c07d536288c1cb8f8ad1f Mon Sep 17 00:00:00 2001 From: JegernOUTT Date: Thu, 10 Apr 2025 15:53:21 +0930 Subject: [PATCH 3/9] Add new AT commands for knowledge loading Introduce `@knowledge-load` and `@knowledge-load-last` commands to load knowledge entries based on a search key, memory ID, or most recent entries using the vecdb feature. Update mod.rs to include the new at_knowledge module and register the commands in at_commands.rs. --- .../engine/src/at_commands/at_commands.rs | 4 + .../engine/src/at_commands/at_knowledge.rs | 177 ++++++++++++++++++ refact-agent/engine/src/at_commands/mod.rs | 2 + 3 files changed, 183 insertions(+) create mode 100644 refact-agent/engine/src/at_commands/at_knowledge.rs diff --git a/refact-agent/engine/src/at_commands/at_commands.rs b/refact-agent/engine/src/at_commands/at_commands.rs index 215aa4642..af66b3404 100644 --- a/refact-agent/engine/src/at_commands/at_commands.rs +++ b/refact-agent/engine/src/at_commands/at_commands.rs @@ -103,6 +103,10 @@ pub async fn at_commands_dict(gcx: Arc>) -> HashMap))), #[cfg(feature="vecdb")] ("@search".to_string(), Arc::new(AMutex::new(Box::new(crate::at_commands::at_search::AtSearch::new()) as Box))), + #[cfg(feature="vecdb")] + ("@knowledge-load".to_string(), Arc::new(AMutex::new(Box::new(crate::at_commands::at_knowledge::AtLoadKnowledge::new()) as Box))), + #[cfg(feature="vecdb")] + ("@knowledge-load-last".to_string(), Arc::new(AMutex::new(Box::new(crate::at_commands::at_knowledge::AtLoadLastKnowledge::new()) as Box))), ]); let (ast_on, vecdb_on) = { diff --git a/refact-agent/engine/src/at_commands/at_knowledge.rs b/refact-agent/engine/src/at_commands/at_knowledge.rs new file mode 100644 index 000000000..611802657 --- /dev/null +++ b/refact-agent/engine/src/at_commands/at_knowledge.rs @@ -0,0 +1,177 @@ +use std::sync::Arc; +use std::collections::HashSet; +use async_trait::async_trait; +use tokio::sync::Mutex as AMutex; + +use crate::at_commands::at_commands::{AtCommand, AtCommandsContext, AtParam}; +use crate::at_commands::execute_at::AtCommandMember; +use crate::call_validation::{ContextEnum, ContextFile}; +use crate::vecdb::vdb_highlev::{memories_search, memories_select_all}; +use crate::vecdb::vdb_structs::MemoRecord; + +/// @knowledge-load command - loads knowledge entries by search key or memory ID +pub struct AtLoadKnowledge { + params: Vec>>, +} + +impl AtLoadKnowledge { + pub fn new() -> Self { + AtLoadKnowledge { + params: vec![], + } + } +} + +#[async_trait] +impl AtCommand for AtLoadKnowledge { + fn params(&self) -> &Vec>> { + &self.params + } + + async fn at_execute( + &self, + ccx: Arc>, + _cmd: &mut AtCommandMember, + args: &mut Vec, + ) -> Result<(Vec, String), String> { + if args.is_empty() { + return Err("Usage: @knowledge-load ".to_string()); + } + + let search_key_or_memid = args[0].text.clone(); + let gcx = { + let ccx_locked = ccx.lock().await; + ccx_locked.global_context.clone() + }; + + // TODO: memories_select_all -> memories_select_by_memid (after we merge choredb + memdb combination) + let vec_db = gcx.read().await.vec_db.clone(); + let all_memories = memories_select_all(vec_db.clone()).await?; + let memory_by_id = all_memories.iter() + .find(|m| m.memid == search_key_or_memid); + if let Some(memory) = memory_by_id { + let mut result = String::new(); + result.push_str(&format!("🗃️{}\n", memory.memid)); + result.push_str(&memory.m_payload); + return Ok((vec![ContextEnum::ContextFile(ContextFile { + file_name: format!("knowledge/{}.md", memory.memid), + file_content: result, + line1: 1, + line2: 1, + symbols: Vec::new(), + gradient_type: -1, + usefulness: 0.0 + })], "Knowledge entry loaded".to_string())); + } + + // If not a memory ID, treat as a search key + let mem_top_n = 5; + let memories = memories_search(gcx.clone(), &search_key_or_memid, mem_top_n).await?; + let mut seen_memids = HashSet::new(); + let unique_memories: Vec<_> = memories.results.into_iter() + .filter(|m| seen_memids.insert(m.memid.clone())) + .collect(); + if unique_memories.is_empty() { + return Err(format!("No knowledge entries found for: {}", search_key_or_memid)); + } + let mut results = Vec::new(); + for memory in unique_memories { + let mut content = String::new(); + content.push_str(&format!("🗃️{}\n", memory.memid)); + content.push_str(&memory.m_payload); + results.push(ContextEnum::ContextFile(ContextFile { + file_name: format!("knowledge/{}.md", memory.memid), + file_content: content, + line1: 1, + line2: 1, + symbols: Vec::new(), + gradient_type: -1, + usefulness: 0.0 + })); + } + + let count = results.len(); + Ok((results, format!("Loaded {} knowledge entries", count))) + } + + fn depends_on(&self) -> Vec { + vec!["vecdb".to_string()] + } +} + +/// @knowledge-load-last command - loads the most recent knowledge entries +pub struct AtLoadLastKnowledge { + params: Vec>>, +} + +impl AtLoadLastKnowledge { + pub fn new() -> Self { + AtLoadLastKnowledge { + params: vec![], + } + } +} + +#[async_trait] +impl AtCommand for AtLoadLastKnowledge { + fn params(&self) -> &Vec>> { + &self.params + } + + async fn at_execute( + &self, + ccx: Arc>, + _cmd: &mut AtCommandMember, + args: &mut Vec, + ) -> Result<(Vec, String), String> { + let count = if !args.is_empty() { + args[0].text.parse::().unwrap_or(5) + } else { + 5 // Default to 5 entries + }; + + let gcx = { + let ccx_locked = ccx.lock().await; + ccx_locked.global_context.clone() + }; + + let vec_db = gcx.read().await.vec_db.clone(); + let all_memories = memories_select_all(vec_db.clone()).await?; + + // Sort by memory ID (assuming newer entries have higher IDs) + // This is a simplification - in a real system you might want to sort by timestamp + let mut sorted_memories: Vec = all_memories.clone(); + sorted_memories.sort_by(|a, b| b.memid.cmp(&a.memid)); + + // Take only the requested number of entries + let recent_memories = sorted_memories.into_iter().take(count).collect::>(); + + if recent_memories.is_empty() { + return Err("No knowledge entries found".to_string()); + } + + let mut results = Vec::new(); + for memory in recent_memories { + let mut content = String::new(); + content.push_str(&format!("🗃️{}\n", memory.memid)); + content.push_str(&memory.m_payload); + + results.push(ContextEnum::ContextFile(ContextFile { + file_name: format!("knowledge/{}.md", memory.memid), + file_content: content, + line1: 1, + line2: 1, + symbols: Vec::new(), + gradient_type: -1, + usefulness: 0.0 + })); + } + + let count = results.len(); + Ok((results, format!("Loaded {} most recent knowledge entries", count))) + } + + fn depends_on(&self) -> Vec { + vec!["vecdb".to_string()] + } +} diff --git a/refact-agent/engine/src/at_commands/mod.rs b/refact-agent/engine/src/at_commands/mod.rs index 534c103bd..da2d3868b 100644 --- a/refact-agent/engine/src/at_commands/mod.rs +++ b/refact-agent/engine/src/at_commands/mod.rs @@ -8,3 +8,5 @@ pub mod at_tree; #[cfg(feature="vecdb")] pub mod at_search; +#[cfg(feature="vecdb")] +pub mod at_knowledge; From 775a1ad7343019c71c494ec2b40cb2bcb2b39844 Mon Sep 17 00:00:00 2001 From: JegernOUTT Date: Mon, 21 Apr 2025 15:12:45 +0930 Subject: [PATCH 4/9] Remove obsolete `@knowledge-load-last` command from at_knowledge.rs and at_commands.rs --- .../engine/src/agentic/compress_trajectory.rs | 4 +- .../engine/src/at_commands/at_commands.rs | 2 - .../engine/src/at_commands/at_knowledge.rs | 78 ------------------- 3 files changed, 2 insertions(+), 82 deletions(-) diff --git a/refact-agent/engine/src/agentic/compress_trajectory.rs b/refact-agent/engine/src/agentic/compress_trajectory.rs index 9a65d8f10..49679a23b 100644 --- a/refact-agent/engine/src/agentic/compress_trajectory.rs +++ b/refact-agent/engine/src/agentic/compress_trajectory.rs @@ -101,12 +101,12 @@ pub async fn compress_trajectory( let (model_id, n_ctx) = match try_load_caps_quickly_if_not_present(gcx.clone(), 0).await { Ok(caps) => { let model_id = caps.defaults.chat_default_model.clone(); - if let Some(model_rec) = caps.code_chat_models.get(&strip_model_from_finetune(&model_id)) { + if let Some(model_rec) = caps.chat_models.get(&strip_model_from_finetune(&model_id)) { Ok((model_id, model_rec.base.n_ctx)) } else { Err(format!( "Model '{}' not found, server has these models: {:?}", - model_id, caps.code_chat_models.keys() + model_id, caps.chat_models.keys() )) } }, diff --git a/refact-agent/engine/src/at_commands/at_commands.rs b/refact-agent/engine/src/at_commands/at_commands.rs index af66b3404..c3240a37d 100644 --- a/refact-agent/engine/src/at_commands/at_commands.rs +++ b/refact-agent/engine/src/at_commands/at_commands.rs @@ -105,8 +105,6 @@ pub async fn at_commands_dict(gcx: Arc>) -> HashMap))), #[cfg(feature="vecdb")] ("@knowledge-load".to_string(), Arc::new(AMutex::new(Box::new(crate::at_commands::at_knowledge::AtLoadKnowledge::new()) as Box))), - #[cfg(feature="vecdb")] - ("@knowledge-load-last".to_string(), Arc::new(AMutex::new(Box::new(crate::at_commands::at_knowledge::AtLoadLastKnowledge::new()) as Box))), ]); let (ast_on, vecdb_on) = { diff --git a/refact-agent/engine/src/at_commands/at_knowledge.rs b/refact-agent/engine/src/at_commands/at_knowledge.rs index 611802657..04b553f28 100644 --- a/refact-agent/engine/src/at_commands/at_knowledge.rs +++ b/refact-agent/engine/src/at_commands/at_knowledge.rs @@ -7,7 +7,6 @@ use crate::at_commands::at_commands::{AtCommand, AtCommandsContext, AtParam}; use crate::at_commands::execute_at::AtCommandMember; use crate::call_validation::{ContextEnum, ContextFile}; use crate::vecdb::vdb_highlev::{memories_search, memories_select_all}; -use crate::vecdb::vdb_structs::MemoRecord; /// @knowledge-load command - loads knowledge entries by search key or memory ID pub struct AtLoadKnowledge { @@ -98,80 +97,3 @@ impl AtCommand for AtLoadKnowledge { vec!["vecdb".to_string()] } } - -/// @knowledge-load-last command - loads the most recent knowledge entries -pub struct AtLoadLastKnowledge { - params: Vec>>, -} - -impl AtLoadLastKnowledge { - pub fn new() -> Self { - AtLoadLastKnowledge { - params: vec![], - } - } -} - -#[async_trait] -impl AtCommand for AtLoadLastKnowledge { - fn params(&self) -> &Vec>> { - &self.params - } - - async fn at_execute( - &self, - ccx: Arc>, - _cmd: &mut AtCommandMember, - args: &mut Vec, - ) -> Result<(Vec, String), String> { - let count = if !args.is_empty() { - args[0].text.parse::().unwrap_or(5) - } else { - 5 // Default to 5 entries - }; - - let gcx = { - let ccx_locked = ccx.lock().await; - ccx_locked.global_context.clone() - }; - - let vec_db = gcx.read().await.vec_db.clone(); - let all_memories = memories_select_all(vec_db.clone()).await?; - - // Sort by memory ID (assuming newer entries have higher IDs) - // This is a simplification - in a real system you might want to sort by timestamp - let mut sorted_memories: Vec = all_memories.clone(); - sorted_memories.sort_by(|a, b| b.memid.cmp(&a.memid)); - - // Take only the requested number of entries - let recent_memories = sorted_memories.into_iter().take(count).collect::>(); - - if recent_memories.is_empty() { - return Err("No knowledge entries found".to_string()); - } - - let mut results = Vec::new(); - for memory in recent_memories { - let mut content = String::new(); - content.push_str(&format!("🗃️{}\n", memory.memid)); - content.push_str(&memory.m_payload); - - results.push(ContextEnum::ContextFile(ContextFile { - file_name: format!("knowledge/{}.md", memory.memid), - file_content: content, - line1: 1, - line2: 1, - symbols: Vec::new(), - gradient_type: -1, - usefulness: 0.0 - })); - } - - let count = results.len(); - Ok((results, format!("Loaded {} most recent knowledge entries", count))) - } - - fn depends_on(&self) -> Vec { - vec!["vecdb".to_string()] - } -} From 1b54877ef87b23e13f4b970d6247cece5daa24b7 Mon Sep 17 00:00:00 2001 From: JegernOUTT Date: Wed, 30 Apr 2025 17:51:35 +0930 Subject: [PATCH 5/9] Modify trajectory compression to append conversation prompt in error handling --- refact-agent/engine/src/agentic/compress_trajectory.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/refact-agent/engine/src/agentic/compress_trajectory.rs b/refact-agent/engine/src/agentic/compress_trajectory.rs index 49679a23b..03813406d 100644 --- a/refact-agent/engine/src/agentic/compress_trajectory.rs +++ b/refact-agent/engine/src/agentic/compress_trajectory.rs @@ -160,5 +160,6 @@ pub async fn compress_trajectory( .flatten() .flatten() .ok_or("No traj message was generated".to_string())?; - Ok(("".to_string(), content)) + let compressed_message = format!("{content}\n\nPlease, continue the conversation based on the provided summary"); + Ok(("".to_string(), compressed_message)) } From b6bc1f12725b62fbf0001553407ceb0606913c5c Mon Sep 17 00:00:00 2001 From: JegernOUTT Date: Wed, 30 Apr 2025 15:48:10 +0930 Subject: [PATCH 6/9] Refactor path handling logic to correctly manage absolute paths in tool_create_textdoc.rs --- .../tools/file_edit/tool_create_textdoc.rs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/refact-agent/engine/src/tools/file_edit/tool_create_textdoc.rs b/refact-agent/engine/src/tools/file_edit/tool_create_textdoc.rs index b0dd68df9..b2940ceaf 100644 --- a/refact-agent/engine/src/tools/file_edit/tool_create_textdoc.rs +++ b/refact-agent/engine/src/tools/file_edit/tool_create_textdoc.rs @@ -40,19 +40,23 @@ async fn parse_args( s.trim() )); }; - let path = if let Some(parent) = raw_path.parent() { - let parent_str = parent.to_string_lossy().to_string(); - let candidates_dir = correct_to_nearest_dir_path(gcx.clone(), &parent_str, false, 3).await; - let candidate_parent_dir = match return_one_candidate_or_a_good_error(gcx.clone(), &parent_str, &candidates_dir, &get_project_dirs(gcx.clone()).await, true).await { - Ok(f) => f, - Err(e) => return Err(e) - }; - canonicalize_normalized_path(PathBuf::from(candidate_parent_dir).join(filename_str)) + let path = if !raw_path.is_absolute() { + if let Some(parent) = raw_path.parent() { + let parent_str = parent.to_string_lossy().to_string(); + let candidates_dir = correct_to_nearest_dir_path(gcx.clone(), &parent_str, false, 3).await; + let candidate_parent_dir = match return_one_candidate_or_a_good_error(gcx.clone(), &parent_str, &candidates_dir, &get_project_dirs(gcx.clone()).await, true).await { + Ok(f) => f, + Err(e) => return Err(e) + }; + canonicalize_normalized_path(PathBuf::from(candidate_parent_dir).join(filename_str)) + } else { + return Err(format!( + "Error: The provided path '{}' is not absolute. Please provide a full path starting from the root directory.", + s.trim() + )); + } } else { - return Err(format!( - "Error: The provided path '{}' is not absolute. Please provide a full path starting from the root directory.", - s.trim() - )); + raw_path }; if check_file_privacy(privacy_settings, &path, &FilePrivacyLevel::AllowToSendAnywhere).is_err() { return Err(format!( From 01bd48f9b4b4b778ce2c4ade987d97b3f70c668c Mon Sep 17 00:00:00 2001 From: JegernOUTT Date: Mon, 28 Apr 2025 16:50:14 +0930 Subject: [PATCH 7/9] Handle decorated definitions in Python AST parsing and add test case --- refact-agent/engine/src/ast/parse_python.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/refact-agent/engine/src/ast/parse_python.rs b/refact-agent/engine/src/ast/parse_python.rs index 18ec938bb..f75b33dd7 100644 --- a/refact-agent/engine/src/ast/parse_python.rs +++ b/refact-agent/engine/src/ast/parse_python.rs @@ -787,6 +787,18 @@ fn py_body<'a>(cx: &mut ContextPy, node: &Node<'a>, path: &Vec) -> Strin }, "class_definition" => py_class(cx, node, path), // calls py_body recursively "function_definition" => py_function(cx, node, path), // calls py_body recursively + "decorated_definition" => { + if let Some(definition) = node.child_by_field_name("definition") { + match definition.kind() { + "class_definition" => py_class(cx, &definition, path), + "function_definition" => py_function(cx, &definition, path), + _ => { + let msg = cx.ap.error_report(&definition, format!("decorated_definition with unknown definition type")); + debug!(cx, "{}", msg); + } + } + } + }, "assignment" => py_assignment(cx, node, path, false), "for_statement" => { py_assignment(cx, node, path, true); @@ -911,4 +923,11 @@ mod tests { let annotated = py_parse4test(code); std::fs::write("src/ast/alt_testsuite/py_goat_main_annotated.py", annotated).expect("Unable to write file"); } + + #[test] + fn test_parse_py_decorated() { + let code = include_str!("alt_testsuite/py_decorated.py"); + let annotated = py_parse4test(code); + std::fs::write("src/ast/alt_testsuite/py_decorated_annotated.py", annotated).expect("Unable to write file"); + } } From 1a3c482849edd4604947c451fdb19ab4953d54db Mon Sep 17 00:00:00 2001 From: JegernOUTT Date: Wed, 30 Apr 2025 18:12:55 +0930 Subject: [PATCH 8/9] Add o4-mini model entry to known_models.json configuration --- refact-agent/engine/src/known_models.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/refact-agent/engine/src/known_models.json b/refact-agent/engine/src/known_models.json index bc29a9dac..f2a375db7 100644 --- a/refact-agent/engine/src/known_models.json +++ b/refact-agent/engine/src/known_models.json @@ -433,6 +433,21 @@ "similar_models": [ "openai/o3-mini" ] + }, + "o4-mini": { + "n_ctx": 200000, + "supports_tools": true, + "supports_multimodality": true, + "supports_agent": true, + "supports_reasoning": "openai", + "supports_boost_reasoning": true, + "scratchpad": "PASSTHROUGH", + "tokenizer": "hf://Xenova/gpt-4o", + "similar_models": [ + "openai/o4-mini", + "o3", + "openai/o3" + ] }, "gpt-4.5-preview": { "n_ctx": 128000, From 8a723182fd6f248eefde87a106804a793bfc4c7a Mon Sep 17 00:00:00 2001 From: JegernOUTT Date: Wed, 30 Apr 2025 18:20:40 +0930 Subject: [PATCH 9/9] Remove redundant test for parsing decorated Python code --- refact-agent/engine/src/ast/parse_python.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/refact-agent/engine/src/ast/parse_python.rs b/refact-agent/engine/src/ast/parse_python.rs index f75b33dd7..723da8c69 100644 --- a/refact-agent/engine/src/ast/parse_python.rs +++ b/refact-agent/engine/src/ast/parse_python.rs @@ -923,11 +923,4 @@ mod tests { let annotated = py_parse4test(code); std::fs::write("src/ast/alt_testsuite/py_goat_main_annotated.py", annotated).expect("Unable to write file"); } - - #[test] - fn test_parse_py_decorated() { - let code = include_str!("alt_testsuite/py_decorated.py"); - let annotated = py_parse4test(code); - std::fs::write("src/ast/alt_testsuite/py_decorated_annotated.py", annotated).expect("Unable to write file"); - } }