dsh-prompt-customizer 0.3.1 → 0.4.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.en.md +15 -1
- package/README.md +18 -3
- package/client/client.js +154 -13
- package/client/client.js.map +1 -1
- package/lib/effective.js +49 -0
- package/lib/index.js +132 -56
- package/lib/schema.js +10 -0
- package/lib/vars.js +147 -0
- package/package.json +1 -1
- package/src/client/PresetsTab.tsx +82 -4
- package/src/client/SectionsTab.tsx +4 -1
- package/src/client/index.ts +23 -0
- package/src/client/locales.ts +38 -2
- package/src/client/preset-io.ts +6 -5
- package/src/client/types.ts +8 -0
package/src/client/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ const CONFIG_URL = '/api/prompt-customizer/config'
|
|
|
26
26
|
const CONFIG_SET_URL = '/api/prompt-customizer/config/set'
|
|
27
27
|
const CONFIG_UNSET_URL = '/api/prompt-customizer/config/unset'
|
|
28
28
|
const CONFIG_APPLY_URL = '/api/prompt-customizer/config/apply'
|
|
29
|
+
const CONFIG_RESET_URL = '/api/prompt-customizer/config/reset'
|
|
29
30
|
const PRESETS_CREATE_URL = '/api/prompt-customizer/presets'
|
|
30
31
|
const PREVIEW_URL = '/api/prompt-customizer/preview'
|
|
31
32
|
|
|
@@ -283,6 +284,25 @@ function Panel({ t }: { t: Translate }): ReactElement {
|
|
|
283
284
|
// 收窄了字段类型以匹配 SectionsTab 的 prop 签名)。
|
|
284
285
|
const writeGlobalField = writeField as (field: 'sections', value: unknown) => void
|
|
285
286
|
|
|
287
|
+
// 恢复初始状态:服务端清空全部定制并关闭 forceSections(与不装插件等效)。
|
|
288
|
+
// 二次确认由配置 Tab 的调用点负责;成功后清草稿、重拉全部视图。
|
|
289
|
+
const resetAll = (): void => {
|
|
290
|
+
fetch(CONFIG_RESET_URL, {
|
|
291
|
+
method: 'POST',
|
|
292
|
+
headers: { 'content-type': 'application/json' },
|
|
293
|
+
})
|
|
294
|
+
.then((r) => r.json())
|
|
295
|
+
.then((body) => {
|
|
296
|
+
if (body?.ok !== true) throw new Error(body?.error ?? 'reset failed')
|
|
297
|
+
setCfg(body.config as Config)
|
|
298
|
+
setDraft(null)
|
|
299
|
+
setError(null)
|
|
300
|
+
setVersion((n) => n + 1)
|
|
301
|
+
showFlash(t('resetOk'))
|
|
302
|
+
})
|
|
303
|
+
.catch((e: unknown) => setError(`${t('resetFail')}: ${e instanceof Error ? e.message : String(e)}`))
|
|
304
|
+
}
|
|
305
|
+
|
|
286
306
|
// 切换 Tab:提示词 ↔ 工具是同一编辑域,草稿保留;切到预设/预览即离开
|
|
287
307
|
// 编辑域,脏草稿经确认后丢弃。
|
|
288
308
|
const switchTab = (next: 'sections' | 'tools' | 'presets' | 'preview'): void => {
|
|
@@ -394,6 +414,9 @@ function Panel({ t }: { t: Translate }): ReactElement {
|
|
|
394
414
|
writeGlobal,
|
|
395
415
|
saveAsPreset,
|
|
396
416
|
forkSource: target ? (agentPresets.find((p) => p.id === target)?.name ?? target) : undefined,
|
|
417
|
+
onReset: resetAll,
|
|
418
|
+
// 黑名单永远是全局字段:取原始配置(不经 editView 的目标叠加)。
|
|
419
|
+
envBlocklist: cfg.envBlocklist ?? [],
|
|
397
420
|
})
|
|
398
421
|
: h(PreviewTab, { t, active: tab === 'preview', refreshId, target, version, phases }),
|
|
399
422
|
])
|
package/src/client/locales.ts
CHANGED
|
@@ -87,7 +87,7 @@ export const DICT = {
|
|
|
87
87
|
toolCopied: '已把「{name}」复制到{to}:{from}那份保持不动,隐藏/启用状态一起带过去。',
|
|
88
88
|
toolShown: '「{name}」已在{to}显示。',
|
|
89
89
|
toolHiddenIn: '「{name}」已在{to}隐藏。',
|
|
90
|
-
sectionsTakenOver: '
|
|
90
|
+
sectionsTakenOver: '「{name}」段声明了 complete 整段接管(宿主在装配瀑布流之后强制还原为那一条段)。本插件默认的 forceSections 已绕开该机制,段级屏蔽 / 替换 / 注入 / 排序照常生效;此提示只会在 forceSections 关闭或强制覆盖失效时出现,开启 forceSections 即可恢复。',
|
|
91
91
|
sectionsLost: '本插件在该阶段产出的 {emitted} 个段里,只有 {survived} 个进入最终提示词:其余被下游装配规则丢弃,段级定制不会完全生效(工具过滤不受影响)。',
|
|
92
92
|
sectionBlockedStrip: '(本阶段已屏蔽,模型不可见)',
|
|
93
93
|
phaseSuppressed: '被抑制(不在任何阶段的装配中)',
|
|
@@ -102,6 +102,24 @@ export const DICT = {
|
|
|
102
102
|
saveOk: '已保存',
|
|
103
103
|
saveFail: '保存失败',
|
|
104
104
|
discardConfirm: '有未保存的更改,离开将丢弃。确定离开吗?',
|
|
105
|
+
forceTitle: '强制覆盖(forceSections)',
|
|
106
|
+
forceHint: '开启后所有预设的提示词段一律以本插件为准(绕过 complete 整段接管与预设阶段裁段);关闭后退回瀑布流内过滤,预设可能压过定制。「恢复初始状态」会自动关闭它。',
|
|
107
|
+
forceOn: '已开启',
|
|
108
|
+
forceOff: '已关闭',
|
|
109
|
+
envBlockTitle: '环境变量黑名单(envBlocklist)',
|
|
110
|
+
envBlockHint: '系统环境变量(process.env)已全量注册为提示词变量:段文本里写 {{env_键名小写}} 引用(如 {{env_path}});命中黑名单的键不注册——env 里常有密钥,进了提示词就会随请求发给模型。条目支持 * 通配、大小写不敏感。内置变量 {{date}} {{time}} {{datetime}} {{weekday}} {{hostname}} {{platform}} {{arch}} {{username}} {{home}} {{shell}} {{locale}} {{node_version}} 恒可用。',
|
|
111
|
+
envBlockAdd: '键名或通配,如 GITHUB_TOKEN 或 *_KEY*',
|
|
112
|
+
envBlockAddAction: '添加',
|
|
113
|
+
envBlockEmpty: '黑名单为空:所有环境变量都会被注册',
|
|
114
|
+
envVarsTitle: '已注册的提示词变量',
|
|
115
|
+
envVarsHint: '段文本里引用 {{变量名}};引用未注册的名字会让整次渲染报错(宿主严格模式)。',
|
|
116
|
+
importBlockMerge: ',文件中的环境变量黑名单已并入(+{count} 条)',
|
|
117
|
+
resetTitle: '恢复初始状态',
|
|
118
|
+
resetHint: '清空全部定制(屏蔽 / 替换 / 注入 / 排序、阶段工具目录、配置快照、agent 预设覆盖),并关闭 forceSections —— 之后所有 AI 对话不再受本插件影响,与卸载插件等效,无需卸载或重启。此操作不可撤销;要重新启用定制,在上方打开「强制覆盖」开关即可。',
|
|
119
|
+
resetConfirm: '确定清空全部定制并恢复初始状态吗?\n\n将删除:屏蔽名单、段替换、注入段、阶段工具目录、配置快照、agent 预设覆盖;并关闭 forceSections。\n之后所有 AI 对话都不再受本插件影响(与卸载插件等效)。\n此操作不可撤销。',
|
|
120
|
+
resetAction: '清空全部定制',
|
|
121
|
+
resetOk: '已恢复初始状态:所有 AI 对话不再受本插件影响',
|
|
122
|
+
resetFail: '恢复初始状态失败',
|
|
105
123
|
scopeFallback: '该 agent 预设的常驻 scope 未能挂载,以下显示的是全局层内容(并非该预设的原生段与工具)。',
|
|
106
124
|
previewDegraded: '伪会话触发了某个预设插件的异常,本次预览已降级为无会话装配——预设原生的阶段裁剪规则未参与运行。',
|
|
107
125
|
previewFail: '该阶段装配失败(scope 挂载失败或预设插件异常),请切换目标或查看服务日志。',
|
|
@@ -197,7 +215,7 @@ export const DICT = {
|
|
|
197
215
|
toolCopied: 'Copied "{name}" to {to}: the copy in {from} is left untouched, and its hidden/enabled state carries over.',
|
|
198
216
|
toolShown: '"{name}" is now visible in {to}.',
|
|
199
217
|
toolHiddenIn: '"{name}" is now hidden in {to}.',
|
|
200
|
-
sectionsTakenOver: 'The
|
|
218
|
+
sectionsTakenOver: 'The "{name}" section declares a complete takeover (the host restores that single section after the assembly waterfall). This plugin’s forceSections (default on) bypasses that mechanism, so section-level blocking / replacement / injection / ordering still applies; this notice only appears when forceSections is off or the override fails — enable it to restore.',
|
|
201
219
|
sectionsLost: 'Only {survived} of the {emitted} sections this plugin emitted for this phase reach the final prompt — the rest are dropped by downstream assembly rules, so section-level customization cannot fully apply (tool filtering is unaffected).',
|
|
202
220
|
sectionBlockedStrip: ' (blocked in this period; invisible to the model)',
|
|
203
221
|
phaseSuppressed: 'Suppressed (absent from every phase assembly)',
|
|
@@ -212,6 +230,24 @@ export const DICT = {
|
|
|
212
230
|
saveOk: 'Saved',
|
|
213
231
|
saveFail: 'Save failed',
|
|
214
232
|
discardConfirm: 'You have unsaved changes; leaving will discard them. Leave anyway?',
|
|
233
|
+
forceTitle: 'Force override (forceSections)',
|
|
234
|
+
forceHint: 'When on, every preset’s prompt sections always follow this plugin (bypassing complete takeover and preset phase pruning); when off, filtering falls back to the waterfall, where presets may override your customization. "Restore initial state" turns this off automatically.',
|
|
235
|
+
forceOn: 'On',
|
|
236
|
+
forceOff: 'Off',
|
|
237
|
+
envBlockTitle: 'Environment variable blocklist (envBlocklist)',
|
|
238
|
+
envBlockHint: 'All system environment variables (process.env) are registered as prompt variables: reference them in section text as {{env_lowercase_key}} (e.g. {{env_path}}); keys hit by the blocklist are not registered — env often carries secrets, and anything in the prompt is sent to the model. Entries support * wildcards, case-insensitive. Built-ins {{date}} {{time}} {{datetime}} {{weekday}} {{hostname}} {{platform}} {{arch}} {{username}} {{home}} {{shell}} {{locale}} {{node_version}} are always available.',
|
|
239
|
+
envBlockAdd: 'Key or wildcard, e.g. GITHUB_TOKEN or *_KEY*',
|
|
240
|
+
envBlockAddAction: 'Add',
|
|
241
|
+
envBlockEmpty: 'Blocklist is empty: every environment variable gets registered',
|
|
242
|
+
envVarsTitle: 'Registered prompt variables',
|
|
243
|
+
envVarsHint: 'Reference {{name}} in section text; an unregistered name fails the whole render (host strict mode).',
|
|
244
|
+
importBlockMerge: ', the file’s env-variable blocklist was merged in (+{count} entries)',
|
|
245
|
+
resetTitle: 'Restore initial state',
|
|
246
|
+
resetHint: 'Clears all customization (blocking / replacement / injection / ordering, per-phase tool catalogs, config snapshots, agent-preset overrides) and turns forceSections off — every AI conversation goes back to being unaffected by this plugin, equivalent to uninstalling it, without uninstalling or restarting. This cannot be undone; to re-enable customization, turn the "Force override" switch above back on.',
|
|
247
|
+
resetConfirm: 'Clear all customization and restore the initial state?\n\nThis will delete: block lists, section replacements, injected sections, per-phase tool catalogs, config snapshots, and agent-preset overrides; forceSections will be turned off.\nAfterwards no AI conversation is affected by this plugin (equivalent to uninstalling).\nThis cannot be undone.',
|
|
248
|
+
resetAction: 'Clear all customization',
|
|
249
|
+
resetOk: 'Initial state restored: no AI conversation is affected by this plugin anymore',
|
|
250
|
+
resetFail: 'Failed to restore initial state',
|
|
215
251
|
scopeFallback: "This agent preset's standing scope could not be mounted; what you see is the global layer (not the preset's native sections/tools).",
|
|
216
252
|
previewDegraded: 'A preset plugin threw on the synthetic session; this preview fell back to an agent-less assembly — native phase rules did not run.',
|
|
217
253
|
previewFail: 'Assembly for this phase failed (scope mount error or a preset plugin threw); switch target or check the server log.',
|
package/src/client/preset-io.ts
CHANGED
|
@@ -129,9 +129,10 @@ export function readPickedFile(reader: FileReaderLike, file: unknown): Promise<s
|
|
|
129
129
|
|
|
130
130
|
// ── 纯文件格式 ──────────────────────────────────────────────────────────────
|
|
131
131
|
|
|
132
|
-
/** 把单个预设编码为导出文件的 JSON
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
/** 把单个预设编码为导出文件的 JSON 格式(单对象格式)。`envBlocklist`
|
|
133
|
+
* 是全局环境变量黑名单的随行快照:导入端按并集并入(见 PresetsTab)。 */
|
|
134
|
+
export function encodePresetExport(preset: Preset, envBlocklist?: string[]): string {
|
|
135
|
+
return JSON.stringify({ name: preset.name, data: preset.data, ...(Array.isArray(envBlocklist) ? { envBlocklist } : {}) }, null, 2)
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
/**
|
|
@@ -186,10 +187,10 @@ export type ExportResult = { ok: boolean; via: 'tauri' | 'browser'; cancelled?:
|
|
|
186
187
|
* 导出一个预设:宿主能提供原生对话框时走 tauri 保存(cancelled = 用户
|
|
187
188
|
* 拒绝,绝不回退下载);否则走 Web 下载。
|
|
188
189
|
*/
|
|
189
|
-
export async function exportPresetFile(preset: Preset, io?: PresetIoEnv): Promise<ExportResult> {
|
|
190
|
+
export async function exportPresetFile(preset: Preset, io?: PresetIoEnv, envBlocklist?: string[]): Promise<ExportResult> {
|
|
190
191
|
const env = io ?? makeIoEnv()
|
|
191
192
|
try {
|
|
192
|
-
const text = encodePresetExport(preset)
|
|
193
|
+
const text = encodePresetExport(preset, envBlocklist)
|
|
193
194
|
const filename = presetExportFilename(preset.name)
|
|
194
195
|
if (env.tauri) {
|
|
195
196
|
const out = await env.saveText(filename, text)
|
package/src/client/types.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface Inventory {
|
|
|
6
6
|
tools: Array<{ name: string; description?: string; hidden: boolean }>
|
|
7
7
|
/** false = 预设 scope 未能挂载,清单回退到了全局层。 */
|
|
8
8
|
scopeResolved?: boolean
|
|
9
|
+
/** 当前已注册的提示词变量名(内置 + 黑名单过滤后的 env),供引用参考。 */
|
|
10
|
+
variables?: string[]
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
/** `/api/prompt-customizer/agent-presets` 返回的一个已安装 agent 预设。 */
|
|
@@ -90,6 +92,12 @@ export interface Config {
|
|
|
90
92
|
/** custom 为隐藏标记:true 表示本插件注入(可删除),不依赖名字碰撞识别。 */
|
|
91
93
|
inject?: Array<{ name: string; order: number; text: string; phase?: Phase; custom?: boolean }>
|
|
92
94
|
tools?: ToolsConfig
|
|
95
|
+
/** 强制覆盖(默认 true):装配入口重建提示词段,所有预设一律以本插件为准。
|
|
96
|
+
* 为 false 时退回瀑布流内过滤(complete 接管 / 预设裁段可能压过定制)。 */
|
|
97
|
+
forceSections?: boolean
|
|
98
|
+
/** 环境变量黑名单(全局字段):命中的 process.env 键不注册为提示词变量。
|
|
99
|
+
* 条目支持 `*` 通配、大小写不敏感;缺省 = 预填的常见密钥类名单。 */
|
|
100
|
+
envBlocklist?: string[]
|
|
93
101
|
presets?: Preset[]
|
|
94
102
|
activePreset?: string
|
|
95
103
|
/** 按 agent 预设 id 的字段级覆盖。 */
|