Skip to content

Commit be00be7

Browse files
committed
Merge branch 'qv2' into qv2-migration
2 parents 764b056 + 80987c0 commit be00be7

File tree

21 files changed

+445
-104
lines changed

21 files changed

+445
-104
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ manual_ok_or = "warn"
179179
map_err_ignore = "warn"
180180
map_flatten = "warn"
181181
map_unwrap_or = "warn"
182-
match_on_vec_items = "warn"
182+
183183
# match_same_arms = "warn"
184184
match_wild_err_arm = "warn"
185185
match_wildcard_for_single_variants = "warn"

crates/agent/src/agent/agent_config/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ use tracing::{
3434
use super::util::directories::{
3535
global_agents_path,
3636
legacy_global_mcp_config_path,
37-
};
38-
use crate::agent::util::directories::{
3937
legacy_workspace_mcp_config_path,
4038
local_agents_path,
4139
};

crates/agent/src/agent/consts.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/// Name of the default agent.
2-
pub const DEFAULT_AGENT_NAME: &str = "q_cli_default";
1+
pub const DEFAULT_AGENT_NAME: &str = "kiro_default";
32

43
pub const MAX_CONVERSATION_STATE_HISTORY_LEN: usize = 500;
54

crates/agent/src/agent/util/directories.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use super::error::{
1414
use crate::agent::util::consts::env_var::CLI_DATA_DIR;
1515

1616
const DATA_DIR_NAME: &str = "amazon-q";
17-
const AWS_DIR_NAME: &str = "amazonq";
1817

1918
type Result<T, E = UtilError> = std::result::Result<T, E>;
2019

@@ -57,28 +56,50 @@ pub fn settings_schema_path(base: impl AsRef<Path>) -> PathBuf {
5756
base.as_ref().join("settings_schema.json")
5857
}
5958

59+
fn resolve_migrated_path(is_global: bool, subpath: &str) -> Result<PathBuf> {
60+
let (kiro_base, amazonq_base) = if is_global {
61+
let home = home_dir()?;
62+
(home.join(".aws/kiro"), home.join(".aws/amazonq"))
63+
} else {
64+
let cwd = env::current_dir().context("unable to get the current directory")?;
65+
(cwd.join(".kiro"), cwd.join(".amazonq"))
66+
};
67+
68+
let scope = if is_global { "global" } else { "workspace" };
69+
70+
match (kiro_base.exists(), amazonq_base.exists()) {
71+
(true, false) => {
72+
warn!("Using .kiro {} configuration", scope);
73+
Ok(kiro_base.join(subpath))
74+
},
75+
(false, true) => {
76+
warn!("Migration notice: Using .amazonq {} configs", scope);
77+
Ok(amazonq_base.join(subpath))
78+
},
79+
(true, true) => {
80+
warn!("Both .amazonq and .kiro {} configs exist, using .amazonq", scope);
81+
Ok(amazonq_base.join(subpath))
82+
},
83+
(false, false) => Ok(kiro_base.join(subpath)), // Default to kiro
84+
}
85+
}
86+
6087
/// Path to the directory containing local agent configs.
6188
pub fn local_agents_path() -> Result<PathBuf> {
62-
Ok(env::current_dir()
63-
.context("unable to get the current directory")?
64-
.join(format!(".{AWS_DIR_NAME}"))
65-
.join("cli-agents"))
89+
resolve_migrated_path(false, "cli-agents")
6690
}
6791

6892
/// Path to the directory containing global agent configs.
6993
pub fn global_agents_path() -> Result<PathBuf> {
70-
Ok(home_dir()?.join(".aws").join(AWS_DIR_NAME).join("cli-agents"))
94+
resolve_migrated_path(true, "cli-agents")
7195
}
7296

7397
/// Legacy workspace MCP server config path
7498
pub fn legacy_workspace_mcp_config_path() -> Result<PathBuf> {
75-
Ok(env::current_dir()
76-
.context("unable to get the current directory")?
77-
.join(format!(".{AWS_DIR_NAME}"))
78-
.join("mcp.json"))
99+
resolve_migrated_path(false, "mcp.json")
79100
}
80101

81102
/// Legacy global MCP server config path
82103
pub fn legacy_global_mcp_config_path() -> Result<PathBuf> {
83-
Ok(home_dir()?.join(".aws").join(AWS_DIR_NAME).join("mcp.json"))
104+
resolve_migrated_path(true, "mcp.json")
84105
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ use crate::cli::agent::hook::{
6060
Hook,
6161
HookTrigger,
6262
};
63+
use crate::constants::DEFAULT_AGENT_NAME;
6364
use crate::database::settings::Setting;
6465
use crate::os::Os;
6566
use crate::theme::StyledText;
@@ -71,8 +72,6 @@ use crate::util::{
7172
paths,
7273
};
7374

74-
pub const DEFAULT_AGENT_NAME: &str = "q_cli_default";
75-
7675
#[derive(Debug, Error)]
7776
pub enum AgentConfigError {
7877
#[error("Json supplied at {} is invalid: {}", path.display(), error)]
@@ -197,7 +196,6 @@ impl Default for Agent {
197196
resources: {
198197
let mut resources = Vec::new();
199198
resources.extend(paths::workspace::DEFAULT_AGENT_RESOURCES.iter().map(|&s| s.into()));
200-
resources.push(format!("file://{}", paths::workspace::RULES_PATTERN).into());
201199
resources
202200
},
203201
hooks: Default::default(),
@@ -740,6 +738,13 @@ impl Agents {
740738

741739
all_agents.push({
742740
let mut agent = Agent::default();
741+
742+
// Add rules pattern using dynamic path resolution
743+
if let Ok(rules_dir) = resolver.workspace().rules_dir() {
744+
let rules_pattern = paths::workspace::RULES_PATTERN.replace("{}", &rules_dir.display().to_string());
745+
agent.resources.push(rules_pattern.into());
746+
}
747+
743748
if mcp_enabled {
744749
'load_legacy_mcp_json: {
745750
if global_mcp_config.is_none() {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use super::{
2525
use crate::database::settings::Setting;
2626
use crate::os::Os;
2727
use crate::theme::StyledText;
28-
use crate::util::paths;
2928
use crate::util::paths::PathResolver;
3029

3130
#[derive(Clone, Debug, Subcommand, PartialEq, Eq)]
@@ -336,7 +335,7 @@ pub async fn create_agent(
336335
bail!("Path must be a directory");
337336
}
338337

339-
path.join(paths::workspace::AGENTS_DIR)
338+
PathResolver::new(os).workspace().agents_dir()?
340339
} else {
341340
PathResolver::new(os).global().agents_dir()?
342341
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ impl ClearArgs {
2929
"\nAre you sure? This will erase the conversation history and context from hooks for the current session. "
3030
),
3131
style::Print("["),
32-
StyledText::success_fg(),
32+
StyledText::current_item_fg(),
3333
style::Print("y"),
3434
StyledText::secondary_fg(),
3535
style::Print("/"),
36-
StyledText::success_fg(),
36+
StyledText::current_item_fg(),
3737
style::Print("n"),
3838
StyledText::secondary_fg(),
3939
style::Print("]:\n\n"),

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,14 @@ impl PromptsArgs {
733733
}
734734

735735
if !global_prompts.is_empty() {
736+
let global_dir = PathResolver::new(os)
737+
.global()
738+
.prompts_dir()
739+
.map_or_else(|_| "global prompts".to_string(), |p| p.display().to_string());
736740
queue!(
737741
session.stderr,
738742
style::SetAttribute(Attribute::Bold),
739-
style::Print(&format!("Global ({}):", crate::util::paths::global::PROMPTS_DIR)),
743+
style::Print(&format!("Global ({global_dir}):")),
740744
StyledText::reset_attributes(),
741745
style::Print("\n"),
742746
)?;
@@ -750,10 +754,14 @@ impl PromptsArgs {
750754
if !global_prompts.is_empty() {
751755
queue!(session.stderr, style::Print("\n"))?;
752756
}
757+
let local_dir = PathResolver::new(os)
758+
.workspace()
759+
.prompts_dir()
760+
.map_or_else(|_| "local prompts".to_string(), |p| p.display().to_string());
753761
queue!(
754762
session.stderr,
755763
style::SetAttribute(Attribute::Bold),
756-
style::Print(&format!("Local ({}):", crate::util::paths::workspace::PROMPTS_DIR)),
764+
style::Print(&format!("Local ({local_dir}):")),
757765
StyledText::reset_attributes(),
758766
style::Print("\n"),
759767
)?;
@@ -2069,8 +2077,8 @@ mod tests {
20692077
let temp_dir = TempDir::new().unwrap();
20702078

20712079
// Create test prompts in temp directory structure
2072-
let global_dir = temp_dir.path().join(crate::util::paths::global::PROMPTS_DIR);
2073-
let local_dir = temp_dir.path().join(crate::util::paths::workspace::PROMPTS_DIR);
2080+
let global_dir = temp_dir.path().join(".aws/amazonq/prompts");
2081+
let local_dir = temp_dir.path().join(".amazonq/prompts");
20742082

20752083
create_prompt_file(&global_dir, "global_only", "Global content");
20762084
create_prompt_file(&global_dir, "shared", "Global shared");
@@ -2090,8 +2098,8 @@ mod tests {
20902098
let temp_dir = TempDir::new().unwrap();
20912099

20922100
// Create global and local directories
2093-
let global_dir = temp_dir.path().join(crate::util::paths::global::PROMPTS_DIR);
2094-
let local_dir = temp_dir.path().join(crate::util::paths::workspace::PROMPTS_DIR);
2101+
let global_dir = temp_dir.path().join(".aws/amazonq/prompts");
2102+
let local_dir = temp_dir.path().join(".amazonq/prompts");
20952103

20962104
// Create prompts: one with same name in both directories, one unique to each
20972105
create_prompt_file(&global_dir, "shared", "Global version");

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ use crossterm::{
1515
};
1616

1717
use crate::api_client::model::Tool as FigTool;
18-
use crate::cli::agent::{
19-
Agent,
20-
DEFAULT_AGENT_NAME,
21-
};
18+
use crate::cli::agent::Agent;
2219
use crate::cli::chat::consts::{
2320
AGENT_FORMAT_TOOLS_DOC_URL,
2421
DUMMY_TOOL_NAME,
@@ -30,6 +27,7 @@ use crate::cli::chat::{
3027
ChatState,
3128
trust_all_text,
3229
};
30+
use crate::constants::DEFAULT_AGENT_NAME;
3331
use crate::constants::help_text::tools_long_help;
3432
use crate::theme::StyledText;
3533
use crate::util::consts::MCP_SERVER_TOOL_DELIMITER;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ use winnow::stream::Offset;
162162

163163
use super::agent::{
164164
Agent,
165-
DEFAULT_AGENT_NAME,
166165
PermissionEvalResult,
167166
};
168167
use crate::api_client::model::ToolResultStatus;
@@ -191,6 +190,7 @@ use crate::cli::experiment::experiment_manager::{
191190
ExperimentName,
192191
};
193192
use crate::constants::{
193+
DEFAULT_AGENT_NAME,
194194
error_messages,
195195
tips,
196196
};

0 commit comments

Comments
 (0)