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
@@ -3,10 +3,6 @@ import { ensureMarkersRegistered, parseMarkers, getMarker, allMarkers, collectGu
3
3
  import { loadStateFromBranch, appendSnapshot } from "./markers/store.js";
4
4
  import { ACTION_NAMESPACE, initActionState } from "./markers/builtins/action.js";
5
5
  ensureMarkersRegistered();
6
- const _DEFAULT_MARKERS = {
7
- markersEnabled: true,
8
- disabledMarkers: [],
9
- };
10
6
  export class MarkerService {
11
7
  host;
12
8
  settings;
@@ -14,29 +10,52 @@ export class MarkerService {
14
10
  overlayCache = new Map();
15
11
  constructor(host) {
16
12
  this.host = host;
17
- this.settings = this.host.stateStore.getMarkerSettings(this.host.clientId);
13
+ const loaded = this.host.stateStore.getMarkerSettings(this.host.clientId);
14
+ this.settings = { disabledMarkers: [...loaded.disabledMarkers] };
15
+ // 旧版有独立的「启用标记工具(全局)」开关:曾经全局关闭的用户迁移成「所有标记关闭」,
16
+ // 否则升级后标记会默默复活。写回后旧字段随 markers 整块覆盖消失。
17
+ if (this.host.stateStore.getLegacyMarkersGlobalOff?.() === true) {
18
+ this.setDisabledMarkers(this.visibleMarkerNames());
19
+ }
18
20
  }
19
21
  get current() {
20
- return { ...this.settings, disabledMarkers: [...this.settings.disabledMarkers] };
22
+ return { disabledMarkers: [...this.settings.disabledMarkers] };
21
23
  }
22
24
  get allMarkerNames() {
23
25
  return listMarkerNames();
24
26
  }
25
- isGlobalEnabled() {
26
- return this.settings.markersEnabled;
27
+ /** UI 可见(非别名)的标记名:全局开关只看这一组,别名跟随主标记。 */
28
+ visibleMarkerNames() {
29
+ const names = [];
30
+ for (const m of allMarkers()) {
31
+ if (m.isAlias || m.name === "suggest")
32
+ continue;
33
+ if (names.includes(m.name))
34
+ continue;
35
+ names.push(m.name);
36
+ }
37
+ return names;
27
38
  }
28
- isMarkerEnabled(name) {
29
- if (!this.settings.markersEnabled)
39
+ isNameEnabled(name) {
40
+ const disabled = this.settings.disabledMarkers;
41
+ if (disabled.includes(name))
30
42
  return false;
31
- if (name === "suggest" && this.settings.disabledMarkers.includes("action"))
43
+ if (name === "suggest" && disabled.includes("action"))
32
44
  return false;
33
- return !this.settings.disabledMarkers.includes(name);
45
+ return true;
46
+ }
47
+ /** 全局是否启用:没有独立开关,只要还剩任意一个标记开着就是启用;全关 = 全局关闭。 */
48
+ isGlobalEnabled() {
49
+ return this.visibleMarkerNames().some((name) => this.isNameEnabled(name));
50
+ }
51
+ isMarkerEnabled(name) {
52
+ return this.isNameEnabled(name) && this.isGlobalEnabled();
34
53
  }
35
54
  lang() {
36
55
  return this.host.lang?.() ?? "en";
37
56
  }
38
57
  buildGuidance() {
39
- if (!this.settings.markersEnabled)
58
+ if (!this.isGlobalEnabled())
40
59
  return "";
41
60
  const disabled = new Set(this.settings.disabledMarkers);
42
61
  const lines = collectGuidance(disabled, "en");
@@ -48,10 +67,14 @@ export class MarkerService {
48
67
  linesText +
49
68
  "\n──────────\n");
50
69
  }
51
- setEnabled(enabled) {
52
- this.settings.markersEnabled = !!enabled;
70
+ persist() {
53
71
  this.host.stateStore.saveMarkerSettings(this.host.clientId, this.settings);
54
72
  }
73
+ /** per-marker 开关的唯一写入口;全局状态由它派生,不再接受「全局开关」字段。 */
74
+ setDisabledMarkers(names) {
75
+ this.settings = { disabledMarkers: [...new Set(names)] };
76
+ this.persist();
77
+ }
55
78
  toggleMarker(name, enabled) {
56
79
  const set = new Set(this.settings.disabledMarkers);
57
80
  if (enabled) {
@@ -64,20 +87,7 @@ export class MarkerService {
64
87
  if (name === "action")
65
88
  set.add("suggest");
66
89
  }
67
- this.settings.disabledMarkers = [...set];
68
- this.host.stateStore.saveMarkerSettings(this.host.clientId, this.settings);
69
- }
70
- setAll(settings) {
71
- if (settings.markersEnabled !== undefined)
72
- this.settings.markersEnabled = !!settings.markersEnabled;
73
- if (settings.disabledMarkers !== undefined) {
74
- this.settings.disabledMarkers = [...new Set(settings.disabledMarkers)];
75
- }
76
- else {
77
- this.host.stateStore.saveMarkerSettings(this.host.clientId, this.settings);
78
- return;
79
- }
80
- this.host.stateStore.saveMarkerSettings(this.host.clientId, this.settings);
90
+ this.setDisabledMarkers([...set]);
81
91
  }
82
92
  memFor(convId, ns) {
83
93
  return this.memStore.get(convId)?.get(ns);
@@ -133,7 +143,7 @@ export class MarkerService {
133
143
  this.chains.delete(conversationId);
134
144
  }
135
145
  async processAssistantText(conversationId, text) {
136
- if (!text || !this.settings.markersEnabled)
146
+ if (!text || !this.isGlobalEnabled())
137
147
  return;
138
148
  const tokens = parseMarkers(text);
139
149
  if (tokens.length === 0)
@@ -219,6 +229,8 @@ export class MarkerService {
219
229
  }
220
230
  overlayLines(conversationId) {
221
231
  const lines = [];
232
+ if (!this.isGlobalEnabled())
233
+ return lines;
222
234
  for (const m of allMarkers()) {
223
235
  if (m.isAlias || m.name === "suggest")
224
236
  continue;
@@ -2,6 +2,7 @@ import { defineTool } from "@earendil-works/pi-coding-agent";
2
2
  import { Type } from "typebox";
3
3
  import { pick } from "./i18n.js";
4
4
  import { MCP_MANAGE_TOOL_NAME } from "./tool-manager.js";
5
+ export const MCP_MANAGE_ACTIONS = ["list", "check", "install", "remove", "reload"];
5
6
  function formatServerLine(s) {
6
7
  const target = s.url ? s.url : [s.command, ...(s.args ?? [])].filter(Boolean).join(" ");
7
8
  const toolNames = (s.tools ?? []).map((t) => t.name).join(", ");
@@ -18,7 +19,7 @@ export function makeMcpManageTool(host, lang) {
18
19
  return defineTool({
19
20
  name: MCP_MANAGE_TOOL_NAME,
20
21
  label: "Manage MCP servers",
21
- description: "Inspect, verify, install, remove, or reload Model Context Protocol (MCP) servers in project (.pi/mcp.json) or global (~/.pi/agent/mcp.json) config and sync their tools into the active session.",
22
+ description: "Manage Model Context Protocol servers in the project (.pi/mcp.json) or global (~/.pi/agent/mcp.json) config; install and reload sync their tools into this session.",
22
23
  promptSnippet: "check whether an MCP server is installed or install/configure one",
23
24
  promptGuidelines: [
24
25
  "Run mcp_manage with action='check' before installing an MCP server to avoid duplicate entries.",
@@ -26,54 +27,28 @@ export function makeMcpManageTool(host, lang) {
26
27
  "Prefer package shorthand (e.g. package='@modelcontextprotocol/server-filesystem') for npm-based stdio MCP servers.",
27
28
  ],
28
29
  parameters: Type.Object({
29
- action: Type.Union([
30
- Type.Literal("list"),
31
- Type.Literal("check"),
32
- Type.Literal("install"),
33
- Type.Literal("remove"),
34
- Type.Literal("reload"),
35
- ], {
36
- description: "Operation to perform: list, check, install, remove, or reload.",
30
+ action: Type.Unsafe({
31
+ type: "string",
32
+ enum: [...MCP_MANAGE_ACTIONS],
33
+ description: "list | check(query) | remove(name,scope?) | reload | " +
34
+ "install(name?,package?|command?|url?,args?,env?,cwd?,headers?,type?,scope?,overwrite?,description?)",
37
35
  }),
38
- query: Type.Optional(Type.String({
39
- description: "check: server name, npm package name, command, or URL substring to look up.",
40
- })),
41
- name: Type.Optional(Type.String({
42
- description: "install/remove: server identifier (letters, digits, underscore, hyphen). Auto-derived from package/url if omitted on install.",
43
- })),
44
- package: Type.Optional(Type.String({
45
- description: "install: npm package name shorthand (e.g. '@modelcontextprotocol/server-memory'); expands to npx -y <package>.",
46
- })),
47
- command: Type.Optional(Type.String({
48
- description: "install: executable for stdio MCP server (e.g. 'npx', 'uvx', 'node', 'python').",
49
- })),
50
- args: Type.Optional(Type.Array(Type.String(), {
51
- description: "install: command arguments (appended after package when package is set).",
52
- })),
53
- env: Type.Optional(Type.Record(Type.String(), Type.String(), {
54
- description: "install: environment variables passed to the stdio MCP server.",
55
- })),
56
- cwd: Type.Optional(Type.String({
57
- description: "install: working directory for the stdio MCP server.",
58
- })),
59
- url: Type.Optional(Type.String({
60
- description: "install: endpoint URL for http / streamable-http MCP server.",
61
- })),
62
- headers: Type.Optional(Type.Record(Type.String(), Type.String(), {
63
- description: "install: HTTP headers for remote MCP server.",
64
- })),
65
- type: Type.Optional(Type.Union([Type.Literal("stdio"), Type.Literal("http"), Type.Literal("streamable-http")], {
66
- description: "install: transport type (defaults to stdio, or streamable-http when url is given).",
67
- })),
68
- scope: Type.Optional(Type.Union([Type.Literal("project"), Type.Literal("global")], {
69
- description: "install/remove: config scope ('project' = .pi/mcp.json, 'global' = ~/.pi/agent/mcp.json).",
70
- })),
71
- overwrite: Type.Optional(Type.Boolean({
72
- description: "install: set true to replace an existing server with the same name (its command/args/env get overwritten).",
73
- })),
74
- description: Type.Optional(Type.String({
75
- description: "install: human-readable server note.",
36
+ query: Type.Optional(Type.String()),
37
+ name: Type.Optional(Type.String({ description: "Server id; install derives it from package/url" })),
38
+ package: Type.Optional(Type.String({ description: "npm package, expands to npx -y <package>" })),
39
+ command: Type.Optional(Type.String()),
40
+ args: Type.Optional(Type.Array(Type.String())),
41
+ env: Type.Optional(Type.Unsafe({ type: "object" })),
42
+ cwd: Type.Optional(Type.String()),
43
+ url: Type.Optional(Type.String()),
44
+ headers: Type.Optional(Type.Unsafe({ type: "object" })),
45
+ type: Type.Optional(Type.Unsafe({
46
+ type: "string",
47
+ enum: ["stdio", "http", "streamable-http"],
76
48
  })),
49
+ scope: Type.Optional(Type.Unsafe({ type: "string", enum: ["project", "global"] })),
50
+ overwrite: Type.Optional(Type.Boolean()),
51
+ description: Type.Optional(Type.String()),
77
52
  }),
78
53
  execute: async (_id, params) => {
79
54
  const L = getLang();
@@ -0,0 +1,16 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ /**
3
+ * Provider session id for calls that bypass `AgentSession`.
4
+ *
5
+ * The SDK only fills `options.sessionId` inside the agent loop; direct `ModelRuntime` callers
6
+ * must supply it themselves. Relay gateways (opencode / opencode-go) reject requests without the
7
+ * derived `x-opencode-session` routing header with `400 MissingSessionID`.
8
+ *
9
+ * Pass a stable seed for multi-turn conversations so follow-ups keep the same route and prompt
10
+ * cache; omit it for one-shot calls.
11
+ */
12
+ export function modelSessionId(seed) {
13
+ if (!seed)
14
+ return `pi-web-${randomUUID()}`;
15
+ return `pi-web-${createHash("sha256").update(seed).digest("hex").slice(0, 32)}`;
16
+ }
@@ -75,11 +75,12 @@ extract() {
75
75
  }
76
76
  }'
77
77
  }
78
- native=$(extract session_id)
78
+ native=$(extract conversationId)
79
+ [ -n "$native" ] || native=$(extract session_id)
79
80
  case "$native" in *[!a-fA-F0-9-]*) native= ;; esac
80
81
  case "$native" in ????????-????-????-????-????????????) ;; *) native= ;; esac
81
82
  case "$kind" in
82
- submitted) [ "$(extract hook_event_name)" = UserPromptSubmit ] || exit 0 ;;
83
+ submitted) [ "$(extract hook_event_name)" = UserPromptSubmit ] || [ -n "$(extract lastUserInput)" ] || [ -n "$(extract invocationNum)" ] || exit 0 ;;
83
84
  notification)
84
85
  notification=$(extract notification_type)
85
86
  case "$notification" in permission_prompt) kind=approval ;; elicitation_dialog) kind=question ;; *) exit 0 ;; esac ;;
@@ -212,7 +212,7 @@ export async function prepareNativeCliSessionLaunch(config, inputRef, ctx) {
212
212
  "--fork",
213
213
  "--no-session",
214
214
  ])
215
- : flag(optionArgs, ["--conversation", "--continue", "-c"]);
215
+ : flag(optionArgs, ["--conversation", "--resume", "-r", "--continue", "-c"]);
216
216
  const recoveredId = durableId ||
217
217
  [...oldEvents].reverse().find((event) => event.type === "session" && event.nativeId)?.nativeId ||
218
218
  [...oldEvents].reverse().find((event) => event.nativeId)?.nativeId;
@@ -228,7 +228,11 @@ export async function prepareNativeCliSessionLaunch(config, inputRef, ctx) {
228
228
  ref.nativeId = durableId;
229
229
  observedId = ref.nativeId;
230
230
  capabilities = {
231
- resume: config.preset === "custom" ? "none" : config.preset === "agy" || !ref.nativeId ? "explicit-only" : "exact",
231
+ resume: config.preset === "custom"
232
+ ? "none"
233
+ : config.preset === "agy" || config.preset === "dsh" || !ref.nativeId
234
+ ? "explicit-only"
235
+ : "exact",
232
236
  events: observationFailed ? "process" : "hooks",
233
237
  };
234
238
  acceptsEvents = true;
@@ -434,6 +438,27 @@ export async function prepareNativeCliSessionLaunch(config, inputRef, ctx) {
434
438
  capabilities.resume = "explicit-only";
435
439
  if (!explicit && ref.nativeId)
436
440
  launchOptions.push("--conversation", ref.nativeId);
441
+ if (!flag(optionArgs, ["--settings", "--disable-hooks", "--bare"])) {
442
+ const command = await reporter();
443
+ const hook = (type, matcher) => [
444
+ { ...(matcher ? { matcher } : {}), hooks: [{ type: "command", command: `${command} ${type}`, timeout: 5 }] },
445
+ ];
446
+ launchOptions.push("--settings", JSON.stringify({
447
+ hooks: {
448
+ SessionStart: hook("session"),
449
+ PreInvocation: hook("submitted"),
450
+ PreToolUse: hook("working", "*"),
451
+ Stop: hook("done"),
452
+ },
453
+ }));
454
+ capabilities.events = "hooks";
455
+ acceptsEvents = true;
456
+ }
457
+ }
458
+ else if (config.preset === "dsh") {
459
+ capabilities.resume = "explicit-only";
460
+ if (!explicit && ref.nativeId)
461
+ launchOptions.push("--resume", ref.nativeId);
437
462
  }
438
463
  if (!explicit)
439
464
  observedId = ref.nativeId;
@@ -23,14 +23,8 @@ Each file section starts with \`[path#TAG]\` (or \`[path]\` if the hash is unkno
23
23
  - Body rows under \`:\` headers MUST start with \`+\` (\`+\` alone = blank line). Divergence triggers a 3-way merge.
24
24
  Success returns the next anchor tag and live LSP diagnostics.`,
25
25
  parameters: Type.Object({
26
- patch: Type.String({
27
- description: "The complete Hashline patch text containing one or more [path#TAG] sections with PUT/CUT/REM/MV operations.",
28
- }),
29
- timeout: Type.Optional(Type.Number({
30
- minimum: 1,
31
- maximum: 300,
32
- description: "Optional execution timeout in seconds.",
33
- })),
26
+ patch: Type.String(),
27
+ timeout: Type.Optional(Type.Number({ description: "Seconds" })),
34
28
  }),
35
29
  async execute(_callId, params, _signal, _onUpdate, _ctx) {
36
30
  const L = getLang();
@@ -0,0 +1,167 @@
1
+ import { Type } from "typebox";
2
+ import { PHONE_TOOL_NAME } from "./tool-manager.js";
3
+ const PHONE_CALL_DEFAULT_TIMEOUT_MS = 20_000;
4
+ const PHONE_CALL_MIN_TIMEOUT_MS = 1_000;
5
+ const PHONE_CALL_MAX_TIMEOUT_MS = 60_000;
6
+ /** `op` 的枚举:schema 显式列出,运行时仍接受任意非空字符串(旧客户端兼容)。 */
7
+ export const PHONE_OPS = [
8
+ "status",
9
+ "dump",
10
+ "tap",
11
+ "long_press",
12
+ "swipe",
13
+ "input",
14
+ "key",
15
+ "launch",
16
+ "screenshot",
17
+ ];
18
+ export const PHONE_KEYS = ["back", "home", "recents", "notifications", "quickSettings"];
19
+ /** 每 op 的签名是参数文档的唯一归属地,字段本身不再写说明。 */
20
+ export const PHONE_OP_SIGNATURE = "status | dump(maxNodes?,maxDepth?) | tap(x,y) | long_press(x,y,durationMs?) | " +
21
+ "swipe(x1,y1,x2,y2,durationMs?) | input(text) | key(back|home|recents|notifications|quickSettings) | " +
22
+ "launch(packageName) | screenshot(maxWidth?)";
23
+ const PHONE_ARG_KEYS = [
24
+ "x",
25
+ "y",
26
+ "x1",
27
+ "y1",
28
+ "x2",
29
+ "y2",
30
+ "durationMs",
31
+ "text",
32
+ "packageName",
33
+ "maxWidth",
34
+ "maxNodes",
35
+ "maxDepth",
36
+ ];
37
+ export function collectPhoneArgs(params) {
38
+ const args = {};
39
+ for (const key of PHONE_ARG_KEYS) {
40
+ if (params[key] !== undefined)
41
+ args[key] = params[key];
42
+ }
43
+ return args;
44
+ }
45
+ export function normalizePhoneCallTimeoutMs(value) {
46
+ const n = typeof value === "number" && Number.isFinite(value) ? Math.floor(value) : PHONE_CALL_DEFAULT_TIMEOUT_MS;
47
+ return Math.min(PHONE_CALL_MAX_TIMEOUT_MS, Math.max(PHONE_CALL_MIN_TIMEOUT_MS, n));
48
+ }
49
+ export function formatPhoneCallResult(result) {
50
+ if (typeof result === "string")
51
+ return result.length > 0 ? result : "(empty)";
52
+ if (result === undefined || result === null)
53
+ return "(no result)";
54
+ try {
55
+ return JSON.stringify(result, null, 2) ?? String(result);
56
+ }
57
+ catch {
58
+ return String(result);
59
+ }
60
+ }
61
+ export function formatPhoneError(op, error) {
62
+ return [
63
+ `phone "${op}" failed: ${error}`,
64
+ `phone "${op}" 失败:${error}`,
65
+ 'Next: op:"status" tells you whether the phone has the accessibility service on. If it is off, ask the user to enable it in system settings instead of retrying.',
66
+ '下一步:op:"status" 能看出手机有没有开启无障碍服务;没开就请用户在系统设置里开启,不要反复重试。',
67
+ ].join("\n");
68
+ }
69
+ /** 客户端回来的截图统一成长这样(宿主桥把 base64 拼成 dataUrl)。 */
70
+ export function extractPhoneShot(result) {
71
+ if (!result || typeof result !== "object")
72
+ return undefined;
73
+ const image = result.image;
74
+ if (!image || typeof image !== "object")
75
+ return undefined;
76
+ const src = image;
77
+ if (typeof src.dataUrl !== "string")
78
+ return undefined;
79
+ const match = /^data:([^;,]+);base64,(.+)$/s.exec(src.dataUrl);
80
+ if (!match)
81
+ return undefined;
82
+ return {
83
+ data: match[2],
84
+ mimeType: match[1],
85
+ width: typeof src.width === "number" ? src.width : undefined,
86
+ height: typeof src.height === "number" ? src.height : undefined,
87
+ };
88
+ }
89
+ export function makePhoneTool(clientSession, ownerId) {
90
+ return {
91
+ name: PHONE_TOOL_NAME,
92
+ label: "Phone",
93
+ description: "Read the phone screen and drive it through the accessibility service.",
94
+ promptSnippet: "read and drive this Android phone: UI tree, tap, swipe, type, keys, shots",
95
+ promptGuidelines: [
96
+ "Use phone only when the user asked you to operate their phone; never tap, type or navigate their apps on your own initiative",
97
+ 'Start with op:"dump" and act on the returned nodes: bounds are screen pixels already, so tap the centre of a node instead of guessing coordinates. Take a screenshot when the tree is not enough.',
98
+ "Typing text goes to the focused input only. If the user must enter a password, payment or system setting, stop and ask them to do it themselves.",
99
+ "After each action, dump again to confirm the screen changed instead of firing several actions blindly.",
100
+ ],
101
+ parameters: Type.Object({
102
+ op: Type.Unsafe({
103
+ type: "string",
104
+ enum: [...PHONE_OPS],
105
+ description: PHONE_OP_SIGNATURE,
106
+ }),
107
+ x: Type.Optional(Type.Number()),
108
+ y: Type.Optional(Type.Number()),
109
+ x1: Type.Optional(Type.Number()),
110
+ y1: Type.Optional(Type.Number()),
111
+ x2: Type.Optional(Type.Number()),
112
+ y2: Type.Optional(Type.Number()),
113
+ durationMs: Type.Optional(Type.Number()),
114
+ text: Type.Optional(Type.String()),
115
+ packageName: Type.Optional(Type.String()),
116
+ maxWidth: Type.Optional(Type.Number()),
117
+ maxNodes: Type.Optional(Type.Number()),
118
+ maxDepth: Type.Optional(Type.Number()),
119
+ key: Type.Optional(Type.Unsafe({ type: "string", enum: [...PHONE_KEYS] })),
120
+ timeoutMs: Type.Optional(Type.Number()),
121
+ }),
122
+ execute: async (_id, params, signal) => {
123
+ const p = (params ?? {});
124
+ const op = typeof p.op === "string" ? p.op.trim() : "";
125
+ if (!op) {
126
+ throw new Error('phone requires a non-empty `op` (e.g. "dump", "tap").\nphone 需要非空的 op(如 dump/tap)。');
127
+ }
128
+ const args = collectPhoneArgs(p);
129
+ // key 是枚举,但放在 args 里过桥,保持一个入口。
130
+ if (typeof p.key === "string" && p.key.length > 0)
131
+ args.name = p.key;
132
+ const resolved = await clientSession.phoneCall({ op, args, timeoutMs: normalizePhoneCallTimeoutMs(p.timeoutMs) }, { aborted: signal?.aborted }, ownerId);
133
+ if (!resolved.ok)
134
+ throw new Error(formatPhoneError(op, resolved.error));
135
+ const shot = extractPhoneShot(resolved.result);
136
+ const details = {
137
+ op,
138
+ args,
139
+ result: shot ? { ...resolved.result, image: "[image]" } : resolved.result,
140
+ };
141
+ if (!shot) {
142
+ return { content: [{ type: "text", text: formatPhoneCallResult(resolved.result) }], details };
143
+ }
144
+ const caption = [
145
+ `Phone screenshot — ${shot.width ?? "?"}×${shot.height ?? "?"} px.`,
146
+ `手机截图 — ${shot.width ?? "?"}×${shot.height ?? "?"} px。`,
147
+ ].join("\n");
148
+ if (clientSession.canSeeImages?.() === true) {
149
+ return {
150
+ content: [
151
+ { type: "text", text: caption },
152
+ { type: "image", data: shot.data, mimeType: shot.mimeType },
153
+ ],
154
+ details,
155
+ };
156
+ }
157
+ const bridged = await clientSession.transcribeToolImage?.(shot, signal);
158
+ const note = bridged?.text
159
+ ? `\n\n<vision-bridge>\n${bridged.text}\n</vision-bridge>`
160
+ : [
161
+ `\n\n(当前模型看不到图片:${bridged?.reason ?? "视觉桥不可用"} —— 可改用 op:"dump" 走控件树,或换支持识图的模型)`,
162
+ `(The current model cannot see images: ${bridged?.reason ?? "vision bridge unavailable"} — use op:"dump" instead)`,
163
+ ].join("\n");
164
+ return { content: [{ type: "text", text: caption + note }], details };
165
+ },
166
+ };
167
+ }
@@ -5,7 +5,6 @@ const BLOCKED_TOOLS = new Set([
5
5
  "write_file",
6
6
  "edit",
7
7
  "edit_file",
8
- "edit_soft",
9
8
  "apply_patch",
10
9
  "patch",
11
10
  "patch_tool",
@@ -397,9 +396,11 @@ export function readOnlyToolCallAllowed(name, params) {
397
396
  "tool_search",
398
397
  "compact_context",
399
398
  "ask_user_question",
400
- "browser_search",
401
399
  ].includes(name))
402
400
  return true;
401
+ // 搜索已并入 browser_use(action="search");只读搜索在计划模式下仍然放行
402
+ if (name === "browser_use")
403
+ return String(p.action ?? "") === "search";
403
404
  const action = typeof p.action === "string" ? p.action : "";
404
405
  if (name === "skill")
405
406
  return !action || ["read", "list", "report"].includes(action);
@@ -430,6 +431,8 @@ export function readOnlyToolCallAllowed(name, params) {
430
431
  ].includes(action);
431
432
  if (name === "browser_page")
432
433
  return ["pages", "read", "shot"].includes(String(p.op));
434
+ if (name === "browser_script")
435
+ return ["list", "status"].includes(String(p.action));
433
436
  return false;
434
437
  }
435
438
  export function planModeDenial(toolName, params) {
@@ -440,8 +443,8 @@ export function planModeDenial(toolName, params) {
440
443
  if (!isReadOnlyConversationAction(act)) {
441
444
  return {
442
445
  kind: "bypass-tool",
443
- reason: `计划模式:不能调用 subagent(action="${act || "spawn"}")(它会在别的会话里执行,绕过本会话的只读约束)。请在本对话内用只读工具完成调研。`,
444
- reasonEn: `Plan mode: subagent(action="${act || "spawn"}") is unavailable (it runs outside this conversation and would bypass the read-only constraint). Research with read-only tools here.`,
446
+ reason: `计划模式:不能调用 conversation(action="${act || "spawn"}")(它会在别的会话里执行,绕过本会话的只读约束)。请在本对话内用只读工具完成调研。`,
447
+ reasonEn: `Plan mode: conversation(action="${act || "spawn"}") is unavailable (it runs outside this conversation and would bypass the read-only constraint). Research with read-only tools here.`,
445
448
  };
446
449
  }
447
450
  }
@@ -39,18 +39,15 @@ export function makePlanUpdateTool(planManager, getActiveConvTarget, emit, flush
39
39
  ],
40
40
  parameters: Type.Object({
41
41
  steps: Type.Array(Type.Object({
42
- id: Type.String({ description: "Unique step ID, e.g. '1', 'step-1'" }),
43
- title: Type.String({ description: "Short step title" }),
42
+ id: Type.String(),
43
+ title: Type.String(),
44
44
  status: Type.Optional(Type.Unsafe({
45
45
  type: "string",
46
46
  enum: ["pending", "in_progress", "done", "failed"],
47
- description: "Step status: pending | in_progress | done | failed (default: pending)",
48
47
  })),
49
- description: Type.Optional(Type.String({
50
- description: "Optional step detail: acceptance criteria, files touched, rollback note.",
51
- })),
52
- }), { description: "List of plan steps" }),
53
- activeStepId: Type.Optional(Type.String({ description: "ID of the step currently being executed" })),
48
+ description: Type.Optional(Type.String()),
49
+ })),
50
+ activeStepId: Type.Optional(Type.String()),
54
51
  }),
55
52
  execute: async (toolCallId, params) => {
56
53
  const target = getActiveConvTarget();
@@ -138,12 +138,24 @@ export const HOST_METHODS = [
138
138
  summary: "反向代理前缀(透传到 127.0.0.1:port,防 SSRF 锁回环)",
139
139
  example: `host.registerProxy("/app", 3000)`,
140
140
  },
141
+ {
142
+ name: "delivery",
143
+ needs: "chat",
144
+ summary: "出站投递:register 发送器 + send 入队;失败按错误类别退避重试、死信可观测",
145
+ example: `await host.delivery.send({ channel: "qq", target, payload, key })`,
146
+ },
141
147
  {
142
148
  name: "chat",
143
149
  needs: "chat",
144
150
  summary: "无头调用:把外部通道文本投给 agent(fire-and-forget)",
145
151
  example: `await host.chat({ text: "hi" })`,
146
152
  },
153
+ {
154
+ name: "inbox",
155
+ needs: "-",
156
+ summary: "本地投递账本:claim 幂等占位 / complete / fail / pending / dead(跨重启去重)",
157
+ example: `if (host.inbox.claim(eventId).status !== "new") return;`,
158
+ },
147
159
  {
148
160
  name: "chatWait",
149
161
  needs: "chat",
@@ -219,7 +231,7 @@ export const HOST_METHODS = [
219
231
  {
220
232
  name: "storage",
221
233
  needs: "-",
222
- summary: "插件私有 KV(storage.json,原子写,卸载即删)",
234
+ summary: "插件私有 KV(plugin-data/<id>/storage.json,原子写,卸载即删)",
223
235
  example: `host.storage.get("k")`,
224
236
  },
225
237
  { name: "secrets", needs: "-", summary: "加密 secrets(明文永不落盘/下发)", example: `host.secrets.get("token")` },