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
feat(skill): Add /skills use command
dreamofapsychiccat08f6503e9224
diff --git a/jiuwenclaw/agentserver/interface.py b/jiuwenclaw/agentserver/interface.pyindex 4e52acd01c..457e5b04b2 100644--- a/jiuwenclaw/agentserver/interface.py+++ b/jiuwenclaw/agentserver/interface.py@@ -13,6 +13,7 @@ from __future__ import annotationsimport asyncioimport jsonimport logging+import reimport timefrom typing import Any, AsyncIterator, Tuple@@ -78,16 +79,42 @@ _SKILL_ROUTES: dict[ReqMethod, str] = {ReqMethod.SKILLS_EVOLUTION_SAVE: "handle_skills_evolution_save",}+_SKILL_COMMAND_REGEX = re.compile(+ r"^/skills use\s+(?P<skill_names>[^,]+)\s*,\s*(?P<query>.*)$"+)+++def _handle_skills_use_slash_command(query: str) -> Tuple[list, str]:+ """Handle the /skills use slash command"""+ stripped = query.strip()+ if not stripped.startswith("/skills use"):+ return [], query++ skill_list = []+ matches = _SKILL_COMMAND_REGEX.match(stripped)+ if matches:+ skill_list.append(matches.group("skill_names")) # Currently only extracts one skill+ new_query = matches.group("query")+ return skill_list, new_query+ else:+ logger.warning(f"Couldn't parse command: {stripped}")+ return [], query+def build_user_prompt(content: str, files: dict, channel: str, language: str, *,trusted_dirs: list[str] | None = None, metadata: dict[str, Any] | None = None) -> str:"""Build user prompt for the agent."""+interaction_prefix = ""if metadata:interaction_ctx = str(metadata.get("interaction_context") or "").strip()if interaction_ctx:interaction_prefix = f"\n{interaction_ctx}\n\n"+ skills_to_use, new_content = _handle_skills_use_slash_command(content)+ if new_content:+ content = new_content+if language == "zh":prompt = "你收到一条消息:\n"else:@@ -119,6 +146,7 @@ def build_user_prompt(content: str, files: dict, channel: str, language: str, *,now = datetime.now(timezone(timedelta(hours=8)))now_str = now.strftime("%Y-%m-%d %H:%M:%S")+user_message_context = {"source": channel,"timezone": "Asia/Shanghai",@@ -126,13 +154,16 @@ def build_user_prompt(content: str, files: dict, channel: str, language: str, *,"preferred_response_language": language,"content": content,"files_updated_by_user": json.dumps(files, ensure_ascii=False),- "type": "user input"+ "type": "user input",}+ if skills_to_use:+ user_message_context["skills_to_use"] = skills_to_useif trusted_dirs:user_message_context["trusted_dirs"] = json.dumps(trusted_dirs, ensure_ascii=False)return interaction_prefix + prompt + json.dumps(user_message_context, ensure_ascii=False)+class JiuWenClaw:"""JiuWenClaw 统一门面.diff --git a/jiuwenclaw/cli/src/core/commands/builtins/skills.ts b/jiuwenclaw/cli/src/core/commands/builtins/skills.tsindex 0c64e6cdfe..0f626437a8 100644--- a/jiuwenclaw/cli/src/core/commands/builtins/skills.ts+++ b/jiuwenclaw/cli/src/core/commands/builtins/skills.ts@@ -57,8 +57,8 @@ async function listSkills(ctx: import("../types.js").CommandContext): Promise<voexport function createSkillsCommand(): SlashCommand {return {name: "skills",- description: "Manage skills (list, install, uninstall, marketplace)",- usage: "/skills [list|install|uninstall|marketplace]",+ description: "Manage skills (list, install, uninstall, marketplace, use)",+ usage: "/skills [list|install|uninstall|marketplace|use]",example: "/skills list",kind: CommandKind.BUILT_IN,action: async (ctx) => {@@ -234,6 +234,32 @@ export function createSkillsCommand(): SlashCommand {},],},+ {+ name: "use",+ description: "Use a skill to execute a query",+ usage: "/skills use <skill_name>, <query>",+ example: "/skills use my-skill, Code and execute a Hello World program.",+ kind: CommandKind.BUILT_IN,+ takesArgs: true,+ action: async (ctx, args) => {+ const parts = args.trim().split(/\s*,\s*(.*)/);+ const skill_name = parts[0];+ const query = parts[1];+ if (!skill_name || !query) {+ ctx.addItem(makeItem(ctx.sessionId, "error", "Usage: /skills use <skill_name>, <query>"));+ return;+ }+ const text = `/skills use ${skill_name}, ${query}`++ const requestId = ctx.sendMessage(text)+ if (!requestId) {+ ctx.addItem(+ makeItem(ctx.sessionId, "error", "offline: waiting for reconnect before sending /skills use request"),+ );+ return;+ }+ },+ },],};}