pi-web-ui 0.113.0 → 0.114.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 (228) hide show
  1. package/CHANGELOG.md +69 -1
  2. package/README.md +117 -252
  3. package/README.zh-CN.md +145 -223
  4. package/README.zh-TW.md +145 -223
  5. package/bin/device-hub-cli.mjs +577 -0
  6. package/bin/pi-device-hub.mjs +9 -0
  7. package/bin/pi-web-ui.mjs +145 -20
  8. package/dist/gh-comment-781.md +5 -0
  9. package/dist/server/agent-service-daemon.js +102 -24
  10. package/dist/server/agent-service.js +2296 -1121
  11. package/dist/server/approval-rules.js +29 -3
  12. package/dist/server/ask-user-question-tool.js +8 -8
  13. package/dist/server/atomic-file.js +35 -14
  14. package/dist/server/attachment-store.js +71 -35
  15. package/dist/server/attachments.js +18 -8
  16. package/dist/server/canvas/canvas-agent-tool.js +65 -15
  17. package/dist/server/canvas/canvas-dispatch.js +61 -20
  18. package/dist/server/canvas/canvas-orchestrator.js +516 -199
  19. package/dist/server/canvas/canvas-scheduler.js +99 -0
  20. package/dist/server/canvas/canvas-store.js +107 -54
  21. package/dist/server/canvas/canvas-validation.js +131 -0
  22. package/dist/server/canvas/canvas-workspace.js +284 -0
  23. package/dist/server/client-id-utils.js +8 -0
  24. package/dist/server/client-state.js +104 -22
  25. package/dist/server/communicate-tool.js +76 -0
  26. package/dist/server/compact-context-tool.js +2 -3
  27. package/dist/server/compaction-instructions.js +75 -0
  28. package/dist/server/compaction-markers.js +7 -2
  29. package/dist/server/compaction-state.js +84 -0
  30. package/dist/server/composer-drafts.js +43 -40
  31. package/dist/server/context-evidence.js +346 -0
  32. package/dist/server/control-socket.js +6 -2
  33. package/dist/server/conversation-communication.js +368 -0
  34. package/dist/server/conversation-read-tool.js +3 -4
  35. package/dist/server/conversation-tool-names.js +14 -0
  36. package/dist/server/conversation-tool.js +57 -0
  37. package/dist/server/delegate-mode.js +17 -4
  38. package/dist/server/device-center/bot-catalog.js +88 -0
  39. package/dist/server/device-center/bot-execution.js +106 -0
  40. package/dist/server/device-center/bots.js +170 -0
  41. package/dist/server/device-center/collab-service.js +153 -0
  42. package/dist/server/device-center/collab-tool.js +184 -0
  43. package/dist/server/device-center/connector.js +332 -0
  44. package/dist/server/device-center/desktop-linux.js +372 -0
  45. package/dist/server/device-center/desktop-native.js +413 -0
  46. package/dist/server/device-center/desktop-page.js +232 -0
  47. package/dist/server/device-center/desktop-setup.js +30 -0
  48. package/dist/server/device-center/desktop.js +387 -0
  49. package/dist/server/device-center/device-portals.js +241 -0
  50. package/dist/server/device-center/execution-failure.js +70 -0
  51. package/dist/server/device-center/executor.js +371 -0
  52. package/dist/server/device-center/file-sync.js +493 -0
  53. package/dist/server/device-center/hub-auth.js +69 -0
  54. package/dist/server/device-center/hub-page.js +68 -0
  55. package/dist/server/device-center/hub-setup.js +214 -0
  56. package/dist/server/device-center/hub.js +829 -0
  57. package/dist/server/device-center/local-page.js +17 -0
  58. package/dist/server/device-center/local.js +476 -0
  59. package/dist/server/device-center/main.js +118 -0
  60. package/dist/server/device-center/native-desktop/macos.js +192 -0
  61. package/dist/server/device-center/native-desktop/windows.js +118 -0
  62. package/dist/server/device-center/path-portal.js +120 -0
  63. package/dist/server/device-center/relay.js +959 -0
  64. package/dist/server/device-center/runtime.js +253 -0
  65. package/dist/server/device-center/smoke-preview.js +3 -0
  66. package/dist/server/device-center/store.js +122 -0
  67. package/dist/server/device-center/task-error.js +14 -0
  68. package/dist/server/device-center/transfers.js +293 -0
  69. package/dist/server/device-center/workspaces.js +45 -0
  70. package/dist/server/dispatch-domain-handlers.js +83 -27
  71. package/dist/server/dsh/dsh-agent-service.js +277 -158
  72. package/dist/server/dsh/dsh-client.js +12 -2
  73. package/dist/server/durable/durable-agent-service.js +1 -1
  74. package/dist/server/evidence-tool-hooks.js +49 -0
  75. package/dist/server/file-save.js +95 -0
  76. package/dist/server/file-transfer-routes.js +97 -47
  77. package/dist/server/files-service.js +110 -34
  78. package/dist/server/goal-review-gate.js +16 -6
  79. package/dist/server/goal-service.js +54 -30
  80. package/dist/server/http-proxy.js +120 -0
  81. package/dist/server/index.js +236 -232
  82. package/dist/server/load-timing.js +31 -0
  83. package/dist/server/mcp-bridge.js +219 -94
  84. package/dist/server/mcp-hot-reload.js +31 -5
  85. package/dist/server/mcp-manager.js +192 -93
  86. package/dist/server/mcp-oauth-login.js +169 -0
  87. package/dist/server/mcp-oauth-ui.js +137 -0
  88. package/dist/server/mcp-oauth.js +395 -0
  89. package/dist/server/mcp-project-runtime.js +207 -0
  90. package/dist/server/message-window.js +74 -21
  91. package/dist/server/net-guard.js +122 -20
  92. package/dist/server/payload-limits.js +17 -0
  93. package/dist/server/pending-question.js +82 -0
  94. package/dist/server/plan-mode.js +338 -137
  95. package/dist/server/plugin-assets.js +8 -4
  96. package/dist/server/plugin-chat-attachments.js +48 -0
  97. package/dist/server/plugin-facilities.js +67 -220
  98. package/dist/server/plugin-installer.js +2 -1
  99. package/dist/server/plugin-removal.js +49 -0
  100. package/dist/server/plugin-secrets.js +179 -0
  101. package/dist/server/plugins.js +262 -92
  102. package/dist/server/preset-fields.js +49 -0
  103. package/dist/server/preset-plugin-dependencies.js +57 -0
  104. package/dist/server/preset-share.js +112 -72
  105. package/dist/server/protocol-version.js +1 -1
  106. package/dist/server/queue-modes.js +10 -0
  107. package/dist/server/remote-ssh-service.js +160 -67
  108. package/dist/server/request-context.js +164 -0
  109. package/dist/server/sandbox-data.js +655 -0
  110. package/dist/server/sandbox-engines.js +7 -0
  111. package/dist/server/sandbox-runtime-gate.js +41 -0
  112. package/dist/server/sandbox-service.js +139 -698
  113. package/dist/server/sandbox-tool.js +21 -4
  114. package/dist/server/scheduler-tasks.js +63 -48
  115. package/dist/server/serialize.js +48 -19
  116. package/dist/server/session-branch.js +25 -3
  117. package/dist/server/session-parser.js +28 -18
  118. package/dist/server/session-scan.js +130 -0
  119. package/dist/server/session-search.js +51 -37
  120. package/dist/server/settings-service.js +267 -111
  121. package/dist/server/setup-config.js +58 -0
  122. package/dist/server/skill-maintenance.js +112 -24
  123. package/dist/server/subagent-helpers.js +4 -1
  124. package/dist/server/subagent-notify.js +4 -1
  125. package/dist/server/subagent-security-gate.js +52 -11
  126. package/dist/server/subagent-task.js +27 -0
  127. package/dist/server/subagents.js +217 -46
  128. package/dist/server/tabs.js +9 -1
  129. package/dist/server/terminals.js +467 -363
  130. package/dist/server/tool-guards.js +42 -6
  131. package/dist/server/tool-manager.js +47 -20
  132. package/dist/server/tool-overrides.js +13 -11
  133. package/dist/server/tool-prompt-overrides.js +32 -2
  134. package/dist/server/tool-prompts.js +1 -1
  135. package/dist/server/turn-timing.js +11 -0
  136. package/dist/server/universal/session-store.js +48 -6
  137. package/dist/server/universal/universal-service.js +1 -1
  138. package/dist/server/universal/universal-session.js +334 -231
  139. package/dist/server/uploads.js +64 -5
  140. package/dist/server/webui-context.js +6 -6
  141. package/dist/server/worktree-service.js +32 -24
  142. package/dist/server/ws-pending-queue.js +73 -27
  143. package/dist/test-artifact.md +9 -0
  144. package/dist/test-preview-modal.md +11 -0
  145. package/dist/test-report.html +20 -0
  146. package/docs/device-center.md +142 -0
  147. package/docs/device-desktop.md +48 -0
  148. package/package.json +4 -1
  149. package/plugin-sdk/index.d.ts +45 -9
  150. package/plugin-sdk/ssh-host-trust.mjs +225 -0
  151. package/plugins/catalog.json +1 -1
  152. package/themes/aetheris.css +1 -107
  153. package/themes/ayu-light.css +5 -29
  154. package/themes/bases/flow-base.css +0 -6
  155. package/themes/bases/statusbar-flat-base.css +112 -0
  156. package/themes/bases/zhujian-base.css +1 -0
  157. package/themes/bases/zhupi-base.css +1 -0
  158. package/themes/catppuccin-latte.css +4 -27
  159. package/themes/catppuccin.css +4 -35
  160. package/themes/claude-code-dark.css +1 -0
  161. package/themes/codex.css +4 -28
  162. package/themes/cyberpunk.css +3 -61
  163. package/themes/dark-teal.css +0 -1
  164. package/themes/dazzle.css +3 -73
  165. package/themes/everforest-light.css +4 -27
  166. package/themes/geist.css +4 -28
  167. package/themes/gruvbox-light.css +4 -27
  168. package/themes/kanagawa-lotus.css +4 -27
  169. package/themes/md-preview.css +3 -213
  170. package/themes/mist.css +4 -24
  171. package/themes/nord.css +4 -35
  172. package/themes/one-dark.css +4 -37
  173. package/themes/paper.css +4 -16
  174. package/themes/rose-pine-dawn.css +4 -28
  175. package/themes/sakura.css +4 -24
  176. package/themes/solarized-light.css +4 -27
  177. package/themes/tokyo-night.css +3 -34
  178. package/themes/white.css +4 -26
  179. package/themes/zhujian-dark.css +1 -0
  180. package/themes/zhupi-dark.css +1 -0
  181. package/web/dist/.build-assets.json +1 -0
  182. package/web/dist/assets/BgTasksModal-CS7UNzcw.js +1 -0
  183. package/web/dist/assets/BgTasksModal-Dk-tp78W.js +1 -0
  184. package/web/dist/assets/CanvasStudio-BEJZE5BI.js +1579 -0
  185. package/web/dist/assets/CanvasStudio-CgUNHqos.js +1579 -0
  186. package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +3 -0
  187. package/web/dist/assets/DeviceCenter-CVblvhNX.js +3 -0
  188. package/web/dist/assets/Dropdown-Oug0DDte.js +1 -0
  189. package/web/dist/assets/FilePreview-CvdX6nr6.js +2 -0
  190. package/web/dist/assets/FilePreview-kCZhfBAF.js +2 -0
  191. package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +1 -0
  192. package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +1 -0
  193. package/web/dist/assets/GroupConversation-Cgo4xbpa.js +1 -0
  194. package/web/dist/assets/GroupConversation-DZ71jEi8.js +1 -0
  195. package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +2 -0
  196. package/web/dist/assets/PiSetupModal-mkWPSxMj.js +1 -0
  197. package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +1 -0
  198. package/web/dist/assets/SCMPanel-BP1TUT-V.js +2 -0
  199. package/web/dist/assets/SCMPanel-BscPm9kf.js +2 -0
  200. package/web/dist/assets/SettingsModal-C8UgMjVM.js +20 -0
  201. package/web/dist/assets/SettingsModal-VynB7jNb.js +20 -0
  202. package/web/dist/assets/TerminalPanel-D6cPRFei.js +3 -0
  203. package/web/dist/assets/TerminalPanel-DL20uKgU.js +3 -0
  204. package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +1 -0
  205. package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +1 -0
  206. package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +1 -0
  207. package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +1 -0
  208. package/web/dist/assets/app-globals-CnO6KlEM.js +325 -0
  209. package/web/dist/assets/desktop-DPyTy4M3.js +1 -0
  210. package/web/dist/assets/es-DWMIuDU2.js +2 -0
  211. package/web/dist/assets/index-CPgAH5q7.js +83 -0
  212. package/web/dist/assets/index-Cje8iugL.js +83 -0
  213. package/web/dist/assets/index-DnKeiDbj.css +1 -0
  214. package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
  215. package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
  216. package/web/dist/assets/math-1uRJCsA9.js +257 -0
  217. package/web/dist/assets/math-BorAY7qD.css +1 -0
  218. package/web/dist/assets/plugin-host-CqA4yW6w.js +1 -0
  219. package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
  220. package/web/dist/assets/theme-BqdAjEjF.js +1 -0
  221. package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
  222. package/web/dist/index.html +15 -9
  223. package/web/dist/sw.js +1 -1
  224. package/web/dist/assets/TerminalPanel-3wojLfLk.js +0 -3
  225. package/web/dist/assets/index-A8YXwnpZ.js +0 -2008
  226. package/web/dist/assets/index-BwL7qBh6.css +0 -1
  227. package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
  228. package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
@@ -46,6 +46,8 @@ export const PRESET_FIELD_GROUPS = {
46
46
  "toolApprovalEnabled",
47
47
  "toolWatchdogTimeoutMs",
48
48
  "questionnaireEnabled",
49
+ "questionPresentation",
50
+ "questionTimeoutSeconds",
49
51
  "editSoftEnabled",
50
52
  "terminalToolsEnabled",
51
53
  ],
@@ -62,6 +64,8 @@ export const PRESET_FIELD_GROUPS = {
62
64
  ],
63
65
  // 模型侧行为与各专用提示词
64
66
  ai: [
67
+ "steeringMode",
68
+ "followUpMode",
65
69
  "retryMaxAttempts",
66
70
  "softCapTokens",
67
71
  "softCapByModel",
@@ -91,6 +95,9 @@ export const PRESET_FIELD_GROUPS = {
91
95
  "showForkedParentSessions",
92
96
  "retainFinishedConversations",
93
97
  "openRecentSessionOnProjectSwitch",
98
+ "chatUploadMaxMb",
99
+ "workspaceUploadMaxMb",
100
+ "folderUploadMaxMb",
94
101
  "bgAutoCleanupMin",
95
102
  "quickPhrases",
96
103
  "quickPhrasesEnabled",
@@ -231,6 +238,24 @@ export const PRESET_FIELD_META = {
231
238
  hintZh: "执行危险或写操作工具前弹出用户确认确认框",
232
239
  hintEn: "Require user approval before executing tools",
233
240
  },
241
+ chatUploadMaxMb: {
242
+ labelZh: "聊天附件大小上限",
243
+ labelEn: "Chat attachment size limit",
244
+ hintZh: "单个文件大小,单位 MB(1–100)",
245
+ hintEn: "Per-file limit in MB (1–100)",
246
+ },
247
+ workspaceUploadMaxMb: {
248
+ labelZh: "文件面板上传大小上限",
249
+ labelEn: "File panel upload size limit",
250
+ hintZh: "单个文件大小,单位 MB(1–100)",
251
+ hintEn: "Per-file limit in MB (1–100)",
252
+ },
253
+ folderUploadMaxMb: {
254
+ labelZh: "文件夹上传大小上限",
255
+ labelEn: "Folder upload size limit",
256
+ hintZh: "每个文件的大小,单位 MB(1–100)",
257
+ hintEn: "Per-file limit in MB (1–100)",
258
+ },
234
259
  bgAutoCleanupMin: {
235
260
  labelZh: "后台任务自动清理",
236
261
  labelEn: "Background Task Auto-cleanup",
@@ -249,6 +274,18 @@ export const PRESET_FIELD_META = {
249
274
  hintZh: "允许 AI 遇到歧义时弹窗向用户多选/单选确认",
250
275
  hintEn: "Allow agent to ask interactive multiple-choice questions",
251
276
  },
277
+ questionPresentation: {
278
+ labelZh: "问卷提醒方式",
279
+ labelEn: "Questionnaire reminders",
280
+ hintZh: "当前对话弹出、全部弹出或仅队列",
281
+ hintEn: "Current conversation, all popups, or manual queue",
282
+ },
283
+ questionTimeoutSeconds: {
284
+ labelZh: "子代理问卷等待期限",
285
+ labelEn: "Subagent question timeout",
286
+ hintZh: "秒;0 为持续等待,超时不自动选择答案",
287
+ hintEn: "Seconds; 0 waits indefinitely, timeout never selects an answer",
288
+ },
252
289
  editSoftEnabled: {
253
290
  labelZh: "宽松缩进编辑 (edit_soft)",
254
291
  labelEn: "Soft Indentation Edit",
@@ -318,6 +355,18 @@ export const PRESET_FIELD_META = {
318
355
  hintEn: "Total catalog character limit (default 20000), falls back to compact name index when exceeded",
319
356
  },
320
357
  // ai
358
+ steeringMode: {
359
+ labelZh: "插话队列模式",
360
+ labelEn: "Steering Queue Mode",
361
+ hintZh: "一次处理全部插话或每次一条",
362
+ hintEn: "Process all queued steering messages or one at a time",
363
+ },
364
+ followUpMode: {
365
+ labelZh: "追问队列模式",
366
+ labelEn: "Follow-Up Queue Mode",
367
+ hintZh: "一次处理全部追问或每次一条",
368
+ hintEn: "Process all queued follow-up messages or one at a time",
369
+ },
321
370
  retryMaxAttempts: {
322
371
  labelZh: "网络重试上限",
323
372
  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,15 @@ 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
+ questionTimeoutSeconds: "questionTimeout",
243
252
  editSoftEnabled: "bool",
244
253
  terminalToolsEnabled: "bool",
245
254
  // -- terminal --------------------------------------------------------
@@ -254,6 +263,8 @@ const PRESET_FIELD_KINDS = {
254
263
  skillsCatalogShowLocation: "bool",
255
264
  skillsCatalogBudget: "number",
256
265
  // -- ai --------------------------------------------------------------
266
+ steeringMode: "queueMode",
267
+ followUpMode: "queueMode",
257
268
  retryMaxAttempts: "retry",
258
269
  softCapTokens: "softCap",
259
270
  softCapByModel: "softCapByModel",
@@ -378,6 +389,18 @@ export function sanitizePresetSettings(input, opts) {
378
389
  else
379
390
  rejected.push(key);
380
391
  break;
392
+ case "questionPresentation":
393
+ if (raw === "queue" || raw === "all" || raw === "manual")
394
+ settings[key] = raw;
395
+ else
396
+ rejected.push(key);
397
+ break;
398
+ case "questionTimeout":
399
+ if (typeof raw === "number" && Number.isSafeInteger(raw) && raw >= 0 && raw <= 86400)
400
+ settings[key] = raw;
401
+ else
402
+ rejected.push(key);
403
+ break;
381
404
  case "codemodeMode":
382
405
  if (raw === "on" || raw === "only")
383
406
  settings[key] = raw;
@@ -390,6 +413,12 @@ export function sanitizePresetSettings(input, opts) {
390
413
  else
391
414
  rejected.push(key);
392
415
  break;
416
+ case "queueMode":
417
+ if (raw === "all" || raw === "one-at-a-time")
418
+ settings[key] = raw;
419
+ else
420
+ rejected.push(key);
421
+ break;
393
422
  case "retry":
394
423
  if (typeof raw === "number" && Number.isFinite(raw))
395
424
  settings[key] = normalizeRetryMaxAttempts(raw);
@@ -543,6 +572,7 @@ export function parseShareDoc(raw, lang = "en") {
543
572
  createdAt: clampText(doc["createdAt"], 40),
544
573
  appVersion: clampText(doc["appVersion"], 40),
545
574
  ...(rawEnabled ? { enabledTools: rawEnabled } : {}),
575
+ plugins: normalizePresetPlugins(doc["plugins"]),
546
576
  settings: sanitized.settings,
547
577
  },
548
578
  sanitized,
@@ -564,59 +594,36 @@ export function presetSummary(settings) {
564
594
  /* ------------------------------------------------------------------ */
565
595
  /** 带超时、大小上限、DNS 解析后 IP 校验与重定向逐跳校验的抓取(#602)。 */
566
596
  export async function fetchText(url, opts = {}) {
567
- const fetcher = opts.fetcher ?? defaultTextFetcher;
568
- const timeoutMs = opts.timeoutMs ?? FETCH_TIMEOUT_MS;
569
597
  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) {
598
+ const signal = AbortSignal.timeout(opts.timeoutMs ?? FETCH_TIMEOUT_MS);
599
+ let res;
600
+ try {
601
+ res = await safeFetch(url, { signal }, {
602
+ lookup: opts.lookup,
603
+ maxRedirects: opts.maxRedirects,
604
+ timeoutMs: opts.timeoutMs ?? FETCH_TIMEOUT_MS,
605
+ // Only explicit injection selects a mock transport; global fetch does not affect policy.
606
+ fetcher: opts.fetcher
607
+ ? (u, init) => opts.fetcher(u, init)
608
+ : undefined,
609
+ });
610
+ }
611
+ catch (error) {
612
+ if (error instanceof FetchUrlError) {
581
613
  return {
582
614
  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",
615
+ errorKey: error.reason === "scheme" ? "presets.url.scheme" : "presets.url.host",
616
+ error: error.message,
587
617
  };
588
618
  }
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;
619
+ if (error instanceof Error && error.message.startsWith("Too many redirects")) {
620
+ return { ok: false, errorKey: "presets.fetch.status", error: error.message };
613
621
  }
614
- break;
615
- }
616
- if (!res) {
617
- return { ok: false, errorKey: "presets.fetch.status", error: "Empty response" };
622
+ throw error;
618
623
  }
619
624
  if (!res.ok) {
625
+ if (res.body)
626
+ await res.body.getReader().cancel();
620
627
  return {
621
628
  ok: false,
622
629
  errorKey: "presets.fetch.status",
@@ -631,27 +638,33 @@ export async function fetchText(url, opts = {}) {
631
638
  const decoder = new TextDecoder();
632
639
  let received = 0;
633
640
  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 */
641
+ try {
642
+ for (;;) {
643
+ const { done, value } = await readBeforeAbort(reader.read(), signal);
644
+ if (done)
645
+ break;
646
+ if (!value)
647
+ continue;
648
+ received += value.byteLength;
649
+ if (received > maxBytes) {
650
+ try {
651
+ await reader.cancel();
652
+ }
653
+ catch {
654
+ /* body already consumed/closed */
655
+ }
656
+ return {
657
+ ok: false,
658
+ errorKey: "presets.fetch.tooLarge",
659
+ error: `Content too large (> ${Math.round(maxBytes / 1024)} KB)`,
660
+ };
647
661
  }
648
- return {
649
- ok: false,
650
- errorKey: "presets.fetch.tooLarge",
651
- error: `Content too large (> ${Math.round(maxBytes / 1024)} KB)`,
652
- };
662
+ chunks.push(value);
653
663
  }
654
- chunks.push(value);
664
+ }
665
+ finally {
666
+ void reader.cancel().catch(() => { });
667
+ reader.releaseLock?.();
655
668
  }
656
669
  const merged = new Uint8Array(received);
657
670
  let offset = 0;
@@ -661,7 +674,7 @@ export async function fetchText(url, opts = {}) {
661
674
  }
662
675
  return { ok: true, text: decoder.decode(merged) };
663
676
  }
664
- const text = await res.text();
677
+ const text = await readBeforeAbort(res.text(), signal);
665
678
  if (Buffer.byteLength(text, "utf8") > maxBytes) {
666
679
  return {
667
680
  ok: false,
@@ -949,6 +962,7 @@ function buildDocFromPort(port, opts) {
949
962
  const n = (opts.name ?? "").trim();
950
963
  let settings;
951
964
  let name;
965
+ let savedPlugins;
952
966
  if (current) {
953
967
  settings = port.currentSettings();
954
968
  name = n || pick(lang, "当前设置", "Current settings", "presets.share.currentName");
@@ -961,11 +975,13 @@ function buildDocFromPort(port, opts) {
961
975
  error: pick(lang, `预设不存在:${n}`, `Preset does not exist: ${n}`, "presets.share.missing", { name: n }),
962
976
  };
963
977
  }
964
- const { name: _drop, ...rest } = hit;
978
+ const { name: _drop, plugins, ...rest } = hit;
979
+ savedPlugins = plugins;
965
980
  settings = { ...rest };
966
981
  name = hit.name;
967
982
  }
968
- const doc = buildShareDoc(name, settings, {
983
+ const doc = buildShareDoc(name, sanitizePresetSettings(settings).settings, {
984
+ plugins: opts.plugins ?? savedPlugins,
969
985
  description: opts.description,
970
986
  author: opts.author,
971
987
  tags: opts.tags,
@@ -981,6 +997,7 @@ export function buildImportPreview(name, doc, sanitized, replaces) {
981
997
  description: doc.description,
982
998
  author: doc.author,
983
999
  tags: doc.tags,
1000
+ plugins: normalizePresetPlugins(doc.plugins),
984
1001
  format: doc.format,
985
1002
  version: doc.version,
986
1003
  fields: sanitized.fields,
@@ -1000,7 +1017,7 @@ export function buildImportPreview(name, doc, sanitized, replaces) {
1000
1017
  /** preset_import / preset_import_url 的共同后段:预览 →(非 dryRun)落盘 →(可选)应用。 */
1001
1018
  async function applyImport(port, parsed, opts) {
1002
1019
  const lang = port.lang();
1003
- const name = (opts.name ?? "").trim() || parsed.doc.name;
1020
+ const name = normalizePresetName(opts.name) || parsed.doc.name;
1004
1021
  const replaces = port.presets().some((p) => p.name === name);
1005
1022
  const preview = buildImportPreview(name, parsed.doc, parsed.sanitized, replaces);
1006
1023
  if (opts.dryRun) {
@@ -1024,14 +1041,39 @@ async function applyImport(port, parsed, opts) {
1024
1041
  return;
1025
1042
  }
1026
1043
  const applied = Object.keys(settings).sort();
1027
- port.upsertPreset(toSettingsPreset(name, settings));
1044
+ const plugins = normalizePresetPlugins(parsed.doc.plugins);
1045
+ try {
1046
+ port.upsertPreset({ ...toSettingsPreset(name, settings), ...(plugins.length ? { plugins } : {}) });
1047
+ }
1048
+ catch (error) {
1049
+ port.emit({
1050
+ type: "preset_import_result",
1051
+ requestId: opts.requestId,
1052
+ ok: false,
1053
+ dryRun: false,
1054
+ error: error instanceof Error ? error.message : String(error),
1055
+ });
1056
+ return;
1057
+ }
1028
1058
  port.pushSettings();
1059
+ let applyError;
1060
+ if (opts.apply) {
1061
+ try {
1062
+ await port.applyPreset(name);
1063
+ }
1064
+ catch (error) {
1065
+ applyError = error instanceof Error ? error.message : String(error);
1066
+ }
1067
+ }
1029
1068
  port.emit({
1030
1069
  type: "preset_import_result",
1031
1070
  requestId: opts.requestId,
1032
1071
  ok: true,
1033
1072
  dryRun: false,
1034
1073
  preview: { ...preview, fields: applied },
1074
+ applied: opts.apply === true && !applyError && !port.isApplyPending?.(),
1075
+ ...(opts.apply && !applyError && port.isApplyPending?.() ? { applyDeferred: true } : {}),
1076
+ ...(applyError ? { applyError } : {}),
1035
1077
  });
1036
1078
  port.emit({
1037
1079
  type: "notice",
@@ -1039,8 +1081,6 @@ async function applyImport(port, parsed, opts) {
1039
1081
  text: replaces ? `预设已更新:${name}` : `预设已导入:${name}`,
1040
1082
  textEn: replaces ? `Preset updated: ${name}` : `Preset imported: ${name}`,
1041
1083
  });
1042
- if (opts.apply)
1043
- await port.applyPreset(name);
1044
1084
  }
1045
1085
  /** preset_export:把预设(或当前设置)导成可复制/可下载的 JSON 文本。 */
1046
1086
  export function exportPresetVia(port, msg) {
@@ -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 = 38;
@@ -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
+ }