From 90d0b0f5fbe58411050436d8207dcfe8ee0fdeb0 Mon Sep 17 00:00:00 2001 From: QQ Date: Thu, 12 Nov 2026 09:26:49 +0800 Subject: [PATCH] Import vendor/dsh-brain/lib/skill-admin.js --- vendor/dsh-brain/lib/skill-admin.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/vendor/dsh-brain/lib/skill-admin.js b/vendor/dsh-brain/lib/skill-admin.js index 8222432..e8f8065 100644 --- a/vendor/dsh-brain/lib/skill-admin.js +++ b/vendor/dsh-brain/lib/skill-admin.js @@ -604,6 +604,35 @@ export class SkillAdmin { await rm(plan.stagingDir, { recursive: true, force: true }).catch(() => { }); 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, folderInput) { + 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) { const planId = typeof planInput.planId === 'string' ? planInput.planId : '';