Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src-tauri/src/cli/commands/skills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use crate::app_config::{AppType, SkillApps};
use crate::cli::commands::app_targets::{
app_target_names, app_targets_or_default, parse_app_targets, supported_app_target_labels,
};
use crate::cli::i18n::texts;
use crate::cli::ui::{create_table, highlight, info, success};
use crate::error::AppError;
use crate::services::skill::{ImportSkillSelection, SkillRepo, SyncMethod};
use crate::services::skill::{ImportSkillSelection, SkillRepo, SkillStorageLocation, SyncMethod};
use crate::services::SkillService;

#[derive(Subcommand)]
Expand Down Expand Up @@ -110,6 +111,12 @@ pub enum SkillsCommand {
#[arg(value_enum)]
method: Option<SyncMethod>,
},
/// Get or change the managed Skills storage location
StorageLocation {
/// Optional location to set (omit to show current)
#[arg(value_enum)]
location: Option<SkillStorageLocation>,
},
/// Manage skill repositories
#[command(subcommand)]
Repos(SkillReposCommand),
Expand Down Expand Up @@ -164,6 +171,7 @@ pub fn execute(cmd: SkillsCommand, app: Option<AppType>) -> Result<(), AppError>
SkillsCommand::ImportFromApps { apps, directories } => import_from_apps(apps, directories),
SkillsCommand::Info { spec } => show_skill_info(&spec),
SkillsCommand::SyncMethod { method } => sync_method(method),
SkillsCommand::StorageLocation { location } => storage_location(location),
SkillsCommand::Repos(repos_cmd) => execute_repos(repos_cmd),
}
}
Expand Down Expand Up @@ -619,6 +627,46 @@ fn sync_method(method: Option<SyncMethod>) -> Result<(), AppError> {
Ok(())
}

fn storage_location(location: Option<SkillStorageLocation>) -> Result<(), AppError> {
let Some(target) = location else {
println!(
"{}",
match crate::settings::get_skill_storage_location() {
SkillStorageLocation::CcSwitch => "cc-switch",
SkillStorageLocation::Unified => "unified",
}
);
return Ok(());
};

let result = SkillService::migrate_storage(target)?;
let location = texts::tui_skills_storage_location_name(target);
let summary = if result.errors.is_empty() {
texts::tui_toast_skills_storage_location_set(
location,
result.migrated_count,
result.skipped_count,
)
} else {
texts::tui_toast_skills_storage_location_partial(
location,
result.migrated_count,
result.skipped_count,
result.errors.len(),
)
};

if result.errors.is_empty() {
println!("{}", success(&summary));
Ok(())
} else {
Err(AppError::Message(format!(
"{summary}\n{}",
result.errors.join("\n")
)))
}
}

fn parse_repo_spec(raw: &str) -> Result<SkillRepo, AppError> {
let raw = raw.trim().trim_end_matches('/');
if raw.is_empty() {
Expand Down
76 changes: 76 additions & 0 deletions src-tauri/src/cli/i18n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5653,6 +5653,53 @@ pub mod texts {
}
}

pub fn tui_settings_skills_storage_location_label() -> &'static str {
if is_chinese() {
"技能存储位置"
} else {
"Skill storage location"
}
}

pub fn tui_skills_storage_location_title() -> &'static str {
if is_chinese() {
"选择技能存储位置"
} else {
"Select Skill Storage Location"
}
}

pub fn tui_skills_storage_location_name(
location: crate::services::skill::SkillStorageLocation,
) -> &'static str {
match location {
crate::services::skill::SkillStorageLocation::CcSwitch => {
"CC Switch (~/.cc-switch/skills)"
}
crate::services::skill::SkillStorageLocation::Unified => "Unified (~/.agents/skills)",
}
}

pub fn tui_confirm_skills_storage_location(
location: crate::services::skill::SkillStorageLocation,
count: usize,
) -> String {
let target = tui_skills_storage_location_name(location);
if is_chinese() {
format!("将把 {count} 个已管理技能迁移到 {target},并刷新各应用的技能部署。继续吗?")
} else {
format!("Move {count} managed Skill(s) to {target} and refresh their app deployments?")
}
}

pub fn tui_skills_storage_location_loading() -> &'static str {
if is_chinese() {
"正在迁移技能并刷新应用部署..."
} else {
"Moving Skills and refreshing app deployments..."
}
}

pub fn tui_skills_sync_method_name(method: crate::services::skill::SyncMethod) -> &'static str {
match method {
crate::services::skill::SyncMethod::Auto => {
Expand Down Expand Up @@ -8601,6 +8648,35 @@ pub mod texts {
}
}

pub fn tui_toast_skills_storage_location_set(
location: &str,
migrated: usize,
skipped: usize,
) -> String {
if is_chinese() {
format!("技能存储位置已切换为 {location}:迁移 {migrated} 个,跳过 {skipped} 个。")
} else {
format!("Skill storage set to {location}: {migrated} moved, {skipped} skipped.")
}
}

pub fn tui_toast_skills_storage_location_partial(
location: &str,
migrated: usize,
skipped: usize,
failed: usize,
) -> String {
if is_chinese() {
format!(
"技能存储已切换为 {location}:迁移 {migrated} 个,跳过 {skipped} 个,失败 {failed} 个。"
)
} else {
format!(
"Skill storage set to {location}: {migrated} moved, {skipped} skipped, {failed} failed."
)
}
}

pub fn tui_toast_repo_spec_empty() -> &'static str {
if is_chinese() {
"仓库不能为空。"
Expand Down
31 changes: 31 additions & 0 deletions src-tauri/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,37 @@ mod tests {
}
}

#[test]
fn parses_skills_storage_location_query_and_values() {
let query = Cli::parse_from(["cc-switch", "skills", "storage-location"]);
assert!(matches!(
query.command,
Some(Commands::Skills(
super::commands::skills::SkillsCommand::StorageLocation { location: None }
))
));

let unified = Cli::parse_from(["cc-switch", "skills", "storage-location", "unified"]);
assert!(matches!(
unified.command,
Some(Commands::Skills(
super::commands::skills::SkillsCommand::StorageLocation {
location: Some(crate::services::skill::SkillStorageLocation::Unified)
}
))
));

let cc_switch = Cli::parse_from(["cc-switch", "skills", "storage-location", "cc_switch"]);
assert!(matches!(
cc_switch.command,
Some(Commands::Skills(
super::commands::skills::SkillsCommand::StorageLocation {
location: Some(crate::services::skill::SkillStorageLocation::CcSwitch)
}
))
));
}

#[test]
fn parses_manual_skill_update_commands() {
let check = Cli::parse_from(["cc-switch", "skills", "check-updates"]);
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/cli/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::app_config::AppType;
use crate::cli::i18n::current_language;
use crate::cli::i18n::texts;
use crate::cli::i18n::Language;
use crate::services::skill::SyncMethod;
use crate::services::skill::{SkillStorageLocation, SyncMethod};

use super::data::UiData;
use super::form::{
Expand Down
7 changes: 6 additions & 1 deletion src-tauri/src/cli/tui/app/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ pub enum Action {
SkillsSetSyncMethod {
method: SyncMethod,
},
SkillsSetStorageLocation {
location: SkillStorageLocation,
},
SkillsDiscover {
query: String,
source: SkillsDiscoverSource,
Expand Down Expand Up @@ -500,6 +503,7 @@ pub enum SettingsItem {
PreferredEditor,
VisibleAppsMode,
VisibleApps,
SkillsStorageLocation,
OpenClawConfigDir,
ManagedAccounts,
SkipClaudeOnboarding,
Expand All @@ -512,14 +516,15 @@ pub enum SettingsItem {
}

impl SettingsItem {
pub const ALL: [SettingsItem; 15] = [
pub const ALL: [SettingsItem; 16] = [
SettingsItem::ManagedAccounts,
SettingsItem::Language,
SettingsItem::Theme,
SettingsItem::Icons,
SettingsItem::PreferredEditor,
SettingsItem::VisibleAppsMode,
SettingsItem::VisibleApps,
SettingsItem::SkillsStorageLocation,
SettingsItem::OpenClawConfigDir,
SettingsItem::SkipClaudeOnboarding,
SettingsItem::ClaudePluginIntegration,
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/cli/tui/app/content_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,14 @@ impl App {
};
Action::None
}
Some(SettingsItem::SkillsStorageLocation) => {
self.overlay = Overlay::SkillsStorageLocationPicker {
selected: storage_location_picker_index(
crate::settings::get_skill_storage_location(),
),
};
Action::None
}
Some(SettingsItem::OpenClawConfigDir) => {
let buffer = crate::settings::get_settings()
.openclaw_config_dir
Expand Down
14 changes: 14 additions & 0 deletions src-tauri/src/cli/tui/app/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,20 @@ pub(crate) fn sync_method_for_picker_index(index: usize) -> SyncMethod {
}
}

pub(crate) fn storage_location_picker_index(location: SkillStorageLocation) -> usize {
match location {
SkillStorageLocation::CcSwitch => 0,
SkillStorageLocation::Unified => 1,
}
}

pub(crate) fn storage_location_for_picker_index(index: usize) -> SkillStorageLocation {
match index {
1 => SkillStorageLocation::Unified,
_ => SkillStorageLocation::CcSwitch,
}
}

pub(crate) fn openclaw_tools_profile_picker_index(profile: Option<&str>) -> Option<usize> {
OPENCLAW_TOOLS_PROFILE_PICKER_VALUES
.iter()
Expand Down
5 changes: 5 additions & 0 deletions src-tauri/src/cli/tui/app/overlay_handlers/dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ impl App {
ConfirmAction::SkillsUninstall { directory } => Action::SkillsUninstall {
directory: directory.clone(),
},
ConfirmAction::SkillsMigrateStorage { location } => {
Action::SkillsSetStorageLocation {
location: *location,
}
}
ConfirmAction::SkillsRepoRemove { owner, name } => Action::SkillsRepoRemove {
owner: owner.clone(),
name: name.clone(),
Expand Down
49 changes: 49 additions & 0 deletions src-tauri/src/cli/tui/app/overlay_handlers/pickers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ impl App {
if let Some(action) = self.handle_sync_method_picker_key(key, data) {
return Some(action);
}
if let Some(action) = self.handle_storage_location_picker_key(key, data) {
return Some(action);
}
if let Some(action) = self.handle_claude_api_format_picker_key(key, data) {
return Some(action);
}
Expand Down Expand Up @@ -285,6 +288,52 @@ impl App {
})
}

fn handle_storage_location_picker_key(
&mut self,
key: KeyEvent,
data: &UiData,
) -> Option<Action> {
let Overlay::SkillsStorageLocationPicker { selected } = &mut self.overlay else {
return None;
};

Some(match key.code {
KeyCode::Esc => {
self.close_overlay();
Action::None
}
KeyCode::Up => {
*selected = selected.saturating_sub(1);
Action::None
}
KeyCode::Down => {
*selected = (*selected + 1).min(1);
Action::None
}
KeyCode::Enter => {
let location = storage_location_for_picker_index(*selected);
if location == crate::settings::get_skill_storage_location() {
self.overlay = Overlay::None;
Action::SkillsSetStorageLocation { location }
} else if data.skills.installed.is_empty() {
self.overlay = Overlay::None;
Action::SkillsSetStorageLocation { location }
} else {
self.overlay = Overlay::Confirm(ConfirmOverlay {
title: texts::tui_confirm_title().to_string(),
message: texts::tui_confirm_skills_storage_location(
location,
data.skills.installed.len(),
),
action: ConfirmAction::SkillsMigrateStorage { location },
});
Action::None
}
}
_ => Action::None,
})
}

fn handle_claude_api_format_picker_key(
&mut self,
key: KeyEvent,
Expand Down
Loading
Loading