Skip to content

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

fix: 修复agent无法卸载本地导入的skill的问题

xutuoa04d653cab43
diff --git a/jiuwenclaw/agentserver/tools/skill_toolkits.py b/jiuwenclaw/agentserver/tools/skill_toolkits.py
index 12e8c88913..899912f9fd 100644
--- a/jiuwenclaw/agentserver/tools/skill_toolkits.py
+++ b/jiuwenclaw/agentserver/tools/skill_toolkits.py
@@ -472,12 +472,32 @@ class SkillToolkit:
logger.info("[SkillToolkit] _list_installed_skills called")
payload = await self._manager.handle_skills_installed({})
if not payload.get("plugins"):
- return {"success": True, "items": [], "detail": ""}
+ plugin_items: list[dict[str, Any]] = []
+ else:
+ plugin_items = []
+ for plugin in payload.get("plugins", []):
+ name = str(plugin.get("plugin_name", "")).strip()
+ source = str(plugin.get("marketplace", "")).strip() or "local"
+ if name:
+ plugin_items.append(self._build_installed_item(name, source))
items: list[dict[str, Any]] = []
- for plugin in payload.get("plugins", []):
- name = str(plugin.get("plugin_name", "")).strip()
- source = str(plugin.get("marketplace", "")).strip() or "local"
+ seen: set[str] = set()
+ for item in plugin_items:
+ name = str(item.get("name", "")).strip()
+ if not name or name in seen:
+ continue
+ seen.add(name)
+ items.append(item)
+
+ for local_skill in self._manager.get_local_skills():
+ if not isinstance(local_skill, dict):
+ continue
+ name = str(local_skill.get("name", "")).strip()
+ if not name or name in seen:
+ continue
+ source = str(local_skill.get("source", "")).strip() or "local"
+ seen.add(name)
items.append(self._build_installed_item(name, source))
return {"success": True, "items": items, "detail": ""}
except Exception as exc: # noqa: BLE001
diff --git a/tests/unit_tests/agentserver/test_skill_toolkits.py b/tests/unit_tests/agentserver/test_skill_toolkits.py
new file mode 100644
index 0000000000..03b70c5752
--- /dev/null
+++ b/tests/unit_tests/agentserver/test_skill_toolkits.py
@@ -0,0 +1,30 @@
+from __future__ import annotations
+
+import asyncio
+
+from jiuwenclaw.agentserver.skill_manager import SkillManager
+from jiuwenclaw.agentserver.tools.skill_toolkits import SkillToolkit
+
+
+def test_uninstall_skill_removes_local_skill_without_plugin_record(tmp_path):
+ manager = SkillManager(workspace_dir=str(tmp_path / "workspace"))
+ toolkit = SkillToolkit(manager)
+
+ source = tmp_path / "source-skill"
+ source.mkdir()
+ (source / "SKILL.md").write_text(
+ "---\nname: local-only-skill\ndescription: local only\n---\nbody\n",
+ encoding="utf-8",
+ )
+
+ imported = asyncio.run(manager.handle_skills_import_local({"path": str(source)}))
+ assert imported["success"] is True
+ assert manager.get_installed_plugins() == []
+ assert (tmp_path / "workspace" / "skills" / "local-only-skill").is_dir()
+
+ result = asyncio.run(toolkit.uninstall_skill("local-only-skill"))
+
+ assert result["success"] is True
+ assert result["removed"] is True
+ assert not (tmp_path / "workspace" / "skills" / "local-only-skill").exists()
+ assert manager.get_local_skills() == []