import { tool } from "@opencode-ai/plugin"; const internalBaseUrl = process.env.TJWATER_AGENT_INTERNAL_BASE_URL ?? "http://127.0.0.1:8787"; const internalToken = process.env.TJWATER_AGENT_INTERNAL_TOKEN ?? ""; export default tool({ description: "维护已验证、可复用、非敏感的 workflow 或方法模式。支持 list、write_skill、remove_skill、append_pattern、remove_pattern、write_reference、remove_reference、write_script、remove_script。", args: { action: tool.schema .enum([ "list", "write_skill", "remove_skill", "append_pattern", "remove_pattern", "write_reference", "remove_reference", "write_script", "remove_script", ]) .describe("Skill maintenance operation."), skill_path: tool.schema .string() .describe( "Target skill directory path relative to .opencode/skills. Use 'workflow' for the workflow index, or '__root__' for the root skills index.", ), pattern: tool.schema.string().optional().describe("Pattern text used by append_pattern."), target_id: tool.schema .string() .optional() .describe("Stable learned pattern id used by remove_pattern."), file_path: tool.schema .string() .optional() .describe("Asset file path. For references use references/*.md; for scripts use scripts/*.py."), content: tool.schema .string() .optional() .describe("Content used by write_skill, write_reference, or write_script."), }, async execute(args, context) { const response = await fetch( `${internalBaseUrl}/internal/tools/skill-manager`, { method: "POST", headers: { "Content-Type": "application/json", "x-agent-internal-token": internalToken, }, body: JSON.stringify({ ...args, session_id: context.sessionID, }), }, ); const text = await response.text(); if (!response.ok) { throw new Error(text); } return text; }, });