feat: inject global rules into AI system prompt and fix Rules UI seeding
- Load global rules (AIFact/AIMemory) from local CloudModel and inject them into the Bedrock/OpenAI system prompt as a '## Global Rules' section when memory is enabled. - Fix rule seeding: always re-seed predefined rules when the CloudModel has none, regardless of the has_seeded_predefined_rules flag (handles case where flag was set but rules never persisted due to prior missing owner). - Rename /context slash command to /copy-context: dumps the full context window (global rules, progressive summary, message history) to the clipboard for debugging.
This commit is contained in:
@@ -1890,7 +1890,7 @@ async fn test_full_proto_round_trip_with_tool_history() {
|
||||
);
|
||||
|
||||
let messages = super::request_translator::extract_messages_from_request(&request);
|
||||
let system_prompt = super::request_translator::extract_system_prompt(&request);
|
||||
let system_prompt = super::request_translator::extract_system_prompt(&request, &[]);
|
||||
let tools = super::request_translator::extract_tools(&request);
|
||||
|
||||
println!("\n=== FULL PROTO ROUND-TRIP TEST ===");
|
||||
|
||||
@@ -954,7 +954,7 @@ fn collect_tool_result_ids(content: &MessageContent, ids: &mut std::collections:
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extract_system_prompt(request: &api::Request) -> Option<String> {
|
||||
pub fn extract_system_prompt(request: &api::Request, global_rules: &[(String, String)]) -> Option<String> {
|
||||
let mut prompt = String::with_capacity(2048);
|
||||
|
||||
prompt.push_str("You are Galaxy, an AI coding assistant embedded in a terminal application. You help users with software engineering tasks including writing code, debugging, explaining concepts, and navigating codebases.\n\n");
|
||||
@@ -1009,6 +1009,19 @@ pub fn extract_system_prompt(request: &api::Request) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
// Inject global rules from the local CloudModel (stored as AIFact/AIMemory)
|
||||
if !global_rules.is_empty() {
|
||||
prompt.push_str("## Global Rules\n");
|
||||
prompt.push_str("The following rules have been configured by the user and should be followed:\n\n");
|
||||
for (name, content) in global_rules {
|
||||
if !name.is_empty() {
|
||||
prompt.push_str(&format!("### {}\n", name));
|
||||
}
|
||||
prompt.push_str(content);
|
||||
prompt.push_str("\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
prompt.push_str("## Tool Usage\n");
|
||||
prompt.push_str("You have been given every tool you need to complete your tasks. Use them to achieve results with as few calls and as little back-and-forth as possible.\n\n");
|
||||
prompt.push_str("**How to choose tools:**\n");
|
||||
|
||||
@@ -18,6 +18,8 @@ pub struct TranslatorRequest {
|
||||
pub bedrock_tool_result_archive: Vec<ConversationMessage>,
|
||||
pub bedrock_progressive_summary: Option<String>,
|
||||
pub bedrock_messages_sent: Arc<Mutex<Vec<ConversationMessage>>>,
|
||||
/// Global rules (name, content) from the local CloudModel.
|
||||
pub global_rules: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
pub async fn execute(
|
||||
@@ -104,7 +106,7 @@ pub async fn execute(
|
||||
|
||||
request_translator::sanitize_messages_for_bedrock(&mut messages);
|
||||
|
||||
let system_prompt = request_translator::extract_system_prompt(request);
|
||||
let system_prompt = request_translator::extract_system_prompt(request, ¶ms.global_rules);
|
||||
let tools = request_translator::extract_tools(request);
|
||||
|
||||
log::info!(
|
||||
|
||||
Reference in New Issue
Block a user