更新 src/skill-admin.ts

This commit is contained in:
QQ 2026-11-12 09:23:52 +08:00
parent 3562dd00d9
commit 61556800b8
1 changed files with 29 additions and 0 deletions

View File

@ -729,6 +729,35 @@ export class SkillAdmin {
return { installed, skipped, remaining }
}
/**
* Import one skill folder from another tool's skills directory (the
* "从其他软件导入" action). The caller (the group manager) has already
* resolved and vetted the source directory; this side owns the target:
* the name is validated, an existing skill — enabled or parked — is
* never overwritten, and the copy drops `.git` and symlinks exactly
* like a git install does.
*/
async importFolder(fromDir: string, folderInput: unknown): Promise<{ folder: string }> {
this.guardSync()
const folder = checkFolder(folderInput)
const existing = await this.locate(folder)
if (existing !== undefined) {
fail('already_exists', existing.area === 'holding'
? `DSH 里已有一个停用中的同名技能(${folder}),先处理它再导入。`
: `DSH 里已有同名技能(${folder}),不重复导入。`)
}
const skillsRoot = resolve(this.deps.skillsRoot())
await mkdir(skillsRoot, { recursive: true })
const target = resolve(skillsRoot, folder)
if (!target.startsWith(`${skillsRoot}${sep}`)) fail('path_escape', '导入目标越出技能目录。')
await cp(fromDir, target, {
recursive: true,
filter: (sourcePath) => !sourcePath.split(/[\\/]/).includes('.git') && !isSymlinkSync(sourcePath),
})
this.deps.log(`skill imported from another tool: ${folder}`)
return { folder }
}
/** Throw away a staged plan and its clone. */
async cancelInstall(planInput: { planId?: unknown }): Promise<{ cancelled: string }> {
const planId = typeof planInput.planId === 'string' ? planInput.planId : ''