@cheemsup/dsh-plugin-console 0.0.0-stage → 0.2.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.
Files changed (101) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +95 -3
  3. package/cordis.patch.yml +5 -0
  4. package/icon.svg +203 -0
  5. package/lib/client.activity.js +222 -0
  6. package/lib/client.apply.js +171 -0
  7. package/lib/client.changes.js +206 -0
  8. package/lib/client.cleanup.js +270 -0
  9. package/lib/client.control.js +247 -0
  10. package/lib/client.dialog.js +77 -0
  11. package/lib/client.disable-preview.js +904 -0
  12. package/lib/client.draft.js +280 -0
  13. package/lib/client.editor-messages.js +421 -0
  14. package/lib/client.editor-store.js +266 -0
  15. package/lib/client.editor.js +433 -0
  16. package/lib/client.effects.js +115 -0
  17. package/lib/client.impact-tree.js +487 -0
  18. package/lib/client.influence.js +361 -0
  19. package/lib/client.js +246 -0
  20. package/lib/client.page.js +646 -0
  21. package/lib/client.plugin-filters.js +62 -0
  22. package/lib/client.plugins.js +506 -0
  23. package/lib/client.preview-messages.js +506 -0
  24. package/lib/client.preview-raw.js +132 -0
  25. package/lib/client.preview-store.js +128 -0
  26. package/lib/client.preview-tools.js +194 -0
  27. package/lib/client.preview.js +448 -0
  28. package/lib/client.relation-graph.js +364 -0
  29. package/lib/client.schema.js +327 -0
  30. package/lib/client.search.js +409 -0
  31. package/lib/client.session-detail.js +503 -0
  32. package/lib/client.sessions.js +495 -0
  33. package/lib/client.shared.js +562 -0
  34. package/lib/client.store.js +452 -0
  35. package/lib/client.styles.js +589 -0
  36. package/lib/client.template-card.js +240 -0
  37. package/lib/client.tools.js +366 -0
  38. package/lib/client.workspace-picker.js +204 -0
  39. package/lib/host/activity.js +252 -0
  40. package/lib/host/assembly-preview.js +244 -0
  41. package/lib/host/attribution.js +341 -0
  42. package/lib/host/catalog.js +133 -0
  43. package/lib/host/categorize.js +40 -0
  44. package/lib/host/config-layers.js +589 -0
  45. package/lib/host/constants.js +69 -0
  46. package/lib/host/control.js +159 -0
  47. package/lib/host/disable-preview.js +651 -0
  48. package/lib/host/entries.js +289 -0
  49. package/lib/host/fiber.js +86 -0
  50. package/lib/host/fs.js +99 -0
  51. package/lib/host/health.js +178 -0
  52. package/lib/host/http.js +65 -0
  53. package/lib/host/impact.js +138 -0
  54. package/lib/host/injection-owners.js +60 -0
  55. package/lib/host/layers.js +132 -0
  56. package/lib/host/masks.js +145 -0
  57. package/lib/host/modes.js +96 -0
  58. package/lib/host/names.js +44 -0
  59. package/lib/host/patch-config.js +554 -0
  60. package/lib/host/patch-scan.js +103 -0
  61. package/lib/host/preview-conditions.js +281 -0
  62. package/lib/host/preview-contexts.js +174 -0
  63. package/lib/host/preview-envelope.js +31 -0
  64. package/lib/host/preview-instructions.js +450 -0
  65. package/lib/host/preview-messages.js +284 -0
  66. package/lib/host/preview-modules.js +233 -0
  67. package/lib/host/preview-skills.js +200 -0
  68. package/lib/host/prompt.js +213 -0
  69. package/lib/host/recipe-overlay.js +209 -0
  70. package/lib/host/request-preview.js +114 -0
  71. package/lib/host/routes/activation.js +96 -0
  72. package/lib/host/routes/activity.js +22 -0
  73. package/lib/host/routes/apply.js +93 -0
  74. package/lib/host/routes/cleanup.js +62 -0
  75. package/lib/host/routes/control.js +22 -0
  76. package/lib/host/routes/disable-preview.js +19 -0
  77. package/lib/host/routes/impact.js +19 -0
  78. package/lib/host/routes/operations.js +22 -0
  79. package/lib/host/routes/preview.js +58 -0
  80. package/lib/host/routes/session-influence.js +23 -0
  81. package/lib/host/routes/snapshot.js +21 -0
  82. package/lib/host/routes/template.js +54 -0
  83. package/lib/host/routes/templates.js +28 -0
  84. package/lib/host/scope-impact.js +125 -0
  85. package/lib/host/session-events.js +39 -0
  86. package/lib/host/session-influence.js +467 -0
  87. package/lib/host/sessions.js +293 -0
  88. package/lib/host/snapshot.js +218 -0
  89. package/lib/host/source-scan.js +225 -0
  90. package/lib/host/templates/cleanup.js +219 -0
  91. package/lib/host/templates/inheritance.js +144 -0
  92. package/lib/host/templates/materialize.js +317 -0
  93. package/lib/host/templates/message-overlay.js +184 -0
  94. package/lib/host/templates/repository.js +323 -0
  95. package/lib/host/templates/store.js +131 -0
  96. package/lib/host/tool-set.js +150 -0
  97. package/lib/host/tools.js +129 -0
  98. package/lib/index.js +106 -0
  99. package/locale/en.json +6 -0
  100. package/locale/zh.json +6 -0
  101. package/package.json +124 -6
@@ -0,0 +1,503 @@
1
+ /**
2
+ * 会话展开后的详情:追溯链、提示词定制模板绑定、本会话已挂载,以及实际请求摘要。
3
+ *
4
+ * 这些内容与「会话列表行」分开,是因为它们都在回答「这一行背后是什么」:
5
+ * - 追溯链:全局插件 ← 模式要求的插件 ← 本会话已挂载;
6
+ * - 提示词定制模板绑定:上面看这份配方改了什么,下面放开关与本会话清理;
7
+ * - 本会话已挂载:本进程真正 ACTIVE 的模块;
8
+ * - 实际请求:来自 session log 的最终构造。
9
+ *
10
+ * 本文件是一个包内 chunk:入口用 `require.async('./client.session-detail.js')` 取它。
11
+ */
12
+
13
+ window.__ModuleLoader__.load({
14
+ id: '@cheemsup/dsh-plugin-console',
15
+ chunk: 'client.session-detail.js',
16
+ factory: (require) => {
17
+ const React = require('react')
18
+ const { createElement: h } = React
19
+
20
+ return function create(deps) {
21
+ const { modeTitle, shortModule, switchButton, textButton, influence } = deps
22
+
23
+ /**
24
+ * 会话绑定的提示词模板怎么显示。
25
+ * @param {object} binding - 会话的提示词模板绑定。
26
+ * @returns {string} 展示用的提示词模板名。
27
+ */
28
+ function templateLabelOf(binding) {
29
+ if (typeof binding.templateName === 'string' && binding.templateName.length > 0) return binding.templateName
30
+ if (typeof binding.templateId === 'string' && binding.templateId.length > 0) {
31
+ const id = binding.templateId
32
+ const shown = id.length <= 16 ? id : id.slice(0, 12) + '…'
33
+ // 调用处已经写了「提示词定制模板」前缀,这里再带一次会读成两遍模板。
34
+ return '已删除(' + shown + ')'
35
+ }
36
+ return '已删除'
37
+ }
38
+
39
+ /**
40
+ * 一份已应用配方的改动清单。
41
+ *
42
+ * manifest 里存的是**差异**而不是全文:追加的段落、被改写的段落(完整新文本)、
43
+ * 被禁用的工具。空字符串的改写表示把这一段清空,不是「没改」。
44
+ * @param {object} recipe - 会话 manifest 里的配方。
45
+ * @returns {{append: string, overrides: Array<[string, string]>, disabled: string[], empty: boolean}} 改动清单。
46
+ */
47
+ function changesOf(recipe) {
48
+ const prompt = recipe?.prompt ?? {}
49
+ const append = typeof prompt.appendText === 'string' ? prompt.appendText : ''
50
+ const overrides = Object.entries(prompt.sectionOverrides ?? {})
51
+ .filter(([, text]) => typeof text === 'string')
52
+ const disabled = (Array.isArray(recipe?.tools?.disabled) ? recipe.tools.disabled : [])
53
+ .filter((name) => typeof name === 'string')
54
+ const contexts = Object.entries(recipe?.contexts ?? {})
55
+ .filter(([, text]) => typeof text === 'string')
56
+ const messages = Object.entries(recipe?.messages ?? {})
57
+ .filter(([, spec]) => spec !== null && typeof spec === 'object')
58
+ return {
59
+ append,
60
+ overrides,
61
+ disabled,
62
+ contexts,
63
+ messages,
64
+ empty: append.length === 0 && overrides.length === 0 && disabled.length === 0
65
+ && contexts.length === 0 && messages.length === 0,
66
+ }
67
+ }
68
+
69
+ /** 一条消息覆盖的界面说法。 */
70
+ function messageAction(spec) {
71
+ if (spec?.hidden === true) return '隐藏整条'
72
+ if (typeof spec?.text === 'string') return '整段改写'
73
+ if (Array.isArray(spec?.hiddenEntries) || spec?.descriptions !== undefined) return '目录条目调整'
74
+ return '覆盖'
75
+ }
76
+
77
+ /** 折叠头右侧的结论:改了几段、禁了几个工具,让人不展开也能判断值不值得看。 */
78
+ function changesSummary(changes) {
79
+ const parts = []
80
+ if (changes.append.length > 0) parts.push('追加 1 段')
81
+ if (changes.overrides.length > 0) parts.push('改写 ' + changes.overrides.length + ' 段')
82
+ if (changes.disabled.length > 0) parts.push('禁用 ' + changes.disabled.length + ' 个工具')
83
+ if (changes.contexts.length > 0) parts.push('上下文 ' + changes.contexts.length + ' 段')
84
+ if (changes.messages.length > 0) parts.push('消息 ' + changes.messages.length + ' 项')
85
+ return parts.length === 0 ? '无改动' : parts.join(' · ')
86
+ }
87
+
88
+ /**
89
+ * 信息区:这份提示词模板对会话做了什么改动。
90
+ *
91
+ * 默认收起。它回答「这个会话的提示词/工具为什么和别的不一样」,属于诊断信息;
92
+ * 开关与清理是操作,单独放一行——说明和动作混在一起时,动作会被读成说明的一部分。
93
+ * @param {object} binding - 会话的提示词模板绑定。
94
+ * @returns {object} React 节点。
95
+ */
96
+ function changesBlock(binding) {
97
+ const changes = changesOf(binding.recipe)
98
+ return h(
99
+ 'details',
100
+ { className: 'ptFold ptFoldable' },
101
+ h(
102
+ 'summary',
103
+ null,
104
+ h('span', null, '应用的改动'),
105
+ h('span', { className: 'ptFoldMeta' }, changesSummary(changes)),
106
+ ),
107
+ h(
108
+ 'div',
109
+ { className: 'ptFoldBody ptChangeList' },
110
+ changes.append.length > 0
111
+ ? h(
112
+ 'div',
113
+ { className: 'ptSubSection' },
114
+ h('p', { className: 'ptSubTitle' }, '追加的提示词段落'),
115
+ h('pre', { className: 'ptChangeText' }, changes.append),
116
+ )
117
+ : null,
118
+ changes.overrides.length > 0
119
+ ? h(
120
+ 'div',
121
+ { className: 'ptSubSection' },
122
+ h('p', { className: 'ptSubTitle' }, '改写的提示词段(' + changes.overrides.length + ')'),
123
+ changes.overrides.map(([name, text]) =>
124
+ h(
125
+ 'details',
126
+ { key: name, className: 'ptFold' },
127
+ h(
128
+ 'summary',
129
+ null,
130
+ h('span', { className: 'ptPromptName' }, name),
131
+ h('span', { className: 'ptFoldMeta' }, text.length === 0 ? '隐藏该段' : text.length + ' 字'),
132
+ ),
133
+ text.length === 0
134
+ ? h('p', { className: 'ptSectionNote', style: { padding: '8px 12px' } }, '这一段的文本被清空,模型不再收到它。')
135
+ : h('pre', { className: 'ptChangeText', style: { margin: '8px 12px' } }, text),
136
+ ),
137
+ ),
138
+ )
139
+ : null,
140
+ changes.contexts.length > 0
141
+ ? h(
142
+ 'div',
143
+ { className: 'ptSubSection' },
144
+ h('p', { className: 'ptSubTitle' }, '改写的运行时上下文(' + changes.contexts.length + ')'),
145
+ h(
146
+ 'ul',
147
+ { className: 'ptDepList' },
148
+ changes.contexts.map(([name, text]) => h(
149
+ 'li',
150
+ { key: name },
151
+ h('span', { className: 'ptDepKey' }, name),
152
+ h('span', { className: 'ptCount', style: { marginLeft: '6px' } }, text.length === 0 ? '隐藏该段' : text.length + ' 字'),
153
+ )),
154
+ ),
155
+ )
156
+ : null,
157
+ changes.messages.length > 0
158
+ ? h(
159
+ 'div',
160
+ { className: 'ptSubSection' },
161
+ h('p', { className: 'ptSubTitle' }, '改写的消息(' + changes.messages.length + ')'),
162
+ h(
163
+ 'ul',
164
+ { className: 'ptDepList' },
165
+ changes.messages.map(([kind, spec]) => h(
166
+ 'li',
167
+ { key: kind },
168
+ h('span', { className: 'ptDepKey' }, kind),
169
+ h('span', { className: 'ptCount', style: { marginLeft: '6px' } }, messageAction(spec)),
170
+ )),
171
+ ),
172
+ )
173
+ : null,
174
+ changes.disabled.length > 0
175
+ ? h(
176
+ 'div',
177
+ { className: 'ptSubSection' },
178
+ h('p', { className: 'ptSubTitle' }, '禁用的工具(' + changes.disabled.length + ')'),
179
+ h(
180
+ 'ul',
181
+ { className: 'ptDepList' },
182
+ changes.disabled.map((name) => h('li', { key: name }, h('span', { className: 'ptDepKey' }, name))),
183
+ ),
184
+ )
185
+ : null,
186
+ changes.empty
187
+ ? h('p', { className: 'ptSectionNote' }, '这份配方没有改动任何提示词段或工具,应用后与基础组合一致。')
188
+ : null,
189
+ ),
190
+ )
191
+ }
192
+
193
+ /**
194
+ * 快照语义:绑定来自哪、和谁隔离。
195
+ *
196
+ * 这两句解释的是整段绑定的性质,不属于某一条改动,所以不再占用正文一行,
197
+ * 收进标题的 `title`:`.ptSectionTitle[title]` 会给出 help 光标,悬停才展开。
198
+ * 子 Agent 比普通会话多一句继承来源,换行后由原生 tooltip 分行显示。
199
+ * @param {object} binding - 会话的提示词模板绑定。
200
+ * @returns {string} 悬停说明。
201
+ */
202
+ function snapshotNoteText(binding) {
203
+ const notes = [typeof binding.templateName === 'string'
204
+ ? '本会话使用的是提示词定制模板的复制快照,彼此相互隔离'
205
+ : '模板定义已删除;这份配方随会话保留,仍可开关。']
206
+ if (typeof binding.inheritedFrom === 'string') {
207
+ notes.push('本会话模板快照从父会话 ' + binding.inheritedFrom + ' 复制继承')
208
+ }
209
+ return notes.join('\n')
210
+ }
211
+
212
+ /**
213
+ * 一次确认弹窗。
214
+ *
215
+ * 用 fixed 覆盖层而不是面板内的卡片:确认要打断当前动作,留在文流里容易被当成
216
+ * 又一段说明滚过去。Esc、点遮罩与「取消」都算取消,默认焦点落在取消上——
217
+ * 这两个动作都有账单或删除代价,不该一按回车就执行。
218
+ * @param {string} id - 标题节点 id,供 `aria-labelledby` 引用。
219
+ * @param {string} title - 要确认的问题。
220
+ * @param {string} detail - 代价与影响的说明。
221
+ * @param {string} confirmLabel - 确认按钮文字。
222
+ * @param {Function} onConfirm - 确认回调。
223
+ * @param {Function} onCancel - 取消回调。
224
+ * @param {object} [opts] - `{ disabled }`。
225
+ * @returns {object} React 节点。
226
+ */
227
+ function confirmDialog(id, title, detail, confirmLabel, onConfirm, onCancel, opts) {
228
+ return h(
229
+ 'div',
230
+ {
231
+ className: 'ptModalOverlay',
232
+ onClick: onCancel,
233
+ onKeyDown: (event) => {
234
+ if (event.key === 'Escape') onCancel()
235
+ },
236
+ },
237
+ h(
238
+ 'div',
239
+ {
240
+ className: 'ptModal',
241
+ role: 'dialog',
242
+ 'aria-modal': 'true',
243
+ 'aria-labelledby': id,
244
+ onClick: (event) => event.stopPropagation(),
245
+ },
246
+ h('p', { className: 'ptModalTitle', id }, title),
247
+ h('p', { className: 'ptHint', style: { margin: 0 } }, detail),
248
+ h(
249
+ 'div',
250
+ { className: 'ptModalActions' },
251
+ h('button', { type: 'button', className: 'ptBtn', autoFocus: true, onClick: onCancel }, '取消'),
252
+ h(
253
+ 'button',
254
+ { type: 'button', className: 'ptBtn', 'data-tone': 'danger', disabled: opts?.disabled === true, onClick: onConfirm },
255
+ confirmLabel,
256
+ ),
257
+ ),
258
+ ),
259
+ )
260
+ }
261
+
262
+ /**
263
+ * 开关前的二次确认。
264
+ *
265
+ * 模板改的是请求体最前面的工具定义与系统提示词;缓存按前缀匹配,前缀一变,
266
+ * 后面全部失效,所以这次操作有直接的账单代价。这句话必须在发请求之前说。
267
+ * @param {object} session - 会话记录。
268
+ * @param {{enabled: boolean}} target - 待确认的目标状态。
269
+ * @param {boolean} busy - 是否有提交正在进行。
270
+ * @param {object} vc - 视图上下文。
271
+ * @returns {object} React 节点。
272
+ */
273
+ function activationConfirm(session, target, busy, vc) {
274
+ return confirmDialog(
275
+ 'pt-activation-confirm-title',
276
+ '开关模板可能影响提示词缓存,造成Token账单花费增加,是否继续?',
277
+ '模板改写的工具定义与系统提示词位于请求体最前面;开关会让这段前缀变化,缓存按前缀匹配,因此会整体失效。',
278
+ target.enabled ? '确认开启' : '确认关闭',
279
+ () => { void vc.toggleActivation(session.id, target.enabled, session.preset ?? null) },
280
+ vc.cancelActivation,
281
+ { disabled: busy },
282
+ )
283
+ }
284
+
285
+ /** 清理本会话绑定前的二次确认。 */
286
+ function cleanupConfirm(target, busy, vc) {
287
+ return confirmDialog(
288
+ 'pt-cleanup-confirm-title',
289
+ '删除这个会话的提示词定制模板绑定?',
290
+ '会删除绑定、开关与掩码;提示词模板定义与其他会话不受影响,运行中的注册也不受影响。',
291
+ '确认清理',
292
+ () => { void vc.runCleanup(target) },
293
+ vc.cancelCleanup,
294
+ { disabled: busy },
295
+ )
296
+ }
297
+
298
+ /**
299
+ * 会话的提示词定制模板绑定:上面是信息(改了什么),下面是操作(开关 + 本会话清理)。
300
+ *
301
+ * 开关只控制「提示词模板是否生效」;清理删除的是持久绑定本身。二者都在动
302
+ * 请求体最前面的装配前缀,所以开关先弹缓存代价的确认。
303
+ * @param {object} session - 会话记录。
304
+ * @param {object} vc - 视图上下文。
305
+ * @returns {object} React 节点。
306
+ */
307
+ function bindingSection(session, vc) {
308
+ const binding = (vc.snapshot?.bindings ?? {})[session.id]
309
+ const cleanupPending = vc.cleanupPending?.scope === 'session' && vc.cleanupPending.sessionId === session.id
310
+ const cleanupBusy = vc.cleanupBusy === 'session:' + session.id
311
+ const target = { scope: 'session', sessionId: session.id }
312
+
313
+ if (binding === undefined) {
314
+ return h(
315
+ 'div',
316
+ { className: 'ptSection' },
317
+ h('p', { className: 'ptSectionTitle' }, '提示词定制模板绑定'),
318
+ h('p', { className: 'ptSectionNote' }, '这个会话没有绑定提示词定制模板,不会应用任何提示词或工具改动'),
319
+ )
320
+ }
321
+
322
+ const toggling = vc.togglingSession?.get?.(session.id)
323
+ const toggleBusy = toggling !== undefined
324
+ const label = templateLabelOf(binding)
325
+ const activated = vc.activationPending?.sessionId === session.id ? vc.activationPending : null
326
+ return h(
327
+ 'div',
328
+ { className: 'ptSection' },
329
+ h('p', { className: 'ptSectionTitle', title: snapshotNoteText(binding) }, '提示词定制模板绑定'),
330
+ changesBlock(binding),
331
+ // 信息区是「改了什么」,下面是「能对它做什么」:一条 hairline 把读与写分开。
332
+ h('hr', { className: 'ptDivider' }),
333
+ // 操作区:开关与清理分成两行。破坏性动作不和主开关挤在同一行,
334
+ // 也为以后新增的会话级动作留出位置。
335
+ h(
336
+ 'div',
337
+ { className: 'ptBindingActions' },
338
+ h(
339
+ 'div',
340
+ { className: 'ptBindingRow', style: { padding: 0 } },
341
+ switchButton(binding.enabled, '提示词定制模板 ' + label, () => {
342
+ if (toggleBusy) return
343
+ vc.requestActivation(session.id, !binding.enabled, session.preset ?? null)
344
+ }, {
345
+ disabled: toggleBusy,
346
+ title: binding.enabled
347
+ ? '关闭后会话将不再应用相关提示词定制模板快照的改动行为'
348
+ : '打开会按绑定的提示词定制模板快照重新应用改动行为',
349
+ }),
350
+ toggleBusy
351
+ ? h('span', { className: 'ptMeta' }, toggling ? '开启中…' : '关闭中…')
352
+ : h('span', { className: 'ptMeta' }, binding.enabled ? (binding.materialized ? '注册生效中' : '登记为启用,当前无注册') : '基础组合'),
353
+ // 冷会话的生效时机与活会话不同,仍需写清楚;活会话的「下一步生效」
354
+ // 是恒定的实现细节,占一行反而不如不写。
355
+ session.live ? null : h('span', { className: 'ptMeta' }, '冷会话 · resume 时决定'),
356
+ ),
357
+ h(
358
+ 'div',
359
+ { className: 'ptBindingRow', style: { padding: 0 } },
360
+ textButton('清理本会话提示词模板', () => { vc.requestCleanup(target) }, {
361
+ tone: 'danger',
362
+ disabled: cleanupBusy,
363
+ title: '删除本会话绑定的提示词定制模板快照',
364
+ }),
365
+ ),
366
+ ),
367
+ binding.enabled
368
+ ? null
369
+ : h('p', { className: 'ptSectionNote' }, '提示词模板登记为未启用;打开后下一步重新注册。清理会删除这条持久绑定。'),
370
+ // 同一时刻只弹一个确认框。两个待确认状态正常不会同时存在,这里仍按优先级取舍。
371
+ activated !== null
372
+ ? activationConfirm(session, activated, toggleBusy, vc)
373
+ : cleanupPending
374
+ ? cleanupConfirm(target, cleanupBusy, vc)
375
+ : null,
376
+ )
377
+ }
378
+
379
+ /**
380
+ * 会话的插件组合:全局条目 → 模式要求的插件 → 本会话实际挂载。
381
+ *
382
+ * 不再单独列一节「本会话已挂载」:模式清单上的圆点已经表示每一行是否挂载,
383
+ * 唯一不在清单里的是全局层额外挂载的模块,作为一个小分组列在清单下方。
384
+ * @param {object} session - 会话记录。
385
+ * @param {Map<string, object>} presetsById - 模式索引。
386
+ * @param {object} vc - 视图上下文。
387
+ * @returns {object} React 节点。
388
+ */
389
+ function renderSessionTrace(session, presetsById, vc) {
390
+ const mode = presetsById.get(session.preset)
391
+ const runtime = session.runtime ?? null
392
+ const runtimeNames = new Set(runtime?.modules ?? [])
393
+ const declaredRows = mode?.rows ?? []
394
+
395
+ const resolved = declaredRows.map((row) => ({
396
+ row,
397
+ live: runtimeNames.has(row.moduleName),
398
+ }))
399
+ const declaredModules = new Set(declaredRows.map((row) => row.moduleName))
400
+ // 模式清单之外、却在本会话里活着的模块,只能来自全局层。
401
+ const fromGlobal = runtime === null ? [] : [...(runtime.modules ?? [])].filter((name) => !declaredModules.has(name))
402
+ // 没有模式清单也没有全局层额外模块时,不渲染空的子区块容器。
403
+ const hasCompositionDetail = mode !== undefined || fromGlobal.length > 0
404
+
405
+ return h(
406
+ 'div',
407
+ { className: 'ptDetail' },
408
+ // 与插件详情一致:展开的详情总是可以原地收起,不必回列表找一个已被滚走的行。
409
+ h('div', { className: 'ptDetailClose' }, textButton('收起', () => vc.setOpenSession(null))),
410
+ h(
411
+ 'div',
412
+ { className: 'ptSection' },
413
+ h(
414
+ 'p',
415
+ {
416
+ className: 'ptSectionTitle',
417
+ // 说明收进标题悬停:模式清单是声明值,这句话每行都读得到会盖过清单本身。
418
+ title: mode === undefined
419
+ ? undefined
420
+ : runtime === null
421
+ ? '本模式要求挂载的插件集,冷会话没有 fiber 所以不显示挂载状态、也无法判断运行时全局层是否注入其他模块'
422
+ : '本模式要求挂载的插件集以及挂载状态',
423
+ },
424
+ '插件组合',
425
+ ),
426
+ h(
427
+ 'div',
428
+ { className: 'ptChain' },
429
+ h('span', { className: 'ptTag' }, '全局插件'),
430
+ h('span', { className: 'ptChainArrow' }, '→'),
431
+ h('span', { className: 'ptTag' }, '模式 ' + labelOf(mode, session.preset)),
432
+ h('span', { className: 'ptChainArrow' }, '→'),
433
+ h('span', { className: 'ptTag', 'data-tone': runtime === null ? undefined : 'user' }, runtime === null ? '会话未激活' : '本会话'),
434
+ ),
435
+ mode === undefined
436
+ ? h('p', { className: 'ptSectionNote' }, '该会话记录的模式不在当前 roster 里,无法列出它要求的插件。')
437
+ : null,
438
+ runtime !== null && runtime.leakedServices.length
439
+ ? h('p', { className: 'ptSectionNote' }, h('span', { className: 'ptError' }, '服务泄漏:' + runtime.leakedServices.join('、')))
440
+ : null,
441
+ ),
442
+ hasCompositionDetail
443
+ ? h(
444
+ 'div',
445
+ { className: 'ptSubBlocks' },
446
+ mode !== undefined
447
+ ? h(
448
+ 'details',
449
+ { className: 'ptFold ptFoldable', open: declaredRows.length <= 12 ? true : undefined },
450
+ h(
451
+ 'summary',
452
+ null,
453
+ h('span', null, '模式要求的插件'),
454
+ h('span', { className: 'ptFoldMeta' }, declaredRows.length + ' 个'),
455
+ ),
456
+ h(
457
+ 'ul',
458
+ { className: 'ptDepList', style: { padding: '6px 12px 10px' } },
459
+ resolved.map(({ row, live }) =>
460
+ h(
461
+ 'li',
462
+ { key: row.entryId ?? row.moduleName },
463
+ runtime !== null
464
+ ? h('span', { className: 'ptDot', 'data-phase': live ? 'active' : 'none', role: 'img', 'aria-label': live ? '运行时已挂载' : '运行时未挂载' })
465
+ : null,
466
+ h('span', { className: 'ptDepKey' }, shortModule(row.moduleName)),
467
+ row.conditional ? h('span', { className: 'ptTag', 'data-tone': 'warn', title: row.condition === undefined || row.condition === '' ? '条件满足时才挂载' : '挂载条件:' + row.condition }, '条件挂载') : null,
468
+ live ? h('span', { className: 'ptTag', 'data-tone': 'user', title: '已挂载:会话运行时存在这个插件的 fiber' }, '已挂载') : null,
469
+ ),
470
+ ),
471
+ ),
472
+ )
473
+ : null,
474
+ fromGlobal.length
475
+ ? h(
476
+ 'div',
477
+ { className: 'ptSubSection' },
478
+ h('p', { className: 'ptSubTitle' }, '全局层额外挂载(' + fromGlobal.length + ')'),
479
+ h('p', { className: 'ptSectionNote' }, '这些模块不在上面的模式要求里,由全局层继承而来。'),
480
+ h(
481
+ 'ul',
482
+ { className: 'ptDepList' },
483
+ fromGlobal.map((name) => h('li', { key: name }, h('span', { className: 'ptDepKey' }, shortModule(name)))),
484
+ ),
485
+ )
486
+ : null,
487
+ )
488
+ : null,
489
+ bindingSection(session, vc),
490
+ influence?.renderSessionInfluence?.(session, vc) ?? null,
491
+ )
492
+ }
493
+
494
+ /** 模式展示名;roster 里没有时退回 id。 */
495
+ function labelOf(mode, fallback) {
496
+ if (mode !== undefined) return modeTitle(mode)
497
+ return typeof fallback === 'string' ? fallback : '未记录'
498
+ }
499
+
500
+ return { renderSessionTrace, templateLabelOf }
501
+ }
502
+ },
503
+ })