Skip to content

Commit 6cf2f6d

Browse files
committed
Centralize config paths and prompts into dedicated modules
- Add CODEY_DIR and TRANSCRIPTS_DIR constants to config.rs - Create prompts.rs with all system prompts (SYSTEM_PROMPT, COMPACTION_PROMPT, SUB_AGENT_PROMPT, WELCOME_MESSAGE) - Update app.rs to import from config and prompts modules - Update transcript.rs to import paths from config - Update spawn_agent.rs to import prompt from prompts module - Add prompts module to lib.rs and main.rs This removes the cross-module dependencies that required importing from app.rs, making the codebase cleaner and avoiding issues with library builds.
1 parent 49119e8 commit 6cf2f6d

7 files changed

Lines changed: 106 additions & 91 deletions

File tree

src/app.rs

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -17,86 +17,25 @@ use ratatui::{
1717
use tokio::sync::oneshot;
1818

1919
use crate::commands::Command;
20-
use crate::config::{AgentRuntimeConfig, Config};
20+
use crate::config::{AgentRuntimeConfig, Config, CODEY_DIR};
2121
use crate::ide::{Ide, IdeEvent, Nvim};
2222
use crate::llm::{Agent, AgentId, AgentRegistry, AgentStep, RequestMode};
2323
#[cfg(feature = "profiling")]
2424
use crate::{profile_frame, profile_span};
25+
use crate::prompts::{COMPACTION_PROMPT, SYSTEM_MD_FILENAME, SYSTEM_PROMPT, WELCOME_MESSAGE};
2526
use crate::tool_filter::ToolFilters;
2627
use crate::tools::{
2728
init_agent_context, update_agent_oauth, Effect, ToolCall, ToolDecision, ToolEvent,
2829
ToolExecutor, ToolRegistry,
2930
};
30-
use crate::transcript::{BlockType, Role, Status, TextBlock, Transcript, CODEY_DIR};
31+
use crate::transcript::{BlockType, Role, Status, TextBlock, Transcript};
3132
use crate::ui::{Attachment, ChatView, InputBox};
3233

3334
const MIN_FRAME_TIME: Duration = Duration::from_millis(16);
3435

3536
pub const APP_NAME: &str = "Codey";
3637
pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
3738

38-
const WELCOME_MESSAGE: &str =
39-
"Welcome to Codey! I'm your AI coding assistant. How can I help you today?";
40-
const SYSTEM_PROMPT: &str = r#"You are Codey, an AI coding assistant running in a terminal interface.
41-
42-
## Capabilities
43-
You have access to the following tools:
44-
- `read_file`: Read file contents, optionally with line ranges
45-
- `write_file`: Create new files
46-
- `edit_file`: Make precise edits using search/replace
47-
- `shell`: Execute bash commands
48-
- `fetch_url`: Fetch web content
49-
50-
## Guidelines
51-
52-
### Reading Files
53-
- Always read a file before editing it
54-
- Use line ranges for large files: `read_file(path, start_line=100, end_line=200)`
55-
- Use `shell("ls -la")` to explore directories
56-
- When reading files, be careful about reading large files in one-go. Use line ranges,
57-
or check the file stats with `shell("stat <file_path>")` first.
58-
- shell grep is a great way to get a line number to read a targeted section of a file
59-
60-
### Editing Files
61-
- Use `edit_file` for existing files, `write_file` only for new files
62-
- The `old_string` must match EXACTLY, including whitespace and indentation
63-
- If `old_string` appears multiple times, include more context to make it unique
64-
- Apply edits sequentially; each edit sees the result of previous edits
65-
- You can do multiple edits at once, but keep it under 1000 lines
66-
- Avoid the urge to completely rewrite files - make precise, minimal edits so the user can review them easily
67-
68-
### Shell Commands
69-
- Prefer `read_file` over `cat`, `head`, `tail`
70-
- Use `ls` for directory exploration
71-
- Use `grep` or `rg` for searching code
72-
73-
### Background Execution
74-
For long-running operations, you can execute tools in the background by adding `"background": true` to the tool call. This returns immediately with a task ID while the tool runs asynchronously.
75-
Use `list_background_tasks` to check status and `get_background_task` to retrieve results when complete.
76-
77-
### General
78-
- Be concise but thorough
79-
- Explain what you're doing before executing tools
80-
- If a tool fails, explain the error and suggest fixes
81-
- Ask for clarification if the request is ambiguous
82-
- If you feel like backing out of a path, always get confirmation before git resetting the work tree
83-
- Always get confirmation before making destructive changes (this includes building a release)
84-
"#;
85-
const COMPACTION_PROMPT: &str = r#"The conversation context is getting large and needs to be compacted.
86-
87-
Please provide a comprehensive summary of our conversation so far in markdown format. Include:
88-
89-
1. **What was accomplished** - Main tasks and changes completed as a bulleted list
90-
2. **What still needs to be done** - Remaining tasks or open areas of work as a bulleted list
91-
3. **Key project information** - Important facts about the project that the user has shared or that we're not immediately apparent
92-
4. **Relevant files** - Files most relevant to the current work with brief descriptions, line numbers, or method/variable names
93-
5. **Relevant documentation paths or URLs** - Links to docs or resources we will use to continue our work
94-
6. **Quotes and log snippets** - Any important quotes or logs that the user provided that we'll need later
95-
96-
Be thorough but concise - this summary will seed a fresh conversation context."#;
97-
98-
const SYSTEM_MD_FILENAME: &str = "SYSTEM.md";
99-
10039
/// Build the complete system prompt by appending content from SYSTEM.md files.
10140
/// Checks (in order):
10241
/// 1. User config: ~/.config/codey/SYSTEM.md

src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ use crate::tools::{
1111
EditFileTool, FetchUrlTool, ReadFileTool, ShellTool, WebSearchTool, WriteFileTool,
1212
};
1313

14+
/// Directory name for Codey project-level configuration and data
15+
pub const CODEY_DIR: &str = ".codey";
16+
17+
/// Directory name for storing conversation transcripts
18+
pub const TRANSCRIPTS_DIR: &str = "transcripts";
19+
1420
/// Main configuration structure
1521
#[derive(Debug, Clone, Serialize, Deserialize)]
1622
#[serde(default)]

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ mod compaction;
4545
mod config;
4646
mod ide;
4747
mod llm;
48+
mod prompts;
4849
mod tool_filter;
4950
mod tools;
5051
mod transcript;

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod ide;
77
mod llm;
88
#[cfg(feature = "profiling")]
99
mod profiler;
10+
mod prompts;
1011
mod tool_filter;
1112
mod tools;
1213
mod transcript;

src/prompts.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//! Centralized prompt definitions for Codey
2+
//!
3+
//! This module contains all system prompts used throughout the application.
4+
5+
/// Welcome message shown when the application starts
6+
pub const WELCOME_MESSAGE: &str =
7+
"Welcome to Codey! I'm your AI coding assistant. How can I help you today?";
8+
9+
/// Main system prompt for the primary agent
10+
pub const SYSTEM_PROMPT: &str = r#"You are Codey, an AI coding assistant running in a terminal interface.
11+
12+
## Capabilities
13+
You have access to the following tools:
14+
- `read_file`: Read file contents, optionally with line ranges
15+
- `write_file`: Create new files
16+
- `edit_file`: Make precise edits using search/replace
17+
- `shell`: Execute bash commands
18+
- `fetch_url`: Fetch web content
19+
20+
## Guidelines
21+
22+
### Reading Files
23+
- Always read a file before editing it
24+
- Use line ranges for large files: `read_file(path, start_line=100, end_line=200)`
25+
- Use `shell("ls -la")` to explore directories
26+
- When reading files, be careful about reading large files in one-go. Use line ranges,
27+
or check the file stats with `shell("stat <file_path>")` first.
28+
- shell grep is a great way to get a line number to read a targeted section of a file
29+
30+
### Editing Files
31+
- Use `edit_file` for existing files, `write_file` only for new files
32+
- The `old_string` must match EXACTLY, including whitespace and indentation
33+
- If `old_string` appears multiple times, include more context to make it unique
34+
- Apply edits sequentially; each edit sees the result of previous edits
35+
- You can do multiple edits at once, but keep it under 1000 lines
36+
- Avoid the urge to completely rewrite files - make precise, minimal edits so the user can review them easily
37+
38+
### Shell Commands
39+
- Prefer `read_file` over `cat`, `head`, `tail`
40+
- Use `ls` for directory exploration
41+
- Use `grep` or `rg` for searching code
42+
43+
### Background Execution
44+
For long-running operations, you can execute tools in the background by adding `"background": true` to the tool call. This returns immediately with a task ID while the tool runs asynchronously.
45+
Use `list_background_tasks` to check status and `get_background_task` to retrieve results when complete.
46+
47+
### General
48+
- Be concise but thorough
49+
- Explain what you're doing before executing tools
50+
- If a tool fails, explain the error and suggest fixes
51+
- Ask for clarification if the request is ambiguous
52+
- If you feel like backing out of a path, always get confirmation before git resetting the work tree
53+
- Always get confirmation before making destructive changes (this includes building a release)
54+
"#;
55+
56+
/// Prompt used when compacting conversation context
57+
pub const COMPACTION_PROMPT: &str = r#"The conversation context is getting large and needs to be compacted.
58+
59+
Please provide a comprehensive summary of our conversation so far in markdown format. Include:
60+
61+
1. **What was accomplished** - Main tasks and changes completed as a bulleted list
62+
2. **What still needs to be done** - Remaining tasks or open areas of work as a bulleted list
63+
3. **Key project information** - Important facts about the project that the user has shared or that we're not immediately apparent
64+
4. **Relevant files** - Files most relevant to the current work with brief descriptions, line numbers, or method/variable names
65+
5. **Relevant documentation paths or URLs** - Links to docs or resources we will use to continue our work
66+
6. **Quotes and log snippets** - Any important quotes or logs that the user provided that we'll need later
67+
68+
Be thorough but concise - this summary will seed a fresh conversation context."#;
69+
70+
/// System prompt for sub-agents (background research agents)
71+
pub const SUB_AGENT_PROMPT: &str = r#"You are a background research agent. Your task is to investigate, explore, or analyze as directed.
72+
73+
## Capabilities
74+
You have read-only access to:
75+
- `read_file`: Read file contents
76+
- `shell`: Execute commands (for searching, exploring)
77+
- `fetch_url`: Fetch web content
78+
- `web_search`: Search the web
79+
- `open_file`: Signal a file to open in the IDE
80+
81+
## Guidelines
82+
- Focus on the specific task assigned to you
83+
- Be thorough but concise in your findings
84+
- Report back with structured, actionable information
85+
- You cannot modify files - only read and explore
86+
- If you need to suggest changes, describe them clearly for the primary agent to implement
87+
"#;
88+
89+
/// Filename for custom system prompt additions
90+
pub const SYSTEM_MD_FILENAME: &str = "SYSTEM.md";

src/tools/impls/spawn_agent.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
use std::sync::OnceLock;
44

55
use super::{Tool, ToolPipeline};
6-
use crate::tools::ToolRegistry;
76
use crate::auth::OAuthCredentials;
87
use crate::config::AgentRuntimeConfig;
98
use crate::impl_base_block;
10-
use crate::llm::{Agent, RequestMode};
119
use crate::llm::background::run_agent;
10+
use crate::llm::{Agent, RequestMode};
11+
use crate::prompts::SUB_AGENT_PROMPT;
1212
use crate::tools::pipeline::{EffectHandler, Step};
13-
use crate::transcript::{render_approval_prompt, render_prefix, Block, BlockType, ToolBlock, Status};
13+
use crate::tools::ToolRegistry;
14+
use crate::transcript::{render_approval_prompt, render_prefix, Block, BlockType, Status, ToolBlock};
1415
use ratatui::{
1516
style::{Color, Style},
1617
text::{Line, Span},
@@ -19,25 +20,6 @@ use serde::{Deserialize, Serialize};
1920
use serde_json::json;
2021
use tokio::sync::RwLock;
2122

22-
/// System prompt for sub-agents (background research agents)
23-
const SUB_AGENT_PROMPT: &str = r#"You are a background research agent. Your task is to investigate, explore, or analyze as directed.
24-
25-
## Capabilities
26-
You have read-only access to:
27-
- `read_file`: Read file contents
28-
- `shell`: Execute commands (for searching, exploring)
29-
- `fetch_url`: Fetch web content
30-
- `web_search`: Search the web
31-
- `open_file`: Signal a file to open in the IDE
32-
33-
## Guidelines
34-
- Focus on the specific task assigned to you
35-
- Be thorough but concise in your findings
36-
- Report back with structured, actionable information
37-
- You cannot modify files - only read and explore
38-
- If you need to suggest changes, describe them clearly for the primary agent to implement
39-
"#;
40-
4123
// =============================================================================
4224
// Agent Context - global state for spawning sub-agents
4325
// =============================================================================

src/transcript.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ use ratatui::{
1313
use serde::{Deserialize, Serialize};
1414

1515
use crate::compaction::CompactionBlock;
16-
17-
/// Directory name for Codey project-level configuration and data
18-
pub const CODEY_DIR: &str = ".codey";
19-
/// Directory name for storing transcripts
20-
pub const TRANSCRIPTS_DIR: &str = "transcripts";
16+
use crate::config::{CODEY_DIR, TRANSCRIPTS_DIR};
2117

2218

2319
/// Role of the message sender

0 commit comments

Comments
 (0)