dsh-prompt-customizer 0.4.0 → 0.4.2

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,92 +1,92 @@
1
- /** 预览 Tab:两个只读子视图 —— 所有插件过滤后的最终装配系统提示词,
2
- * 以及当前定制(黑名单过滤之后)将注入的工具目录视图。
3
- * 两个视图都不修改配置。预览目标跟随面板顶部的编辑目标(`target`);
4
- * 数据直接来自 Panel 并行拉取的三阶段装配(`phases`)—— 与提示词/
5
- * 工具 Tab 同源(同一份 base + post 视图),杜绝三个视图数据不一致。
6
- * 阶段按钮恒为引导期 / 常驻期 / 压缩受控期三个(与另两个 Tab 同源同形)。 */
7
- import { createElement as h, useState, type ReactElement } from 'react'
8
- import type { PhaseViewKey, Preview } from './types.ts'
9
- import type { Translate } from './locales.ts'
10
- import { PART_ORDER } from './presets.ts'
11
- import { s } from './styles.ts'
12
- import { PreviewTools } from './PreviewTools.tsx'
13
-
14
- export function PreviewTab({ t, active, refreshId, target, version, phases }: {
15
- t: Translate
16
- active: boolean
17
- refreshId: number
18
- /** 顶部编辑目标:undefined = 全局(standard scope);字符串 = agent 预设 id。 */
19
- target: string | undefined
20
- /** 配置写入计数:Panel 每次成功写配置后 +1(驱动统一重载)。
21
- * ponytail: refreshId/version 由 Panel 的统一重载消费,本组件内未直接使用。 */
22
- version: number
23
- /** Panel 并行拉取的三阶段装配(模型视角统一数据源)。 */
24
- phases: Record<PhaseViewKey, Preview | null> | null
25
- }): ReactElement {
26
- const [sub, setSub] = useState<'prompt' | 'tools'>('prompt')
27
- const [phase, setPhase] = useState<PhaseViewKey>('bootstrap')
28
-
29
- const data = phases?.[phase] ?? null
30
- // 按当前所选阶段判定「段级定制没进最终提示词」:有 complete 段整段接管就说
31
- // 接管,否则探测本插件产出的段是否被下游丢弃(丢弃规则不止一种)。
32
- const lossNote = data === null || data === undefined ? null
33
- : data.takenOverBy !== undefined
34
- ? t('sectionsTakenOver', { name: data.takenOverBy })
35
- : data.lostSections !== undefined
36
- ? t('sectionsLost', { emitted: data.lostSections.emitted, survived: data.lostSections.survived })
37
- : null
38
-
39
- // 阶段按钮命名:引导期 / 常驻期 / 压缩受控期。
40
- const stageLabel = (p: PhaseViewKey): string =>
41
- p === 'bootstrap' ? t('phaseStageGuide') : p === 'compaction' ? t('phaseStageControlled') : t('phaseStageResident')
42
-
43
- return h('div', { style: s.list }, [
44
- h('div', { style: s.bar }, [
45
- h('button', { style: sub === 'prompt' ? s.tabActive : s.tab, onClick: () => setSub('prompt') }, t('previewPrompt')),
46
- h('button', { style: sub === 'tools' ? s.tabActive : s.tab, onClick: () => setSub('tools') }, t('previewTools')),
47
- h('div', { style: { marginLeft: 'auto', display: 'flex', gap: 4 } },
48
- PART_ORDER.map((key) => h('button', {
49
- key,
50
- style: phase === key ? s.tabActive : s.tab,
51
- onClick: () => setPhase(key),
52
- }, stageLabel(key)))),
53
- ]),
54
- // 该阶段的本插件段级产出没进最终提示词(整段接管或被下游丢弃)。
55
- lossNote !== null ? h('div', { style: s.noticeWarn }, lossNote) : null,
56
- // scope 挂载失败回退全局层时明确警示:这不是该预设的原生装配。
57
- data !== null && data.scopeResolved === false
58
- ? h('div', { style: s.noticeWarn }, t('scopeFallback'))
59
- : null,
60
- // 伪会话触发预设插件异常时本次预览降级为无会话装配(原生阶段规则未运行)。
61
- data !== null && data.degraded === true
62
- ? h('div', { style: s.noticeWarn }, t('previewDegraded'))
63
- : null,
64
- phases === null ? h('div', { style: s.muted }, t('loading')) : null,
65
- phases !== null && data === null
66
- ? h('div', { style: s.error }, t('previewFail'))
67
- : null,
68
- sub === 'prompt'
69
- ? data
70
- ? [
71
- h('div', { style: s.rowTitle }, [
72
- h('span', { style: s.muted }, t('previewHint')),
73
- h('span', { style: s.orderTag }, `${data.sections.length} ${t('previewSections')}`),
74
- ]),
75
- h('pre', { style: s.previewText }, data.text || t('empty')),
76
- ]
77
- : null
78
- : data
79
- ? [
80
- // 模型视角 vs 注册表视角的对照:预览按所选阶段运行全部装配规则
81
- // (含预设原生的阶段裁剪),某些预设(如 PTC / Code Mode)会把
82
- // 完整目录包装成单一工具,注册表原始目录仍列在工具 Tab。
83
- h('div', { style: s.rowTitle }, [
84
- h('span', { style: s.muted }, t('previewToolsHint')),
85
- h('span', { style: s.orderTag },
86
- `${data.tools.length} / ${data.registryTotal ?? '?'} ${t('previewToolsCount')}`),
87
- ]),
88
- h(PreviewTools, { tools: data.tools, t }),
89
- ]
90
- : null,
91
- ])
1
+ /** 预览 Tab:两个只读子视图 —— 所有插件过滤后的最终装配系统提示词,
2
+ * 以及当前定制(黑名单过滤之后)将注入的工具目录视图。
3
+ * 两个视图都不修改配置。预览目标跟随面板顶部的编辑目标(`target`);
4
+ * 数据直接来自 Panel 并行拉取的三阶段装配(`phases`)—— 与提示词/
5
+ * 工具 Tab 同源(同一份 base + post 视图),杜绝三个视图数据不一致。
6
+ * 阶段按钮恒为引导期 / 常驻期 / 压缩受控期三个(与另两个 Tab 同源同形)。 */
7
+ import { createElement as h, useState, type ReactElement } from 'react'
8
+ import type { PhaseViewKey, Preview } from './types.ts'
9
+ import type { Translate } from './locales.ts'
10
+ import { PART_ORDER } from './presets.ts'
11
+ import { s } from './styles.ts'
12
+ import { PreviewTools } from './PreviewTools.tsx'
13
+
14
+ export function PreviewTab({ t, active, refreshId, target, version, phases }: {
15
+ t: Translate
16
+ active: boolean
17
+ refreshId: number
18
+ /** 顶部编辑目标:undefined = 全局(standard scope);字符串 = agent 预设 id。 */
19
+ target: string | undefined
20
+ /** 配置写入计数:Panel 每次成功写配置后 +1(驱动统一重载)。
21
+ * ponytail: refreshId/version 由 Panel 的统一重载消费,本组件内未直接使用。 */
22
+ version: number
23
+ /** Panel 并行拉取的三阶段装配(模型视角统一数据源)。 */
24
+ phases: Record<PhaseViewKey, Preview | null> | null
25
+ }): ReactElement {
26
+ const [sub, setSub] = useState<'prompt' | 'tools'>('prompt')
27
+ const [phase, setPhase] = useState<PhaseViewKey>('bootstrap')
28
+
29
+ const data = phases?.[phase] ?? null
30
+ // 按当前所选阶段判定「段级定制没进最终提示词」:有 complete 段整段接管就说
31
+ // 接管,否则探测本插件产出的段是否被下游丢弃(丢弃规则不止一种)。
32
+ const lossNote = data === null || data === undefined ? null
33
+ : data.takenOverBy !== undefined
34
+ ? t('sectionsTakenOver', { name: data.takenOverBy })
35
+ : data.lostSections !== undefined
36
+ ? t('sectionsLost', { emitted: data.lostSections.emitted, survived: data.lostSections.survived })
37
+ : null
38
+
39
+ // 阶段按钮命名:引导期 / 常驻期 / 压缩受控期。
40
+ const stageLabel = (p: PhaseViewKey): string =>
41
+ p === 'bootstrap' ? t('phaseStageGuide') : p === 'compaction' ? t('phaseStageControlled') : t('phaseStageResident')
42
+
43
+ return h('div', { style: s.list }, [
44
+ h('div', { style: s.bar }, [
45
+ h('button', { style: sub === 'prompt' ? s.tabActive : s.tab, onClick: () => setSub('prompt') }, t('previewPrompt')),
46
+ h('button', { style: sub === 'tools' ? s.tabActive : s.tab, onClick: () => setSub('tools') }, t('previewTools')),
47
+ h('div', { style: { marginLeft: 'auto', display: 'flex', gap: 4 } },
48
+ PART_ORDER.map((key) => h('button', {
49
+ key,
50
+ style: phase === key ? s.tabActive : s.tab,
51
+ onClick: () => setPhase(key),
52
+ }, stageLabel(key)))),
53
+ ]),
54
+ // 该阶段的本插件段级产出没进最终提示词(整段接管或被下游丢弃)。
55
+ lossNote !== null ? h('div', { style: s.noticeWarn }, lossNote) : null,
56
+ // scope 挂载失败回退全局层时明确警示:这不是该预设的原生装配。
57
+ data !== null && data.scopeResolved === false
58
+ ? h('div', { style: s.noticeWarn }, t('scopeFallback'))
59
+ : null,
60
+ // 伪会话触发预设插件异常时本次预览降级为无会话装配(原生阶段规则未运行)。
61
+ data !== null && data.degraded === true
62
+ ? h('div', { style: s.noticeWarn }, t('previewDegraded'))
63
+ : null,
64
+ phases === null ? h('div', { style: s.muted }, t('loading')) : null,
65
+ phases !== null && data === null
66
+ ? h('div', { style: s.error }, t('previewFail'))
67
+ : null,
68
+ sub === 'prompt'
69
+ ? data
70
+ ? [
71
+ h('div', { style: s.rowTitle }, [
72
+ h('span', { style: s.muted }, t('previewHint')),
73
+ h('span', { style: s.orderTag }, `${data.sections.length} ${t('previewSections')}`),
74
+ ]),
75
+ h('pre', { style: s.previewText }, data.text || t('empty')),
76
+ ]
77
+ : null
78
+ : data
79
+ ? [
80
+ // 模型视角 vs 注册表视角的对照:预览按所选阶段运行全部装配规则
81
+ // (含预设原生的阶段裁剪),某些预设(如 PTC / Code Mode)会把
82
+ // 完整目录包装成单一工具,注册表原始目录仍列在工具 Tab。
83
+ h('div', { style: s.rowTitle }, [
84
+ h('span', { style: s.muted }, t('previewToolsHint')),
85
+ h('span', { style: s.orderTag },
86
+ `${data.tools.length} / ${data.registryTotal ?? '?'} ${t('previewToolsCount')}`),
87
+ ]),
88
+ h(PreviewTools, { tools: data.tools, t }),
89
+ ]
90
+ : null,
91
+ ])
92
92
  }
@@ -1,33 +1,33 @@
1
- /** 工具预览:当前定制(黑名单过滤之后)最终对模型可见的工具目录,
2
- * 只读、清单式呈现:列出即代表模型看得见 —— 这里没有「已屏蔽」状态。
3
- * 本视图绝不修改黑名单配置。 */
4
- import { createElement as h, type ReactElement } from 'react'
5
- import type { Translate } from './locales.ts'
6
- import { s } from './styles.ts'
7
-
8
- /** 预览工具条目:对象形态或纯字符串工具名(统一归一化为对象)。 */
9
- export type PreviewTool = { name: string; description: string } | string
10
-
11
- /** 把字符串形态的条目补全为 { name, description: '' }。 */
12
-
13
- function norm(tool: PreviewTool): { name: string; description: string } {
14
- return typeof tool === 'string' ? { name: tool, description: '' } : tool
15
- }
16
-
17
- export function PreviewTools({ tools, t }: { tools: PreviewTool[]; t: Translate }): ReactElement {
18
- if (tools.length === 0) return h('div', { style: s.muted }, t('empty'))
19
- return h('div', { style: s.list }, [
20
- h('div', { style: s.rowTitle }, [
21
- h('span', { style: s.orderTag }, `${tools.length} ${t('previewToolCount')}`),
22
- ]),
23
- tools.map((tool) => {
24
- const { name, description } = norm(tool)
25
- return h('div', { key: name, style: s.row }, [
26
- h('div', { style: s.rowBody }, [
27
- h('div', { style: s.rowTitle }, h('span', { style: s.code }, name)),
28
- h('div', { style: s.preview }, String(description ?? '').slice(0, 140)),
29
- ]),
30
- ])
31
- }),
32
- ])
33
- }
1
+ /** 工具预览:当前定制(黑名单过滤之后)最终对模型可见的工具目录,
2
+ * 只读、清单式呈现:列出即代表模型看得见 —— 这里没有「已屏蔽」状态。
3
+ * 本视图绝不修改黑名单配置。 */
4
+ import { createElement as h, type ReactElement } from 'react'
5
+ import type { Translate } from './locales.ts'
6
+ import { s } from './styles.ts'
7
+
8
+ /** 预览工具条目:对象形态或纯字符串工具名(统一归一化为对象)。 */
9
+ export type PreviewTool = { name: string; description: string } | string
10
+
11
+ /** 把字符串形态的条目补全为 { name, description: '' }。 */
12
+
13
+ function norm(tool: PreviewTool): { name: string; description: string } {
14
+ return typeof tool === 'string' ? { name: tool, description: '' } : tool
15
+ }
16
+
17
+ export function PreviewTools({ tools, t }: { tools: PreviewTool[]; t: Translate }): ReactElement {
18
+ if (tools.length === 0) return h('div', { style: s.muted }, t('empty'))
19
+ return h('div', { style: s.list }, [
20
+ h('div', { style: s.rowTitle }, [
21
+ h('span', { style: s.orderTag }, `${tools.length} ${t('previewToolCount')}`),
22
+ ]),
23
+ tools.map((tool) => {
24
+ const { name, description } = norm(tool)
25
+ return h('div', { key: name, style: s.row }, [
26
+ h('div', { style: s.rowBody }, [
27
+ h('div', { style: s.rowTitle }, h('span', { style: s.code }, name)),
28
+ h('div', { style: s.preview }, String(description ?? '').slice(0, 140)),
29
+ ]),
30
+ ])
31
+ }),
32
+ ])
33
+ }