pi-web-ui 0.113.1 → 0.114.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 (280) hide show
  1. package/CHANGELOG.md +71 -1
  2. package/README.md +187 -316
  3. package/README.zh-CN.md +227 -299
  4. package/README.zh-TW.md +227 -299
  5. package/bin/device-hub-cli.mjs +577 -0
  6. package/bin/frp-manager.mjs +1573 -1573
  7. package/bin/pi-device-hub.mjs +9 -0
  8. package/bin/pi-web-ui.mjs +4081 -4041
  9. package/deploy/nginx-subpath.conf +100 -100
  10. package/deploy/pi-web-ui.service +36 -36
  11. package/dist/server/agent-service-daemon.js +102 -24
  12. package/dist/server/agent-service.js +2419 -1174
  13. package/dist/server/approval-rules.js +29 -3
  14. package/dist/server/ask-user-question-tool.js +8 -8
  15. package/dist/server/atomic-file.js +35 -14
  16. package/dist/server/attachment-store.js +71 -35
  17. package/dist/server/attachments.js +69 -13
  18. package/dist/server/canvas/canvas-agent-tool.js +68 -18
  19. package/dist/server/canvas/canvas-cards.js +1 -1
  20. package/dist/server/canvas/canvas-dispatch.js +61 -20
  21. package/dist/server/canvas/canvas-orchestrator.js +519 -202
  22. package/dist/server/canvas/canvas-scheduled-task.js +45 -0
  23. package/dist/server/canvas/canvas-scheduler.js +99 -0
  24. package/dist/server/canvas/canvas-store.js +107 -54
  25. package/dist/server/canvas/canvas-validation.js +131 -0
  26. package/dist/server/canvas/canvas-workspace.js +284 -0
  27. package/dist/server/client-id-utils.js +8 -0
  28. package/dist/server/client-state.js +110 -24
  29. package/dist/server/communicate-tool.js +76 -0
  30. package/dist/server/compact-context-tool.js +2 -3
  31. package/dist/server/compaction-instructions.js +75 -0
  32. package/dist/server/compaction-markers.js +7 -2
  33. package/dist/server/compaction-state.js +84 -0
  34. package/dist/server/composer-drafts.js +43 -40
  35. package/dist/server/context-evidence.js +346 -0
  36. package/dist/server/conversation-communication.js +368 -0
  37. package/dist/server/conversation-read-tool.js +3 -4
  38. package/dist/server/conversation-tool-names.js +14 -0
  39. package/dist/server/conversation-tool.js +57 -0
  40. package/dist/server/delegate-mode.js +17 -4
  41. package/dist/server/device-center/bot-catalog.js +88 -0
  42. package/dist/server/device-center/bot-execution.js +106 -0
  43. package/dist/server/device-center/bots.js +170 -0
  44. package/dist/server/device-center/collab-service.js +153 -0
  45. package/dist/server/device-center/collab-tool.js +184 -0
  46. package/dist/server/device-center/connector.js +351 -0
  47. package/dist/server/device-center/desktop-linux.js +372 -0
  48. package/dist/server/device-center/desktop-native.js +413 -0
  49. package/dist/server/device-center/desktop-page.js +232 -0
  50. package/dist/server/device-center/desktop-setup.js +30 -0
  51. package/dist/server/device-center/desktop.js +387 -0
  52. package/dist/server/device-center/device-portals.js +241 -0
  53. package/dist/server/device-center/execution-failure.js +70 -0
  54. package/dist/server/device-center/executor.js +371 -0
  55. package/dist/server/device-center/file-sync.js +493 -0
  56. package/dist/server/device-center/hub-auth.js +69 -0
  57. package/dist/server/device-center/hub-page.js +68 -0
  58. package/dist/server/device-center/hub-setup.js +214 -0
  59. package/dist/server/device-center/hub.js +830 -0
  60. package/dist/server/device-center/local-hub.js +92 -0
  61. package/dist/server/device-center/local.js +529 -0
  62. package/dist/server/device-center/main.js +118 -0
  63. package/dist/server/device-center/native-desktop/macos.js +192 -0
  64. package/dist/server/device-center/native-desktop/windows.js +118 -0
  65. package/dist/server/device-center/path-portal.js +120 -0
  66. package/dist/server/device-center/relay.js +996 -0
  67. package/dist/server/device-center/runtime.js +253 -0
  68. package/dist/server/device-center/store.js +122 -0
  69. package/dist/server/device-center/task-error.js +14 -0
  70. package/dist/server/device-center/transfers.js +293 -0
  71. package/dist/server/device-center/workspaces.js +45 -0
  72. package/dist/server/dispatch-domain-handlers.js +84 -27
  73. package/dist/server/dsh/dsh-agent-service.js +282 -159
  74. package/dist/server/dsh/dsh-client.js +12 -2
  75. package/dist/server/dsh/runtime/cordis.yml +1 -1
  76. package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
  77. package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
  78. package/dist/server/dsh/runtime/launcher.mjs +235 -235
  79. package/dist/server/dsh/runtime/override.patch.yml +89 -89
  80. package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
  81. package/dist/server/durable/durable-agent-service.js +1 -1
  82. package/dist/server/engine-probe.js +36 -6
  83. package/dist/server/eval-tool.js +135 -135
  84. package/dist/server/evidence-tool-hooks.js +49 -0
  85. package/dist/server/file-save.js +95 -0
  86. package/dist/server/file-transfer-routes.js +97 -47
  87. package/dist/server/files-service.js +38 -26
  88. package/dist/server/global-loader.js +40 -2
  89. package/dist/server/goal-review-gate.js +16 -6
  90. package/dist/server/goal-service.js +54 -30
  91. package/dist/server/http-proxy.js +120 -0
  92. package/dist/server/index.js +285 -255
  93. package/dist/server/load-timing.js +31 -0
  94. package/dist/server/mcp-bridge.js +219 -94
  95. package/dist/server/mcp-hot-reload.js +31 -5
  96. package/dist/server/mcp-manager.js +192 -93
  97. package/dist/server/mcp-oauth-login.js +169 -0
  98. package/dist/server/mcp-oauth-ui.js +137 -0
  99. package/dist/server/mcp-oauth.js +395 -0
  100. package/dist/server/mcp-project-runtime.js +207 -0
  101. package/dist/server/message-window.js +74 -21
  102. package/dist/server/net-guard.js +122 -20
  103. package/dist/server/patch-bash-process.js +125 -0
  104. package/dist/server/patch-tool.js +9 -9
  105. package/dist/server/patch-turn-end-boundary.js +3 -3
  106. package/dist/server/payload-limits.js +17 -0
  107. package/dist/server/pending-question.js +82 -0
  108. package/dist/server/persona-chain.js +8 -8
  109. package/dist/server/plan-mode.js +338 -137
  110. package/dist/server/plugin-assets.js +8 -4
  111. package/dist/server/plugin-chat-attachments.js +48 -0
  112. package/dist/server/plugin-facilities.js +67 -220
  113. package/dist/server/plugin-installer.js +2 -1
  114. package/dist/server/plugin-removal.js +49 -0
  115. package/dist/server/plugin-secrets.js +179 -0
  116. package/dist/server/plugins.js +288 -94
  117. package/dist/server/preset-fields.js +56 -0
  118. package/dist/server/preset-plugin-dependencies.js +57 -0
  119. package/dist/server/preset-share.js +113 -72
  120. package/dist/server/prompt-templates.js +106 -0
  121. package/dist/server/protocol-version.js +1 -1
  122. package/dist/server/queue-modes.js +10 -0
  123. package/dist/server/remote-ssh-service.js +199 -106
  124. package/dist/server/request-context.js +164 -0
  125. package/dist/server/resolve-global-sdk.js +2 -0
  126. package/dist/server/sandbox-data.js +655 -0
  127. package/dist/server/sandbox-engines.js +7 -0
  128. package/dist/server/sandbox-runtime-gate.js +41 -0
  129. package/dist/server/sandbox-service.js +139 -698
  130. package/dist/server/sandbox-tool.js +21 -4
  131. package/dist/server/schedule-agent-tool.js +39 -21
  132. package/dist/server/scheduler-tasks.js +106 -55
  133. package/dist/server/scm-commitmsg.js +10 -10
  134. package/dist/server/serialize.js +48 -19
  135. package/dist/server/session-branch.js +25 -3
  136. package/dist/server/session-parser.js +28 -18
  137. package/dist/server/session-scan.js +130 -0
  138. package/dist/server/session-search.js +51 -37
  139. package/dist/server/settings-service.js +273 -111
  140. package/dist/server/setup-config.js +58 -0
  141. package/dist/server/setup-page.js +620 -620
  142. package/dist/server/skill-maintenance.js +112 -24
  143. package/dist/server/subagent-helpers.js +4 -1
  144. package/dist/server/subagent-notify.js +4 -1
  145. package/dist/server/subagent-security-gate.js +52 -11
  146. package/dist/server/subagent-task.js +27 -0
  147. package/dist/server/subagents.js +217 -46
  148. package/dist/server/tabs.js +9 -1
  149. package/dist/server/terminals.js +467 -363
  150. package/dist/server/text-quote.js +9 -0
  151. package/dist/server/tool-guards.js +42 -6
  152. package/dist/server/tool-manager.js +48 -20
  153. package/dist/server/tool-overrides.js +13 -11
  154. package/dist/server/tool-prompt-overrides.js +32 -2
  155. package/dist/server/tool-prompts.js +1 -1
  156. package/dist/server/turn-timing.js +11 -0
  157. package/dist/server/universal/drivers/claude-code.js +5 -0
  158. package/dist/server/universal/drivers/codex.js +336 -0
  159. package/dist/server/universal/index.js +1 -0
  160. package/dist/server/universal/session-store.js +48 -6
  161. package/dist/server/universal/universal-attachments.js +24 -1
  162. package/dist/server/universal/universal-service.js +1 -1
  163. package/dist/server/universal/universal-session.js +357 -231
  164. package/dist/server/uploads.js +64 -5
  165. package/dist/server/vision-bridge.js +18 -18
  166. package/dist/server/worktree-service.js +32 -24
  167. package/dist/server/ws-pending-queue.js +73 -27
  168. package/docs/device-center.md +148 -0
  169. package/docs/device-desktop.md +48 -0
  170. package/docs/dsh-engine.md +493 -493
  171. package/extensions/webui.ts +335 -335
  172. package/package.json +5 -2
  173. package/plugin-sdk/README.md +174 -174
  174. package/plugin-sdk/client-utils.mjs +279 -279
  175. package/plugin-sdk/import-check.mjs +210 -210
  176. package/plugin-sdk/index.d.ts +698 -676
  177. package/plugin-sdk/index.mjs +696 -696
  178. package/plugin-sdk/package.json +13 -13
  179. package/plugin-sdk/ssh-host-trust.mjs +225 -0
  180. package/plugins/catalog.json +11 -1
  181. package/themes/aetheris.css +501 -607
  182. package/themes/ayu-light.css +116 -140
  183. package/themes/bases/flow-base.css +1357 -1363
  184. package/themes/bases/obsidian-base.css +895 -895
  185. package/themes/bases/statusbar-flat-base.css +112 -0
  186. package/themes/bases/zhujian-base.css +688 -687
  187. package/themes/bases/zhupi-base.css +660 -659
  188. package/themes/catppuccin-latte.css +119 -142
  189. package/themes/catppuccin.css +116 -147
  190. package/themes/claude-code-dark.css +147 -146
  191. package/themes/codex.css +114 -138
  192. package/themes/cyberpunk.css +50 -108
  193. package/themes/dark-teal.css +264 -265
  194. package/themes/dazzle.css +38 -108
  195. package/themes/everforest-light.css +115 -138
  196. package/themes/flow-light.css +164 -164
  197. package/themes/flow.css +161 -161
  198. package/themes/geist.css +114 -138
  199. package/themes/gruvbox-light.css +115 -138
  200. package/themes/kanagawa-lotus.css +115 -138
  201. package/themes/md-preview.css +24 -234
  202. package/themes/mist.css +166 -186
  203. package/themes/nord.css +107 -138
  204. package/themes/one-dark.css +106 -139
  205. package/themes/paper.css +174 -186
  206. package/themes/rose-pine-dawn.css +114 -138
  207. package/themes/sakura.css +166 -186
  208. package/themes/solarized-light.css +114 -137
  209. package/themes/tokyo-night.css +115 -146
  210. package/themes/translucent.css +85 -85
  211. package/themes/transparent.css +116 -116
  212. package/themes/vs-code-dark.css +147 -147
  213. package/themes/wallpaper-flow.css +382 -382
  214. package/themes/wallpaper-obsidian.css +74 -74
  215. package/themes/white.css +164 -186
  216. package/themes/zhujian-dark.css +115 -114
  217. package/themes/zhujian.css +114 -114
  218. package/themes/zhupi-dark.css +115 -114
  219. package/themes/zhupi.css +114 -114
  220. package/web/dist/.build-assets.json +1 -0
  221. package/web/dist/assets/BgTasksModal-BcXJ20RO.js +1 -0
  222. package/web/dist/assets/BgTasksModal-DjQmiKnE.js +1 -0
  223. package/web/dist/assets/CanvasStudio-PI9pid0Y.js +1579 -0
  224. package/web/dist/assets/CanvasStudio-nf5-HxLM.js +1579 -0
  225. package/web/dist/assets/DeviceCenter-CYttJw2a.js +3 -0
  226. package/web/dist/assets/DeviceCenter-DPe4sz74.js +3 -0
  227. package/web/dist/assets/DeviceGroups-D2rogxEN.js +1 -0
  228. package/web/dist/assets/Dropdown-ZLS04O8p.js +1 -0
  229. package/web/dist/assets/FilePreview-C9Ut4Lq6.js +2 -0
  230. package/web/dist/assets/FilePreview-CvK3ZzX5.js +2 -0
  231. package/web/dist/assets/GlobalSearchModal-C5e-OCw2.js +1 -0
  232. package/web/dist/assets/GlobalSearchModal-H7pFK2UC.js +1 -0
  233. package/web/dist/assets/GroupConversation-C2wNM0dQ.js +1 -0
  234. package/web/dist/assets/GroupConversation-ChN3TWQK.js +1 -0
  235. package/web/dist/assets/ModelConfigModal-DDZccDYt.js +2 -0
  236. package/web/dist/assets/PiSetupModal-DHbqfx8T.js +1 -0
  237. package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +1 -0
  238. package/web/dist/assets/SCMPanel-buTGziDB.js +2 -0
  239. package/web/dist/assets/SCMPanel-kx-SCL2s.js +2 -0
  240. package/web/dist/assets/SettingsModal-BsUF8jqr.js +20 -0
  241. package/web/dist/assets/SettingsModal-D357Ky7P.js +20 -0
  242. package/web/dist/assets/TerminalPanel-BBuM_Sez.js +3 -0
  243. package/web/dist/assets/TerminalPanel-D6x6xz8Q.js +3 -0
  244. package/web/dist/assets/TuiOverlayModal-CdbGV3Za.js +1 -0
  245. package/web/dist/assets/TuiOverlayModal-d6x9u25n.js +1 -0
  246. package/web/dist/assets/app-globals-DcyO0UPi.js +1 -0
  247. package/web/dist/assets/desktop-YguLbrX1.js +1 -0
  248. package/web/dist/assets/es-DWMIuDU2.js +2 -0
  249. package/web/dist/assets/fi-DaSO0Q-m.js +325 -0
  250. package/web/dist/assets/index-BPvpea8t.js +85 -0
  251. package/web/dist/assets/index-D6u8xH0o.js +85 -0
  252. package/web/dist/assets/index-DDZMv6LO.css +1 -0
  253. package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
  254. package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
  255. package/web/dist/assets/math-1uRJCsA9.js +257 -0
  256. package/web/dist/assets/math-BorAY7qD.css +1 -0
  257. package/web/dist/assets/plugin-host-BRBg6zmQ.js +1 -0
  258. package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
  259. package/web/dist/assets/theme-DDl-Oy1b.js +1 -0
  260. package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
  261. package/web/dist/index.html +42 -35
  262. package/web/dist/sw.js +179 -179
  263. package/web/public/sw.js +179 -179
  264. package/dist/gh-comment-781.md +0 -5
  265. package/dist/server/durable/durable-capabilities.js +0 -11
  266. package/dist/server/markers/builtins/services.js +0 -123
  267. package/dist/server/markers/builtins/todo.js +0 -189
  268. package/dist/server/markers-list-tool.js +0 -34
  269. package/dist/server/orchestrator.js +0 -109
  270. package/dist/server/system-prompt-soul.js +0 -41
  271. package/dist/server/univer-service.js +0 -448
  272. package/dist/server/universal/drivers/dsh-driver.js +0 -379
  273. package/dist/test-artifact.md +0 -9
  274. package/dist/test-preview-modal.md +0 -11
  275. package/dist/test-report.html +0 -20
  276. package/web/dist/assets/TerminalPanel-Ci55JtJL.js +0 -3
  277. package/web/dist/assets/index-ByiO9f-N.js +0 -2008
  278. package/web/dist/assets/index-ycGLh4a4.css +0 -1
  279. package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
  280. package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Settings service — 从 agent-service.ts 抽出(系统提示词 / 技能插件开关 /
3
- * 目标审查提示词 / 预设 / 视觉桥偏好)。设置持久化在 client-state.json 按客户端隔离。
3
+ * 目标审查提示词 / 预设 / 视觉桥偏好)。设置持久化在 client-state.json 全局共享。
4
4
  *
5
5
  * 经 SettingsHost 回调与 ClientSession 解耦:本模块只管「设置状态 + 面板推送 +
6
6
  * 预设存取 + 何时需要 reload」,真正动 runtime 的 session.reload() 走宿主回调
@@ -30,6 +30,11 @@ export class SettingsService {
30
30
  knownExtensions = new Map();
31
31
  /** 流式中改了需要 reload 的设置 → agent_end 后延迟应用(防拆毁运行中 run)。 */
32
32
  pendingReload = false;
33
+ unsubscribeSettings;
34
+ sharedVersion = 0;
35
+ sharedQueue = Promise.resolve();
36
+ committingSettings = false;
37
+ disposed = false;
33
38
  constructor(host,
34
39
  /** 全局子代理模板库(所有客户端共享;模板改动无需 reload runtime)。 */
35
40
  templates,
@@ -41,8 +46,94 @@ export class SettingsService {
41
46
  this.settings = host.stateStore.getSettings(host.clientId);
42
47
  this.presets = host.stateStore.getPresets(host.clientId);
43
48
  }
49
+ /** Immutable snapshot: repeated hot-path reads share the same detached object. */
44
50
  get current() {
45
- return this.settings;
51
+ return (this.host.stateStore.getSettingsSnapshot?.(this.host.clientId) ??
52
+ this.host.stateStore.getSettings(this.host.clientId));
53
+ }
54
+ /** Call once after the host has assigned settingsSvc and finished initialization. */
55
+ subscribeSharedSettings() {
56
+ if (this.unsubscribeSettings || this.disposed)
57
+ return;
58
+ this.sharedVersion = this.host.stateStore.getSettingsVersion();
59
+ this.unsubscribeSettings = this.host.stateStore.subscribeSettings((change) => {
60
+ if (this.committingSettings) {
61
+ this.sharedVersion = Math.max(this.sharedVersion, change.version);
62
+ return;
63
+ }
64
+ return this.receiveSharedSettings(change);
65
+ });
66
+ }
67
+ dispose() {
68
+ this.disposed = true;
69
+ this.unsubscribeSettings?.();
70
+ this.unsubscribeSettings = undefined;
71
+ this.pendingReload = false;
72
+ }
73
+ /** Apply a durable commit without saving it again. Serialize reloads; ignore stale deliveries. */
74
+ receiveSharedSettings(change) {
75
+ if (this.disposed || this.host.isDisposed() || change.version <= this.sharedVersion)
76
+ return this.sharedQueue;
77
+ this.sharedVersion = change.version;
78
+ this.sharedQueue = this.sharedQueue
79
+ .then(async () => {
80
+ if (this.disposed || this.host.isDisposed())
81
+ return;
82
+ await this.applySharedSettings(change.before, change.settings);
83
+ })
84
+ .catch((error) => {
85
+ if (this.disposed || this.host.isDisposed())
86
+ return;
87
+ console.error("[settings] shared settings apply failed:", error);
88
+ this.host.emit({
89
+ type: "notice",
90
+ level: "error",
91
+ text: "共享设置已保存,但当前会话应用失败,请重试或重新加载会话。",
92
+ textEn: "Shared settings were saved, but could not be applied to this session. Retry or reload the session.",
93
+ });
94
+ });
95
+ return this.sharedQueue;
96
+ }
97
+ async applySharedSettings(before, after) {
98
+ const changed = (...keys) => keys.some((key) => JSON.stringify(before[key]) !== JSON.stringify(after[key]));
99
+ if (changed("retryMaxAttempts"))
100
+ this.host.applyRetryOverrides();
101
+ if (changed("steeringMode", "followUpMode"))
102
+ this.host.applyQueueModes?.();
103
+ if (changed("softCapTokens", "softCapByModel"))
104
+ this.host.applyCompactionOverrides();
105
+ if (changed("codemodeMode", "codemodeInlineBudget"))
106
+ this.host.applyCodemodeOverrides?.();
107
+ if (changed("disabledAgentTools", "disabledPluginTools", "disabledPlugins", "toolPromptOverrides", "toolLazyLoading", "terminalToolsEnabled", "editSoftEnabled", "questionnaireEnabled"))
108
+ this.host.applyToolGating();
109
+ if (before.goalModeEnabled !== false && after.goalModeEnabled === false)
110
+ this.host.onGoalModeDisabled?.();
111
+ if (changed("showForkedParentSessions"))
112
+ this.host.onSessionsFilterChanged?.();
113
+ this.push(false);
114
+ this.host.flushSnapshot();
115
+ if (changed("promptMode", "customSystemPrompt", "promptTemplate", "promptOverrides", "promptDisabled", "disabledSkills", "disabledExtensions"))
116
+ await this.applyRuntime();
117
+ }
118
+ commitSettings(patch) {
119
+ this.committingSettings = true;
120
+ try {
121
+ this.host.stateStore.saveSettings(this.host.clientId, patch);
122
+ this.settings = this.host.stateStore.getSettings(this.host.clientId);
123
+ }
124
+ catch (error) {
125
+ this.settings = this.host.stateStore.getSettings(this.host.clientId);
126
+ this.host.emit({
127
+ type: "notice",
128
+ level: "error",
129
+ text: "设置保存失败,修改未生效。请检查磁盘空间和文件权限后重试。",
130
+ textEn: "Settings were not saved or applied. Check disk space and file permissions, then retry.",
131
+ });
132
+ throw error;
133
+ }
134
+ finally {
135
+ this.committingSettings = false;
136
+ }
46
137
  }
47
138
  /** Effective dev-no-cache: explicit setting wins, else source-tree default
48
139
  * (ON from source, OFF for installs) — same rule as the index.html route.
@@ -128,7 +219,11 @@ export class SettingsService {
128
219
  }
129
220
  return false;
130
221
  }
131
- push() {
222
+ push(maintain = true) {
223
+ if (this.disposed || this.host.isDisposed())
224
+ return;
225
+ this.settings = this.host.stateStore.getSettings(this.host.clientId);
226
+ this.presets = this.host.stateStore.getPresets(this.host.clientId);
132
227
  const disabledSkills = new Set(this.settings.disabledSkills);
133
228
  const reviewDisabledSkills = new Set(this.settings.reviewDisabledSkills);
134
229
  const disabledExts = new Set(this.settings.disabledExtensions);
@@ -141,10 +236,11 @@ export class SettingsService {
141
236
  loadedSkillNames = new Set(loadedSkills.map((s) => s.name));
142
237
  loadedExtNames = new Set(loadedExts.map((e) => extensionKey(e)));
143
238
  // 实时全源磁盘扫描:动态发现外部新安装/更新的各类 Agent 全局与本地技能
144
- const diskSkills = discoverDiskSkills({
239
+ const discoveredSkills = discoverDiskSkills({
145
240
  cwd: this.host.cwd(),
146
241
  agentDir: this.host.agentDir(),
147
242
  });
243
+ const diskSkills = this.host.filterDiskSkills?.(discoveredSkills) ?? discoveredSkills;
148
244
  // Prune entries that no longer exist on disk AND aren't disabled
149
245
  // (e.g. a skill/extension file was deleted). Disabled entries are
150
246
  // kept so they can be re-enabled even when filtered out of the loader.
@@ -198,8 +294,8 @@ export class SettingsService {
198
294
  }
199
295
  // 若发现磁盘新增了 loader 尚未加载的技能,触发会话后台异步 reload 以刷新提示词和技能工具
200
296
  const hasUnloadedDiskSkills = diskSkills.some((ds) => !loadedSkillNames.has(ds.name));
201
- if (hasUnloadedDiskSkills && !this.host.isStreaming()) {
202
- void this.host.reloadSession();
297
+ if (maintain && hasUnloadedDiskSkills && !this.host.isStreaming()) {
298
+ void this.applyRuntime();
203
299
  }
204
300
  }
205
301
  catch {
@@ -209,7 +305,7 @@ export class SettingsService {
209
305
  // disabledSkills / reviewDisabledSkills 持久化记录中移除——否则每次
210
306
  // 推送都会把已删除的 skill 以灰条形式永恒地补回面板(“关闭过的
211
307
  // skill 被一直记录”)。session 未就绪时保守跳过。
212
- if (loadedSkillNames !== null) {
308
+ if (maintain && loadedSkillNames !== null) {
213
309
  const stale = [
214
310
  ...new Set([
215
311
  ...this.settings.disabledSkills,
@@ -221,7 +317,7 @@ export class SettingsService {
221
317
  this.settings.disabledSkills = this.settings.disabledSkills.filter((n) => !stale.includes(n));
222
318
  this.settings.reviewDisabledSkills = this.settings.reviewDisabledSkills.filter((n) => !stale.includes(n));
223
319
  this.settings.skillsFullText = normalizeSkillList(this.settings.skillsFullText).filter((n) => !stale.includes(n));
224
- this.host.stateStore.saveSettings(this.host.clientId, {
320
+ this.commitSettings({
225
321
  disabledSkills: this.settings.disabledSkills,
226
322
  reviewDisabledSkills: this.settings.reviewDisabledSkills,
227
323
  skillsFullText: this.settings.skillsFullText,
@@ -234,11 +330,11 @@ export class SettingsService {
234
330
  // disabledExtensions 同理:已卸载(loader 里没有、磁盘/配置里也没有)的扩展
235
331
  // 从禁用记录里剔除并持久化 —— 否则卸载过的扩展以“已禁用”灰条永生(issue #192)。
236
332
  // loadedExtNames 非 null 即 session 就绪;取不到(catch 分支)时保守跳过。
237
- if (loadedExtNames !== null) {
333
+ if (maintain && loadedExtNames !== null) {
238
334
  const staleExts = this.settings.disabledExtensions.filter((id) => isInternalExtension({ path: id }) || (!loadedExtNames.has(id) && !this.extensionStillOnDisk(id)));
239
335
  if (staleExts.length > 0) {
240
336
  this.settings.disabledExtensions = this.settings.disabledExtensions.filter((n) => !staleExts.includes(n));
241
- this.host.stateStore.saveSettings(this.host.clientId, {
337
+ this.commitSettings({
242
338
  disabledExtensions: this.settings.disabledExtensions,
243
339
  });
244
340
  }
@@ -323,6 +419,9 @@ export class SettingsService {
323
419
  showForkedParentSessions: this.settings.showForkedParentSessions ?? false,
324
420
  retainFinishedConversations: this.settings.retainFinishedConversations ?? false,
325
421
  openRecentSessionOnProjectSwitch: this.settings.openRecentSessionOnProjectSwitch ?? true,
422
+ chatUploadMaxMb: this.settings.chatUploadMaxMb ?? 20,
423
+ workspaceUploadMaxMb: this.settings.workspaceUploadMaxMb ?? 100,
424
+ folderUploadMaxMb: this.settings.folderUploadMaxMb ?? 32,
326
425
  visionBridgeEnabled: this.settings.visionBridgeEnabled,
327
426
  visionBridgeModel: this.settings.visionBridgeModel,
328
427
  visionBridgePromptMode: this.settings.visionBridgePromptMode,
@@ -366,7 +465,12 @@ export class SettingsService {
366
465
  subagentDefaultTemplates: DEFAULT_TEMPLATES.map((t) => t.name),
367
466
  subagentDefaultModel: this.settings.subagentDefaultModel ?? null,
368
467
  subagentMaxDepth: this.settings.subagentMaxDepth ?? 0,
468
+ questionPresentation: this.settings.questionPresentation ?? "queue",
469
+ toolApprovalPresentation: this.settings.toolApprovalPresentation ?? "all",
470
+ questionTimeoutSeconds: this.settings.questionTimeoutSeconds ?? 240,
369
471
  subagentAutoWakeMaxTurns: this.settings.subagentAutoWakeMaxTurns ?? defaultSubagentAutoWakeMaxTurns(),
472
+ steeringMode: this.settings.steeringMode,
473
+ followUpMode: this.settings.followUpMode,
370
474
  retryMaxAttempts: this.settings.retryMaxAttempts,
371
475
  softCapTokens: this.settings.softCapTokens,
372
476
  softCapByModel: { ...this.settings.softCapByModel },
@@ -423,6 +527,8 @@ export class SettingsService {
423
527
  /** Persist + apply a partial settings update (compose template / per-source
424
528
  * overrides, skill/extension toggles). */
425
529
  async set(partial) {
530
+ const before = this.host.stateStore.getSettings(this.host.clientId);
531
+ const next = structuredClone(before);
426
532
  const needsReload = partial.promptMode !== undefined ||
427
533
  partial.customSystemPrompt !== undefined ||
428
534
  partial.promptTemplate !== undefined ||
@@ -440,262 +546,303 @@ export class SettingsService {
440
546
  partial.toolPromptOverrides !== undefined ||
441
547
  partial.toolLazyLoading !== undefined;
442
548
  if (partial.promptMode !== undefined)
443
- this.settings.promptMode = partial.promptMode;
549
+ next.promptMode = partial.promptMode;
444
550
  if (partial.customSystemPrompt !== undefined) {
445
- this.settings.customSystemPrompt = partial.customSystemPrompt;
551
+ next.customSystemPrompt = partial.customSystemPrompt;
446
552
  }
447
553
  if (partial.promptTemplate !== undefined) {
448
- this.settings.promptTemplate = partial.promptTemplate;
554
+ next.promptTemplate = partial.promptTemplate;
449
555
  }
450
556
  if (partial.promptOverrides !== undefined) {
451
557
  // 只合并给出的 key;空串 = 清除该来源覆盖。
452
- const next = { ...this.settings.promptOverrides };
558
+ const overrides = { ...next.promptOverrides };
453
559
  for (const [k, v] of Object.entries(partial.promptOverrides)) {
454
560
  if (v && v.trim())
455
- next[k] = v;
561
+ overrides[k] = v;
456
562
  else
457
- delete next[k];
563
+ delete overrides[k];
458
564
  }
459
- this.settings.promptOverrides = next;
565
+ next.promptOverrides = overrides;
460
566
  }
461
567
  if (partial.promptDisabled !== undefined)
462
- this.settings.promptDisabled = [...partial.promptDisabled];
568
+ next.promptDisabled = [...partial.promptDisabled];
463
569
  if (partial.toolPromptOverrides !== undefined) {
464
570
  // 逐工具合并:给出的键整体替换(归一化后为空 = 清除该工具覆盖)。
465
- const next = { ...this.settings.toolPromptOverrides };
571
+ const overrides = { ...next.toolPromptOverrides };
466
572
  const normalized = normalizeToolPromptOverrides(partial.toolPromptOverrides);
467
573
  for (const key of Object.keys(partial.toolPromptOverrides)) {
468
574
  if (normalized[key])
469
- next[key] = normalized[key];
575
+ overrides[key] = normalized[key];
470
576
  else
471
- delete next[key];
577
+ delete overrides[key];
472
578
  }
473
- this.settings.toolPromptOverrides = normalizeToolPromptOverrides(next);
579
+ next.toolPromptOverrides = normalizeToolPromptOverrides(overrides);
474
580
  }
475
581
  if (partial.disabledSkills !== undefined) {
476
- this.settings.disabledSkills = partial.disabledSkills;
582
+ next.disabledSkills = partial.disabledSkills;
477
583
  }
478
584
  if (partial.disabledExtensions !== undefined) {
479
- this.settings.disabledExtensions = partial.disabledExtensions;
585
+ next.disabledExtensions = partial.disabledExtensions;
480
586
  }
481
587
  // 插件开关是纯 UI 隐藏(不进 needsReload——运行时无需重载)。
482
588
  if (partial.disabledPlugins !== undefined) {
483
- this.settings.disabledPlugins = partial.disabledPlugins;
589
+ next.disabledPlugins = partial.disabledPlugins;
484
590
  }
485
591
  // UI 布局偏好只是渲染层的事(顶栏/底栏/右键菜单由前端拼),同样不需 reload。
486
592
  if (partial.uiLayout !== undefined) {
487
- this.settings.uiLayout = normalizeUiLayout(partial.uiLayout);
593
+ next.uiLayout = normalizeUiLayout(partial.uiLayout);
488
594
  }
489
595
  // 统一工具开关:新字段优先;只给遗留单开关时折回新字段。两边写完再由
490
596
  // deriveLegacy 回填遗留别名,保证内存/推送/落盘三处一致。
491
597
  if (partial.disabledAgentTools !== undefined) {
492
- this.settings.disabledAgentTools = normalizeDisabledAgentTools(partial.disabledAgentTools);
598
+ next.disabledAgentTools = normalizeDisabledAgentTools(partial.disabledAgentTools);
493
599
  }
494
600
  if (partial.disabledPluginTools !== undefined) {
495
- this.settings.disabledPluginTools = normalizeDisabledPluginTools(partial.disabledPluginTools);
601
+ next.disabledPluginTools = normalizeDisabledPluginTools(partial.disabledPluginTools);
496
602
  }
497
603
  if (partial.terminalToolsEnabled !== undefined ||
498
604
  partial.editSoftEnabled !== undefined ||
499
605
  partial.questionnaireEnabled !== undefined) {
500
- this.settings.disabledAgentTools = foldLegacyIntoDisabled(this.settings.disabledAgentTools ?? [], {
606
+ next.disabledAgentTools = foldLegacyIntoDisabled(next.disabledAgentTools ?? [], {
501
607
  terminalToolsEnabled: partial.terminalToolsEnabled,
502
608
  editSoftEnabled: partial.editSoftEnabled,
503
609
  questionnaireEnabled: partial.questionnaireEnabled,
504
610
  });
505
611
  }
506
612
  {
507
- const legacy = deriveLegacy(this.settings.disabledAgentTools ?? []);
508
- this.settings.terminalToolsEnabled = legacy.terminalToolsEnabled;
509
- this.settings.editSoftEnabled = legacy.editSoftEnabled;
510
- this.settings.questionnaireEnabled = legacy.questionnaireEnabled;
613
+ const legacy = deriveLegacy(next.disabledAgentTools ?? []);
614
+ next.terminalToolsEnabled = legacy.terminalToolsEnabled;
615
+ next.editSoftEnabled = legacy.editSoftEnabled;
616
+ next.questionnaireEnabled = legacy.questionnaireEnabled;
511
617
  }
512
618
  if (partial.terminalBash !== undefined) {
513
- this.settings.terminalBash = partial.terminalBash;
619
+ next.terminalBash = partial.terminalBash;
514
620
  }
515
621
  if (partial.terminalBashIdleMs !== undefined) {
516
- this.settings.terminalBashIdleMs = Math.max(0, Math.floor(partial.terminalBashIdleMs) || 0);
622
+ next.terminalBashIdleMs = Math.max(0, Math.floor(partial.terminalBashIdleMs) || 0);
517
623
  }
518
624
  if (partial.terminalBashMaxForegroundMs !== undefined) {
519
- this.settings.terminalBashMaxForegroundMs = Math.max(0, Math.floor(partial.terminalBashMaxForegroundMs) || 0);
625
+ next.terminalBashMaxForegroundMs = Math.max(0, Math.floor(partial.terminalBashMaxForegroundMs) || 0);
520
626
  }
521
627
  if (partial.toolWatchdogTimeoutMs !== undefined) {
522
- this.settings.toolWatchdogTimeoutMs = normalizeToolWatchdogTimeoutMs(partial.toolWatchdogTimeoutMs);
628
+ next.toolWatchdogTimeoutMs = normalizeToolWatchdogTimeoutMs(partial.toolWatchdogTimeoutMs);
523
629
  }
524
630
  // read 读目录开关:覆盖定义每次调用实时读取,改动即时生效,无需 reload。
525
631
  if (partial.readDirEnabled !== undefined) {
526
- this.settings.readDirEnabled = partial.readDirEnabled;
632
+ next.readDirEnabled = partial.readDirEnabled;
527
633
  }
528
634
  // 「后台任务」自动清理阈值(分钟;0 = 关):bg-servers 的定时器每轮实时读,即时生效。
529
635
  if (partial.bgAutoCleanupMin !== undefined) {
530
- this.settings.bgAutoCleanupMin = normalizeBgCleanupMinutes(partial.bgAutoCleanupMin);
636
+ next.bgAutoCleanupMin = normalizeBgCleanupMinutes(partial.bgAutoCleanupMin);
531
637
  }
532
638
  // 工具延迟加载开关(默认关,设置页可开):门控每次实时读取,改动经 applyToolGating 重放生效
533
639
  // (见 toolGatingChanged)——**只影响新会话与之后的门控重放**,已有对话的已加载
534
640
  // 集合不会被反向清空(不想让在跑的对话凭空丢掉工具)。
535
641
  if (partial.toolLazyLoading !== undefined) {
536
- this.settings.toolLazyLoading = partial.toolLazyLoading === true;
642
+ next.toolLazyLoading = partial.toolLazyLoading === true;
537
643
  }
538
644
  let codemodeChanged = false;
539
- if (partial.codemodeMode !== undefined && partial.codemodeMode !== this.settings.codemodeMode) {
540
- this.settings.codemodeMode = partial.codemodeMode;
645
+ if (partial.codemodeMode !== undefined && partial.codemodeMode !== next.codemodeMode) {
646
+ next.codemodeMode = partial.codemodeMode;
541
647
  codemodeChanged = true;
542
648
  }
543
- if (partial.codemodeInlineBudget !== undefined &&
544
- partial.codemodeInlineBudget !== this.settings.codemodeInlineBudget) {
545
- this.settings.codemodeInlineBudget = partial.codemodeInlineBudget;
649
+ if (partial.codemodeInlineBudget !== undefined && partial.codemodeInlineBudget !== next.codemodeInlineBudget) {
650
+ next.codemodeInlineBudget = partial.codemodeInlineBudget;
546
651
  codemodeChanged = true;
547
652
  }
548
- if (codemodeChanged) {
549
- this.host.applyCodemodeOverrides?.();
550
- }
551
653
  // 工具执行审批总开关:审批入口每次实时读取(askApproval 顶部门禁),无需 reload。
552
654
  if (partial.toolApprovalEnabled !== undefined) {
553
- this.settings.toolApprovalEnabled = partial.toolApprovalEnabled;
655
+ next.toolApprovalEnabled = partial.toolApprovalEnabled;
554
656
  }
555
657
  // 目标模式总开关:运行时无需重载(goal bar / 服务端入口实时读取)。
556
658
  // on→off 时立即停掉在飞的目标/调研 —— 不停的话循环照跑照派,开关名存实亡。
557
659
  if (partial.goalModeEnabled !== undefined) {
558
- const wasOn = this.settings.goalModeEnabled !== false;
559
- this.settings.goalModeEnabled = partial.goalModeEnabled;
560
- if (wasOn && partial.goalModeEnabled === false)
561
- this.host.onGoalModeDisabled?.();
660
+ next.goalModeEnabled = partial.goalModeEnabled;
562
661
  }
563
662
  // 同项目并行提醒开关:同上,发送入口逐轮实时读取,无需 reload。
564
663
  if (partial.parallelReminderEnabled !== undefined) {
565
- this.settings.parallelReminderEnabled = partial.parallelReminderEnabled;
664
+ next.parallelReminderEnabled = partial.parallelReminderEnabled;
566
665
  }
567
666
  if (partial.devNoCache !== undefined) {
568
- this.settings.devNoCache = partial.devNoCache;
667
+ next.devNoCache = partial.devNoCache;
569
668
  }
570
669
  if (partial.autoReload !== undefined) {
571
- this.settings.autoReload = partial.autoReload;
670
+ next.autoReload = partial.autoReload;
572
671
  }
573
672
  if (partial.thinkingWrap !== undefined) {
574
- this.settings.thinkingWrap = partial.thinkingWrap;
673
+ next.thinkingWrap = partial.thinkingWrap;
575
674
  }
576
675
  if (partial.toolsWrap !== undefined) {
577
- this.settings.toolsWrap = partial.toolsWrap;
676
+ next.toolsWrap = partial.toolsWrap;
578
677
  }
579
678
  if (partial.toolImagesEnabled !== undefined) {
580
- this.settings.toolImagesEnabled = partial.toolImagesEnabled;
679
+ next.toolImagesEnabled = partial.toolImagesEnabled;
581
680
  }
582
681
  if (partial.keepRecentMessages !== undefined) {
583
- this.settings.keepRecentMessages = normalizeKeepRecentMessages(partial.keepRecentMessages);
682
+ next.keepRecentMessages = normalizeKeepRecentMessages(partial.keepRecentMessages);
584
683
  }
585
684
  // 向上分页加载:前端 MessageList 实时读它(纯渲染策略),无需 reload runtime。
586
685
  if (partial.reversePagination !== undefined) {
587
- this.settings.reversePagination = Boolean(partial.reversePagination);
686
+ next.reversePagination = Boolean(partial.reversePagination);
588
687
  }
589
688
  if (partial.retainFinishedConversations !== undefined) {
590
- this.settings.retainFinishedConversations = Boolean(partial.retainFinishedConversations);
689
+ next.retainFinishedConversations = Boolean(partial.retainFinishedConversations);
591
690
  }
592
691
  if (partial.openRecentSessionOnProjectSwitch !== undefined) {
593
- this.settings.openRecentSessionOnProjectSwitch = Boolean(partial.openRecentSessionOnProjectSwitch);
692
+ next.openRecentSessionOnProjectSwitch = Boolean(partial.openRecentSessionOnProjectSwitch);
594
693
  }
595
694
  let sessionsFilterChanged = false;
596
695
  if (partial.showForkedParentSessions !== undefined) {
597
696
  const nextVal = Boolean(partial.showForkedParentSessions);
598
- if (nextVal !== (this.settings.showForkedParentSessions ?? false)) {
697
+ if (nextVal !== (next.showForkedParentSessions ?? false)) {
599
698
  sessionsFilterChanged = true;
600
699
  }
601
- this.settings.showForkedParentSessions = nextVal;
700
+ next.showForkedParentSessions = nextVal;
602
701
  }
603
702
  // 编排模式 / skill 全文注入:before_agent_start 逐 run 实时读取(agent-service
604
703
  // composeInputs + 指导块追加),开关下一轮即生效,无需 reload runtime。
605
704
  if (partial.skillsFullText !== undefined) {
606
- this.settings.skillsFullText = normalizeSkillList(partial.skillsFullText);
705
+ next.skillsFullText = normalizeSkillList(partial.skillsFullText);
607
706
  }
608
707
  if (partial.skillsCatalogMaxDesc !== undefined) {
609
- this.settings.skillsCatalogMaxDesc = normalizeSkillsCatalogMaxDesc(partial.skillsCatalogMaxDesc);
708
+ next.skillsCatalogMaxDesc = normalizeSkillsCatalogMaxDesc(partial.skillsCatalogMaxDesc);
610
709
  }
611
710
  if (partial.skillsCatalogShowLocation !== undefined) {
612
- this.settings.skillsCatalogShowLocation = Boolean(partial.skillsCatalogShowLocation);
711
+ next.skillsCatalogShowLocation = Boolean(partial.skillsCatalogShowLocation);
613
712
  }
614
713
  if (partial.skillsCatalogBudget !== undefined) {
615
- this.settings.skillsCatalogBudget = normalizeSkillsCatalogBudget(partial.skillsCatalogBudget);
714
+ next.skillsCatalogBudget = normalizeSkillsCatalogBudget(partial.skillsCatalogBudget);
715
+ }
716
+ for (const key of ["chatUploadMaxMb", "workspaceUploadMaxMb", "folderUploadMaxMb"]) {
717
+ if (partial[key] !== undefined)
718
+ next[key] = partial[key];
616
719
  }
617
720
  if (partial.visionBridgeEnabled !== undefined) {
618
- this.settings.visionBridgeEnabled = partial.visionBridgeEnabled;
721
+ next.visionBridgeEnabled = partial.visionBridgeEnabled;
619
722
  }
620
723
  if (partial.visionBridgeModel !== undefined) {
621
- this.settings.visionBridgeModel = partial.visionBridgeModel ?? null;
724
+ next.visionBridgeModel = partial.visionBridgeModel ?? null;
622
725
  }
623
726
  if (partial.visionBridgePromptMode !== undefined) {
624
- this.settings.visionBridgePromptMode = partial.visionBridgePromptMode;
727
+ next.visionBridgePromptMode = partial.visionBridgePromptMode;
625
728
  }
626
729
  if (partial.visionBridgePrompt !== undefined) {
627
- this.settings.visionBridgePrompt = partial.visionBridgePrompt;
730
+ next.visionBridgePrompt = partial.visionBridgePrompt;
628
731
  }
629
732
  if (partial.scmCommitMsgPromptMode !== undefined) {
630
- this.settings.scmCommitMsgPromptMode = partial.scmCommitMsgPromptMode;
733
+ next.scmCommitMsgPromptMode = partial.scmCommitMsgPromptMode;
631
734
  }
632
735
  if (partial.scmCommitMsgPrompt !== undefined) {
633
- this.settings.scmCommitMsgPrompt = partial.scmCommitMsgPrompt;
736
+ next.scmCommitMsgPrompt = partial.scmCommitMsgPrompt;
634
737
  }
635
738
  if (partial.planModePromptMode !== undefined) {
636
- this.settings.planModePromptMode = partial.planModePromptMode;
739
+ next.planModePromptMode = partial.planModePromptMode;
637
740
  }
638
741
  if (partial.planModePrompt !== undefined) {
639
- this.settings.planModePrompt = partial.planModePrompt;
742
+ next.planModePrompt = partial.planModePrompt;
640
743
  }
641
744
  if (partial.reviewPrompt !== undefined) {
642
- this.settings.reviewPrompt = partial.reviewPrompt;
745
+ next.reviewPrompt = partial.reviewPrompt;
643
746
  }
644
747
  if (partial.reviewDisabledSkills !== undefined) {
645
- this.settings.reviewDisabledSkills = partial.reviewDisabledSkills;
748
+ next.reviewDisabledSkills = partial.reviewDisabledSkills;
646
749
  }
647
750
  if (partial.subagentDefaultModel !== undefined) {
648
751
  // 空串归一为 null(跟随主对话);其余剥空白后存格式 provider/id。
649
752
  const m = partial.subagentDefaultModel?.trim() ?? "";
650
- this.settings.subagentDefaultModel = m ? m : null;
753
+ next.subagentDefaultModel = m ? m : null;
754
+ }
755
+ if (partial.questionPresentation !== undefined) {
756
+ if (!["queue", "all", "manual"].includes(partial.questionPresentation))
757
+ throw new Error("Invalid questionnaire presentation");
758
+ next.questionPresentation = partial.questionPresentation;
759
+ }
760
+ if (partial.toolApprovalPresentation !== undefined) {
761
+ if (!["queue", "all", "manual"].includes(partial.toolApprovalPresentation))
762
+ throw new Error("Invalid tool approval presentation");
763
+ next.toolApprovalPresentation = partial.toolApprovalPresentation;
764
+ }
765
+ if (partial.questionTimeoutSeconds !== undefined) {
766
+ const seconds = partial.questionTimeoutSeconds;
767
+ if (!Number.isSafeInteger(seconds) || seconds < 0 || seconds > 86400)
768
+ throw new Error("Question timeout must be 0–86400 seconds");
769
+ next.questionTimeoutSeconds = seconds;
651
770
  }
652
771
  if (partial.subagentMaxDepth !== undefined) {
653
772
  const n = Math.floor(Number(partial.subagentMaxDepth));
654
- this.settings.subagentMaxDepth = Number.isFinite(n) && n > 0 ? n : 0;
773
+ next.subagentMaxDepth = Number.isFinite(n) && n > 0 ? n : 0;
655
774
  }
656
775
  if (partial.subagentAutoWakeMaxTurns !== undefined) {
657
- this.settings.subagentAutoWakeMaxTurns = normalizeSubagentAutoWakeMaxTurns(partial.subagentAutoWakeMaxTurns);
776
+ next.subagentAutoWakeMaxTurns = normalizeSubagentAutoWakeMaxTurns(partial.subagentAutoWakeMaxTurns);
777
+ }
778
+ for (const key of ["steeringMode", "followUpMode"]) {
779
+ const mode = partial[key];
780
+ if (mode === undefined)
781
+ continue;
782
+ if (mode !== "all" && mode !== "one-at-a-time")
783
+ throw new Error(`Invalid ${key}`);
784
+ next[key] = mode;
658
785
  }
659
786
  if (partial.retryMaxAttempts !== undefined) {
660
787
  // 出错重试次数:持久化 + 即时注入各会话(SDK 在每次退避前都重读
661
788
  // getRetrySettings,无需 reload runtime;见宿主 applyRetryOverrides)。
662
- this.settings.retryMaxAttempts = normalizeRetryMaxAttempts(partial.retryMaxAttempts);
663
- this.host.applyRetryOverrides();
789
+ next.retryMaxAttempts = normalizeRetryMaxAttempts(partial.retryMaxAttempts);
664
790
  }
665
791
  if (partial.softCapTokens !== undefined || partial.softCapByModel !== undefined) {
666
792
  // 压缩软上限:持久化 + 即时重算各会话的 compaction reserveTokens
667
793
  // 覆盖(SDK 每次自动压缩检查前都重读 getCompactionSettings,无需
668
794
  // reload;见宿主 applyCompactionOverrides,issue #229)。
669
795
  if (partial.softCapTokens !== undefined)
670
- this.settings.softCapTokens = normalizeSoftCapTokens(partial.softCapTokens);
796
+ next.softCapTokens = normalizeSoftCapTokens(partial.softCapTokens);
671
797
  if (partial.softCapByModel !== undefined)
672
- this.settings.softCapByModel = normalizeSoftCapByModel(partial.softCapByModel);
673
- this.host.applyCompactionOverrides();
798
+ next.softCapByModel = normalizeSoftCapByModel(partial.softCapByModel);
674
799
  // 底栏标记线读快照的 contextUsage.softCap——推一次快照让在线页即时看到。
675
- this.host.flushSnapshot();
676
800
  }
677
801
  if (partial.quickPhrases !== undefined) {
678
802
  // 归一化:去空白/空项/重名,单条 ≤200 字,最多 30 条。纯 UI 偏好,不 reload。
679
803
  const seen = new Set();
680
- this.settings.quickPhrases = (Array.isArray(partial.quickPhrases) ? partial.quickPhrases : [])
804
+ next.quickPhrases = (Array.isArray(partial.quickPhrases) ? partial.quickPhrases : [])
681
805
  .map((p) => String(p).trim().slice(0, 200))
682
806
  .filter((p) => p && !seen.has(p) && (seen.add(p), true))
683
807
  .slice(0, 30);
684
808
  }
685
809
  if (partial.quickPhrasesEnabled !== undefined) {
686
- this.settings.quickPhrasesEnabled = partial.quickPhrasesEnabled;
810
+ next.quickPhrasesEnabled = partial.quickPhrasesEnabled;
687
811
  }
688
812
  if (partial.minimalNewChat !== undefined) {
689
- this.settings.minimalNewChat = partial.minimalNewChat;
813
+ next.minimalNewChat = partial.minimalNewChat;
690
814
  }
691
815
  if (partial.preserveDraftAcrossConversations !== undefined) {
692
- this.settings.preserveDraftAcrossConversations = Boolean(partial.preserveDraftAcrossConversations);
816
+ next.preserveDraftAcrossConversations = Boolean(partial.preserveDraftAcrossConversations);
693
817
  }
694
818
  // 统一工具开关 live 生效(ActiveSet 加减;失败静默,下次创建/reload 重放)。
695
819
  // 必须在 this.push() 前生效,保证 promptSnapshot 收集到的是最新的活跃工具集与完整提示词!
820
+ const patch = {};
821
+ for (const key of Object.keys(partial)) {
822
+ if (key in next && partial[key] !== undefined) {
823
+ Object.assign(patch, { [key]: next[key] });
824
+ }
825
+ }
826
+ if (partial.disabledAgentTools !== undefined ||
827
+ partial.terminalToolsEnabled !== undefined ||
828
+ partial.editSoftEnabled !== undefined ||
829
+ partial.questionnaireEnabled !== undefined) {
830
+ patch.disabledAgentTools = next.disabledAgentTools;
831
+ Object.assign(patch, deriveLegacy(next.disabledAgentTools ?? []));
832
+ }
833
+ this.commitSettings(patch);
834
+ if (codemodeChanged)
835
+ this.host.applyCodemodeOverrides?.();
836
+ if (before.goalModeEnabled !== false && next.goalModeEnabled === false)
837
+ this.host.onGoalModeDisabled?.();
838
+ if (partial.retryMaxAttempts !== undefined)
839
+ this.host.applyRetryOverrides();
840
+ if (before.steeringMode !== next.steeringMode || before.followUpMode !== next.followUpMode)
841
+ this.host.applyQueueModes?.();
842
+ if (partial.softCapTokens !== undefined || partial.softCapByModel !== undefined)
843
+ this.host.applyCompactionOverrides();
696
844
  if (toolGatingChanged)
697
845
  this.host.applyToolGating();
698
- this.host.stateStore.saveSettings(this.host.clientId, this.settings);
699
846
  this.push();
700
847
  if (sessionsFilterChanged)
701
848
  this.host.onSessionsFilterChanged?.();
@@ -715,6 +862,7 @@ export class SettingsService {
715
862
  });
716
863
  return;
717
864
  }
865
+ this.presets = this.host.stateStore.getPresets(this.host.clientId);
718
866
  const preset = this.snapshotPreset(n);
719
867
  const existing = this.presets.findIndex((p) => p.name === n);
720
868
  if (existing >= 0)
@@ -728,11 +876,13 @@ export class SettingsService {
728
876
  * **全量**:`ClientSettings` 的每个字段都进预设(字段清单/分组见 `server/preset-fields.ts`),
729
877
  * 导出/分享/导入共用同一张白名单;深层对象做一份拷贝,避免与当前设置共享引用。 */
730
878
  snapshotPreset(name) {
731
- const s = structuredClone(this.settings);
879
+ const s = structuredClone(this.current);
732
880
  return { ...s, name };
733
881
  }
734
882
  /** Replace the current settings with the named preset and apply it. */
735
883
  async applyPreset(name) {
884
+ this.settings = this.current;
885
+ this.presets = this.host.stateStore.getPresets(this.host.clientId);
736
886
  const p = this.presets.find((x) => x.name === name);
737
887
  if (!p) {
738
888
  this.host.emit({
@@ -744,6 +894,7 @@ export class SettingsService {
744
894
  return;
745
895
  }
746
896
  // 统一工具开关:新预设直接用它;旧预设(只有遗留两开关)按当前禁用名单折算。
897
+ const hasToolSettings = ["disabledAgentTools", "terminalToolsEnabled", "editSoftEnabled"].some((key) => Object.prototype.hasOwnProperty.call(p, key));
747
898
  const presetDisabled = normalizeDisabledAgentTools(p.disabledAgentTools ??
748
899
  foldLegacyIntoDisabled(this.settings.disabledAgentTools ?? [], {
749
900
  terminalToolsEnabled: p.terminalToolsEnabled,
@@ -754,25 +905,30 @@ export class SettingsService {
754
905
  // 旧预设(19 字段)、以及导入时只勾了一部分的预设,都靠这个 merge 落地。
755
906
  const patch = { ...p };
756
907
  delete patch.name;
908
+ delete patch.plugins;
757
909
  for (const k of Object.keys(patch))
758
910
  if (patch[k] === undefined)
759
911
  delete patch[k];
760
912
  const prevShowForked = this.settings.showForkedParentSessions ?? false;
761
- this.settings = {
762
- ...this.settings,
913
+ this.commitSettings({
763
914
  ...patch,
764
- // 工具开关与两个遗留别名以派生结果为准(单源:disabledAgentTools)。
765
- disabledAgentTools: presetDisabled,
766
- terminalToolsEnabled: presetLegacy.terminalToolsEnabled,
767
- editSoftEnabled: presetLegacy.editSoftEnabled,
768
- };
769
- this.host.stateStore.saveSettings(this.host.clientId, this.settings);
915
+ // 部分预设未携带工具字段时,保持当前设置;遗留别名仍统一派生。
916
+ ...(hasToolSettings
917
+ ? {
918
+ disabledAgentTools: presetDisabled,
919
+ terminalToolsEnabled: presetLegacy.terminalToolsEnabled,
920
+ editSoftEnabled: presetLegacy.editSoftEnabled,
921
+ }
922
+ : {}),
923
+ });
770
924
  // 统一收口重放配置覆盖与工具门控(包含 retry/compaction/codemode 与 toolGating)
771
925
  if (this.host.applySessionOverrides) {
772
926
  this.host.applySessionOverrides();
773
927
  }
774
928
  else {
775
929
  this.host.applyRetryOverrides();
930
+ this.host.applyQueueModes?.();
931
+ this.host.applyCompactionOverrides();
776
932
  this.host.applyCodemodeOverrides?.();
777
933
  this.host.applyToolGating();
778
934
  }
@@ -780,11 +936,11 @@ export class SettingsService {
780
936
  if ((this.settings.showForkedParentSessions ?? false) !== prevShowForked) {
781
937
  this.host.onSessionsFilterChanged?.();
782
938
  }
783
- await this.applyRuntime();
939
+ await this.applyRuntime(true);
784
940
  }
785
941
  /** Remove a named preset. */
786
942
  async deletePreset(name) {
787
- this.presets = this.presets.filter((p) => p.name !== name);
943
+ this.presets = this.host.stateStore.getPresets(this.host.clientId).filter((p) => p.name !== name);
788
944
  this.host.stateStore.savePresets(this.host.clientId, this.presets);
789
945
  this.push();
790
946
  }
@@ -800,12 +956,13 @@ export class SettingsService {
800
956
  return {
801
957
  lang: () => this.lang,
802
958
  appVersion: () => packageVersion(),
803
- presets: () => this.presets,
959
+ presets: () => this.host.stateStore.getPresets(this.host.clientId),
804
960
  currentSettings: () => {
805
961
  const { name: _drop, ...rest } = this.snapshotPreset("");
806
962
  return { ...rest };
807
963
  },
808
964
  upsertPreset: (preset) => {
965
+ this.presets = this.host.stateStore.getPresets(this.host.clientId);
809
966
  const i = this.presets.findIndex((p) => p.name === preset.name);
810
967
  if (i >= 0)
811
968
  this.presets[i] = preset;
@@ -814,6 +971,7 @@ export class SettingsService {
814
971
  this.host.stateStore.savePresets(this.host.clientId, this.presets);
815
972
  },
816
973
  applyPreset: (name) => this.applyPreset(name),
974
+ isApplyPending: () => this.hasPendingReload(),
817
975
  pushSettings: () => this.push(),
818
976
  emit: (msg) => this.host.emit(msg),
819
977
  };
@@ -964,8 +1122,8 @@ export class SettingsService {
964
1122
  * overrides read this.settings at call time, so a reload re-applies them.
965
1123
  * Reloading mid-stream would tear down the in-flight run — defer instead.
966
1124
  */
967
- async applyRuntime() {
968
- if (this.host.isDisposed())
1125
+ async applyRuntime(throwOnError = false) {
1126
+ if (this.disposed || this.host.isDisposed())
969
1127
  return;
970
1128
  if (this.host.isStreaming()) {
971
1129
  this.pendingReload = true;
@@ -977,11 +1135,11 @@ export class SettingsService {
977
1135
  });
978
1136
  return;
979
1137
  }
980
- await this.applyReload();
1138
+ await this.applyReload(throwOnError);
981
1139
  }
982
1140
  /** session.reload() + refresh the slash-command catalog + push state. */
983
- async applyReload() {
984
- if (this.host.isDisposed())
1141
+ async applyReload(throwOnError = false) {
1142
+ if (this.disposed || this.host.isDisposed())
985
1143
  return;
986
1144
  if (this.host.isStreaming()) {
987
1145
  this.pendingReload = true;
@@ -995,7 +1153,9 @@ export class SettingsService {
995
1153
  }
996
1154
  try {
997
1155
  await this.host.reloadSession();
998
- this.push();
1156
+ if (this.disposed || this.host.isDisposed())
1157
+ return;
1158
+ this.push(false);
999
1159
  this.host.flushSnapshot();
1000
1160
  this.host.emit({ type: "notice", level: "info", text: "设置已应用", textEn: "Settings applied" });
1001
1161
  }
@@ -1007,6 +1167,8 @@ export class SettingsService {
1007
1167
  text: `设置应用失败:${err.message}`,
1008
1168
  textEn: `Failed to apply settings: ${err.message}`,
1009
1169
  });
1170
+ if (throwOnError)
1171
+ throw err;
1010
1172
  }
1011
1173
  }
1012
1174
  }