dsh-capability-switch 0.0.0-stage → 1.5.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/CHANGELOG.md +273 -0
- package/LICENSE +21 -0
- package/README.md +239 -2
- package/cordis.patch.yml +9 -0
- package/docs/screenshots/mcp.png +0 -0
- package/docs/screenshots/overview.png +0 -0
- package/icon.svg +5 -0
- package/lib/client.js +840 -0
- package/lib/imports.js +120 -0
- package/lib/index.js +320 -0
- package/lib/mcp.js +306 -0
- package/lib/skills.js +526 -0
- package/lib/update.js +193 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +61 -4
package/lib/update.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs'
|
|
2
|
+
import { basename, dirname, join } from 'node:path'
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
4
|
+
import { dshHome } from './skills.js'
|
|
5
|
+
|
|
6
|
+
export const UPDATE_BUNDLE = 'dsh-capability-switch'
|
|
7
|
+
const UPDATE_REGISTRY_PACKAGE = UPDATE_BUNDLE + '@'
|
|
8
|
+
const INITIAL_DELAY = 45_000
|
|
9
|
+
const CHECK_INTERVAL = 6 * 60 * 60 * 1000
|
|
10
|
+
|
|
11
|
+
function installedVersion() {
|
|
12
|
+
try { return createRequire(import.meta.url)('../package.json').version } catch { return null }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function preferencesPath() {
|
|
16
|
+
return join(dshHome(), 'capability-switch', 'update-preferences.json')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function readPreferences() {
|
|
20
|
+
try {
|
|
21
|
+
const parsed = JSON.parse(await fs.readFile(preferencesPath(), 'utf8'))
|
|
22
|
+
return { autoUpdate: parsed?.autoUpdate !== false }
|
|
23
|
+
} catch {
|
|
24
|
+
return { autoUpdate: true }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function writePreferences(value) {
|
|
29
|
+
const file = preferencesPath()
|
|
30
|
+
await fs.mkdir(dirname(file), { recursive: true })
|
|
31
|
+
const temporary = join(dirname(file), `.${basename(file)}.${process.pid}.tmp`)
|
|
32
|
+
await fs.writeFile(temporary, JSON.stringify({ autoUpdate: value.autoUpdate !== false }, null, 2) + '\n')
|
|
33
|
+
await fs.rename(temporary, file)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function statusMessage(error) {
|
|
37
|
+
return error?.message || String(error)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Keep the npm-installed copy current through DSH's plugin manager.
|
|
42
|
+
* Local links, Git installs, and incompatible releases are deliberately left alone.
|
|
43
|
+
*/
|
|
44
|
+
export function createUpdateManager(ctx) {
|
|
45
|
+
let current = installedVersion()
|
|
46
|
+
let latest = null
|
|
47
|
+
let phase = 'idle'
|
|
48
|
+
let error = null
|
|
49
|
+
let checkedAt = null
|
|
50
|
+
let autoUpdate = true
|
|
51
|
+
let supported = null
|
|
52
|
+
let running = null
|
|
53
|
+
let timer = null
|
|
54
|
+
let interval = null
|
|
55
|
+
|
|
56
|
+
const manager = () => {
|
|
57
|
+
const value = ctx.get('pluginManager')
|
|
58
|
+
return value && typeof value.listBundles === 'function' && typeof value.listVersions === 'function' && typeof value.updateBundle === 'function'
|
|
59
|
+
? value
|
|
60
|
+
: null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const status = () => ({
|
|
64
|
+
name: UPDATE_BUNDLE,
|
|
65
|
+
current,
|
|
66
|
+
latest,
|
|
67
|
+
state: phase,
|
|
68
|
+
error,
|
|
69
|
+
checkedAt,
|
|
70
|
+
autoUpdate,
|
|
71
|
+
supported,
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
async function loadPreferences() {
|
|
75
|
+
const preferences = await readPreferences()
|
|
76
|
+
autoUpdate = preferences.autoUpdate
|
|
77
|
+
return status()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function setAutoUpdate(enabled) {
|
|
81
|
+
autoUpdate = enabled !== false
|
|
82
|
+
await writePreferences({ autoUpdate })
|
|
83
|
+
return status()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function check({ auto = false } = {}) {
|
|
87
|
+
if (running) return running
|
|
88
|
+
running = (async () => {
|
|
89
|
+
const pluginManager = manager()
|
|
90
|
+
if (!pluginManager) {
|
|
91
|
+
phase = 'unsupported'
|
|
92
|
+
supported = false
|
|
93
|
+
error = '当前 DSH 未提供插件管理器'
|
|
94
|
+
checkedAt = new Date().toISOString()
|
|
95
|
+
return status()
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const bundles = await pluginManager.listBundles()
|
|
99
|
+
const bundle = Array.isArray(bundles) ? bundles.find(item => item?.name === UPDATE_BUNDLE) : null
|
|
100
|
+
if (bundle?.version) current = bundle.version
|
|
101
|
+
supported = bundle?.update === 'registry'
|
|
102
|
+
&& typeof bundle.source === 'string'
|
|
103
|
+
&& bundle.source.startsWith(UPDATE_REGISTRY_PACKAGE)
|
|
104
|
+
if (!supported) {
|
|
105
|
+
phase = 'unsupported'
|
|
106
|
+
error = bundle?.source?.startsWith('link:')
|
|
107
|
+
? '本地目录安装不支持自动更新,请改用 npm 安装'
|
|
108
|
+
: '当前安装来源不支持自动更新,请改用 npm 安装'
|
|
109
|
+
checkedAt = new Date().toISOString()
|
|
110
|
+
return status()
|
|
111
|
+
}
|
|
112
|
+
const listed = await pluginManager.listVersions(UPDATE_BUNDLE)
|
|
113
|
+
if (listed?.status !== 'listed') {
|
|
114
|
+
phase = 'failed'
|
|
115
|
+
error = listed?.reason || '无法读取 npm 版本列表'
|
|
116
|
+
checkedAt = new Date().toISOString()
|
|
117
|
+
return status()
|
|
118
|
+
}
|
|
119
|
+
const candidate = listed.versions.find(item => item?.bundle === true
|
|
120
|
+
&& item.incompatible === undefined
|
|
121
|
+
&& item.deprecated === undefined
|
|
122
|
+
&& item.prerelease !== true
|
|
123
|
+
&& item.version !== current)
|
|
124
|
+
checkedAt = new Date().toISOString()
|
|
125
|
+
latest = candidate?.version || null
|
|
126
|
+
if (!candidate) {
|
|
127
|
+
phase = 'current'
|
|
128
|
+
error = null
|
|
129
|
+
return status()
|
|
130
|
+
}
|
|
131
|
+
phase = 'available'
|
|
132
|
+
error = null
|
|
133
|
+
if (auto && autoUpdate) return await apply(candidate.version, pluginManager)
|
|
134
|
+
return status()
|
|
135
|
+
} catch (problem) {
|
|
136
|
+
phase = 'failed'
|
|
137
|
+
error = statusMessage(problem)
|
|
138
|
+
checkedAt = new Date().toISOString()
|
|
139
|
+
return status()
|
|
140
|
+
}
|
|
141
|
+
})().finally(() => { running = null })
|
|
142
|
+
return running
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function apply(version, knownManager) {
|
|
146
|
+
const pluginManager = knownManager || manager()
|
|
147
|
+
if (!pluginManager || !version) return status()
|
|
148
|
+
if (phase === 'updating') return status()
|
|
149
|
+
phase = 'updating'
|
|
150
|
+
latest = version
|
|
151
|
+
error = null
|
|
152
|
+
try {
|
|
153
|
+
const result = await pluginManager.updateBundle(UPDATE_BUNDLE, version)
|
|
154
|
+
const application = result?.result?.application
|
|
155
|
+
if (application === 'applied' || application === 'restart-required') {
|
|
156
|
+
current = version
|
|
157
|
+
phase = application === 'applied' ? 'updated' : 'restart-required'
|
|
158
|
+
} else {
|
|
159
|
+
phase = 'failed'
|
|
160
|
+
error = result?.result?.error?.diagnostic || result?.result?.error?.code || '插件管理器未完成更新'
|
|
161
|
+
}
|
|
162
|
+
} catch (problem) {
|
|
163
|
+
phase = 'failed'
|
|
164
|
+
error = statusMessage(problem)
|
|
165
|
+
}
|
|
166
|
+
checkedAt = new Date().toISOString()
|
|
167
|
+
return status()
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function start() {
|
|
171
|
+
void loadPreferences()
|
|
172
|
+
const run = () => {
|
|
173
|
+
if (!autoUpdate) return
|
|
174
|
+
void check({ auto: true }).catch(problem => {
|
|
175
|
+
phase = 'failed'
|
|
176
|
+
error = statusMessage(problem)
|
|
177
|
+
checkedAt = new Date().toISOString()
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
timer = setTimeout(run, INITIAL_DELAY)
|
|
181
|
+
timer.unref?.()
|
|
182
|
+
interval = setInterval(run, CHECK_INTERVAL)
|
|
183
|
+
interval.unref?.()
|
|
184
|
+
return () => {
|
|
185
|
+
if (timer) clearTimeout(timer)
|
|
186
|
+
if (interval) clearInterval(interval)
|
|
187
|
+
timer = null
|
|
188
|
+
interval = null
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return { status, check, apply, setAutoUpdate, loadPreferences, start }
|
|
193
|
+
}
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Skills & MCP capabilities",
|
|
4
|
+
"description": "Manage Skills and MCP servers with a CC Switch-inspired unified list from the Capabilities sidebar page or Settings → Capabilities. Search, create, edit, toggle, delete, and test MCP connections. Skills writes are limited to user-level roots and project entries are read-only; MCP changes affect the active DSH profile. Display settings customize the sidebar entry, default tab, descriptions, and row density and persist in the DSH plugin configuration."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-capability-switch",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "A DSH sidebar plugin for managing Skills and MCP servers.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "lock-down",
|
|
7
|
+
"homepage": "https://github.com/lock-down/dsh-capability-switch#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/lock-down/dsh-capability-switch.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/lock-down/dsh-capability-switch/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"dsh",
|
|
17
|
+
"deepseek-harness",
|
|
18
|
+
"skills",
|
|
19
|
+
"mcp",
|
|
20
|
+
"plugin"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./lib/index.js",
|
|
25
|
+
"./client": "./lib/client.js",
|
|
26
|
+
"./locale/*.json": "./locale/*.json",
|
|
27
|
+
"./icon": "./icon.svg"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"lib",
|
|
31
|
+
"cordis.patch.yml",
|
|
32
|
+
"locale/*.json",
|
|
33
|
+
"docs",
|
|
34
|
+
"icon.svg",
|
|
35
|
+
"README.md",
|
|
36
|
+
"CHANGELOG.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"test": "node test/run.mjs"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"smol-toml": "^1.9.1",
|
|
44
|
+
"yaml": "^2.9.1"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"dsh": ">=0.2.2-rc.3 <0.3.0"
|
|
48
|
+
},
|
|
49
|
+
"dsh": {
|
|
50
|
+
"bundle": {
|
|
51
|
+
"patch": "./cordis.patch.yml"
|
|
52
|
+
},
|
|
53
|
+
"client": {
|
|
54
|
+
"platform": "web",
|
|
55
|
+
"immediately": true,
|
|
56
|
+
"inject": [
|
|
57
|
+
"@deepseek-ai/dsh-client-ui-layout",
|
|
58
|
+
"@deepseek-ai/dsh-client-ui-sidebar",
|
|
59
|
+
"@deepseek-ai/dsh-client-locale"
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|