dsh-plugin-skill-manager 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/cordis.patch.yml +4 -0
- package/lib/index.js +99 -0
- package/package.json +32 -0
package/README.md
ADDED
package/cordis.patch.yml
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
|
|
6
|
+
const DSH_HOME = process.env.DSH_HOME || path.join(os.homedir(), '.dsh')
|
|
7
|
+
const SKILLS_DIR = path.join(DSH_HOME, 'skills')
|
|
8
|
+
function safeName(name) {
|
|
9
|
+
return typeof name === 'string' && name.length > 0 && !name.includes('/') && !name.includes('\\') && name !== '.' && name !== '..'
|
|
10
|
+
}
|
|
11
|
+
function frontmatterDescription(dir, enabled) {
|
|
12
|
+
const p = path.join(SKILLS_DIR, enabled ? dir : dir + '.disabled', 'SKILL.md')
|
|
13
|
+
try {
|
|
14
|
+
const text = fs.readFileSync(p, 'utf8')
|
|
15
|
+
const fm = text.match(/^---\r?\n([\s\S]*?)\r?\n---/)
|
|
16
|
+
if (fm) { const d = /description:\s*(.+)/.exec(fm[1]); return d ? String(d[1]).trim().slice(0, 200) : '' }
|
|
17
|
+
} catch (e) {}
|
|
18
|
+
return ''
|
|
19
|
+
}
|
|
20
|
+
function listSkills() {
|
|
21
|
+
let names = []
|
|
22
|
+
try { names = fs.readdirSync(SKILLS_DIR).sort() } catch (e) { return [] }
|
|
23
|
+
const skills = []
|
|
24
|
+
for (const raw of names) {
|
|
25
|
+
if (!fs.statSync(path.join(SKILLS_DIR, raw)).isDirectory()) continue
|
|
26
|
+
const disabled = raw.endsWith('.disabled')
|
|
27
|
+
const name = disabled ? raw.slice(0, -'.disabled'.length) : raw
|
|
28
|
+
if (name.length === 0) continue
|
|
29
|
+
skills.push({ name, enabled: !disabled, description: frontmatterDescription(name, !disabled) })
|
|
30
|
+
}
|
|
31
|
+
return skills
|
|
32
|
+
}
|
|
33
|
+
function setSkillEnabled(skillName, enabled) {
|
|
34
|
+
if (!safeName(skillName)) throw new Error('invalid skill name: ' + skillName)
|
|
35
|
+
const active = path.join(SKILLS_DIR, skillName)
|
|
36
|
+
const disabled = path.join(SKILLS_DIR, skillName + '.disabled')
|
|
37
|
+
if (enabled) { if (fs.existsSync(disabled)) fs.renameSync(disabled, active) }
|
|
38
|
+
else { if (fs.existsSync(active)) fs.renameSync(active, disabled) }
|
|
39
|
+
return { name: skillName, enabled }
|
|
40
|
+
}
|
|
41
|
+
function removeSkill(skillName) {
|
|
42
|
+
if (!safeName(skillName)) throw new Error('invalid skill name: ' + skillName)
|
|
43
|
+
let removed = false
|
|
44
|
+
for (const c of [path.join(SKILLS_DIR, skillName), path.join(SKILLS_DIR, skillName + '.disabled')]) {
|
|
45
|
+
if (fs.existsSync(c)) { fs.rmSync(c, { recursive: true, force: true }); removed = true }
|
|
46
|
+
}
|
|
47
|
+
return { removed }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const CLIENT_JS = `(function(){
|
|
51
|
+
if (window.__dshSkills) return
|
|
52
|
+
window.__dshSkills = true
|
|
53
|
+
function render(host){
|
|
54
|
+
var p = document.createElement('div'); p.className='dsh-sk-panel'
|
|
55
|
+
p.innerHTML = '<div class="dsh-sk-head">技能(Skills)</div><div class="dsh-sk-list"></div>'
|
|
56
|
+
host.appendChild(p)
|
|
57
|
+
var list = p.querySelector('.dsh-sk-list')
|
|
58
|
+
function load(){
|
|
59
|
+
fetch('/dsh-plugin-skill-manager/skills.json').then(function(r){return r.json()}).then(function(d){
|
|
60
|
+
list.innerHTML=''
|
|
61
|
+
var items = d.skills||[]
|
|
62
|
+
if (!items.length){ list.innerHTML='<div class="dsh-sk-empty">暂无已安装的技能</div>'; return }
|
|
63
|
+
items.forEach(function(s){
|
|
64
|
+
var row=document.createElement('div'); row.className='dsh-sk-row'
|
|
65
|
+
row.innerHTML='<span class="dsh-sk-name">'+ (s.name||'') +'</span>'+
|
|
66
|
+
'<button class="dsh-sk-toggle">'+(s.enabled?'停用':'启用')+'</button>'+
|
|
67
|
+
'<button class="dsh-sk-del">删除</button>'
|
|
68
|
+
row.querySelector('.dsh-sk-toggle').onclick=function(){ toggle(s.name, !s.enabled) }
|
|
69
|
+
row.querySelector('.dsh-sk-del').onclick=function(){ remove(s.name) }
|
|
70
|
+
list.appendChild(row)
|
|
71
|
+
})
|
|
72
|
+
}).catch(function(){ list.innerHTML='<div class="dsh-sk-empty">加载失败</div>' })
|
|
73
|
+
}
|
|
74
|
+
function toggle(name,en){ fetch('/dsh-plugin-skill-manager/skills.json',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({action:'setEnabled',name:String(name),enabled:en})}).then(load) }
|
|
75
|
+
function remove(name){ fetch('/dsh-plugin-skill-manager/skills.json',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({action:'remove',name:String(name)})}).then(load) }
|
|
76
|
+
load()
|
|
77
|
+
}
|
|
78
|
+
function ensure(){ var host=document.querySelector('[class*="settings"], [data-role="settings"], main, body'); if(!host) return setTimeout(ensure,300); render(host) }
|
|
79
|
+
if (document.readyState==='loading') document.addEventListener('DOMContentLoaded', ensure)
|
|
80
|
+
else ensure()
|
|
81
|
+
})()`
|
|
82
|
+
|
|
83
|
+
const name = 'dsh-plugin-skill-manager'
|
|
84
|
+
const inject = ['webServer']
|
|
85
|
+
function apply(ctx){
|
|
86
|
+
const json=(res,o)=>{res.writeHead(200,{'Content-Type':'application/json; charset=utf-8','Cache-Control':'no-store'});res.end(JSON.stringify(o))}
|
|
87
|
+
ctx.webServer.register({kind:'exact',path:'/dsh-plugin-skill-manager/skills.json',handler:(req,res)=>{
|
|
88
|
+
if(req.method==='POST'){
|
|
89
|
+
let body=''; req.on('data',c=>body+=c); req.on('end',()=>{ try{
|
|
90
|
+
const p=JSON.parse(body||'{}')
|
|
91
|
+
if(p.action==='setEnabled'){ setSkillEnabled(String(p.name), !!p.enabled); return json(res,{ok:true}) }
|
|
92
|
+
if(p.action==='remove'){ removeSkill(String(p.name)); return json(res,{ok:true}) }
|
|
93
|
+
json(res,{ok:false,error:'unknown action'})
|
|
94
|
+
}catch(e){ json(res,{ok:false,error:String(e&&e.message||e)}) } })
|
|
95
|
+
} else { json(res,{ok:true,skills:listSkills()}) }
|
|
96
|
+
}})
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
export { name, inject, apply }
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-plugin-skill-manager",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "DSH Skill 启停/删除管理",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dsh",
|
|
7
|
+
"dsh-plugin",
|
|
8
|
+
"deepseek-harness",
|
|
9
|
+
"skill",
|
|
10
|
+
"skills"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "lib/index.js",
|
|
14
|
+
"files": [
|
|
15
|
+
"lib",
|
|
16
|
+
"cordis.patch.yml",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"dsh": {
|
|
20
|
+
"bundle": {
|
|
21
|
+
"patch": "./cordis.patch.yml"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/mengyu-arch/dsh-plugins.git"
|
|
31
|
+
}
|
|
32
|
+
}
|