feat: Integrate ClawdHub skill registry
This commit is contained in:
Generated
+236
-2
@@ -8,6 +8,17 @@ version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||
|
||||
[[package]]
|
||||
name = "aes"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cipher",
|
||||
"cpufeatures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.7.8"
|
||||
@@ -537,6 +548,25 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bzip2"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47"
|
||||
dependencies = [
|
||||
"bzip2-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bzip2-sys"
|
||||
version = "0.1.13+1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cairo-rs"
|
||||
version = "0.18.5"
|
||||
@@ -611,6 +641,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b97463e1064cb1b1c1384ad0a0b9c8abd0988e2a91f52606c80ef14aadb63e36"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"jobserver",
|
||||
"libc",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
@@ -673,6 +705,16 @@ dependencies = [
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cipher"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
|
||||
dependencies = [
|
||||
"crypto-common",
|
||||
"inout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "combine"
|
||||
version = "4.6.7"
|
||||
@@ -710,6 +752,12 @@ dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6"
|
||||
|
||||
[[package]]
|
||||
name = "convert_case"
|
||||
version = "0.4.0"
|
||||
@@ -775,6 +823,21 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc"
|
||||
version = "3.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d"
|
||||
dependencies = [
|
||||
"crc-catalog",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc-catalog"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.5.0"
|
||||
@@ -881,6 +944,12 @@ dependencies = [
|
||||
"syn 2.0.110",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deflate64"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26bf8fc351c5ed29b5c2f0cbbac1b209b74f60ecd62e675a998df72c49af5204"
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.5.5"
|
||||
@@ -923,6 +992,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1743,6 +1813,15 @@ version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "hmac"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
|
||||
dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "html5ever"
|
||||
version = "0.29.1"
|
||||
@@ -2038,6 +2117,15 @@ dependencies = [
|
||||
"cfb",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inout"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.11.0"
|
||||
@@ -2124,6 +2212,16 @@ version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33"
|
||||
dependencies = [
|
||||
"getrandom 0.3.4",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.82"
|
||||
@@ -2293,6 +2391,27 @@ version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
|
||||
|
||||
[[package]]
|
||||
name = "lzma-rs"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "297e814c836ae64db86b36cf2a557ba54368d03f6afcd7d947c266692f71115e"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"crc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lzma-sys"
|
||||
version = "0.1.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mac"
|
||||
version = "0.1.1"
|
||||
@@ -2858,7 +2977,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "openchamber-desktop"
|
||||
version = "1.4.5"
|
||||
version = "1.4.6"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"axum",
|
||||
@@ -2897,6 +3016,7 @@ dependencies = [
|
||||
"urlencoding",
|
||||
"uuid",
|
||||
"window-vibrancy 0.7.1",
|
||||
"zip 2.4.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2999,6 +3119,16 @@ version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
|
||||
|
||||
[[package]]
|
||||
name = "pbkdf2"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2"
|
||||
dependencies = [
|
||||
"digest",
|
||||
"hmac",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.2"
|
||||
@@ -4210,6 +4340,17 @@ dependencies = [
|
||||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha1"
|
||||
version = "0.10.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
@@ -4839,7 +4980,7 @@ dependencies = [
|
||||
"tokio",
|
||||
"url",
|
||||
"windows-sys 0.60.2",
|
||||
"zip",
|
||||
"zip 4.6.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6467,6 +6608,15 @@ dependencies = [
|
||||
"rustix",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xz2"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2"
|
||||
dependencies = [
|
||||
"lzma-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yoke"
|
||||
version = "0.8.1"
|
||||
@@ -6598,6 +6748,20 @@ name = "zeroize"
|
||||
version = "1.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
|
||||
dependencies = [
|
||||
"zeroize_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zeroize_derive"
|
||||
version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.110",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerotrie"
|
||||
@@ -6632,6 +6796,36 @@ dependencies = [
|
||||
"syn 2.0.110",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "2.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fabe6324e908f85a1c52063ce7aa26b68dcb7eb6dbc83a2d148403c9bc3eba50"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"arbitrary",
|
||||
"bzip2",
|
||||
"constant_time_eq",
|
||||
"crc32fast",
|
||||
"crossbeam-utils",
|
||||
"deflate64",
|
||||
"displaydoc",
|
||||
"flate2",
|
||||
"getrandom 0.3.4",
|
||||
"hmac",
|
||||
"indexmap 2.12.0",
|
||||
"lzma-rs",
|
||||
"memchr",
|
||||
"pbkdf2",
|
||||
"sha1",
|
||||
"thiserror 2.0.17",
|
||||
"time",
|
||||
"xz2",
|
||||
"zeroize",
|
||||
"zopfli",
|
||||
"zstd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "4.6.1"
|
||||
@@ -6644,6 +6838,46 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zopfli"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"crc32fast",
|
||||
"log",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd"
|
||||
version = "0.13.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a"
|
||||
dependencies = [
|
||||
"zstd-safe",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd-safe"
|
||||
version = "7.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d"
|
||||
dependencies = [
|
||||
"zstd-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd-sys"
|
||||
version = "2.0.16+zstd.1.5.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zvariant"
|
||||
version = "5.8.0"
|
||||
|
||||
@@ -52,6 +52,7 @@ tauri-plugin-updater = "2"
|
||||
tauri-plugin-process = "2"
|
||||
base64 = "0.22.1"
|
||||
urlencoding = "2.1"
|
||||
zip = "2.1"
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2.5.3", features = [] }
|
||||
|
||||
@@ -44,6 +44,21 @@ pub struct SkillsCatalogInstalledBadge {
|
||||
pub scope: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ClawdHubSkillMetadata {
|
||||
pub slug: String,
|
||||
pub version: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub display_name: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub owner: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub downloads: Option<u64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub stars: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SkillsCatalogItem {
|
||||
@@ -63,6 +78,8 @@ pub struct SkillsCatalogItem {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub warnings: Option<Vec<String>>,
|
||||
pub installed: SkillsCatalogInstalledBadge,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub clawdhub: Option<ClawdHubSkillMetadata>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
@@ -701,6 +718,180 @@ fn cache_key(normalized_repo: &str, subpath: Option<&str>, identity_id: Option<&
|
||||
)
|
||||
}
|
||||
|
||||
// ============== ClawdHub API ==============
|
||||
|
||||
const CLAWDHUB_API_BASE: &str = "https://clawdhub.com/api/v1";
|
||||
|
||||
fn is_clawdhub_source(source: &str) -> bool {
|
||||
source.starts_with("clawdhub:")
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ClawdHubSkillOwner {
|
||||
handle: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ClawdHubSkillStats {
|
||||
downloads: Option<u64>,
|
||||
stars: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ClawdHubSkillTags {
|
||||
latest: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ClawdHubSkillVersion {
|
||||
version: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ClawdHubSkillListItem {
|
||||
slug: String,
|
||||
display_name: Option<String>,
|
||||
summary: Option<String>,
|
||||
tags: Option<ClawdHubSkillTags>,
|
||||
latest_version: Option<ClawdHubSkillVersion>,
|
||||
stats: Option<ClawdHubSkillStats>,
|
||||
owner: Option<ClawdHubSkillOwner>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ClawdHubSkillsResponse {
|
||||
items: Vec<ClawdHubSkillListItem>,
|
||||
next_cursor: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ClawdHubSkillInfoResponse {
|
||||
skill: Option<ClawdHubSkillInfoSkill>,
|
||||
latest_version: Option<ClawdHubSkillVersion>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ClawdHubSkillInfoSkill {
|
||||
tags: Option<ClawdHubSkillTags>,
|
||||
}
|
||||
|
||||
async fn scan_clawdhub() -> Result<Vec<SkillsCatalogItem>> {
|
||||
let client = reqwest::Client::builder()
|
||||
.user_agent("OpenChamber-Desktop/1.0")
|
||||
.timeout(Duration::from_secs(30))
|
||||
.build()?;
|
||||
|
||||
let mut all_items = Vec::new();
|
||||
let mut cursor: Option<String> = None;
|
||||
let max_pages = 20;
|
||||
|
||||
for _ in 0..max_pages {
|
||||
let url = match &cursor {
|
||||
Some(c) => format!("{}{}?cursor={}", CLAWDHUB_API_BASE, "/skills", urlencoding::encode(c)),
|
||||
None => format!("{}/skills", CLAWDHUB_API_BASE),
|
||||
};
|
||||
|
||||
let response = client.get(&url).send().await?;
|
||||
if !response.status().is_success() {
|
||||
return Err(anyhow!("ClawdHub API error: {}", response.status()));
|
||||
}
|
||||
|
||||
let data: ClawdHubSkillsResponse = response.json().await?;
|
||||
|
||||
for item in data.items {
|
||||
let latest_version = item
|
||||
.tags
|
||||
.as_ref()
|
||||
.and_then(|t| t.latest.clone())
|
||||
.or_else(|| item.latest_version.as_ref().and_then(|v| v.version.clone()))
|
||||
.unwrap_or_else(|| "1.0.0".to_string());
|
||||
|
||||
all_items.push(SkillsCatalogItem {
|
||||
source_id: "clawdhub".to_string(),
|
||||
repo_source: "clawdhub:registry".to_string(),
|
||||
repo_subpath: None,
|
||||
git_identity_id: None,
|
||||
skill_dir: item.slug.clone(),
|
||||
skill_name: item.slug.clone(),
|
||||
frontmatter_name: item.display_name.clone(),
|
||||
description: item.summary,
|
||||
installable: true,
|
||||
warnings: None,
|
||||
installed: SkillsCatalogInstalledBadge {
|
||||
is_installed: false,
|
||||
scope: None,
|
||||
},
|
||||
clawdhub: Some(ClawdHubSkillMetadata {
|
||||
slug: item.slug,
|
||||
version: latest_version,
|
||||
display_name: item.display_name,
|
||||
owner: item.owner.and_then(|o| o.handle),
|
||||
downloads: item.stats.as_ref().and_then(|s| s.downloads),
|
||||
stars: item.stats.as_ref().and_then(|s| s.stars),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
match data.next_cursor {
|
||||
Some(c) => cursor = Some(c),
|
||||
None => break,
|
||||
}
|
||||
|
||||
// Rate limiting
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
|
||||
// Sort by downloads (most popular first)
|
||||
all_items.sort_by(|a, b| {
|
||||
let a_downloads = a.clawdhub.as_ref().and_then(|c| c.downloads).unwrap_or(0);
|
||||
let b_downloads = b.clawdhub.as_ref().and_then(|c| c.downloads).unwrap_or(0);
|
||||
b_downloads.cmp(&a_downloads)
|
||||
});
|
||||
|
||||
Ok(all_items)
|
||||
}
|
||||
|
||||
async fn download_clawdhub_skill(slug: &str, version: &str) -> Result<Vec<u8>> {
|
||||
let client = reqwest::Client::builder()
|
||||
.user_agent("OpenChamber-Desktop/1.0")
|
||||
.timeout(Duration::from_secs(60))
|
||||
.build()?;
|
||||
|
||||
let url = format!(
|
||||
"{}/download?slug={}&version={}",
|
||||
CLAWDHUB_API_BASE,
|
||||
urlencoding::encode(slug),
|
||||
urlencoding::encode(version)
|
||||
);
|
||||
|
||||
let response = client.get(&url).send().await?;
|
||||
if !response.status().is_success() {
|
||||
return Err(anyhow!("ClawdHub download error: {}", response.status()));
|
||||
}
|
||||
|
||||
Ok(response.bytes().await?.to_vec())
|
||||
}
|
||||
|
||||
async fn fetch_clawdhub_skill_info(slug: &str) -> Result<ClawdHubSkillInfoResponse> {
|
||||
let client = reqwest::Client::builder()
|
||||
.user_agent("OpenChamber-Desktop/1.0")
|
||||
.timeout(Duration::from_secs(15))
|
||||
.build()?;
|
||||
|
||||
let url = format!("{}/skills/{}", CLAWDHUB_API_BASE, urlencoding::encode(slug));
|
||||
let response = client.get(&url).send().await?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(anyhow!("ClawdHub skill info error: {}", response.status()));
|
||||
}
|
||||
|
||||
Ok(response.json().await?)
|
||||
}
|
||||
|
||||
fn load_custom_catalog_sources() -> Vec<SkillsCatalogSource> {
|
||||
let settings_path = dirs::home_dir().map(|mut home| {
|
||||
home.push(".config");
|
||||
@@ -786,14 +977,24 @@ fn load_custom_catalog_sources() -> Vec<SkillsCatalogSource> {
|
||||
}
|
||||
|
||||
pub async fn get_curated_sources() -> Vec<SkillsCatalogSource> {
|
||||
let mut sources = vec![SkillsCatalogSource {
|
||||
id: "anthropic".to_string(),
|
||||
label: "Anthropic".to_string(),
|
||||
description: Some("Anthropic’s public skills repository".to_string()),
|
||||
source: "anthropics/skills".to_string(),
|
||||
default_subpath: Some("skills".to_string()),
|
||||
git_identity_id: None,
|
||||
}];
|
||||
let mut sources = vec![
|
||||
SkillsCatalogSource {
|
||||
id: "anthropic".to_string(),
|
||||
label: "Anthropic".to_string(),
|
||||
description: Some("Anthropic's public skills repository".to_string()),
|
||||
source: "anthropics/skills".to_string(),
|
||||
default_subpath: Some("skills".to_string()),
|
||||
git_identity_id: None,
|
||||
},
|
||||
SkillsCatalogSource {
|
||||
id: "clawdhub".to_string(),
|
||||
label: "ClawdHub".to_string(),
|
||||
description: Some("Community skill registry with vector search".to_string()),
|
||||
source: "clawdhub:registry".to_string(),
|
||||
default_subpath: None,
|
||||
git_identity_id: None,
|
||||
},
|
||||
];
|
||||
|
||||
sources.extend(load_custom_catalog_sources());
|
||||
sources
|
||||
@@ -811,6 +1012,69 @@ pub async fn get_catalog(working_directory: &Path, refresh: bool) -> SkillsCatal
|
||||
let mut items_by_source: HashMap<String, Vec<SkillsCatalogItem>> = HashMap::new();
|
||||
|
||||
for src in &sources {
|
||||
// Handle ClawdHub sources separately (API-based, not git-based)
|
||||
if is_clawdhub_source(&src.source) {
|
||||
let key = "clawdhub:registry".to_string();
|
||||
|
||||
let maybe_cached = if refresh {
|
||||
None
|
||||
} else {
|
||||
let cache = CATALOG_CACHE.lock().await;
|
||||
cache.get(&key).cloned()
|
||||
};
|
||||
|
||||
let cached_items = maybe_cached.and_then(|entry| {
|
||||
if entry.created_at.elapsed() < CACHE_TTL {
|
||||
Some(entry.items)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
|
||||
let scanned_items = if let Some(items) = cached_items {
|
||||
items
|
||||
} else {
|
||||
let items = match scan_clawdhub().await {
|
||||
Ok(items) => items,
|
||||
Err(_) => {
|
||||
items_by_source.insert(src.id.clone(), vec![]);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let mut cache = CATALOG_CACHE.lock().await;
|
||||
cache.insert(
|
||||
key,
|
||||
CacheEntry {
|
||||
created_at: Instant::now(),
|
||||
items: items.clone(),
|
||||
},
|
||||
);
|
||||
|
||||
items
|
||||
};
|
||||
|
||||
// Update installed badges
|
||||
let enriched: Vec<SkillsCatalogItem> = scanned_items
|
||||
.into_iter()
|
||||
.map(|mut item| {
|
||||
let installed = installed_by_name.get(&item.skill_name);
|
||||
item.installed = SkillsCatalogInstalledBadge {
|
||||
is_installed: installed.is_some(),
|
||||
scope: installed.map(|s| match s.scope {
|
||||
opencode_config::Scope::User => "user".to_string(),
|
||||
opencode_config::Scope::Project => "project".to_string(),
|
||||
}),
|
||||
};
|
||||
item
|
||||
})
|
||||
.collect();
|
||||
|
||||
items_by_source.insert(src.id.clone(), enriched);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle GitHub sources (git clone based)
|
||||
let parsed = match parse_repo_source(&src.source, None) {
|
||||
Ok(p) => p,
|
||||
Err(_) => {
|
||||
@@ -899,6 +1163,7 @@ pub async fn get_catalog(working_directory: &Path, refresh: bool) -> SkillsCatal
|
||||
opencode_config::Scope::Project => "project".to_string(),
|
||||
}),
|
||||
},
|
||||
clawdhub: None,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -989,6 +1254,7 @@ pub async fn scan_repository(req: SkillsScanRequest) -> SkillsRepoScanResponse {
|
||||
is_installed: false,
|
||||
scope: None,
|
||||
},
|
||||
clawdhub: None,
|
||||
});
|
||||
}
|
||||
items.sort_by(|a, b| a.skill_name.cmp(&b.skill_name));
|
||||
@@ -1019,10 +1285,18 @@ pub async fn scan_repository(req: SkillsScanRequest) -> SkillsRepoScanResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ClawdHubInstallMeta {
|
||||
pub slug: String,
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SkillsInstallSelection {
|
||||
pub skill_dir: String,
|
||||
pub clawdhub: Option<ClawdHubInstallMeta>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@@ -1123,10 +1397,269 @@ async fn copy_dir_no_symlinks(src: &Path, dst: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn install_skills_from_clawdhub(
|
||||
working_directory: &Path,
|
||||
req: &SkillsInstallRequest,
|
||||
) -> SkillsInstallResponse {
|
||||
let mut installed = vec![];
|
||||
let mut skipped = vec![];
|
||||
|
||||
let _user_dir = match user_skill_dir() {
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
return SkillsInstallResponse {
|
||||
ok: false,
|
||||
installed: None,
|
||||
skipped: None,
|
||||
error: Some(simple_error("unknown", &e.to_string())),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// Check for conflicts first
|
||||
let mut conflicts = vec![];
|
||||
for sel in &req.selections {
|
||||
let slug = sel.clawdhub.as_ref().map(|c| c.slug.as_str()).unwrap_or(&sel.skill_dir);
|
||||
if !validate_skill_name(slug) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let target = match target_skill_dir(&req.scope, working_directory, slug) {
|
||||
Ok(p) => p,
|
||||
Err(_) => continue,
|
||||
};
|
||||
|
||||
if target.exists() {
|
||||
let decision = req
|
||||
.conflict_decisions
|
||||
.as_ref()
|
||||
.and_then(|m| m.get(slug))
|
||||
.map(|s| s.as_str());
|
||||
|
||||
let auto = req.conflict_policy.as_deref().unwrap_or("prompt");
|
||||
|
||||
if decision.is_none() && auto != "skipAll" && auto != "overwriteAll" {
|
||||
conflicts.push(SkillConflict {
|
||||
skill_name: slug.to_string(),
|
||||
scope: req.scope.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !conflicts.is_empty() {
|
||||
return SkillsInstallResponse {
|
||||
ok: false,
|
||||
installed: None,
|
||||
skipped: None,
|
||||
error: Some(conflicts_error(conflicts)),
|
||||
};
|
||||
}
|
||||
|
||||
for sel in &req.selections {
|
||||
let slug = sel.clawdhub.as_ref().map(|c| c.slug.as_str()).unwrap_or(&sel.skill_dir);
|
||||
let mut version = sel.clawdhub.as_ref().map(|c| c.version.as_str()).unwrap_or("latest").to_string();
|
||||
|
||||
if !validate_skill_name(slug) {
|
||||
skipped.push(SkippedSkill {
|
||||
skill_name: slug.to_string(),
|
||||
reason: "Invalid skill name".to_string(),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
// Resolve 'latest' version
|
||||
if version == "latest" {
|
||||
if let Ok(info) = fetch_clawdhub_skill_info(slug).await {
|
||||
version = info
|
||||
.skill
|
||||
.and_then(|s| s.tags)
|
||||
.and_then(|t| t.latest)
|
||||
.or_else(|| info.latest_version.and_then(|v| v.version))
|
||||
.unwrap_or_else(|| "latest".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
let target_dir = match target_skill_dir(&req.scope, working_directory, slug) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
skipped.push(SkippedSkill {
|
||||
skill_name: slug.to_string(),
|
||||
reason: e.to_string(),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let exists = target_dir.exists();
|
||||
let mut decision = req
|
||||
.conflict_decisions
|
||||
.as_ref()
|
||||
.and_then(|m| m.get(slug))
|
||||
.cloned();
|
||||
|
||||
let auto = req.conflict_policy.as_deref().unwrap_or("prompt");
|
||||
|
||||
if decision.is_none() {
|
||||
if exists && auto == "skipAll" {
|
||||
decision = Some("skip".to_string());
|
||||
}
|
||||
if exists && auto == "overwriteAll" {
|
||||
decision = Some("overwrite".to_string());
|
||||
}
|
||||
if !exists {
|
||||
decision = Some("overwrite".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
if exists && decision.as_deref() == Some("skip") {
|
||||
skipped.push(SkippedSkill {
|
||||
skill_name: slug.to_string(),
|
||||
reason: "Already installed (skipped)".to_string(),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
if exists && decision.as_deref() == Some("overwrite") {
|
||||
let _ = tokio::fs::remove_dir_all(&target_dir).await;
|
||||
}
|
||||
|
||||
// Download and extract
|
||||
match download_clawdhub_skill(slug, &version).await {
|
||||
Ok(zip_data) => {
|
||||
let temp_dir = std::env::temp_dir().join(format!("clawdhub-{}-{}", slug, Uuid::new_v4()));
|
||||
let _ = tokio::fs::remove_dir_all(&temp_dir).await;
|
||||
|
||||
// Extract ZIP using the zip crate
|
||||
let cursor = std::io::Cursor::new(&zip_data);
|
||||
let mut archive = match zip::ZipArchive::new(cursor) {
|
||||
Ok(a) => a,
|
||||
Err(e) => {
|
||||
skipped.push(SkippedSkill {
|
||||
skill_name: slug.to_string(),
|
||||
reason: format!("Failed to open ZIP: {}", e),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(e) = std::fs::create_dir_all(&temp_dir) {
|
||||
skipped.push(SkippedSkill {
|
||||
skill_name: slug.to_string(),
|
||||
reason: format!("Failed to create temp dir: {}", e),
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut extract_ok = true;
|
||||
for i in 0..archive.len() {
|
||||
let mut file = match archive.by_index(i) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
skipped.push(SkippedSkill {
|
||||
skill_name: slug.to_string(),
|
||||
reason: format!("Failed to read ZIP entry: {}", e),
|
||||
});
|
||||
extract_ok = false;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
let outpath = temp_dir.join(file.name());
|
||||
|
||||
if file.name().ends_with('/') {
|
||||
let _ = std::fs::create_dir_all(&outpath);
|
||||
} else {
|
||||
if let Some(p) = outpath.parent() {
|
||||
let _ = std::fs::create_dir_all(p);
|
||||
}
|
||||
let mut outfile = match std::fs::File::create(&outpath) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
skipped.push(SkippedSkill {
|
||||
skill_name: slug.to_string(),
|
||||
reason: format!("Failed to create file: {}", e),
|
||||
});
|
||||
extract_ok = false;
|
||||
break;
|
||||
}
|
||||
};
|
||||
if let Err(e) = std::io::copy(&mut file, &mut outfile) {
|
||||
skipped.push(SkippedSkill {
|
||||
skill_name: slug.to_string(),
|
||||
reason: format!("Failed to write file: {}", e),
|
||||
});
|
||||
extract_ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !extract_ok {
|
||||
let _ = std::fs::remove_dir_all(&temp_dir);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Verify SKILL.md exists
|
||||
let skill_md_path = temp_dir.join("SKILL.md");
|
||||
if !skill_md_path.exists() {
|
||||
skipped.push(SkippedSkill {
|
||||
skill_name: slug.to_string(),
|
||||
reason: "SKILL.md not found in downloaded package".to_string(),
|
||||
});
|
||||
let _ = std::fs::remove_dir_all(&temp_dir);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Move to target directory
|
||||
if let Some(parent) = target_dir.parent() {
|
||||
let _ = tokio::fs::create_dir_all(parent).await;
|
||||
}
|
||||
|
||||
if let Err(e) = tokio::fs::rename(&temp_dir, &target_dir).await {
|
||||
// If rename fails (cross-device), try copy
|
||||
if let Err(e2) = copy_dir_no_symlinks(&temp_dir, &target_dir).await {
|
||||
skipped.push(SkippedSkill {
|
||||
skill_name: slug.to_string(),
|
||||
reason: format!("Failed to move files: {} / {}", e, e2),
|
||||
});
|
||||
let _ = tokio::fs::remove_dir_all(&temp_dir).await;
|
||||
continue;
|
||||
}
|
||||
let _ = tokio::fs::remove_dir_all(&temp_dir).await;
|
||||
}
|
||||
|
||||
installed.push(InstalledSkill {
|
||||
skill_name: slug.to_string(),
|
||||
scope: req.scope.clone(),
|
||||
});
|
||||
}
|
||||
Err(e) => {
|
||||
skipped.push(SkippedSkill {
|
||||
skill_name: slug.to_string(),
|
||||
reason: format!("Failed to download: {}", e),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SkillsInstallResponse {
|
||||
ok: true,
|
||||
installed: Some(installed),
|
||||
skipped: Some(skipped),
|
||||
error: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn install_skills(
|
||||
working_directory: &Path,
|
||||
req: SkillsInstallRequest,
|
||||
) -> SkillsInstallResponse {
|
||||
// Handle ClawdHub sources separately
|
||||
if is_clawdhub_source(&req.source) {
|
||||
return install_skills_from_clawdhub(working_directory, &req).await;
|
||||
}
|
||||
|
||||
let ssh_key = resolve_identity_ssh_key(req.git_identity_id.as_deref());
|
||||
|
||||
let selections: Vec<String> = req
|
||||
|
||||
Reference in New Issue
Block a user