fix: generate skill/slashcommand descriptions synchronously when pre-provided (#1087)
* fix: generate skill/slashcommand tool descriptions synchronously when pre-provided When skills are passed via options (pre-resolved), build the tool description synchronously instead of fire-and-forget async. This eliminates the race condition where the description getter returns the bare prefix before the async cache-warming microtask completes. Fixes #1039 * chore: changes by sisyphus-dev-ai --------- Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
This commit is contained in:
@@ -57,6 +57,45 @@ const mockContext = {
|
||||
abort: new AbortController().signal,
|
||||
}
|
||||
|
||||
describe("skill tool - synchronous description", () => {
|
||||
it("includes available_skills immediately when skills are pre-provided", () => {
|
||||
// #given
|
||||
const loadedSkills = [createMockSkill("test-skill")]
|
||||
|
||||
// #when
|
||||
const tool = createSkillTool({ skills: loadedSkills })
|
||||
|
||||
// #then
|
||||
expect(tool.description).toContain("<available_skills>")
|
||||
expect(tool.description).toContain("test-skill")
|
||||
})
|
||||
|
||||
it("includes all pre-provided skills in available_skills immediately", () => {
|
||||
// #given
|
||||
const loadedSkills = [
|
||||
createMockSkill("playwright"),
|
||||
createMockSkill("frontend-ui-ux"),
|
||||
createMockSkill("git-master"),
|
||||
]
|
||||
|
||||
// #when
|
||||
const tool = createSkillTool({ skills: loadedSkills })
|
||||
|
||||
// #then
|
||||
expect(tool.description).toContain("playwright")
|
||||
expect(tool.description).toContain("frontend-ui-ux")
|
||||
expect(tool.description).toContain("git-master")
|
||||
})
|
||||
|
||||
it("shows no-skills message immediately when empty skills are pre-provided", () => {
|
||||
// #given / #when
|
||||
const tool = createSkillTool({ skills: [] })
|
||||
|
||||
// #then
|
||||
expect(tool.description).toContain("No skills are currently available")
|
||||
})
|
||||
})
|
||||
|
||||
describe("skill tool - agent restriction", () => {
|
||||
it("allows skill without agent restriction to any agent", async () => {
|
||||
// #given
|
||||
|
||||
@@ -147,7 +147,14 @@ export function createSkillTool(options: SkillLoadOptions = {}): ToolDefinition
|
||||
return cachedDescription
|
||||
}
|
||||
|
||||
getDescription()
|
||||
if (options.skills) {
|
||||
const skillInfos = options.skills.map(loadedSkillToInfo)
|
||||
cachedDescription = skillInfos.length === 0
|
||||
? TOOL_DESCRIPTION_NO_SKILLS
|
||||
: TOOL_DESCRIPTION_PREFIX + formatSkillsXml(skillInfos)
|
||||
} else {
|
||||
getDescription()
|
||||
}
|
||||
|
||||
return tool({
|
||||
get description() {
|
||||
|
||||
Reference in New Issue
Block a user