pi-web-ui 0.118.0 → 0.120.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 (195) hide show
  1. package/CHANGELOG.md +143 -1
  2. package/bin/hub-upgrade.mjs +33 -15
  3. package/bin/lib/atomic-file.mjs +90 -0
  4. package/dist/server/agent-service-daemon.js +44 -10
  5. package/dist/server/agent-service.js +930 -166
  6. package/dist/server/approval-default-rules.js +4 -4
  7. package/dist/server/ask-user-question-tool.js +3 -40
  8. package/dist/server/atomic-file.js +130 -5
  9. package/dist/server/background-executors.js +235 -0
  10. package/dist/server/bash-timeout.js +47 -0
  11. package/dist/server/bash-tool.js +72 -5
  12. package/dist/server/bg-servers.js +19 -13
  13. package/dist/server/browser-page-tool.js +38 -29
  14. package/dist/server/browser-script-tool.js +119 -0
  15. package/dist/server/canvas/canvas-agent-tool.js +46 -35
  16. package/dist/server/canvas/canvas-dispatch.js +12 -1
  17. package/dist/server/claim-files-tool.js +6 -7
  18. package/dist/server/client-state.js +457 -41
  19. package/dist/server/communicate-tool.js +59 -77
  20. package/dist/server/compact-context-tool.js +4 -13
  21. package/dist/server/conversation-communication.js +23 -1
  22. package/dist/server/conversation-read-tool.js +14 -23
  23. package/dist/server/conversation-rows.js +17 -0
  24. package/dist/server/conversation-tool-names.js +2 -2
  25. package/dist/server/conversation-tool.js +23 -15
  26. package/dist/server/conversation-touches.js +1 -1
  27. package/dist/server/delegate-mode.js +0 -1
  28. package/dist/server/delegate-task.js +18 -39
  29. package/dist/server/device-center/approval-summary.js +0 -1
  30. package/dist/server/device-center/bot-execution.js +0 -1
  31. package/dist/server/device-center/group-router-runtime.js +2 -0
  32. package/dist/server/device-center/hub-upgrade.js +5 -10
  33. package/dist/server/device-center/task-progress.js +2 -2
  34. package/dist/server/dispatch-domain-handlers.js +97 -24
  35. package/dist/server/dispatch-plugin-handlers.js +10 -0
  36. package/dist/server/dsh/dsh-agent-service.js +21 -19
  37. package/dist/server/durable/durable-agent-service.js +1 -1
  38. package/dist/server/edit-tool.js +293 -0
  39. package/dist/server/engine-catalog.js +8 -2
  40. package/dist/server/engine-cli.js +29 -7
  41. package/dist/server/engine-probe.js +11 -6
  42. package/dist/server/eval-tool.js +5 -19
  43. package/dist/server/files-service.js +41 -19
  44. package/dist/server/fs-copy.js +93 -0
  45. package/dist/server/goal-review-gate.js +2 -3
  46. package/dist/server/index.js +92 -3
  47. package/dist/server/job-runner.js +345 -0
  48. package/dist/server/lsp-tool.js +10 -28
  49. package/dist/server/marker-service.js +42 -30
  50. package/dist/server/mcp-agent-tool.js +22 -47
  51. package/dist/server/model-session.js +16 -0
  52. package/dist/server/native-cli-session-hooks.js +3 -2
  53. package/dist/server/native-cli-session.js +27 -2
  54. package/dist/server/patch-tool.js +2 -8
  55. package/dist/server/phone-tool.js +167 -0
  56. package/dist/server/plan-mode.js +7 -4
  57. package/dist/server/plan-update-tool.js +5 -8
  58. package/dist/server/plugin-api-catalog.js +13 -1
  59. package/dist/server/plugin-bundled.js +35 -28
  60. package/dist/server/plugin-catalog.js +6 -0
  61. package/dist/server/plugin-delivery.js +358 -0
  62. package/dist/server/plugin-inbox.js +152 -0
  63. package/dist/server/plugin-installer.js +15 -0
  64. package/dist/server/plugin-ledger.js +183 -0
  65. package/dist/server/plugin-manifest-validate.js +19 -0
  66. package/dist/server/plugin-materialize.js +161 -0
  67. package/dist/server/plugin-paths.js +60 -0
  68. package/dist/server/plugin-removal.js +16 -3
  69. package/dist/server/plugin-schedule.js +8 -7
  70. package/dist/server/plugin-secrets.js +7 -3
  71. package/dist/server/plugin-updater.js +2 -4
  72. package/dist/server/plugins.js +205 -48
  73. package/dist/server/present-files-tool.js +7 -13
  74. package/dist/server/preset-fields.js +23 -12
  75. package/dist/server/preset-share.js +1 -1
  76. package/dist/server/process-utils.js +11 -0
  77. package/dist/server/project-scripts.js +38 -0
  78. package/dist/server/prompt-composer.js +40 -21
  79. package/dist/server/protocol-version.js +1 -1
  80. package/dist/server/question-params.js +98 -0
  81. package/dist/server/quick-ask-settings.js +0 -1
  82. package/dist/server/quick-ask.js +3 -0
  83. package/dist/server/read-tool.js +10 -17
  84. package/dist/server/remote-ssh-service.js +40 -1
  85. package/dist/server/sandbox-runtime-gate.js +1 -1
  86. package/dist/server/sandbox-service.js +0 -1
  87. package/dist/server/sandbox-tool.js +25 -34
  88. package/dist/server/schedule-agent-tool.js +9 -19
  89. package/dist/server/scm-commitmsg.js +2 -1
  90. package/dist/server/serialize.js +8 -0
  91. package/dist/server/session-list-index.js +246 -0
  92. package/dist/server/session-list-scan.js +5 -0
  93. package/dist/server/session-parser.js +16 -0
  94. package/dist/server/settings-service.js +49 -19
  95. package/dist/server/skill-tool.js +4 -6
  96. package/dist/server/subagent-budget.js +68 -0
  97. package/dist/server/subagent-evidence.js +297 -0
  98. package/dist/server/subagent-helpers.js +12 -0
  99. package/dist/server/subagent-ledger.js +401 -0
  100. package/dist/server/subagent-notify.js +6 -2
  101. package/dist/server/subagent-security-gate.js +2 -3
  102. package/dist/server/subagent-settle.js +71 -0
  103. package/dist/server/subagents.js +566 -211
  104. package/dist/server/tabs.js +8 -1
  105. package/dist/server/terminals.js +34 -28
  106. package/dist/server/tool-approval.js +15 -1
  107. package/dist/server/tool-guards.js +0 -91
  108. package/dist/server/tool-manager.js +127 -47
  109. package/dist/server/tool-overrides.js +8 -1
  110. package/dist/server/tool-prompt-overrides.js +3 -6
  111. package/dist/server/tool-prompts.js +60 -17
  112. package/dist/server/universal/driver-base.js +2 -0
  113. package/dist/server/universal/drivers/claude-code.js +210 -211
  114. package/dist/server/universal/drivers/codex.js +29 -24
  115. package/dist/server/universal/engine-mcp.js +107 -0
  116. package/dist/server/universal/universal-attachments.js +77 -1
  117. package/dist/server/universal/universal-service.js +1 -1
  118. package/dist/server/universal/universal-session.js +106 -69
  119. package/dist/server/vision-bridge.js +2 -0
  120. package/dist/server/workspace-handle.js +119 -17
  121. package/dist/server/workspace-queue.js +37 -0
  122. package/dist/server/worktree-tool.js +13 -20
  123. package/docs/README.md +40 -36
  124. package/docs/architecture-plugins.md +64 -35
  125. package/docs/device-center.md +1 -1
  126. package/package.json +16 -4
  127. package/plugin-sdk/index.d.ts +102 -0
  128. package/plugins/catalog.json +23 -51
  129. package/themes/bases/flow-base.css +8 -17
  130. package/themes/dark-teal.css +0 -3
  131. package/web/dist/.build-assets.json +1 -1
  132. package/web/dist/assets/BgTasksModal-BdOJ19Hj.js +1 -0
  133. package/web/dist/assets/BgTasksModal-SAH2XCkY.js +1 -0
  134. package/web/dist/assets/{CanvasStudio-CAWcs9tm.js → CanvasStudio-BB_Iq7pl.js} +3 -3
  135. package/web/dist/assets/CanvasStudio-DU6O3N4u.js +1579 -0
  136. package/web/dist/assets/DeviceCenter-By1zVTSY.js +3 -0
  137. package/web/dist/assets/DeviceCenter-Cnm0Tjrx.js +3 -0
  138. package/web/dist/assets/DeviceExecutionSettings-qJzbI0Cf.js +1 -0
  139. package/web/dist/assets/{DeviceGroups-C_fZMNeK.js → DeviceGroups-DPrQxW6B.js} +1 -1
  140. package/web/dist/assets/DeviceGroups-DoucyUjI.js +1 -0
  141. package/web/dist/assets/{Dropdown-CTgVLUbp.js → Dropdown-kj_NIj6e.js} +1 -1
  142. package/web/dist/assets/FilePreview-Bub8Y9uq.js +2 -0
  143. package/web/dist/assets/FilePreview-CC76Z6an.js +2 -0
  144. package/web/dist/assets/GlobalSearchModal-01nkgw4X.js +1 -0
  145. package/web/dist/assets/GlobalSearchModal-CiT6wBmR.js +1 -0
  146. package/web/dist/assets/GroupConversation-1-lsPO1f.js +61 -0
  147. package/web/dist/assets/GroupConversation-HeiyW_O_.js +61 -0
  148. package/web/dist/assets/{GroupWorkItems-BIvZtr10.js → GroupWorkItems-BYJv2XFj.js} +1 -1
  149. package/web/dist/assets/{HintTip-Da6qc566.js → HintTip-DFhoclDw.js} +1 -1
  150. package/web/dist/assets/ModelConfigModal-D2Ro-jUZ.js +2 -0
  151. package/web/dist/assets/ModelConfigModal-DPc9R1pq.js +2 -0
  152. package/web/dist/assets/{NativeCliPanel-CU1rZmyu.js → NativeCliPanel-B108d697.js} +3 -3
  153. package/web/dist/assets/NativeCliPanel-DupvGwQM.js +5 -0
  154. package/web/dist/assets/{PiSetupModal-DZKY5Wiw.js → PiSetupModal-D0HitBfd.js} +1 -1
  155. package/web/dist/assets/ProviderOAuthControls-BLKUEDde.js +1 -0
  156. package/web/dist/assets/SCMPanel-DDbWrUHR.js +2 -0
  157. package/web/dist/assets/SCMPanel-DluNcd2-.js +2 -0
  158. package/web/dist/assets/SettingsModal-Cy5lRC97.css +1 -0
  159. package/web/dist/assets/SettingsModal-DQu18366.js +33 -0
  160. package/web/dist/assets/SettingsModal-Dm_haPme.js +33 -0
  161. package/web/dist/assets/{TermXterm-Bt5WKAxP.js → TermXterm-SYc-MUk2.js} +2 -2
  162. package/web/dist/assets/TerminalPanel-CgA_lhVT.js +1 -0
  163. package/web/dist/assets/TerminalPanel-vdSIOPjD.js +1 -0
  164. package/web/dist/assets/TuiOverlayModal-Cy1jYYIw.js +1 -0
  165. package/web/dist/assets/TuiOverlayModal-kXY_4hV8.js +1 -0
  166. package/web/dist/assets/app-globals-CBEscsYP.js +129 -0
  167. package/web/dist/assets/{canvas-client-WkhM55mR.js → canvas-client-Clsypfs6.js} +1 -1
  168. package/web/dist/assets/{desktop-B8NZ3KW-.js → desktop-C6D9a8HZ.js} +1 -1
  169. package/web/dist/assets/index-BD29OL9L.js +404 -0
  170. package/web/dist/assets/index-BlCxbqqr.js +404 -0
  171. package/web/dist/assets/index-DB55rbKC.css +1 -0
  172. package/web/dist/assets/plugin-host-VWBcq-LQ.js +1 -0
  173. package/web/dist/assets/remote-ssh-client-C2eab5Kw.js +1 -0
  174. package/web/dist/assets/theme-CpQk_Agp.js +1 -0
  175. package/web/dist/index.html +10 -10
  176. package/web/dist/sw.js +1 -1
  177. package/dist/server/edit-soft-tool.js +0 -297
  178. package/web/dist/assets/BgTasksModal-D-x7kA63.js +0 -1
  179. package/web/dist/assets/DeviceCenter-Dc0whRcu.js +0 -3
  180. package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +0 -1
  181. package/web/dist/assets/FilePreview-C6W0PvaK.js +0 -2
  182. package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +0 -1
  183. package/web/dist/assets/GroupConversation-C81YjF2C.js +0 -61
  184. package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +0 -2
  185. package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +0 -1
  186. package/web/dist/assets/SCMPanel-CuEgzAlO.js +0 -2
  187. package/web/dist/assets/SettingsModal-Cdu5h29p.js +0 -33
  188. package/web/dist/assets/TerminalPanel-BCIBV8se.js +0 -1
  189. package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +0 -1
  190. package/web/dist/assets/app-globals-CZjFtI4F.js +0 -129
  191. package/web/dist/assets/index-CQc3VrWa.css +0 -1
  192. package/web/dist/assets/index-D_AGu4Zv.js +0 -404
  193. package/web/dist/assets/plugin-host-uqZGpvCs.js +0 -1
  194. package/web/dist/assets/remote-ssh-client-Cdf-cTUe.js +0 -1
  195. package/web/dist/assets/theme-DGL7hLUs.js +0 -1
@@ -0,0 +1,38 @@
1
+ import { existsSync, readFileSync, statSync } from "node:fs";
2
+ import { dirname, join, resolve } from "node:path";
3
+ const MAX_PKG_BYTES = 512 * 1024;
4
+ function readScripts(pkgPath) {
5
+ try {
6
+ if (!existsSync(pkgPath) || statSync(pkgPath).size > MAX_PKG_BYTES)
7
+ return undefined;
8
+ const raw = JSON.parse(readFileSync(pkgPath, "utf8"));
9
+ if (!raw || typeof raw !== "object" || !raw.scripts || typeof raw.scripts !== "object")
10
+ return undefined;
11
+ const out = {};
12
+ for (const [k, v] of Object.entries(raw.scripts)) {
13
+ if (typeof v === "string" && v.trim())
14
+ out[k] = v.trim().slice(0, 500);
15
+ if (Object.keys(out).length >= 60)
16
+ break;
17
+ }
18
+ return Object.keys(out).length > 0 ? out : undefined;
19
+ }
20
+ catch {
21
+ return undefined;
22
+ }
23
+ }
24
+ /** 从 cwd 就近向上找 package.json(含 scripts 的那一层),找不到返回 cwd 本身 + 空表。 */
25
+ export function resolveProjectScripts(cwd) {
26
+ const start = resolve(cwd || process.cwd());
27
+ let cur = start;
28
+ while (cur) {
29
+ const scripts = readScripts(join(cur, "package.json"));
30
+ if (scripts)
31
+ return { cwd: cur, scripts };
32
+ const parent = dirname(cur);
33
+ if (parent === cur)
34
+ break;
35
+ cur = parent;
36
+ }
37
+ return { cwd: start, scripts: {} };
38
+ }
@@ -5,8 +5,6 @@ export const PROMPT_TOKENS = [
5
5
  "guidelines",
6
6
  "pi_docs",
7
7
  "append",
8
- "persona",
9
- "terminal",
10
8
  "markers",
11
9
  "plugin_dev",
12
10
  "context",
@@ -17,8 +15,6 @@ export const READONLY_PROMPT_SOURCES = [
17
15
  "tools",
18
16
  "pi_docs",
19
17
  "plugin_dev",
20
- "persona",
21
- "terminal",
22
18
  "markers",
23
19
  "context",
24
20
  "skills",
@@ -28,6 +24,17 @@ export const DEFAULT_PROMPT_DISABLED = ["plugin_dev"];
28
24
  export function isReadonlyPromptSource(token) {
29
25
  return READONLY_PROMPT_SOURCES.includes(token);
30
26
  }
27
+ /**
28
+ * 已下线的历史来源:`{{terminal}}`(终端工具引导)、`{{persona}}`(Windows 约束)。
29
+ * 老模板/老预设里残留该 token 时渲染为空——不留 `{{terminal}}` / `{{persona}}` 字面量,也不复活该段文本。
30
+ *
31
+ * `{{persona}}` 下线理由:Windows / 远程工作区约束由宿主在 append 段无条件注入(`WINDOWS_PERSONA`),
32
+ * 再挂一个可开关 token 只会让同一段文字注入两遍;设置面板也不该让用户去「启用」平台安全约束。
33
+ */
34
+ export const LEGACY_PROMPT_TOKENS = ["terminal", "persona"];
35
+ export function isLegacyPromptToken(token) {
36
+ return LEGACY_PROMPT_TOKENS.includes(token);
37
+ }
31
38
  export const DEFAULT_PROMPT_TEMPLATE = PROMPT_TOKENS.map((t) => `{{${t}}}`).join("\n\n");
32
39
  const TOKEN_RE = /\{\{\s*([A-Za-z_][A-Za-z0-9_]*)\s*\}\}/g;
33
40
  export function collectTemplateTokens(template) {
@@ -197,25 +204,37 @@ function buildContextText(files, lang = "en") {
197
204
  "</project_context>",
198
205
  ].join("\n");
199
206
  }
200
- function buildToolsText(inputs, lang) {
207
+ const TOOLS_TAIL = "In addition to the tools above, you may have access to other custom tools depending on the project.";
208
+ function buildToolsText(inputs) {
201
209
  const listed = inputs.catalogTools ?? inputs.selectedTools;
202
- const visible = listed.filter((n) => !!inputs.toolSnippets[n]);
203
- if (!inputs.lazy && visible.length === 0)
204
- return "";
205
- const toolsList = visible.length > 0
206
- ? visible
210
+ if (inputs.lazy) {
211
+ // 按需目录:只列名单工具(常驻工具 schema 已全量下发,不重复列)。
212
+ // 名单为空 = 没有任何工具可加载,整段(目录 + load_tools 说明 + 尾巴)都不输出。
213
+ if (listed.length === 0)
214
+ return "";
215
+ const onDemandList = listed
207
216
  .map((n) => {
208
217
  const sig = inputs.toolSignatures?.[n] ? ` ${inputs.toolSignatures[n]}` : "";
209
- return `- ${n}:${sig} ${inputs.toolSnippets[n]}`;
218
+ const snippet = inputs.toolSnippets[n];
219
+ return `- ${n}:${sig}${snippet ? ` ${snippet}` : ""}`;
210
220
  })
211
- .join("\n")
212
- : "(none)";
213
- const parts = [`Available tools:\n${toolsList}`];
214
- if (inputs.lazy) {
215
- parts.push(pick(lang, "核心工具(bash, read, edit, write)及 `load_tools` 始终常驻可用,无需加载。上表中其他尚未附加参数 schema 的工具,调用前先用 `load_tools` 附加上完整参数(本对话后续轮次持续有效)。", "Core tools (bash, read, edit, write) and `load_tools` are always active and ready to use. Other tools above do NOT have their parameter schema attached yet: pass their names to `load_tools` before calling them to attach full schemas for the rest of this conversation.", "prompt.tools.lazy"));
221
+ .join("\n");
222
+ // 纯英文精简:工具段不进双语(与工具提示词口径一致)。
223
+ return [
224
+ `On-demand tools (schema not attached — call \`load_tools\` with the names first):\n${onDemandList}`,
225
+ TOOLS_TAIL,
226
+ ].join("\n\n");
216
227
  }
217
- parts.push("In addition to the tools above, you may have access to other custom tools depending on the project.");
218
- return parts.join("\n\n");
228
+ const visible = listed.filter((n) => !!inputs.toolSnippets[n]);
229
+ if (visible.length === 0)
230
+ return "";
231
+ const toolsList = visible
232
+ .map((n) => {
233
+ const sig = inputs.toolSignatures?.[n] ? ` ${inputs.toolSignatures[n]}` : "";
234
+ return `- ${n}:${sig} ${inputs.toolSnippets[n]}`;
235
+ })
236
+ .join("\n");
237
+ return [`Available tools:\n${toolsList}`, TOOLS_TAIL].join("\n\n");
219
238
  }
220
239
  export function buildToolsSchemaText(tools) {
221
240
  if (tools.length === 0)
@@ -242,12 +261,10 @@ export function resolveSectionTexts(inputs) {
242
261
  soul = `${soul}\nBe concise in your responses\nShow file paths clearly when working with files`;
243
262
  return {
244
263
  soul,
245
- tools: buildToolsText(inputs, lang),
264
+ tools: buildToolsText(inputs),
246
265
  guidelines: buildGuidelinesText(inputs),
247
266
  pi_docs: buildPiDocsText(inputs.piReadme, inputs.piDocs, inputs.piExamples, lang),
248
267
  append: inputs.appendFiles.join("\n\n"),
249
- persona: inputs.windowsPersona,
250
- terminal: inputs.terminalGuidance,
251
268
  markers: inputs.markersGuidance,
252
269
  plugin_dev: buildPluginDevText(inputs, lang),
253
270
  context: buildContextText(inputs.contextFiles, lang),
@@ -264,6 +281,8 @@ export function renderPromptTemplate(template, texts, overrides, disabled) {
264
281
  return effectiveTemplate(template).replace(TOKEN_RE, (full, name) => {
265
282
  if (dis.has(name))
266
283
  return "";
284
+ if (isLegacyPromptToken(name))
285
+ return "";
267
286
  const ov = overrideOf(overrides, name);
268
287
  if (ov)
269
288
  return ov;
@@ -1 +1 @@
1
- export const PROTOCOL_VERSION = 51;
1
+ export const PROTOCOL_VERSION = 55;
@@ -0,0 +1,98 @@
1
+ import { Type } from "typebox";
2
+ // 结构化提问的唯一 schema 单源:富档给 ask_user_question,转发档给 communicate / conversation consult。
3
+ // 转发档少声明富字段但不减能力——TypeBox 默认不写 additionalProperties:false,富字段照样通过校验原样转发。
4
+ /** 富选项:浏览器弹窗里渲染的单个选项。 */
5
+ export function questionOptionSchema() {
6
+ return Type.Object({
7
+ label: Type.String({ minLength: 1, description: "Display label (1-5 words)" }),
8
+ description: Type.Optional(Type.String({ description: "Short explanation of impact/tradeoff" })),
9
+ preview: Type.Optional(Type.String({ description: "Optional preview (markdown/HTML/code)" })),
10
+ recommended: Type.Optional(Type.Boolean({ description: "Highlight as recommended option" })),
11
+ });
12
+ }
13
+ /** 富问题:一条问题(含富选项、联动、动态选项)。 */
14
+ export function richQuestionSchema() {
15
+ const options = Type.Array(questionOptionSchema(), {
16
+ description: "2-4 choices (recommended option first)",
17
+ minItems: 2,
18
+ maxItems: 4,
19
+ });
20
+ return Type.Object({
21
+ id: Type.String({ minLength: 1, description: "Unique identifier (snake_case)" }),
22
+ question: Type.String({ minLength: 1, description: "Question text (markdown/HTML ok)" }),
23
+ detail: Type.Optional(Type.String({ description: "Optional context under question" })),
24
+ header: Type.Optional(Type.String({ description: "Optional short header" })),
25
+ options: Type.Optional(options),
26
+ multiSelect: Type.Optional(Type.Boolean({ description: "Allow multiple choices (default: false)" })),
27
+ dependsOn: Type.Optional(Type.Object({
28
+ questionId: Type.String({ description: "Prior question ID" }),
29
+ value: Type.Optional(Type.Union([Type.String(), Type.Array(Type.String())], {
30
+ description: "Show when prior answer matches",
31
+ })),
32
+ })),
33
+ optionsMap: Type.Optional(Type.Record(Type.String(), Type.Array(questionOptionSchema(), { minItems: 2, maxItems: 4 }), {
34
+ description: "Dynamic options keyed by prior answer",
35
+ })),
36
+ });
37
+ }
38
+ /** 富问题列表:弹窗能力的事实源。 */
39
+ export function richQuestionsSchema(description = "Questions to ask (prefer 1).") {
40
+ return Type.Array(richQuestionSchema(), { description, minItems: 1, maxItems: 3 });
41
+ }
42
+ /** 弹窗专属字段:模型不需要声明,导出 schema 里省略;运行时照常接收。 */
43
+ const ASK_HIDDEN_QUESTION_FIELDS = ["header", "dependsOn", "optionsMap"];
44
+ /** 纯装饰的 JSON Schema 关键字:发给模型前删掉,运行时校验留在原处。 */
45
+ const DECORATION_KEYS = ["description", "minItems", "maxItems", "minLength", "minimum", "maximum"];
46
+ function stripDecoration(node) {
47
+ if (!node || typeof node !== "object")
48
+ return;
49
+ const record = node;
50
+ for (const [key, value] of Object.entries(record)) {
51
+ // `properties` 的键是字段名(可能就叫 description),只下沉不删除。
52
+ if (key === "properties") {
53
+ if (value && typeof value === "object")
54
+ for (const child of Object.values(value))
55
+ stripDecoration(child);
56
+ continue;
57
+ }
58
+ if (DECORATION_KEYS.includes(key)) {
59
+ delete record[key];
60
+ continue;
61
+ }
62
+ stripDecoration(value);
63
+ }
64
+ }
65
+ /**
66
+ * `ask_user_question` 的导出参数:富档的派生视图 —— 去掉弹窗专属字段与装饰关键字,
67
+ * 模型只看到「问什么、给哪些选项」。字段定义仍只有 {@link richQuestionSchema} 一处。
68
+ */
69
+ export function askQuestionsSchema() {
70
+ const schema = richQuestionsSchema();
71
+ for (const key of ASK_HIDDEN_QUESTION_FIELDS)
72
+ delete schema.items.properties[key];
73
+ const optionItems = schema.items.properties.options?.items;
74
+ if (optionItems?.properties)
75
+ delete optionItems.properties.preview;
76
+ stripDecoration(schema);
77
+ return schema;
78
+ }
79
+ /** 转发问题列表:只声明跨对话转发时必须填的字段。 */
80
+ export function relayQuestionsSchema(description) {
81
+ return Type.Array(Type.Object({
82
+ id: Type.String({ minLength: 1 }),
83
+ question: Type.String({ minLength: 1 }),
84
+ options: Type.Optional(Type.Array(Type.Object({
85
+ label: Type.String({ minLength: 1 }),
86
+ description: Type.Optional(Type.String()),
87
+ }), { minItems: 2, maxItems: 4 })),
88
+ multiSelect: Type.Optional(Type.Boolean()),
89
+ }), { description, minItems: 1, maxItems: 3 });
90
+ }
91
+ /** 回答列表:`communicate reply` 与 `conversation answer` 共用。 */
92
+ export function answersSchema(description) {
93
+ return Type.Array(Type.Object({
94
+ id: Type.String(),
95
+ selected: Type.Array(Type.String()),
96
+ custom: Type.Optional(Type.String()),
97
+ }), { minItems: 1, maxItems: 3, ...(description ? { description } : {}) });
98
+ }
@@ -53,7 +53,6 @@ export function normalizeQuickAskSettings(value) {
53
53
  translatePrompt.length <= MAX_QUICK_ASK_PROMPT_LENGTH
54
54
  ? translatePrompt
55
55
  : DEFAULT_QUICK_ASK_TRANSLATE_PROMPT,
56
- quickAskShowOriginal: typeof value.quickAskShowOriginal === "boolean" ? value.quickAskShowOriginal : false,
57
56
  quickAskReferenceMenus: typeof value.quickAskReferenceMenus === "boolean" ? value.quickAskReferenceMenus : true,
58
57
  quickAskConversationScope: value.quickAskConversationScope === "full" ? "full" : "recent",
59
58
  quickAskFolderScope: value.quickAskFolderScope === "content" ? "content" : "listing",
@@ -1,6 +1,7 @@
1
1
  import { ModelRuntime } from "@earendil-works/pi-coding-agent";
2
2
  import { join } from "node:path";
3
3
  import { isQuickAskModel, normalizeQuickAskSettings } from "./quick-ask-settings.js";
4
+ import { modelSessionId } from "./model-session.js";
4
5
  import { MAX_QUICK_ASK_ATTACHMENTS, MAX_QUICK_ASK_TOTAL_IMAGE_BYTES, QuickAskError, parseQuickAskAttachment, quickAskAttachmentText, parseQuickAskContextRequest, resolveQuickAskContext, QUICK_ASK_CONTEXT_TIMEOUT_MS, } from "./quick-ask-context.js";
5
6
  export const MAX_QUICK_ASK_TEXT_LENGTH = 65_536;
6
7
  export const MAX_QUICK_ASK_MESSAGES = 100;
@@ -106,6 +107,8 @@ async function complete(request, settings, runtime, signal, emit) {
106
107
  ...(settings.quickAskThinking !== "off" ? { reasoning: settings.quickAskThinking } : {}),
107
108
  signal,
108
109
  maxTokens: 4096,
110
+ // Keep one provider session per popup topic: relay gateways reject requests without it.
111
+ sessionId: modelSessionId(request.messages[0]?.content),
109
112
  };
110
113
  let result;
111
114
  if (emit) {
@@ -26,29 +26,22 @@ export async function isDirectoryPath(absolutePath) {
26
26
  }
27
27
  }
28
28
  const readDirSchema = Type.Object({
29
- path: Type.String({
30
- description: "Path to the file (or directory) to read (relative or absolute)",
31
- }),
32
- file_path: Type.Optional(Type.String({
33
- description: "Alias of `path` — some clients/models emit file_path; if both are given, `path` wins",
34
- })),
29
+ path: Type.String(),
35
30
  offset: Type.Optional(Type.Number({
36
- description: "Line number to start reading from (1-indexed)",
37
- })),
38
- limit: Type.Optional(Type.Number({
39
- description: "Maximum number of lines to read (for a directory path: maximum number of entries)",
31
+ description: "1-indexed start line",
40
32
  })),
41
- }, {});
33
+ limit: Type.Optional(Type.Number()),
34
+ });
42
35
  export function prepareReadArguments(raw) {
43
36
  const args = raw && typeof raw === "object" && !Array.isArray(raw) ? { ...raw } : {};
44
- const primary = typeof args.path === "string" ? args.path : "";
45
- const alias = typeof args.file_path === "string" ? args.file_path : "";
46
- if (!primary.trim() && alias.trim())
47
- args.path = alias;
37
+ const path = typeof args.path === "string" && args.path.trim() ? args.path : args.file_path;
38
+ if (typeof path === "string")
39
+ args.path = path;
48
40
  return args;
49
41
  }
50
42
  const DIR_DESCRIPTION_NOTE = "Also accepts a directory path: its entries are listed instead of contents (one per line, directories suffixed with '/'); `limit` then caps entries and `offset` is ignored.";
51
- const FILE_PATH_ALIAS_NOTE = "Also accepts `file_path` as an alias of `path`.";
43
+ /** `read` 的主描述(目录能力与截断规则都在这一句里)。 */
44
+ const READ_DESCRIPTION = "Read file text/image or list directory entries ('/' suffix). Truncated to 2000 lines/50KB; use offset/limit to paginate.";
52
45
  const DIR_GUIDELINE = "No need to shell out to `ls`: read lists a directory's entries";
53
46
  async function dirAwareExecute(base, ls, fallbackCwd, dirEnabled, getLang, normalizePath, toolCallId, params, signal, onUpdate, ctx) {
54
47
  const input = (params ?? {});
@@ -92,7 +85,7 @@ export function makeReadDirTool(fallbackCwd, options = {}) {
92
85
  const getLang = options.getLang ?? (() => "en");
93
86
  return defineTool({
94
87
  ...base,
95
- description: `${base.description} ${FILE_PATH_ALIAS_NOTE} ${DIR_DESCRIPTION_NOTE}`,
88
+ description: READ_DESCRIPTION,
96
89
  promptSnippet: "file contents by path (a directory lists its entries)",
97
90
  promptGuidelines: [...(base.promptGuidelines ?? []), DIR_GUIDELINE],
98
91
  parameters: readDirSchema,
@@ -140,7 +140,7 @@ export function buildRemoteWorkspacePersona(remoteUri) {
140
140
  `You are operating inside a REMOTE SSH workspace (${remoteUri}).`,
141
141
  `- Target host: ${hostDesc}`,
142
142
  `- Remote working directory: ${remoteDir}`,
143
- `- All built-in workspace tools (bash, read, write, edit, edit_soft, ls, find, grep) and interactive terminals are ALREADY transparently bridged to execute directly on the remote host in "${remoteDir}".`,
143
+ `- All built-in workspace tools (bash, read, write, edit, ls, find, grep) and interactive terminals are ALREADY transparently bridged to execute directly on the remote host in "${remoteDir}".`,
144
144
  `- Use normal POSIX relative paths (e.g. "src/index.ts") or remote absolute paths (e.g. "${remoteDir}/src/index.ts") directly in read/write/edit/bash/ls/find/grep. Do NOT wrap bash commands in "ssh ..." and do NOT treat this workspace as the local client OS.`,
145
145
  ``,
146
146
  `Follow these rules to avoid hanging the session:`,
@@ -285,6 +285,7 @@ export class RemoteSshService {
285
285
  hostConnections = new Map();
286
286
  inflightConnects = new Map();
287
287
  credentialCache = new Map();
288
+ pendingHostKeys = new Map();
288
289
  secretKey = null;
289
290
  constructor(dataDir) {
290
291
  this.dataDir = dataDir;
@@ -730,9 +731,20 @@ export class RemoteSshService {
730
731
  conn = this.registerConnection(client, hydrated);
731
732
  }
732
733
  catch (err) {
734
+ const anyErr = err;
735
+ const hostKey = err.hostKey;
736
+ if (anyErr.hostTrust && Buffer.isBuffer(hostKey)) {
737
+ if (!this.pendingHostKeys)
738
+ this.pendingHostKeys = new Map();
739
+ this.pendingHostKeys.set(`${anyErr.hostTrust.host.toLowerCase()}:${anyErr.hostTrust.port}`, {
740
+ key: Buffer.from(hostKey),
741
+ fingerprint: anyErr.hostTrust.fingerprint,
742
+ });
743
+ }
733
744
  return {
734
745
  ok: false,
735
746
  error: err.message || String(err),
747
+ hostTrust: anyErr.hostTrust,
736
748
  };
737
749
  }
738
750
  }
@@ -783,6 +795,33 @@ done
783
795
  };
784
796
  }
785
797
  }
798
+ async trustHostKey(params) {
799
+ try {
800
+ const pending = this.pendingHostKeys?.get(`${params.host.toLowerCase()}:${params.port}`);
801
+ if (!pending || pending.fingerprint !== params.fingerprint) {
802
+ return {
803
+ ok: false,
804
+ error: "主机密钥已过期,请重新连接获取最新指纹后再确认 / Host key expired; reconnect first",
805
+ };
806
+ }
807
+ const packageRoot = resolveDefaultPkgRoot();
808
+ if (!packageRoot)
809
+ throw new Error("Cannot locate SSH host verification module");
810
+ const { saveTrustedHostKey } = await import(pathToFileURL(path.join(packageRoot, "plugin-sdk", "ssh-host-trust.mjs")).href);
811
+ await saveTrustedHostKey({
812
+ host: params.host,
813
+ port: params.port,
814
+ key: pending.key,
815
+ fingerprint: pending.fingerprint,
816
+ replace: params.replace,
817
+ });
818
+ this.pendingHostKeys?.delete(`${params.host.toLowerCase()}:${params.port}`);
819
+ return { ok: true };
820
+ }
821
+ catch (err) {
822
+ return { ok: false, error: err.message || String(err) };
823
+ }
824
+ }
786
825
  parseProbeOutput(raw) {
787
826
  const lines = raw.split(/\r?\n/).map((l) => l.trim());
788
827
  const sections = {};
@@ -1,5 +1,5 @@
1
1
  import { evaluateSandboxJail } from "./sandbox-service.js";
2
- const HOST_CAPABILITIES = new Set(["read", "write", "edit", "edit_soft", "patch", "present_files", "sandbox"]);
2
+ const HOST_CAPABILITIES = new Set(["read", "write", "edit", "patch", "present_files", "sandbox"]);
3
3
  export function createSandboxRuntimeGate(getSandbox, cwd) {
4
4
  const trusted = new Map();
5
5
  let session;
@@ -181,7 +181,6 @@ export function evaluateSandboxJail(sandbox, toolName, params, cwd, policy = {})
181
181
  case "read":
182
182
  case "write":
183
183
  case "edit":
184
- case "edit_soft":
185
184
  if (p.path !== undefined)
186
185
  paths.push(p.path);
187
186
  if (p.file_path !== undefined)
@@ -3,48 +3,39 @@ import { existsSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
4
  import { pick } from "./i18n.js";
5
5
  export const SANDBOX_TOOL_NAME = "sandbox";
6
+ const SANDBOX_ACTIONS = [
7
+ "list",
8
+ "create",
9
+ "diff",
10
+ "reset",
11
+ "persist",
12
+ "promote",
13
+ "apply_to_source",
14
+ "destroy",
15
+ ];
16
+ /** 每 action 要哪些参数,只在 `action` 字段里交代一次;字段本身不再写说明。 */
17
+ export const SANDBOX_ACTION_SIGNATURE = "list | create(mode?,sourcePath?,name?,ephemeral?,switchTo?) | diff/reset/persist/apply_to_source(sandbox?) | " +
18
+ "promote(targetPath,sandbox?,switchTo?) | destroy(sandbox?)";
6
19
  const SandboxParameters = Type.Object({
7
- action: Type.Union([
8
- Type.Literal("list"),
9
- Type.Literal("create"),
10
- Type.Literal("diff"),
11
- Type.Literal("reset"),
12
- Type.Literal("persist"),
13
- Type.Literal("promote"),
14
- Type.Literal("apply_to_source"),
15
- Type.Literal("destroy"),
16
- ], {
17
- description: "Operation to perform: list | create | diff | reset | persist | promote | apply_to_source | destroy.",
20
+ action: Type.Unsafe({
21
+ type: "string",
22
+ enum: [...SANDBOX_ACTIONS],
23
+ description: SANDBOX_ACTION_SIGNATURE,
18
24
  }),
19
- mode: Type.Optional(Type.Union([Type.Literal("blank"), Type.Literal("import")], {
20
- description: 'create: "import" clones an existing project into an isolated sandbox (default); "blank" creates an empty sandbox.',
21
- })),
22
- sourcePath: Type.Optional(Type.String({
23
- description: 'create (when mode="import"): source directory path to clone. Defaults to the current workspace (or its original sourcePath if already in a sandbox).',
24
- })),
25
- name: Type.Optional(Type.String({
26
- description: "create: optional display name for the sandbox.",
27
- })),
28
- ephemeral: Type.Optional(Type.Boolean({
29
- description: "create: true (default) for a temporary sandbox; false for a permanent sandbox.",
30
- })),
31
- switchTo: Type.Optional(Type.Boolean({
32
- description: "create/promote: true to switch the active workspace to the created/exported directory immediately; false (default for create) keeps the current workspace and returns the sandbox path (useful for spawning a subagent with cwd).",
33
- })),
34
- sandbox: Type.Optional(Type.String({
35
- description: "diff/reset/persist/promote/apply_to_source/destroy: target sandbox ID or path. Defaults to the current workspace if it is a sandbox.",
36
- })),
37
- targetPath: Type.Optional(Type.String({
38
- description: "promote: destination directory path outside sandboxes (must be a new or empty directory).",
39
- })),
25
+ mode: Type.Optional(Type.Unsafe({ type: "string", enum: ["blank", "import"] })),
26
+ sourcePath: Type.Optional(Type.String()),
27
+ name: Type.Optional(Type.String()),
28
+ ephemeral: Type.Optional(Type.Boolean()),
29
+ switchTo: Type.Optional(Type.Boolean()),
30
+ sandbox: Type.Optional(Type.String()),
31
+ targetPath: Type.Optional(Type.String()),
40
32
  });
41
33
  const MAX_DIFF_FILES_IN_DETAILS = 100;
42
34
  export function makeSandboxTool(host, getLang) {
43
35
  return {
44
36
  name: SANDBOX_TOOL_NAME,
45
37
  label: "Manage isolated sandbox workspaces",
46
- description: "Create, inspect, diff, reset, export, or destroy isolated copy-on-write sandbox workspaces. " +
47
- "Supports blank sandboxes or imported project copies (auto-skipping node_modules and build caches) where edits never touch the original files.",
38
+ description: "Manage isolated copy-on-write sandbox workspaces: blank or imported project copies where edits never touch the original files.",
48
39
  promptSnippet: "create or manage isolated sandbox workspaces for safe experimentation",
49
40
  promptGuidelines: [
50
41
  "Use sandbox(action='create') for risky refactors, dependency upgrades, or standalone prototypes so original project files remain untouched",
@@ -89,10 +89,8 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
89
89
  return defineTool({
90
90
  name: SCHEDULE_TOOL_NAME,
91
91
  label: "Manage scheduled tasks",
92
- description: "Create, list, or cancel persistent scheduled tasks. Without graphId, delivers a required prompt to the current conversation; " +
93
- "if unavailable, falls back to the project's active conversation or a headless run. With graphId, runs that existing canvas; " +
94
- "prompt is optional and otherwise uses the graph's input. Canvas tasks do not bind a conversation or override node models. " +
95
- "One-shot by default; recurring=true repeats. Minimum delay 60s.",
92
+ description: "Schedule persistent tasks that fire later or on a cron: a turn in this conversation, or a run of an existing canvas graph. " +
93
+ "Minimum delay 60s.",
96
94
  promptSnippet: "Create, list, or cancel conversation or canvas schedules",
97
95
  promptGuidelines: [
98
96
  "Use action=create for periodic checks, delayed reminders, and scheduled summaries — never sleep loops (they cannot push messages back)",
@@ -102,24 +100,16 @@ export function makeScheduleTool(host, ownerConversationId, lang) {
102
100
  action: Type.Unsafe({
103
101
  type: "string",
104
102
  enum: [...SCHEDULE_ACTIONS],
105
- description: "The schedule action to perform.",
103
+ description: "list | cancel(id) | create(schedule,prompt?,graphId?,label?,recurring?)",
106
104
  }),
107
105
  schedule: Type.Optional(Type.String({
108
- description: 'create: when to fire — 5-field cron ("0 * * * *" hourly) or relative delay ("in 30m", "in 1h", "30m"). Minimum 60s.',
106
+ description: 'create: 5-field cron ("0 * * * *") or relative delay ("in 30m"), minimum 60s',
109
107
  })),
110
- graphId: Type.Optional(Type.String({
111
- description: "create: existing canvas graph id; when provided, targets the canvas instead of a conversation.",
112
- })),
113
- prompt: Type.Optional(Type.String({
114
- description: "create: instruction for the conversation or canvas. Required for conversations; omit for canvas to use graph input. Max 8000 chars.",
115
- })),
116
- label: Type.Optional(Type.String({
117
- description: "create: short name shown in the background-tasks panel. Defaults to the prompt head.",
118
- })),
119
- recurring: Type.Optional(Type.Boolean({
120
- description: "create: repeat on schedule (default false = one-shot, auto-deleted after firing).",
121
- })),
122
- id: Type.Optional(Type.String({ description: "cancel: task id from action=list." })),
108
+ graphId: Type.Optional(Type.String()),
109
+ prompt: Type.Optional(Type.String()),
110
+ label: Type.Optional(Type.String()),
111
+ recurring: Type.Optional(Type.Boolean()),
112
+ id: Type.Optional(Type.String()),
123
113
  }),
124
114
  execute: async (_id, p, signal) => {
125
115
  signal?.throwIfAborted();
@@ -1,5 +1,6 @@
1
1
  import { isNotRepoError, scmCommitContext } from "./scm.js";
2
2
  import { pick } from "./i18n.js";
3
+ import { modelSessionId } from "./model-session.js";
3
4
  export const SCM_COMMITMSG_TIMEOUT_MS = 60_000;
4
5
  export const MAX_COMMITMSG_LEN = 200;
5
6
  const MAX_FILE_LINES = 200;
@@ -118,7 +119,7 @@ export async function generateScmCommitMessage(opts) {
118
119
  content: [{ type: "text", text: input }],
119
120
  },
120
121
  ],
121
- }, { signal: ac.signal, maxTokens: 400 });
122
+ }, { signal: ac.signal, maxTokens: 400, sessionId: modelSessionId() });
122
123
  }
123
124
  finally {
124
125
  clearTimeout(timer);
@@ -227,6 +227,9 @@ function serializeAssistantMessage(m, id, streaming = false) {
227
227
  role: "assistant",
228
228
  content: serializeAssistantContent(m.content, streaming),
229
229
  timestamp: m.timestamp,
230
+ ...(typeof m.durationMs === "number" && Number.isFinite(m.durationMs) && m.durationMs >= 0
231
+ ? { durationMs: Math.round(m.durationMs) }
232
+ : {}),
230
233
  model: m.model,
231
234
  provider: m.provider,
232
235
  usageCost: typeof m.usage?.cost?.total === "number" ? m.usage.cost.total : undefined,
@@ -320,6 +323,11 @@ export function serializeMessage(m, seq) {
320
323
  toolName: m.toolName,
321
324
  isError: m.isError,
322
325
  timestamp: m.timestamp,
326
+ ...(typeof m.durationMs === "number" &&
327
+ Number.isFinite(m.durationMs) &&
328
+ m.durationMs >= 0
329
+ ? { durationMs: Math.round(m.durationMs) }
330
+ : {}),
323
331
  };
324
332
  if (m.details !== undefined) {
325
333
  try {