更新 lib/skill-admin.js

This commit is contained in:
QQ 2026-11-12 09:23:30 +08:00
parent 9d970b4fc0
commit 887b84bc6e
1 changed files with 29 additions and 0 deletions

View File

@ -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 : '';