完善 skill_manager 的技能维护能力

This commit is contained in:
2026-06-05 13:03:39 +08:00
parent fc0e76439d
commit ad31956f53
9 changed files with 392 additions and 41 deletions
+31 -23
View File
@@ -3,17 +3,19 @@ import { tool } from "@opencode-ai/plugin";
import { SkillStore } from "../../src/skills/store.js";
import { SessionRuntimeContextStore } from "../../src/sessions/runtimeContextStore.js";
const toolContextStore = new SessionRuntimeContextStore();
const initializePromise = toolContextStore.initialize();
const skillStore = new SkillStore();
export default tool({
export const createSkillManagerTool = (
skillStore = new SkillStore(),
toolContextStore = new SessionRuntimeContextStore(),
initializePromise: Promise<unknown> = toolContextStore.initialize(),
) => tool({
description:
"维护已验证、可复用、非敏感的 workflow 或方法模式。支持 list、append_pattern、remove_pattern、write_reference、remove_reference、write_script、remove_script。",
"维护已验证、可复用、非敏感的 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",
@@ -30,7 +32,7 @@ export default tool({
skill_path: tool.schema
.string()
.describe(
"Target skill directory path relative to .opencode/skills.",
"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()
@@ -47,7 +49,7 @@ export default tool({
content: tool.schema
.string()
.optional()
.describe("Asset content used by write_reference or write_script."),
.describe("Content used by write_skill, write_reference, or write_script."),
},
async execute(args, context) {
await initializePromise;
@@ -84,25 +86,29 @@ export default tool({
}
const result =
args.action === "append_pattern"
? await skillStore.appendPattern(args.skill_path, args.pattern ?? "")
: args.action === "remove_pattern"
? await skillStore.removePattern(args.skill_path, args.target_id ?? "")
: args.action === "write_reference"
? await skillStore.writeReference(
args.skill_path,
args.file_path ?? "",
args.content ?? "",
)
: args.action === "remove_reference"
? await skillStore.removeReference(args.skill_path, args.file_path ?? "")
: args.action === "write_script"
? await skillStore.writeScript(
args.action === "write_skill"
? await skillStore.writeSkill(args.skill_path, args.content ?? "")
: args.action === "remove_skill"
? await skillStore.removeSkill(args.skill_path)
: args.action === "append_pattern"
? await skillStore.appendPattern(args.skill_path, args.pattern ?? "")
: args.action === "remove_pattern"
? await skillStore.removePattern(args.skill_path, args.target_id ?? "")
: args.action === "write_reference"
? await skillStore.writeReference(
args.skill_path,
args.file_path ?? "",
args.content ?? "",
)
: await skillStore.removeScript(args.skill_path, args.file_path ?? "");
: args.action === "remove_reference"
? await skillStore.removeReference(args.skill_path, args.file_path ?? "")
: args.action === "write_script"
? await skillStore.writeScript(
args.skill_path,
args.file_path ?? "",
args.content ?? "",
)
: await skillStore.removeScript(args.skill_path, args.file_path ?? "");
return JSON.stringify({
ok: true,
@@ -113,3 +119,5 @@ export default tool({
});
},
});
export default createSkillManagerTool();