dsh-skill-harbor 0.5.2 → 0.5.3

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.
@@ -1,24 +1,25 @@
1
- /**
2
- * 技能港湾面板(客户端半)。
3
- *
4
- * 无框架依赖:DSH 的 slots 只要求返回 DOM 节点。用原生 DOM 避免把 React
5
- * 打进插件包,也避免跨 React 根复用组件的样式事故。
6
- */
7
- import { api, dict } from './api.js'
8
- import { FILE_STATE_LABEL } from './labels.js'
9
-
1
+ /**
2
+ * 技能港湾面板(客户端半)。
3
+ *
4
+ * 无框架依赖:DSH 的 slots 只要求返回 DOM 节点。用原生 DOM 避免把 React
5
+ * 打进插件包,也避免跨 React 根复用组件的样式事故。
6
+ */
7
+ import { api, dict } from './api.js'
8
+ import { FILE_STATE_LABEL } from './labels.js'
9
+
10
10
  const CSS_ID = 'dsh-skill-harbor-style'
11
11
 
12
- /* __STAR_INLINE_BEGIN__ — 手写内联 star 面板(v1→v2→v3 阶梯,_tools/star-row 计划)。
12
+ /* __STAR_INLINE_BEGIN__ — 手写内联 star 面板(v1→v2→v3→v4 阶梯,_tools/star-row 计划)。
13
13
  * 本仓浏览器半边是手写 JS/无 TS 构建,插不进 star-row-copy.ts,故内联等价实现
14
14
  * (沿用 dsh-preset-doctor 先例)。STAR_GEN / STAR_VERSION 由 _tools/star-row/ladder.mjs
15
- * 每次发版改写:v1 = 话术+★CTA+×隐藏;v2 = 一行页脚点过即收;v3 = 两行页脚「我已支持」才收。
15
+ * 每次发版改写:v1 = 话术+★CTA+×隐藏;v2 = 一行页脚点过即收;v3 = 两行页脚「我已支持」才收
16
+ * (冻结版见 gens/inline.star-panel.v3.js);v4 = 三动作描边胶囊 + v4.supported 键。
16
17
  * 契约由本仓 tests/star-panel.test.* 锁定(★/💬 跳转语义、写键、旧键不迁值、10 语)。 */
17
18
  (function () {
18
19
  var REPO_URL = "https://github.com/drscrewdriver/dsh-skill-harbor";
19
20
  var STAR_NS = "skill-harbor";
20
- var STAR_GEN = "v3"; /* ladder:gen */
21
- var STAR_VERSION = "0.5.1"; /* ladder:ver */
21
+ var STAR_GEN = "v4"; /* ladder:gen */
22
+ var STAR_VERSION = "0.5.3"; /* ladder:ver */
22
23
  var LANGS = ["zh", "en", "ja", "ko", "fr", "de", "it", "ru", "es", "pt"];
23
24
 
24
25
  // 三代共享:GitHub 单色 mark(octicon 轮廓,fill 随 currentColor)。
@@ -62,6 +63,7 @@ const CSS_ID = 'dsh-skill-harbor-style'
62
63
  var K_V1 = "dsh.star." + STAR_NS + ".dismissed";
63
64
  var K_V2 = "dsh.star." + STAR_NS + ".v2.dismissed";
64
65
  var K_V3 = "dsh.star." + STAR_NS + ".v3.supported";
66
+ var K_V4 = "dsh.star." + STAR_NS + ".v4.supported";
65
67
  function lsGet(k) { try { return localStorage.getItem(k); } catch (e) { return null; } }
66
68
  function lsSet(k) { try { localStorage.setItem(k, "1"); } catch (e) {} }
67
69
  function lsRm(k) { try { if (localStorage.getItem(k) !== null) localStorage.removeItem(k); } catch (e) {} }
@@ -90,6 +92,12 @@ const CSS_ID = 'dsh-skill-harbor-style'
90
92
  if (tag === "a" && href) { el.href = href; el.target = "_blank"; el.rel = "noopener noreferrer"; }
91
93
  el.textContent = text; return el;
92
94
  }
95
+ function footBtn(d, tag, text, href) {
96
+ var el = d.createElement(tag); el.className = "dsh-star-btn";
97
+ if (tag === "a" && href) { el.href = href; el.target = "_blank"; el.rel = "noopener noreferrer"; }
98
+ if (tag === "button") el.type = "button";
99
+ el.textContent = text; return el;
100
+ }
93
101
  function dot(d) { var x = d.createElement("span"); x.className = "dsh-star-dot"; x.textContent = "·"; return x; }
94
102
 
95
103
  function render(d) {
@@ -133,39 +141,43 @@ const CSS_ID = 'dsh-skill-harbor-style'
133
141
  st2.addEventListener("click", collapse2); is2.addEventListener("click", collapse2);
134
142
  return r2;
135
143
  }
136
- // v3
144
+ // v4(v3 结构 + 三动作描边胶囊;STAR_GEN 仍为 v3 的仓走本分支即升级为 v4 语义)
137
145
  inject(d, "dsh-star-foot-style", FOOT +
138
- ".dsh-star-foot{display:flex;flex-direction:column;align-items:flex-start;gap:2px}.dsh-star-foot-line{display:flex;align-items:center;gap:6px;flex-wrap:wrap;min-width:0}" +
139
- ".dsh-star-foot .dsh-star-support{appearance:none;border:0;background:none;padding:0;margin:0;font:inherit;line-height:inherit;color:inherit;cursor:pointer;opacity:.72;text-decoration:underline;text-underline-offset:2px}.dsh-star-foot .dsh-star-support:hover{opacity:1}" +
140
- ".dsh-star-foot-collapsed{display:flex;align-items:center;gap:8px;flex-wrap:wrap;font-size:12px;line-height:1.6;color:inherit;opacity:.72;margin-top:10px}.dsh-star-foot-collapsed a{color:inherit;text-decoration:none}.dsh-star-foot-collapsed a:hover{text-decoration:underline}");
146
+ ".dsh-star-foot{display:flex;flex-direction:column;align-items:flex-start;gap:6px;opacity:.85}.dsh-star-foot-line{display:flex;align-items:center;gap:6px;flex-wrap:wrap;min-width:0}" +
147
+ ".dsh-star-foot .dsh-star-ask{opacity:.8}" +
148
+ ".dsh-star-btn{display:inline-flex;align-items:center;gap:4px;flex:none;appearance:none;font:inherit;font-size:11px;line-height:1.5;padding:2px 10px;border-radius:999px;border:1px solid currentColor;background:transparent;color:inherit;cursor:pointer;text-decoration:none;opacity:.75}" +
149
+ ".dsh-star-btn:hover{opacity:1;background:rgba(127,127,127,.12);text-decoration:none}" +
150
+ ".dsh-star-foot-collapsed{display:flex;align-items:center;gap:8px;flex-wrap:wrap;font-size:12px;line-height:1.6;color:inherit;opacity:.72;margin-top:10px}" +
151
+ ".dsh-star-foot-collapsed .dsh-star-row{display:inline-flex;align-items:center;gap:7px;color:inherit;text-decoration:none}" +
152
+ ".dsh-star-foot-collapsed a{color:inherit;text-decoration:none}");
141
153
  var n3 = neutralLink(d);
142
- lsRm(K_V2); lsRm(K_V1); // v3 加载即清两旧键,不迁值
154
+ lsRm(K_V3); lsRm(K_V2); lsRm(K_V1); // v4 加载即清三旧键,不迁值
143
155
  var iss = issuesUrl();
144
- if (lsGet(K_V3) === "1") {
156
+ if (lsGet(K_V4) === "1") {
145
157
  var box = d.createElement("div"); box.className = "dsh-star-foot-collapsed";
146
158
  n3.className = "dsh-star-row"; box.appendChild(n3);
147
- box.appendChild(footItem(d, "a", "💬 " + (ISSUE_TXT[L] || ISSUE_TXT.en), iss));
159
+ box.appendChild(footBtn(d, "a", "💬 " + (ISSUE_TXT[L] || ISSUE_TXT.en), iss));
148
160
  return box;
149
161
  }
150
162
  var r3 = d.createElement("div"); r3.className = "dsh-star-foot";
151
163
  var l1 = d.createElement("div"); l1.className = "dsh-star-foot-line";
152
164
  var v3 = d.createElement("span"); v3.className = "dsh-star-ver"; v3.textContent = "v" + STAR_VERSION; l1.appendChild(v3);
153
165
  l1.appendChild(dot(d)); l1.appendChild(footItem(d, "span", FASK[L] || FASK.en));
154
- l1.appendChild(footItem(d, "a", "⭐ " + (STAR_TXT[L] || STAR_TXT.en), REPO_URL));
166
+ l1.appendChild(footBtn(d, "a", "⭐ " + (STAR_TXT[L] || STAR_TXT.en), REPO_URL));
155
167
  l1.appendChild(dot(d));
156
- var sup = d.createElement("button"); sup.type = "button"; sup.className = "dsh-star-support"; sup.textContent = SUPPORT_TXT[L] || SUPPORT_TXT.en;
168
+ var sup = d.createElement("button"); sup.type = "button"; sup.className = "dsh-star-btn dsh-star-support"; sup.textContent = SUPPORT_TXT[L] || SUPPORT_TXT.en;
157
169
  sup.addEventListener("click", function () {
158
- lsSet(K_V3);
170
+ lsSet(K_V4);
159
171
  if (r3.parentNode) {
160
172
  var b = d.createElement("div"); b.className = "dsh-star-foot-collapsed";
161
173
  var nn = neutralLink(d); nn.className = "dsh-star-row"; b.appendChild(nn);
162
- b.appendChild(footItem(d, "a", "💬 " + (ISSUE_TXT[L] || ISSUE_TXT.en), iss));
174
+ b.appendChild(footBtn(d, "a", "💬 " + (ISSUE_TXT[L] || ISSUE_TXT.en), iss));
163
175
  r3.parentNode.replaceChild(b, r3);
164
176
  }
165
177
  });
166
178
  l1.appendChild(sup);
167
179
  var l2 = d.createElement("div"); l2.className = "dsh-star-foot-line";
168
- l2.appendChild(footItem(d, "a", "💬 " + (ISSUE_TXT[L] || ISSUE_TXT.en), iss));
180
+ l2.appendChild(footBtn(d, "a", "💬 " + (ISSUE_TXT[L] || ISSUE_TXT.en), iss));
169
181
  r3.appendChild(l1); r3.appendChild(l2);
170
182
  return r3;
171
183
  }
@@ -179,336 +191,337 @@ const CSS_ID = 'dsh-skill-harbor-style'
179
191
  /* __STAR_INLINE_END__ */
180
192
 
181
193
 
182
-
183
- function injectStyles() {
184
- if (typeof document === 'undefined') return
185
- if (document.getElementById(CSS_ID) !== null) return
186
- const style = document.createElement('style')
187
- style.id = CSS_ID
188
- style.textContent = `
189
- .dshh-root { display: flex; flex-direction: column; gap: 12px; padding: 12px; font-size: 13px; }
190
- .dshh-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--dsw-alias-border, #3334); }
191
- .dshh-tab { padding: 6px 12px; cursor: pointer; border: none; background: transparent; color: inherit; border-radius: 4px 4px 0 0; }
192
- .dshh-tab[data-active="true"] { background: var(--dsw-alias-surface, #ffffff10); font-weight: 600; }
193
- .dshh-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: nowrap; }
194
- .dshh-spacer { flex: 1; }
195
- .dshh-table { width: 100%; border-collapse: collapse; }
196
- .dshh-table th, .dshh-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--dsw-alias-border, #3333); }
197
- .dshh-state { padding: 1px 6px; border-radius: 3px; font-size: 11px; }
198
- .dshh-state[data-state="editable"] { background: #2e7d3233; color: #4caf50; }
199
- .dshh-state[data-state="provider-file"] { background: #ed6c0233; color: #ff9800; }
200
- .dshh-state[data-state="virtual"] { background: #9e9e9e33; color: #9e9e9e; }
201
- .dshh-shadowed { opacity: 0.55; }
202
- .dshh-shadow-tag { font-size: 11px; color: #ff9800; }
203
- .dshh-btn { padding: 3px 8px; border-radius: 3px; border: 1px solid var(--dsw-alias-border, #3336); background: transparent; color: inherit; cursor: pointer; }
204
- .dshh-btn:disabled { opacity: 0.4; cursor: not-allowed; }
205
- .dshh-empty { padding: 24px; text-align: center; opacity: 0.6; }
206
- .dshh-verdict { padding: 1px 6px; border-radius: 3px; font-size: 11px; }
207
- .dshh-verdict[data-v="ok"] { background: #2e7d3233; color: #4caf50; }
208
- .dshh-verdict[data-v="warn"] { background: #ed6c0233; color: #ff9800; }
209
- .dshh-verdict[data-v="fail"] { background: #c6282833; color: #f44336; }
210
- .dshh-verdict[data-v="skipped"] { background: #9e9e9e33; color: #9e9e9e; }
211
- .dshh-dup-panel { border: 1px solid var(--dsw-alias-border, #3334); border-radius: 6px; padding: 10px; margin-bottom: 12px; }
212
- .dshh-dup-heading { font-weight: 600; margin-bottom: 8px; }
213
- .dshh-dup-group { margin-bottom: 10px; }
214
- .dshh-dup-group:last-child { margin-bottom: 0; }
215
- .dshh-dup-title { font-size: 12px; opacity: 0.75; margin-bottom: 4px; }
216
- .dshh-dup-row { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 12px; }
217
- .dshh-dup-meta { opacity: 0.6; }
218
- .dshh-dup-winner { color: #4caf50; font-weight: 600; }
219
- `
220
- document.head.appendChild(style)
221
- }
222
-
223
- function el(tag, props = {}, children = []) {
224
- const node = document.createElement(tag)
225
- for (const [key, value] of Object.entries(props)) {
226
- if (key === 'className') node.className = value
227
- else if (key.startsWith('data-')) node.setAttribute(key, value)
228
- else if (key === 'text') node.textContent = value
229
- else if (key === 'onClick') node.addEventListener('click', value)
230
- else node.setAttribute(key, value)
231
- }
232
- for (const child of children) node.append(child)
233
- return node
234
- }
235
-
236
- /**
237
- * 创建面板。返回 { node, destroy }。
238
- * @param {{ lang?: string }} options
239
- */
240
- export function createPanel(options = {}) {
241
- const lang = options.lang ?? 'zh'
242
- const t = dict(lang)
243
-
244
- injectStyles()
245
-
246
- let tab = 'overview'
247
- let state = { skills: [], duplicates: [], totals: {}, audit: null, budget: null, error: null }
248
- let destroyed = false
249
-
250
- const root = el('div', { className: 'dshh-root' })
251
- const tabsBar = el('div', { className: 'dshh-tabs' })
252
- const body = el('div', {})
253
-
254
- const tabs = [
255
- ['overview', t.tabOverview],
256
- ['audit', t.tabAudit],
257
- ['budget', t.tabBudget],
258
- ]
259
-
260
- function renderTabs() {
261
- tabsBar.replaceChildren(
262
- ...tabs.map(([id, label]) =>
263
- el('button', {
264
- className: 'dshh-tab',
265
- 'data-active': String(tab === id),
266
- text: label,
267
- onClick: () => {
268
- tab = id
269
- void refresh()
270
- },
271
- }),
272
- ),
273
- )
274
- }
275
-
276
- function renderOverview() {
277
- if (state.skills.length === 0) {
278
- return el('div', { className: 'dshh-empty', text: t.noSkills })
279
- }
280
-
281
- return el('div', {}, [
282
- // 同名冲突先给树状视图:谁的 rank 高、谁被压住
283
- state.duplicates.length > 0 ? renderDuplicates() : el('span', {}),
284
- renderTable(),
285
- ])
286
- }
287
-
288
- /**
289
- * 遮蔽关系树:一组同名技能按 rank 升序竖排,
290
- * 胜者标「胜出」,其余标注被谁压住。
291
- */
292
- function renderDuplicates() {
293
- const groups = state.duplicates.map(group => {
294
- // 从 skills 里捞出该组的全部条目(list 已按 rank 排序)
295
- const entries = state.skills
296
- .filter(skill => skill.name.toLowerCase() === group.name.toLowerCase())
297
- .sort((a, b) => a.rank - b.rank)
298
-
299
- const rows = entries.map((skill, index) => {
300
- const isWinner = index === 0
301
- return el('div', {
302
- className: isWinner ? 'dshh-dup-row' : 'dshh-dup-row dshh-shadowed',
303
- style: `padding-left:${index * 16}px`,
304
- }, [
305
- el('span', { text: isWinner ? '▼ ' : ' └ ' }),
306
- el('span', { text: `${skill.name} ` }),
307
- el('span', { className: 'dshh-dup-meta', text: `${sourceLabel(t, skill.source)} (rank ${skill.rank})` }),
308
- isWinner
309
- ? el('span', { className: 'dshh-dup-winner', text: ` — ${t.winner}` })
310
- : el('span', { className: 'dshh-shadow-tag', text: ` — ${t.shadowedBy}` }),
311
- ])
312
- })
313
-
314
- return el('div', { className: 'dshh-dup-group' }, [
315
- el('div', { className: 'dshh-dup-title', text: `${t.duplicateGroup}: ${group.name}` }),
316
- ...rows,
317
- ])
318
- })
319
-
320
- return el('div', { className: 'dshh-dup-panel' }, [
321
- el('div', { className: 'dshh-dup-heading', text: t.duplicateGroup }),
322
- ...groups,
323
- ])
324
- }
325
-
326
- function renderTable() {
327
- const rows = state.skills.map(skill => {
328
- const shadowed = skill.shadowedBy !== null
329
- const cells = [
330
- el('td', { text: skill.name }),
331
- el('td', { text: sourceLabel(t, skill.source) }),
332
- el('td', { text: String(skill.rank) }),
333
- el('td', {}, [
334
- el('span', {
335
- className: 'dshh-state',
336
- 'data-state': skill.fileState,
337
- text: FILE_STATE_LABEL[skill.fileState] ?? skill.fileState,
338
- }),
339
- ]),
340
- el('td', { text: skill.modelInvocable ? '✓' : '—' }),
341
- el('td', { text: String(skill.announcementChars) }),
342
- el('td', {}, [
343
- shadowed
344
- ? el('span', { className: 'dshh-shadow-tag', text: `${t.shadowedBy}: ${skill.shadowedBy.source}` })
345
- : buildActions(skill),
346
- ]),
347
- ]
348
- return el('tr', { className: shadowed ? 'dshh-shadowed' : '' }, cells)
349
- })
350
-
351
- return el('div', {}, [
352
- el('table', { className: 'dshh-table' }, [
353
- el('thead', {}, [
354
- el('tr', {}, [
355
- el('th', { text: t.colName }),
356
- el('th', { text: t.colSource }),
357
- el('th', { text: t.colRank }),
358
- el('th', { text: t.colState }),
359
- el('th', { text: t.colModel }),
360
- el('th', { text: t.colChars }),
361
- el('th', { text: t.colActions }),
362
- ]),
363
- ]),
364
- el('tbody', {}, rows),
365
- ]),
366
- ])
367
- }
368
-
369
- function buildActions(skill) {
370
- // provider-file / virtual 一律不渲染写控件
371
- if (!skill.writable) return el('span', {})
372
-
373
- const toggle = el('button', {
374
- className: 'dshh-btn',
375
- text: skill.modelInvocable ? t.actionDisable : t.actionEnable,
376
- onClick: async () => {
377
- try {
378
- await api.setEnabled(skill.path, !skill.modelInvocable)
379
- await refresh()
380
- } catch (error) {
381
- state.error = error.message
382
- render()
383
- }
384
- },
385
- })
386
-
387
- const remove = el('button', {
388
- className: 'dshh-btn',
389
- text: t.actionDelete,
390
- onClick: async () => {
391
- if (!window.confirm(t.deleteConfirm)) return
392
- try {
393
- await api.remove(skill.path)
394
- await refresh()
395
- } catch (error) {
396
- state.error = error.message
397
- render()
398
- }
399
- },
400
- })
401
-
402
- return el('span', {}, [toggle, document.createTextNode(' '), remove])
403
- }
404
-
405
- function renderAudit() {
406
- if (state.audit === null) return el('div', { className: 'dshh-empty', text: t.loading })
407
- const rows = state.audit.results.map(result =>
408
- el('tr', {}, [
409
- el('td', { text: result.name }),
410
- el('td', {}, [el('span', { className: 'dshh-verdict', 'data-v': result.verdict, text: verdictLabel(t, result.verdict) })]),
411
- el('td', {
412
- text: result.findings.map(f => `${f.rule} ${f.message}`).join('; ') || result.reason || '',
413
- }),
414
- ]),
415
- )
416
- const totals = state.audit.totals
417
- return el('div', {}, [
418
- el('div', { className: 'dshh-toolbar' }, [
419
- el('span', { text: `${t.auditOk}: ${totals.ok}` }),
420
- el('span', { text: `${t.auditWarn}: ${totals.warn}` }),
421
- el('span', { text: `${t.auditFail}: ${totals.fail}` }),
422
- el('span', { text: `${t.auditSkipped}: ${totals.skipped}` }),
423
- ]),
424
- el('table', { className: 'dshh-table' }, [
425
- el('thead', {}, [el('tr', {}, [
426
- el('th', { text: t.colName }),
427
- el('th', { text: t.tabAudit }),
428
- el('th', { text: t.colActions }),
429
- ])]),
430
- el('tbody', {}, rows),
431
- ]),
432
- ])
433
- }
434
-
435
- function renderBudget() {
436
- if (state.budget === null) return el('div', { className: 'dshh-empty', text: t.loading })
437
- const budget = state.budget
438
- return el('div', {}, [
439
- el('div', { className: 'dshh-toolbar' }, [
440
- el('span', { text: `${t.budgetTotal}: ${budget.total} chars` }),
441
- el('span', { text: `${t.budgetAnnounced}: ${budget.announcedTotal} chars (${budget.announcedCount})` }),
442
- el('span', { text: `${t.budgetSkipped}: ${budget.skippedTotal} chars (${budget.skippedCount})` }),
443
- ]),
444
- budget.overLimit.length > 0
445
- ? el('ul', {}, budget.overLimit.map(row =>
446
- el('li', { text: `${row.name}: ${row.chars} > ${budget.perSkillLimit} (${t.budgetOverLimit})` }),
447
- ))
448
- : el('span', {}),
449
- ])
450
- }
451
-
452
- function render() {
453
- if (destroyed) return
454
- renderTabs()
455
- body.replaceChildren(
456
- state.error !== null ? el('div', { className: 'dshh-empty', text: state.error }) : el('span', {}),
457
- tab === 'overview' ? renderOverview() : tab === 'audit' ? renderAudit() : renderBudget(),
458
- )
459
- }
460
-
461
- async function refresh() {
462
- state.error = null
463
- render()
464
- try {
465
- if (tab === 'overview') {
466
- const data = await api.list()
467
- state.skills = data.skills
468
- state.duplicates = data.duplicates
469
- state.totals = data.totals
470
- } else if (tab === 'audit') {
471
- state.audit = await api.audit()
472
- } else {
473
- state.budget = await api.budget()
474
- }
475
- } catch (error) {
476
- state.error = error.message
477
- }
478
- render()
479
- }
480
-
481
- root.append(tabsBar, body)
482
- // star 快车道行(内联手写,_tools/star-row 阶梯;改本段无效,回 gens/inline.star-panel.js 真源)
483
- try {
484
- const starApi = (typeof window !== "undefined" && window.__StarPanel) || (typeof globalThis !== "undefined" && globalThis.__StarPanel)
485
- if (starApi) { const n = starApi.mount(); if (n) root.append(n) }
486
- } catch (e) { /* 面板挂载失败不影响主功能 */ }
487
- void refresh()
488
-
489
- return {
490
- node: root,
491
- destroy() {
492
- destroyed = true
493
- root.remove()
494
- },
495
- }
496
- }
497
-
498
- function sourceLabel(t, source) {
499
- const map = {
500
- 'project-dsh': t.sourceProjectDsh,
501
- 'project-agents': t.sourceProjectAgents,
502
- runtime: t.sourceRuntime,
503
- custom: t.sourceCustom,
504
- 'user-dsh': t.sourceUserDsh,
505
- 'user-agents': t.sourceUserAgents,
506
- bundled: t.sourceBundled,
507
- }
508
- return map[source] ?? source
509
- }
510
-
511
- function verdictLabel(t, verdict) {
512
- const map = { ok: t.auditOk, warn: t.auditWarn, fail: t.auditFail, skipped: t.auditSkipped }
513
- return map[verdict] ?? verdict
514
- }
194
+
195
+
196
+ function injectStyles() {
197
+ if (typeof document === 'undefined') return
198
+ if (document.getElementById(CSS_ID) !== null) return
199
+ const style = document.createElement('style')
200
+ style.id = CSS_ID
201
+ style.textContent = `
202
+ .dshh-root { display: flex; flex-direction: column; gap: 12px; padding: 12px; font-size: 13px; }
203
+ .dshh-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--dsw-alias-border, #3334); }
204
+ .dshh-tab { padding: 6px 12px; cursor: pointer; border: none; background: transparent; color: inherit; border-radius: 4px 4px 0 0; }
205
+ .dshh-tab[data-active="true"] { background: var(--dsw-alias-surface, #ffffff10); font-weight: 600; }
206
+ .dshh-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: nowrap; }
207
+ .dshh-spacer { flex: 1; }
208
+ .dshh-table { width: 100%; border-collapse: collapse; }
209
+ .dshh-table th, .dshh-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--dsw-alias-border, #3333); }
210
+ .dshh-state { padding: 1px 6px; border-radius: 3px; font-size: 11px; }
211
+ .dshh-state[data-state="editable"] { background: #2e7d3233; color: #4caf50; }
212
+ .dshh-state[data-state="provider-file"] { background: #ed6c0233; color: #ff9800; }
213
+ .dshh-state[data-state="virtual"] { background: #9e9e9e33; color: #9e9e9e; }
214
+ .dshh-shadowed { opacity: 0.55; }
215
+ .dshh-shadow-tag { font-size: 11px; color: #ff9800; }
216
+ .dshh-btn { padding: 3px 8px; border-radius: 3px; border: 1px solid var(--dsw-alias-border, #3336); background: transparent; color: inherit; cursor: pointer; }
217
+ .dshh-btn:disabled { opacity: 0.4; cursor: not-allowed; }
218
+ .dshh-empty { padding: 24px; text-align: center; opacity: 0.6; }
219
+ .dshh-verdict { padding: 1px 6px; border-radius: 3px; font-size: 11px; }
220
+ .dshh-verdict[data-v="ok"] { background: #2e7d3233; color: #4caf50; }
221
+ .dshh-verdict[data-v="warn"] { background: #ed6c0233; color: #ff9800; }
222
+ .dshh-verdict[data-v="fail"] { background: #c6282833; color: #f44336; }
223
+ .dshh-verdict[data-v="skipped"] { background: #9e9e9e33; color: #9e9e9e; }
224
+ .dshh-dup-panel { border: 1px solid var(--dsw-alias-border, #3334); border-radius: 6px; padding: 10px; margin-bottom: 12px; }
225
+ .dshh-dup-heading { font-weight: 600; margin-bottom: 8px; }
226
+ .dshh-dup-group { margin-bottom: 10px; }
227
+ .dshh-dup-group:last-child { margin-bottom: 0; }
228
+ .dshh-dup-title { font-size: 12px; opacity: 0.75; margin-bottom: 4px; }
229
+ .dshh-dup-row { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 12px; }
230
+ .dshh-dup-meta { opacity: 0.6; }
231
+ .dshh-dup-winner { color: #4caf50; font-weight: 600; }
232
+ `
233
+ document.head.appendChild(style)
234
+ }
235
+
236
+ function el(tag, props = {}, children = []) {
237
+ const node = document.createElement(tag)
238
+ for (const [key, value] of Object.entries(props)) {
239
+ if (key === 'className') node.className = value
240
+ else if (key.startsWith('data-')) node.setAttribute(key, value)
241
+ else if (key === 'text') node.textContent = value
242
+ else if (key === 'onClick') node.addEventListener('click', value)
243
+ else node.setAttribute(key, value)
244
+ }
245
+ for (const child of children) node.append(child)
246
+ return node
247
+ }
248
+
249
+ /**
250
+ * 创建面板。返回 { node, destroy }。
251
+ * @param {{ lang?: string }} options
252
+ */
253
+ export function createPanel(options = {}) {
254
+ const lang = options.lang ?? 'zh'
255
+ const t = dict(lang)
256
+
257
+ injectStyles()
258
+
259
+ let tab = 'overview'
260
+ let state = { skills: [], duplicates: [], totals: {}, audit: null, budget: null, error: null }
261
+ let destroyed = false
262
+
263
+ const root = el('div', { className: 'dshh-root' })
264
+ const tabsBar = el('div', { className: 'dshh-tabs' })
265
+ const body = el('div', {})
266
+
267
+ const tabs = [
268
+ ['overview', t.tabOverview],
269
+ ['audit', t.tabAudit],
270
+ ['budget', t.tabBudget],
271
+ ]
272
+
273
+ function renderTabs() {
274
+ tabsBar.replaceChildren(
275
+ ...tabs.map(([id, label]) =>
276
+ el('button', {
277
+ className: 'dshh-tab',
278
+ 'data-active': String(tab === id),
279
+ text: label,
280
+ onClick: () => {
281
+ tab = id
282
+ void refresh()
283
+ },
284
+ }),
285
+ ),
286
+ )
287
+ }
288
+
289
+ function renderOverview() {
290
+ if (state.skills.length === 0) {
291
+ return el('div', { className: 'dshh-empty', text: t.noSkills })
292
+ }
293
+
294
+ return el('div', {}, [
295
+ // 同名冲突先给树状视图:谁的 rank 高、谁被压住
296
+ state.duplicates.length > 0 ? renderDuplicates() : el('span', {}),
297
+ renderTable(),
298
+ ])
299
+ }
300
+
301
+ /**
302
+ * 遮蔽关系树:一组同名技能按 rank 升序竖排,
303
+ * 胜者标「胜出」,其余标注被谁压住。
304
+ */
305
+ function renderDuplicates() {
306
+ const groups = state.duplicates.map(group => {
307
+ // 从 skills 里捞出该组的全部条目(list 已按 rank 排序)
308
+ const entries = state.skills
309
+ .filter(skill => skill.name.toLowerCase() === group.name.toLowerCase())
310
+ .sort((a, b) => a.rank - b.rank)
311
+
312
+ const rows = entries.map((skill, index) => {
313
+ const isWinner = index === 0
314
+ return el('div', {
315
+ className: isWinner ? 'dshh-dup-row' : 'dshh-dup-row dshh-shadowed',
316
+ style: `padding-left:${index * 16}px`,
317
+ }, [
318
+ el('span', { text: isWinner ? '▼ ' : ' └ ' }),
319
+ el('span', { text: `${skill.name} ` }),
320
+ el('span', { className: 'dshh-dup-meta', text: `${sourceLabel(t, skill.source)} (rank ${skill.rank})` }),
321
+ isWinner
322
+ ? el('span', { className: 'dshh-dup-winner', text: ` — ${t.winner}` })
323
+ : el('span', { className: 'dshh-shadow-tag', text: ` — ${t.shadowedBy}` }),
324
+ ])
325
+ })
326
+
327
+ return el('div', { className: 'dshh-dup-group' }, [
328
+ el('div', { className: 'dshh-dup-title', text: `${t.duplicateGroup}: ${group.name}` }),
329
+ ...rows,
330
+ ])
331
+ })
332
+
333
+ return el('div', { className: 'dshh-dup-panel' }, [
334
+ el('div', { className: 'dshh-dup-heading', text: t.duplicateGroup }),
335
+ ...groups,
336
+ ])
337
+ }
338
+
339
+ function renderTable() {
340
+ const rows = state.skills.map(skill => {
341
+ const shadowed = skill.shadowedBy !== null
342
+ const cells = [
343
+ el('td', { text: skill.name }),
344
+ el('td', { text: sourceLabel(t, skill.source) }),
345
+ el('td', { text: String(skill.rank) }),
346
+ el('td', {}, [
347
+ el('span', {
348
+ className: 'dshh-state',
349
+ 'data-state': skill.fileState,
350
+ text: FILE_STATE_LABEL[skill.fileState] ?? skill.fileState,
351
+ }),
352
+ ]),
353
+ el('td', { text: skill.modelInvocable ? '✓' : '—' }),
354
+ el('td', { text: String(skill.announcementChars) }),
355
+ el('td', {}, [
356
+ shadowed
357
+ ? el('span', { className: 'dshh-shadow-tag', text: `${t.shadowedBy}: ${skill.shadowedBy.source}` })
358
+ : buildActions(skill),
359
+ ]),
360
+ ]
361
+ return el('tr', { className: shadowed ? 'dshh-shadowed' : '' }, cells)
362
+ })
363
+
364
+ return el('div', {}, [
365
+ el('table', { className: 'dshh-table' }, [
366
+ el('thead', {}, [
367
+ el('tr', {}, [
368
+ el('th', { text: t.colName }),
369
+ el('th', { text: t.colSource }),
370
+ el('th', { text: t.colRank }),
371
+ el('th', { text: t.colState }),
372
+ el('th', { text: t.colModel }),
373
+ el('th', { text: t.colChars }),
374
+ el('th', { text: t.colActions }),
375
+ ]),
376
+ ]),
377
+ el('tbody', {}, rows),
378
+ ]),
379
+ ])
380
+ }
381
+
382
+ function buildActions(skill) {
383
+ // provider-file / virtual 一律不渲染写控件
384
+ if (!skill.writable) return el('span', {})
385
+
386
+ const toggle = el('button', {
387
+ className: 'dshh-btn',
388
+ text: skill.modelInvocable ? t.actionDisable : t.actionEnable,
389
+ onClick: async () => {
390
+ try {
391
+ await api.setEnabled(skill.path, !skill.modelInvocable)
392
+ await refresh()
393
+ } catch (error) {
394
+ state.error = error.message
395
+ render()
396
+ }
397
+ },
398
+ })
399
+
400
+ const remove = el('button', {
401
+ className: 'dshh-btn',
402
+ text: t.actionDelete,
403
+ onClick: async () => {
404
+ if (!window.confirm(t.deleteConfirm)) return
405
+ try {
406
+ await api.remove(skill.path)
407
+ await refresh()
408
+ } catch (error) {
409
+ state.error = error.message
410
+ render()
411
+ }
412
+ },
413
+ })
414
+
415
+ return el('span', {}, [toggle, document.createTextNode(' '), remove])
416
+ }
417
+
418
+ function renderAudit() {
419
+ if (state.audit === null) return el('div', { className: 'dshh-empty', text: t.loading })
420
+ const rows = state.audit.results.map(result =>
421
+ el('tr', {}, [
422
+ el('td', { text: result.name }),
423
+ el('td', {}, [el('span', { className: 'dshh-verdict', 'data-v': result.verdict, text: verdictLabel(t, result.verdict) })]),
424
+ el('td', {
425
+ text: result.findings.map(f => `${f.rule} ${f.message}`).join('; ') || result.reason || '',
426
+ }),
427
+ ]),
428
+ )
429
+ const totals = state.audit.totals
430
+ return el('div', {}, [
431
+ el('div', { className: 'dshh-toolbar' }, [
432
+ el('span', { text: `${t.auditOk}: ${totals.ok}` }),
433
+ el('span', { text: `${t.auditWarn}: ${totals.warn}` }),
434
+ el('span', { text: `${t.auditFail}: ${totals.fail}` }),
435
+ el('span', { text: `${t.auditSkipped}: ${totals.skipped}` }),
436
+ ]),
437
+ el('table', { className: 'dshh-table' }, [
438
+ el('thead', {}, [el('tr', {}, [
439
+ el('th', { text: t.colName }),
440
+ el('th', { text: t.tabAudit }),
441
+ el('th', { text: t.colActions }),
442
+ ])]),
443
+ el('tbody', {}, rows),
444
+ ]),
445
+ ])
446
+ }
447
+
448
+ function renderBudget() {
449
+ if (state.budget === null) return el('div', { className: 'dshh-empty', text: t.loading })
450
+ const budget = state.budget
451
+ return el('div', {}, [
452
+ el('div', { className: 'dshh-toolbar' }, [
453
+ el('span', { text: `${t.budgetTotal}: ${budget.total} chars` }),
454
+ el('span', { text: `${t.budgetAnnounced}: ${budget.announcedTotal} chars (${budget.announcedCount})` }),
455
+ el('span', { text: `${t.budgetSkipped}: ${budget.skippedTotal} chars (${budget.skippedCount})` }),
456
+ ]),
457
+ budget.overLimit.length > 0
458
+ ? el('ul', {}, budget.overLimit.map(row =>
459
+ el('li', { text: `${row.name}: ${row.chars} > ${budget.perSkillLimit} (${t.budgetOverLimit})` }),
460
+ ))
461
+ : el('span', {}),
462
+ ])
463
+ }
464
+
465
+ function render() {
466
+ if (destroyed) return
467
+ renderTabs()
468
+ body.replaceChildren(
469
+ state.error !== null ? el('div', { className: 'dshh-empty', text: state.error }) : el('span', {}),
470
+ tab === 'overview' ? renderOverview() : tab === 'audit' ? renderAudit() : renderBudget(),
471
+ )
472
+ }
473
+
474
+ async function refresh() {
475
+ state.error = null
476
+ render()
477
+ try {
478
+ if (tab === 'overview') {
479
+ const data = await api.list()
480
+ state.skills = data.skills
481
+ state.duplicates = data.duplicates
482
+ state.totals = data.totals
483
+ } else if (tab === 'audit') {
484
+ state.audit = await api.audit()
485
+ } else {
486
+ state.budget = await api.budget()
487
+ }
488
+ } catch (error) {
489
+ state.error = error.message
490
+ }
491
+ render()
492
+ }
493
+
494
+ root.append(tabsBar, body)
495
+ // star 快车道行(内联手写,_tools/star-row 阶梯;改本段无效,回 gens/inline.star-panel.js 真源)
496
+ try {
497
+ const starApi = (typeof window !== "undefined" && window.__StarPanel) || (typeof globalThis !== "undefined" && globalThis.__StarPanel)
498
+ if (starApi) { const n = starApi.mount(); if (n) root.append(n) }
499
+ } catch (e) { /* 面板挂载失败不影响主功能 */ }
500
+ void refresh()
501
+
502
+ return {
503
+ node: root,
504
+ destroy() {
505
+ destroyed = true
506
+ root.remove()
507
+ },
508
+ }
509
+ }
510
+
511
+ function sourceLabel(t, source) {
512
+ const map = {
513
+ 'project-dsh': t.sourceProjectDsh,
514
+ 'project-agents': t.sourceProjectAgents,
515
+ runtime: t.sourceRuntime,
516
+ custom: t.sourceCustom,
517
+ 'user-dsh': t.sourceUserDsh,
518
+ 'user-agents': t.sourceUserAgents,
519
+ bundled: t.sourceBundled,
520
+ }
521
+ return map[source] ?? source
522
+ }
523
+
524
+ function verdictLabel(t, verdict) {
525
+ const map = { ok: t.auditOk, warn: t.auditWarn, fail: t.auditFail, skipped: t.auditSkipped }
526
+ return map[verdict] ?? verdict
527
+ }