-
Notifications
You must be signed in to change notification settings - Fork 354
feat(desktop): SkillHub 支持导入本地 zip/SKILL.md #1232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MagicLizi
merged 3 commits into
makecindy:main
from
codeingforcoffee:feat/skillhub-import-local-skill
Jul 31, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
apps/desktop/src/main/skillhub/__tests__/importLocalSkill.pure.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { | ||
| classifyImportSourcePath, | ||
| extractSkillMetadataFromMd, | ||
| findZipSkillPackageRoot, | ||
| isValidImportSkillName, | ||
| relativizeZipEntry, | ||
| } from '../importLocalSkill.pure'; | ||
|
|
||
| describe('isValidImportSkillName', () => { | ||
| it('accepts registry-safe names', () => { | ||
| expect(isValidImportSkillName('my-skill')).toBe(true); | ||
| expect(isValidImportSkillName('a')).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects uppercase, underscores, empty', () => { | ||
| expect(isValidImportSkillName('My-Skill')).toBe(false); | ||
| expect(isValidImportSkillName('my_skill')).toBe(false); | ||
| expect(isValidImportSkillName('')).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('classifyImportSourcePath', () => { | ||
| it('accepts zip and SKILL.md', () => { | ||
| expect(classifyImportSourcePath('/tmp/pkg.zip')).toEqual({ kind: 'zip' }); | ||
| expect(classifyImportSourcePath('/tmp/SKILL.md')).toEqual({ kind: 'md' }); | ||
| expect(classifyImportSourcePath('/tmp/skill.md')).toEqual({ kind: 'md' }); | ||
| }); | ||
|
|
||
| it('rejects other md names and unknown extensions', () => { | ||
| expect(classifyImportSourcePath('/tmp/README.md')).toMatchObject({ error: expect.any(String) }); | ||
| expect(classifyImportSourcePath('/tmp/foo.tar')).toMatchObject({ error: expect.any(String) }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('findZipSkillPackageRoot', () => { | ||
| it('finds SKILL.md at zip root', () => { | ||
| expect(findZipSkillPackageRoot(['SKILL.md', 'refs/a.md'])).toEqual({ packageRoot: '' }); | ||
| }); | ||
|
|
||
| it('finds SKILL.md under a single top-level folder', () => { | ||
| expect(findZipSkillPackageRoot(['my-skill/SKILL.md', 'my-skill/refs/x.md'])).toEqual({ | ||
| packageRoot: 'my-skill/', | ||
| }); | ||
| }); | ||
|
|
||
| it('errors when missing or ambiguous', () => { | ||
| expect(findZipSkillPackageRoot(['readme.txt'])).toMatchObject({ error: expect.any(String) }); | ||
| expect( | ||
| findZipSkillPackageRoot(['a/SKILL.md', 'b/SKILL.md']), | ||
| ).toMatchObject({ error: expect.any(String) }); | ||
| }); | ||
|
|
||
| it('prefers root SKILL.md when nested copies also exist', () => { | ||
| expect(findZipSkillPackageRoot(['SKILL.md', 'vendor/SKILL.md'])).toEqual({ packageRoot: '' }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('relativizeZipEntry', () => { | ||
| it('strips package root and skips __MACOSX', () => { | ||
| expect(relativizeZipEntry('my-skill/SKILL.md', 'my-skill/')).toBe('SKILL.md'); | ||
| expect(relativizeZipEntry('__MACOSX/._x', '')).toBeNull(); | ||
| expect(relativizeZipEntry('other/SKILL.md', 'my-skill/')).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('extractSkillMetadataFromMd', () => { | ||
| it('extracts name, description, and version', () => { | ||
| const result = extractSkillMetadataFromMd(`--- | ||
| name: demo-skill | ||
| description: Does useful things | ||
| version: 1.2.3 | ||
| --- | ||
|
|
||
| # Body | ||
| `); | ||
| expect(result).toEqual({ | ||
| ok: true, | ||
| metadata: { | ||
| name: 'demo-skill', | ||
| description: 'Does useful things', | ||
| version: '1.2.3', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('defaults version to 0.1.0', () => { | ||
| const result = extractSkillMetadataFromMd(`--- | ||
| name: demo-skill | ||
| description: Does useful things | ||
| --- | ||
| `); | ||
| expect(result.ok && result.metadata.version).toBe('0.1.0'); | ||
| }); | ||
|
|
||
| it('rejects missing name/description and invalid name', () => { | ||
| expect( | ||
| extractSkillMetadataFromMd(`--- | ||
| description: only desc | ||
| --- | ||
| `), | ||
| ).toMatchObject({ ok: false, errorCode: 'INVALID_FRONTMATTER' }); | ||
|
|
||
| expect( | ||
| extractSkillMetadataFromMd(`--- | ||
| name: Bad_Name | ||
| description: x | ||
| --- | ||
| `), | ||
| ).toMatchObject({ ok: false, errorCode: 'INVALID_NAME' }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.