Import vendor/dsh-brain/lib/skill-admin.js
This commit is contained in:
parent
c86cba7696
commit
90d0b0f5fb
|
|
@ -604,6 +604,35 @@ export class SkillAdmin {
|
||||||
await rm(plan.stagingDir, { recursive: true, force: true }).catch(() => { });
|
await rm(plan.stagingDir, { recursive: true, force: true }).catch(() => { });
|
||||||
return { installed, skipped, remaining };
|
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. */
|
/** Throw away a staged plan and its clone. */
|
||||||
async cancelInstall(planInput) {
|
async cancelInstall(planInput) {
|
||||||
const planId = typeof planInput.planId === 'string' ? planInput.planId : '';
|
const planId = typeof planInput.planId === 'string' ? planInput.planId : '';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue