@crocketc/dsh-capability-manager 0.2.0 → 0.3.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 +26 -12
- package/docs/screenshots/budget-preview-after-toggle.png +0 -0
- package/docs/screenshots/capability-dashboard.png +0 -0
- package/icon.svg +23 -0
- package/locale/en.json +1 -0
- package/package.json +5 -3
- package/src/accounting.js +10 -0
- package/src/client.js +209 -31
- package/src/index.js +44 -3
- package/src/plugin-update.js +13 -0
package/README.md
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="icon.svg" alt="Agent 能力管理图标" width="88" height="88">
|
|
3
|
+
<h1>DSH Agent 能力管理</h1>
|
|
4
|
+
<p><strong>按 Agent 预设管理工具与技能,并看清它们在新会话首个模型请求中的注入规模。</strong></p>
|
|
5
|
+
<p>
|
|
6
|
+
<code>准备发布 0.3.0</code>
|
|
7
|
+
<code>DSH 0.2.2-rc.5</code>
|
|
8
|
+
<code>Web profile</code>
|
|
9
|
+
<code>Node.js ≥24.9</code>
|
|
10
|
+
</p>
|
|
11
|
+
</div>
|
|
2
12
|
|
|
3
|
-
|
|
13
|
+
Agent 能力管理是一个可插拔的 DeepSeek Harness(DSH)Web 插件。它把预设能力开关、逐项 token 预算和首请求注入统计放在同一个面板中,让你在配置时了解 Agent 会向模型提供哪些能力、预计占用多少上下文。
|
|
4
14
|
|
|
5
|
-
|
|
15
|
+
## 功能截图
|
|
6
16
|
|
|
7
|
-
|
|
17
|
+
以下截图来自 DSH `0.2.2-rc.5` Web profile 中运行的插件。统计数字会随当前预设、工作区和能力目录变化。
|
|
18
|
+
|
|
19
|
+
### 能力总览与首请求预算
|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
### 调整开关后的即时预览
|
|
24
|
+
|
|
25
|
+

|
|
8
26
|
|
|
9
27
|
## 能做什么
|
|
10
28
|
|
|
@@ -14,8 +32,9 @@ Agent 能力管理是一个可插拔的 DeepSeek Harness(DSH)Web 插件。
|
|
|
14
32
|
- **预览首请求预算**:切换开关时,实时查看启用数量、能力 token 小计、初始注入总量及相对已保存配置的变化。
|
|
15
33
|
- **查看实际首请求**:在新会话发出首个模型请求后,按实际组装内容估算注入分项,并单独显示服务商报告的输入 token。
|
|
16
34
|
- **估算费用变化**:以 DSH 当前默认模型为计价模型,按每月 1,500 次请求估算能力开关变化带来的输入费用差值。
|
|
35
|
+
- **检查插件更新**:加载时自动检查,手动刷新也检查 npm 或 GitHub 来源;dsh-market 公共 Update API v1 可用时由其提供检查和更新进度,否则按当前安装来源回退检查,并把更新交给 DSH 插件管理器。
|
|
17
36
|
|
|
18
|
-
##
|
|
37
|
+
## 快速开始
|
|
19
38
|
|
|
20
39
|
需要已安装 DSH,并使用 Node.js `>=24.9`。将 `web` 替换为目标 profile:
|
|
21
40
|
|
|
@@ -81,6 +100,8 @@ dsh --profile web
|
|
|
81
100
|
- PTC 的 `run_code` 是 DSH 保留的模型工具入口,无法在本面板关闭。
|
|
82
101
|
- 技能开关控制 DSH 对目标预设发布的技能目录,并保留技能源文件及其在其他应用中的使用方式。
|
|
83
102
|
- 发现技能首版支持 `skills.sh` 搜索和公开 GitHub 仓库浏览;私有仓库与其他技能市场不在当前范围。
|
|
103
|
+
- 插件页显示当前安装版本、更新状态和 GitHub 仓库入口;不修改 DSH 宿主的已安装插件列表及详情页。
|
|
104
|
+
- GitHub 来源在 dsh-market 不可用时,以安装 commit 和仓库默认分支 HEAD 比较;profile 未保留原始分支或标签时,无法确认的提交历史显示为暂不可用。
|
|
84
105
|
|
|
85
106
|
## 数据位置
|
|
86
107
|
|
|
@@ -98,10 +119,3 @@ npm install
|
|
|
98
119
|
npm test
|
|
99
120
|
npm pack --dry-run
|
|
100
121
|
```
|
|
101
|
-
|
|
102
|
-
## 项目资料
|
|
103
|
-
|
|
104
|
-
- [Agent 能力管理交互原型](docs/prototype-agent-capability.html):可在“当前实现”和“调整方案”间切换;方案以整体统计区域定高,并让注入明细同高、均分左右列。
|
|
105
|
-
- [P0 范围与验收决定](docs/p0.md)
|
|
106
|
-
- [术语表](GLOSSARY.md)
|
|
107
|
-
- [问题反馈与源码](https://github.com/crocketc/dsh-capability-manager)
|
|
Binary file
|
|
Binary file
|
package/icon.svg
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" fill="none">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="bg" x1="16" y1="12" x2="112" y2="118" gradientUnits="userSpaceOnUse">
|
|
4
|
+
<stop stop-color="#263A72"/>
|
|
5
|
+
<stop offset="1" stop-color="#172449"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<linearGradient id="core" x1="43" y1="43" x2="82" y2="84" gradientUnits="userSpaceOnUse">
|
|
8
|
+
<stop stop-color="#8DE8DC"/>
|
|
9
|
+
<stop offset="1" stop-color="#4FC8C0"/>
|
|
10
|
+
</linearGradient>
|
|
11
|
+
</defs>
|
|
12
|
+
<rect x="4" y="4" width="120" height="120" rx="34" fill="url(#bg)"/>
|
|
13
|
+
<path d="M64 62 31 34M64 62l33-28M64 66v34" stroke="#9DB3E8" stroke-width="6" stroke-linecap="round"/>
|
|
14
|
+
<circle cx="30" cy="32" r="13" fill="#F4F7FF"/>
|
|
15
|
+
<circle cx="98" cy="32" r="13" fill="#F4F7FF"/>
|
|
16
|
+
<circle cx="64" cy="101" r="13" fill="#F4F7FF"/>
|
|
17
|
+
<circle cx="30" cy="32" r="5" fill="#8B9FE0"/>
|
|
18
|
+
<path d="M94 32h8M98 28v8" stroke="#6CCFC4" stroke-width="3" stroke-linecap="round"/>
|
|
19
|
+
<path d="M60 101h8" stroke="#8B9FE0" stroke-width="3" stroke-linecap="round"/>
|
|
20
|
+
<circle cx="64" cy="64" r="25" fill="url(#core)" stroke="#E9FFFC" stroke-width="4"/>
|
|
21
|
+
<path d="M64 48.5 67.7 59l10.5 3.5-10.5 3.7L64 76.5l-3.7-10.3L50 62.5 60.3 59 64 48.5Z" fill="#18365A"/>
|
|
22
|
+
<circle cx="64" cy="62.5" r="3.3" fill="#F5FFFE"/>
|
|
23
|
+
</svg>
|
package/locale/en.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"Agent能力管理"}}
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crocketc/dsh-capability-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Manage Agent capabilities and first-request token budgets in DeepSeek Harness",
|
|
5
|
+
"icon": "./icon.svg",
|
|
5
6
|
"repository": "git+https://github.com/crocketc/dsh-capability-manager.git",
|
|
6
7
|
"type": "module",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": "./src/index.js",
|
|
9
|
-
"./client": "./src/client.js"
|
|
10
|
+
"./client": "./src/client.js",
|
|
11
|
+
"./locale/*.json": "./locale/*.json"
|
|
10
12
|
},
|
|
11
|
-
"files": ["src", "data", "cordis.patch.yml"],
|
|
13
|
+
"files": ["src", "data", "locale", "icon.svg", "cordis.patch.yml", "docs/screenshots"],
|
|
12
14
|
"engines": { "node": ">=24.9" },
|
|
13
15
|
"scripts": { "test": "node --test" },
|
|
14
16
|
"dsh": {
|
package/src/accounting.js
CHANGED
|
@@ -280,6 +280,14 @@ export function readInitial(recordEvents, context = {}) {
|
|
|
280
280
|
...(providerUsage === undefined ? {} : { providerUsage }),
|
|
281
281
|
});
|
|
282
282
|
measured.prompt.workspaceSkillCatalogTokens += workspaceSkillCatalogTokens;
|
|
283
|
+
const toolCounts = { tool: 0, mcp: 0 };
|
|
284
|
+
const seenToolNames = new Set();
|
|
285
|
+
for (const tool of measured.toolRows) {
|
|
286
|
+
if (seenToolNames.has(tool.name)) continue;
|
|
287
|
+
seenToolNames.add(tool.name);
|
|
288
|
+
if (tool.source === 'mcp') toolCounts.mcp++;
|
|
289
|
+
else toolCounts.tool++;
|
|
290
|
+
}
|
|
283
291
|
|
|
284
292
|
return {
|
|
285
293
|
...(context.presetId === undefined ? {} : { presetId: context.presetId }),
|
|
@@ -293,6 +301,7 @@ export function readInitial(recordEvents, context = {}) {
|
|
|
293
301
|
},
|
|
294
302
|
measured,
|
|
295
303
|
count: measured.toolRows.length + skillCount,
|
|
304
|
+
categoryCounts: { ...toolCounts, skill: skillCount },
|
|
296
305
|
...(workspaceSkillCatalogTokens > 0 ? { workspaceSkillCatalogTokens } : {}),
|
|
297
306
|
};
|
|
298
307
|
}
|
|
@@ -330,6 +339,7 @@ export function formatBudget(measuredInput, count) {
|
|
|
330
339
|
];
|
|
331
340
|
return {
|
|
332
341
|
count,
|
|
342
|
+
categoryCounts: measuredInput?.categoryCounts ?? { tool: 0, mcp: 0, skill: 0 },
|
|
333
343
|
capability,
|
|
334
344
|
total,
|
|
335
345
|
breakdown: rows.filter(([, , tokens]) => tokens > 0).map(([key, label, tokens]) => ({ key, label, tokens })),
|
package/src/client.js
CHANGED
|
@@ -2,10 +2,15 @@ window.__ModuleLoader__.load({ id: '@crocketc/dsh-capability-manager', factory(r
|
|
|
2
2
|
const React = require('react')
|
|
3
3
|
|
|
4
4
|
/** Browser entry for the Agent Capability Manager panel. */
|
|
5
|
-
const inject = ['slots']
|
|
5
|
+
const inject = ['slots', 'pluginNavigation']
|
|
6
6
|
|
|
7
7
|
const ID = 'dsh-capability-manager'
|
|
8
|
+
const PACKAGE_NAME = '@crocketc/dsh-capability-manager'
|
|
8
9
|
const ENDPOINT = '/api/dsh-capability-manager'
|
|
10
|
+
const MARKET_CAPABILITIES_PATH = '/dsh-market/api/v1/capabilities'
|
|
11
|
+
const MARKET_UPDATES_PATH = '/dsh-market/api/v1/updates'
|
|
12
|
+
const MARKET_OPERATIONS_PATH = '/dsh-market/api/v1/operations'
|
|
13
|
+
const PLUGIN_VERSION = '0.3.0'
|
|
9
14
|
const categories = [
|
|
10
15
|
['skill-catalog', '全局技能', '#7843d6'],
|
|
11
16
|
['workspace-skill-catalog', '工作区技能', '#c23080'],
|
|
@@ -48,13 +53,51 @@ function apply(ctx) {
|
|
|
48
53
|
})
|
|
49
54
|
}
|
|
50
55
|
|
|
56
|
+
async function marketApi(signal) {
|
|
57
|
+
try {
|
|
58
|
+
const capabilityResponse = await fetch(MARKET_CAPABILITIES_PATH, { credentials: 'same-origin', signal })
|
|
59
|
+
if (!capabilityResponse.ok) return undefined
|
|
60
|
+
const capability = await capabilityResponse.json()
|
|
61
|
+
if (capability.schema !== 'dsh-market/update-api/v1' || capability.apiVersion !== 1 ||
|
|
62
|
+
capability.stability === undefined || !capability.features?.check || !capability.features?.update || !capability.features?.progress ||
|
|
63
|
+
capability.endpoints?.updates !== MARKET_UPDATES_PATH || capability.endpoints?.operations !== MARKET_OPERATIONS_PATH) return undefined
|
|
64
|
+
return true
|
|
65
|
+
} catch {
|
|
66
|
+
return undefined
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function checkMarketUpdate(installedSource, installedVersion, signal) {
|
|
71
|
+
try {
|
|
72
|
+
if (!['npm', 'git'].includes(installedSource)) return undefined
|
|
73
|
+
if (!await marketApi(signal)) return undefined
|
|
74
|
+
const response = await fetch(`${MARKET_UPDATES_PATH}?name=${encodeURIComponent(PACKAGE_NAME)}&force=1`, { credentials: 'same-origin', signal })
|
|
75
|
+
if (!response.ok) return undefined
|
|
76
|
+
const result = await response.json()
|
|
77
|
+
if (result.schema !== 'dsh-market/update-api/v1' || result.package?.name !== PACKAGE_NAME) return undefined
|
|
78
|
+
const item = result.package
|
|
79
|
+
const reportedSource = typeof item.source === 'string' ? item.source : item.source?.kind
|
|
80
|
+
const marketSource = ({ github: 'git', git: 'git', npm: 'npm', registry: 'npm' })[String(reportedSource || '').toLowerCase()]
|
|
81
|
+
if (!marketSource || marketSource !== installedSource || item.installedVersion !== installedVersion ||
|
|
82
|
+
(item.updateAvailable && typeof item.latestVersion !== 'string')) return undefined
|
|
83
|
+
return { version: item.installedVersion, ...(item.updateAvailable ? { update: item.latestVersion } : {}),
|
|
84
|
+
status: 'checked', source: marketSource, market: true }
|
|
85
|
+
} catch {
|
|
86
|
+
return undefined
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
51
90
|
function Panel({ useSessions }) {
|
|
52
91
|
const [data, setData] = useState(null)
|
|
92
|
+
const [pluginVersion, setPluginVersion] = useState({ version: PLUGIN_VERSION })
|
|
53
93
|
const [draft, setDraft] = useState(null)
|
|
54
94
|
const [savedPolicy, setSavedPolicy] = useState(null)
|
|
55
95
|
const [busy, setBusy] = useState(false)
|
|
56
96
|
const [refreshing, setRefreshing] = useState(false)
|
|
57
97
|
const [refreshStatus, setRefreshStatus] = useState('')
|
|
98
|
+
const [updateProgress, setUpdateProgress] = useState('')
|
|
99
|
+
const [updateFallback, setUpdateFallback] = useState(false)
|
|
100
|
+
const [updatingPlugin, setUpdatingPlugin] = useState(false)
|
|
58
101
|
const [error, setError] = useState('')
|
|
59
102
|
const [notice, setNotice] = useState('')
|
|
60
103
|
const [toolQuery, setToolQuery] = useState('')
|
|
@@ -65,6 +108,7 @@ function apply(ctx) {
|
|
|
65
108
|
const [skillGroup, setSkillGroup] = useState('global')
|
|
66
109
|
const [skillSource, setSkillSource] = useState('skills.sh')
|
|
67
110
|
const [discoverQuery, setDiscoverQuery] = useState('')
|
|
111
|
+
const [discoveryError, setDiscoveryError] = useState('')
|
|
68
112
|
const [results, setResults] = useState([])
|
|
69
113
|
const [target, setTarget] = useState('global')
|
|
70
114
|
const [searching, setSearching] = useState(false)
|
|
@@ -74,6 +118,8 @@ function apply(ctx) {
|
|
|
74
118
|
const feedbackTimer = useRef(null)
|
|
75
119
|
const refreshGeneration = useRef(0)
|
|
76
120
|
const searchSeq = useRef(0)
|
|
121
|
+
const updateInFlight = useRef(false)
|
|
122
|
+
const updateController = useRef(null)
|
|
77
123
|
const sessions = useSessions(state => state)
|
|
78
124
|
const activeSession = Object.values(sessions.byId).find(session => (session.retainedBy?.mainView ?? 0) > 0)?.id
|
|
79
125
|
const [recordSession, setRecordSession] = useState(undefined)
|
|
@@ -99,7 +145,17 @@ function apply(ctx) {
|
|
|
99
145
|
}, [sessionId])
|
|
100
146
|
|
|
101
147
|
useEffect(() => { load() }, [load])
|
|
102
|
-
useEffect(() =>
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
let active = true
|
|
150
|
+
request('plugin-version').then(local => checkMarketUpdate(local.source, local.version).then(result => result || local))
|
|
151
|
+
.then(result => { if (active && result.status !== 'unavailable') setPluginVersion(result) }).catch(() => {})
|
|
152
|
+
return () => { active = false }
|
|
153
|
+
}, [])
|
|
154
|
+
useEffect(() => () => {
|
|
155
|
+
seq.current++; searchSeq.current++; refreshGeneration.current++
|
|
156
|
+
updateController.current?.abort()
|
|
157
|
+
clearTimeout(debounce.current); clearTimeout(refreshTimer.current); clearTimeout(feedbackTimer.current)
|
|
158
|
+
}, [])
|
|
103
159
|
|
|
104
160
|
const refresh = useCallback((selection = {}, value = draft) => {
|
|
105
161
|
clearTimeout(refreshTimer.current)
|
|
@@ -115,16 +171,85 @@ function apply(ctx) {
|
|
|
115
171
|
setRefreshStatus('正在刷新能力清单…')
|
|
116
172
|
setError('')
|
|
117
173
|
const succeeded = await load({ presetId: data.presetId, workspaceId: data.workspaceId, ...(draft ? { draft } : {}) }, true)
|
|
174
|
+
let versionCheck = '插件版本检查暂不可用'
|
|
175
|
+
try {
|
|
176
|
+
const localVersion = await request('plugin-version')
|
|
177
|
+
const nextVersion = await checkMarketUpdate(localVersion.source, localVersion.version) || localVersion
|
|
178
|
+
if (generation === refreshGeneration.current && nextVersion.status !== 'unavailable') setPluginVersion(nextVersion)
|
|
179
|
+
versionCheck = nextVersion.status === 'checked'
|
|
180
|
+
? '插件版本检查完成'
|
|
181
|
+
: nextVersion.status === 'unsupported'
|
|
182
|
+
? '插件来源暂不支持版本检查'
|
|
183
|
+
: nextVersion.status === 'unavailable'
|
|
184
|
+
? '插件版本检查暂不可用'
|
|
185
|
+
: '插件版本状态已刷新'
|
|
186
|
+
} catch {
|
|
187
|
+
// Keep the last successful version result if local source checking also fails.
|
|
188
|
+
}
|
|
118
189
|
if (generation !== refreshGeneration.current) return
|
|
119
190
|
setRefreshing(false)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return
|
|
123
|
-
}
|
|
124
|
-
setRefreshStatus(succeeded ? '能力清单已刷新' : '刷新失败')
|
|
191
|
+
const inventoryCheck = succeeded === true ? '能力清单已刷新' : succeeded === false ? '能力清单刷新失败' : '能力清单刷新状态已变化'
|
|
192
|
+
setRefreshStatus(`${inventoryCheck};${versionCheck}`)
|
|
125
193
|
feedbackTimer.current = setTimeout(() => setRefreshStatus(''), 1800)
|
|
126
194
|
}
|
|
127
195
|
|
|
196
|
+
async function updatePlugin() {
|
|
197
|
+
if (!pluginVersion.market) { ctx.pluginNavigation.openBundle(PACKAGE_NAME); return }
|
|
198
|
+
if (updateInFlight.current) return
|
|
199
|
+
updateInFlight.current = true
|
|
200
|
+
const controller = new AbortController()
|
|
201
|
+
updateController.current = controller
|
|
202
|
+
setUpdatingPlugin(true)
|
|
203
|
+
setUpdateFallback(false)
|
|
204
|
+
setUpdateProgress('正在通过插件市场更新…')
|
|
205
|
+
try {
|
|
206
|
+
const localVersion = await request('plugin-version', {}, controller.signal)
|
|
207
|
+
const verifiedMarketVersion = await checkMarketUpdate(localVersion.source, localVersion.version, controller.signal)
|
|
208
|
+
if (controller.signal.aborted) return
|
|
209
|
+
if (!verifiedMarketVersion?.market || verifiedMarketVersion.source !== localVersion.source) {
|
|
210
|
+
ctx.pluginNavigation.openBundle(PACKAGE_NAME); setUpdateProgress('插件市场来源校验未通过,已打开 DSH 插件管理器'); return
|
|
211
|
+
}
|
|
212
|
+
if (!verifiedMarketVersion.update) {
|
|
213
|
+
setPluginVersion(verifiedMarketVersion)
|
|
214
|
+
setUpdateProgress('插件已是最新版本')
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
const response = await fetch(MARKET_UPDATES_PATH, { method: 'POST', credentials: 'same-origin',
|
|
218
|
+
headers: { 'content-type': 'application/json' }, body: JSON.stringify({ packageName: PACKAGE_NAME }), signal: controller.signal })
|
|
219
|
+
if (!response.ok) throw new Error(`更新请求失败 (${response.status})`)
|
|
220
|
+
const { operationId } = await response.json()
|
|
221
|
+
if (!operationId) throw new Error('更新接口未返回操作编号')
|
|
222
|
+
for (let attempt = 0; attempt < 300; attempt++) {
|
|
223
|
+
const progress = await fetch(`${MARKET_OPERATIONS_PATH}?operationId=${encodeURIComponent(operationId)}`, { credentials: 'same-origin', signal: controller.signal })
|
|
224
|
+
if (!progress.ok) throw new Error(`读取更新进度失败 (${progress.status})`)
|
|
225
|
+
const operation = await progress.json()
|
|
226
|
+
const state = operation.operation || operation
|
|
227
|
+
setUpdateProgress(state.message || state.step || state.status || '正在更新…')
|
|
228
|
+
if (['succeeded', 'failed', 'cancelled', 'rolled-back'].includes(state.status)) {
|
|
229
|
+
if (state.status === 'rolled-back') {
|
|
230
|
+
setUpdateProgress(state.message || '更新失败,已回滚到更新前版本')
|
|
231
|
+
setUpdateFallback(true)
|
|
232
|
+
return
|
|
233
|
+
}
|
|
234
|
+
if (state.status === 'failed' || state.status === 'cancelled') throw new Error(state.message || '更新未完成')
|
|
235
|
+
if (state.installedVersion) setPluginVersion({ version: state.installedVersion, status: 'checked', source: pluginVersion.source })
|
|
236
|
+
setUpdateProgress(state.restartRequired ? '更新完成,请重启 DSH' : '更新完成')
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
240
|
+
}
|
|
241
|
+
throw new Error('等待更新结果超时,请在插件市场已安装页面查看状态')
|
|
242
|
+
} catch (error) {
|
|
243
|
+
if (controller.signal.aborted) return
|
|
244
|
+
setUpdateProgress(error.message || '市场更新不可用,请在 DSH 插件管理器中更新')
|
|
245
|
+
setUpdateFallback(true)
|
|
246
|
+
} finally {
|
|
247
|
+
updateInFlight.current = false
|
|
248
|
+
if (updateController.current === controller) updateController.current = null
|
|
249
|
+
if (!controller.signal.aborted) setUpdatingPlugin(false)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
128
253
|
const changed = JSON.stringify(draft) !== JSON.stringify(savedPolicy || {})
|
|
129
254
|
const toggle = (kind, item) => {
|
|
130
255
|
if (!item.available || item.fixed) return
|
|
@@ -160,25 +285,26 @@ function apply(ctx) {
|
|
|
160
285
|
|
|
161
286
|
const search = useCallback((query, source = skillSource) => {
|
|
162
287
|
clearTimeout(debounce.current)
|
|
163
|
-
|
|
288
|
+
setDiscoveryError('')
|
|
164
289
|
const requestId = ++searchSeq.current
|
|
290
|
+
if (!query.trim()) { setResults([]); setSearching(false); return }
|
|
165
291
|
setSearching(true)
|
|
166
292
|
debounce.current = setTimeout(async () => {
|
|
167
293
|
try {
|
|
168
294
|
const result = await request('search', { source, query: query.trim() })
|
|
169
295
|
if (requestId === searchSeq.current) setResults(result.results || [])
|
|
170
|
-
} catch (err) { if (requestId === searchSeq.current)
|
|
296
|
+
} catch (err) { if (requestId === searchSeq.current) setDiscoveryError(err.message || String(err)) }
|
|
171
297
|
finally { if (requestId === searchSeq.current) setSearching(false) }
|
|
172
298
|
}, 320)
|
|
173
299
|
}, [skillSource])
|
|
174
300
|
|
|
175
301
|
async function importSkill(selection) {
|
|
176
|
-
setBusy(true); setError(''); setNotice('')
|
|
302
|
+
setBusy(true); setError(''); setDiscoveryError(''); setNotice('')
|
|
177
303
|
try {
|
|
178
304
|
const result = await request('import', { selection, workspaceId: data?.workspaceId, target })
|
|
179
305
|
setNotice(`已导入 ${result.name || selection.name || selection.id || '技能'}`)
|
|
180
306
|
await load({ presetId: data?.presetId, workspaceId: data?.workspaceId, ...(changed ? { draft } : {}) })
|
|
181
|
-
} catch (err) {
|
|
307
|
+
} catch (err) { setDiscoveryError(err.message || String(err)) }
|
|
182
308
|
finally { setBusy(false) }
|
|
183
309
|
}
|
|
184
310
|
|
|
@@ -195,15 +321,37 @@ function apply(ctx) {
|
|
|
195
321
|
const n = value => Number(value || 0).toLocaleString('zh-CN')
|
|
196
322
|
const labelGroup = value => ({ builtin: '内置工具', plugin: '插件工具', mcp: 'MCP 工具', unknown: '其他来源', global: '全局技能', workspace: '工作区技能' })[value] || value || '其他'
|
|
197
323
|
const delta = value => `${value > 0 ? '+' : ''}${n(value)}`
|
|
324
|
+
const tokenSum = keys => (visibleBudget?.breakdown || []).reduce((total, row) => total + (keys.includes(row.key) ? row.tokens : 0), 0)
|
|
325
|
+
const actualCounts = visibleBudget?.categoryCounts
|
|
326
|
+
const categoryCounts = actualCounts || data.budget?.categoryCounts || { tool: 0, mcp: 0, skill: 0 }
|
|
327
|
+
const actualCategoryCountsMissing = showActual && data.actual && (!actualCounts ||
|
|
328
|
+
Number(actualCounts.tool || 0) + Number(actualCounts.mcp || 0) + Number(actualCounts.skill || 0) === 0) && (visibleBudget?.count > 0)
|
|
329
|
+
const countLabel = key => actualCategoryCountsMissing ? '—' : n(categoryCounts[key])
|
|
198
330
|
const fee = value => new Intl.NumberFormat('zh-CN', { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 4, signDisplay: 'exceptZero' }).format(value)
|
|
199
331
|
const fees = data.pricing?.minimum == null ? data.pricing?.status || '暂无适用费率'
|
|
200
332
|
: h('span', { className: 'dcm-fees' },
|
|
201
333
|
data.pricing.minimum === data.pricing.maximum ? fee(data.pricing.minimum) : `${fee(data.pricing.minimum)} ~ ${fee(data.pricing.maximum)}`,
|
|
202
334
|
h('small', { className: 'dcm-currency-code' }, data.pricing.currency))
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
335
|
+
const validGitHubRepository = value => /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})\/[A-Za-z0-9._-]{1,100}$/.test(value)
|
|
336
|
+
|| /^https:\/\/github\.com\/[A-Za-z0-9-]+\/[A-Za-z0-9._-]+(?:\/tree\/.+)?\/?$/.test(value)
|
|
337
|
+
const discoveryFeedback = discoveryError && h('div', { className: 'dcm-discovery-error', role: 'alert' },
|
|
338
|
+
h('span', null, discoveryError),
|
|
339
|
+
h('button', { type: 'button', onClick: () => setDiscoveryError(''), 'aria-label': '关闭错误提示', title: '关闭错误提示' }, '×'))
|
|
340
|
+
function searchDiscovery(value, source = skillSource) {
|
|
341
|
+
if (source === 'github' && value.trim() && !validGitHubRepository(value.trim())) {
|
|
342
|
+
clearTimeout(debounce.current)
|
|
343
|
+
searchSeq.current++
|
|
344
|
+
setResults([])
|
|
345
|
+
setSearching(false)
|
|
346
|
+
setDiscoveryError('请输入精确的 GitHub owner/repo 或公开仓库 URL')
|
|
347
|
+
return
|
|
348
|
+
}
|
|
349
|
+
search(value, source)
|
|
350
|
+
}
|
|
351
|
+
const heading = h('header', { className: 'dcm-head' },
|
|
352
|
+
h('div', { className: 'dcm-heading-main' },
|
|
353
|
+
h('h1', null, 'Agent 能力管理'),
|
|
354
|
+
h('div', { className: 'dcm-controls' },
|
|
207
355
|
h('label', null, 'Agent 预设',
|
|
208
356
|
h('select', {
|
|
209
357
|
value: data.presetId || '',
|
|
@@ -216,14 +364,24 @@ function apply(ctx) {
|
|
|
216
364
|
value: data.workspaceId || '',
|
|
217
365
|
onChange: e => load({ presetId: data.presetId, workspaceId: e.target.value, ...(changed ? { draft } : {}) }),
|
|
218
366
|
}, h('option', { value: '' }, '无工作区'), ...(data.workspaces || []).map(w => h('option', { key: w.id, value: w.id }, w.name)))))),
|
|
219
|
-
|
|
220
|
-
|
|
367
|
+
h('div', { className: 'dcm-heading-tools' },
|
|
368
|
+
h('a', { className: 'dcm-repository', href: 'https://github.com/crocketc/dsh-capability-manager', target: '_blank', rel: 'noreferrer', title: '打开 Agent 能力管理 GitHub 仓库', 'aria-label': '打开 Agent 能力管理 GitHub 仓库' },
|
|
369
|
+
h('svg', { viewBox: '0 0 24 24', 'aria-hidden': true }, h('path', { fill: 'currentColor', d: 'M12 .5C5.65.5.5 5.75.5 12.23c0 5.18 3.3 9.57 7.88 11.12.58.11.79-.26.79-.57v-2.17c-3.2.71-3.87-1.39-3.87-1.39-.53-1.36-1.28-1.72-1.28-1.72-1.05-.74.08-.73.08-.73 1.16.08 1.77 1.22 1.77 1.22 1.03 1.8 2.7 1.28 3.36.98.1-.76.4-1.28.73-1.57-2.55-.3-5.23-1.3-5.23-5.8 0-1.28.45-2.32 1.2-3.14-.12-.3-.52-1.49.11-3.1 0 0 .98-.32 3.2 1.2a10.85 10.85 0 0 1 5.82 0c2.22-1.52 3.2-1.2 3.2-1.2.63 1.61.23 2.8.12 3.1.75.82 1.2 1.86 1.2 3.14 0 4.51-2.69 5.5-5.26 5.79.41.36.78 1.06.78 2.14v3.18c0 .31.21.69.8.57A11.74 11.74 0 0 0 23.5 12.23C23.5 5.75 18.35.5 12 .5z' }))),
|
|
370
|
+
pluginVersion.update
|
|
371
|
+
? h('button', { type: 'button', className: 'dcm-plugin-update', onClick: updatePlugin, disabled: updatingPlugin, title: `更新来源:${pluginVersion.source || 'npm'}` }, updatingPlugin ? '正在更新…' : `新版本 ↑ ${pluginVersion.update}`)
|
|
372
|
+
: h('span', { className: 'dcm-plugin-version', title: pluginVersion.detail || (pluginVersion.status === 'unsupported'
|
|
373
|
+
? 'Git 来源暂时无法精确检查更新'
|
|
374
|
+
: `当前安装版本${pluginVersion.status === 'unavailable' ? ';暂时无法检查更新' : ''}`) },
|
|
375
|
+
`v${pluginVersion.version || PLUGIN_VERSION}${pluginVersion.status === 'unsupported' ? ' · 无法精确检查' : ''}`),
|
|
376
|
+
h('div', { className: 'dcm-actions' },
|
|
377
|
+
(refreshStatus || updateProgress) && h('small', { className: 'dcm-action-status', 'aria-live': 'polite' }, updateProgress || refreshStatus),
|
|
378
|
+
updateFallback && h('button', { type: 'button', className: 'dcm-button', onClick: () => ctx.pluginNavigation.openBundle(PACKAGE_NAME) }, '打开 DSH 插件管理器'),
|
|
221
379
|
h('button', {
|
|
222
380
|
type: 'button', className: `dcm-refresh ${refreshing ? 'is-refreshing' : ''}`,
|
|
223
381
|
disabled: refreshing || busy, onClick: refreshInventory,
|
|
224
382
|
title: '刷新能力清单', 'aria-label': '刷新能力清单',
|
|
225
383
|
}, h('span', { 'aria-hidden': true }, '↻')),
|
|
226
|
-
h('button', { className: 'dcm-primary', disabled: !changed || busy || refreshing, onClick: save }, busy ? '处理中…' : '保存预设')))
|
|
384
|
+
h('button', { className: 'dcm-primary', disabled: !changed || busy || refreshing, onClick: save }, busy ? '处理中…' : '保存预设'))))
|
|
227
385
|
|
|
228
386
|
const displayedActual = showActual && data.actual
|
|
229
387
|
const sessionOptions = sessions.ids.map(id => sessions.byId[id]).filter(row => row && !row.parentId)
|
|
@@ -241,10 +399,15 @@ function apply(ctx) {
|
|
|
241
399
|
title('整体统计', '月度费用按每月 1,500 次模型请求、未命中缓存的输入费率估算。'),
|
|
242
400
|
h('span', null, `计价模型 ${data.pricing?.model || '—'} · DSH 默认`)),
|
|
243
401
|
h('div', { className: 'dcm-metrics' },
|
|
244
|
-
metric('
|
|
245
|
-
metric('
|
|
246
|
-
metric('
|
|
247
|
-
|
|
402
|
+
metric('工具', `${countLabel('tool')} 项`, `≈ ${n(tokenSum(['builtin-tools', 'plugin-tools', 'unknown-tools', 'ptc-builtin-tools', 'ptc-plugin-tools', 'ptc-unknown-tools', 'run-code']))} tok`),
|
|
403
|
+
metric('MCP 工具', `${countLabel('mcp')} 项`, `≈ ${n(tokenSum(['mcp-tools', 'ptc-mcp-tools']))} tok`),
|
|
404
|
+
metric('技能', `${countLabel('skill')} 项`, `≈ ${n(tokenSum(['skill-catalog', 'workspace-skill-catalog']))} tok`),
|
|
405
|
+
h('div', { className: 'dcm-metric dcm-agent-summary' },
|
|
406
|
+
h('small', null, 'Agent 能力小计'),
|
|
407
|
+
h('strong', null, `${n(visibleBudget?.capability)} tok`),
|
|
408
|
+
h('small', null, `${delta(data.budget.capability - data.savedBudget.capability)} tok 较已保存`),
|
|
409
|
+
h('strong', { className: 'dcm-summary-total' }, `初始注入总量 ${n(visibleBudget?.total)} tok`)),
|
|
410
|
+
metric('月度输入费用变化', fees, '较已保存 · 每月 1,500 次请求'))),
|
|
248
411
|
h('article', { className: 'dcm-card dcm-injection' },
|
|
249
412
|
h('div', { className: 'dcm-card-title' },
|
|
250
413
|
title(displayedActual ? '首请求注入明细 · 实际' : '首请求注入明细 · 估算', '按注入内容估算 token。技能按目录条目计量。预算排除用户消息、会话历史和工作区指令。'),
|
|
@@ -276,7 +439,7 @@ function apply(ctx) {
|
|
|
276
439
|
const skillPanel = h('section', { className: 'dcm-card dcm-list' }, h('div', { className: 'dcm-listhead' }, h('h2', null, '技能'),
|
|
277
440
|
tabs([['global', '全局技能'], ['workspace', '工作区技能'], ['discover', '发现技能']], skillGroup, setSkillGroup),
|
|
278
441
|
skillGroup !== 'discover' && h('span', null, `${skillTab.filter(x => x.enabled).length} / ${skillTab.length} 已启用`)),
|
|
279
|
-
skillGroup === 'discover' ? h('div', { className: 'dcm-discover' }, h('div', { className: 'dcm-filter' }, h('select', { value: skillSource, onChange: e => { setSkillSource(e.target.value);
|
|
442
|
+
skillGroup === 'discover' ? h('div', { className: 'dcm-discover' }, h('div', { className: 'dcm-filter' }, h('select', { value: skillSource, onChange: e => { setSkillSource(e.target.value); setDiscoveryError(''); searchDiscovery(discoverQuery, e.target.value) }, 'aria-label': '发现技能来源' }, h('option', { value: 'skills.sh' }, 'skills.sh'), h('option', { value: 'github' }, 'GitHub 仓库')), h('input', { type: 'search', value: discoverQuery, placeholder: skillSource === 'github' ? 'owner/repo 或公开 GitHub 仓库 URL' : '搜索技能关键词', onChange: e => { setDiscoverQuery(e.target.value); searchDiscovery(e.target.value) }, 'aria-label': skillSource === 'github' ? '输入 GitHub 仓库' : '搜索技能关键词' })), discoveryFeedback, h('div', { className: 'dcm-target' }, h('span', null, '导入到'), h('select', { value: target, onChange: e => setTarget(e.target.value) }, h('option', { value: 'global' }, 'DSH 全局技能'), h('option', { value: 'workspace', disabled: !data.workspaceId }, '当前工作区技能'))), h('div', { className: 'dcm-scroll' }, searching ? empty('正在搜索…') : results.length ? results.map(row => h('div', { className: 'dcm-row', key: row.id }, h('div', { className: 'dcm-row-info' }, h('strong', null, row.name), h('small', null, row.description || ''), h('small', null, `${row.source || skillSource} · ${row.repository || ''}${row.path ? `/${row.path}` : ''}`)), h('button', { className: 'dcm-button', disabled: busy, onClick: () => importSkill(row) }, '导入'))) : empty(skillSource === 'github' ? '输入公开 GitHub 仓库查看可导入技能' : '输入关键词搜索技能目录')))
|
|
280
443
|
: h(React.Fragment, null, h('div', { className: 'dcm-filter' }, h('input', { type: 'search', value: skillQuery, placeholder: '搜索名称、说明或来源', onChange: e => setSkillQuery(e.target.value), 'aria-label': '搜索技能' }), statusFilter(skillStatus, setSkillStatus)), h('div', { className: 'dcm-scroll', role: 'region', 'aria-label': '技能列表' }, skills.length ? skills.map(row => itemRow(row, 'skill')) : empty('没有符合条件的技能'))))
|
|
281
444
|
|
|
282
445
|
return h('main', { className: 'dcm' }, h(Style), heading, error ? h('div', { className: 'dcm-error', role: 'alert' }, error) : null, notice ? h('div', { className: 'dcm-notice', role: 'status' }, notice) : null,
|
|
@@ -320,7 +483,9 @@ function apply(ctx) {
|
|
|
320
483
|
function Style() {
|
|
321
484
|
return h('style', null, `.dcm{--ink:#17243a;--muted:#68768a;--line:#dce3ed;--accent:#2867c8;color:var(--ink);font:14px/1.4 Inter,"Segoe UI",sans-serif;height:100%;min-height:0;padding:14px 16px;display:flex;flex-direction:column;overflow:auto;container-type:inline-size;background:#f3f6fa}
|
|
322
485
|
.dcm *{box-sizing:border-box}
|
|
323
|
-
.dcm-head{display:flex;align-items:center;justify-content:space-between;gap:30px;margin-bottom:
|
|
486
|
+
.dcm-head{display:flex;align-items:center;justify-content:space-between;gap:30px;margin-bottom:8px;min-width:0}
|
|
487
|
+
.dcm-heading-main{display:flex;align-items:center;gap:30px;min-width:0;flex:1}
|
|
488
|
+
.dcm-heading-tools{display:flex;align-items:center;justify-content:flex-end;gap:8px;flex:none;min-width:0}
|
|
324
489
|
.dcm h1{font-size:20px;margin:0;white-space:nowrap}
|
|
325
490
|
.dcm h2{font-size:15px;margin:0}
|
|
326
491
|
.dcm-muted{color:var(--muted);font-size:11px;margin:4px 0 0}
|
|
@@ -328,27 +493,38 @@ function apply(ctx) {
|
|
|
328
493
|
.dcm-controls label{display:grid;gap:3px;font-size:10px;color:var(--muted)}
|
|
329
494
|
.dcm select,.dcm input{min-width:125px;border:1px solid #bbc9da;border-radius:7px;padding:6px 8px;background:white;color:var(--ink);font:inherit}
|
|
330
495
|
.dcm button{font:inherit;cursor:pointer}
|
|
331
|
-
.dcm-actions{display:flex;align-items:center;justify-content:flex-end;gap:
|
|
496
|
+
.dcm-actions{display:flex;align-items:center;justify-content:flex-end;gap:7px;min-height:34px}
|
|
332
497
|
.dcm-action-status{margin-right:auto;color:var(--muted);font-size:11px}
|
|
498
|
+
.dcm-repository{display:grid;place-items:center;width:27px;height:27px;border-radius:50%;background:#eef2f7;color:#536276}
|
|
499
|
+
.dcm-repository:hover,.dcm-repository:focus-visible{background:#e3ecfa;color:#225fbd}
|
|
500
|
+
.dcm-repository svg{width:16px;height:16px;display:block}
|
|
501
|
+
.dcm-plugin-version{font-size:11px;color:#626d7c;white-space:nowrap}
|
|
502
|
+
.dcm-plugin-update{border:1px solid #d5d8de;border-radius:999px;background:#fff;color:#6e747e;padding:5px 10px;font-size:11px;white-space:nowrap}
|
|
503
|
+
.dcm-plugin-update:hover,.dcm-plugin-update:focus-visible{background:#f4f7fb;color:#245bb1}
|
|
333
504
|
.dcm-primary,.dcm-button{border:1px solid #c7d2e1;border-radius:7px;padding:6px 11px;background:#fff;color:#24344b}
|
|
334
505
|
.dcm-primary{background:#2867c8;border-color:#2867c8;color:white;font-weight:600}
|
|
335
506
|
.dcm button:disabled{opacity:.48;cursor:not-allowed}
|
|
336
507
|
.dcm-refresh{width:30px;height:30px;display:grid;place-items:center;border:1px solid #c7d2e1;border-radius:7px;background:white;color:#24344b;font-size:19px;line-height:1}
|
|
337
508
|
.dcm-refresh.is-refreshing span{animation:dcm-spin .8s linear infinite}
|
|
338
509
|
@keyframes dcm-spin{to{transform:rotate(360deg)}}
|
|
339
|
-
.dcm-dashboard{flex:1;min-height:0;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:
|
|
510
|
+
.dcm-dashboard{flex:1;min-height:0;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:minmax(0,1fr) minmax(0,2fr);gap:8px}
|
|
340
511
|
.dcm-summary{grid-column:1/-1;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;min-height:0;align-items:stretch}
|
|
341
512
|
.dcm-card{background:#fff;border:1px solid var(--line);border-radius:11px;box-shadow:0 2px 8px #24395408;min-width:0}
|
|
342
513
|
.dcm-summary>.dcm-card{padding:9px 11px;min-height:0;overflow:hidden}
|
|
514
|
+
.dcm-summary>.dcm-card:first-child{display:flex;flex-direction:column}
|
|
343
515
|
.dcm-card-title,.dcm-listhead{display:flex;align-items:center;justify-content:space-between;gap:7px;min-width:0}
|
|
344
516
|
.dcm-card-title h2{margin-right:auto;white-space:nowrap}
|
|
345
517
|
.dcm-card-title>span,.dcm-listhead>span{font-size:10px;color:var(--muted)}
|
|
346
518
|
.dcm-card-title select,.dcm-card-title .dcm-button{font-size:10px;padding:3px 5px;min-width:0;max-width:110px}
|
|
347
519
|
.dcm-help{margin-left:4px;border:0;border-radius:50%;height:15px;width:15px;padding:0;background:#e7edf4;color:#58697e;font-size:10px!important}
|
|
348
|
-
.dcm-metrics{display:grid;grid-template-columns:repeat(
|
|
349
|
-
.dcm-metric{padding:6px 7px;border:1px solid var(--line);border-radius:8px;background:#f8fafc;min-width:0}
|
|
350
|
-
.dcm-metric
|
|
351
|
-
.dcm-metric
|
|
520
|
+
.dcm-metrics{display:grid;flex:1;min-height:0;grid-template-columns:repeat(6,minmax(0,1fr));grid-template-rows:repeat(2,minmax(0,1fr));gap:6px;margin:7px 0 0}
|
|
521
|
+
.dcm-metric{grid-column:span 2;padding:6px 7px;border:1px solid var(--line);border-radius:8px;background:#f8fafc;min-width:0;overflow:hidden}
|
|
522
|
+
.dcm-metric:nth-child(n+4){grid-column:span 3}
|
|
523
|
+
.dcm-metric small{display:block;color:var(--muted);font-size:clamp(9px,1.1vh,13px);line-height:1.2;overflow-wrap:anywhere}
|
|
524
|
+
.dcm-metric strong{display:block;font-size:clamp(14px,2.4vh,24px);line-height:1.1;margin:3px 0;overflow-wrap:anywhere}
|
|
525
|
+
.dcm-agent-summary{display:flex;flex-direction:column;justify-content:center;gap:clamp(0px,.35vh,3px)}
|
|
526
|
+
.dcm-agent-summary strong{font-weight:700}
|
|
527
|
+
.dcm-agent-summary .dcm-summary-total{padding-top:2px;border-top:1px solid var(--line);color:var(--ink);font-size:clamp(14px,2.4vh,24px);font-weight:700}
|
|
352
528
|
.dcm-fees{white-space:nowrap;font-size:.9em}
|
|
353
529
|
.dcm-currency-code{font-size:.68em;color:var(--muted);font-weight:500;margin-left:4px}
|
|
354
530
|
.dcm-injection{display:flex;flex-direction:column;min-height:0;contain:size}
|
|
@@ -389,13 +565,15 @@ function apply(ctx) {
|
|
|
389
565
|
.dcm-tabs button{border:0;border-bottom:2px solid transparent;background:none;color:var(--muted);padding:4px 1px;white-space:nowrap;font-size:11px}
|
|
390
566
|
.dcm-tabs button.active{color:var(--accent);border-color:var(--accent);font-weight:600}
|
|
391
567
|
.dcm-discover{display:flex;flex:1;min-height:0;flex-direction:column}
|
|
568
|
+
.dcm-discovery-error{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;padding:7px 9px;border:1px solid #f0c4bf;border-radius:7px;background:#fff0ee;color:#9c2f26;font-size:11px;line-height:1.35}
|
|
569
|
+
.dcm-discovery-error button{flex:none;border:0;background:transparent;color:inherit;font-size:16px;line-height:1;cursor:pointer}
|
|
392
570
|
.dcm-target{display:flex;align-items:center;gap:8px;padding:5px 9px;color:var(--muted);font-size:11px}
|
|
393
571
|
.dcm-target select{padding:4px;min-width:0}
|
|
394
572
|
.dcm-empty{padding:16px 4px;color:var(--muted);font-size:11px}
|
|
395
573
|
.dcm-error,.dcm-notice{padding:7px 10px;margin:0 0 8px;border-radius:7px;font-size:11px}
|
|
396
574
|
.dcm-error{color:#9c2f26;background:#fff0ee;border:1px solid #f0c4bf}
|
|
397
575
|
.dcm-notice{color:#24623c;background:#effaf2;border:1px solid #c7e7ce}
|
|
398
|
-
@media(max-width:850px){.dcm{padding:12px}.dcm-head{align-items:
|
|
576
|
+
@media(max-width:850px){.dcm{padding:12px}.dcm-head{align-items:stretch;flex-direction:column;gap:7px}.dcm-heading-main{justify-content:space-between;gap:14px;flex-wrap:wrap}.dcm-heading-tools{justify-content:flex-end;flex-wrap:wrap}.dcm-controls{justify-content:flex-start}.dcm-dashboard{display:flex;flex-direction:column;min-height:0}.dcm-summary{grid-template-columns:1fr}.dcm-summary>.dcm-card{min-height:140px}.dcm-injection{min-height:175px;contain:none}.dcm-metrics{grid-template-columns:repeat(6,minmax(0,1fr));grid-template-rows:repeat(2,minmax(64px,auto))}.dcm-metric{grid-column:span 2}.dcm-metric:nth-child(n+4){grid-column:span 3}.dcm-list{height:42vh;min-height:240px;flex:none}}
|
|
399
577
|
@container (max-width:640px){.dcm-dashboard{display:flex;flex-direction:column}.dcm-summary{grid-template-columns:1fr}.dcm-list{min-height:230px;flex:none}.dcm-breakdown{gap:0 8px}}
|
|
400
578
|
`)
|
|
401
579
|
}
|
package/src/index.js
CHANGED
|
@@ -7,9 +7,10 @@ import { applyScopedToolVisibility, applySkillVisibility, groupForDefinition, in
|
|
|
7
7
|
import { quoteMonthly } from './pricing.js'
|
|
8
8
|
import { formatBudget, readInitial, sdkDeclarations } from './accounting.js'
|
|
9
9
|
import { importSkill, searchSkills } from './discovery.js'
|
|
10
|
+
import { formatGitHubComparison } from './plugin-update.js'
|
|
10
11
|
|
|
11
12
|
export const name = 'dsh-capability-manager'
|
|
12
|
-
export const inject = ['connection', 'agentPresets', 'agents', 'workspaceRegistry', 'skills', 'tools', 'systemPrompt', 'agentDefaultModel', 'llm']
|
|
13
|
+
export const inject = ['connection', 'agentPresets', 'agents', 'workspaceRegistry', 'skills', 'tools', 'systemPrompt', 'agentDefaultModel', 'llm', 'pluginManager']
|
|
13
14
|
|
|
14
15
|
const presetNames = { standard: '标准模式', ptc: 'PTC 模式', minimal: '极简模式', cordis: '创造模式', creative: '创造模式' }
|
|
15
16
|
const globalHome = () => resolve(process.env.DSH_HOME?.trim() || join(homedir(), '.dsh'))
|
|
@@ -43,6 +44,15 @@ function validatedPolicy(draft, saved, tools, skills) {
|
|
|
43
44
|
return { ...clean, importedSkills: saved.importedSkills }
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
function categoryCountsFor(snapshot) {
|
|
48
|
+
const enabledTools = snapshot.tools.filter(row => row.enabled);
|
|
49
|
+
return {
|
|
50
|
+
tool: enabledTools.filter(row => row.group !== 'mcp').length,
|
|
51
|
+
mcp: enabledTools.filter(row => row.group === 'mcp').length,
|
|
52
|
+
skill: snapshot.skills.filter(row => row.enabled).length,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
export async function apply(ctx) {
|
|
47
57
|
const home = globalHome()
|
|
48
58
|
const store = await openPolicyStore(join(home, 'dsh-capability-manager.json'))
|
|
@@ -212,8 +222,8 @@ export async function apply(ctx) {
|
|
|
212
222
|
if (save && !body.draft) throw makeError('缺少待保存的预设开关')
|
|
213
223
|
const current = body.draft ? await preview(ctx, facts, draft, args, sdkDeclarations) : baseline
|
|
214
224
|
if (save) await store.save(presetId, draft)
|
|
215
|
-
const budget = formatBudget(current.measured, current.count)
|
|
216
|
-
const savedBudget = save ? budget : formatBudget(baseline.measured, baseline.count)
|
|
225
|
+
const budget = formatBudget({ ...current.measured, categoryCounts: categoryCountsFor(current) }, current.count)
|
|
226
|
+
const savedBudget = save ? budget : formatBudget({ ...baseline.measured, categoryCounts: categoryCountsFor(baseline) }, baseline.count)
|
|
217
227
|
let pricing
|
|
218
228
|
try {
|
|
219
229
|
const present = !!model && ctx.llm.listProviders().some(provider => provider.id === model.provider)
|
|
@@ -228,6 +238,36 @@ export async function apply(ctx) {
|
|
|
228
238
|
})
|
|
229
239
|
}
|
|
230
240
|
|
|
241
|
+
async function pluginVersion() {
|
|
242
|
+
const packageName = '@crocketc/dsh-capability-manager'
|
|
243
|
+
const bundle = (await ctx.pluginManager.listBundles()).find(row => row.name === packageName)
|
|
244
|
+
if (!bundle) return { version: '0.3.0', status: 'unmanaged' }
|
|
245
|
+
if (bundle.update === 'registry') {
|
|
246
|
+
const listing = await ctx.pluginManager.listVersions(packageName)
|
|
247
|
+
if (listing.status !== 'listed') return { version: bundle.version, status: 'unavailable', source: 'npm' }
|
|
248
|
+
const update = listing.versions.find(row => row.bundle && !row.deprecated && !row.incompatible && !row.prerelease)
|
|
249
|
+
return { version: bundle.version, ...(update ? { update: update.version } : {}), status: 'checked', source: 'npm' }
|
|
250
|
+
}
|
|
251
|
+
if (bundle.update === 'git' && typeof bundle.source === 'string') {
|
|
252
|
+
const spec = bundle.source.replace(/^@[^@]+@/, '').replace(/^git\+/, '')
|
|
253
|
+
const match = spec.match(/^(?:github:|(?:https?|ssh):\/\/(?:git@)?github\.com\/)([A-Za-z0-9-]+)\/([A-Za-z0-9._-]+?)(?:\.git)?(?:[#?].*)?$/i)
|
|
254
|
+
if (!match) return { version: bundle.version, status: 'unsupported', source: 'git' }
|
|
255
|
+
const installed = spec.match(/[&#](?:commit=)?([0-9a-f]{40})(?=$|[&#])/i)?.[1]
|
|
256
|
+
if (!installed) return { version: bundle.version, status: 'unsupported', source: 'git' }
|
|
257
|
+
try {
|
|
258
|
+
const response = await fetch(`https://api.github.com/repos/${match[1]}/${match[2]}/compare/${installed}...HEAD`, {
|
|
259
|
+
headers: { accept: 'application/vnd.github+json', 'user-agent': 'dsh-capability-manager' },
|
|
260
|
+
})
|
|
261
|
+
if (!response.ok) return { version: bundle.version, status: 'unavailable', source: 'git' }
|
|
262
|
+
const comparison = await response.json()
|
|
263
|
+
return formatGitHubComparison(bundle.version, installed, comparison)
|
|
264
|
+
} catch {
|
|
265
|
+
return { version: bundle.version, status: 'unavailable', source: 'git' }
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return { version: bundle.version, status: bundle.update ?? 'unsupported' }
|
|
269
|
+
}
|
|
270
|
+
|
|
231
271
|
async function route(request) {
|
|
232
272
|
if (request.headers.get('x-dsh-capability-manager') !== '1' ||
|
|
233
273
|
!request.headers.get('content-type')?.startsWith('application/json')) {
|
|
@@ -240,6 +280,7 @@ export async function apply(ctx) {
|
|
|
240
280
|
try { body = JSON.parse(data) } catch { throw makeError('无效的 JSON 请求') }
|
|
241
281
|
if (!body || typeof body !== 'object') throw makeError('无效的请求数据')
|
|
242
282
|
if (body.action === 'state' || body.action === 'save') return Response.json(await state(body, body.action === 'save'))
|
|
283
|
+
if (body.action === 'plugin-version') return Response.json(await pluginVersion())
|
|
243
284
|
if (body.action === 'search') return Response.json({ results: await searchSkills(body.source, body.query) })
|
|
244
285
|
if (body.action === 'import') {
|
|
245
286
|
const workspace = body.target === 'workspace' && ctx.workspaceRegistry.get(body.workspaceId)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function formatGitHubComparison(version, installed, comparison) {
|
|
2
|
+
const detail = '比较的是 GitHub 仓库默认分支 HEAD;DSH profile 未保留原始分支或标签。'
|
|
3
|
+
if (comparison?.base_commit?.sha?.toLowerCase() !== installed.toLowerCase()) {
|
|
4
|
+
return { version, status: 'unavailable', source: 'git', detail }
|
|
5
|
+
}
|
|
6
|
+
if (comparison?.status === 'identical') return { version, status: 'checked', source: 'git', detail }
|
|
7
|
+
const latest = comparison?.head_commit?.sha
|
|
8
|
+
if (comparison?.status === 'ahead' && Number.isInteger(comparison.ahead_by) && comparison.ahead_by > 0 &&
|
|
9
|
+
typeof latest === 'string' && /^[0-9a-f]{40}$/i.test(latest)) {
|
|
10
|
+
return { version, update: latest.slice(0, 7), status: 'checked', source: 'git', detail }
|
|
11
|
+
}
|
|
12
|
+
return { version, status: 'unavailable', source: 'git', detail }
|
|
13
|
+
}
|