pi-web-ui 0.115.0 → 0.117.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 (161) hide show
  1. package/CHANGELOG.md +65 -2
  2. package/bin/device-hub-cli.mjs +26 -3
  3. package/bin/pi-web-ui.mjs +159 -71
  4. package/dist/server/agent-service-daemon.js +136 -8
  5. package/dist/server/agent-service.js +594 -159
  6. package/dist/server/canvas/canvas-workspace.js +18 -86
  7. package/dist/server/client-state.js +52 -8
  8. package/dist/server/compaction-markers.js +43 -24
  9. package/dist/server/dangling-tools.js +172 -16
  10. package/dist/server/device-center/bot-execution.js +77 -2
  11. package/dist/server/device-center/collab-service.js +61 -12
  12. package/dist/server/device-center/collab-tool.js +482 -21
  13. package/dist/server/device-center/connector.js +107 -37
  14. package/dist/server/device-center/delivery-authority.js +98 -0
  15. package/dist/server/device-center/delivery-subject.js +30 -0
  16. package/dist/server/device-center/device-integration.js +453 -183
  17. package/dist/server/device-center/execution-guides.js +17 -7
  18. package/dist/server/device-center/execution-instructions.js +2 -1
  19. package/dist/server/device-center/execution-settings.js +138 -25
  20. package/dist/server/device-center/executor.js +51 -6
  21. package/dist/server/device-center/file-sync.js +14 -13
  22. package/dist/server/device-center/group-context-message.js +3 -1
  23. package/dist/server/device-center/group-context.js +73 -3
  24. package/dist/server/device-center/hub-conversations.js +71 -6
  25. package/dist/server/device-center/hub-deliveries.js +120 -15
  26. package/dist/server/device-center/hub-integration.js +655 -334
  27. package/dist/server/device-center/hub-locks.js +320 -0
  28. package/dist/server/device-center/hub-page.js +16 -35
  29. package/dist/server/device-center/hub-setup.js +23 -1
  30. package/dist/server/device-center/hub-transaction-log.js +197 -0
  31. package/dist/server/device-center/hub-webhooks.js +165 -0
  32. package/dist/server/device-center/hub.js +1531 -305
  33. package/dist/server/device-center/integration-verification.js +113 -0
  34. package/dist/server/device-center/local-hub.js +8 -3
  35. package/dist/server/device-center/local-publication.js +423 -0
  36. package/dist/server/device-center/local-verification-job.js +97 -0
  37. package/dist/server/device-center/local-verification.js +274 -0
  38. package/dist/server/device-center/local.js +181 -13
  39. package/dist/server/device-center/main.js +4 -1
  40. package/dist/server/device-center/partition-log.js +330 -0
  41. package/dist/server/device-center/publication-journal.js +312 -0
  42. package/dist/server/device-center/publish-intent.js +379 -0
  43. package/dist/server/device-center/relay.js +134 -24
  44. package/dist/server/device-center/runtime.js +475 -42
  45. package/dist/server/device-center/store.js +366 -89
  46. package/dist/server/device-center/task-outcome.js +81 -0
  47. package/dist/server/device-center/task-recovery.js +603 -178
  48. package/dist/server/device-center/task-scheduler.js +48 -3
  49. package/dist/server/device-center/task-settlement.js +353 -0
  50. package/dist/server/device-center/task-workspace.js +443 -0
  51. package/dist/server/device-center/transfers.js +41 -15
  52. package/dist/server/device-center/verification-limits.js +10 -0
  53. package/dist/server/device-center/work-contract.js +995 -0
  54. package/dist/server/dispatch-domain-handlers.js +29 -3
  55. package/dist/server/dsh/dsh-agent-service.js +9 -2
  56. package/dist/server/engine-probe.js +112 -1
  57. package/dist/server/global-loader.js +119 -19
  58. package/dist/server/index.js +159 -17
  59. package/dist/server/managed.js +2 -0
  60. package/dist/server/model-admin.js +48 -6
  61. package/dist/server/model-enrich.js +10 -1
  62. package/dist/server/patch-node-pty.js +3 -2
  63. package/dist/server/patch-remote-catalog.js +3 -2
  64. package/dist/server/plugins.js +64 -7
  65. package/dist/server/preset-fields.js +17 -1
  66. package/dist/server/preset-share.js +1 -0
  67. package/dist/server/prompt-composer.js +39 -0
  68. package/dist/server/protocol-version.js +1 -1
  69. package/dist/server/quick-ask-settings.js +28 -0
  70. package/dist/server/quick-ask.js +164 -0
  71. package/dist/server/reasoning-registry.js +207 -0
  72. package/dist/server/resolve-global-sdk.js +61 -11
  73. package/dist/server/scheduler-tasks.js +35 -8
  74. package/dist/server/session-list-scan.js +223 -0
  75. package/dist/server/session-open.js +93 -0
  76. package/dist/server/session-parser.js +4 -0
  77. package/dist/server/session-scan.js +90 -38
  78. package/dist/server/settings-service.js +9 -1
  79. package/dist/server/soft-cap.js +5 -0
  80. package/dist/server/startup-banner.js +35 -0
  81. package/dist/server/subagents.js +2 -1
  82. package/dist/server/tool-manager.js +17 -9
  83. package/dist/server/transcript-prepare.js +73 -0
  84. package/dist/server/unauthorized-page.js +319 -0
  85. package/dist/server/universal/drivers/claude-code.js +98 -34
  86. package/dist/server/universal/universal-session.js +4 -0
  87. package/dist/server/workspace-handle.js +428 -0
  88. package/docs/architecture-plugins.md +959 -0
  89. package/docs/device-center.md +34 -20
  90. package/package.json +4 -4
  91. package/plugin-sdk/README.md +16 -8
  92. package/plugin-sdk/client.d.ts +27 -0
  93. package/plugin-sdk/client.mjs +82 -0
  94. package/plugin-sdk/index.d.ts +10 -0
  95. package/plugin-sdk/index.mjs +4 -683
  96. package/plugin-sdk/package.json +15 -4
  97. package/plugin-sdk/testing.d.ts +10 -0
  98. package/plugin-sdk/testing.mjs +566 -0
  99. package/themes/flow-cristallo.css +168 -0
  100. package/themes/flow-ink.css +169 -0
  101. package/themes/flow-obsidian.css +169 -0
  102. package/themes/flow-zurich.css +169 -0
  103. package/web/dist/.build-assets.json +1 -1
  104. package/web/dist/assets/{BgTasksModal-BYzPgmoq.js → BgTasksModal-BjNRIUIc.js} +1 -1
  105. package/web/dist/assets/{BgTasksModal-ni0VTmAQ.js → BgTasksModal-C0zuU8FE.js} +1 -1
  106. package/web/dist/assets/{CanvasStudio-DNmDNBod.js → CanvasStudio-BWvdmJ0M.js} +3 -3
  107. package/web/dist/assets/{CanvasStudio-BCUeEf25.js → CanvasStudio-VQFjmTGq.js} +3 -3
  108. package/web/dist/assets/DeviceCenter-DI9_0aBB.js +3 -0
  109. package/web/dist/assets/DeviceCenter-DsNtXqzY.js +3 -0
  110. package/web/dist/assets/DeviceExecutionSettings-BLP1Su5G.js +1 -0
  111. package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +1 -0
  112. package/web/dist/assets/DeviceGroups-CP7CcyPD.js +1 -0
  113. package/web/dist/assets/{Dropdown-CGXD0DfT.js → Dropdown-CQtstPGv.js} +1 -1
  114. package/web/dist/assets/FilePreview-BMB2tNyT.js +2 -0
  115. package/web/dist/assets/FilePreview-RGFQUbJo.js +2 -0
  116. package/web/dist/assets/{GlobalSearchModal-mevF-ySi.js → GlobalSearchModal-BM5wxiqU.js} +1 -1
  117. package/web/dist/assets/{GlobalSearchModal-qL99FN_F.js → GlobalSearchModal-DGv_WINq.js} +1 -1
  118. package/web/dist/assets/GroupConversation-B7SnuXj1.js +61 -0
  119. package/web/dist/assets/GroupConversation-Dda69q-2.js +61 -0
  120. package/web/dist/assets/{HintTip-LHwkS2jV.js → HintTip-ChTW8o1m.js} +1 -1
  121. package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +2 -0
  122. package/web/dist/assets/ModelConfigModal-yqeadyab.js +2 -0
  123. package/web/dist/assets/{PiSetupModal-DE5-gEtI.js → PiSetupModal-BX5rUuoI.js} +1 -1
  124. package/web/dist/assets/{ProviderOAuthControls-6UMARucA.js → ProviderOAuthControls-DY4SCfXg.js} +1 -1
  125. package/web/dist/assets/SCMPanel-C4KbQvvK.js +2 -0
  126. package/web/dist/assets/SCMPanel-DPAyY2sW.js +2 -0
  127. package/web/dist/assets/SettingsModal-DxZp6D_g.js +32 -0
  128. package/web/dist/assets/SettingsModal-WhQzaOPt.js +32 -0
  129. package/web/dist/assets/{TerminalPanel-CTp_BZ4S.js → TerminalPanel-D4By_RVc.js} +2 -2
  130. package/web/dist/assets/{TerminalPanel-CkYxC-Gh.js → TerminalPanel-lZw8-i3j.js} +2 -2
  131. package/web/dist/assets/{TuiOverlayModal-1cRLP8IF.js → TuiOverlayModal-C3pAVuC8.js} +1 -1
  132. package/web/dist/assets/{TuiOverlayModal-2xlptqWX.js → TuiOverlayModal-D7_rEXcJ.js} +1 -1
  133. package/web/dist/assets/app-globals-KqOVtmp1.js +123 -0
  134. package/web/dist/assets/{canvas-client-Bye9nSFO.js → canvas-client-BY6ojmle.js} +1 -1
  135. package/web/dist/assets/{desktop-kjBoE3Nu.js → desktop-CV6KKp9R.js} +1 -1
  136. package/web/dist/assets/index-BawF7ZP5.js +397 -0
  137. package/web/dist/assets/index-BoGCoq5X.js +397 -0
  138. package/web/dist/assets/index-CVW9FoY2.css +1 -0
  139. package/web/dist/assets/{plugin-host-C8mNgghx.js → plugin-host-Dn8Dd6SC.js} +1 -1
  140. package/web/dist/assets/{remote-ssh-client-CeP3CLUW.js → remote-ssh-client-Dzi-eEyE.js} +1 -1
  141. package/web/dist/assets/{theme-BXGpyTMh.js → theme-D_bihpdN.js} +1 -1
  142. package/web/dist/index.html +11 -11
  143. package/web/dist/sw.js +1 -1
  144. package/dist/server/patch-turn-end-boundary.js +0 -77
  145. package/web/dist/assets/DeviceCenter-BcBhRgL6.js +0 -3
  146. package/web/dist/assets/DeviceCenter-CmL5FZmt.js +0 -3
  147. package/web/dist/assets/DeviceGroups-CLdpdnI7.js +0 -1
  148. package/web/dist/assets/DeviceGroups-CgBaDPrD.js +0 -1
  149. package/web/dist/assets/FilePreview-B8iqnBjy.js +0 -2
  150. package/web/dist/assets/FilePreview-BqviZKCN.js +0 -2
  151. package/web/dist/assets/GroupConversation-B88Yy-lt.js +0 -3
  152. package/web/dist/assets/GroupConversation-BwP5NVOE.js +0 -3
  153. package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +0 -2
  154. package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +0 -2
  155. package/web/dist/assets/SCMPanel-ezY_ZtCu.js +0 -2
  156. package/web/dist/assets/SettingsModal-6HgeEsJ8.js +0 -20
  157. package/web/dist/assets/SettingsModal-CF-7MwqS.js +0 -20
  158. package/web/dist/assets/app-globals-DZNa9v8u.js +0 -325
  159. package/web/dist/assets/index-CsFs_HMb.css +0 -1
  160. package/web/dist/assets/index-DHeeHS_l.js +0 -85
  161. package/web/dist/assets/index-DTZch8uz.js +0 -85
@@ -20,9 +20,9 @@ import { botExecutionMessageAllowed } from "./device-center/bot-execution.js";
20
20
  import { ALL_AGENT_TOOL_ENTRIES, effectiveDisabledAgentTools, isToolSupportedOnPlatform } from "./tool-manager.js";
21
21
  // MUST be imported before the SDK is loaded so on-disk patches apply cleanly.
22
22
  import "./patch-remote-catalog.js";
23
- import "./patch-turn-end-boundary.js";
24
23
  import { existsSync, mkdirSync, readFileSync, readdirSync, statSync } from "node:fs";
25
24
  import { registerPromptTemplateRoutes } from "./prompt-templates.js";
25
+ import { createQuickAskRuntime, registerQuickAskRoutes } from "./quick-ask.js";
26
26
  import { readFile, stat } from "node:fs/promises";
27
27
  import { createServer } from "node:http";
28
28
  import { proxyHttp } from "./http-proxy.js";
@@ -74,6 +74,8 @@ import { globalLspPool } from "./lsp-tool.js";
74
74
  import { buildPiWebTokenCookie, decodeCookieToken, isTlsRequest } from "./auth-cookie.js";
75
75
  import { isLoopbackAddress, loadServerFileConfig, saveServerFileConfig, tokenWarning } from "./server-config.js";
76
76
  import { renderSetupHtml } from "./setup-page.js";
77
+ import { renderUnauthorizedHtml } from "./unauthorized-page.js";
78
+ import { formatStartupBannerLines } from "./startup-banner.js";
77
79
  import { getAppVersion, getPkgRoot } from "./pkg-info.js";
78
80
  import { handleFileMessage, handleScmMessage, handleBgServerMessage, handlePresetAndDshMessage, handleModelAndProviderMessage, handleTerminalMessage, handleSessionLifecycleMessage, handlePlanAndGoalMessage, handleScheduleMessage, handleSettingsMessage, handleInteractiveResponseMessage, handleRemoteSshMessage, } from "./dispatch-domain-handlers.js";
79
81
  import { RemoteSshService, isRemoteWorkspaceUri, serveRemoteWorkspaceFile, setGlobalRemoteSshService, } from "./remote-ssh-service.js";
@@ -211,6 +213,10 @@ const LOCALE_BASE_URL = process.env.PI_WEB_LOCALE_BASE_URL?.trim() || "https://r
211
213
  function appVersion() {
212
214
  return getAppVersion();
213
215
  }
216
+ /** 本次服务进程的运行实例 id(ready 帧的 runId):
217
+ * 重启即变,同一进程内所有连接共享。客户端用它区分「断线重连」与「新实例」,
218
+ * 决定问卷的已答 id 缓存 / 未确认答案能否保留(否则已答问卷会被在途旧快照复活)。 */
219
+ const SERVER_RUN_ID = randomUUID();
214
220
  /** On-disk web-build id: the main JS bundle hash from the built index.html.
215
221
  * Changes on every rebuild — stale pages compare and reload themselves.
216
222
  * Declared near use (below webDist), not here: webDist is a const further
@@ -520,6 +526,15 @@ app.use((req, res, next) => {
520
526
  next();
521
527
  return;
522
528
  }
529
+ const isHtml = Boolean(req.headers.accept?.includes("text/html"));
530
+ if (isHtml) {
531
+ const isLoopback = isLoopbackAddress(req.socket?.remoteAddress);
532
+ res.status(401);
533
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
534
+ res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
535
+ res.send(renderUnauthorizedHtml({ isLoopback, isStaleCookie: Boolean(cookie), port: PORT }));
536
+ return;
537
+ }
523
538
  res
524
539
  .status(401)
525
540
  .send(cookie
@@ -529,6 +544,10 @@ app.use((req, res, next) => {
529
544
  /** 共享客户端持久化存储:双引擎(pi + dsh)共用同一份内存缓存与落盘通道,避免互相覆盖。 */
530
545
  const sharedStateStore = new ClientStateStore(join(DATA_DIR, "client-state.json"));
531
546
  registerPromptTemplateRoutes(app, DATA_DIR);
547
+ registerQuickAskRoutes(app, {
548
+ getSettings: () => sharedStateStore.getSettingsSnapshot(""),
549
+ getRuntime: (signal) => createQuickAskRuntime(getAgentDir(), signal),
550
+ });
532
551
  /** 启动参数显式指定的引擎(--engine pi|dsh|codex|claude|durable 或 PI_WEB_ENGINE)。未显式传则优先读持久化默认引擎。 */
533
552
  const EXPLICIT_ENGINE_ARG = cliFlag("--engine") ?? process.env.PI_WEB_ENGINE;
534
553
  let currentDefaultEngine = EXPLICIT_ENGINE_ARG === "codex"
@@ -1063,6 +1082,7 @@ const deviceCenter = await installLocalDeviceCenter({
1063
1082
  recovery: runtime.recovery,
1064
1083
  reportOutbox: runtime.reportOutbox,
1065
1084
  onTask: runtime.onTask,
1085
+ onSteer: (taskId, text) => runtime.steerTask(taskId, text),
1066
1086
  onInteractionAnswer: (answer) => runtime.answerTaskInteraction(answer.taskId, answer.attemptId, answer),
1067
1087
  onConnect: syncBots,
1068
1088
  onCommand: runtime.onCommand,
@@ -1373,7 +1393,7 @@ heartbeatTimer.unref?.();
1373
1393
  import { DshAgentService } from "./dsh/dsh-agent-service.js";
1374
1394
  import { UniversalAgentService, ClaudeCodeDriver, probeClaudeCode, CodexDriver } from "./universal/index.js";
1375
1395
  import { DurableAgentService } from "./durable/index.js";
1376
- import { probeAllEngines, probeEngine, getCachedEngineStatuses, updateEngineBackground, isEngineUpdating, ENGINE_PACKAGES, } from "./engine-probe.js";
1396
+ import { probeAllEngines, probeEngine, getCachedEngineStatuses, updateEngineBackground, isEngineUpdating, uninstallEngineBackground, isEngineUninstalling, ENGINE_PACKAGES, } from "./engine-probe.js";
1377
1397
  let piServiceInstance = null;
1378
1398
  let dshServiceInstance = null;
1379
1399
  let claudeServiceInstance = null;
@@ -1597,6 +1617,13 @@ const service = {
1597
1617
  resolveSharedQuestion(viewerId, id, answers, cancelled, cancelReason) {
1598
1618
  return (ensureEngine(resolveClientEngine(viewerId)).resolveSharedQuestion?.(viewerId, id, answers, cancelled, cancelReason) ?? false);
1599
1619
  },
1620
+ resolveGlobalQuestion(id, answers, cancelled, cancelReason) {
1621
+ for (const s of activeEngines()) {
1622
+ if (s.resolveGlobalQuestion?.(id, answers, cancelled, cancelReason))
1623
+ return true;
1624
+ }
1625
+ return false;
1626
+ },
1600
1627
  resolveSharedToolApproval(viewerId, ...args) {
1601
1628
  return ensureEngine(resolveClientEngine(viewerId)).resolveSharedToolApproval?.(viewerId, ...args) ?? false;
1602
1629
  },
@@ -1834,6 +1861,7 @@ const scheduler = new SchedulerStore(DATA_DIR, {
1834
1861
  else {
1835
1862
  const runHeadless = () => svc.chatFromScheduler({
1836
1863
  id: task.id,
1864
+ name: task.name,
1837
1865
  cwd: task.cwd,
1838
1866
  prompt: task.prompt,
1839
1867
  model: task.model,
@@ -1900,6 +1928,15 @@ const scheduler = new SchedulerStore(DATA_DIR, {
1900
1928
  else {
1901
1929
  // 降级可见性(issue #231):必须无头时明确广播去向,不静默。
1902
1930
  pushNoticeToAll("warning", `定时任务「${task.name}」原对话不在、同项目也无存活对话,已转后台执行(无头)。报告在后台任务面板的调度历史中查看。`, `Scheduled task "${task.name}" found no live conversation and runs headless; see its report in the background-tasks panel history.`);
1931
+ // 周期任务解绑已失效对话(issue #836),转为标准无头模式,避免每轮触发重复探测与广播警告
1932
+ if (!task.oneShot) {
1933
+ try {
1934
+ scheduler.rebind(task.id, { conversationId: "", sessionFile: "" });
1935
+ }
1936
+ catch {
1937
+ // 解绑失败不影响本次无头执行
1938
+ }
1939
+ }
1903
1940
  result = await runHeadless();
1904
1941
  }
1905
1942
  }
@@ -2564,6 +2601,103 @@ wss.on("connection", (ws) => {
2564
2601
  });
2565
2602
  }
2566
2603
  };
2604
+ const handleUninstallEngine = async (msg) => {
2605
+ const targetEngine = String(msg.engineId || "").trim();
2606
+ if (targetEngine === "pi") {
2607
+ send({
2608
+ type: "notice",
2609
+ level: "error",
2610
+ text: "Pi 为内置核心引擎,不支持卸载",
2611
+ textEn: "Pi is the built-in core engine and cannot be uninstalled",
2612
+ });
2613
+ return;
2614
+ }
2615
+ const meta = ENGINE_PACKAGES[targetEngine];
2616
+ if (!meta || !meta.packageName) {
2617
+ send({
2618
+ type: "notice",
2619
+ level: "error",
2620
+ text: `不支持或未知的引擎「${targetEngine}」`,
2621
+ textEn: `Unsupported or unknown engine "${targetEngine}"`,
2622
+ });
2623
+ return;
2624
+ }
2625
+ const refusal = managedRefusal("uninstall_engine", MANAGED);
2626
+ if (refusal) {
2627
+ send({ type: "notice", level: "error", text: refusal });
2628
+ return;
2629
+ }
2630
+ if (isEngineUpdating(targetEngine)) {
2631
+ send({
2632
+ type: "notice",
2633
+ level: "warning",
2634
+ text: `引擎「${targetEngine.toUpperCase()}」正在后台更新中,请稍候再试`,
2635
+ textEn: `Engine "${targetEngine.toUpperCase()}" is currently updating, please wait…`,
2636
+ });
2637
+ return;
2638
+ }
2639
+ if (isEngineUninstalling(targetEngine)) {
2640
+ send({
2641
+ type: "notice",
2642
+ level: "warning",
2643
+ text: `引擎「${targetEngine.toUpperCase()}」正在后台卸载中,请稍候…`,
2644
+ textEn: `Engine "${targetEngine.toUpperCase()}" is already uninstalling, please wait…`,
2645
+ });
2646
+ return;
2647
+ }
2648
+ const engineDisplayNames = {
2649
+ pi: { zh: "Pi", en: "Pi" },
2650
+ dsh: { zh: "DSH", en: "DSH" },
2651
+ claude: { zh: "Claude Code", en: "Claude Code" },
2652
+ codex: { zh: "Codex", en: "Codex" },
2653
+ durable: { zh: "Pi Durable", en: "Pi Durable" },
2654
+ };
2655
+ const displayName = engineDisplayNames[targetEngine] ?? {
2656
+ zh: targetEngine.toUpperCase(),
2657
+ en: targetEngine.toUpperCase(),
2658
+ };
2659
+ const broadcastStatuses = (list) => {
2660
+ const payload = JSON.stringify({ type: "engines_status", engines: list });
2661
+ for (const c of wss.clients) {
2662
+ if (c.readyState === WebSocket.OPEN) {
2663
+ try {
2664
+ c.send(payload);
2665
+ }
2666
+ catch {
2667
+ /* ignore */
2668
+ }
2669
+ }
2670
+ }
2671
+ };
2672
+ send({
2673
+ type: "notice",
2674
+ level: "info",
2675
+ text: `正在后台卸载 ${displayName.zh} 引擎(npm uninstall -g ${meta.packageName})…`,
2676
+ textEn: `Uninstalling ${displayName.en} engine in background (npm uninstall -g ${meta.packageName})…`,
2677
+ });
2678
+ const uninstallPromise = uninstallEngineBackground(targetEngine);
2679
+ broadcastStatuses(getCachedEngineStatuses());
2680
+ const res = await uninstallPromise;
2681
+ const freshEngines = await probeAllEngines(true);
2682
+ broadcastStatuses(freshEngines);
2683
+ if (res.ok) {
2684
+ send({
2685
+ type: "notice",
2686
+ level: "info",
2687
+ text: `✅ ${displayName.zh} 引擎卸载完成`,
2688
+ textEn: `✅ ${displayName.en} engine uninstalled successfully`,
2689
+ });
2690
+ }
2691
+ else {
2692
+ const detail = res.error || (res.output ? res.output.slice(-200) : "");
2693
+ send({
2694
+ type: "notice",
2695
+ level: "error",
2696
+ text: `❌ ${displayName.zh} 引擎卸载失败${detail ? `:${detail}` : ""}`,
2697
+ textEn: `❌ Failed to uninstall ${displayName.en} engine${detail ? `: ${detail}` : ""}`,
2698
+ });
2699
+ }
2700
+ };
2567
2701
  const dispatch = (msg, wireBytes) => {
2568
2702
  if (!clientId) {
2569
2703
  if (!pending.push(msg, wireBytes))
@@ -2579,6 +2713,10 @@ wss.on("connection", (ws) => {
2579
2713
  void handleUpdateEngine(msg);
2580
2714
  return;
2581
2715
  }
2716
+ if (msg.type === "uninstall_engine") {
2717
+ void handleUninstallEngine(msg);
2718
+ return;
2719
+ }
2582
2720
  if (msg.type === "check_engines") {
2583
2721
  void probeAllEngines(msg.force).then((engines) => {
2584
2722
  if (!closed)
@@ -2663,7 +2801,7 @@ wss.on("connection", (ws) => {
2663
2801
  return;
2664
2802
  if (handleTerminalMessage(msg, cs))
2665
2803
  return;
2666
- if (handleSessionLifecycleMessage(msg, cs, send))
2804
+ if (handleSessionLifecycleMessage(msg, cs, send, service, clientId))
2667
2805
  return;
2668
2806
  if (handlePlanAndGoalMessage(msg, cs))
2669
2807
  return;
@@ -2899,6 +3037,9 @@ wss.on("connection", (ws) => {
2899
3037
  // which a managed instance never runs.
2900
3038
  appVersion: appVersion(),
2901
3039
  buildId: buildId(),
3040
+ // 本进程运行实例 id:客户端靠它区分「断线重连」与「换了新服务」,
3041
+ // 决定已答问卷 id / 未确认答案能否跨连接保留(issue: 问卷无限重生)。
3042
+ runId: SERVER_RUN_ID,
2902
3043
  managed: MANAGED,
2903
3044
  tabs: TABS ? [...TABS] : undefined,
2904
3045
  service: SERVICE_INFO ?? undefined,
@@ -3042,6 +3183,8 @@ wss.on("connection", (ws) => {
3042
3183
  // 新连接/新客户端 attach 首次快照必须强制全量(forceFull=true),
3043
3184
  // 保证新标签页/刷新页能立刻拿到完整的会话基线,绝不因增量 delta 而卡在加载中。
3044
3185
  cs.flushSnapshot(true);
3186
+ void cs.pushProjects();
3187
+ void cs.refreshSessions();
3045
3188
  // 内置定时任务列表随附推一次(后续变更经 pushSchedulerTasks 广播)。
3046
3189
  try {
3047
3190
  send({ type: "scheduler_tasks", tasks: scheduler.list() });
@@ -3057,6 +3200,8 @@ wss.on("connection", (ws) => {
3057
3200
  // ensureLoaded 失败(如磁盘读错)不能卡死快照——前端 30s 无消息
3058
3201
  // 会重连,重连又失败会陷入循环。至少把状态推下去(同样强制全量)。
3059
3202
  cs.flushSnapshot(true);
3203
+ void cs.pushProjects();
3204
+ void cs.refreshSessions();
3060
3205
  replayQueued();
3061
3206
  });
3062
3207
  // hello may carry the UI locale — persist it before replaying
@@ -3170,22 +3315,19 @@ if (process.env[RESTART_CHILD_ENV] === "1") {
3170
3315
  }
3171
3316
  }
3172
3317
  httpServer.listen(PORT, HOST, () => {
3173
- console.log("");
3174
- console.log(" ⚡ pi-web-ui — web chat for the pi coding agent");
3175
- console.log(` http://localhost:${PORT}`);
3176
- console.log(` workspace : ${CWD}`);
3177
- console.log(` session dir : ${SESSION_DIR_ROOT}`);
3178
- console.log(` pi SDK : v${VERSION}`);
3179
- // issue #260:全局那份 pi SDK 不是服务在用的那份(自带副本赢在 Node 解析顺序上)。
3180
- // #321 起默认已反转(resolve-global-sdk 自动跟随更新的那份),这条提示只在
3181
- // 「进程没跟上」(升级发生在启动后 / 旧构建没注入钩子)或显式 PI_WEB_SDK=bundled
3182
- // 钉死自带副本时出现。
3183
3318
  const sdkNote = sdkOriginNote(sdkCopies(), VERSION);
3184
- if (sdkNote) {
3185
- console.log(` pi SDK note : ${sdkNote}`);
3319
+ const bannerLines = formatStartupBannerLines({
3320
+ port: PORT,
3321
+ host: HOST,
3322
+ token: AUTH_TOKEN,
3323
+ cwd: CWD,
3324
+ sessionDir: SESSION_DIR_ROOT,
3325
+ version: VERSION,
3326
+ sdkNote,
3327
+ });
3328
+ for (const line of bannerLines) {
3329
+ console.log(line);
3186
3330
  }
3187
- console.log(` bind : ${HOST}:${PORT}`);
3188
- console.log(` setup : http://127.0.0.1:${PORT}/setup (仅本机:配 token/监听/白名单)`);
3189
3331
  if (autoGeneratedToken) {
3190
3332
  console.log("");
3191
3333
  console.log(" ╔═══════════════════════════════════════════════════════════════════════════════╗");
@@ -33,6 +33,8 @@ export const MANAGED_MESSAGES = [
33
33
  "install_pi_agent",
34
34
  /** Updates an agent engine package via background process. */
35
35
  "update_engine",
36
+ /** Uninstalls an agent engine package via background process. */
37
+ "uninstall_engine",
36
38
  /** Plugin market: fetches and installs a plugin from the network. */
37
39
  "plugin_catalog_add",
38
40
  /** Plugin install/update/uninstall run as a background job (issue #152). */
@@ -16,6 +16,7 @@ import { dirname, join } from "node:path";
16
16
  import { writeJsonAtomicSync } from "./atomic-file.js";
17
17
  import { stripJsonComments } from "./json-utils.js";
18
18
  import { enrichBatch } from "./model-enrich.js";
19
+ import { resolveModelReasoningSpec } from "./reasoning-registry.js";
19
20
  import { pick } from "./i18n.js";
20
21
  import { ProviderOAuthFlowManager } from "./provider-oauth-flow.js";
21
22
  /** Drop provisional overlay rows once the official catalog lists the same id.
@@ -135,6 +136,30 @@ export function mergeProviderConfigEntry(prevEntry, config, models) {
135
136
  const thinkingLevelMap = sanitizeThinkingLevelMap(model.thinkingLevelMap);
136
137
  if (thinkingLevelMap)
137
138
  merged.thinkingLevelMap = thinkingLevelMap;
139
+ if (model.compat && typeof model.compat === "object")
140
+ merged.compat = model.compat;
141
+ if (model.samplingParams && typeof model.samplingParams === "object")
142
+ merged.samplingParams = model.samplingParams;
143
+ if (typeof model.customExtraBody === "string") {
144
+ if (model.customExtraBody.trim()) {
145
+ merged.customExtraBody = model.customExtraBody.trim();
146
+ try {
147
+ const parsed = JSON.parse(model.customExtraBody.trim());
148
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
149
+ merged.samplingParams = {
150
+ ...(merged.samplingParams ?? {}),
151
+ ...parsed,
152
+ };
153
+ }
154
+ }
155
+ catch {
156
+ // 忽略非合法 JSON
157
+ }
158
+ }
159
+ else {
160
+ delete merged.customExtraBody;
161
+ }
162
+ }
138
163
  return merged;
139
164
  });
140
165
  const mergedEntry = { ...prevEntry };
@@ -376,12 +401,13 @@ function parseOpenAiModel(m) {
376
401
  boolMeta(r.supports_vision) === true ||
377
402
  boolMeta(r.vision) === true ||
378
403
  strArrMeta(r.input)?.includes("image") === true;
379
- // 名字与元数据兜底:端点未提供 reasoning 时通过通用推理模型特征推断。
404
+ // 名字与元数据兜底:端点未提供 reasoning 时通过通用推理模型特征或权威知识库推断。
380
405
  // 只增不减:取消勾选靠手填(编辑页/刷新合并都只补缺)。
381
406
  // 网关自报推理档位同样是「这是推理模型」的铁证(如聚合网关的 glm-5.3,
382
407
  // 名字认不出来,但 reasoning_levels 报了 low/high/max)。
383
- const thinkingLevelMap = buildThinkingLevelMapFromMeta(r);
384
- const reasoning = detectReasoningCapability(id, r) || thinkingLevelMap !== undefined;
408
+ const knownSpec = resolveModelReasoningSpec(id, r);
409
+ const thinkingLevelMap = buildThinkingLevelMapFromMeta(r) ?? knownSpec?.thinkingLevelMap;
410
+ const reasoning = detectReasoningCapability(id, r) || thinkingLevelMap !== undefined || Boolean(knownSpec);
385
411
  const contextWindow = numMeta(r.context_window) ?? numMeta(r.context_length) ?? numMeta(r.max_model_len) ?? numMeta(r.max_context_length);
386
412
  const maxTokens = numMeta(r.max_tokens) ?? numMeta(r.max_output_tokens) ?? numMeta(r.max_completion_tokens);
387
413
  return {
@@ -402,9 +428,10 @@ function parseGoogleModel(m) {
402
428
  const rawName = typeof r.name === "string" ? r.name : "";
403
429
  const id = rawName.replace(/^models\//, "");
404
430
  const displayName = typeof r.displayName === "string" ? r.displayName : undefined;
405
- // 与 OpenAI 形状同口径的推断兜底(见 detectReasoningCapability)。
406
- const thinkingLevelMap = buildThinkingLevelMapFromMeta(r);
407
- const reasoning = detectReasoningCapability(id, r) || thinkingLevelMap !== undefined;
431
+ // 与 OpenAI 形状同口径的推断兜底(见 detectReasoningCapability 与 resolveModelReasoningSpec)。
432
+ const knownGoogleSpec = resolveModelReasoningSpec(id, r);
433
+ const thinkingLevelMap = buildThinkingLevelMapFromMeta(r) ?? knownGoogleSpec?.thinkingLevelMap;
434
+ const reasoning = detectReasoningCapability(id, r) || thinkingLevelMap !== undefined || Boolean(knownGoogleSpec);
408
435
  return {
409
436
  id,
410
437
  ...(displayName && displayName !== id ? { name: displayName } : {}),
@@ -1847,11 +1874,26 @@ export class ModelAdminService {
1847
1874
  * from sibling models at compose time. */
1848
1875
  static toModelRow(m) {
1849
1876
  const thinkingLevelMap = sanitizeThinkingLevelMap(m.thinkingLevelMap);
1877
+ let samplingParams = m.samplingParams;
1878
+ if (typeof m.customExtraBody === "string" && m.customExtraBody.trim()) {
1879
+ try {
1880
+ const parsed = JSON.parse(m.customExtraBody.trim());
1881
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
1882
+ samplingParams = { ...(samplingParams ?? {}), ...parsed };
1883
+ }
1884
+ }
1885
+ catch {
1886
+ // 忽略格式错误,保留原样
1887
+ }
1888
+ }
1850
1889
  return {
1851
1890
  id: m.id.trim(),
1852
1891
  ...(m.name?.trim() ? { name: m.name.trim() } : {}),
1853
1892
  ...(m.reasoning ? { reasoning: true } : {}),
1854
1893
  ...(thinkingLevelMap ? { thinkingLevelMap } : {}),
1894
+ ...(m.compat && typeof m.compat === "object" ? { compat: m.compat } : {}),
1895
+ ...(samplingParams && typeof samplingParams === "object" ? { samplingParams } : {}),
1896
+ ...(m.customExtraBody?.trim() ? { customExtraBody: m.customExtraBody.trim() } : {}),
1855
1897
  ...(m.input?.length ? { input: m.input } : {}),
1856
1898
  ...(m.contextWindow ? { contextWindow: Number(m.contextWindow) } : {}),
1857
1899
  ...(m.maxTokens ? { maxTokens: Number(m.maxTokens) } : {}),
@@ -1,3 +1,4 @@
1
+ import { resolveModelReasoningSpec } from "./reasoning-registry.js";
1
2
  const t = (lang, zh, en) => (lang === "zh" ? zh : en);
2
3
  /** 反代路由档位后缀(只在精确匹配失败后剥离;-pro/-flash/-lite 等真实
3
4
  * 家族区分绝不在此列)。 */
@@ -284,13 +285,17 @@ function familySuggestions(norm, indexes, cap = 6) {
284
285
  return out;
285
286
  }
286
287
  function toResult(lang, id, model, source, matchType) {
288
+ const reasoningSpec = resolveModelReasoningSpec(id) ?? resolveModelReasoningSpec(model.id);
289
+ const isReasoning = Boolean(model.reasoning || reasoningSpec);
287
290
  return {
288
291
  id,
289
292
  status: "matched",
290
293
  ...(model.contextWindow ? { contextWindow: model.contextWindow } : {}),
291
294
  ...(model.maxTokens ? { maxTokens: model.maxTokens } : {}),
292
295
  ...(model.vision ? { input: ["text", "image"] } : {}),
293
- ...(model.reasoning ? { reasoning: true } : {}),
296
+ ...(isReasoning ? { reasoning: true } : {}),
297
+ ...(reasoningSpec?.thinkingLevelMap ? { thinkingLevelMap: reasoningSpec.thinkingLevelMap } : {}),
298
+ ...(reasoningSpec?.type ? { reasoningType: reasoningSpec.type } : {}),
294
299
  ...(model.name && model.name.toLowerCase() !== id.toLowerCase() ? { name: model.name } : {}),
295
300
  source: `${source}${matchType === "exact" || matchType === "hint" ? "" : t(lang, "(别名)", " (alias)")}`,
296
301
  matchType,
@@ -464,9 +469,13 @@ export async function enrichBatch(ids, hints, opts = {}) {
464
469
  continue;
465
470
  }
466
471
  const suggestions = familySuggestions(norm, indexes());
472
+ const reasoningSpec = resolveModelReasoningSpec(id);
467
473
  results.push({
468
474
  id,
469
475
  status: suggestions.length ? "suggested" : "unmatched",
476
+ ...(reasoningSpec
477
+ ? { reasoning: true, thinkingLevelMap: reasoningSpec.thinkingLevelMap, reasoningType: reasoningSpec.type }
478
+ : {}),
470
479
  ...(suggestions.length ? { suggestions, matchType: "family" } : {}),
471
480
  note: suggestions.length
472
481
  ? t(lang, "家族相近,可用其 id 作依据重试", "Close family match — retry with its id as evidence")
@@ -27,7 +27,8 @@
27
27
  * read-only node_modules or a different node-pty version just skips the patch
28
28
  * (the runtime console.warn filter in terminals.ts still guards the flood).
29
29
  */
30
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
30
+ import { existsSync, readFileSync } from "node:fs";
31
+ import { writeAtomicSync } from "./atomic-file.js";
31
32
  import { createRequire } from "node:module";
32
33
  import { dirname, join } from "node:path";
33
34
  const require = createRequire(import.meta.url);
@@ -52,7 +53,7 @@ function patchFile(pkgDir, rel, find, replace) {
52
53
  return; // already patched
53
54
  if (!src.includes(find))
54
55
  return; // unexpected content — leave alone
55
- writeFileSync(file, src.replace(find, replace), "utf8");
56
+ writeAtomicSync(file, src.replace(find, replace));
56
57
  }
57
58
  catch {
58
59
  // best-effort — the runtime console.warn filter still guards the flood
@@ -21,7 +21,8 @@
21
21
  * default union semantics — never a crash). MUST be imported before the SDK
22
22
  * modules are first loaded (agent-service.ts imports this first).
23
23
  */
24
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
24
+ import { existsSync, readFileSync } from "node:fs";
25
+ import { writeAtomicSync } from "./atomic-file.js";
25
26
  import { fileURLToPath } from "node:url";
26
27
  import { dirname, join } from "node:path";
27
28
  /** Supported patch pairs across SDK versions (0.87.x, 1.1.0+). */
@@ -67,7 +68,7 @@ function applyPatch() {
67
68
  }
68
69
  }
69
70
  if (changed) {
70
- writeFileSync(file, src, "utf8");
71
+ writeAtomicSync(file, src);
71
72
  }
72
73
  }
73
74
  catch {
@@ -290,7 +290,21 @@ export const UI_SLOT_ALIASES = {
290
290
  leftbar: "sidebar.left",
291
291
  rightbar: "sidebar.right",
292
292
  "tool.footer": "tool.card.footer",
293
+ statusbar: "bottombar",
294
+ statusBar: "bottombar",
295
+ "status.bar": "bottombar",
296
+ bottom: "bottombar",
297
+ footer: "bottombar",
293
298
  };
299
+ /**
300
+ * 宿主在 manifest.ui 下认识的结构性元数据扩展键(非挂载点 Slot,不作为未知 slot 报警丢弃):
301
+ * - items: 平铺声明项列表
302
+ * - arrange: 槽位整理与排序意图
303
+ * - views: 插件自定义视图元信息声明
304
+ * - commands: 插件动作与命令元信息声明
305
+ * - menus: 插件菜单声明
306
+ */
307
+ export const UI_STRUCTURAL_KEYS = new Set(["items", "arrange", "views", "commands", "menus"]);
294
308
  /** 合法的条目种类(缺省 action;settings.pages 缺省 page)。 */
295
309
  export const UI_KINDS = new Set([
296
310
  "view",
@@ -349,6 +363,23 @@ export function parseUiItem(raw, slot, diagnostics) {
349
363
  diag(`ui item "${id}": label truncated to 60 chars`);
350
364
  const kindRaw = trimStr(o.kind, 16);
351
365
  let kind = kindRaw && UI_KINDS.has(kindRaw) ? kindRaw : undefined;
366
+ // 兼容 action 字段写成 { type: "view", viewId: ... } 的历史/异形结构(推断 kind="view")
367
+ let actionStr;
368
+ let viewFromAction;
369
+ if (typeof o.action === "string") {
370
+ actionStr = trimStr(o.action, 64);
371
+ }
372
+ else if (o.action && typeof o.action === "object" && !Array.isArray(o.action)) {
373
+ const actObj = o.action;
374
+ if (actObj.type === "view") {
375
+ if (!kindRaw && !kind)
376
+ kind = "view";
377
+ if (typeof actObj.viewId === "string" && actObj.viewId.trim()) {
378
+ const vid = actObj.viewId.trim();
379
+ viewFromAction = vid.startsWith("plugin:") ? vid : `plugin:${vid}`;
380
+ }
381
+ }
382
+ }
352
383
  if (kindRaw && !kind)
353
384
  diag(`ui item "${id}": unknown kind "${kindRaw}", fallback to default`);
354
385
  if (!kind)
@@ -434,19 +465,21 @@ export function parseUiItem(raw, slot, diagnostics) {
434
465
  diag(`ui item "${id}": options all invalid, ignored`);
435
466
  }
436
467
  }
468
+ const hintRaw = o.hint ?? o.title;
469
+ const view = trimStr(o.view, 64) ?? viewFromAction;
437
470
  if (wasTruncated(o.labelEn, 60))
438
471
  diag(`ui item "${id}": labelEn truncated to 60 chars`);
439
472
  if (wasTruncated(o.icon, 16))
440
473
  diag(`ui item "${id}": icon truncated to 16 chars`);
441
- if (wasTruncated(o.hint, 200))
474
+ if (wasTruncated(hintRaw, 200))
442
475
  diag(`ui item "${id}": hint truncated to 200 chars`);
443
476
  if (wasTruncated(o.hintEn, 200))
444
477
  diag(`ui item "${id}": hintEn truncated to 200 chars`);
445
478
  if (wasTruncated(o.group, 40))
446
479
  diag(`ui item "${id}": group truncated to 40 chars`);
447
- if (wasTruncated(o.action, 64))
480
+ if (wasTruncated(actionStr, 64))
448
481
  diag(`ui item "${id}": action truncated to 64 chars`);
449
- if (wasTruncated(o.view, 64))
482
+ if (wasTruncated(view, 64))
450
483
  diag(`ui item "${id}": view truncated to 64 chars`);
451
484
  if (wasTruncated(o.badge, 24))
452
485
  diag(`ui item "${id}": badge truncated to 24 chars`);
@@ -464,15 +497,15 @@ export function parseUiItem(raw, slot, diagnostics) {
464
497
  ...(normalizeIconSvg(o.iconSvg)
465
498
  ? { iconSvg: normalizeIconSvg(o.iconSvg) }
466
499
  : {}),
467
- ...(trimStr(o.hint, 200) ? { hint: trimStr(o.hint, 200) } : {}),
500
+ ...(trimStr(hintRaw, 200) ? { hint: trimStr(hintRaw, 200) } : {}),
468
501
  ...(trimStr(o.hintEn, 200) ? { hintEn: trimStr(o.hintEn, 200) } : {}),
469
502
  kind,
470
503
  ...(children.length ? { children } : {}),
471
504
  ...(Number.isFinite(num) ? { order: num } : {}),
472
505
  ...(trimStr(o.group, 40) ? { group: trimStr(o.group, 40) } : {}),
473
506
  ...(o.hidden === true ? { hidden: true } : {}),
474
- ...(trimStr(o.action, 64) ? { action: trimStr(o.action, 64) } : {}),
475
- ...(trimStr(o.view, 64) ? { view: trimStr(o.view, 64) } : {}),
507
+ ...(actionStr ? { action: actionStr } : {}),
508
+ ...(view ? { view } : {}),
476
509
  ...(when?.length ? { when } : {}),
477
510
  ...(trimStr(o.badge, 24) ? { badge: trimStr(o.badge, 24) } : {}),
478
511
  ...(typeof o.checked === "boolean" ? { checked: o.checked } : {}),
@@ -541,7 +574,7 @@ export function parseUiContributions(raw, diagnostics) {
541
574
  }
542
575
  }
543
576
  for (const [rawKey, val] of Object.entries(o)) {
544
- if (rawKey === "items" || rawKey === "arrange")
577
+ if (UI_STRUCTURAL_KEYS.has(rawKey))
545
578
  continue;
546
579
  const key = UI_SLOT_ALIASES[rawKey] ?? rawKey;
547
580
  if (!UI_SLOTS.has(key)) {
@@ -3961,6 +3994,30 @@ export class PluginManager {
3961
3994
  self.uiRuntimeFor(info.id).items.set(id, parsed);
3962
3995
  void self.pushToAll().catch(() => { });
3963
3996
  },
3997
+ patch: (arg1, arg2, arg3) => {
3998
+ if (!can("ui"))
3999
+ return;
4000
+ const targetId = typeof arg3 === "object" && arg3 !== null ? String(arg2) : String(arg1);
4001
+ const patchObj = (typeof arg3 === "object" && arg3 !== null ? arg3 : arg2);
4002
+ if (!patchObj || typeof patchObj !== "object" || Array.isArray(patchObj))
4003
+ return;
4004
+ const base = self.uiOf(info.id)?.items.find((x) => x.id === targetId);
4005
+ if (!base) {
4006
+ self.pushRuntimeDiag(info.id, `ui.patch: unknown id "${String(targetId).slice(0, 32)}", ignored`);
4007
+ return;
4008
+ }
4009
+ const diags = [];
4010
+ const mergedRaw = { ...base, ...patchObj, id: targetId, slot: base.slot };
4011
+ const parsed = parseUiItem(mergedRaw, base.slot, diags);
4012
+ for (const m of diags)
4013
+ self.pushRuntimeDiag(info.id, `ui.patch: ${m}`);
4014
+ if (!parsed) {
4015
+ self.pushRuntimeDiag(info.id, `ui.patch: merged item invalid, patch ignored`);
4016
+ return;
4017
+ }
4018
+ self.uiRuntimeFor(info.id).items.set(targetId, parsed);
4019
+ void self.pushToAll().catch(() => { });
4020
+ },
3964
4021
  remove: (id) => {
3965
4022
  if (!can("ui"))
3966
4023
  return;
@@ -9,11 +9,20 @@
9
9
  *
10
10
  * 纪律:
11
11
  * 1. 这里只描述**元数据**(字段名 / 分组 / 文案 key),净化与归一化仍在 preset-share 里;
12
- * 2. `PRESET_FIELD_NAMES` 必须覆盖 `ClientSettings` 的每个字段 —— 单测
12
+ * 2. `PRESET_FIELD_NAMES` / `PRESET_EXCLUDED_KEYS` 必须覆盖 `ClientSettings` 的每个字段 —— 单测
13
13
  * `tests/unit/preset-share.test.ts` 用类型 + 快照双重守卫,漏字段会红;
14
14
  * 3. 分组只影响 UI 折叠与「勾一组」,不影响写入逻辑(导入按字段名过滤)。
15
15
  */
16
16
  import { resolveEnabledAgentTools } from "./tool-manager.js";
17
+ /** Internal flags and independent popup preferences are excluded from agent presets. */
18
+ export const PRESET_EXCLUDED_KEYS = [
19
+ "_promptPluginDevConfigured",
20
+ "quickAskEnabled",
21
+ "quickAskModel",
22
+ "quickAskThinking",
23
+ "quickAskSystemPrompt",
24
+ "quickAskExplainPrompt",
25
+ ];
17
26
  /** 预设字段分组(导入预览里的折叠块;顺序即展示顺序)。 */
18
27
  export const PRESET_GROUP_ORDER = ["prompt", "tools", "terminal", "skills", "ai", "ui", "engine"];
19
28
  /**
@@ -72,6 +81,7 @@ export const PRESET_FIELD_GROUPS = {
72
81
  "retryMaxAttempts",
73
82
  "softCapTokens",
74
83
  "softCapByModel",
84
+ "autoCompactionInstructions",
75
85
  "subagentDefaultModel",
76
86
  "subagentMaxDepth",
77
87
  "subagentAutoWakeMaxTurns",
@@ -406,6 +416,12 @@ export const PRESET_FIELD_META = {
406
416
  hintZh: "针对不同模型单独设置的上下文压缩阈值",
407
417
  hintEn: "Custom soft-cap thresholds configured per model",
408
418
  },
419
+ autoCompactionInstructions: {
420
+ labelZh: "自动压缩附加指令",
421
+ labelEn: "Auto-Compaction Instructions",
422
+ hintZh: "软上限自动压缩时传给 SDK 的自定义指令(留空 = SDK 默认摘要;不影响手动 /compact)",
423
+ hintEn: "Custom instructions passed to automatic soft-cap compaction (empty = SDK default; does not affect manual /compact)",
424
+ },
409
425
  subagentDefaultModel: {
410
426
  labelZh: "子代理默认模型",
411
427
  labelEn: "Subagent Default Model",
@@ -271,6 +271,7 @@ const PRESET_FIELD_KINDS = {
271
271
  retryMaxAttempts: "retry",
272
272
  softCapTokens: "softCap",
273
273
  softCapByModel: "softCapByModel",
274
+ autoCompactionInstructions: "text",
274
275
  subagentDefaultModel: "nullableString",
275
276
  subagentMaxDepth: "number",
276
277
  subagentAutoWakeMaxTurns: "number",