Remove automatic README loading from context window
README.md is no longer auto-loaded into the LLM context at startup. This saves ~4,600 tokens per session while AGENTS.md and memory.md still provide all critical information for code tasks. Changes: - Delete read_project_readme() function - Remove readme_content parameter from combine_project_content() - Rename extract_readme_heading() -> extract_project_heading() - Rename Agent constructors: *_with_readme_* -> *_with_project_context_* - Update context preservation to only check for Agent Configuration - Remove has_readme field from LoadedContent - Update all tests to use new markers and function names The LLM can still read README.md on-demand via read_file when needed.
This commit is contained in:
@@ -283,8 +283,8 @@ Format this as a detailed but concise summary that can be used to resume the con
|
||||
if let Some(system_prompt) = preserved.system_prompt {
|
||||
self.add_message(system_prompt);
|
||||
}
|
||||
if let Some(readme) = preserved.readme {
|
||||
self.add_message(readme);
|
||||
if let Some(project_context) = preserved.project_context {
|
||||
self.add_message(project_context);
|
||||
}
|
||||
|
||||
// Add ACD stub if provided (before summary so LLM knows about dehydrated context)
|
||||
@@ -322,10 +322,10 @@ Format this as a detailed but concise summary that can be used to resume the con
|
||||
fn extract_preserved_messages(&self) -> PreservedMessages {
|
||||
let system_prompt = self.conversation_history.first().cloned();
|
||||
|
||||
let readme = self.conversation_history.get(1).and_then(|msg| {
|
||||
// Look for project context (AGENTS.md, memory, etc.) in the second message
|
||||
let project_context = self.conversation_history.get(1).and_then(|msg| {
|
||||
if matches!(msg.role, MessageRole::System)
|
||||
&& (msg.content.contains("Project README")
|
||||
|| msg.content.contains("Agent Configuration"))
|
||||
&& msg.content.contains("Agent Configuration")
|
||||
{
|
||||
Some(msg.clone())
|
||||
} else {
|
||||
@@ -343,7 +343,7 @@ Format this as a detailed but concise summary that can be used to resume the con
|
||||
|
||||
PreservedMessages {
|
||||
system_prompt,
|
||||
readme,
|
||||
project_context,
|
||||
last_assistant_message,
|
||||
}
|
||||
}
|
||||
@@ -740,7 +740,7 @@ Format this as a detailed but concise summary that can be used to resume the con
|
||||
/// Messages preserved across compaction.
|
||||
struct PreservedMessages {
|
||||
system_prompt: Option<Message>,
|
||||
readme: Option<Message>,
|
||||
project_context: Option<Message>,
|
||||
last_assistant_message: Option<Message>,
|
||||
}
|
||||
|
||||
|
||||
@@ -214,22 +214,22 @@ impl<W: UiWriter> Agent<W> {
|
||||
Self::new_with_mode(config, ui_writer, true, false).await
|
||||
}
|
||||
|
||||
pub async fn new_with_readme_and_quiet(
|
||||
pub async fn new_with_project_context_and_quiet(
|
||||
config: Config,
|
||||
ui_writer: W,
|
||||
readme_content: Option<String>,
|
||||
project_context: Option<String>,
|
||||
quiet: bool,
|
||||
) -> Result<Self> {
|
||||
Self::new_with_mode_and_readme(config, ui_writer, false, readme_content, quiet, None).await
|
||||
Self::new_with_mode_and_project_context(config, ui_writer, false, project_context, quiet, None).await
|
||||
}
|
||||
|
||||
pub async fn new_autonomous_with_readme_and_quiet(
|
||||
pub async fn new_autonomous_with_project_context_and_quiet(
|
||||
config: Config,
|
||||
ui_writer: W,
|
||||
readme_content: Option<String>,
|
||||
project_context: Option<String>,
|
||||
quiet: bool,
|
||||
) -> Result<Self> {
|
||||
Self::new_with_mode_and_readme(config, ui_writer, true, readme_content, quiet, None).await
|
||||
Self::new_with_mode_and_project_context(config, ui_writer, true, project_context, quiet, None).await
|
||||
}
|
||||
|
||||
/// Create a new agent with a custom system prompt (for agent mode)
|
||||
@@ -238,13 +238,13 @@ impl<W: UiWriter> Agent<W> {
|
||||
config: Config,
|
||||
ui_writer: W,
|
||||
custom_system_prompt: String,
|
||||
readme_content: Option<String>,
|
||||
project_context: Option<String>,
|
||||
) -> Result<Self> {
|
||||
Self::new_with_mode_and_readme(
|
||||
Self::new_with_mode_and_project_context(
|
||||
config,
|
||||
ui_writer,
|
||||
false,
|
||||
readme_content,
|
||||
project_context,
|
||||
false,
|
||||
Some(custom_system_prompt),
|
||||
)
|
||||
@@ -261,17 +261,17 @@ impl<W: UiWriter> Agent<W> {
|
||||
ui_writer: W,
|
||||
providers: ProviderRegistry,
|
||||
) -> Result<Self> {
|
||||
Self::new_for_test_with_readme(config, ui_writer, providers, None).await
|
||||
Self::new_for_test_with_project_context(config, ui_writer, providers, None).await
|
||||
}
|
||||
|
||||
/// Create a new agent for testing with README content.
|
||||
/// Create a new agent for testing with project context.
|
||||
/// This allows tests to verify context window structure with combined content.
|
||||
#[doc(hidden)]
|
||||
pub async fn new_for_test_with_readme(
|
||||
pub async fn new_for_test_with_project_context(
|
||||
config: Config,
|
||||
ui_writer: W,
|
||||
providers: ProviderRegistry,
|
||||
readme_content: Option<String>,
|
||||
project_context: Option<String>,
|
||||
) -> Result<Self> {
|
||||
use crate::context_window::ContextWindow;
|
||||
use crate::prompts::get_system_prompt_for_native;
|
||||
@@ -285,10 +285,10 @@ impl<W: UiWriter> Agent<W> {
|
||||
let system_message = Message::new(MessageRole::System, system_prompt);
|
||||
context_window.add_message(system_message);
|
||||
|
||||
// Add README content if provided
|
||||
if let Some(readme) = readme_content {
|
||||
let readme_message = Message::new(MessageRole::System, readme);
|
||||
context_window.add_message(readme_message);
|
||||
// Add project context if provided
|
||||
if let Some(context) = project_context {
|
||||
let context_message = Message::new(MessageRole::System, context);
|
||||
context_window.add_message(context_message);
|
||||
}
|
||||
|
||||
// For tests: auto_compact=false, is_autonomous=false, quiet=true, no computer_controller
|
||||
@@ -310,14 +310,14 @@ impl<W: UiWriter> Agent<W> {
|
||||
is_autonomous: bool,
|
||||
quiet: bool,
|
||||
) -> Result<Self> {
|
||||
Self::new_with_mode_and_readme(config, ui_writer, is_autonomous, None, quiet, None).await
|
||||
Self::new_with_mode_and_project_context(config, ui_writer, is_autonomous, None, quiet, None).await
|
||||
}
|
||||
|
||||
async fn new_with_mode_and_readme(
|
||||
async fn new_with_mode_and_project_context(
|
||||
config: Config,
|
||||
ui_writer: W,
|
||||
is_autonomous: bool,
|
||||
readme_content: Option<String>,
|
||||
project_context: Option<String>,
|
||||
quiet: bool,
|
||||
custom_system_prompt: Option<String>,
|
||||
) -> Result<Self> {
|
||||
@@ -361,10 +361,10 @@ impl<W: UiWriter> Agent<W> {
|
||||
let system_message = Message::new(MessageRole::System, system_prompt);
|
||||
context_window.add_message(system_message);
|
||||
|
||||
// If README content is provided, add it as a second system message (after the main system prompt)
|
||||
if let Some(readme) = readme_content {
|
||||
let readme_message = Message::new(MessageRole::System, readme);
|
||||
context_window.add_message(readme_message);
|
||||
// If project context is provided, add it as a second system message (after the main system prompt)
|
||||
if let Some(context) = project_context {
|
||||
let context_message = Message::new(MessageRole::System, context);
|
||||
context_window.add_message(context_message);
|
||||
}
|
||||
|
||||
// NOTE: TODO lists are now session-scoped and stored in .g3/sessions/<session_id>/todo.g3.md
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Integration tests for project context loading and ordering.
|
||||
//!
|
||||
//! Tests that the context window has the correct structure when projects are loaded.
|
||||
//! Tests that the context window has the correct structure when project context is loaded.
|
||||
//! Also tests that project content survives compaction.
|
||||
|
||||
use g3_core::{
|
||||
@@ -11,7 +11,7 @@ use g3_config::Config;
|
||||
use g3_providers::{mock::MockProvider, ProviderRegistry, MockResponse, MessageRole};
|
||||
|
||||
/// Helper to create a test agent with mock provider
|
||||
async fn create_test_agent(readme_content: Option<String>) -> Agent<NullUiWriter> {
|
||||
async fn create_test_agent(project_context: Option<String>) -> Agent<NullUiWriter> {
|
||||
let config = Config::default();
|
||||
let provider = MockProvider::new()
|
||||
.with_response(MockResponse::text("Test response"));
|
||||
@@ -19,7 +19,7 @@ async fn create_test_agent(readme_content: Option<String>) -> Agent<NullUiWriter
|
||||
let mut registry = ProviderRegistry::new();
|
||||
registry.register(provider);
|
||||
|
||||
Agent::new_for_test_with_readme(config, NullUiWriter, registry, readme_content)
|
||||
Agent::new_for_test_with_project_context(config, NullUiWriter, registry, project_context)
|
||||
.await
|
||||
.expect("Failed to create test agent")
|
||||
}
|
||||
@@ -337,7 +337,7 @@ async fn create_agent_with_mock_and_readme(
|
||||
let mut registry = ProviderRegistry::new();
|
||||
registry.register(provider);
|
||||
|
||||
Agent::new_for_test_with_readme(config, NullUiWriter, registry, readme_content)
|
||||
Agent::new_for_test_with_project_context(config, NullUiWriter, registry, readme_content)
|
||||
.await
|
||||
.expect("Failed to create test agent")
|
||||
}
|
||||
|
||||
@@ -104,9 +104,9 @@ fn test_reset_with_summary_and_stub_no_stub() {
|
||||
assert!(has_summary, "Should have summary");
|
||||
}
|
||||
|
||||
/// Test that README message is preserved during reset
|
||||
/// Test that project context message is preserved during reset
|
||||
#[test]
|
||||
fn test_reset_preserves_readme() {
|
||||
fn test_reset_preserves_project_context() {
|
||||
let mut context = ContextWindow::new(100000);
|
||||
|
||||
// Add system prompt
|
||||
@@ -115,10 +115,10 @@ fn test_reset_preserves_readme() {
|
||||
"You are a helpful assistant.".to_string(),
|
||||
));
|
||||
|
||||
// Add README message (second system message with specific content)
|
||||
// Add project context message (second system message with Agent Configuration)
|
||||
context.add_message(Message::new(
|
||||
MessageRole::System,
|
||||
"Project README: This is a test project.".to_string(),
|
||||
"🤖 Agent Configuration (from AGENTS.md):\nTest agent config.".to_string(),
|
||||
));
|
||||
|
||||
// Add conversation
|
||||
@@ -133,11 +133,11 @@ fn test_reset_preserves_readme() {
|
||||
Some(stub),
|
||||
);
|
||||
|
||||
// README should be preserved
|
||||
let has_readme = context.conversation_history.iter().any(|m|
|
||||
m.content.contains("Project README")
|
||||
// Project context should be preserved
|
||||
let has_project_context = context.conversation_history.iter().any(|m|
|
||||
m.content.contains("Agent Configuration")
|
||||
);
|
||||
assert!(has_readme, "README message should be preserved");
|
||||
assert!(has_project_context, "Project context message should be preserved");
|
||||
}
|
||||
|
||||
/// Test fragment chain integrity
|
||||
|
||||
@@ -15,7 +15,7 @@ use tempfile::TempDir;
|
||||
async fn create_test_agent(temp_dir: &TempDir) -> Agent<NullUiWriter> {
|
||||
std::env::set_current_dir(temp_dir.path()).unwrap();
|
||||
let config = Config::default();
|
||||
Agent::new_with_readme_and_quiet(config, NullUiWriter, None, true)
|
||||
Agent::new_with_project_context_and_quiet(config, NullUiWriter, None, true)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
@@ -24,7 +24,7 @@ async fn create_test_agent(temp_dir: &TempDir) -> Agent<NullUiWriter> {
|
||||
async fn create_agent_mode_agent(temp_dir: &TempDir, agent_name: &str) -> Agent<NullUiWriter> {
|
||||
std::env::set_current_dir(temp_dir.path()).unwrap();
|
||||
let config = Config::default();
|
||||
let mut agent = Agent::new_with_readme_and_quiet(config, NullUiWriter, None, true)
|
||||
let mut agent = Agent::new_with_project_context_and_quiet(config, NullUiWriter, None, true)
|
||||
.await
|
||||
.unwrap();
|
||||
agent.set_agent_mode(agent_name);
|
||||
|
||||
@@ -54,18 +54,18 @@ fn test_reset_with_summary_preserves_system_prompt() {
|
||||
assert!(has_user_msg, "Should have the latest user message");
|
||||
}
|
||||
|
||||
/// Test that reset_with_summary preserves README message if present
|
||||
/// Test that reset_with_summary preserves project context message if present
|
||||
#[test]
|
||||
fn test_reset_with_summary_preserves_readme() {
|
||||
fn test_reset_with_summary_preserves_project_context() {
|
||||
let mut context = ContextWindow::new(10000);
|
||||
|
||||
// Add the system prompt as the first message
|
||||
let system_prompt = "You are G3, an AI programming agent...";
|
||||
context.add_message(Message::new(MessageRole::System, system_prompt.to_string()));
|
||||
|
||||
// Add README as second system message
|
||||
let readme_content = "# Project README\n\nThis is a test project.";
|
||||
context.add_message(Message::new(MessageRole::System, readme_content.to_string()));
|
||||
// Add project context as second system message (with Agent Configuration marker)
|
||||
let project_context = "🤖 Agent Configuration (from AGENTS.md):\n\nTest agent config.";
|
||||
context.add_message(Message::new(MessageRole::System, project_context.to_string()));
|
||||
|
||||
// Add some conversation history
|
||||
context.add_message(Message::new(MessageRole::User, "Task: Write a function".to_string()));
|
||||
@@ -85,15 +85,15 @@ fn test_reset_with_summary_preserves_readme() {
|
||||
"First message should be the system prompt"
|
||||
);
|
||||
|
||||
// Verify the README was preserved as the second message
|
||||
// Verify the project context was preserved as the second message
|
||||
let second_message = &context.conversation_history[1];
|
||||
assert!(
|
||||
matches!(second_message.role, MessageRole::System),
|
||||
"Second message should be a System message"
|
||||
);
|
||||
assert!(
|
||||
second_message.content.contains("Project README"),
|
||||
"Second message should be the README"
|
||||
second_message.content.contains("Agent Configuration"),
|
||||
"Second message should be the project context"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user