mirror of
https://github.com/openai/codex.git
synced 2026-11-24 07:20:27 +00:00
Group external agent config migration into a module (#35992)
## What changed - Move the migration flow, model, and source picker under the `external_agent_config_migration` module. - Keep their tests and snapshots alongside the corresponding module files and update imports and snapshot source paths. GitOrigin-RevId: 4b2f83ca689534e4d9cd1dc7aaa8424e76166bba
This commit is contained in:
1 parent
1da9f846b3
commit
f9b18d04ba
18 files changed
+31
-29
No files matched your search
@@ -0,0 +1,379 @@
|
||||
use crate::app_server_session::AppServerSession;
|
||||
use crate::app_server_session::EXTERNAL_AGENT_CONFIG_IMPORT_IN_PROGRESS_MESSAGE;
|
||||
use crate::legacy_core::config::Config;
|
||||
use crate::tui;
|
||||
use codex_app_server_protocol::ExternalAgentConfigDetectParams;
|
||||
use codex_app_server_protocol::ExternalAgentConfigImportCompletedNotification;
|
||||
use codex_app_server_protocol::ExternalAgentConfigMigrationItem;
|
||||
use codex_app_server_protocol::ExternalAgentConfigMigrationItemType;
|
||||
use ratatui::prelude::Stylize as _;
|
||||
use ratatui::text::Line;
|
||||
|
||||
use super::ExternalAgentConfigMigrationOutcome;
|
||||
use super::model::external_agent_config_migration_item_count;
|
||||
use super::model::external_agent_config_migration_type_label;
|
||||
use super::run_external_agent_config_migration_prompt;
|
||||
use super::source::ExternalAgentConfigMigrationSource;
|
||||
use super::source::run_external_agent_config_source_prompt;
|
||||
|
||||
pub(crate) const EXTERNAL_AGENT_CONFIG_MIGRATION_NO_ITEMS_MESSAGE: &str =
|
||||
"No compatible setup was found to import.";
|
||||
pub(crate) const EXTERNAL_AGENT_CONFIG_MIGRATION_REMOTE_UNAVAILABLE_MESSAGE: &str = "Import from other apps is unavailable in remote sessions. Start Codex locally and run /import.";
|
||||
pub(crate) const EXTERNAL_AGENT_CONFIG_MIGRATION_DAEMON_UNAVAILABLE_MESSAGE: &str = "Import from other apps is unavailable while Codex is connected to the local app-server daemon. Stop the daemon, restart Codex, and run /import.";
|
||||
|
||||
pub(crate) enum ExternalAgentConfigMigrationFlowOutcome {
|
||||
Started(Vec<Line<'static>>),
|
||||
NoItems,
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
struct DetectedExternalAgentConfigSource {
|
||||
source: ExternalAgentConfigMigrationSource,
|
||||
items: Vec<ExternalAgentConfigMigrationItem>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ExternalAgentConfigDetection {
|
||||
sources: Vec<DetectedExternalAgentConfigSource>,
|
||||
errors: Vec<String>,
|
||||
}
|
||||
|
||||
enum ExternalAgentConfigDetectionOutcome {
|
||||
Sources(Vec<DetectedExternalAgentConfigSource>),
|
||||
NoItems,
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
impl ExternalAgentConfigDetection {
|
||||
fn record_items(
|
||||
&mut self,
|
||||
source: ExternalAgentConfigMigrationSource,
|
||||
items: Vec<ExternalAgentConfigMigrationItem>,
|
||||
) {
|
||||
if !items.is_empty() {
|
||||
self.sources
|
||||
.push(DetectedExternalAgentConfigSource { source, items });
|
||||
}
|
||||
}
|
||||
|
||||
fn record_error(
|
||||
&mut self,
|
||||
source: ExternalAgentConfigMigrationSource,
|
||||
error: impl std::fmt::Display,
|
||||
) {
|
||||
self.errors.push(format!("{}: {error}", source.label()));
|
||||
}
|
||||
|
||||
fn finish(self) -> ExternalAgentConfigDetectionOutcome {
|
||||
if !self.sources.is_empty() {
|
||||
ExternalAgentConfigDetectionOutcome::Sources(self.sources)
|
||||
} else if self.errors.is_empty() {
|
||||
ExternalAgentConfigDetectionOutcome::NoItems
|
||||
} else {
|
||||
ExternalAgentConfigDetectionOutcome::Failed(format!(
|
||||
"Could not check for importable setup: {}",
|
||||
self.errors.join("; ")
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn external_agent_config_migration_started_lines(
|
||||
selected_items: &[ExternalAgentConfigMigrationItem],
|
||||
remaining_item_count: usize,
|
||||
) -> Vec<Line<'static>> {
|
||||
let mut import_summaries =
|
||||
Vec::<(ExternalAgentConfigMigrationItemType, usize, Vec<&str>)>::new();
|
||||
for item in selected_items {
|
||||
let names = item
|
||||
.details
|
||||
.as_ref()
|
||||
.map_or_else(Vec::new, |details| match item.item_type {
|
||||
ExternalAgentConfigMigrationItemType::Plugins => details
|
||||
.plugins
|
||||
.iter()
|
||||
.flat_map(|plugin_group| plugin_group.plugin_names.iter())
|
||||
.map(String::as_str)
|
||||
.collect(),
|
||||
ExternalAgentConfigMigrationItemType::Skills => details
|
||||
.skills
|
||||
.iter()
|
||||
.map(|skill| skill.name.as_str())
|
||||
.collect(),
|
||||
ExternalAgentConfigMigrationItemType::McpServerConfig => details
|
||||
.mcp_servers
|
||||
.iter()
|
||||
.map(|server| server.name.as_str())
|
||||
.collect(),
|
||||
ExternalAgentConfigMigrationItemType::Subagents => details
|
||||
.subagents
|
||||
.iter()
|
||||
.map(|agent| agent.name.as_str())
|
||||
.collect(),
|
||||
ExternalAgentConfigMigrationItemType::Hooks => details
|
||||
.hooks
|
||||
.iter()
|
||||
.map(|hook| hook.name.as_str())
|
||||
.collect(),
|
||||
ExternalAgentConfigMigrationItemType::Commands => details
|
||||
.commands
|
||||
.iter()
|
||||
.map(|command| command.name.as_str())
|
||||
.collect(),
|
||||
ExternalAgentConfigMigrationItemType::Memory => {
|
||||
details.memory.iter().map(String::as_str).collect()
|
||||
}
|
||||
ExternalAgentConfigMigrationItemType::Sessions => details
|
||||
.sessions
|
||||
.iter()
|
||||
.filter_map(|session| session.title.as_deref())
|
||||
.collect(),
|
||||
ExternalAgentConfigMigrationItemType::AgentsMd
|
||||
| ExternalAgentConfigMigrationItemType::Config => Vec::new(),
|
||||
});
|
||||
let count = external_agent_config_migration_item_count(item);
|
||||
if let Some((_, type_count, type_names)) = import_summaries
|
||||
.iter_mut()
|
||||
.find(|(item_type, _, _)| *item_type == item.item_type)
|
||||
{
|
||||
*type_count += count;
|
||||
type_names.extend(names);
|
||||
} else {
|
||||
import_summaries.push((item.item_type, count, names));
|
||||
}
|
||||
}
|
||||
|
||||
let mut lines = vec![
|
||||
vec![
|
||||
"• ".dim(),
|
||||
"Import started.".cyan(),
|
||||
" You can keep working while it finishes.".into(),
|
||||
]
|
||||
.into(),
|
||||
vec![" ".into(), "Imported setup will apply to new chats.".dim()].into(),
|
||||
vec![" ".into(), "Importing:".cyan().bold()].into(),
|
||||
];
|
||||
lines.extend(
|
||||
import_summaries
|
||||
.into_iter()
|
||||
.map(|(item_type, count, names)| {
|
||||
let mut line = vec![
|
||||
" ".into(),
|
||||
external_agent_config_migration_type_label(item_type).cyan(),
|
||||
": ".into(),
|
||||
count.to_string().green(),
|
||||
];
|
||||
if !names.is_empty() {
|
||||
let shown_names = names.iter().take(3).copied().collect::<Vec<_>>();
|
||||
let mut name_summary = shown_names.join(", ");
|
||||
if names.len() > shown_names.len() {
|
||||
name_summary
|
||||
.push_str(&format!(", +{} more", names.len() - shown_names.len()));
|
||||
}
|
||||
line.extend([" — ".dim(), name_summary.into()]);
|
||||
}
|
||||
line.into()
|
||||
}),
|
||||
);
|
||||
if let Some(remaining_items_handoff) = remaining_items_handoff(remaining_item_count) {
|
||||
lines.push(vec![" ".into(), remaining_items_handoff.dim()].into());
|
||||
}
|
||||
lines
|
||||
}
|
||||
|
||||
pub(crate) fn external_agent_config_migration_finished_lines(
|
||||
notification: &ExternalAgentConfigImportCompletedNotification,
|
||||
) -> Vec<Line<'static>> {
|
||||
let imported_count = notification
|
||||
.item_type_results
|
||||
.iter()
|
||||
.map(|type_result| type_result.successes.len())
|
||||
.sum::<usize>();
|
||||
let failed_count = notification
|
||||
.item_type_results
|
||||
.iter()
|
||||
.map(|type_result| type_result.failures.len())
|
||||
.sum::<usize>();
|
||||
let failed_count = if failed_count == 0 {
|
||||
format!("{failed_count} failed").green()
|
||||
} else {
|
||||
format!("{failed_count} failed").red()
|
||||
};
|
||||
let mut lines = vec![
|
||||
vec![
|
||||
"• ".dim(),
|
||||
"Import finished: ".into(),
|
||||
format!("{imported_count} imported").green(),
|
||||
", ".into(),
|
||||
failed_count,
|
||||
".".into(),
|
||||
]
|
||||
.into(),
|
||||
];
|
||||
if !notification.item_type_results.is_empty() {
|
||||
lines.push(vec![" ".into(), "Results by type:".cyan().bold()].into());
|
||||
lines.extend(notification.item_type_results.iter().map(|type_result| {
|
||||
let failed_count = format!("{} failed", type_result.failures.len());
|
||||
let failed_count = if type_result.failures.is_empty() {
|
||||
failed_count.green()
|
||||
} else {
|
||||
failed_count.red()
|
||||
};
|
||||
vec![
|
||||
" ".into(),
|
||||
external_agent_config_migration_type_label(type_result.item_type).cyan(),
|
||||
": ".into(),
|
||||
format!("{} imported", type_result.successes.len()).green(),
|
||||
", ".into(),
|
||||
failed_count,
|
||||
]
|
||||
.into()
|
||||
}));
|
||||
}
|
||||
lines.push(
|
||||
vec![
|
||||
" ".into(),
|
||||
"Run /import again to check for additional items.".dim(),
|
||||
]
|
||||
.into(),
|
||||
);
|
||||
lines
|
||||
}
|
||||
|
||||
fn remaining_items_handoff(remaining_item_count: usize) -> Option<String> {
|
||||
match remaining_item_count {
|
||||
0 => None,
|
||||
1 => Some(
|
||||
"1 additional item remains. After it finishes, run /import again to review it."
|
||||
.to_string(),
|
||||
),
|
||||
_ => Some(format!(
|
||||
"{remaining_item_count} additional items remain. After it finishes, run /import again to review them."
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn handle_external_agent_config_migration_prompt(
|
||||
tui: &mut tui::Tui,
|
||||
app_server: &mut AppServerSession,
|
||||
config: &Config,
|
||||
) -> Result<ExternalAgentConfigMigrationFlowOutcome, String> {
|
||||
if app_server.uses_remote_workspace() {
|
||||
return Err(EXTERNAL_AGENT_CONFIG_MIGRATION_REMOTE_UNAVAILABLE_MESSAGE.to_string());
|
||||
}
|
||||
if !app_server.uses_embedded_app_server() {
|
||||
return Err(EXTERNAL_AGENT_CONFIG_MIGRATION_DAEMON_UNAVAILABLE_MESSAGE.to_string());
|
||||
}
|
||||
if app_server.external_agent_config_import_in_progress() {
|
||||
return Err(EXTERNAL_AGENT_CONFIG_IMPORT_IN_PROGRESS_MESSAGE.to_string());
|
||||
}
|
||||
|
||||
let cwd = config.cwd.to_path_buf();
|
||||
let mut detection = ExternalAgentConfigDetection::default();
|
||||
for source in ExternalAgentConfigMigrationSource::ALL {
|
||||
let response = match app_server
|
||||
.external_agent_config_detect(ExternalAgentConfigDetectParams {
|
||||
include_home: true,
|
||||
cwds: Some(vec![cwd.clone()]),
|
||||
max_session_age_days: None,
|
||||
max_sessions: None,
|
||||
source: None,
|
||||
migration_source: Some(source.migration_source().to_string()),
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(response) => response,
|
||||
Err(err) => {
|
||||
tracing::warn!(
|
||||
error = %err,
|
||||
cwd = %cwd.display(),
|
||||
source = source.label(),
|
||||
"failed to detect external agent config migrations"
|
||||
);
|
||||
detection.record_error(source, err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
detection.record_items(source, response.items);
|
||||
}
|
||||
|
||||
let detected_sources = match detection.finish() {
|
||||
ExternalAgentConfigDetectionOutcome::Sources(sources) => sources,
|
||||
ExternalAgentConfigDetectionOutcome::NoItems => {
|
||||
return Ok(ExternalAgentConfigMigrationFlowOutcome::NoItems);
|
||||
}
|
||||
ExternalAgentConfigDetectionOutcome::Failed(error) => return Err(error),
|
||||
};
|
||||
|
||||
let selected_source = if detected_sources.len() == 1 {
|
||||
detected_sources[0].source
|
||||
} else {
|
||||
let sources = detected_sources
|
||||
.iter()
|
||||
.map(|detected| detected.source)
|
||||
.collect::<Vec<_>>();
|
||||
let Some(source) = run_external_agent_config_source_prompt(tui, &sources).await else {
|
||||
return Ok(ExternalAgentConfigMigrationFlowOutcome::Cancelled);
|
||||
};
|
||||
source
|
||||
};
|
||||
let Some(detected_source) = detected_sources
|
||||
.into_iter()
|
||||
.find(|detected| detected.source == selected_source)
|
||||
else {
|
||||
return Err("Selected import source is no longer available.".to_string());
|
||||
};
|
||||
let detected_items = detected_source.items;
|
||||
|
||||
let mut selected_items = detected_items.clone();
|
||||
let mut error: Option<String> = None;
|
||||
|
||||
loop {
|
||||
match run_external_agent_config_migration_prompt(
|
||||
tui,
|
||||
&detected_items,
|
||||
&selected_items,
|
||||
error.as_deref(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
ExternalAgentConfigMigrationOutcome::Proceed(items) => {
|
||||
selected_items = items.clone();
|
||||
match app_server
|
||||
.external_agent_config_import(
|
||||
items,
|
||||
selected_source.migration_source().to_string(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {
|
||||
let remaining_item_count =
|
||||
detected_items.len().saturating_sub(selected_items.len());
|
||||
let started_lines = external_agent_config_migration_started_lines(
|
||||
&selected_items,
|
||||
remaining_item_count,
|
||||
);
|
||||
return Ok(ExternalAgentConfigMigrationFlowOutcome::Started(
|
||||
started_lines,
|
||||
));
|
||||
}
|
||||
Err(err) => {
|
||||
tracing::warn!(
|
||||
error = %err,
|
||||
cwd = %cwd.display(),
|
||||
"failed to import external agent config migration items"
|
||||
);
|
||||
error = Some(format!("Import failed: {err}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
ExternalAgentConfigMigrationOutcome::Skip => {
|
||||
return Ok(ExternalAgentConfigMigrationFlowOutcome::Cancelled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "flow_tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,395 @@
|
||||
use super::*;
|
||||
use codex_app_server_protocol::ExternalAgentConfigImportItemTypeFailure;
|
||||
use codex_app_server_protocol::ExternalAgentConfigImportItemTypeSuccess;
|
||||
use codex_app_server_protocol::ExternalAgentConfigImportTypeResult;
|
||||
use codex_app_server_protocol::ExternalAgentConfigMigrationItemType;
|
||||
use codex_app_server_protocol::McpServerMigration;
|
||||
use codex_app_server_protocol::MigrationDetails;
|
||||
use codex_app_server_protocol::PluginsMigration;
|
||||
use codex_app_server_protocol::SessionMigration;
|
||||
use codex_app_server_protocol::SkillMigration;
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::text::Line;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn detected_item(description: &str) -> ExternalAgentConfigMigrationItem {
|
||||
ExternalAgentConfigMigrationItem {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Config,
|
||||
description: description.to_string(),
|
||||
cwd: None,
|
||||
details: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn selected_items() -> Vec<ExternalAgentConfigMigrationItem> {
|
||||
vec![
|
||||
ExternalAgentConfigMigrationItem {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Config,
|
||||
description: "Import settings".to_string(),
|
||||
cwd: None,
|
||||
details: None,
|
||||
},
|
||||
ExternalAgentConfigMigrationItem {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Memory,
|
||||
description: "Import memory".to_string(),
|
||||
cwd: None,
|
||||
details: Some(MigrationDetails {
|
||||
memory: vec!["project-a".to_string(), "project-b".to_string()],
|
||||
..Default::default()
|
||||
}),
|
||||
},
|
||||
ExternalAgentConfigMigrationItem {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Skills,
|
||||
description: "Import skills".to_string(),
|
||||
cwd: None,
|
||||
details: Some(MigrationDetails {
|
||||
skills: vec![
|
||||
SkillMigration {
|
||||
name: "triage".to_string(),
|
||||
},
|
||||
SkillMigration {
|
||||
name: "release-notes".to_string(),
|
||||
},
|
||||
SkillMigration {
|
||||
name: "risk-check".to_string(),
|
||||
},
|
||||
SkillMigration {
|
||||
name: "incident-review".to_string(),
|
||||
},
|
||||
],
|
||||
..Default::default()
|
||||
}),
|
||||
},
|
||||
ExternalAgentConfigMigrationItem {
|
||||
item_type: ExternalAgentConfigMigrationItemType::McpServerConfig,
|
||||
description: "Import MCP servers".to_string(),
|
||||
cwd: None,
|
||||
details: Some(MigrationDetails {
|
||||
mcp_servers: vec![
|
||||
McpServerMigration {
|
||||
name: "docs".to_string(),
|
||||
},
|
||||
McpServerMigration {
|
||||
name: "issues".to_string(),
|
||||
},
|
||||
],
|
||||
..Default::default()
|
||||
}),
|
||||
},
|
||||
ExternalAgentConfigMigrationItem {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Sessions,
|
||||
description: "Import chat sessions".to_string(),
|
||||
cwd: None,
|
||||
details: Some(MigrationDetails {
|
||||
sessions: vec![
|
||||
SessionMigration {
|
||||
path: PathBuf::from("/sessions/alpha.jsonl"),
|
||||
cwd: PathBuf::from("/workspace/project"),
|
||||
title: Some("Alpha rollout".to_string()),
|
||||
},
|
||||
SessionMigration {
|
||||
path: PathBuf::from("/sessions/beta.jsonl"),
|
||||
cwd: PathBuf::from("/workspace/project"),
|
||||
title: Some("Beta review".to_string()),
|
||||
},
|
||||
SessionMigration {
|
||||
path: PathBuf::from("/sessions/gamma.jsonl"),
|
||||
cwd: PathBuf::from("/workspace/project"),
|
||||
title: Some("Gamma notes".to_string()),
|
||||
},
|
||||
],
|
||||
..Default::default()
|
||||
}),
|
||||
},
|
||||
ExternalAgentConfigMigrationItem {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Plugins,
|
||||
description: "Import plugins".to_string(),
|
||||
cwd: None,
|
||||
details: Some(MigrationDetails {
|
||||
plugins: vec![PluginsMigration {
|
||||
marketplace_name: "example".to_string(),
|
||||
plugin_names: vec!["formatter".to_string(), "reviewer".to_string()],
|
||||
}],
|
||||
..Default::default()
|
||||
}),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn completed_notification() -> ExternalAgentConfigImportCompletedNotification {
|
||||
ExternalAgentConfigImportCompletedNotification {
|
||||
import_id: "import-1".to_string(),
|
||||
item_type_results: vec![
|
||||
ExternalAgentConfigImportTypeResult {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Config,
|
||||
successes: vec![ExternalAgentConfigImportItemTypeSuccess {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Config,
|
||||
cwd: None,
|
||||
source: Some("settings.json".to_string()),
|
||||
target: Some("config.toml".to_string()),
|
||||
title: None,
|
||||
}],
|
||||
failures: Vec::new(),
|
||||
},
|
||||
ExternalAgentConfigImportTypeResult {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Memory,
|
||||
successes: vec![
|
||||
ExternalAgentConfigImportItemTypeSuccess {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Memory,
|
||||
cwd: None,
|
||||
source: Some("project-a".to_string()),
|
||||
target: Some("memory resources".to_string()),
|
||||
title: None,
|
||||
},
|
||||
ExternalAgentConfigImportItemTypeSuccess {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Memory,
|
||||
cwd: None,
|
||||
source: Some("project-b".to_string()),
|
||||
target: Some("memory resources".to_string()),
|
||||
title: None,
|
||||
},
|
||||
],
|
||||
failures: Vec::new(),
|
||||
},
|
||||
ExternalAgentConfigImportTypeResult {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Plugins,
|
||||
successes: vec![ExternalAgentConfigImportItemTypeSuccess {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Plugins,
|
||||
cwd: None,
|
||||
source: Some("formatter@example".to_string()),
|
||||
target: Some("formatter@example".to_string()),
|
||||
title: None,
|
||||
}],
|
||||
failures: vec![ExternalAgentConfigImportItemTypeFailure {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Plugins,
|
||||
error_type: Some("plugin_install_failed".to_string()),
|
||||
sub_error_type: Some("failed_to_copy_plugin_file".to_string()),
|
||||
failure_stage: "plugin_import".to_string(),
|
||||
message: "install failed".to_string(),
|
||||
cwd: Some(PathBuf::from("/workspace/project")),
|
||||
source: Some("deployer@example".to_string()),
|
||||
}],
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_agent_config_migration_messages_snapshot() {
|
||||
let selected_items = selected_items();
|
||||
let completed_notification = completed_notification();
|
||||
let messages = [0, 1, 2]
|
||||
.into_iter()
|
||||
.flat_map(|remaining_item_count| {
|
||||
external_agent_config_migration_started_lines(&selected_items, remaining_item_count)
|
||||
})
|
||||
.chain(external_agent_config_migration_finished_lines(
|
||||
&completed_notification,
|
||||
))
|
||||
.chain([
|
||||
Line::from(EXTERNAL_AGENT_CONFIG_MIGRATION_NO_ITEMS_MESSAGE),
|
||||
Line::from(EXTERNAL_AGENT_CONFIG_MIGRATION_REMOTE_UNAVAILABLE_MESSAGE),
|
||||
Line::from(EXTERNAL_AGENT_CONFIG_MIGRATION_DAEMON_UNAVAILABLE_MESSAGE),
|
||||
Line::from(EXTERNAL_AGENT_CONFIG_IMPORT_IN_PROGRESS_MESSAGE),
|
||||
])
|
||||
.map(|line| {
|
||||
line.spans
|
||||
.into_iter()
|
||||
.map(|span| span.content.into_owned())
|
||||
.collect::<String>()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
insta::assert_snapshot!("external_agent_config_migration_messages", messages);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memory_without_a_selection_counts_as_zero() {
|
||||
let item = ExternalAgentConfigMigrationItem {
|
||||
item_type: ExternalAgentConfigMigrationItemType::Memory,
|
||||
description: "Import memory".to_string(),
|
||||
cwd: None,
|
||||
details: None,
|
||||
};
|
||||
|
||||
assert_eq!(external_agent_config_migration_item_count(&item), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_agent_config_migration_status_lines_use_semantic_colors() {
|
||||
assert_eq!(
|
||||
external_agent_config_migration_started_lines(
|
||||
&selected_items(),
|
||||
/*remaining_item_count*/ 0,
|
||||
),
|
||||
vec![
|
||||
Line::from(vec![
|
||||
"• ".dim(),
|
||||
"Import started.".cyan(),
|
||||
" You can keep working while it finishes.".into(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
" ".into(),
|
||||
"Imported setup will apply to new chats.".dim(),
|
||||
]),
|
||||
Line::from(vec![" ".into(), "Importing:".cyan().bold()]),
|
||||
Line::from(vec![
|
||||
" ".into(),
|
||||
"Settings".cyan(),
|
||||
": ".into(),
|
||||
"1".green(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
" ".into(),
|
||||
"Memory".cyan(),
|
||||
": ".into(),
|
||||
"2".green(),
|
||||
" — ".dim(),
|
||||
"project-a, project-b".into(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
" ".into(),
|
||||
"Skills".cyan(),
|
||||
": ".into(),
|
||||
"4".green(),
|
||||
" — ".dim(),
|
||||
"triage, release-notes, risk-check, +1 more".into(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
" ".into(),
|
||||
"MCP servers".cyan(),
|
||||
": ".into(),
|
||||
"2".green(),
|
||||
" — ".dim(),
|
||||
"docs, issues".into(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
" ".into(),
|
||||
"Chat sessions".cyan(),
|
||||
": ".into(),
|
||||
"3".green(),
|
||||
" — ".dim(),
|
||||
"Alpha rollout, Beta review, Gamma notes".into(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
" ".into(),
|
||||
"Plugins".cyan(),
|
||||
": ".into(),
|
||||
"2".green(),
|
||||
" — ".dim(),
|
||||
"formatter, reviewer".into(),
|
||||
]),
|
||||
]
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
external_agent_config_migration_finished_lines(&completed_notification()),
|
||||
vec![
|
||||
Line::from(vec![
|
||||
"• ".dim(),
|
||||
"Import finished: ".into(),
|
||||
"4 imported".green(),
|
||||
", ".into(),
|
||||
"1 failed".red(),
|
||||
".".into(),
|
||||
]),
|
||||
Line::from(vec![" ".into(), "Results by type:".cyan().bold()]),
|
||||
Line::from(vec![
|
||||
" ".into(),
|
||||
"Settings".cyan(),
|
||||
": ".into(),
|
||||
"1 imported".green(),
|
||||
", ".into(),
|
||||
"0 failed".green(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
" ".into(),
|
||||
"Memory".cyan(),
|
||||
": ".into(),
|
||||
"2 imported".green(),
|
||||
", ".into(),
|
||||
"0 failed".green(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
" ".into(),
|
||||
"Plugins".cyan(),
|
||||
": ".into(),
|
||||
"1 imported".green(),
|
||||
", ".into(),
|
||||
"1 failed".red(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
" ".into(),
|
||||
"Run /import again to check for additional items.".dim(),
|
||||
]),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_agent_config_detection_keeps_one_or_multiple_available_sources() {
|
||||
let mut detection = ExternalAgentConfigDetection::default();
|
||||
detection.record_items(
|
||||
ExternalAgentConfigMigrationSource::Cla,
|
||||
vec![detected_item("first")],
|
||||
);
|
||||
detection.record_items(ExternalAgentConfigMigrationSource::Cur, Vec::new());
|
||||
let ExternalAgentConfigDetectionOutcome::Sources(sources) = detection.finish() else {
|
||||
panic!("expected one detected source");
|
||||
};
|
||||
assert_eq!(sources.len(), 1);
|
||||
assert_eq!(sources[0].source, ExternalAgentConfigMigrationSource::Cla);
|
||||
assert_eq!(sources[0].items, vec![detected_item("first")]);
|
||||
|
||||
let mut detection = ExternalAgentConfigDetection::default();
|
||||
detection.record_items(
|
||||
ExternalAgentConfigMigrationSource::Cla,
|
||||
vec![detected_item("first")],
|
||||
);
|
||||
detection.record_items(
|
||||
ExternalAgentConfigMigrationSource::Cur,
|
||||
vec![detected_item("second")],
|
||||
);
|
||||
let ExternalAgentConfigDetectionOutcome::Sources(sources) = detection.finish() else {
|
||||
panic!("expected two detected sources");
|
||||
};
|
||||
assert_eq!(sources.len(), 2);
|
||||
assert_eq!(sources[0].source, ExternalAgentConfigMigrationSource::Cla);
|
||||
assert_eq!(sources[1].source, ExternalAgentConfigMigrationSource::Cur);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_agent_config_detection_tolerates_a_partial_failure() {
|
||||
let mut detection = ExternalAgentConfigDetection::default();
|
||||
detection.record_error(ExternalAgentConfigMigrationSource::Cla, "unavailable");
|
||||
detection.record_items(
|
||||
ExternalAgentConfigMigrationSource::Cur,
|
||||
vec![detected_item("available")],
|
||||
);
|
||||
|
||||
let ExternalAgentConfigDetectionOutcome::Sources(sources) = detection.finish() else {
|
||||
panic!("expected the available source");
|
||||
};
|
||||
assert_eq!(sources.len(), 1);
|
||||
assert_eq!(sources[0].source, ExternalAgentConfigMigrationSource::Cur);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_agent_config_detection_distinguishes_no_items_from_total_failure() {
|
||||
assert!(matches!(
|
||||
ExternalAgentConfigDetection::default().finish(),
|
||||
ExternalAgentConfigDetectionOutcome::NoItems
|
||||
));
|
||||
|
||||
let mut detection = ExternalAgentConfigDetection::default();
|
||||
detection.record_error(ExternalAgentConfigMigrationSource::Cla, "first failure");
|
||||
detection.record_error(ExternalAgentConfigMigrationSource::Cur, "second failure");
|
||||
let ExternalAgentConfigDetectionOutcome::Failed(error) = detection.finish() else {
|
||||
panic!("expected detection failure");
|
||||
};
|
||||
assert_eq!(
|
||||
error,
|
||||
"Could not check for importable setup: Claude Code: first failure; Cursor: second failure"
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,262 @@
|
||||
use codex_app_server_protocol::ExternalAgentConfigMigrationItem;
|
||||
use codex_app_server_protocol::ExternalAgentConfigMigrationItemType;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct ExternalAgentConfigMigrationGroupModel {
|
||||
pub(crate) label: String,
|
||||
pub(crate) description: &'static str,
|
||||
pub(crate) item_indices: Vec<usize>,
|
||||
}
|
||||
|
||||
pub(crate) fn external_agent_config_migration_groups(
|
||||
items: &[ExternalAgentConfigMigrationItem],
|
||||
) -> Vec<ExternalAgentConfigMigrationGroupModel> {
|
||||
let tools_and_setup = items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(idx, item)| {
|
||||
(item.cwd.is_none() && item.item_type != ExternalAgentConfigMigrationItemType::Sessions)
|
||||
.then_some(idx)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let projects = items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(idx, item)| {
|
||||
(item.cwd.is_some() && item.item_type != ExternalAgentConfigMigrationItemType::Sessions)
|
||||
.then_some(idx)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let chat_sessions = items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(idx, item)| {
|
||||
(item.item_type == ExternalAgentConfigMigrationItemType::Sessions).then_some(idx)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut groups = Vec::new();
|
||||
if !tools_and_setup.is_empty() {
|
||||
groups.push(ExternalAgentConfigMigrationGroupModel {
|
||||
label: "Tools & setup".to_string(),
|
||||
description: "Settings, instructions, integrations, agents, commands, and skills",
|
||||
item_indices: tools_and_setup,
|
||||
});
|
||||
}
|
||||
if !projects.is_empty() {
|
||||
let project_count = projects
|
||||
.iter()
|
||||
.filter_map(|idx| items[*idx].cwd.as_deref())
|
||||
.collect::<BTreeSet<_>>()
|
||||
.len();
|
||||
groups.push(ExternalAgentConfigMigrationGroupModel {
|
||||
label: if project_count == 1 {
|
||||
"Current project".to_string()
|
||||
} else {
|
||||
format!("Projects ({project_count})")
|
||||
},
|
||||
description: "Add Codex files alongside your existing project files",
|
||||
item_indices: projects,
|
||||
});
|
||||
}
|
||||
if !chat_sessions.is_empty() {
|
||||
let session_count = chat_sessions
|
||||
.iter()
|
||||
.filter_map(|idx| items[*idx].details.as_ref())
|
||||
.map(|details| details.sessions.len())
|
||||
.sum::<usize>();
|
||||
groups.push(ExternalAgentConfigMigrationGroupModel {
|
||||
label: format!("Chat sessions ({session_count})"),
|
||||
description: "Last 30 days of chats",
|
||||
item_indices: chat_sessions,
|
||||
});
|
||||
}
|
||||
groups
|
||||
}
|
||||
|
||||
pub(crate) fn external_agent_config_migration_item_label(
|
||||
item: &ExternalAgentConfigMigrationItem,
|
||||
) -> &'static str {
|
||||
match item.item_type {
|
||||
ExternalAgentConfigMigrationItemType::AgentsMd => "Instructions",
|
||||
ExternalAgentConfigMigrationItemType::Config => "Settings",
|
||||
ExternalAgentConfigMigrationItemType::Skills => "Skills",
|
||||
ExternalAgentConfigMigrationItemType::Plugins => "Plugins",
|
||||
ExternalAgentConfigMigrationItemType::McpServerConfig => "MCP servers",
|
||||
ExternalAgentConfigMigrationItemType::Subagents => "Agents",
|
||||
ExternalAgentConfigMigrationItemType::Hooks => "Hooks",
|
||||
ExternalAgentConfigMigrationItemType::Commands => "Slash commands",
|
||||
ExternalAgentConfigMigrationItemType::Memory => "Memory",
|
||||
ExternalAgentConfigMigrationItemType::Sessions => "Recent chat sessions",
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn external_agent_config_migration_type_label(
|
||||
item_type: ExternalAgentConfigMigrationItemType,
|
||||
) -> &'static str {
|
||||
match item_type {
|
||||
ExternalAgentConfigMigrationItemType::AgentsMd => "Instructions",
|
||||
ExternalAgentConfigMigrationItemType::Config => "Settings",
|
||||
ExternalAgentConfigMigrationItemType::Skills => "Skills",
|
||||
ExternalAgentConfigMigrationItemType::Plugins => "Plugins",
|
||||
ExternalAgentConfigMigrationItemType::McpServerConfig => "MCP servers",
|
||||
ExternalAgentConfigMigrationItemType::Subagents => "Agents",
|
||||
ExternalAgentConfigMigrationItemType::Hooks => "Hooks",
|
||||
ExternalAgentConfigMigrationItemType::Commands => "Slash commands",
|
||||
ExternalAgentConfigMigrationItemType::Memory => "Memory",
|
||||
ExternalAgentConfigMigrationItemType::Sessions => "Chat sessions",
|
||||
}
|
||||
}
|
||||
|
||||
/// Summarizes the concrete objects represented by selected migration items.
|
||||
///
|
||||
/// Most detected item types carry the objects they will import in `details`; types without
|
||||
/// details represent one importable file or source directory per migration item.
|
||||
pub(crate) fn external_agent_config_migration_count_summary<'a>(
|
||||
items: impl IntoIterator<Item = &'a ExternalAgentConfigMigrationItem>,
|
||||
) -> String {
|
||||
let mut counts = Vec::<(ExternalAgentConfigMigrationItemType, usize)>::new();
|
||||
for item in items {
|
||||
let count = external_agent_config_migration_item_count(item);
|
||||
if let Some((_, type_count)) = counts
|
||||
.iter_mut()
|
||||
.find(|(item_type, _)| *item_type == item.item_type)
|
||||
{
|
||||
*type_count += count;
|
||||
} else {
|
||||
counts.push((item.item_type, count));
|
||||
}
|
||||
}
|
||||
|
||||
counts
|
||||
.into_iter()
|
||||
.map(|(item_type, count)| {
|
||||
format!(
|
||||
"{} {count}",
|
||||
external_agent_config_migration_type_label(item_type)
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
}
|
||||
|
||||
pub(crate) fn external_agent_config_migration_item_count(
|
||||
item: &ExternalAgentConfigMigrationItem,
|
||||
) -> usize {
|
||||
match item.item_type {
|
||||
ExternalAgentConfigMigrationItemType::Plugins => {
|
||||
item.details.as_ref().map_or(1, |details| {
|
||||
details
|
||||
.plugins
|
||||
.iter()
|
||||
.map(|plugin_group| plugin_group.plugin_names.len())
|
||||
.sum()
|
||||
})
|
||||
}
|
||||
ExternalAgentConfigMigrationItemType::McpServerConfig => item
|
||||
.details
|
||||
.as_ref()
|
||||
.map_or(1, |details| details.mcp_servers.len()),
|
||||
ExternalAgentConfigMigrationItemType::Subagents => item
|
||||
.details
|
||||
.as_ref()
|
||||
.map_or(1, |details| details.subagents.len()),
|
||||
ExternalAgentConfigMigrationItemType::Hooks => item
|
||||
.details
|
||||
.as_ref()
|
||||
.map_or(1, |details| details.hooks.len()),
|
||||
ExternalAgentConfigMigrationItemType::Commands => item
|
||||
.details
|
||||
.as_ref()
|
||||
.map_or(1, |details| details.commands.len()),
|
||||
ExternalAgentConfigMigrationItemType::Memory => item
|
||||
.details
|
||||
.as_ref()
|
||||
.map_or(0, |details| details.memory.len()),
|
||||
ExternalAgentConfigMigrationItemType::Sessions => item
|
||||
.details
|
||||
.as_ref()
|
||||
.map_or(1, |details| details.sessions.len()),
|
||||
ExternalAgentConfigMigrationItemType::Skills => item
|
||||
.details
|
||||
.as_ref()
|
||||
.map_or(1, |details| details.skills.len()),
|
||||
ExternalAgentConfigMigrationItemType::AgentsMd
|
||||
| ExternalAgentConfigMigrationItemType::Config => 1,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn external_agent_config_migration_item_detail(
|
||||
item: &ExternalAgentConfigMigrationItem,
|
||||
) -> Option<String> {
|
||||
let details = item.details.as_ref()?;
|
||||
match item.item_type {
|
||||
ExternalAgentConfigMigrationItemType::Plugins => None,
|
||||
ExternalAgentConfigMigrationItemType::Skills => Some(format_counted_details(
|
||||
"skill",
|
||||
details.skills.len(),
|
||||
details.skills.iter().map(|skill| skill.name.as_str()),
|
||||
)),
|
||||
ExternalAgentConfigMigrationItemType::McpServerConfig => Some(format_counted_details(
|
||||
"MCP server",
|
||||
details.mcp_servers.len(),
|
||||
details
|
||||
.mcp_servers
|
||||
.iter()
|
||||
.map(|server| server.name.as_str()),
|
||||
)),
|
||||
ExternalAgentConfigMigrationItemType::Subagents => Some(format_counted_details(
|
||||
"agent",
|
||||
details.subagents.len(),
|
||||
details.subagents.iter().map(|agent| agent.name.as_str()),
|
||||
)),
|
||||
ExternalAgentConfigMigrationItemType::Hooks => Some(format_counted_details(
|
||||
"hook",
|
||||
details.hooks.len(),
|
||||
details.hooks.iter().map(|hook| hook.name.as_str()),
|
||||
)),
|
||||
ExternalAgentConfigMigrationItemType::Commands => Some(format_counted_details(
|
||||
"slash command",
|
||||
details.commands.len(),
|
||||
details.commands.iter().map(|command| command.name.as_str()),
|
||||
)),
|
||||
ExternalAgentConfigMigrationItemType::Memory => {
|
||||
let memory = &details.memory;
|
||||
let count = memory.len();
|
||||
let noun = if count == 1 { "memory" } else { "memories" };
|
||||
let names = memory
|
||||
.iter()
|
||||
.map(String::as_str)
|
||||
.take(4)
|
||||
.collect::<Vec<_>>();
|
||||
Some(if names.is_empty() {
|
||||
format!("{count} {noun}")
|
||||
} else {
|
||||
format!("{count} {noun}: {}", names.join(", "))
|
||||
})
|
||||
}
|
||||
ExternalAgentConfigMigrationItemType::Sessions => Some(format_counted_details(
|
||||
"chat session",
|
||||
details.sessions.len(),
|
||||
details
|
||||
.sessions
|
||||
.iter()
|
||||
.filter_map(|session| session.title.as_deref()),
|
||||
)),
|
||||
ExternalAgentConfigMigrationItemType::AgentsMd
|
||||
| ExternalAgentConfigMigrationItemType::Config => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn format_counted_details<'a>(
|
||||
noun: &str,
|
||||
count: usize,
|
||||
names: impl Iterator<Item = &'a str>,
|
||||
) -> String {
|
||||
let suffix = if count == 1 { "" } else { "s" };
|
||||
match names.take(4).collect::<Vec<_>>() {
|
||||
names if names.is_empty() => format!("{count} {noun}{suffix}"),
|
||||
names => format!("{count} {noun}{suffix}: {}", names.join(", ")),
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
---
|
||||
source: tui/src/external_agent_config_migration/flow_tests.rs
|
||||
expression: messages
|
||||
---
|
||||
• Import started. You can keep working while it finishes.
|
||||
Imported setup will apply to new chats.
|
||||
Importing:
|
||||
Settings: 1
|
||||
Memory: 2 — project-a, project-b
|
||||
Skills: 4 — triage, release-notes, risk-check, +1 more
|
||||
MCP servers: 2 — docs, issues
|
||||
Chat sessions: 3 — Alpha rollout, Beta review, Gamma notes
|
||||
Plugins: 2 — formatter, reviewer
|
||||
• Import started. You can keep working while it finishes.
|
||||
Imported setup will apply to new chats.
|
||||
Importing:
|
||||
Settings: 1
|
||||
Memory: 2 — project-a, project-b
|
||||
Skills: 4 — triage, release-notes, risk-check, +1 more
|
||||
MCP servers: 2 — docs, issues
|
||||
Chat sessions: 3 — Alpha rollout, Beta review, Gamma notes
|
||||
Plugins: 2 — formatter, reviewer
|
||||
1 additional item remains. After it finishes, run /import again to review it.
|
||||
• Import started. You can keep working while it finishes.
|
||||
Imported setup will apply to new chats.
|
||||
Importing:
|
||||
Settings: 1
|
||||
Memory: 2 — project-a, project-b
|
||||
Skills: 4 — triage, release-notes, risk-check, +1 more
|
||||
MCP servers: 2 — docs, issues
|
||||
Chat sessions: 3 — Alpha rollout, Beta review, Gamma notes
|
||||
Plugins: 2 — formatter, reviewer
|
||||
2 additional items remain. After it finishes, run /import again to review them.
|
||||
• Import finished: 4 imported, 1 failed.
|
||||
Results by type:
|
||||
Settings: 1 imported, 0 failed
|
||||
Memory: 2 imported, 0 failed
|
||||
Plugins: 1 imported, 1 failed
|
||||
Run /import again to check for additional items.
|
||||
No compatible setup was found to import.
|
||||
Import from other apps is unavailable in remote sessions. Start Codex locally and run /import.
|
||||
Import from other apps is unavailable while Codex is connected to the local app-server daemon. Stop the daemon, restart Codex, and run /import.
|
||||
A previous external agent import is still running. Wait for it to finish before importing again.
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
---
|
||||
source: tui/src/external_agent_config_migration/source_tests.rs
|
||||
expression: terminal.backend()
|
||||
---
|
||||
|
||||
Choose an import source
|
||||
|
||||
Select the app whose setup you want to import.
|
||||
|
||||
› 1. Claude Code
|
||||
2. Cursor
|
||||
|
||||
Press enter to continue
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
---
|
||||
source: tui/src/external_agent_config_migration/mod.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
> Choose what to import
|
||||
Choose items to import.
|
||||
Codex may add files to your current project folder.
|
||||
Your existing setup will not be changed.
|
||||
Home
|
||||
› [x] Settings
|
||||
Import /Users/alex/.claude/settings.json into /Users/alex/.codex/conf…
|
||||
[x] Memory
|
||||
Import memory files from /Users/alex/.claude/projects to /Users/alex/…
|
||||
1 memory: project
|
||||
[x] Recent chat sessions
|
||||
Import recent Claude Code sessions
|
||||
1 chat session: Investigate migration UX
|
||||
|
||||
Current project: /workspace/project
|
||||
[x] Plugins
|
||||
Import enabled plugins from .claude/settings.json (4 marketplaces, 6 …
|
||||
• acme-tools: deployer, formatter, +1 more
|
||||
• team-marketplace: asana
|
||||
• debug: sample
|
||||
• +1 more marketplaces
|
||||
[x] Instructions
|
||||
Import CLAUDE.md to AGENTS.md
|
||||
|
||||
Selected 5 of 5 items.
|
||||
1. Review selection
|
||||
Use ↑/↓ to move, space to toggle, b to go back
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
---
|
||||
source: tui/src/external_agent_config_migration/mod.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
> Choose what to import
|
||||
Choose items to import.
|
||||
Codex may add files to your current project folder.
|
||||
Your existing setup will not be changed.
|
||||
Home
|
||||
[x] Settings
|
||||
Import /Users/alex/.claude/settings.json into /Users/alex/.codex/conf…
|
||||
[x] Recent chat sessions
|
||||
Import recent Claude Code sessions
|
||||
1 chat session: Investigate migration UX
|
||||
|
||||
Current project: /workspace/project
|
||||
[x] Plugins
|
||||
Import enabled plugins from .claude/settings.json (4 marketplaces, 6 …
|
||||
• acme-tools: deployer, formatter, +1 more
|
||||
• team-marketplace: asana
|
||||
• debug: sample
|
||||
• +1 more marketplaces
|
||||
[x] Instructions
|
||||
Import CLAUDE.md to AGENTS.md
|
||||
|
||||
Selected 4 of 4 items.
|
||||
› 1. Review selection
|
||||
Press enter to continue, ↑/↓ to move, b to go back
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
---
|
||||
source: tui/src/external_agent_config_migration/mod.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
> Choose what to import
|
||||
Choose items to import.
|
||||
Codex may add files to your current project folder.
|
||||
Your existing setup will not be changed.
|
||||
Home
|
||||
[x] Settings
|
||||
Import /Users/alex/.claude/settings.json into /Users/alex/.codex/conf…
|
||||
[x] Recent chat sessions
|
||||
Import recent Claude Code sessions
|
||||
1 chat session: Investigate migration UX
|
||||
|
||||
Current project: C:\workspace\project
|
||||
[x] Plugins
|
||||
Import enabled plugins from .claude/settings.json (4 marketplaces, 6 …
|
||||
• acme-tools: deployer, formatter, +1 more
|
||||
• team-marketplace: asana
|
||||
• debug: sample
|
||||
• +1 more marketplaces
|
||||
[x] Instructions
|
||||
Import CLAUDE.md to AGENTS.md
|
||||
|
||||
Selected 4 of 4 items.
|
||||
› 1. Review selection
|
||||
Press enter to continue, ↑/↓ to move, b to go back
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
---
|
||||
source: tui/src/external_agent_config_migration/mod.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
> Choose what to import
|
||||
Choose items to import.
|
||||
Codex may add files to your current project folder.
|
||||
Your existing setup will not be changed.
|
||||
Home
|
||||
› [x] Settings
|
||||
Import /Users/alex/.claude/settings.json into /Users/alex/.codex/conf…
|
||||
[x] Memory
|
||||
Import memory files from /Users/alex/.claude/projects to /Users/alex/…
|
||||
1 memory: project
|
||||
[x] Recent chat sessions
|
||||
Import recent Claude Code sessions
|
||||
1 chat session: Investigate migration UX
|
||||
|
||||
Current project: C:\workspace\project
|
||||
[x] Plugins
|
||||
Import enabled plugins from .claude/settings.json (4 marketplaces, 6 …
|
||||
• acme-tools: deployer, formatter, +1 more
|
||||
• team-marketplace: asana
|
||||
• debug: sample
|
||||
• +1 more marketplaces
|
||||
[x] Instructions
|
||||
Import CLAUDE.md to AGENTS.md
|
||||
|
||||
Selected 5 of 5 items.
|
||||
1. Review selection
|
||||
Use ↑/↓ to move, space to toggle, b to go back
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
---
|
||||
source: tui/src/external_agent_config_migration/mod.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
> Import setup
|
||||
Bring over supported setup from another coding agent.
|
||||
Codex may add files to your current project folder.
|
||||
Your existing setup will not be changed.
|
||||
[x] Tools & setup
|
||||
Settings, instructions, integrations, agents, commands, and skills
|
||||
Importing: Settings 1, Memory 1
|
||||
[x] Current project
|
||||
Add Codex files alongside your existing project files
|
||||
Importing: Plugins 6, Instructions 1
|
||||
[x] Chat sessions (1)
|
||||
Last 30 days of chats
|
||||
Importing: Chat sessions 1
|
||||
|
||||
Selected 5 of 5 items.
|
||||
› 1. Import selected
|
||||
2. Customize selection
|
||||
3. Cancel
|
||||
Use ↑/↓ to move, enter to select, c to customize
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
---
|
||||
source: tui/src/external_agent_config_migration/mod.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
> Import setup
|
||||
Bring over supported setup from another coding agent.
|
||||
Codex may add files to your current project folder.
|
||||
Your existing setup will not be changed.
|
||||
[x] Tools & setup
|
||||
Settings, instructions, integrations, agents, commands, and skills
|
||||
Importing: Settings 1, Memory 1
|
||||
[x] Current project
|
||||
Add Codex files alongside your existing project files
|
||||
Importing: Plugins 6, Instructions 1
|
||||
[x] Chat sessions (1)
|
||||
Last 30 days of chats
|
||||
Importing: Chat sessions 1
|
||||
|
||||
Selected 5 of 5 items.
|
||||
› 1. Import selected
|
||||
2. Customize selection
|
||||
3. Cancel
|
||||
Use ↑/↓ to move, enter to select, c to customize
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
---
|
||||
source: tui/src/external_agent_config_migration/mod.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
> Choose what to import
|
||||
Choose items to import.
|
||||
Codex may add files to your current project folder.
|
||||
Your existing setup will not be changed.
|
||||
Home
|
||||
› [x] Settings
|
||||
Import /Users/alex/.cursor/cli-config.json into /Users/alex/.codex/co…
|
||||
|
||||
Selected 1 of 1 item.
|
||||
1. Review selection
|
||||
Use ↑/↓ to move, space to toggle, b to go back
|
||||
@@ -0,0 +1,200 @@
|
||||
use crate::key_hint;
|
||||
use crate::render::Insets;
|
||||
use crate::render::renderable::ColumnRenderable;
|
||||
use crate::render::renderable::Renderable;
|
||||
use crate::render::renderable::RenderableExt as _;
|
||||
use crate::tui::FrameRequester;
|
||||
use crate::tui::Tui;
|
||||
use crate::tui::TuiEvent;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyEventKind;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::prelude::Stylize as _;
|
||||
use ratatui::prelude::Widget;
|
||||
use ratatui::text::Line;
|
||||
use ratatui::text::Span;
|
||||
use ratatui::widgets::Clear;
|
||||
use ratatui::widgets::WidgetRef;
|
||||
use tokio_stream::StreamExt;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum ExternalAgentConfigMigrationSource {
|
||||
Cla,
|
||||
Cur,
|
||||
}
|
||||
|
||||
impl ExternalAgentConfigMigrationSource {
|
||||
pub(crate) const ALL: [Self; 2] = [Self::Cla, Self::Cur];
|
||||
|
||||
pub(crate) fn migration_source(self) -> &'static str {
|
||||
match self {
|
||||
Self::Cla => "claude-code",
|
||||
Self::Cur => "cursor",
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::Cla => "Claude Code",
|
||||
Self::Cur => "Cursor",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn run_external_agent_config_source_prompt(
|
||||
tui: &mut Tui,
|
||||
sources: &[ExternalAgentConfigMigrationSource],
|
||||
) -> Option<ExternalAgentConfigMigrationSource> {
|
||||
let mut screen = ExternalAgentConfigSourceScreen::new(tui.frame_requester(), sources);
|
||||
let _ = tui.draw(u16::MAX, |frame| {
|
||||
frame.render_widget_ref(&screen, frame.area());
|
||||
});
|
||||
|
||||
let events = tui.event_stream();
|
||||
tokio::pin!(events);
|
||||
|
||||
while !screen.is_done() {
|
||||
if let Some(event) = events.next().await {
|
||||
match event {
|
||||
TuiEvent::Key(key_event) => screen.handle_key(key_event),
|
||||
TuiEvent::Paste(_) => {}
|
||||
TuiEvent::Draw | TuiEvent::Resize => {
|
||||
let _ = tui.draw(u16::MAX, |frame| {
|
||||
frame.render_widget_ref(&screen, frame.area());
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
screen.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
screen.selection()
|
||||
}
|
||||
|
||||
struct ExternalAgentConfigSourceScreen {
|
||||
request_frame: FrameRequester,
|
||||
sources: Vec<ExternalAgentConfigMigrationSource>,
|
||||
highlighted_idx: usize,
|
||||
selection: Option<ExternalAgentConfigMigrationSource>,
|
||||
done: bool,
|
||||
}
|
||||
|
||||
impl ExternalAgentConfigSourceScreen {
|
||||
fn new(request_frame: FrameRequester, sources: &[ExternalAgentConfigMigrationSource]) -> Self {
|
||||
Self {
|
||||
request_frame,
|
||||
sources: sources.to_vec(),
|
||||
highlighted_idx: 0,
|
||||
selection: None,
|
||||
done: sources.is_empty(),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_key(&mut self, key_event: KeyEvent) {
|
||||
if key_event.kind == KeyEventKind::Release || self.sources.is_empty() {
|
||||
return;
|
||||
}
|
||||
if key_event.modifiers.contains(KeyModifiers::CONTROL)
|
||||
&& matches!(key_event.code, KeyCode::Char('c') | KeyCode::Char('d'))
|
||||
{
|
||||
self.cancel();
|
||||
return;
|
||||
}
|
||||
match key_event.code {
|
||||
KeyCode::Up | KeyCode::Char('k') => self.move_highlight(/*delta*/ -1),
|
||||
KeyCode::Down | KeyCode::Char('j') => self.move_highlight(/*delta*/ 1),
|
||||
KeyCode::Char(character) if character.is_ascii_digit() => {
|
||||
let Some(index) = character
|
||||
.to_digit(10)
|
||||
.and_then(|index| index.checked_sub(1))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
self.select(index as usize);
|
||||
}
|
||||
KeyCode::Enter => self.select(self.highlighted_idx),
|
||||
KeyCode::Esc => self.cancel(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn move_highlight(&mut self, delta: isize) {
|
||||
self.highlighted_idx = self
|
||||
.highlighted_idx
|
||||
.saturating_add_signed(delta)
|
||||
.min(self.sources.len().saturating_sub(1));
|
||||
self.request_frame.schedule_frame();
|
||||
}
|
||||
|
||||
fn select(&mut self, index: usize) {
|
||||
let Some(source) = self.sources.get(index).copied() else {
|
||||
return;
|
||||
};
|
||||
self.selection = Some(source);
|
||||
self.done = true;
|
||||
self.request_frame.schedule_frame();
|
||||
}
|
||||
|
||||
fn cancel(&mut self) {
|
||||
self.selection = None;
|
||||
self.done = true;
|
||||
self.request_frame.schedule_frame();
|
||||
}
|
||||
|
||||
fn is_done(&self) -> bool {
|
||||
self.done
|
||||
}
|
||||
|
||||
fn selection(&self) -> Option<ExternalAgentConfigMigrationSource> {
|
||||
self.selection
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetRef for &ExternalAgentConfigSourceScreen {
|
||||
fn render_ref(&self, area: Rect, buf: &mut Buffer) {
|
||||
Clear.render(area, buf);
|
||||
let mut column = ColumnRenderable::new();
|
||||
column.push("");
|
||||
column.push("Choose an import source".bold());
|
||||
column.push("");
|
||||
column.push(
|
||||
Line::from("Select the app whose setup you want to import.".dim()).inset(Insets::tlbr(
|
||||
/*top*/ 0, /*left*/ 2, /*bottom*/ 0, /*right*/ 0,
|
||||
)),
|
||||
);
|
||||
column.push("");
|
||||
for (index, source) in self.sources.iter().enumerate() {
|
||||
let prefix = if index == self.highlighted_idx {
|
||||
"›"
|
||||
} else {
|
||||
" "
|
||||
};
|
||||
let label = Span::from(format!("{prefix} {}. {}", index + 1, source.label()));
|
||||
column.push(Line::from(if index == self.highlighted_idx {
|
||||
label.cyan()
|
||||
} else {
|
||||
label
|
||||
}));
|
||||
}
|
||||
column.push("");
|
||||
column.push(
|
||||
Line::from(vec![
|
||||
"Press ".dim(),
|
||||
key_hint::plain(KeyCode::Enter).into(),
|
||||
" to continue".dim(),
|
||||
])
|
||||
.inset(Insets::tlbr(
|
||||
/*top*/ 0, /*left*/ 2, /*bottom*/ 0, /*right*/ 0,
|
||||
)),
|
||||
);
|
||||
column.render(area, buf);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "source_tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,43 @@
|
||||
use super::*;
|
||||
use crate::test_backend::VT100Backend;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::Terminal;
|
||||
use ratatui::widgets::FrameExt;
|
||||
|
||||
fn new_screen() -> ExternalAgentConfigSourceScreen {
|
||||
ExternalAgentConfigSourceScreen::new(
|
||||
FrameRequester::test_dummy(),
|
||||
&ExternalAgentConfigMigrationSource::ALL,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_agent_config_source_prompt_snapshot() {
|
||||
let screen = new_screen();
|
||||
let mut terminal =
|
||||
Terminal::new(VT100Backend::new(/*width*/ 80, /*height*/ 12)).expect("terminal");
|
||||
terminal
|
||||
.draw(|frame| frame.render_widget_ref(&screen, frame.area()))
|
||||
.expect("render source prompt");
|
||||
insta::assert_snapshot!("external_agent_config_source_prompt", terminal.backend());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_agent_config_source_prompt_selects_highlighted_source() {
|
||||
let mut screen = new_screen();
|
||||
screen.handle_key(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE));
|
||||
screen.handle_key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
assert_eq!(
|
||||
screen.selection(),
|
||||
Some(ExternalAgentConfigMigrationSource::Cur)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_agent_config_source_prompt_can_cancel() {
|
||||
let mut screen = new_screen();
|
||||
screen.handle_key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
|
||||
assert_eq!(screen.selection(), None);
|
||||
}
|
||||
Reference in new issue
Block a user