perf(skill): reuse precomputed command list

This commit is contained in:
YeonGyu-Kim
2026-05-08 16:43:14 +09:00
parent 8eadf2056f
commit 5cf86234ff
2 changed files with 25 additions and 0 deletions
+23
View File
@@ -5,6 +5,7 @@ import type { ToolContext } from "@opencode-ai/plugin/tool"
import type { LoadedSkill } from "../../features/opencode-skill-loader/types"
import * as skillContent from "../../features/opencode-skill-loader/skill-content"
import * as commandDiscovery from "../slashcommand/command-discovery"
import type { CommandInfo } from "../slashcommand/types"
const discoverCommandsSync = mock(() => [])
@@ -128,4 +129,26 @@ describe("createSkillTool", () => {
expect(clearSkillCache.mock.calls.length).toBe(baselineClearSkillCacheCalls + 2)
expect(getAllSkills.mock.calls.length).toBe(baselineGetAllSkillsCalls + 4)
})
it("executes precomputed commands without rediscovering commands", async () => {
// given
const baselineDiscoverCommandsSyncCalls = discoverCommandsSync.mock.calls.length
const command: CommandInfo = {
name: "seeded-command",
metadata: {
name: "seeded-command",
description: "Seeded command",
},
content: "Seeded command body",
scope: "project",
}
const skillTool = await createSkillTool({ skills: [], commands: [command] })
// when
const result = await skillTool.execute({ name: "seeded-command" }, mockContext)
// then
expect(result).toContain("Seeded command body")
expect(discoverCommandsSync.mock.calls.length).toBe(baselineDiscoverCommandsSyncCalls)
})
})
+2
View File
@@ -52,6 +52,8 @@ export function createSkillTool(options: SkillLoadOptions = {}): ToolDefinition
}
const getCommands = (): CommandInfo[] => {
if (options.commands) return [...options.commands]
return commandDiscovery.discoverCommandsSync(undefined, {
pluginsEnabled: options.pluginsEnabled,
enabledPluginsOverride: options.enabledPluginsOverride,