pi-web-ui 0.98.0 → 0.100.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 (69) hide show
  1. package/CHANGELOG.md +85 -5
  2. package/README.md +2 -1
  3. package/README.zh-CN.md +2 -1
  4. package/bin/pi-web-ui.mjs +174 -36
  5. package/dist/server/agent-service.js +1169 -152
  6. package/dist/server/approval-rules.js +95 -23
  7. package/dist/server/attachments.js +55 -0
  8. package/dist/server/bg-servers.js +82 -2
  9. package/dist/server/claim-files-tool.js +4 -4
  10. package/dist/server/client-state.js +41 -0
  11. package/dist/server/compact-context-tool.js +10 -9
  12. package/dist/server/conversation-read-tool.js +7 -8
  13. package/dist/server/conversation-touches.js +19 -0
  14. package/dist/server/delegate-task.js +10 -14
  15. package/dist/server/dsh/dsh-agent-service.js +116 -12
  16. package/dist/server/edit-soft-tool.js +10 -12
  17. package/dist/server/eval-tool.js +26 -6
  18. package/dist/server/goal-evidence.js +173 -0
  19. package/dist/server/goal-service.js +78 -15
  20. package/dist/server/hashline-engine.js +198 -31
  21. package/dist/server/index.js +55 -9
  22. package/dist/server/load-tools-tool.js +100 -0
  23. package/dist/server/lsp-tool.js +10 -16
  24. package/dist/server/marker-service.js +53 -12
  25. package/dist/server/markers/builtins/action.js +108 -0
  26. package/dist/server/markers/index.js +4 -1
  27. package/dist/server/model-enrich.js +2 -0
  28. package/dist/server/patch-remote-catalog.js +28 -10
  29. package/dist/server/patch-tool.js +74 -38
  30. package/dist/server/plan-manager.js +71 -30
  31. package/dist/server/plan-mode.js +7 -6
  32. package/dist/server/plugin-api-catalog.js +10 -3
  33. package/dist/server/plugin-conversation-view.js +47 -0
  34. package/dist/server/plugins.js +113 -26
  35. package/dist/server/present-files-tool.js +10 -11
  36. package/dist/server/preset-fields.js +693 -0
  37. package/dist/server/preset-share.js +1178 -0
  38. package/dist/server/prompt-composer.js +23 -9
  39. package/dist/server/protocol-version.js +1 -1
  40. package/dist/server/read-tool.js +8 -10
  41. package/dist/server/resolve-global-sdk.js +80 -18
  42. package/dist/server/schedule-agent-tool.js +147 -146
  43. package/dist/server/sdk-origin.js +125 -37
  44. package/dist/server/settings-service.js +103 -84
  45. package/dist/server/skill-tool.js +3 -4
  46. package/dist/server/subagents.js +15 -22
  47. package/dist/server/terminals.js +29 -39
  48. package/dist/server/tool-approval.js +3 -1
  49. package/dist/server/tool-manager.js +63 -27
  50. package/dist/server/tool-prompt-overrides.js +158 -0
  51. package/dist/server/tool-prompts.js +42 -0
  52. package/dist/server/tool-signature.js +104 -0
  53. package/dist/server/update-check.js +0 -15
  54. package/dist/server/workspace-snapshot.js +42 -11
  55. package/package.json +5 -3
  56. package/plugin-sdk/README.md +8 -4
  57. package/plugin-sdk/import-check.mjs +210 -0
  58. package/plugin-sdk/index.d.ts +4 -1
  59. package/plugin-sdk/index.mjs +1 -0
  60. package/plugins/catalog.json +33 -2
  61. package/themes/zhupi-dark.css +1 -1
  62. package/themes/zhupi.css +1 -1
  63. package/web/dist/assets/{TerminalPanel-C88r3r3Q.js → TerminalPanel-C3I1Mc-C.js} +2 -2
  64. package/web/dist/assets/index-B-E2EM_0.css +1 -0
  65. package/web/dist/assets/index-BYumAaGi.js +379 -0
  66. package/web/dist/index.html +2 -2
  67. package/web/dist/sw.js +1 -1
  68. package/web/dist/assets/index-2jDtjHvW.css +0 -1
  69. package/web/dist/assets/index-BjdK7s1M.js +0 -368
@@ -0,0 +1,693 @@
1
+ /**
2
+ * preset-fields.ts — 预设能携带哪些设置字段 + 它们归到哪个分组(**零依赖**纯模块)。
3
+ *
4
+ * 为什么单独一个文件:字段清单要同时被
5
+ * - 服务端 `preset-share.ts`(白名单净化 / 交换文档)与 `settings-service.ts`(快照/应用)用,
6
+ * - 前端导入预览的「按分组勾选」用(`web/src/components/PresetShareModal.tsx`)。
7
+ * 而 `preset-share.ts` 依赖 `node:child_process` / `node:fs`,浏览器里 import 会炸;
8
+ * 本文件不 import 任何东西,两端都能安全引用(同 `prompt-composer.ts` / `tool-manager.ts` 的做法)。
9
+ *
10
+ * 纪律:
11
+ * 1. 这里只描述**元数据**(字段名 / 分组 / 文案 key),净化与归一化仍在 preset-share 里;
12
+ * 2. `PRESET_FIELD_NAMES` 必须覆盖 `ClientSettings` 的每个字段 —— 单测
13
+ * `tests/unit/preset-share.test.ts` 用类型 + 快照双重守卫,漏字段会红;
14
+ * 3. 分组只影响 UI 折叠与「勾一组」,不影响写入逻辑(导入按字段名过滤)。
15
+ */
16
+ import { resolveEnabledAgentTools } from "./tool-manager.js";
17
+ /** 预设字段分组(导入预览里的折叠块;顺序即展示顺序)。 */
18
+ export const PRESET_GROUP_ORDER = ["prompt", "tools", "terminal", "skills", "ai", "ui", "engine"];
19
+ /**
20
+ * 字段 → 分组。key 集合 = 预设可携带的全部设置字段名。
21
+ * 前端按 `PRESET_GROUP_ORDER` 渲染勾选块,组的名字走 i18n `presetGroup<Xxx>`。
22
+ *
23
+ * 用 `as const` 保留字面量类型:`PresetFieldName` 由此导出,单测用它做
24
+ * 「`ClientSettings` 的每个字段都在这里」的**编译期**守卫。
25
+ */
26
+ export const PRESET_FIELD_GROUPS = {
27
+ // 提示词(主会话 + 审查者)
28
+ prompt: [
29
+ "promptMode",
30
+ "customSystemPrompt",
31
+ "promptTemplate",
32
+ "promptOverrides",
33
+ "reviewPrompt",
34
+ "reviewDisabledSkills",
35
+ ],
36
+ // 工具开关与模型可见文案
37
+ tools: [
38
+ "disabledAgentTools",
39
+ "disabledPluginTools",
40
+ "toolPromptOverrides",
41
+ "toolLazyLoading",
42
+ "readDirEnabled",
43
+ "toolApprovalEnabled",
44
+ "toolWatchdogTimeoutMs",
45
+ "questionnaireEnabled",
46
+ "editSoftEnabled",
47
+ "terminalToolsEnabled",
48
+ ],
49
+ // 终端接管
50
+ terminal: ["terminalBash", "terminalBashIdleMs", "terminalBashMaxForegroundMs"],
51
+ // 技能与扩展
52
+ skills: ["disabledSkills", "disabledExtensions", "skillsFullText"],
53
+ // 模型侧行为与各专用提示词
54
+ ai: [
55
+ "retryMaxAttempts",
56
+ "softCapTokens",
57
+ "softCapByModel",
58
+ "subagentDefaultModel",
59
+ "visionBridgeEnabled",
60
+ "visionBridgeModel",
61
+ "visionBridgePromptMode",
62
+ "visionBridgePrompt",
63
+ "scmCommitMsgPromptMode",
64
+ "scmCommitMsgPrompt",
65
+ "planModePromptMode",
66
+ "planModePrompt",
67
+ "goalModeEnabled",
68
+ "parallelReminderEnabled",
69
+ ],
70
+ // 界面与交互偏好
71
+ ui: [
72
+ "uiLayout",
73
+ "disabledPlugins",
74
+ "thinkingWrap",
75
+ "toolsWrap",
76
+ "toolImagesEnabled",
77
+ "bgAutoCleanupMin",
78
+ "quickPhrases",
79
+ "quickPhrasesEnabled",
80
+ "devNoCache",
81
+ "autoReload",
82
+ ],
83
+ // 引擎/多引擎默认(DSH 用)
84
+ engine: ["defaultAgentPreset", "defaultPermissionPreset"],
85
+ };
86
+ /** 全部字段名(组顺序 → 组内顺序;去重保护)。 */
87
+ export const PRESET_FIELD_NAMES = (() => {
88
+ const out = [];
89
+ for (const g of PRESET_GROUP_ORDER)
90
+ for (const f of PRESET_FIELD_GROUPS[g])
91
+ if (!out.includes(f))
92
+ out.push(f);
93
+ return out;
94
+ })();
95
+ /** 某字段属于哪个分组(未知字段返回 undefined;前端过滤用)。 */
96
+ export function presetFieldGroup(field) {
97
+ for (const g of PRESET_GROUP_ORDER) {
98
+ if (PRESET_FIELD_GROUPS[g].includes(field))
99
+ return g;
100
+ }
101
+ return undefined;
102
+ }
103
+ /** 按分组把一组字段名摊成「组 → 命中的字段」(空组不给;组顺序固定)。 */
104
+ export function groupPresetFields(fields) {
105
+ const set = new Set(fields);
106
+ const out = [];
107
+ for (const g of PRESET_GROUP_ORDER) {
108
+ const hit = PRESET_FIELD_GROUPS[g].filter((f) => set.has(f));
109
+ if (hit.length > 0)
110
+ out.push({ group: g, fields: hit });
111
+ }
112
+ return out;
113
+ }
114
+ /** 过滤出合法字段名(去重、保持 `PRESET_FIELD_NAMES` 顺序)——导入选择用。 */
115
+ export function normalizePresetFieldSelection(v) {
116
+ if (!Array.isArray(v))
117
+ return undefined;
118
+ const wanted = new Set(v.filter((x) => typeof x === "string"));
119
+ return PRESET_FIELD_NAMES.filter((f) => wanted.has(f));
120
+ }
121
+ /** 预设中 47 个设置项的人类可读元数据映射(支持 satisfies 编译期完整性校验)。 */
122
+ export const PRESET_FIELD_META = {
123
+ // prompt
124
+ promptMode: {
125
+ labelZh: "提示词模式",
126
+ labelEn: "Prompt Mode",
127
+ hintZh: "追加到内置提示词 (append) 或完全替换系统内置提示词 (replace)",
128
+ hintEn: "Append to built-in prompt or completely replace it",
129
+ },
130
+ customSystemPrompt: {
131
+ labelZh: "自定义系统提示词",
132
+ labelEn: "Custom System Prompt",
133
+ hintZh: "定制 AI 基础人设与工作规约的主提示词",
134
+ hintEn: "Main prompt customizing AI persona and instructions",
135
+ },
136
+ promptTemplate: {
137
+ labelZh: "组合模板",
138
+ labelEn: "Prompt Template",
139
+ hintZh: "高级提示词组装模板(包含各个 slot 占位符)",
140
+ hintEn: "Advanced prompt composition template with slot placeholders",
141
+ },
142
+ promptOverrides: {
143
+ labelZh: "逐段提示词覆盖",
144
+ labelEn: "Sectional Prompt Overrides",
145
+ hintZh: "微调特定提示词段落(如 soul/cwd/skills 等)",
146
+ hintEn: "Overrides for specific prompt sections (soul, cwd, skills, etc.)",
147
+ },
148
+ reviewPrompt: {
149
+ labelZh: "目标模式审查提示词",
150
+ labelEn: "Goal Mode Review Prompt",
151
+ hintZh: "目标模式 2.0 中审查者专用的判定与指导提示词",
152
+ hintEn: "Prompt for the reviewer in Goal Mode 2.0",
153
+ },
154
+ reviewDisabledSkills: {
155
+ labelZh: "审查时禁用的技能",
156
+ labelEn: "Skills Disabled in Review",
157
+ hintZh: "仅在目标审查阶段禁止审查者调用的技能列表",
158
+ hintEn: "Skills unavailable to the reviewer in Goal Mode",
159
+ },
160
+ // tools
161
+ disabledAgentTools: {
162
+ labelZh: "禁用的内置工具",
163
+ labelEn: "Disabled Agent Tools",
164
+ hintZh: "不在 AI 可用工具列表中暴露的内置工具",
165
+ hintEn: "Built-in tools removed from agent visibility",
166
+ },
167
+ disabledPluginTools: {
168
+ labelZh: "禁用的插件工具",
169
+ labelEn: "Disabled Plugin Tools",
170
+ hintZh: "禁止向 AI 注册的第三方插件工具",
171
+ hintEn: "Plugin-provided tools removed from agent visibility",
172
+ },
173
+ toolPromptOverrides: {
174
+ labelZh: "工具提示词覆盖",
175
+ labelEn: "Tool Prompt Overrides",
176
+ hintZh: "微调工具在模型视野中的描述、触发条件与使用指南",
177
+ hintEn: "Custom descriptions, snippets and guidelines for tools",
178
+ },
179
+ toolLazyLoading: {
180
+ labelZh: "工具按需延迟加载",
181
+ labelEn: "Tool Lazy Loading",
182
+ hintZh: "仅常驻核心工具,其余工具通过 load_tools 按需动态引入(节省上下文)",
183
+ hintEn: "Keep only core tools active; load others on demand (saves context)",
184
+ },
185
+ readDirEnabled: {
186
+ labelZh: "read 工具列目录",
187
+ labelEn: "Directory Listing in read",
188
+ hintZh: "允许 read 工具在路径为目录时直接返回文件列表",
189
+ hintEn: "Allow read tool to list directory entries when target is a folder",
190
+ },
191
+ toolApprovalEnabled: {
192
+ labelZh: "工具执行审批门禁",
193
+ labelEn: "Tool Execution Approval",
194
+ hintZh: "执行危险或写操作工具前弹出用户确认确认框",
195
+ hintEn: "Require user approval before executing tools",
196
+ },
197
+ bgAutoCleanupMin: {
198
+ labelZh: "后台任务自动清理",
199
+ labelEn: "Background Task Auto-cleanup",
200
+ hintZh: "定期清理闲置超阈值的 AI 起后台实例(分钟;0 = 关;面板里📌钉住的不算)",
201
+ hintEn: "Periodically clean AI-started background instances idle past the threshold (minutes; 0 = off; pinned ones skipped)",
202
+ },
203
+ toolWatchdogTimeoutMs: {
204
+ labelZh: "工具看门狗超时",
205
+ labelEn: "Tool Watchdog Timeout",
206
+ hintZh: "工具长时间未返回时的最长等待熔断时间",
207
+ hintEn: "Maximum execution time before aborting stuck tools",
208
+ },
209
+ questionnaireEnabled: {
210
+ labelZh: "问卷模式 (ask_user_question)",
211
+ labelEn: "Questionnaire Mode",
212
+ hintZh: "允许 AI 遇到歧义时弹窗向用户多选/单选确认",
213
+ hintEn: "Allow agent to ask interactive multiple-choice questions",
214
+ },
215
+ editSoftEnabled: {
216
+ labelZh: "宽松缩进编辑 (edit_soft)",
217
+ labelEn: "Soft Indentation Edit",
218
+ hintZh: "提供忽略前导空白缩进差异的鲁棒编辑工具",
219
+ hintEn: "Provide indentation-tolerant text replacement tool",
220
+ },
221
+ terminalToolsEnabled: {
222
+ labelZh: "终端工具集",
223
+ labelEn: "Terminal Toolset",
224
+ hintZh: "向 AI 开放持久交互式 PTY 终端驱动工具",
225
+ hintEn: "Enable persistent PTY interactive terminal tools",
226
+ },
227
+ // terminal
228
+ terminalBash: {
229
+ labelZh: "终端接管 Bash",
230
+ labelEn: "Terminal Takes Over Bash",
231
+ hintZh: "将 bash 工具调用分流至可见交互终端并实时回显",
232
+ hintEn: "Route bash execution into the visible interactive terminal",
233
+ },
234
+ terminalBashIdleMs: {
235
+ labelZh: "终端静默超时",
236
+ labelEn: "Terminal Idle Timeout",
237
+ hintZh: "终端无新输出时判定为完成的静默时间",
238
+ hintEn: "Idle duration before assuming command finished",
239
+ },
240
+ terminalBashMaxForegroundMs: {
241
+ labelZh: "前台最长运行时间",
242
+ labelEn: "Max Foreground Runtime",
243
+ hintZh: "前台命令超时未退出的强制截断时间",
244
+ hintEn: "Timeout before cutting off long foreground commands",
245
+ },
246
+ // skills
247
+ disabledSkills: {
248
+ labelZh: "禁用的技能",
249
+ labelEn: "Disabled Skills",
250
+ hintZh: "在当前工作区中禁用的技能列表",
251
+ hintEn: "Skills excluded in the current workspace",
252
+ },
253
+ disabledExtensions: {
254
+ labelZh: "禁用的扩展",
255
+ labelEn: "Disabled Extensions",
256
+ hintZh: "在当前项目中禁用的扩展列表",
257
+ hintEn: "Extensions excluded in the current project",
258
+ },
259
+ skillsFullText: {
260
+ labelZh: "技能全文常驻",
261
+ labelEn: "Skills Full Text in Context",
262
+ hintZh: "将指定技能的完整正文直接注入上下文,跳过 skill 工具按需载入",
263
+ hintEn: "Inject full text of selected skills directly into context",
264
+ },
265
+ // ai
266
+ retryMaxAttempts: {
267
+ labelZh: "网络重试上限",
268
+ labelEn: "Network Retry Attempts",
269
+ hintZh: "模型网络请求失败时的最大自动重试次数",
270
+ hintEn: "Max auto-retries when model requests fail",
271
+ },
272
+ softCapTokens: {
273
+ labelZh: "上下文压缩软上限",
274
+ labelEn: "Context Soft-Cap Tokens",
275
+ hintZh: "提前触发上下文平滑压缩的 token 阈值(默认 16384)",
276
+ hintEn: "Token threshold to trigger context compaction early",
277
+ },
278
+ softCapByModel: {
279
+ labelZh: "分模型压缩软上限",
280
+ labelEn: "Per-Model Soft-Cap",
281
+ hintZh: "针对不同模型单独设置的上下文压缩阈值",
282
+ hintEn: "Custom soft-cap thresholds configured per model",
283
+ },
284
+ subagentDefaultModel: {
285
+ labelZh: "子代理默认模型",
286
+ labelEn: "Subagent Default Model",
287
+ hintZh: "派生子代理时优先使用的专用模型(留空跟随主对话)",
288
+ hintEn: "Dedicated model for subagents (empty to follow main chat)",
289
+ },
290
+ visionBridgeEnabled: {
291
+ labelZh: "视觉桥 (看图转写)",
292
+ labelEn: "Vision Bridge",
293
+ hintZh: "主模型不具备识图能力时,自动使用带视觉的模型预先转写图片",
294
+ hintEn: "Use vision model to describe images when main model is text-only",
295
+ },
296
+ visionBridgeModel: {
297
+ labelZh: "视觉桥专属模型",
298
+ labelEn: "Vision Bridge Model",
299
+ hintZh: "用于看图转写的视觉模型 ID",
300
+ hintEn: "Model ID used for vision transcription",
301
+ },
302
+ visionBridgePromptMode: {
303
+ labelZh: "视觉桥提示词模式",
304
+ labelEn: "Vision Bridge Prompt Mode",
305
+ hintZh: "视觉桥转写提示词的追加/替换模式",
306
+ hintEn: "Append or replace mode for vision bridge prompt",
307
+ },
308
+ visionBridgePrompt: {
309
+ labelZh: "视觉桥提示词",
310
+ labelEn: "Vision Bridge Prompt",
311
+ hintZh: "指导视觉模型如何描述图片的系统提示词",
312
+ hintEn: "System prompt guiding image transcription",
313
+ },
314
+ scmCommitMsgPromptMode: {
315
+ labelZh: "Git 提交信息提示词模式",
316
+ labelEn: "Git Commit Prompt Mode",
317
+ hintZh: "AI 生成 Git 提交信息时的提示词模式",
318
+ hintEn: "Prompt mode for AI-generated Git commit messages",
319
+ },
320
+ scmCommitMsgPrompt: {
321
+ labelZh: "Git 提交信息提示词",
322
+ labelEn: "Git Commit Prompt",
323
+ hintZh: "指导 AI 根据 git diff 撰写提交信息的规范提示词",
324
+ hintEn: "Prompt guiding AI to write commit messages from git diff",
325
+ },
326
+ planModePromptMode: {
327
+ labelZh: "计划模式提示词模式",
328
+ labelEn: "Plan Mode Prompt Mode",
329
+ hintZh: "计划模式提示词的追加/替换模式",
330
+ hintEn: "Append or replace mode for Plan Mode prompt",
331
+ },
332
+ planModePrompt: {
333
+ labelZh: "计划模式提示词",
334
+ labelEn: "Plan Mode Prompt",
335
+ hintZh: "计划模式下限制模型只规划不施工的系统提示词",
336
+ hintEn: "System prompt restricting agent to planning only",
337
+ },
338
+ goalModeEnabled: {
339
+ labelZh: "目标模式 2.0",
340
+ labelEn: "Goal Mode 2.0",
341
+ hintZh: "主对话当审查者,服务端常驻执行对话协同干活",
342
+ hintEn: "Reviewer/executor loop architecture for goal tasks",
343
+ },
344
+ parallelReminderEnabled: {
345
+ labelZh: "并行编辑提醒",
346
+ labelEn: "Parallel Edit Reminder",
347
+ hintZh: "多个标签页同时编辑同一会话时的冲突告警",
348
+ hintEn: "Warn when multiple tabs edit the same session",
349
+ },
350
+ // ui
351
+ uiLayout: {
352
+ labelZh: "界面布局与图标排列",
353
+ labelEn: "UI Layout & Icons",
354
+ hintZh: "顶栏、底栏、左右侧边栏按钮的自定义顺序、可见性与对齐",
355
+ hintEn: "Custom order, visibility and alignment for bars and docks",
356
+ },
357
+ disabledPlugins: {
358
+ labelZh: "禁用的插件",
359
+ labelEn: "Disabled Plugins",
360
+ hintZh: "停用的 UI 插件列表",
361
+ hintEn: "List of deactivated UI plugins",
362
+ },
363
+ thinkingWrap: {
364
+ labelZh: "思考区自动折行",
365
+ labelEn: "Thinking Block Word Wrap",
366
+ hintZh: "思考展开区长文本是否自动折行",
367
+ hintEn: "Enable word wrap inside thinking blocks",
368
+ },
369
+ toolsWrap: {
370
+ labelZh: "工具调用自动折行",
371
+ labelEn: "Tool Call Word Wrap",
372
+ hintZh: "工具调用参数与结果长文本是否自动折行",
373
+ hintEn: "Enable word wrap for tool parameters and results",
374
+ },
375
+ toolImagesEnabled: {
376
+ labelZh: "工具调用图片渲染",
377
+ labelEn: "Tool Image Preview",
378
+ hintZh: "直接在工具卡片内渲染输出的图片文件",
379
+ hintEn: "Render image output directly in tool cards",
380
+ },
381
+ quickPhrases: {
382
+ labelZh: "快捷短语列表",
383
+ labelEn: "Quick Phrases List",
384
+ hintZh: "输入框上方的常用提示短语快捷按钮",
385
+ hintEn: "Quick prompt phrase buttons above composer",
386
+ },
387
+ quickPhrasesEnabled: {
388
+ labelZh: "启用快捷短语",
389
+ labelEn: "Enable Quick Phrases",
390
+ hintZh: "是否在输入框上方显示快捷短语药丸栏",
391
+ hintEn: "Display quick phrases bar above composer",
392
+ },
393
+ devNoCache: {
394
+ labelZh: "开发者免缓存模式",
395
+ labelEn: "Developer No-Cache Mode",
396
+ hintZh: "前端静态资源强制请求最新,不走缓存",
397
+ hintEn: "Bypass browser cache for static frontend assets",
398
+ },
399
+ autoReload: {
400
+ labelZh: "插件自动热重载",
401
+ labelEn: "Auto Reload on File Change",
402
+ hintZh: "本地插件文件变更时自动刷新插件运行时",
403
+ hintEn: "Automatically reload plugins when files change",
404
+ },
405
+ // engine
406
+ defaultAgentPreset: {
407
+ labelZh: "默认智能体预设",
408
+ labelEn: "Default Agent Preset",
409
+ hintZh: "新建会话时默认加载的智能体预设(DSH 多引擎)",
410
+ hintEn: "Default agent preset applied to new sessions (DSH)",
411
+ },
412
+ defaultPermissionPreset: {
413
+ labelZh: "默认权限预设",
414
+ labelEn: "Default Permission Preset",
415
+ hintZh: "新建会话时默认加载的权限预设",
416
+ hintEn: "Default permission preset applied to new sessions",
417
+ },
418
+ };
419
+ /** 获取字段的人类可读标签。 */
420
+ export function presetFieldLabel(field, lang = "zh") {
421
+ const meta = PRESET_FIELD_META[field];
422
+ if (!meta)
423
+ return field;
424
+ return lang === "zh" ? meta.labelZh : meta.labelEn;
425
+ }
426
+ /** 获取字段的功能简述。 */
427
+ export function presetFieldHint(field, lang = "zh") {
428
+ const meta = PRESET_FIELD_META[field];
429
+ if (!meta)
430
+ return "";
431
+ return (lang === "zh" ? meta.hintZh : meta.hintEn) || "";
432
+ }
433
+ /**
434
+ * 格式化预设中某字段的具体值:生成简要摘要 + 可展开的详细文本。
435
+ * 解决「用户不知道预设开了哪些工具、改了哪些提示词」的透明度问题。
436
+ */
437
+ export function formatPresetFieldValue(field, value, lang = "zh") {
438
+ const isZh = lang === "zh";
439
+ // 1. 未定义或 null
440
+ if (value === undefined || value === null) {
441
+ return { summary: isZh ? "未配置(跟随当前值)" : "Not configured (keeps current)" };
442
+ }
443
+ // 2. 工具开关列表
444
+ if (field === "disabledAgentTools") {
445
+ const disabledList = Array.isArray(value)
446
+ ? value.filter((x) => typeof x === "string" && Boolean(x))
447
+ : [];
448
+ const enabledList = resolveEnabledAgentTools(disabledList);
449
+ if (disabledList.length === 0) {
450
+ return {
451
+ summary: isZh
452
+ ? `全部启用(共 ${enabledList.length} 个可用工具)`
453
+ : `All enabled (${enabledList.length} available tools)`,
454
+ detail: [
455
+ `[${isZh ? "已启用可用工具" : "Enabled Tools"} (${enabledList.length})]`,
456
+ ...enabledList.map((item) => ` ✓ ${item}`),
457
+ ].join("\n"),
458
+ };
459
+ }
460
+ return {
461
+ summary: isZh
462
+ ? `启用 ${enabledList.length} 个,禁用 ${disabledList.length} 个(默认没开即关)`
463
+ : `Enabled ${enabledList.length}, disabled ${disabledList.length} (defaults to off)`,
464
+ detail: [
465
+ `[${isZh ? "已启用可用配置" : "Enabled Tools"} (${enabledList.length})]`,
466
+ ...enabledList.map((item) => ` ✓ ${item}`),
467
+ "",
468
+ `[${isZh ? "已禁用(默认没开即关)" : "Disabled Tools (defaults to off)"} (${disabledList.length})]`,
469
+ ...disabledList.map((item) => ` ✗ ${item}`),
470
+ ].join("\n"),
471
+ };
472
+ }
473
+ if (field === "disabledPluginTools") {
474
+ const list = Array.isArray(value) ? value.filter((x) => typeof x === "string" && Boolean(x)) : [];
475
+ if (list.length === 0) {
476
+ return { summary: isZh ? "全部启用(无禁用)" : "All enabled (none disabled)" };
477
+ }
478
+ return {
479
+ summary: isZh
480
+ ? `禁用 ${list.length} 个插件工具(${list.join(", ")})`
481
+ : `Disabled ${list.length} plugin tool(s): ${list.join(", ")}`,
482
+ detail: list.map((item) => `- ${item}`).join("\n"),
483
+ };
484
+ }
485
+ // 3. 工具提示词覆盖
486
+ if (field === "toolPromptOverrides") {
487
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
488
+ return { summary: isZh ? "无覆盖" : "No overrides" };
489
+ }
490
+ const map = value;
491
+ const tools = Object.keys(map);
492
+ if (tools.length === 0) {
493
+ return { summary: isZh ? "无覆盖(使用官方出厂提示词)" : "No overrides (uses factory defaults)" };
494
+ }
495
+ const detailLines = [];
496
+ for (const [toolName, ov] of Object.entries(map)) {
497
+ detailLines.push(`[${toolName}]`);
498
+ if (ov.description)
499
+ detailLines.push(` ${isZh ? "描述" : "Description"}: ${ov.description}`);
500
+ if (ov.promptSnippet)
501
+ detailLines.push(` ${isZh ? "触发摘要" : "Snippet"}: ${ov.promptSnippet}`);
502
+ if (ov.promptGuidelines && ov.promptGuidelines.length > 0) {
503
+ detailLines.push(` ${isZh ? "使用指南" : "Guidelines"}:`);
504
+ for (const g of ov.promptGuidelines)
505
+ detailLines.push(` • ${g}`);
506
+ }
507
+ detailLines.push("");
508
+ }
509
+ return {
510
+ summary: isZh
511
+ ? `覆盖了 ${tools.length} 个工具的提示词(${tools.join(", ")})`
512
+ : `Overrides prompts for ${tools.length} tool(s): ${tools.join(", ")}`,
513
+ detail: detailLines.join("\n").trimEnd(),
514
+ };
515
+ }
516
+ // 4. 技能 / 扩展禁用列表
517
+ if (field === "disabledSkills" || field === "disabledExtensions" || field === "reviewDisabledSkills") {
518
+ const list = Array.isArray(value) ? value.filter((x) => typeof x === "string" && Boolean(x)) : [];
519
+ if (list.length === 0) {
520
+ return { summary: isZh ? "全部启用(无禁用)" : "All enabled (none disabled)" };
521
+ }
522
+ return {
523
+ summary: isZh
524
+ ? `禁用 ${list.length} 项(${list.join(", ")})`
525
+ : `Disabled ${list.length} item(s): ${list.join(", ")}`,
526
+ detail: list.map((item) => `- ${item}`).join("\n"),
527
+ };
528
+ }
529
+ // 5. 技能全文常驻
530
+ if (field === "skillsFullText") {
531
+ const list = Array.isArray(value) ? value.filter((x) => typeof x === "string" && Boolean(x)) : [];
532
+ if (list.length === 0) {
533
+ return { summary: isZh ? "无(全部按需加载)" : "None (loaded on demand)" };
534
+ }
535
+ return {
536
+ summary: isZh
537
+ ? `常驻 ${list.length} 项技能全文(${list.join(", ")})`
538
+ : `Pinned full text for ${list.length} skill(s): ${list.join(", ")}`,
539
+ detail: list.map((item) => `- ${item}`).join("\n"),
540
+ };
541
+ }
542
+ // 6. 提示词文本
543
+ if (field === "customSystemPrompt" ||
544
+ field === "promptTemplate" ||
545
+ field === "reviewPrompt" ||
546
+ field === "visionBridgePrompt" ||
547
+ field === "scmCommitMsgPrompt" ||
548
+ field === "planModePrompt") {
549
+ const s = typeof value === "string" ? value : "";
550
+ if (!s.trim()) {
551
+ return { summary: isZh ? "(空)" : "(empty)" };
552
+ }
553
+ const preview = s.length > 60 ? `${s.slice(0, 60)}…` : s;
554
+ return {
555
+ summary: isZh
556
+ ? `包含 ${s.length} 字符:${preview.replace(/\s+/g, " ")}`
557
+ : `${s.length} chars: ${preview.replace(/\s+/g, " ")}`,
558
+ detail: s,
559
+ };
560
+ }
561
+ // 7. 逐段提示词覆盖 (promptOverrides)
562
+ if (field === "promptOverrides") {
563
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
564
+ return { summary: isZh ? "无覆盖" : "No overrides" };
565
+ }
566
+ const map = value;
567
+ const sections = Object.keys(map);
568
+ if (sections.length === 0) {
569
+ return { summary: isZh ? "无覆盖" : "No overrides" };
570
+ }
571
+ const detailLines = [];
572
+ for (const [sec, text] of Object.entries(map)) {
573
+ detailLines.push(`[${sec}] (${text.length} chars)`);
574
+ detailLines.push(text);
575
+ detailLines.push("");
576
+ }
577
+ return {
578
+ summary: isZh
579
+ ? `覆盖 ${sections.length} 个内置段落(${sections.join(", ")})`
580
+ : `Overrides ${sections.length} section(s): ${sections.join(", ")}`,
581
+ detail: detailLines.join("\n").trimEnd(),
582
+ };
583
+ }
584
+ // 8. 模式类字段
585
+ if (field === "promptMode" ||
586
+ field === "visionBridgePromptMode" ||
587
+ field === "scmCommitMsgPromptMode" ||
588
+ field === "planModePromptMode") {
589
+ return {
590
+ summary: value === "replace"
591
+ ? isZh
592
+ ? "替换内置系统提示词 (replace)"
593
+ : "Replaces built-in system prompt (replace)"
594
+ : isZh
595
+ ? "追加到系统提示词后 (append)"
596
+ : "Appends to system prompt (append)",
597
+ };
598
+ }
599
+ // 9. 界面布局 (uiLayout)
600
+ if (field === "uiLayout") {
601
+ if (!value || typeof value !== "object") {
602
+ return { summary: isZh ? "默认布局" : "Default layout" };
603
+ }
604
+ return {
605
+ summary: isZh ? "包含自定义工具栏、停靠栏排列与对齐设置" : "Custom layout, bar order and dock alignment",
606
+ };
607
+ }
608
+ // 10. 布尔开关
609
+ if (typeof value === "boolean") {
610
+ if (field === "toolLazyLoading") {
611
+ return {
612
+ summary: value
613
+ ? isZh
614
+ ? "开启(仅核心工具常驻,其余按需加载)"
615
+ : "Enabled (core only, others on-demand)"
616
+ : isZh
617
+ ? "关闭(所有工具全部直接挂载)"
618
+ : "Disabled (all tools loaded)",
619
+ };
620
+ }
621
+ if (field === "terminalBash") {
622
+ return {
623
+ summary: value
624
+ ? isZh
625
+ ? "开启(命令分流到可见交互终端)"
626
+ : "Enabled (routes to interactive terminal)"
627
+ : isZh
628
+ ? "关闭(后台执行)"
629
+ : "Disabled (runs in background)",
630
+ };
631
+ }
632
+ if (field === "toolApprovalEnabled") {
633
+ return {
634
+ summary: value
635
+ ? isZh
636
+ ? "开启(写操作与高危工具需人工审批)"
637
+ : "Enabled (approval needed for write tools)"
638
+ : isZh
639
+ ? "关闭(直接放行执行)"
640
+ : "Disabled (auto allow)",
641
+ };
642
+ }
643
+ if (field === "questionnaireEnabled") {
644
+ return {
645
+ summary: value
646
+ ? isZh
647
+ ? "开启(遇到歧义向用户发起交互问答)"
648
+ : "Enabled (interactive questions allowed)"
649
+ : isZh
650
+ ? "关闭"
651
+ : "Disabled",
652
+ };
653
+ }
654
+ return { summary: value ? (isZh ? "开启" : "Enabled") : isZh ? "关闭" : "Disabled" };
655
+ }
656
+ // 11. 数字配置
657
+ if (typeof value === "number") {
658
+ if (field === "softCapTokens") {
659
+ return { summary: value > 0 ? `${value} tokens` : isZh ? "跟随默认 (16384 tokens)" : "Default (16384 tokens)" };
660
+ }
661
+ if (field === "retryMaxAttempts") {
662
+ return { summary: isZh ? `最大重试 ${value} 次` : `Max ${value} attempts` };
663
+ }
664
+ if (field === "toolWatchdogTimeoutMs") {
665
+ return { summary: isZh ? `${Math.round(value / 60000)} 分钟` : `${Math.round(value / 60000)} min` };
666
+ }
667
+ if (field === "bgAutoCleanupMin") {
668
+ return {
669
+ summary: value > 0 ? (isZh ? `闲置 ${value} 分钟后清理` : `clean after ${value} min idle`) : isZh ? "关闭" : "Off",
670
+ };
671
+ }
672
+ if (field === "terminalBashIdleMs" || field === "terminalBashMaxForegroundMs") {
673
+ return { summary: isZh ? `${Math.round(value / 1000)} 秒` : `${Math.round(value / 1000)} s` };
674
+ }
675
+ return { summary: String(value) };
676
+ }
677
+ // 12. 快捷短语列表
678
+ if (field === "quickPhrases") {
679
+ const list = Array.isArray(value) ? value.filter((x) => typeof x === "string") : [];
680
+ return {
681
+ summary: isZh ? `包含 ${list.length} 条快捷短语` : `${list.length} quick phrase(s)`,
682
+ detail: list.map((item, idx) => `${idx + 1}. ${item}`).join("\n"),
683
+ };
684
+ }
685
+ // 13. 模型选择
686
+ if (field === "subagentDefaultModel" || field === "visionBridgeModel") {
687
+ const s = typeof value === "string" ? value.trim() : "";
688
+ return {
689
+ summary: s ? (isZh ? `指定模型:${s}` : `Model: ${s}`) : isZh ? "跟随主对话模型" : "Follows main chat model",
690
+ };
691
+ }
692
+ return { summary: String(value) };
693
+ }