JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
[mirror] openJiuwen-ai/jiuwenswarm#1034: fix(clawhub): pass ownerHandle to resolve ambiguous slug 409 Conflict
d300296963e528ebb53f0
diff --git a/jiuwenswarm/agents/harness/common/tools/skill_toolkits.py b/jiuwenswarm/agents/harness/common/tools/skill_toolkits.pyindex b58a6e0128..c2b079600a 100644--- a/jiuwenswarm/agents/harness/common/tools/skill_toolkits.py+++ b/jiuwenswarm/agents/harness/common/tools/skill_toolkits.py@@ -103,6 +103,26 @@ class SkillToolkit:return None+ def _check_already_installed(self, identifier: str, source: str) -> dict[str, Any] | None:+ existing_item = self._find_installed_by_target(identifier, source)+ if existing_item is None:+ return None+ detail = (+ f"Skill `{existing_item['name']}` is already installed. "+ "Skipping duplicate installation."+ )+ return {+ "success": True,+ "source": source,+ "installed": True,+ "already_installed": True,+ "name": existing_item["name"],+ "description": existing_item["description"],+ "identifier": existing_item["identifier"],+ "skill_file": existing_item["skill_file"],+ "detail": detail,+ }+def _is_builtin_skill(self, skill_name: str) -> bool:"""复用原有卸载语义:只有真正运行在 builtin 目录中的技能才视为内置。"""return self._manager.is_builtin_skill(skill_name)@@ -362,32 +382,30 @@ class SkillToolkit:resolved_source = normalized_sourcewait_timeout = self._safe_int(timeout_sec, 60)- existing_item = self._find_installed_by_target(target, resolved_source)- if existing_item is not None:- detail = (- f"Skill `{existing_item['name']}` is already installed. "- "Skipping duplicate installation."- )- return {- "success": True,- "source": resolved_source,- "installed": True,- "already_installed": True,- "name": existing_item["name"],- "description": existing_item["description"],- "identifier": existing_item["identifier"],- "skill_file": existing_item["skill_file"],- "detail": detail,- }if resolved_source == "skillnet":+ r = self._check_already_installed(target, resolved_source)+ if r is not None:+ return rpayload = await self._install_skillnet_sync_wait(target, wait_timeout)elif resolved_source == "teamskillshub":+ r = self._check_already_installed(target, resolved_source)+ if r is not None:+ return rpayload = await self._manager.handle_skills_team_skills_hub_install({"asset_id": target, "force": False})else:- payload = await self._manager.handle_skills_clawhub_download({"slug": target, "force": False})+ clawhub_slug = target+ clawhub_owner = ""+ if "/" in target:+ clawhub_owner, _, clawhub_slug = target.partition("/")+ r = self._check_already_installed(clawhub_slug, resolved_source)+ if r is not None:+ return r+ payload = await self._manager.handle_skills_clawhub_download(+ {"slug": clawhub_slug, "owner_handle": clawhub_owner, "force": False}+ )except Exception as exc: # noqa: BLE001logger.exception("install_skill failed")return {diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/skills.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/skills.tsindex d386601beb..bc358ff26a 100644--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/skills.ts+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/skills.ts@@ -256,14 +256,21 @@ export function createSkillsCommand(): SlashCommand {return;}- // ClawHub install flow: "slug@clawhub" or bare slug that looks like a ClawHub identifier+ // ClawHub install flow: "ownerHandle/slug@clawhub" or "slug@clawhub"// ClawHub identifiers are alphanumeric slugs like "code-review", "daily-report" etc.if (spec.includes("@clawhub") || (spec.includes("@") && spec.endsWith("@clawhub"))) {- const slug = spec.replace(/@clawhub$/i, "");+ const clawhubPart = spec.replace(/@clawhub$/i, "");+ let slug = clawhubPart;+ let ownerHandle: string | undefined;+ if (clawhubPart.includes("/")) {+ const slashIdx = clawhubPart.indexOf("/");+ ownerHandle = clawhubPart.substring(0, slashIdx);+ slug = clawhubPart.substring(slashIdx + 1);+ }ctx.addItem(makeItem(ctx.sessionId, "info", `Installing from ClawHub: ${slug}`));const downloadPayload = await ctx.request<{ success?: boolean; detail?: string; detail_key?: string; skill?: { name?: string; source?: string } }>("skills.clawhub.download",- { slug, force: false },+ { slug, owner_handle: ownerHandle || "", force: false },120_000,);if (downloadPayload.success) {@@ -296,7 +303,7 @@ export function createSkillsCommand(): SlashCommand {ctx.addItem(makeItem(ctx.sessionId, "info", `Force re-installing from ClawHub: ${slug}`));const forcePayload = await ctx.request<{ success?: boolean; detail?: string; detail_key?: string; skill?: { name?: string; source?: string } }>("skills.clawhub.download",- { slug, force: true },+ { slug, owner_handle: ownerHandle || "", force: true },120_000,);if (forcePayload.success) {@@ -324,7 +331,7 @@ export function createSkillsCommand(): SlashCommand {value: s.slug,description: `${s.summary || "(no description)"} | slug: ${s.slug} | v${s.version || "?"}`,}));- ctx.addItem(makeItem(ctx.sessionId, "info", `Found ${searchPayload.skills.length} matching skills on ClawHub. Use the slug shown below:`, "*", { view: "list", title: "ClawHub Search Results (use slug@clawhub to install)", items }));+ ctx.addItem(makeItem(ctx.sessionId, "info", `Found ${searchPayload.skills.length} matching skills on ClawHub. Use the slug shown below:`, "*", { view: "list", title: "ClawHub Search Results", items }));} else {// Search also requires token — if token error, give guidanceif (searchPayload.detail_key === "skills.clawhub.errors.tokenNotConfigured") {diff --git a/jiuwenswarm/channels/web/frontend/src/features/ClawHubSearchModal/index.tsx b/jiuwenswarm/channels/web/frontend/src/features/ClawHubSearchModal/index.tsxindex 00942d6489..e3d5dc4039 100644--- a/jiuwenswarm/channels/web/frontend/src/features/ClawHubSearchModal/index.tsx+++ b/jiuwenswarm/channels/web/frontend/src/features/ClawHubSearchModal/index.tsx@@ -40,6 +40,7 @@ type ClawHubSkillItem = {summary: string;version: string;updated_at: number;+ owner_handle: string;};interface ClawHubSearchModalProps {@@ -256,7 +257,7 @@ export function ClawHubSearchModal({skill?: { name: string };}>("skills.clawhub.download",- withSession({ slug, force: forceOverwrite })+ withSession({ slug, owner_handle: item.owner_handle, force: forceOverwrite }));if (!data.success) {const message = data.detail_key@@ -347,7 +348,7 @@ export function ClawHubSearchModal({const avatar = getSkillAvatar(item.slug);return (<div- key={item.slug}+ key={item.owner_handle ? `${item.owner_handle}/${item.slug}` : item.slug}className={`p-4 rounded-lg border border-border bg-panel ${viewMode === "grid" ? "flex flex-col" : "flex items-start justify-between gap-4"}`}style={viewMode === "grid" ? { width: "496px", height: "168px", flexShrink: 0 } : undefined}>@@ -641,7 +642,7 @@ export function ClawHubSearchModal({const avatar = getSkillAvatar(item.slug);return (<div- key={item.slug}+ key={item.owner_handle ? `${item.owner_handle}/${item.slug}` : item.slug}className="p-4 rounded-lg border border-border bg-panel flex items-start justify-between gap-4"><div className="flex items-center gap-3 min-w-0 flex-1">diff --git a/jiuwenswarm/server/runtime/skill/skill_manager.py b/jiuwenswarm/server/runtime/skill/skill_manager.pyindex f859b88274..b73fc22fb4 100644--- a/jiuwenswarm/server/runtime/skill/skill_manager.py+++ b/jiuwenswarm/server/runtime/skill/skill_manager.py@@ -1343,6 +1343,7 @@ class SkillManager:"summary": item.get("summary", ""),"version": item.get("version", ""),"updated_at": item.get("updatedAt", 0),+ "owner_handle": item.get("ownerHandle", ""),})@@ -1373,6 +1374,7 @@ class SkillManager:params:slug: skill slug (必需)+ owner_handle: 发布者标识 (可选,slug 有多个发布者时必需)version: 版本号 (可选,默认 latest)tag: 标签 (可选,如 latest)force: 强制覆盖 (可选,默认 False)@@ -1394,6 +1396,7 @@ class SkillManager:"detail_key": "skills.clawhub.errors.tokenNotConfigured",}+ owner_handle = str(params.get("owner_handle") or "").strip()version = params.get("version")tag = params.get("tag")force = bool(params.get("force", False))@@ -1416,6 +1419,8 @@ class SkillManager:headers["Authorization"] = f"Bearer {token}"download_params = {"slug": slug}+ if owner_handle:+ download_params["ownerHandle"] = owner_handleif version:download_params["version"] = versionif tag:diff --git a/tests/unit_tests/agentserver/test_skill_manager_clawhub_owner_handle.py b/tests/unit_tests/agentserver/test_skill_manager_clawhub_owner_handle.pynew file mode 100644index 0000000000..d07baa5419--- /dev/null+++ b/tests/unit_tests/agentserver/test_skill_manager_clawhub_owner_handle.py@@ -0,0 +1,250 @@+import json++import pytest++from jiuwenswarm.server.runtime.skill.skill_manager import SkillManager+++class _FakeSearchResponse:+ def __init__(self, data: dict):+ self._data = data++ def json(self):+ return self._data++ @staticmethod+ def raise_for_status():+ return None+++class _FakeSearchClient:+ def __init__(self, results: list[dict]):+ self._results = results++ async def __aenter__(self):+ return self++ async def __aexit__(self, exc_type, exc, tb):+ return False++ async def get(self, url, *, params, headers):+ assert url == "https://clawhub.ai/api/v1/search"+ assert "q" in params+ return _FakeSearchResponse({"results": self._results})+++class _FakeDownloadResponse:+ def __init__(self, status_code: int, text: str = "", content: bytes = b""):+ self.status_code = status_code+ self.text = text+ self.content = content++ def raise_for_status(self):+ if self.status_code >= 400:+ import httpx+ raise httpx.HTTPStatusError(+ message=f"Client error '{self.status_code}'",+ request=httpx.Request("GET", "https://clawhub.ai/api/v1/download"),+ response=self,+ )+++class _FakeDownloadClient:+ def __init__(self, status_code: int = 200, text: str = "", content: bytes = b""):+ self._status_code = status_code+ self._text = text+ self._content = content+ self._captured_params: dict | None = None++ async def __aenter__(self):+ return self++ async def __aexit__(self, exc_type, exc, tb):+ return False++ async def get(self, url, *, params, headers):+ assert url == "https://clawhub.ai/api/v1/download"+ self._captured_params = params+ return _FakeDownloadResponse(+ status_code=self._status_code,+ text=self._text,+ content=self._content,+ )++ def get_captured_params(self) -> dict | None:+ return self._captured_params+++async def test_clawhub_search_returns_owner_handle(tmp_path, monkeypatch):+ manager = SkillManager(workspace_dir=str(tmp_path / "workspace"))+ await manager.handle_skills_clawhub_set_token({"token": "test-token"})++ fake_results = [+ {+ "slug": "ppt-generator",+ "displayName": "PPT Generator",+ "summary": "Generate PPT",+ "version": "1.0.0",+ "updatedAt": 1000000,+ "ownerHandle": "kirkraman",+ },+ {+ "slug": "ppt-generator",+ "displayName": "PPT Gen 2",+ "summary": "Another PPT",+ "version": "2.0.0",+ "updatedAt": 2000000,+ "ownerHandle": "wwlyzzyorg",+ },+ ]++ monkeypatch.setattr(+ "jiuwenswarm.server.runtime.skill.skill_manager.httpx.AsyncClient",+ lambda timeout: _FakeSearchClient(fake_results),+ )++ result = await manager.handle_skills_clawhub_search({"q": "ppt-generator", "limit": 50})++ assert result["success"] is True+ assert len(result["skills"]) == 2+ assert result["skills"][0]["owner_handle"] == "kirkraman"+ assert result["skills"][1]["owner_handle"] == "wwlyzzyorg"+++async def test_clawhub_search_owner_handle_missing_is_empty_string(tmp_path, monkeypatch):+ manager = SkillManager(workspace_dir=str(tmp_path / "workspace"))+ await manager.handle_skills_clawhub_set_token({"token": "test-token"})++ fake_results = [+ {+ "slug": "unique-skill",+ "displayName": "Unique Skill",+ "summary": "Only one publisher",+ "version": "1.0.0",+ "updatedAt": 1000000,+ },+ ]++ monkeypatch.setattr(+ "jiuwenswarm.server.runtime.skill.skill_manager.httpx.AsyncClient",+ lambda timeout: _FakeSearchClient(fake_results),+ )++ result = await manager.handle_skills_clawhub_search({"q": "unique-skill"})++ assert result["success"] is True+ assert result["skills"][0]["owner_handle"] == ""+++async def test_clawhub_download_passes_owner_handle_to_api(tmp_path, monkeypatch):+ manager = SkillManager(workspace_dir=str(tmp_path / "workspace"))+ await manager.handle_skills_clawhub_set_token({"token": "test-token"})++ fake_client = _FakeDownloadClient(status_code=400, text="error")+ monkeypatch.setattr(+ "jiuwenswarm.server.runtime.skill.skill_manager.httpx.AsyncClient",+ lambda timeout: fake_client,+ )++ await manager.handle_skills_clawhub_download(+ {"slug": "ppt-generator", "owner_handle": "kirkraman"}+ )++ captured = fake_client.get_captured_params()+ assert captured is not None+ assert captured["slug"] == "ppt-generator"+ assert captured["ownerHandle"] == "kirkraman"+++async def test_clawhub_download_without_owner_handle_omits_param(tmp_path, monkeypatch):+ manager = SkillManager(workspace_dir=str(tmp_path / "workspace"))+ await manager.handle_skills_clawhub_set_token({"token": "test-token"})++ fake_client = _FakeDownloadClient(status_code=400, text="error")+ monkeypatch.setattr(+ "jiuwenswarm.server.runtime.skill.skill_manager.httpx.AsyncClient",+ lambda timeout: fake_client,+ )++ await manager.handle_skills_clawhub_download({"slug": "unique-skill"})++ captured = fake_client.get_captured_params()+ assert captured is not None+ assert captured["slug"] == "unique-skill"+ assert "ownerHandle" not in captured+++async def test_clawhub_download_empty_owner_handle_omits_param(tmp_path, monkeypatch):+ manager = SkillManager(workspace_dir=str(tmp_path / "workspace"))+ await manager.handle_skills_clawhub_set_token({"token": "test-token"})++ fake_client = _FakeDownloadClient(status_code=400, text="error")+ monkeypatch.setattr(+ "jiuwenswarm.server.runtime.skill.skill_manager.httpx.AsyncClient",+ lambda timeout: fake_client,+ )++ await manager.handle_skills_clawhub_download(+ {"slug": "unique-skill", "owner_handle": ""}+ )++ captured = fake_client.get_captured_params()+ assert captured is not None+ assert "ownerHandle" not in captured+++async def test_install_skill_parses_owner_handle_from_identifier(tmp_path, monkeypatch):+ from jiuwenswarm.agents.harness.common.tools.skill_toolkits import SkillToolkit++ manager = SkillManager(workspace_dir=str(tmp_path / "workspace"))+ await manager.handle_skills_clawhub_set_token({"token": "test-token"})++ toolkit = SkillToolkit(manager=manager)++ fake_client = _FakeDownloadClient(status_code=400, text="error")+ monkeypatch.setattr(+ "jiuwenswarm.server.runtime.skill.skill_manager.httpx.AsyncClient",+ lambda timeout: fake_client,+ )++ result = await toolkit.install_skill(+ identifier="kirkraman/ppt-generator",+ source="clawhub",+ )++ captured = fake_client.get_captured_params()+ assert captured is not None+ assert captured["slug"] == "ppt-generator"+ assert captured["ownerHandle"] == "kirkraman"+++async def test_install_skill_plain_slug_no_owner_handle(tmp_path, monkeypatch):+ from jiuwenswarm.agents.harness.common.tools.skill_toolkits import SkillToolkit++ manager = SkillManager(workspace_dir=str(tmp_path / "workspace"))+ await manager.handle_skills_clawhub_set_token({"token": "test-token"})++ toolkit = SkillToolkit(manager=manager)++ fake_client = _FakeDownloadClient(status_code=400, text="error")+ monkeypatch.setattr(+ "jiuwenswarm.server.runtime.skill.skill_manager.httpx.AsyncClient",+ lambda timeout: fake_client,+ )++ result = await toolkit.install_skill(+ identifier="unique-skill",+ source="clawhub",+ )++ captured = fake_client.get_captured_params()+ assert captured is not None+ assert captured["slug"] == "unique-skill"+ assert "ownerHandle" not in captured