@cheemsup/dsh-plugin-console 0.0.0-stage → 0.1.1

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.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +85 -2
  3. package/cordis.patch.yml +5 -0
  4. package/lib/client.activity.js +222 -0
  5. package/lib/client.apply.js +171 -0
  6. package/lib/client.changes.js +206 -0
  7. package/lib/client.cleanup.js +270 -0
  8. package/lib/client.control.js +242 -0
  9. package/lib/client.dialog.js +77 -0
  10. package/lib/client.draft.js +280 -0
  11. package/lib/client.editor-messages.js +421 -0
  12. package/lib/client.editor-store.js +266 -0
  13. package/lib/client.editor.js +433 -0
  14. package/lib/client.effects.js +115 -0
  15. package/lib/client.influence.js +361 -0
  16. package/lib/client.js +216 -0
  17. package/lib/client.page.js +584 -0
  18. package/lib/client.plugin-filters.js +62 -0
  19. package/lib/client.plugins.js +504 -0
  20. package/lib/client.preview-messages.js +495 -0
  21. package/lib/client.preview-raw.js +132 -0
  22. package/lib/client.preview-store.js +128 -0
  23. package/lib/client.preview-tools.js +194 -0
  24. package/lib/client.preview.js +447 -0
  25. package/lib/client.schema.js +327 -0
  26. package/lib/client.search.js +408 -0
  27. package/lib/client.session-detail.js +503 -0
  28. package/lib/client.sessions.js +495 -0
  29. package/lib/client.shared.js +559 -0
  30. package/lib/client.store.js +452 -0
  31. package/lib/client.styles.js +524 -0
  32. package/lib/client.template-card.js +240 -0
  33. package/lib/client.tools.js +366 -0
  34. package/lib/client.workspace-picker.js +204 -0
  35. package/lib/host/activity.js +252 -0
  36. package/lib/host/assembly-preview.js +244 -0
  37. package/lib/host/attribution.js +307 -0
  38. package/lib/host/catalog.js +133 -0
  39. package/lib/host/categorize.js +40 -0
  40. package/lib/host/constants.js +66 -0
  41. package/lib/host/control.js +159 -0
  42. package/lib/host/entries.js +289 -0
  43. package/lib/host/fiber.js +86 -0
  44. package/lib/host/fs.js +99 -0
  45. package/lib/host/health.js +178 -0
  46. package/lib/host/http.js +65 -0
  47. package/lib/host/impact.js +132 -0
  48. package/lib/host/layers.js +132 -0
  49. package/lib/host/masks.js +145 -0
  50. package/lib/host/modes.js +96 -0
  51. package/lib/host/names.js +44 -0
  52. package/lib/host/patch-scan.js +103 -0
  53. package/lib/host/preview-conditions.js +281 -0
  54. package/lib/host/preview-contexts.js +174 -0
  55. package/lib/host/preview-envelope.js +31 -0
  56. package/lib/host/preview-instructions.js +450 -0
  57. package/lib/host/preview-messages.js +284 -0
  58. package/lib/host/preview-modules.js +233 -0
  59. package/lib/host/preview-skills.js +200 -0
  60. package/lib/host/prompt.js +213 -0
  61. package/lib/host/recipe-overlay.js +209 -0
  62. package/lib/host/request-preview.js +114 -0
  63. package/lib/host/routes/activation.js +96 -0
  64. package/lib/host/routes/activity.js +22 -0
  65. package/lib/host/routes/apply.js +93 -0
  66. package/lib/host/routes/cleanup.js +62 -0
  67. package/lib/host/routes/control.js +22 -0
  68. package/lib/host/routes/impact.js +19 -0
  69. package/lib/host/routes/operations.js +22 -0
  70. package/lib/host/routes/preview.js +58 -0
  71. package/lib/host/routes/session-influence.js +23 -0
  72. package/lib/host/routes/snapshot.js +21 -0
  73. package/lib/host/routes/template.js +54 -0
  74. package/lib/host/routes/templates.js +28 -0
  75. package/lib/host/scope-impact.js +125 -0
  76. package/lib/host/session-events.js +39 -0
  77. package/lib/host/session-influence.js +475 -0
  78. package/lib/host/sessions.js +293 -0
  79. package/lib/host/snapshot.js +218 -0
  80. package/lib/host/source-scan.js +225 -0
  81. package/lib/host/templates/cleanup.js +219 -0
  82. package/lib/host/templates/inheritance.js +144 -0
  83. package/lib/host/templates/materialize.js +317 -0
  84. package/lib/host/templates/message-overlay.js +184 -0
  85. package/lib/host/templates/repository.js +323 -0
  86. package/lib/host/templates/store.js +131 -0
  87. package/lib/host/tool-set.js +150 -0
  88. package/lib/host/tools.js +129 -0
  89. package/lib/index.js +103 -0
  90. package/package.json +111 -4
@@ -0,0 +1,504 @@
1
+ /**
2
+ * 插件视图:这台机器装了什么、都在干什么。
3
+ *
4
+ * 按能力类别分组(可折叠),可再按来源层与状态筛选;点一行展开
5
+ * 基本信息 / 状态 / 组合链 / 服务 / 行为 / 注册项六段事实。
6
+ *
7
+ * 本文件是一个包内 chunk:入口用 `require.async('./client.plugins.js')` 取它,
8
+ * 工厂返回 `create(deps)`,`deps` 是共享工具集合。
9
+ */
10
+
11
+ window.__ModuleLoader__.load({
12
+ id: '@cheemsup/dsh-plugin-console',
13
+ chunk: 'client.plugins.js',
14
+ factory: (require) => {
15
+ const React = require('react')
16
+ const { createElement: h, useEffect } = React
17
+
18
+ return function create(deps) {
19
+ const {
20
+ shortName, layerLabel, depList, fact, shortId, textButton, rowEnd,
21
+ CATEGORY_LABELS, toggleIn, activateOnKey, activity, changes, control, effects, search,
22
+ } = deps
23
+
24
+ /** 分类说明:悬停在分组标题上时回答「这个一级分类是怎么来的」。 */
25
+ const CATEGORY_NOTES = {
26
+ tool: '注册工具定义(dsh-tool-*、MCP 客户端回填的工具也算)',
27
+ ui: '浏览器半的界面槽位、面板与渲染器',
28
+ model: '模型适配与模型选择',
29
+ session: '会话持久化、投影、查询与格式迁移',
30
+ safety: '沙箱、审批、权限预设与凭据',
31
+ transport: 'API 网关、Remote 方法、ACP / JSON-RPC 传输',
32
+ extend: '技能、命令、子 Agent、规划、压缩、Web、上下文与提示词注入',
33
+ client: '客户端内核与前端外壳',
34
+ infra: '存储、进程、工作区、Loader 等宿主基础设施',
35
+ structure: 'cordis:include 这类结构行,不是插件',
36
+ other: '按命名与注册内容都没有命中上面任何一类',
37
+ }
38
+
39
+ /**
40
+ * 详情字段的一句话解释。
41
+ *
42
+ * 绑定在字段名的 `title` 上,悬停即见;这样同一份解读不再以
43
+ * `ptSectionNote` 的形式长期占版面。
44
+ */
45
+ const FACT_TIPS = {
46
+ rowId: '插件声明使用的id',
47
+ entryId: 'Loader树里的运行时实例id',
48
+ loadIndex: '加载顺序就是组合文件的声明顺序',
49
+ module: '这个条目加载的模块名',
50
+ packageName: '从模块名解析出的包名',
51
+ version: '包声明的版本',
52
+ packageDir: '包在磁盘上的目录',
53
+ face: 'host = 宿主/管理侧(Node/Cordis):工具、服务、存储与权限等;client = 浏览器侧(dsh.client):负责面板与交互',
54
+ description: '包提供的本地化描述',
55
+ metaError: '读取包元信息时发生的错误',
56
+ enabled: '当自身未被禁用且祖先 group 也没有被禁用时为启用',
57
+ inheritedDisabled: '插件自身没有禁用,但祖先 group 被禁用',
58
+ disabledExpr: '组合文件里的条件禁用表达式',
59
+ disabledValue: 'true 表示禁用,false 表示启用',
60
+ phase: 'active = 已激活;pending = 等待依赖;loading / unloading = 正在切换;failed = 启动失败;无存活 fiber = 未挂载',
61
+ diagnostic: 'fiber 启动失败时的错误信息',
62
+ config: '插件收到的生效配置,可能包含凭据',
63
+ source: '来源: profile patch(插件市场等 ) / base / web-app / profile / 运行时挂载 / 模式挂载等',
64
+ layerVersion: '插件所属的组合包(bundle)以及版本',
65
+ override: 'patch 层按行id覆盖 config、disabled 等的键内容',
66
+ requires: '插件生效前需要等待的服务,没有提供者时会停在 pending',
67
+ provides: '插件注册和对外提供的服务,停掉后消费者会失去依赖',
68
+ clientDeps: '页面浏览方面(dsh.client)声明需要的的模块依赖',
69
+ behavior: 'Cordis 登记的副作用(注册工具、监听事件、提供服务等)',
70
+ }
71
+
72
+ /** 只有这些来源层值得在行里点出来;base / web-app 是大多数,标出来只是噪音。 */
73
+ const NOTABLE_LAYERS = new Set(['profile', 'runtime', 'mode'])
74
+
75
+ /**
76
+ * 一行「为什么这行留下」。
77
+ *
78
+ * 描述常是用户唯一记得的东西,命中了就要在行上看得见;包名与行 id 命中时
79
+ * 标题本身不带这些字,不给出来就像随机留下的结果。
80
+ * @param {object} entry - 插件行。
81
+ * @param {string} query - 页头搜索词。
82
+ * @returns {object | null} 摘要节点;没命中或行里已看得见原因时为 null。
83
+ */
84
+ function rowReason(entry, query) {
85
+ if (search.normalizeQuery(query) === '') return null
86
+ if (search.matchesQuery(query, [entry.description])) {
87
+ return h('span', { className: 'ptQueryReason', title: '命中的是描述' }, search.markQuery(entry.description, query))
88
+ }
89
+ if (search.matchesQuery(query, [entry.title, entry.moduleName])) return null
90
+ const fields = [
91
+ search.matchesQuery(query, [entry.packageName]) ? '包名 ' + entry.packageName : null,
92
+ search.matchesQuery(query, [entry.rowId]) ? '组合行 ' + entry.rowId : null,
93
+ ].filter((value) => value !== null)
94
+ return fields.length === 0
95
+ ? null
96
+ : h('span', { className: 'ptQueryReason', title: '命中的是行里不显示的字面量' }, fields.join(' · '))
97
+ }
98
+
99
+ /**
100
+ * 单行渲染。
101
+ *
102
+ * 行内只保留「值得瞥一眼」的徽标:非默认来源、禁用、失败、条件、
103
+ * 缺服务、被覆盖、注册量。来源层与工具清单的完整信息在详情里。
104
+ * @param {object} props - 行属性。
105
+ * @returns {object} React 节点。
106
+ */
107
+ function Row(props) {
108
+ const { entry, selected, onSelect, snapshot, focused, byId, usage, activityStatus, activityError, control, sessions, reload, query } = props
109
+ const missing = entry.requires.filter((name) => (snapshot.services[name]?.providers ?? []).length === 0)
110
+ const tools = entry.registrations?.tools?.length ?? 0
111
+ const sections = (entry.registrations?.sections?.length ?? 0) + (entry.registrations?.contexts?.length ?? 0)
112
+ const expanded = selected || focused
113
+ const reason = rowReason(entry, query)
114
+
115
+ return h(
116
+ 'li',
117
+ null,
118
+ h(
119
+ 'button',
120
+ {
121
+ type: 'button',
122
+ className: 'ptRow',
123
+ 'data-selected': expanded ? 'true' : 'false',
124
+ 'data-off': entry.enabled ? 'false' : 'true',
125
+ 'data-failed': entry.phase === 'failed' ? 'true' : 'false',
126
+ 'aria-expanded': expanded ? 'true' : 'false',
127
+ onClick: () => onSelect(expanded ? null : entry.entryId),
128
+ },
129
+ h('span', { className: 'ptIndent', style: { width: `${entry.depth * 14}px` } }),
130
+ h('span', {
131
+ className: 'ptDot',
132
+ 'data-phase': entry.phase ?? 'none',
133
+ 'aria-label': `状态:${entry.phase ?? '无存活 fiber'}`,
134
+ role: 'img',
135
+ }),
136
+ h(
137
+ 'span',
138
+ { className: 'ptName' },
139
+ search.markQuery(shortName(entry), query),
140
+ h('span', { className: 'ptModule', style: { display: 'block' } }, search.markQuery(entry.moduleName, query)),
141
+ reason,
142
+ ),
143
+ NOTABLE_LAYERS.has(entry.layer)
144
+ ? h('span', { className: 'ptTag', title: `来源层:${entry.layer}` }, layerLabel(entry.layer))
145
+ : null,
146
+ entry.phase === 'failed' ? h('span', { className: 'ptTag', 'data-tone': 'error' }, '失败') : null,
147
+ !entry.enabled ? h('span', { className: 'ptTag', 'data-tone': 'warn' }, '已禁用') : null,
148
+ entry.disabledExpr ? h('span', { className: 'ptTag', 'data-tone': 'warn', title: '禁用条件:' + entry.disabledExpr }, '禁用条件') : null,
149
+ missing.length
150
+ ? h('span', { className: 'ptTag', 'data-tone': 'error', title: `缺 ${missing.length} 个服务:${missing.join('、')}` }, '缺 ' + missing.length)
151
+ : null,
152
+ entry.overriddenBy.length
153
+ ? h('span', { className: 'ptTag', 'data-tone': 'user', title: `覆盖来源:${entry.overriddenBy.join('、')}` }, '被覆盖')
154
+ : null,
155
+ // 注册量与活动是读数,不是状态:统一靠右,且不再用胶囊包数字。
156
+ rowEnd(
157
+ tools ? h('span', { className: 'ptCount', title: `注册了 ${tools} 个工具` }, '工具 ' + tools) : null,
158
+ sections ? h('span', { className: 'ptCount', title: `注册了 ${sections} 个提示词区块` }, '提示词段 ' + sections) : null,
159
+ activity?.renderUsageTags?.(usage) ?? null,
160
+ ),
161
+ ),
162
+ expanded
163
+ ? h(Detail, {
164
+ entry,
165
+ snapshot,
166
+ byId,
167
+ usage,
168
+ activityStatus,
169
+ activityError,
170
+ control,
171
+ sessions,
172
+ reload,
173
+ onOpenTool: props.onOpenTool,
174
+ onOpenSection: props.onOpenSection,
175
+ onOpenPlugin: props.onOpenPlugin,
176
+ anchorId: focused ? 'pt-focused' : undefined,
177
+ onClose: () => onSelect(null),
178
+ })
179
+ : null,
180
+ )
181
+ }
182
+
183
+ /** 选中行的若干段事实。 */
184
+ function Detail({ entry, snapshot, byId, onOpenTool, onOpenSection, onOpenPlugin, anchorId, onClose, usage, activityStatus, activityError, control, sessions, reload }) {
185
+ // 被跳转定位时把详情滚进视野。
186
+ //
187
+ // 展开发生在虚拟的高度里,浏览器不会自己滚动;而滚动容器不是 window,
188
+ // 是外层 .ptBody(overflow:auto)。所以用 scrollIntoView 并让它自己找容器。
189
+ useEffect(() => {
190
+ if (anchorId === undefined) return
191
+ const node = document.getElementById(anchorId)
192
+ if (node === null || typeof node.scrollIntoView !== 'function') return
193
+ node.scrollIntoView({ block: 'center', behavior: 'auto' })
194
+ }, [anchorId])
195
+
196
+ /** 服务里的运行时条目 id 渲染成可跳转的名字;对方不是插件时退回纯文本。 */
197
+ const linksOf = (ids) => ids.map((id, index) => {
198
+ const target = byId.get(id)
199
+ if (target === undefined) return h(React.Fragment, { key: id + index }, index === 0 ? null : '、', shortId(id, byId))
200
+ return h(
201
+ React.Fragment,
202
+ { key: id + index },
203
+ index === 0 ? null : '、',
204
+ h('button', {
205
+ type: 'button',
206
+ className: 'ptTag ptLink',
207
+ title: '在插件页展开 ' + (target.title || target.moduleName),
208
+ onClick: () => onOpenPlugin?.(target.rowId),
209
+ }, shortId(id, byId)),
210
+ )
211
+ })
212
+
213
+ const requires = entry.requires.map((name) => {
214
+ const providers = snapshot.services[name]?.providers ?? []
215
+ return {
216
+ key: name,
217
+ node: h(
218
+ React.Fragment,
219
+ null,
220
+ h('span', { className: 'ptDepKey' }, name),
221
+ h(
222
+ 'span',
223
+ { className: providers.length ? 'ptDepValue' : 'ptDepValue ptMissing' },
224
+ providers.length ? h(React.Fragment, null, '← ', linksOf(providers)) : '← 无提供者(停在 pending)',
225
+ ),
226
+ ),
227
+ }
228
+ })
229
+ const provides = entry.provides.map((name) => {
230
+ const consumers = snapshot.services[name]?.consumers ?? []
231
+ return {
232
+ key: name,
233
+ node: h(
234
+ React.Fragment,
235
+ null,
236
+ h('span', { className: 'ptDepKey' }, name),
237
+ h(
238
+ 'span',
239
+ { className: 'ptDepValue' },
240
+ consumers.length ? h(React.Fragment, null, '→ ', linksOf(consumers)) : '→ 无消费者',
241
+ ),
242
+ ),
243
+ }
244
+ })
245
+ const clientDeps = [...entry.clientInject, ...entry.clientExternal].map((name) => ({
246
+ key: name,
247
+ node: h(
248
+ React.Fragment,
249
+ null,
250
+ h('span', { className: 'ptDepKey' }, name),
251
+ h('span', { className: 'ptDepValue' }, '客户端模块依赖'),
252
+ ),
253
+ }))
254
+ const hasServices = requires.length + provides.length + clientDeps.length > 0
255
+ // 客户端模块不是 host 服务,不能并进「需要」;但在标题里单独计数,
256
+ // 读者才不会以为这一板块只有服务供需两类。
257
+ const serviceCounts = `需要 ${requires.length} · 提供 ${provides.length}${clientDeps.length > 0 ? ` · 客户端 ${clientDeps.length}` : ''}`
258
+ const regs = entry.registrations ?? {}
259
+ const regTools = regs.tools ?? []
260
+ const regSections = [...(regs.sections ?? []), ...(regs.contexts ?? [])]
261
+ // 配置值直接来自快照(options.config);旧快照只有字段名时退回名字列表。
262
+ const configRows = Array.isArray(entry.configEntries) ? entry.configEntries : []
263
+ const configNode = configRows.length
264
+ ? h(
265
+ 'ul',
266
+ { className: 'ptConfigList' },
267
+ configRows.map((row) => h(
268
+ 'li',
269
+ { key: row.key },
270
+ h('code', { className: 'ptConfigKey' }, row.key),
271
+ h('span', { className: 'ptConfigEquals' }, '='),
272
+ h('code', { className: 'ptConfigValue' }, row.value),
273
+ )),
274
+ )
275
+ : (entry.configKeys?.length ? h('code', null, entry.configKeys.join(', ')) : null)
276
+
277
+ // 控制是唯一会写宿主状态的一段:先算好节点,再和分隔线一起放到最后。
278
+ const controlNode = control?.renderControlSection?.(entry, { control, sessions, reload }) ?? null
279
+
280
+ return h(
281
+ 'div',
282
+ { className: 'ptDetail', id: anchorId ?? undefined },
283
+ h('div', { className: 'ptDetailClose' }, textButton('收起', onClose)),
284
+ h(
285
+ 'div',
286
+ { className: 'ptDetailGrid' },
287
+ h(
288
+ 'div',
289
+ { className: 'ptSection' },
290
+ h('p', { className: 'ptSectionTitle' }, '基本信息'),
291
+ entry.modeOnly
292
+ ? h('p', { className: 'ptSub' }, `只由模式挂载(${(entry.modeIds ?? []).join('、')}),没有自己的 Loader 行;工具与提示词来自源码扫描。`)
293
+ : null,
294
+ h(
295
+ 'dl',
296
+ { className: 'ptFacts' },
297
+ fact('组合行 id', h('code', null, entry.rowId), FACT_TIPS.rowId),
298
+ entry.entryId !== entry.rowId ? fact('运行时 id', h('code', null, entry.entryId), FACT_TIPS.entryId) : null,
299
+ fact('加载序', typeof entry.loadIndex === 'number' ? '#' + (entry.loadIndex + 1) + '(Loader 声明顺序)' : null, FACT_TIPS.loadIndex),
300
+ fact('模块', h('code', null, entry.moduleName), FACT_TIPS.module),
301
+ fact('包名', entry.packageName ? h('code', null, entry.packageName) : null, FACT_TIPS.packageName),
302
+ fact('版本', entry.version, FACT_TIPS.version),
303
+ fact('包目录', entry.packageDir ? h('code', null, entry.packageDir) : null, FACT_TIPS.packageDir),
304
+ fact('面', entry.face === 'both' ? 'host + client(双面)' : 'host', FACT_TIPS.face),
305
+ fact('描述', entry.description, FACT_TIPS.description),
306
+ entry.metaError ? fact('元信息诊断', h('span', { className: 'ptError' }, entry.metaError), FACT_TIPS.metaError) : null,
307
+ ),
308
+ ),
309
+ h(
310
+ 'div',
311
+ { className: 'ptSection' },
312
+ h('p', { className: 'ptSectionTitle' }, '状态'),
313
+ h(
314
+ 'dl',
315
+ { className: 'ptFacts' },
316
+ fact('有效启用', entry.enabled ? '是' : '否', FACT_TIPS.enabled),
317
+ entry.inheritedDisabled ? fact('禁用来源', '祖先 group 被禁用', FACT_TIPS.inheritedDisabled) : null,
318
+ entry.disabledExpr ? fact('禁用表达式', h('code', null, entry.disabledExpr), FACT_TIPS.disabledExpr) : null,
319
+ entry.disabledExpr ? fact('表达式求值', entry.disabledValue ? 'true(禁用)' : 'false(启用)', FACT_TIPS.disabledValue) : null,
320
+ fact('fiber 阶段', entry.phase ?? '无存活 fiber', FACT_TIPS.phase),
321
+ entry.diagnostic ? fact('失败诊断', h('span', { className: 'ptError' }, entry.diagnostic), FACT_TIPS.diagnostic) : null,
322
+ configNode ? fact('配置字段', configNode, FACT_TIPS.config) : null,
323
+ ),
324
+ ),
325
+ h(
326
+ 'div',
327
+ { className: 'ptSection' },
328
+ h('p', { className: 'ptSectionTitle' }, '组合链(加载与覆盖)'),
329
+ h(
330
+ 'div',
331
+ { className: 'ptFlow' },
332
+ h('div', { className: 'ptFlowStep', title: FACT_TIPS.source }, h('span', { className: 'ptFlowKey' }, '来源'), h('span', { className: 'ptFlowValue' }, entry.userInserted ? 'profile patch 插入' : layerLabel(entry.layer))),
333
+ h('div', { className: 'ptFlowStep', title: FACT_TIPS.layerVersion }, h('span', { className: 'ptFlowKey' }, '层版本'), h('span', { className: 'ptFlowValue' }, entry.layerVersion ? `${layerLabel(entry.layer)}@${entry.layerVersion}` : layerLabel(entry.layer))),
334
+ h('div', { className: 'ptFlowStep', title: FACT_TIPS.rowId }, h('span', { className: 'ptFlowKey' }, '组合行 id'), h('span', { className: 'ptFlowValue' }, entry.rowId)),
335
+ h('div', { className: 'ptFlowStep', title: FACT_TIPS.entryId }, h('span', { className: 'ptFlowKey' }, '运行时 id'), h('span', { className: 'ptFlowValue' }, entry.entryId, typeof entry.loadIndex === 'number' ? h('span', { title: FACT_TIPS.loadIndex }, `(加载序 #${entry.loadIndex + 1})`) : null)),
336
+ entry.overriddenBy.length
337
+ ? h('div', { className: 'ptFlowStep', 'data-tone': 'muted', title: FACT_TIPS.override }, h('span', { className: 'ptFlowKey' }, '覆盖'), h('span', { className: 'ptFlowValue' }, entry.overriddenBy.join(' → ')))
338
+ : null,
339
+ ),
340
+ ),
341
+ h(
342
+ 'div',
343
+ { className: 'ptSection' },
344
+ h('p', { className: 'ptSectionTitle' }, `依赖与提供(${serviceCounts})`),
345
+ hasServices
346
+ ? h(
347
+ React.Fragment,
348
+ null,
349
+ requires.length ? h('p', { className: 'ptSub', style: { margin: 0 }, title: FACT_TIPS.requires }, '需要(inject)') : null,
350
+ requires.length ? depList(requires) : null,
351
+ provides.length ? h('p', { className: 'ptSub', style: { margin: 0 }, title: FACT_TIPS.provides }, '提供(provisions)') : null,
352
+ provides.length ? depList(provides) : null,
353
+ clientDeps.length ? h('p', { className: 'ptSub', style: { margin: 0 }, title: FACT_TIPS.clientDeps }, '客户端模块') : null,
354
+ clientDeps.length ? depList(clientDeps) : null,
355
+ )
356
+ : h('p', { className: 'ptSub', style: { margin: 0 } }, '没有任何依赖、客户端模块或提供项。'),
357
+ ),
358
+ // 先给「它给了你什么」(注册项),再给框架层的「行为」记录;后者更抽象。
359
+ regTools.length + regSections.length
360
+ ? h(
361
+ 'div',
362
+ { className: 'ptSection' },
363
+ h('p', { className: 'ptSectionTitle' }, `注册的工具与提示词(${regTools.length + regSections.length})`),
364
+ regTools.length
365
+ ? h(
366
+ 'div',
367
+ { className: 'ptChipGroup' },
368
+ h('span', { className: 'ptSub' }, `工具 ${regTools.length}`),
369
+ regTools.map((name) => h(
370
+ 'button',
371
+ { key: name, type: 'button', className: 'ptTag ptLink', title: '在「工具」页查看该工具', onClick: () => onOpenTool(name) },
372
+ name,
373
+ )),
374
+ )
375
+ : null,
376
+ regSections.length
377
+ ? h(
378
+ 'div',
379
+ { className: 'ptChipGroup' },
380
+ h('span', { className: 'ptSub' }, `提示词区块 ${regSections.length}`),
381
+ regSections.map((name) => h(
382
+ 'button',
383
+ { key: name, type: 'button', className: 'ptTag ptLink', title: '在「提示词」页查看该段落', onClick: () => onOpenSection(name) },
384
+ name,
385
+ )),
386
+ )
387
+ : null,
388
+ )
389
+ : null,
390
+ h(
391
+ 'div',
392
+ { className: 'ptSection' },
393
+ h('p', { className: 'ptSectionTitle', title: FACT_TIPS.behavior }, `行为(${entry.effects?.length ?? 0})`),
394
+ effects.effectsList(entry.effects ?? []),
395
+ ),
396
+ // 观测在读事实之后:先知道它注册了什么,再看最近 7 天实际被调用了多少。
397
+ activity?.renderPluginActivity?.(entry, usage, activityStatus, activityError) ?? null,
398
+ controlNode === null
399
+ ? null
400
+ : h(React.Fragment, null, h('hr', { className: 'ptDivider' }), controlNode),
401
+ ),
402
+ )
403
+ }
404
+
405
+ /**
406
+ * 插件视图正文:按类别分组,让「base 注入了什么」这类问题一眼可答。
407
+ * 分类说明挂在分组标题的 `title` 上,不再单独占一个可折叠块。
408
+ * @param {object} vc - 视图上下文。
409
+ * @returns {object} React 节点。
410
+ */
411
+ function renderPluginsView(vc) {
412
+ const { filtered, collapsedCategories, setCollapsedCategories, selected, setSelected, snapshot, byId, gotoTool, gotoSection, clearPluginFilters, query, categories } = vc
413
+ // 变更条是全局诊断,不随当前搜索/筛选消失。
414
+ const changeBar = changes?.renderChanges?.(vc) ?? null
415
+ const searching = search.normalizeQuery(query) !== ''
416
+ const totals = new Map((categories ?? []).map((item) => [item.id, item.count]))
417
+
418
+ if (!filtered.length) {
419
+ return h(
420
+ React.Fragment,
421
+ null,
422
+ changeBar,
423
+ h(
424
+ 'div',
425
+ { className: 'ptEmpty' },
426
+ '没有匹配的插件。',
427
+ h('div', { style: { marginTop: '10px' } }, textButton('清除筛选', clearPluginFilters)),
428
+ ),
429
+ )
430
+ }
431
+ const groups = new Map()
432
+ for (const entry of filtered) {
433
+ const list = groups.get(entry.category) ?? []
434
+ list.push(entry)
435
+ groups.set(entry.category, list)
436
+ }
437
+ return h(
438
+ React.Fragment,
439
+ null,
440
+ changeBar,
441
+ [...groups.entries()]
442
+ .sort((left, right) => right[1].length - left[1].length)
443
+ .map(([id, list]) => {
444
+ // 搜索激活时忽略折叠:把命中藏在收起的组里,页面看起来就是空的。
445
+ const open = searching || !collapsedCategories.has(id)
446
+ const total = totals.get(id) ?? list.length
447
+ return h(
448
+ 'section',
449
+ { key: id },
450
+ h(
451
+ 'div',
452
+ {
453
+ className: searching ? 'ptGroupHead' : 'ptGroupHead ptGroupHeadClickable',
454
+ role: searching ? undefined : 'button',
455
+ tabIndex: searching ? undefined : 0,
456
+ title: CATEGORY_NOTES[id] ?? '每个插件只归一类:先看它实际注册的工具/提示词,再看包名职责',
457
+ 'aria-expanded': open ? 'true' : 'false',
458
+ onClick: searching ? undefined : () => toggleIn(setCollapsedCategories, id),
459
+ onKeyDown: searching ? undefined : (event) => activateOnKey(event, () => toggleIn(setCollapsedCategories, id)),
460
+ },
461
+ h('span', { className: 'ptChevron', 'data-open': open ? 'true' : 'false' }, '▶'),
462
+ h('span', null, CATEGORY_LABELS[id] ?? id),
463
+ h(
464
+ 'span',
465
+ { className: 'ptCount', title: searching ? '筛选中:命中数 / 这一类在筛选前的总数' : undefined },
466
+ searching ? `${list.length} / ${total} 个` : `${list.length} 个`,
467
+ ),
468
+ ),
469
+ open
470
+ ? h(
471
+ 'ul',
472
+ { className: 'ptList' },
473
+ list.map((entry) =>
474
+ h(Row, {
475
+ key: entry.entryId,
476
+ entry,
477
+ query,
478
+ snapshot,
479
+ byId,
480
+ usage: activity?.pluginUsage?.(entry, vc.activity),
481
+ activityStatus: vc.activityStatus,
482
+ activityError: vc.activityError,
483
+ control: vc.control,
484
+ sessions: [...(vc.allSessions?.values?.() ?? [])],
485
+ reload: vc.load,
486
+ selected: selected === entry.entryId || selected === 'row:' + entry.rowId,
487
+ focused: selected === 'row:' + entry.rowId,
488
+ onSelect: setSelected,
489
+ onOpenTool: gotoTool,
490
+ onOpenSection: gotoSection,
491
+ onOpenPlugin: vc.gotoPlugin,
492
+ }),
493
+ ),
494
+ )
495
+ : null,
496
+ )
497
+ }),
498
+ )
499
+ }
500
+
501
+ return { Row, Detail, renderPluginsView }
502
+ }
503
+ },
504
+ })