Skip to content

Commit c93008a

Browse files
committed
fix(cli): refresh cached skill registry on add
1 parent d5403db commit c93008a

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

packages/cli/src/__tests__/lib/SkillManager.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,55 @@ describe("SkillManager", () => {
284284
expect(mockedGitUtil.cloneRepository).not.toHaveBeenCalled();
285285
});
286286

287+
it("should pull cached registry before installing skill", async () => {
288+
const repoPath = path.join(os.homedir(), ".ai-devkit", "skills", mockRegistryId);
289+
290+
(mockedFs.pathExists as any).mockImplementation((checkPath: string) => {
291+
if (checkPath === repoPath) {
292+
return Promise.resolve(true);
293+
}
294+
if (checkPath.includes(`${path.sep}skills${path.sep}${mockSkillName}`)) {
295+
return Promise.resolve(true);
296+
}
297+
if (checkPath.endsWith(`${path.sep}SKILL.md`)) {
298+
return Promise.resolve(true);
299+
}
300+
return Promise.resolve(true);
301+
});
302+
303+
mockedGitUtil.isGitRepository.mockResolvedValue(true);
304+
mockedGitUtil.pullRepository.mockResolvedValue(undefined);
305+
306+
await skillManager.addSkill(mockRegistryId, mockSkillName);
307+
308+
expect(mockedGitUtil.cloneRepository).not.toHaveBeenCalled();
309+
expect(mockedGitUtil.pullRepository).toHaveBeenCalledWith(repoPath);
310+
});
311+
312+
it("should skip pull when cached registry is not a git repository", async () => {
313+
const repoPath = path.join(os.homedir(), ".ai-devkit", "skills", mockRegistryId);
314+
315+
(mockedFs.pathExists as any).mockImplementation((checkPath: string) => {
316+
if (checkPath === repoPath) {
317+
return Promise.resolve(true);
318+
}
319+
if (checkPath.includes(`${path.sep}skills${path.sep}${mockSkillName}`)) {
320+
return Promise.resolve(true);
321+
}
322+
if (checkPath.endsWith(`${path.sep}SKILL.md`)) {
323+
return Promise.resolve(true);
324+
}
325+
return Promise.resolve(true);
326+
});
327+
328+
mockedGitUtil.isGitRepository.mockResolvedValue(false);
329+
330+
await skillManager.addSkill(mockRegistryId, mockSkillName);
331+
332+
expect(mockedGitUtil.pullRepository).not.toHaveBeenCalled();
333+
expect(mockedGitUtil.cloneRepository).not.toHaveBeenCalled();
334+
});
335+
287336
it("should throw error if skill not found in repository", async () => {
288337
(mockedFs.pathExists as any).mockResolvedValue(false);
289338

packages/cli/src/lib/SkillManager.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,14 @@ export class SkillManager {
405405
const repoPath = path.join(SKILL_CACHE_DIR, registryId);
406406

407407
if (await fs.pathExists(repoPath)) {
408+
if (await isGitRepository(repoPath)) {
409+
const spinner = ui.spinner(`Updating cached repository ${registryId}...`);
410+
spinner.start();
411+
await pullRepository(repoPath);
412+
spinner.succeed(`Cached repository ${registryId} updated`);
413+
} else {
414+
ui.warning(`Cached registry ${registryId} is not a git repository, using as-is.`);
415+
}
408416
ui.text(' → Using cached repository');
409417
return repoPath;
410418
}
@@ -704,4 +712,4 @@ export class SkillManager {
704712
return nameMatch || descMatch;
705713
});
706714
}
707-
}
715+
}

0 commit comments

Comments
 (0)