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
@@ -46,6 +46,9 @@ export const PRESET_FIELD_GROUPS = {
46
46
  "toolApprovalEnabled",
47
47
  "toolWatchdogTimeoutMs",
48
48
  "questionnaireEnabled",
49
+ "questionPresentation",
50
+ "toolApprovalPresentation",
51
+ "questionTimeoutSeconds",
49
52
  "editSoftEnabled",
50
53
  "terminalToolsEnabled",
51
54
  ],
@@ -62,6 +65,8 @@ export const PRESET_FIELD_GROUPS = {
62
65
  ],
63
66
  // 模型侧行为与各专用提示词
64
67
  ai: [
68
+ "steeringMode",
69
+ "followUpMode",
65
70
  "retryMaxAttempts",
66
71
  "softCapTokens",
67
72
  "softCapByModel",
@@ -91,6 +96,9 @@ export const PRESET_FIELD_GROUPS = {
91
96
  "showForkedParentSessions",
92
97
  "retainFinishedConversations",
93
98
  "openRecentSessionOnProjectSwitch",
99
+ "chatUploadMaxMb",
100
+ "workspaceUploadMaxMb",
101
+ "folderUploadMaxMb",
94
102
  "bgAutoCleanupMin",
95
103
  "quickPhrases",
96
104
  "quickPhrasesEnabled",
@@ -231,6 +239,24 @@ export const PRESET_FIELD_META = {
231
239
  hintZh: "执行危险或写操作工具前弹出用户确认确认框",
232
240
  hintEn: "Require user approval before executing tools",
233
241
  },
242
+ chatUploadMaxMb: {
243
+ labelZh: "聊天附件大小上限",
244
+ labelEn: "Chat attachment size limit",
245
+ hintZh: "单个文件大小,单位 MB(1–100)",
246
+ hintEn: "Per-file limit in MB (1–100)",
247
+ },
248
+ workspaceUploadMaxMb: {
249
+ labelZh: "文件面板上传大小上限",
250
+ labelEn: "File panel upload size limit",
251
+ hintZh: "单个文件大小,单位 MB(1–100)",
252
+ hintEn: "Per-file limit in MB (1–100)",
253
+ },
254
+ folderUploadMaxMb: {
255
+ labelZh: "文件夹上传大小上限",
256
+ labelEn: "Folder upload size limit",
257
+ hintZh: "每个文件的大小,单位 MB(1–100)",
258
+ hintEn: "Per-file limit in MB (1–100)",
259
+ },
234
260
  bgAutoCleanupMin: {
235
261
  labelZh: "后台任务自动清理",
236
262
  labelEn: "Background Task Auto-cleanup",
@@ -249,6 +275,24 @@ export const PRESET_FIELD_META = {
249
275
  hintZh: "允许 AI 遇到歧义时弹窗向用户多选/单选确认",
250
276
  hintEn: "Allow agent to ask interactive multiple-choice questions",
251
277
  },
278
+ questionPresentation: {
279
+ labelZh: "问卷提醒方式",
280
+ labelEn: "Questionnaire reminders",
281
+ hintZh: "当前对话弹出、全部弹出或仅队列",
282
+ hintEn: "Current conversation, all popups, or manual queue",
283
+ },
284
+ toolApprovalPresentation: {
285
+ labelZh: "工具审批提醒方式",
286
+ labelEn: "Tool approval reminders",
287
+ hintZh: "当前对话弹出、全部弹出或仅队列",
288
+ hintEn: "Current conversation, all popups, or manual queue",
289
+ },
290
+ questionTimeoutSeconds: {
291
+ labelZh: "子代理问卷等待期限",
292
+ labelEn: "Subagent question timeout",
293
+ hintZh: "秒;0 为持续等待,超时不自动选择答案",
294
+ hintEn: "Seconds; 0 waits indefinitely, timeout never selects an answer",
295
+ },
252
296
  editSoftEnabled: {
253
297
  labelZh: "宽松缩进编辑 (edit_soft)",
254
298
  labelEn: "Soft Indentation Edit",
@@ -318,6 +362,18 @@ export const PRESET_FIELD_META = {
318
362
  hintEn: "Total catalog character limit (default 20000), falls back to compact name index when exceeded",
319
363
  },
320
364
  // ai
365
+ steeringMode: {
366
+ labelZh: "插话队列模式",
367
+ labelEn: "Steering Queue Mode",
368
+ hintZh: "一次处理全部插话或每次一条",
369
+ hintEn: "Process all queued steering messages or one at a time",
370
+ },
371
+ followUpMode: {
372
+ labelZh: "追问队列模式",
373
+ labelEn: "Follow-Up Queue Mode",
374
+ hintZh: "一次处理全部追问或每次一条",
375
+ hintEn: "Process all queued follow-up messages or one at a time",
376
+ },
321
377
  retryMaxAttempts: {
322
378
  labelZh: "网络重试上限",
323
379
  labelEn: "Network Retry Attempts",
@@ -0,0 +1,57 @@
1
+ const MAX_PLUGINS = 32;
2
+ const ID_RE = /^[A-Za-z0-9_-]{1,100}$/;
3
+ /** Share portable GitHub sources only; never leak local paths or URL credentials. */
4
+ export function portablePresetPluginSource(value) {
5
+ if (typeof value !== "string" || value.length > 300)
6
+ return undefined;
7
+ const source = value.trim();
8
+ if (!source || /[\s\\\x00-\x1f\x7f]/.test(source))
9
+ return undefined;
10
+ let spec = source;
11
+ if (source.startsWith("https://")) {
12
+ try {
13
+ const url = new URL(source);
14
+ if (url.hostname !== "github.com" || url.username || url.password || url.port || url.search)
15
+ return undefined;
16
+ spec = url.pathname.slice(1) + url.hash;
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
22
+ const [path, ref, extra] = spec.split("#");
23
+ if (extra !== undefined || !path || (ref !== undefined && !/^[A-Za-z0-9_./-]+$/.test(ref)))
24
+ return undefined;
25
+ const segments = path.split("/");
26
+ if (segments.length < 2 || segments.some((part) => !/^[A-Za-z0-9_.-]+$/.test(part) || part === "." || part === ".."))
27
+ return undefined;
28
+ if (ref?.split("/").some((part) => !part || part === "." || part === ".."))
29
+ return undefined;
30
+ return spec;
31
+ }
32
+ /** Untrusted metadata is bounded and allowlisted independently of settings. */
33
+ export function normalizePresetPlugins(input) {
34
+ if (!Array.isArray(input))
35
+ return [];
36
+ const result = [];
37
+ const seen = new Set();
38
+ for (const raw of input.slice(0, MAX_PLUGINS)) {
39
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
40
+ continue;
41
+ const item = raw;
42
+ if (typeof item.id !== "string" || !ID_RE.test(item.id) || seen.has(item.id))
43
+ continue;
44
+ seen.add(item.id);
45
+ const text = (value, max) => (typeof value === "string" ? value.trim().slice(0, max) : "");
46
+ const name = text(item.name, 100);
47
+ const version = text(item.version, 60);
48
+ const source = portablePresetPluginSource(item.source);
49
+ result.push({
50
+ id: item.id,
51
+ ...(name ? { name } : {}),
52
+ ...(version ? { version } : {}),
53
+ ...(source ? { source } : {}),
54
+ });
55
+ }
56
+ return result;
57
+ }
@@ -31,9 +31,10 @@ import { pick } from "./i18n.js";
31
31
  import { normalizeSoftCapByModel, normalizeSoftCapTokens } from "./soft-cap.js";
32
32
  import { ALL_KNOWN_AGENT_TOOL_NAMES, isConfigurableAgentTool, normalizeDisabledAgentTools, resolveDisabledAgentToolsFromEnabled, resolveEnabledAgentTools, } from "./tool-manager.js";
33
33
  import { normalizeToolPromptOverrides } from "./tool-prompt-overrides.js";
34
- import { isNativeGlobalFetch, resolveAndValidateUrl, validateFetchUrl } from "./net-guard.js";
34
+ import { FetchUrlError, readBeforeAbort, safeFetch, validateFetchUrl } from "./net-guard.js";
35
35
  import { PRESET_FIELD_NAMES, normalizePresetFieldSelection } from "./preset-fields.js";
36
36
  import { defaultFetcher } from "./update-check.js";
37
+ import { normalizePresetPlugins } from "./preset-plugin-dependencies.js";
37
38
  const execFileAsync = promisify(execFile);
38
39
  /** 预览文本的截断长度(设置面板展示用)。 */
39
40
  const PREVIEW_TEXT_MAX = 400;
@@ -174,6 +175,9 @@ export function buildShareDoc(name, settings, meta = {}) {
174
175
  appVersion: clampText(meta.appVersion, 40),
175
176
  settings,
176
177
  };
178
+ const plugins = normalizePresetPlugins(meta.plugins);
179
+ if (plugins.length)
180
+ doc.plugins = plugins;
177
181
  if (Array.isArray(settings["disabledAgentTools"])) {
178
182
  doc.enabledTools = resolveEnabledAgentTools(settings["disabledAgentTools"]);
179
183
  }
@@ -236,10 +240,16 @@ const PRESET_FIELD_KINDS = {
236
240
  codemodeMode: "codemodeMode",
237
241
  codemodeInlineBudget: "number",
238
242
  readDirEnabled: "bool",
243
+ chatUploadMaxMb: "number",
244
+ workspaceUploadMaxMb: "number",
245
+ folderUploadMaxMb: "number",
239
246
  bgAutoCleanupMin: "number",
240
247
  toolApprovalEnabled: "bool",
241
248
  toolWatchdogTimeoutMs: "number",
242
249
  questionnaireEnabled: "bool",
250
+ questionPresentation: "questionPresentation",
251
+ toolApprovalPresentation: "questionPresentation",
252
+ questionTimeoutSeconds: "questionTimeout",
243
253
  editSoftEnabled: "bool",
244
254
  terminalToolsEnabled: "bool",
245
255
  // -- terminal --------------------------------------------------------
@@ -254,6 +264,8 @@ const PRESET_FIELD_KINDS = {
254
264
  skillsCatalogShowLocation: "bool",
255
265
  skillsCatalogBudget: "number",
256
266
  // -- ai --------------------------------------------------------------
267
+ steeringMode: "queueMode",
268
+ followUpMode: "queueMode",
257
269
  retryMaxAttempts: "retry",
258
270
  softCapTokens: "softCap",
259
271
  softCapByModel: "softCapByModel",
@@ -378,6 +390,18 @@ export function sanitizePresetSettings(input, opts) {
378
390
  else
379
391
  rejected.push(key);
380
392
  break;
393
+ case "questionPresentation":
394
+ if (raw === "queue" || raw === "all" || raw === "manual")
395
+ settings[key] = raw;
396
+ else
397
+ rejected.push(key);
398
+ break;
399
+ case "questionTimeout":
400
+ if (typeof raw === "number" && Number.isSafeInteger(raw) && raw >= 0 && raw <= 86400)
401
+ settings[key] = raw;
402
+ else
403
+ rejected.push(key);
404
+ break;
381
405
  case "codemodeMode":
382
406
  if (raw === "on" || raw === "only")
383
407
  settings[key] = raw;
@@ -390,6 +414,12 @@ export function sanitizePresetSettings(input, opts) {
390
414
  else
391
415
  rejected.push(key);
392
416
  break;
417
+ case "queueMode":
418
+ if (raw === "all" || raw === "one-at-a-time")
419
+ settings[key] = raw;
420
+ else
421
+ rejected.push(key);
422
+ break;
393
423
  case "retry":
394
424
  if (typeof raw === "number" && Number.isFinite(raw))
395
425
  settings[key] = normalizeRetryMaxAttempts(raw);
@@ -543,6 +573,7 @@ export function parseShareDoc(raw, lang = "en") {
543
573
  createdAt: clampText(doc["createdAt"], 40),
544
574
  appVersion: clampText(doc["appVersion"], 40),
545
575
  ...(rawEnabled ? { enabledTools: rawEnabled } : {}),
576
+ plugins: normalizePresetPlugins(doc["plugins"]),
546
577
  settings: sanitized.settings,
547
578
  },
548
579
  sanitized,
@@ -564,59 +595,36 @@ export function presetSummary(settings) {
564
595
  /* ------------------------------------------------------------------ */
565
596
  /** 带超时、大小上限、DNS 解析后 IP 校验与重定向逐跳校验的抓取(#602)。 */
566
597
  export async function fetchText(url, opts = {}) {
567
- const fetcher = opts.fetcher ?? defaultTextFetcher;
568
- const timeoutMs = opts.timeoutMs ?? FETCH_TIMEOUT_MS;
569
598
  const maxBytes = opts.maxBytes ?? PRESET_JSON_MAX_BYTES;
570
- const maxRedirects = opts.maxRedirects ?? 5;
571
- // 真实抓取或显式注入 lookup 时执行 DNS 解析后内网 IP 校验(防 DNS rebinding);
572
- // 纯内存 mock fetcher(未传 lookup)仅执行 URL 校验与重定向逐跳校验。
573
- const useDns = !!opts.lookup || (!opts.fetcher && isNativeGlobalFetch());
574
- let currentUrl = url;
575
- let res = null;
576
- for (let hop = 0; hop <= maxRedirects; hop++) {
577
- const check = useDns
578
- ? await resolveAndValidateUrl(currentUrl, { lookup: opts.lookup })
579
- : validateFetchUrl(currentUrl);
580
- if (!check.ok) {
599
+ const signal = AbortSignal.timeout(opts.timeoutMs ?? FETCH_TIMEOUT_MS);
600
+ let res;
601
+ try {
602
+ res = await safeFetch(url, { signal }, {
603
+ lookup: opts.lookup,
604
+ maxRedirects: opts.maxRedirects,
605
+ timeoutMs: opts.timeoutMs ?? FETCH_TIMEOUT_MS,
606
+ // Only explicit injection selects a mock transport; global fetch does not affect policy.
607
+ fetcher: opts.fetcher
608
+ ? (u, init) => opts.fetcher(u, init)
609
+ : undefined,
610
+ });
611
+ }
612
+ catch (error) {
613
+ if (error instanceof FetchUrlError) {
581
614
  return {
582
615
  ok: false,
583
- errorKey: check.reason === "scheme" ? "presets.url.scheme" : "presets.url.host",
584
- error: check.reason === "scheme"
585
- ? "Only http:// and https:// URLs are supported"
586
- : "Private, loopback, or internal addresses are blocked",
616
+ errorKey: error.reason === "scheme" ? "presets.url.scheme" : "presets.url.host",
617
+ error: error.message,
587
618
  };
588
619
  }
589
- currentUrl = check.url;
590
- res = await fetcher(currentUrl, { signal: AbortSignal.timeout(timeoutMs), redirect: "manual" });
591
- if (res.status === 301 || res.status === 302 || res.status === 303 || res.status === 307 || res.status === 308) {
592
- const location = res.headers?.get?.("location");
593
- if (!location)
594
- break;
595
- if (hop === maxRedirects) {
596
- return {
597
- ok: false,
598
- errorKey: "presets.fetch.status",
599
- error: `Too many redirects (> ${maxRedirects})`,
600
- };
601
- }
602
- try {
603
- currentUrl = new URL(location, currentUrl).toString();
604
- }
605
- catch {
606
- return {
607
- ok: false,
608
- errorKey: "presets.url.scheme",
609
- error: "Invalid redirect URL",
610
- };
611
- }
612
- continue;
620
+ if (error instanceof Error && error.message.startsWith("Too many redirects")) {
621
+ return { ok: false, errorKey: "presets.fetch.status", error: error.message };
613
622
  }
614
- break;
615
- }
616
- if (!res) {
617
- return { ok: false, errorKey: "presets.fetch.status", error: "Empty response" };
623
+ throw error;
618
624
  }
619
625
  if (!res.ok) {
626
+ if (res.body)
627
+ await res.body.getReader().cancel();
620
628
  return {
621
629
  ok: false,
622
630
  errorKey: "presets.fetch.status",
@@ -631,27 +639,33 @@ export async function fetchText(url, opts = {}) {
631
639
  const decoder = new TextDecoder();
632
640
  let received = 0;
633
641
  const chunks = [];
634
- for (;;) {
635
- const { done, value } = await reader.read();
636
- if (done)
637
- break;
638
- if (!value)
639
- continue;
640
- received += value.byteLength;
641
- if (received > maxBytes) {
642
- try {
643
- await reader.cancel();
644
- }
645
- catch {
646
- /* body already consumed/closed */
642
+ try {
643
+ for (;;) {
644
+ const { done, value } = await readBeforeAbort(reader.read(), signal);
645
+ if (done)
646
+ break;
647
+ if (!value)
648
+ continue;
649
+ received += value.byteLength;
650
+ if (received > maxBytes) {
651
+ try {
652
+ await reader.cancel();
653
+ }
654
+ catch {
655
+ /* body already consumed/closed */
656
+ }
657
+ return {
658
+ ok: false,
659
+ errorKey: "presets.fetch.tooLarge",
660
+ error: `Content too large (> ${Math.round(maxBytes / 1024)} KB)`,
661
+ };
647
662
  }
648
- return {
649
- ok: false,
650
- errorKey: "presets.fetch.tooLarge",
651
- error: `Content too large (> ${Math.round(maxBytes / 1024)} KB)`,
652
- };
663
+ chunks.push(value);
653
664
  }
654
- chunks.push(value);
665
+ }
666
+ finally {
667
+ void reader.cancel().catch(() => { });
668
+ reader.releaseLock?.();
655
669
  }
656
670
  const merged = new Uint8Array(received);
657
671
  let offset = 0;
@@ -661,7 +675,7 @@ export async function fetchText(url, opts = {}) {
661
675
  }
662
676
  return { ok: true, text: decoder.decode(merged) };
663
677
  }
664
- const text = await res.text();
678
+ const text = await readBeforeAbort(res.text(), signal);
665
679
  if (Buffer.byteLength(text, "utf8") > maxBytes) {
666
680
  return {
667
681
  ok: false,
@@ -949,6 +963,7 @@ function buildDocFromPort(port, opts) {
949
963
  const n = (opts.name ?? "").trim();
950
964
  let settings;
951
965
  let name;
966
+ let savedPlugins;
952
967
  if (current) {
953
968
  settings = port.currentSettings();
954
969
  name = n || pick(lang, "当前设置", "Current settings", "presets.share.currentName");
@@ -961,11 +976,13 @@ function buildDocFromPort(port, opts) {
961
976
  error: pick(lang, `预设不存在:${n}`, `Preset does not exist: ${n}`, "presets.share.missing", { name: n }),
962
977
  };
963
978
  }
964
- const { name: _drop, ...rest } = hit;
979
+ const { name: _drop, plugins, ...rest } = hit;
980
+ savedPlugins = plugins;
965
981
  settings = { ...rest };
966
982
  name = hit.name;
967
983
  }
968
- const doc = buildShareDoc(name, settings, {
984
+ const doc = buildShareDoc(name, sanitizePresetSettings(settings).settings, {
985
+ plugins: opts.plugins ?? savedPlugins,
969
986
  description: opts.description,
970
987
  author: opts.author,
971
988
  tags: opts.tags,
@@ -981,6 +998,7 @@ export function buildImportPreview(name, doc, sanitized, replaces) {
981
998
  description: doc.description,
982
999
  author: doc.author,
983
1000
  tags: doc.tags,
1001
+ plugins: normalizePresetPlugins(doc.plugins),
984
1002
  format: doc.format,
985
1003
  version: doc.version,
986
1004
  fields: sanitized.fields,
@@ -1000,7 +1018,7 @@ export function buildImportPreview(name, doc, sanitized, replaces) {
1000
1018
  /** preset_import / preset_import_url 的共同后段:预览 →(非 dryRun)落盘 →(可选)应用。 */
1001
1019
  async function applyImport(port, parsed, opts) {
1002
1020
  const lang = port.lang();
1003
- const name = (opts.name ?? "").trim() || parsed.doc.name;
1021
+ const name = normalizePresetName(opts.name) || parsed.doc.name;
1004
1022
  const replaces = port.presets().some((p) => p.name === name);
1005
1023
  const preview = buildImportPreview(name, parsed.doc, parsed.sanitized, replaces);
1006
1024
  if (opts.dryRun) {
@@ -1024,14 +1042,39 @@ async function applyImport(port, parsed, opts) {
1024
1042
  return;
1025
1043
  }
1026
1044
  const applied = Object.keys(settings).sort();
1027
- port.upsertPreset(toSettingsPreset(name, settings));
1045
+ const plugins = normalizePresetPlugins(parsed.doc.plugins);
1046
+ try {
1047
+ port.upsertPreset({ ...toSettingsPreset(name, settings), ...(plugins.length ? { plugins } : {}) });
1048
+ }
1049
+ catch (error) {
1050
+ port.emit({
1051
+ type: "preset_import_result",
1052
+ requestId: opts.requestId,
1053
+ ok: false,
1054
+ dryRun: false,
1055
+ error: error instanceof Error ? error.message : String(error),
1056
+ });
1057
+ return;
1058
+ }
1028
1059
  port.pushSettings();
1060
+ let applyError;
1061
+ if (opts.apply) {
1062
+ try {
1063
+ await port.applyPreset(name);
1064
+ }
1065
+ catch (error) {
1066
+ applyError = error instanceof Error ? error.message : String(error);
1067
+ }
1068
+ }
1029
1069
  port.emit({
1030
1070
  type: "preset_import_result",
1031
1071
  requestId: opts.requestId,
1032
1072
  ok: true,
1033
1073
  dryRun: false,
1034
1074
  preview: { ...preview, fields: applied },
1075
+ applied: opts.apply === true && !applyError && !port.isApplyPending?.(),
1076
+ ...(opts.apply && !applyError && port.isApplyPending?.() ? { applyDeferred: true } : {}),
1077
+ ...(applyError ? { applyError } : {}),
1035
1078
  });
1036
1079
  port.emit({
1037
1080
  type: "notice",
@@ -1039,8 +1082,6 @@ async function applyImport(port, parsed, opts) {
1039
1082
  text: replaces ? `预设已更新:${name}` : `预设已导入:${name}`,
1040
1083
  textEn: replaces ? `Preset updated: ${name}` : `Preset imported: ${name}`,
1041
1084
  });
1042
- if (opts.apply)
1043
- await port.applyPreset(name);
1044
1085
  }
1045
1086
  /** preset_export:把预设(或当前设置)导成可复制/可下载的 JSON 文本。 */
1046
1087
  export function exportPresetVia(port, msg) {
@@ -0,0 +1,106 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { writeJsonAtomicSync } from "./atomic-file.js";
4
+ export function parseStoredTemplate(value) {
5
+ if (!value || typeof value !== "object")
6
+ throw new Error("Invalid template");
7
+ const raw = value;
8
+ if (typeof raw.id !== "string" || !raw.id || raw.id.length > 200)
9
+ throw new Error("Invalid template id");
10
+ if (raw.hidden === true)
11
+ return { id: raw.id, hidden: true };
12
+ const result = { id: raw.id };
13
+ for (const key of ["icon", "title", "desc", "prompt", "command"]) {
14
+ if (raw[key] !== undefined) {
15
+ if (typeof raw[key] !== "string" || raw[key].length > (key === "prompt" ? 100_000 : 1000)) {
16
+ throw new Error(`Invalid template ${key}`);
17
+ }
18
+ result[key] = raw[key];
19
+ }
20
+ }
21
+ if (!result.title?.trim() || !result.prompt?.trim())
22
+ throw new Error("Title and prompt are required");
23
+ if (result.command) {
24
+ result.command = result.command.trim().replace(/^\//, "").toLowerCase();
25
+ if (!/^[a-z][a-z0-9_-]*$/.test(result.command))
26
+ throw new Error("Invalid template command");
27
+ }
28
+ return result;
29
+ }
30
+ /** Mutations read the latest file and commit atomically before returning new state. */
31
+ export function registerPromptTemplateRoutes(app, dataDir) {
32
+ const file = join(dataDir, "prompt-templates.json");
33
+ const load = () => {
34
+ try {
35
+ const data = JSON.parse(readFileSync(file, "utf8"));
36
+ if (!Array.isArray(data))
37
+ throw new Error("Invalid template file");
38
+ return data.map(parseStoredTemplate);
39
+ }
40
+ catch (error) {
41
+ if (error.code === "ENOENT")
42
+ return [];
43
+ throw error;
44
+ }
45
+ };
46
+ app.get("/api/prompt-templates", (_req, res) => {
47
+ try {
48
+ res.setHeader("Cache-Control", "no-store");
49
+ res.json({ templates: load() });
50
+ }
51
+ catch (error) {
52
+ res.status(500).json({ error: String(error) });
53
+ }
54
+ });
55
+ app.post("/api/prompt-templates", (req, res) => {
56
+ // Browser writes must be JSON, preventing cross-origin form submissions.
57
+ if (!req.is("application/json") || req.headers["sec-fetch-site"] === "cross-site") {
58
+ res.status(403).json({ error: "Cross-site template write rejected" });
59
+ return;
60
+ }
61
+ try {
62
+ const body = req.body ?? {};
63
+ let templates = load();
64
+ switch (body.action) {
65
+ case "upsert": {
66
+ const tpl = parseStoredTemplate(body.template);
67
+ if (tpl.command && templates.some((t) => t.id !== tpl.id && t.command === tpl.command)) {
68
+ throw new Error("Template command already exists");
69
+ }
70
+ templates = [...templates.filter((t) => t.id !== tpl.id), tpl];
71
+ break;
72
+ }
73
+ case "remove":
74
+ if (typeof body.id !== "string")
75
+ throw new Error("Invalid template id");
76
+ templates = templates.filter((t) => t.id !== body.id);
77
+ break;
78
+ case "reset":
79
+ templates = [];
80
+ break;
81
+ case "migrate": {
82
+ if (!Array.isArray(body.templates))
83
+ throw new Error("Invalid migration");
84
+ for (const value of body.templates) {
85
+ const tpl = parseStoredTemplate(value);
86
+ if (templates.some((t) => t.id === tpl.id))
87
+ continue;
88
+ if (tpl.command && templates.some((t) => t.command === tpl.command))
89
+ tpl.command = "";
90
+ templates.push(tpl);
91
+ }
92
+ break;
93
+ }
94
+ default:
95
+ throw new Error("Unknown template action");
96
+ }
97
+ if (templates.length > 500)
98
+ throw new Error("Too many templates");
99
+ writeJsonAtomicSync(file, templates);
100
+ res.json({ templates });
101
+ }
102
+ catch (error) {
103
+ res.status(400).json({ error: String(error) });
104
+ }
105
+ });
106
+ }
@@ -8,4 +8,4 @@
8
8
  * its own copy in web/src/protocol-version.ts; scripts/check-protocol-sync.mjs
9
9
  * verifies the two never drift.
10
10
  */
11
- export const PROTOCOL_VERSION = 37;
11
+ export const PROTOCOL_VERSION = 39;
@@ -0,0 +1,10 @@
1
+ /** Apply Web UI queue preferences without changing the user's pi CLI settings. */
2
+ export function applyQueueModesToSession(session, settings) {
3
+ const steeringMode = settings.steeringMode ?? "all";
4
+ const followUpMode = settings.followUpMode ?? "all";
5
+ session.settingsManager.applyOverrides({ steeringMode, followUpMode });
6
+ // The agent reads these fields when dequeuing; changing SettingsManager alone
7
+ // only takes effect after a reload. SDK setters also persist CLI settings.
8
+ session.agent.steeringMode = steeringMode;
9
+ session.agent.followUpMode = followUpMode;
10
+ }