MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / migrate

Function migrate

crates/chat-cli/src/cli/agent/legacy/mod.rs:29–230  ·  view source on GitHub ↗

Performs the migration from legacy profile configuration to agent configuration if it hasn't already been done. Returns [Some] with the newly migrated agents if the migration was performed, [None] if the migration was already done previously.

(os: &mut Os, force: bool)

Source from the content-addressed store, hash-verified

27/// Returns [Some] with the newly migrated agents if the migration was performed, [None] if the
28/// migration was already done previously.
29pub async fn migrate(os: &mut Os, force: bool) -> eyre::Result<Option<Vec<Agent>>> {
30 let has_migrated = os.database.get_has_migrated()?;
31 if !force && has_migrated.is_some_and(|has_migrated| has_migrated) {
32 return Ok(None);
33 }
34
35 let resolver = PathResolver::new(os);
36 let legacy_global_context_path = resolver.global().global_context()?;
37 let legacy_global_context: Option<LegacyContextConfig> = 'global: {
38 let Ok(content) = os.fs.read(&legacy_global_context_path).await else {
39 break 'global None;
40 };
41 serde_json::from_slice::<LegacyContextConfig>(&content).ok()
42 };
43
44 let legacy_profile_path = resolver.global().profiles_dir()?;
45 let mut legacy_profiles: HashMap<String, LegacyContextConfig> = 'profiles: {
46 let mut profiles = HashMap::<String, LegacyContextConfig>::new();
47 let Ok(mut read_dir) = os.fs.read_dir(&legacy_profile_path).await else {
48 break 'profiles profiles;
49 };
50
51 // Here we assume every profile is stored under their own folders
52 // And that the profile config is in profile_name/context.json
53 while let Ok(Some(entry)) = read_dir.next_entry().await {
54 let config_file_path = entry.path().join("context.json");
55 if !os.fs.exists(&config_file_path) {
56 continue;
57 }
58 let Some(profile_name) = entry.file_name().to_str().map(|s| s.to_string()) else {
59 continue;
60 };
61 let Ok(content) = tokio::fs::read_to_string(&config_file_path).await else {
62 continue;
63 };
64 let Ok(mut context_config) = serde_json::from_str::<LegacyContextConfig>(content.as_str()) else {
65 continue;
66 };
67
68 // Combine with global context since you can now only choose one agent at a time
69 // So this is how we make what is previously global available to every new agent migrated
70 if let Some(context) = legacy_global_context.as_ref() {
71 context_config.paths.extend(context.paths.clone());
72 context_config.hooks.extend(context.hooks.clone());
73 }
74
75 profiles.insert(profile_name.clone(), context_config);
76 }
77
78 profiles
79 };
80
81 let mcp_servers = {
82 let config_path = resolver.global().mcp_config()?;
83 if os.fs.exists(&config_path) {
84 match McpServerConfig::load_from_file(os, config_path).await {
85 Ok(mut config) => {
86 config.mcp_servers.iter_mut().for_each(|(_name, config)| {

Callers 2

loadMethod · 0.85
executeMethod · 0.85

Calls 15

dialoguer_themeFunction · 0.85
get_has_migratedMethod · 0.80
global_contextMethod · 0.80
globalMethod · 0.80
readMethod · 0.80
profiles_dirMethod · 0.80
read_dirMethod · 0.80
joinMethod · 0.80
mapMethod · 0.80
to_stringMethod · 0.80
insertMethod · 0.80
mcp_configMethod · 0.80

Tested by

no test coverage detected