代码警告消除和优化
This commit is contained in:
@@ -1126,7 +1126,7 @@ fn list_skills_from_dir(
|
||||
}
|
||||
by_id.insert(
|
||||
id.clone(),
|
||||
build_skill_item(id, scope.clone(), AgentSkillLayout::SkillDirectory, path),
|
||||
build_skill_item(id, scope, AgentSkillLayout::SkillDirectory, path),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@@ -1145,7 +1145,7 @@ fn list_skills_from_dir(
|
||||
}
|
||||
by_id.insert(
|
||||
stem.clone(),
|
||||
build_skill_item(stem, scope.clone(), AgentSkillLayout::MarkdownFile, path),
|
||||
build_skill_item(stem, scope, AgentSkillLayout::MarkdownFile, path),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1167,7 +1167,7 @@ fn locate_existing_skill(
|
||||
if skill_dir.is_dir() && skill_dir.join("SKILL.md").is_file() {
|
||||
return Some(build_skill_item(
|
||||
skill_id.to_string(),
|
||||
scope.clone(),
|
||||
scope,
|
||||
AgentSkillLayout::SkillDirectory,
|
||||
skill_dir,
|
||||
));
|
||||
@@ -1542,6 +1542,7 @@ pub async fn acp_clear_binary_cache(agent_type: AgentType) -> Result<(), AcpErro
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn acp_update_agent_preferences(
|
||||
agent_type: AgentType,
|
||||
enabled: bool,
|
||||
@@ -1923,8 +1924,8 @@ pub async fn acp_list_agent_skills(
|
||||
|
||||
let mut skills = skills_by_key.into_values().collect::<Vec<_>>();
|
||||
skills.sort_by(|a, b| {
|
||||
scope_rank(a.scope.clone())
|
||||
.cmp(&scope_rank(b.scope.clone()))
|
||||
scope_rank(a.scope)
|
||||
.cmp(&scope_rank(b.scope))
|
||||
.then_with(|| a.name.cmp(&b.name))
|
||||
});
|
||||
|
||||
@@ -1953,7 +1954,7 @@ pub async fn acp_read_agent_skill(
|
||||
|
||||
let skill = locate_existing_skill_across_dirs(&dirs, spec.kind, &id, scope)
|
||||
.ok_or_else(|| AcpError::protocol(format!("skill not found: {id}")))?;
|
||||
let content_path = skill_content_path(skill.layout.clone(), Path::new(&skill.path));
|
||||
let content_path = skill_content_path(skill.layout, Path::new(&skill.path));
|
||||
let content = fs::read_to_string(&content_path)
|
||||
.map_err(|e| AcpError::protocol(format!("failed to read skill content: {e}")))?;
|
||||
Ok(AgentSkillContent { skill, content })
|
||||
@@ -1998,7 +1999,7 @@ pub async fn acp_save_agent_skill(
|
||||
};
|
||||
|
||||
let skill_path = PathBuf::from(&skill.path);
|
||||
let content_path = skill_content_path(skill.layout.clone(), &skill_path);
|
||||
let content_path = skill_content_path(skill.layout, &skill_path);
|
||||
|
||||
if skill.layout == AgentSkillLayout::SkillDirectory {
|
||||
fs::create_dir_all(&skill_path).map_err(|e| {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::LazyLock;
|
||||
use std::time::Duration;
|
||||
|
||||
use serde::de::DeserializeOwned;
|
||||
@@ -11,6 +12,14 @@ use crate::app_error::AppCommandError;
|
||||
|
||||
const MARKETPLACE_OFFICIAL: &str = "official_registry";
|
||||
const MARKETPLACE_SMITHERY: &str = "smithery";
|
||||
static MARKETPLACE_HTTP_CLIENT: LazyLock<Result<reqwest::Client, String>> = LazyLock::new(|| {
|
||||
reqwest::Client::builder()
|
||||
.connect_timeout(Duration::from_secs(8))
|
||||
.timeout(Duration::from_secs(20))
|
||||
.user_agent("codeg-mcp-market/1.0")
|
||||
.build()
|
||||
.map_err(|e| format!("failed to initialize marketplace HTTP client: {e}"))
|
||||
});
|
||||
|
||||
fn mcp_invalid_input(message: impl Into<String>) -> AppCommandError {
|
||||
AppCommandError::invalid_input(message)
|
||||
@@ -588,11 +597,9 @@ fn write_codex_root_toml(root: &toml::Value) -> Result<(), AppCommandError> {
|
||||
}
|
||||
|
||||
fn obj_as_string_map(value: Option<&Value>) -> Option<Map<String, Value>> {
|
||||
let Some(obj) = value.and_then(Value::as_object) else {
|
||||
return None;
|
||||
};
|
||||
let obj = value.and_then(Value::as_object)?;
|
||||
|
||||
let mut output = Map::new();
|
||||
let mut output = Map::with_capacity(obj.len());
|
||||
for (key, item) in obj {
|
||||
let Some(s) = item.as_str() else {
|
||||
continue;
|
||||
@@ -616,12 +623,10 @@ fn contains_unresolved_placeholder(value: &str) -> bool {
|
||||
}
|
||||
|
||||
fn marketplace_http_client() -> Result<reqwest::Client, AppCommandError> {
|
||||
reqwest::Client::builder()
|
||||
.connect_timeout(Duration::from_secs(8))
|
||||
.timeout(Duration::from_secs(20))
|
||||
.user_agent("codeg-mcp-market/1.0")
|
||||
.build()
|
||||
.map_err(|e| mcp_network(format!("failed to initialize marketplace HTTP client: {e}")))
|
||||
match &*MARKETPLACE_HTTP_CLIENT {
|
||||
Ok(client) => Ok(client.clone()),
|
||||
Err(err) => Err(mcp_network(err.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
fn should_retry_http_status(status: reqwest::StatusCode) -> bool {
|
||||
@@ -1000,11 +1005,9 @@ fn json_to_toml_value(value: &Value) -> Option<toml::Value> {
|
||||
}
|
||||
Value::String(v) => Some(toml::Value::String(v.clone())),
|
||||
Value::Array(values) => {
|
||||
let mut converted = Vec::new();
|
||||
let mut converted = Vec::with_capacity(values.len());
|
||||
for item in values {
|
||||
let Some(next) = json_to_toml_value(item) else {
|
||||
return None;
|
||||
};
|
||||
let next = json_to_toml_value(item)?;
|
||||
converted.push(next);
|
||||
}
|
||||
Some(toml::Value::Array(converted))
|
||||
|
||||
@@ -29,9 +29,9 @@ where
|
||||
{
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
return builder
|
||||
builder
|
||||
.hidden_title(true)
|
||||
.title_bar_style(tauri::TitleBarStyle::Overlay);
|
||||
.title_bar_style(tauri::TitleBarStyle::Overlay)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
@@ -216,9 +216,9 @@ pub async fn open_folder_window(
|
||||
if let Some(existing) = app.get_webview_window(&label) {
|
||||
ensure_windows_undecorated(&existing);
|
||||
let _ = existing.unminimize();
|
||||
existing.set_focus().map_err(|e| {
|
||||
AppCommandError::window("Failed to focus folder window", e.to_string())
|
||||
})?;
|
||||
existing
|
||||
.set_focus()
|
||||
.map_err(|e| AppCommandError::window("Failed to focus folder window", e.to_string()))?;
|
||||
if let Some(w) = app.get_webview_window("welcome") {
|
||||
let _ = w.close();
|
||||
}
|
||||
@@ -279,7 +279,7 @@ pub async fn open_commit_window(
|
||||
|
||||
let url = WebviewUrl::App(format!("commit?folderId={folder_id}").into());
|
||||
let builder = WebviewWindowBuilder::new(&app, &label, url)
|
||||
.title(&format!("提交代码 - {}", folder.name))
|
||||
.title(format!("提交代码 - {}", folder.name))
|
||||
.inner_size(1220.0, 820.0)
|
||||
.min_inner_size(980.0, 620.0)
|
||||
.always_on_top(true)
|
||||
|
||||
Reference in New Issue
Block a user