Skip to content

Commit 70d580f

Browse files
authored
fix(agent): directory change (#2426)
1 parent 8b8590d commit 70d580f

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

crates/chat-cli/src/cli/agent/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use crate::util::{
7171
directories,
7272
};
7373

74-
const DEFAULT_AGENT_NAME: &str = "q_cli_default";
74+
pub const DEFAULT_AGENT_NAME: &str = "q_cli_default";
7575

7676
#[derive(Debug, Error)]
7777
pub enum AgentConfigError {
@@ -252,7 +252,7 @@ impl Agent {
252252
pub async fn get_agent_by_name(os: &Os, agent_name: &str) -> eyre::Result<(Agent, PathBuf)> {
253253
let config_path: Result<PathBuf, PathBuf> = 'config: {
254254
// local first, and then fall back to looking at global
255-
let local_config_dir = directories::chat_local_agent_dir()?.join(format!("{agent_name}.json"));
255+
let local_config_dir = directories::chat_local_agent_dir(os)?.join(format!("{agent_name}.json"));
256256
if os.fs.exists(&local_config_dir) {
257257
break 'config Ok(local_config_dir);
258258
}
@@ -424,7 +424,7 @@ impl Agents {
424424
},
425425
}
426426

427-
let Ok(path) = directories::chat_local_agent_dir() else {
427+
let Ok(path) = directories::chat_local_agent_dir(os) else {
428428
break 'local Vec::<Agent>::new();
429429
};
430430
let Ok(files) = os.fs.read_dir(path).await else {

crates/chat-cli/src/cli/agent/root_command_args.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ use super::{
2525
};
2626
use crate::database::settings::Setting;
2727
use crate::os::Os;
28-
use crate::util::directories::{
29-
self,
30-
agent_config_dir,
31-
};
28+
use crate::util::directories;
3229

3330
#[derive(Clone, Debug, Subcommand, PartialEq, Eq)]
3431
pub enum AgentSubcommands {
@@ -319,7 +316,7 @@ pub async fn create_agent(
319316
bail!("Path must be a directory");
320317
}
321318

322-
agent_config_dir(path)?
319+
directories::agent_config_dir(path)?
323320
} else {
324321
directories::chat_global_agent_path(os)?
325322
};

crates/chat-cli/src/cli/chat/prompt_parser.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::cli::agent::DEFAULT_AGENT_NAME;
2+
13
/// Components extracted from a prompt string
24
#[derive(Debug, PartialEq)]
35
pub struct PromptComponents {
@@ -40,7 +42,7 @@ pub fn generate_prompt(current_profile: Option<&str>, warning: bool) -> String {
4042
// Generate plain text prompt that will be colored by highlight_prompt
4143
let warning_symbol = if warning { "!" } else { "" };
4244
let profile_part = current_profile
43-
.filter(|&p| p != "default")
45+
.filter(|&p| p != DEFAULT_AGENT_NAME)
4446
.map(|p| format!("[{p}] "))
4547
.unwrap_or_default();
4648

@@ -58,7 +60,7 @@ mod tests {
5860
// Test default prompt with warning
5961
assert_eq!(generate_prompt(None, true), "!> ");
6062
// Test default profile (should be same as no profile)
61-
assert_eq!(generate_prompt(Some("default"), false), "> ");
63+
assert_eq!(generate_prompt(Some(DEFAULT_AGENT_NAME), false), "> ");
6264
// Test custom profile
6365
assert_eq!(generate_prompt(Some("test-profile"), false), "[test-profile] > ");
6466
// Test another custom profile with warning

crates/chat-cli/src/util/directories.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub enum DirectoryError {
3232

3333
type Result<T, E = DirectoryError> = std::result::Result<T, E>;
3434

35+
const WORKSPACE_AGENT_DIR_RELATIVE: &str = ".amazonq/cli-agents";
36+
const GLOBAL_AGENT_DIR_RELATIVE_TO_HOME: &str = ".aws/amazonq/cli-agents";
37+
3538
/// The directory of the users home
3639
///
3740
/// - Linux: /home/Alice
@@ -147,13 +150,13 @@ pub fn chat_legacy_mcp_config(os: &Os) -> Result<PathBuf> {
147150

148151
/// The directory to the directory containing global agents
149152
pub fn chat_global_agent_path(os: &Os) -> Result<PathBuf> {
150-
Ok(home_dir(os)?.join(".aws").join("amazonq").join("agents"))
153+
Ok(home_dir(os)?.join(GLOBAL_AGENT_DIR_RELATIVE_TO_HOME))
151154
}
152155

153156
/// The directory to the directory containing config for the `/context` feature in `q chat`.
154-
pub fn chat_local_agent_dir() -> Result<PathBuf> {
155-
let cwd = std::env::current_dir()?;
156-
Ok(cwd.join(".amazonq").join("agents"))
157+
pub fn chat_local_agent_dir(os: &Os) -> Result<PathBuf> {
158+
let cwd = os.env.current_dir()?;
159+
Ok(cwd.join(WORKSPACE_AGENT_DIR_RELATIVE))
157160
}
158161

159162
/// Derives the absolute path to an agent config directory given a "workspace directory".
@@ -162,7 +165,7 @@ pub fn chat_local_agent_dir() -> Result<PathBuf> {
162165
/// For example, if the given path is /path/one, then the derived config path would be
163166
/// `/path/one/.amazonq/agents`
164167
pub fn agent_config_dir(workspace_dir: PathBuf) -> Result<PathBuf> {
165-
Ok(workspace_dir.join(".amazonq/agents"))
168+
Ok(workspace_dir.join(WORKSPACE_AGENT_DIR_RELATIVE))
166169
}
167170

168171
/// The directory to the directory containing config for the `/context` feature in `q chat`.

docs/agent-format.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The agent configuration file for each agent is a JSON file. The filename (withou
55
Every agent configuration file can include the following sections:
66

77
- [`name`](#name-field) — The name of the agent (optional, derived from filename if not specified).
8+
- [`version`](#version-field) - The version of the agent config.
89
- [`description`](#description-field) — A description of the agent.
910
- [`prompt`](#prompt-field) — High-level context for the agent (not yet implemented).
1011
- [`mcpServers`](#mcpservers-field) — The MCP servers the agent has access to.

0 commit comments

Comments
 (0)