pi-web-ui 0.113.0 → 0.114.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/CHANGELOG.md +69 -1
  2. package/README.md +117 -252
  3. package/README.zh-CN.md +145 -223
  4. package/README.zh-TW.md +145 -223
  5. package/bin/device-hub-cli.mjs +577 -0
  6. package/bin/pi-device-hub.mjs +9 -0
  7. package/bin/pi-web-ui.mjs +145 -20
  8. package/dist/gh-comment-781.md +5 -0
  9. package/dist/server/agent-service-daemon.js +102 -24
  10. package/dist/server/agent-service.js +2296 -1121
  11. package/dist/server/approval-rules.js +29 -3
  12. package/dist/server/ask-user-question-tool.js +8 -8
  13. package/dist/server/atomic-file.js +35 -14
  14. package/dist/server/attachment-store.js +71 -35
  15. package/dist/server/attachments.js +18 -8
  16. package/dist/server/canvas/canvas-agent-tool.js +65 -15
  17. package/dist/server/canvas/canvas-dispatch.js +61 -20
  18. package/dist/server/canvas/canvas-orchestrator.js +516 -199
  19. package/dist/server/canvas/canvas-scheduler.js +99 -0
  20. package/dist/server/canvas/canvas-store.js +107 -54
  21. package/dist/server/canvas/canvas-validation.js +131 -0
  22. package/dist/server/canvas/canvas-workspace.js +284 -0
  23. package/dist/server/client-id-utils.js +8 -0
  24. package/dist/server/client-state.js +104 -22
  25. package/dist/server/communicate-tool.js +76 -0
  26. package/dist/server/compact-context-tool.js +2 -3
  27. package/dist/server/compaction-instructions.js +75 -0
  28. package/dist/server/compaction-markers.js +7 -2
  29. package/dist/server/compaction-state.js +84 -0
  30. package/dist/server/composer-drafts.js +43 -40
  31. package/dist/server/context-evidence.js +346 -0
  32. package/dist/server/control-socket.js +6 -2
  33. package/dist/server/conversation-communication.js +368 -0
  34. package/dist/server/conversation-read-tool.js +3 -4
  35. package/dist/server/conversation-tool-names.js +14 -0
  36. package/dist/server/conversation-tool.js +57 -0
  37. package/dist/server/delegate-mode.js +17 -4
  38. package/dist/server/device-center/bot-catalog.js +88 -0
  39. package/dist/server/device-center/bot-execution.js +106 -0
  40. package/dist/server/device-center/bots.js +170 -0
  41. package/dist/server/device-center/collab-service.js +153 -0
  42. package/dist/server/device-center/collab-tool.js +184 -0
  43. package/dist/server/device-center/connector.js +332 -0
  44. package/dist/server/device-center/desktop-linux.js +372 -0
  45. package/dist/server/device-center/desktop-native.js +413 -0
  46. package/dist/server/device-center/desktop-page.js +232 -0
  47. package/dist/server/device-center/desktop-setup.js +30 -0
  48. package/dist/server/device-center/desktop.js +387 -0
  49. package/dist/server/device-center/device-portals.js +241 -0
  50. package/dist/server/device-center/execution-failure.js +70 -0
  51. package/dist/server/device-center/executor.js +371 -0
  52. package/dist/server/device-center/file-sync.js +493 -0
  53. package/dist/server/device-center/hub-auth.js +69 -0
  54. package/dist/server/device-center/hub-page.js +68 -0
  55. package/dist/server/device-center/hub-setup.js +214 -0
  56. package/dist/server/device-center/hub.js +829 -0
  57. package/dist/server/device-center/local-page.js +17 -0
  58. package/dist/server/device-center/local.js +476 -0
  59. package/dist/server/device-center/main.js +118 -0
  60. package/dist/server/device-center/native-desktop/macos.js +192 -0
  61. package/dist/server/device-center/native-desktop/windows.js +118 -0
  62. package/dist/server/device-center/path-portal.js +120 -0
  63. package/dist/server/device-center/relay.js +959 -0
  64. package/dist/server/device-center/runtime.js +253 -0
  65. package/dist/server/device-center/smoke-preview.js +3 -0
  66. package/dist/server/device-center/store.js +122 -0
  67. package/dist/server/device-center/task-error.js +14 -0
  68. package/dist/server/device-center/transfers.js +293 -0
  69. package/dist/server/device-center/workspaces.js +45 -0
  70. package/dist/server/dispatch-domain-handlers.js +83 -27
  71. package/dist/server/dsh/dsh-agent-service.js +277 -158
  72. package/dist/server/dsh/dsh-client.js +12 -2
  73. package/dist/server/durable/durable-agent-service.js +1 -1
  74. package/dist/server/evidence-tool-hooks.js +49 -0
  75. package/dist/server/file-save.js +95 -0
  76. package/dist/server/file-transfer-routes.js +97 -47
  77. package/dist/server/files-service.js +110 -34
  78. package/dist/server/goal-review-gate.js +16 -6
  79. package/dist/server/goal-service.js +54 -30
  80. package/dist/server/http-proxy.js +120 -0
  81. package/dist/server/index.js +236 -232
  82. package/dist/server/load-timing.js +31 -0
  83. package/dist/server/mcp-bridge.js +219 -94
  84. package/dist/server/mcp-hot-reload.js +31 -5
  85. package/dist/server/mcp-manager.js +192 -93
  86. package/dist/server/mcp-oauth-login.js +169 -0
  87. package/dist/server/mcp-oauth-ui.js +137 -0
  88. package/dist/server/mcp-oauth.js +395 -0
  89. package/dist/server/mcp-project-runtime.js +207 -0
  90. package/dist/server/message-window.js +74 -21
  91. package/dist/server/net-guard.js +122 -20
  92. package/dist/server/payload-limits.js +17 -0
  93. package/dist/server/pending-question.js +82 -0
  94. package/dist/server/plan-mode.js +338 -137
  95. package/dist/server/plugin-assets.js +8 -4
  96. package/dist/server/plugin-chat-attachments.js +48 -0
  97. package/dist/server/plugin-facilities.js +67 -220
  98. package/dist/server/plugin-installer.js +2 -1
  99. package/dist/server/plugin-removal.js +49 -0
  100. package/dist/server/plugin-secrets.js +179 -0
  101. package/dist/server/plugins.js +262 -92
  102. package/dist/server/preset-fields.js +49 -0
  103. package/dist/server/preset-plugin-dependencies.js +57 -0
  104. package/dist/server/preset-share.js +112 -72
  105. package/dist/server/protocol-version.js +1 -1
  106. package/dist/server/queue-modes.js +10 -0
  107. package/dist/server/remote-ssh-service.js +160 -67
  108. package/dist/server/request-context.js +164 -0
  109. package/dist/server/sandbox-data.js +655 -0
  110. package/dist/server/sandbox-engines.js +7 -0
  111. package/dist/server/sandbox-runtime-gate.js +41 -0
  112. package/dist/server/sandbox-service.js +139 -698
  113. package/dist/server/sandbox-tool.js +21 -4
  114. package/dist/server/scheduler-tasks.js +63 -48
  115. package/dist/server/serialize.js +48 -19
  116. package/dist/server/session-branch.js +25 -3
  117. package/dist/server/session-parser.js +28 -18
  118. package/dist/server/session-scan.js +130 -0
  119. package/dist/server/session-search.js +51 -37
  120. package/dist/server/settings-service.js +267 -111
  121. package/dist/server/setup-config.js +58 -0
  122. package/dist/server/skill-maintenance.js +112 -24
  123. package/dist/server/subagent-helpers.js +4 -1
  124. package/dist/server/subagent-notify.js +4 -1
  125. package/dist/server/subagent-security-gate.js +52 -11
  126. package/dist/server/subagent-task.js +27 -0
  127. package/dist/server/subagents.js +217 -46
  128. package/dist/server/tabs.js +9 -1
  129. package/dist/server/terminals.js +467 -363
  130. package/dist/server/tool-guards.js +42 -6
  131. package/dist/server/tool-manager.js +47 -20
  132. package/dist/server/tool-overrides.js +13 -11
  133. package/dist/server/tool-prompt-overrides.js +32 -2
  134. package/dist/server/tool-prompts.js +1 -1
  135. package/dist/server/turn-timing.js +11 -0
  136. package/dist/server/universal/session-store.js +48 -6
  137. package/dist/server/universal/universal-service.js +1 -1
  138. package/dist/server/universal/universal-session.js +334 -231
  139. package/dist/server/uploads.js +64 -5
  140. package/dist/server/webui-context.js +6 -6
  141. package/dist/server/worktree-service.js +32 -24
  142. package/dist/server/ws-pending-queue.js +73 -27
  143. package/dist/test-artifact.md +9 -0
  144. package/dist/test-preview-modal.md +11 -0
  145. package/dist/test-report.html +20 -0
  146. package/docs/device-center.md +142 -0
  147. package/docs/device-desktop.md +48 -0
  148. package/package.json +4 -1
  149. package/plugin-sdk/index.d.ts +45 -9
  150. package/plugin-sdk/ssh-host-trust.mjs +225 -0
  151. package/plugins/catalog.json +1 -1
  152. package/themes/aetheris.css +1 -107
  153. package/themes/ayu-light.css +5 -29
  154. package/themes/bases/flow-base.css +0 -6
  155. package/themes/bases/statusbar-flat-base.css +112 -0
  156. package/themes/bases/zhujian-base.css +1 -0
  157. package/themes/bases/zhupi-base.css +1 -0
  158. package/themes/catppuccin-latte.css +4 -27
  159. package/themes/catppuccin.css +4 -35
  160. package/themes/claude-code-dark.css +1 -0
  161. package/themes/codex.css +4 -28
  162. package/themes/cyberpunk.css +3 -61
  163. package/themes/dark-teal.css +0 -1
  164. package/themes/dazzle.css +3 -73
  165. package/themes/everforest-light.css +4 -27
  166. package/themes/geist.css +4 -28
  167. package/themes/gruvbox-light.css +4 -27
  168. package/themes/kanagawa-lotus.css +4 -27
  169. package/themes/md-preview.css +3 -213
  170. package/themes/mist.css +4 -24
  171. package/themes/nord.css +4 -35
  172. package/themes/one-dark.css +4 -37
  173. package/themes/paper.css +4 -16
  174. package/themes/rose-pine-dawn.css +4 -28
  175. package/themes/sakura.css +4 -24
  176. package/themes/solarized-light.css +4 -27
  177. package/themes/tokyo-night.css +3 -34
  178. package/themes/white.css +4 -26
  179. package/themes/zhujian-dark.css +1 -0
  180. package/themes/zhupi-dark.css +1 -0
  181. package/web/dist/.build-assets.json +1 -0
  182. package/web/dist/assets/BgTasksModal-CS7UNzcw.js +1 -0
  183. package/web/dist/assets/BgTasksModal-Dk-tp78W.js +1 -0
  184. package/web/dist/assets/CanvasStudio-BEJZE5BI.js +1579 -0
  185. package/web/dist/assets/CanvasStudio-CgUNHqos.js +1579 -0
  186. package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +3 -0
  187. package/web/dist/assets/DeviceCenter-CVblvhNX.js +3 -0
  188. package/web/dist/assets/Dropdown-Oug0DDte.js +1 -0
  189. package/web/dist/assets/FilePreview-CvdX6nr6.js +2 -0
  190. package/web/dist/assets/FilePreview-kCZhfBAF.js +2 -0
  191. package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +1 -0
  192. package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +1 -0
  193. package/web/dist/assets/GroupConversation-Cgo4xbpa.js +1 -0
  194. package/web/dist/assets/GroupConversation-DZ71jEi8.js +1 -0
  195. package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +2 -0
  196. package/web/dist/assets/PiSetupModal-mkWPSxMj.js +1 -0
  197. package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +1 -0
  198. package/web/dist/assets/SCMPanel-BP1TUT-V.js +2 -0
  199. package/web/dist/assets/SCMPanel-BscPm9kf.js +2 -0
  200. package/web/dist/assets/SettingsModal-C8UgMjVM.js +20 -0
  201. package/web/dist/assets/SettingsModal-VynB7jNb.js +20 -0
  202. package/web/dist/assets/TerminalPanel-D6cPRFei.js +3 -0
  203. package/web/dist/assets/TerminalPanel-DL20uKgU.js +3 -0
  204. package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +1 -0
  205. package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +1 -0
  206. package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +1 -0
  207. package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +1 -0
  208. package/web/dist/assets/app-globals-CnO6KlEM.js +325 -0
  209. package/web/dist/assets/desktop-DPyTy4M3.js +1 -0
  210. package/web/dist/assets/es-DWMIuDU2.js +2 -0
  211. package/web/dist/assets/index-CPgAH5q7.js +83 -0
  212. package/web/dist/assets/index-Cje8iugL.js +83 -0
  213. package/web/dist/assets/index-DnKeiDbj.css +1 -0
  214. package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
  215. package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
  216. package/web/dist/assets/math-1uRJCsA9.js +257 -0
  217. package/web/dist/assets/math-BorAY7qD.css +1 -0
  218. package/web/dist/assets/plugin-host-CqA4yW6w.js +1 -0
  219. package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
  220. package/web/dist/assets/theme-BqdAjEjF.js +1 -0
  221. package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
  222. package/web/dist/index.html +15 -9
  223. package/web/dist/sw.js +1 -1
  224. package/web/dist/assets/TerminalPanel-3wojLfLk.js +0 -3
  225. package/web/dist/assets/index-A8YXwnpZ.js +0 -2008
  226. package/web/dist/assets/index-BwL7qBh6.css +0 -1
  227. package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
  228. package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
@@ -84,7 +84,10 @@ const TERMINAL_WRITE_TOOLS = new Set(["terminal_input", "terminal_key"]);
84
84
  * 的判定函数);schedule(create/list/cancel)则整工具拒——调度面在计划/审查
85
85
  * 回合都不需要,宁可保守。
86
86
  */
87
- export const SESSION_DISPATCH_TOOLS = new Set(["delegate_task", "schedule"]);
87
+ import { isReadOnlyConversationAction, CONVERSATION_TOOL_NAMES, isConversationTool, } from "./conversation-tool-names.js";
88
+ // Every communication action can carry instructions, including replies and escalations.
89
+ // Plan/delegate/goal reviewers must not direct execution through another conversation.
90
+ export const SESSION_DISPATCH_TOOLS = new Set(["delegate_task", "schedule", "communicate"]);
88
91
  /**
89
92
  * 计划模式下也禁掉的「旁路工具」(真实派发类,见 SESSION_DISPATCH_TOOLS):
90
93
  * 它们能在**别的会话**里干活,而闸门是会话级的 —— 子代理/排程对话的
@@ -97,86 +100,12 @@ export const PLAN_MODE_BLOCKED_TOOL_NAMES = new Set([
97
100
  ...BLOCKED_TOOLS,
98
101
  ...BYPASS_TOOLS,
99
102
  ...TERMINAL_WRITE_TOOLS,
100
- "subagent",
103
+ ...CONVERSATION_TOOL_NAMES,
101
104
  ]);
102
105
  /** bash 类工具名(terminalBash 开关分流后可能是这几个)。 */
103
- const BASH_TOOLS = new Set(["bash", "bash_execute", "run_command", "shell", "terminal", "terminal_exec"]);
104
- /** 计划模式放行的只读命令(basename,无参数)。刻意保守:宁可拒一次让模型换命令。 */
105
- const READ_ONLY_COMMANDS = new Set([
106
- // 目录 / 文件查看
107
- "ls",
108
- "ll",
109
- "pwd",
110
- "cat",
111
- "bat",
112
- "head",
113
- "tail",
114
- "wc",
115
- "file",
116
- "stat",
117
- "du",
118
- "df",
119
- "tree",
120
- "find",
121
- "fd",
122
- "realpath",
123
- "readlink",
124
- "basename",
125
- "dirname",
126
- "which",
127
- "type",
128
- // 检索与文本处理(只读变体;sed 的 -i 在段内另行拒绝)
129
- "grep",
130
- "egrep",
131
- "fgrep",
132
- "rg",
133
- "ag",
134
- "ack",
135
- "sed",
136
- "awk",
137
- "cut",
138
- "tr",
139
- "sort",
140
- "uniq",
141
- "jq",
142
- "yq",
143
- "diff",
144
- "cmp",
145
- // 环境 / 版本
146
- "env",
147
- "printenv",
148
- "date",
149
- "uname",
150
- "whoami",
151
- "node",
152
- "npm",
153
- "python",
154
- "python3",
155
- // 校验和(只读)
156
- "md5sum",
157
- "sha256sum",
158
- ]);
159
- /** git 的只读子命令(写子命令一律禁)。 */
160
- const READ_ONLY_GIT_SUBCOMMANDS = new Set([
161
- "status",
162
- "diff",
163
- "log",
164
- "show",
165
- "blame",
166
- "rev-parse",
167
- "rev-list",
168
- "ls-files",
169
- "ls-tree",
170
- "describe",
171
- "shortlog",
172
- "grep",
173
- "cat-file",
174
- "whatchanged",
175
- ]);
176
- /** 解释器的「只读例外」:只有这些参数组合放行,其余(-e/--eval/run script/子命令)拒。 */
177
- const INTERPRETER_SAFE_ARGS = new Set(["--version", "-v", "-V", "--help", "-h", "--revision"]);
178
- /** 段内出现即判写:重定向、命令替换、后台、heredoc。 */
179
- const WRITE_SHELL_TOKENS = /[><`]|&\s*$/;
106
+ const BASH_TOOLS = new Set(["bash", "bash_execute", "run_command", "shell", "terminal_exec"]);
107
+ /** Reject expansion/escaping even inside quotes: unsupported syntax fails closed. */
108
+ const UNSUPPORTED_SHELL = /[$`\\<>\x00-\x08\x0b-\x1f\x7f]/;
180
109
  /** 引号感知的命令切分:把一条命令按 ; && || | 换行 拆成独立段。 */
181
110
  function splitShellSegments(cmd) {
182
111
  const out = [];
@@ -195,8 +124,9 @@ function splitShellSegments(cmd) {
195
124
  cur += ch;
196
125
  continue;
197
126
  }
198
- // 命令替换 $( … ) 一律视为写(能跑任意代码),整条拒。
199
- if (ch === "$" && cmd[i + 1] === "(")
127
+ // Globbing can inject option-like filenames (e.g. --pre=...). Use quoted patterns
128
+ // with structured search tools instead. All unsupported expansions fail closed.
129
+ if (/[(){}~#*?[\]]/.test(ch))
200
130
  return [""];
201
131
  if (ch === ";" || ch === "\n") {
202
132
  out.push(cur);
@@ -214,80 +144,273 @@ function splitShellSegments(cmd) {
214
144
  cur = "";
215
145
  continue;
216
146
  }
147
+ if (ch === "&")
148
+ return [""];
217
149
  cur += ch;
218
150
  }
151
+ if (quote)
152
+ return [""];
219
153
  out.push(cur);
220
- return out.map((s) => s.trim()).filter((s) => s !== "");
154
+ return out.map((s) => s.trim());
221
155
  }
222
- /** 取一段里的命令 token:跳过 `FOO=bar` 前缀、`/usr/bin/env`、路径前缀。 */
223
- function commandToken(segment) {
224
- const tokens = segment.split(/\s+/);
225
- let i = 0;
226
- while (i < tokens.length) {
227
- const tok = tokens[i];
228
- if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(tok)) {
229
- i++;
156
+ function readOnlyArgs(args, spec) {
157
+ for (let i = 0; i < args.length; i++) {
158
+ const arg = args[i];
159
+ if (arg === "--")
160
+ return true;
161
+ if (!arg.startsWith("-") || arg === "-")
162
+ continue;
163
+ if (spec.flags?.includes(arg))
164
+ continue;
165
+ const eq = arg.indexOf("=");
166
+ if (arg.startsWith("--")) {
167
+ const option = eq < 0 ? arg : arg.slice(0, eq);
168
+ if (!spec.values?.includes(option))
169
+ return false;
170
+ if (eq < 0 && (args[++i] === undefined || args[i].startsWith("-")))
171
+ return false;
230
172
  continue;
231
173
  }
232
- if (tok === "env" || tok === "command" || tok === "nohup" || tok === "time") {
233
- i++;
174
+ if (spec.numeric && /^-\d+$/.test(arg))
234
175
  continue;
176
+ for (let j = 1; j < arg.length; j++) {
177
+ const flag = arg[j];
178
+ if (spec.shortValues?.includes(flag)) {
179
+ if (j === arg.length - 1 && (args[++i] === undefined || args[i].startsWith("-")))
180
+ return false;
181
+ break;
182
+ }
183
+ if (!spec.short?.includes(flag))
184
+ return false;
235
185
  }
236
- return tok;
237
186
  }
238
- return "";
239
- }
240
- function basenameOf(token) {
241
- const idx = token.lastIndexOf("/");
242
- return idx >= 0 ? token.slice(idx + 1) : token;
187
+ return true;
243
188
  }
244
- /** 单段是否只读(不含管道/重定向/命令替换,命令在白名单内)。 */
189
+ const READ_ONLY_OPTIONS = {
190
+ ls: { short: "aAlhRtdrS1Fipn", flags: ["--all", "--almost-all", "--human-readable"] },
191
+ pwd: { short: "LP" },
192
+ cat: { short: "nbsETAv" },
193
+ head: { short: "qv", shortValues: "nc", numeric: true },
194
+ tail: { short: "qv", shortValues: "nc", numeric: true },
195
+ wc: { short: "clmwL", flags: ["--bytes", "--lines", "--words", "--chars"] },
196
+ stat: { short: "Lf", shortValues: "c", values: ["--format"] },
197
+ du: { short: "ahskm", values: ["--max-depth"] },
198
+ df: { short: "hkiPT" },
199
+ realpath: { short: "emqs" },
200
+ readlink: { short: "femqns" },
201
+ basename: { short: "a", shortValues: "s" },
202
+ dirname: {},
203
+ uname: { short: "asnrvmpio" },
204
+ whoami: {},
205
+ printenv: {},
206
+ md5sum: { short: "bct", flags: ["--check"] },
207
+ sha256sum: { short: "bct", flags: ["--check"] },
208
+ grep: {
209
+ short: "EFGPivwnrlLchsoqRH",
210
+ shortValues: "efABCm",
211
+ numeric: true,
212
+ flags: ["--line-number", "--recursive", "--ignore-case", "--fixed-strings"],
213
+ },
214
+ rg: {
215
+ short: "nNliwsvqocUFHL",
216
+ shortValues: "egtfmABC",
217
+ flags: [
218
+ "--files",
219
+ "--hidden",
220
+ "--no-ignore",
221
+ "--no-heading",
222
+ "--heading",
223
+ "--line-number",
224
+ "--count",
225
+ "--fixed-strings",
226
+ "--ignore-case",
227
+ "--files-with-matches",
228
+ "--files-without-match",
229
+ "--stats",
230
+ "--json",
231
+ ],
232
+ values: [
233
+ "--glob",
234
+ "--type",
235
+ "--max-count",
236
+ "--max-depth",
237
+ "--context",
238
+ "--before-context",
239
+ "--after-context",
240
+ "--regexp",
241
+ "--file",
242
+ ],
243
+ },
244
+ fd: {
245
+ short: "HILais0",
246
+ shortValues: "etEd",
247
+ flags: ["--hidden", "--no-ignore", "--absolute-path", "--full-path"],
248
+ values: ["--extension", "--type", "--exclude", "--max-depth"],
249
+ },
250
+ cut: { short: "sn", shortValues: "bcfd", values: ["--bytes", "--characters", "--fields", "--delimiter"] },
251
+ };
252
+ const GIT_OPTIONS = {
253
+ status: {
254
+ short: "sbz",
255
+ flags: [
256
+ "--short",
257
+ "--branch",
258
+ "--porcelain",
259
+ "--porcelain=v1",
260
+ "--porcelain=v2",
261
+ "--untracked-files=no",
262
+ "--untracked-files=all",
263
+ ],
264
+ },
265
+ diff: {
266
+ short: "pwb",
267
+ shortValues: "U",
268
+ flags: [
269
+ "--stat",
270
+ "--numstat",
271
+ "--shortstat",
272
+ "--name-only",
273
+ "--name-status",
274
+ "--cached",
275
+ "--staged",
276
+ "--check",
277
+ "--no-ext-diff",
278
+ "--no-textconv",
279
+ "--no-color",
280
+ "--color=never",
281
+ "--no-renames",
282
+ ],
283
+ },
284
+ log: {
285
+ short: "p",
286
+ shortValues: "n",
287
+ numeric: true,
288
+ flags: [
289
+ "--oneline",
290
+ "--stat",
291
+ "--name-only",
292
+ "--name-status",
293
+ "--all",
294
+ "--graph",
295
+ "--decorate",
296
+ "--no-decorate",
297
+ "--no-color",
298
+ "--no-show-signature",
299
+ ],
300
+ values: ["--max-count", "--since", "--until", "--author", "--grep", "--format", "--pretty"],
301
+ },
302
+ show: {
303
+ short: "ps",
304
+ flags: ["--stat", "--name-only", "--name-status", "--oneline", "--no-ext-diff", "--no-textconv", "--no-color"],
305
+ values: ["--format", "--pretty"],
306
+ },
307
+ blame: { short: "w", shortValues: "L", flags: ["--line-porcelain", "--porcelain"] },
308
+ "rev-parse": {
309
+ flags: [
310
+ "--show-toplevel",
311
+ "--show-prefix",
312
+ "--git-dir",
313
+ "--short",
314
+ "--verify",
315
+ "--abbrev-ref",
316
+ "--is-inside-work-tree",
317
+ ],
318
+ },
319
+ "rev-list": { shortValues: "n", numeric: true, flags: ["--count", "--all"], values: ["--max-count"] },
320
+ "ls-files": { short: "zcmot", flags: ["--cached", "--modified", "--others", "--exclude-standard", "--stage"] },
321
+ "ls-tree": { short: "rdtz", flags: ["--name-only", "--name-status", "--full-tree"] },
322
+ describe: { flags: ["--tags", "--always", "--long", "--dirty"] },
323
+ "cat-file": { short: "ptse" },
324
+ grep: READ_ONLY_OPTIONS.grep,
325
+ };
326
+ /** No assignment prefixes, command wrappers, arbitrary programs or executable paths. */
245
327
  function segmentIsReadOnly(segment) {
246
- if (WRITE_SHELL_TOKENS.test(segment))
247
- return false;
248
- // `>` 重定向在别处已覆盖;这里补 `2>&1` 之外的 fd 复制与 `<<<`/`2>`。
249
- if (/<<|&\s*\d|\d\s*>/.test(segment))
328
+ const words = [];
329
+ let word = "";
330
+ let quote = "";
331
+ let started = false;
332
+ for (const ch of segment) {
333
+ if (quote) {
334
+ if (ch === quote)
335
+ quote = "";
336
+ else
337
+ word += ch;
338
+ }
339
+ else if (ch === "'" || ch === '"') {
340
+ quote = ch;
341
+ started = true;
342
+ }
343
+ else if (/\s/.test(ch)) {
344
+ if (started)
345
+ words.push(word);
346
+ word = "";
347
+ started = false;
348
+ }
349
+ else {
350
+ word += ch;
351
+ started = true;
352
+ }
353
+ }
354
+ if (quote)
250
355
  return false;
251
- const cmd = commandToken(segment);
252
- if (!cmd)
356
+ if (started)
357
+ words.push(word);
358
+ const [name, ...args] = words;
359
+ if (!name || !/^[a-z][a-z0-9-]*$/.test(name))
253
360
  return false;
254
- const name = basenameOf(cmd);
255
- const rest = segment.slice(segment.indexOf(cmd) + cmd.length).trim();
256
- const args = rest.split(/\s+/).filter(Boolean);
361
+ if (["node", "npm", "python", "python3"].includes(name)) {
362
+ const versionFlag = name === "python" || name === "python3" ? "-V" : "-v";
363
+ return args.length === 1 && ["--version", versionFlag, "--help", "-h"].includes(args[0]);
364
+ }
257
365
  if (name === "git") {
258
- const sub = args.find((a) => !a.startsWith("-"));
259
- return sub !== undefined && READ_ONLY_GIT_SUBCOMMANDS.has(sub);
366
+ if (args[0] === "--no-pager")
367
+ args.shift();
368
+ const sub = args.shift() ?? "";
369
+ return Object.hasOwn(GIT_OPTIONS, sub) && readOnlyArgs(args, GIT_OPTIONS[sub]);
260
370
  }
261
- if (!READ_ONLY_COMMANDS.has(name))
262
- return false;
263
- // sed -i / awk 的 system() 之类写路径。
264
- if (name === "sed" && args.some((a) => /^-[a-z]*i/.test(a) || a === "--in-place"))
265
- return false;
266
- if (name === "awk" && /system\s*\(/.test(rest))
267
- return false;
268
- // find 的 -exec/-delete/-fprintf 族有写副作用(issue #483):白名单命中不等于只读,
269
- // `find . -name '*.log' -delete` / `-exec touch x {} +` 无任何重定向特征,必须显式拒。
270
- if (name === "find" && args.some((a) => /^-(exec|execdir|ok|okdir|delete|fprint0|fprint|fprintf|fls)$/.test(a)))
271
- return false;
272
- // 解释器:只放行 --version/--help 这类无副作用调用。
273
- if (name === "node" || name === "python" || name === "python3" || name === "npm") {
274
- return args.length > 0 && args.every((a) => INTERPRETER_SAFE_ARGS.has(a));
371
+ if (name === "jq") {
372
+ // Accept field/index projections, not arbitrary programs or module loading.
373
+ if (args[0] === "-r" || args[0] === "-c")
374
+ args.shift();
375
+ return (args.length > 0 &&
376
+ /^\.(?:[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*|\[\d*\])*)?$/.test(args[0]) &&
377
+ args.slice(1).every((a) => !a.startsWith("-")));
275
378
  }
276
- return true;
379
+ if (name === "find") {
380
+ let i = 0;
381
+ while (i < args.length && !args[i].startsWith("-"))
382
+ i++;
383
+ while (i < args.length) {
384
+ const arg = args[i++];
385
+ if (["-print", "-print0", "-a", "-o"].includes(arg))
386
+ continue;
387
+ if (!["-name", "-iname", "-path", "-type", "-maxdepth", "-mindepth", "-newer", "-mtime", "-size"].includes(arg))
388
+ return false;
389
+ if (args[i] === undefined || args[i++].startsWith("-"))
390
+ return false;
391
+ }
392
+ return true;
393
+ }
394
+ return Object.hasOwn(READ_ONLY_OPTIONS, name) && readOnlyArgs(args, READ_ONLY_OPTIONS[name]);
277
395
  }
278
396
  /**
279
- * bash 命令是否只读(纯函数)。规则:按 `;` `&&` `||` `|` 切段,**每段**都要
280
- * 只读;段内禁重定向 / 命令替换 / 后台 / heredoc;命令在白名单内,
281
- * git 只放只读子命令,解释器只放行 --version/--help。
397
+ * Accept only the supported foreground shell grammar and per-command option allowlists.
398
+ * This is a capability filter, not an OS sandbox: executable resolution and inherited
399
+ * environment/configuration must be trusted by the execution layer.
282
400
  */
283
401
  export function bashCommandIsReadOnly(cmd) {
284
402
  const text = (cmd ?? "").trim();
285
- if (!text)
403
+ if (!bashCommandHasSupportedSyntax(text))
286
404
  return false;
287
- const segments = splitShellSegments(text);
288
- if (segments.length === 0)
405
+ return splitShellSegments(text).every(segmentIsReadOnly);
406
+ }
407
+ /** Shared syntax boundary for readonly commands and the explicit test-runner exception. */
408
+ export function bashCommandHasSupportedSyntax(cmd) {
409
+ const text = (cmd ?? "").trim();
410
+ if (!text || UNSUPPORTED_SHELL.test(text))
289
411
  return false;
290
- return segments.every(segmentIsReadOnly);
412
+ const segments = splitShellSegments(text);
413
+ return segments.length > 0 && segments.every((segment) => segment.length > 0);
291
414
  }
292
415
  /** 从工具参数里取命令文本(各工具字段名不同)。 */
293
416
  function commandOf(params) {
@@ -301,6 +424,86 @@ function commandOf(params) {
301
424
  }
302
425
  return "";
303
426
  }
427
+ /** Narrow the existing action enum without changing execution or other parameters. */
428
+ export function restrictTerminalToolToReadOnly(tool) {
429
+ const parameters = tool.parameters;
430
+ return {
431
+ ...tool,
432
+ parameters: {
433
+ ...parameters,
434
+ properties: {
435
+ ...parameters.properties,
436
+ action: { type: "string", enum: ["list", "read", "wait"] },
437
+ },
438
+ },
439
+ };
440
+ }
441
+ const terminalSchemas = new WeakMap();
442
+ /** Call after registry refresh and before setActiveToolsByName; false restores the full schema. */
443
+ export function syncTerminalReadOnlySchema(session, readOnly) {
444
+ const tool = session._toolRegistry?.get("terminal");
445
+ if (!tool)
446
+ return;
447
+ if (!terminalSchemas.has(tool))
448
+ terminalSchemas.set(tool, tool.parameters);
449
+ const parameters = terminalSchemas.get(tool);
450
+ tool.parameters = readOnly ? restrictTerminalToolToReadOnly({ parameters }).parameters : parameters;
451
+ }
452
+ /** Structured queries are preferred to shell; unknown tools/actions fail closed. */
453
+ export function readOnlyToolCallAllowed(name, params) {
454
+ const p = params && typeof params === "object" ? params : {};
455
+ if (name === "terminal")
456
+ return ["list", "read", "wait"].includes(String(p.action ?? ""));
457
+ if ([
458
+ "read",
459
+ "grep",
460
+ "find",
461
+ "ls",
462
+ "obs_recall",
463
+ "present_files",
464
+ "conversation_read",
465
+ "terminal_read",
466
+ "terminal_list",
467
+ "terminal_wait",
468
+ "load_tools",
469
+ "tool_search",
470
+ "compact_context",
471
+ "ask_user_question",
472
+ "browser_search",
473
+ ].includes(name))
474
+ return true;
475
+ const action = typeof p.action === "string" ? p.action : "";
476
+ if (name === "skill")
477
+ return !action || ["read", "list", "report"].includes(action);
478
+ if (name === "scm")
479
+ return !action || ["status", "diff", "log", "history", "branches", "show"].includes(action);
480
+ if (isConversationTool(name))
481
+ return isReadOnlyConversationAction(action);
482
+ if (name === "claim_files")
483
+ return !action || action === "list";
484
+ if (name === "notes")
485
+ return p.op === "list";
486
+ if (name === "remote_term")
487
+ return action === "list";
488
+ if (name === "canvas")
489
+ return ["list", "get", "get_log", "card_list"].includes(action);
490
+ if (name === "worktree")
491
+ return action === "list";
492
+ if (name === "lsp")
493
+ return [
494
+ "definition",
495
+ "references",
496
+ "hover",
497
+ "diagnostics",
498
+ "documentSymbol",
499
+ "workspaceSymbol",
500
+ "read_symbol",
501
+ "cascade",
502
+ ].includes(action);
503
+ if (name === "browser_page")
504
+ return ["pages", "read", "shot"].includes(String(p.op));
505
+ return false;
506
+ }
304
507
  /**
305
508
  * 计划模式闸门(纯函数):命中即拒绝,并把可操作的替代路径告诉模型。
306
509
  * - 写类工具 → 拒(提示:把要做的事写进计划,用户确认后另起一轮实施)
@@ -310,9 +513,7 @@ function commandOf(params) {
310
513
  */
311
514
  export function planModeDenial(toolName, params) {
312
515
  const name = (toolName ?? "").trim();
313
- if (!name)
314
- return undefined;
315
- if (name === "subagent") {
516
+ if (isConversationTool(name)) {
316
517
  const action = typeof params === "object" && params !== null ? params.action : undefined;
317
518
  const act = typeof action === "string" ? action.trim().toLowerCase() : "";
318
519
  // 与 goal-review-gate 同口径:只读 action(get_result/list/templates,看状态
@@ -320,7 +521,7 @@ export function planModeDenial(toolName, params) {
320
521
  // SUBAGENT_ACTIONS)或未传 action 一律拒 —— steer/handoff 会向运行中的子代理
321
522
  // 会话投指令驱动它继续写代码,子代理会话 planMode=false 工具齐全,等于绕过
322
523
  // 本会话的只读约束(#436 此前只拒了 spawn)。
323
- if (act !== "get_result" && act !== "list" && act !== "templates") {
524
+ if (!isReadOnlyConversationAction(act)) {
324
525
  return {
325
526
  kind: "bypass-tool",
326
527
  reason: `计划模式:不能调用 subagent(action="${act || "spawn"}")(它会在别的会话里执行,绕过本会话的只读约束)。请在本对话内用只读工具完成调研。`,
@@ -359,7 +560,7 @@ export function planModeDenial(toolName, params) {
359
560
  reasonEn: `Plan mode: only read-only commands are allowed; rejected: \`${cmd.slice(0, 200)}\`. Use read/grep or read-only git (status/diff/log). Put proposed changes in the plan and wait for the user's go-ahead.`,
360
561
  };
361
562
  }
362
- if (BLOCKED_TOOLS.has(name)) {
563
+ if (BLOCKED_TOOLS.has(name) || (name !== "plan_update" && !readOnlyToolCallAllowed(name, params))) {
363
564
  return {
364
565
  kind: "write-tool",
365
566
  reason: `计划模式:只规划不实施,${name} 被拒。请把这一步写进计划(plan_update 步骤 + 计划正文),等用户确认后在新一轮里实施。`,
@@ -9,10 +9,10 @@
9
9
  * 5. Staging 隔离解压与原子安全替换;
10
10
  * 6. 细粒度下载进度透传与日志归因。
11
11
  */
12
- import { execSync } from "node:child_process";
12
+ import { execFileSync } from "node:child_process";
13
13
  import { createHash } from "node:crypto";
14
14
  import { createWriteStream, existsSync, mkdirSync, renameSync, rmSync, unlinkSync } from "node:fs";
15
- import { isAbsolute, join, resolve } from "node:path";
15
+ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
16
16
  // 模块级并发单例锁:Key 为 `pluginDir:assetId`
17
17
  const activeAssetPromises = new Map();
18
18
  const assetProgressState = new Map();
@@ -193,8 +193,12 @@ export async function ensurePluginAsset(pluginDir, spec, opts = {}) {
193
193
  const stagingDir = join(pluginDir, `.staging-${spec.id}-${Date.now()}`);
194
194
  mkdirSync(stagingDir, { recursive: true });
195
195
  try {
196
- // 调用跨平台 tar 工具解压(--force-local 防 Windows 盘符冒号被识别为远程主机)
197
- execSync(`tar --force-local -xzf "${tempTar}" -C "${stagingDir}"`, { windowsHide: true });
196
+ // Relative archive names avoid GNU tar treating drive letters as remote hosts.
197
+ // BSD/Windows tar does not support GNU-only --force-local.
198
+ execFileSync("tar", ["-xzf", `./${basename(tempTar)}`, "-C", resolve(stagingDir)], {
199
+ cwd: dirname(resolve(tempTar)),
200
+ windowsHide: true,
201
+ });
198
202
  // 检查 staging 内部形态(若内部包装了同名子目录,取子目录内容)
199
203
  const subDir = join(stagingDir, spec.targetDir);
200
204
  const sourceRoot = existsSync(subDir) ? subDir : stagingDir;
@@ -0,0 +1,48 @@
1
+ const MAX_COUNT = 8;
2
+ const MAX_ITEM_BYTES = 10 * 1024 * 1024;
3
+ const MAX_TOTAL_BYTES = 20 * 1024 * 1024;
4
+ const IMAGE_MIMES = new Set(["image/png", "image/jpeg", "image/gif", "image/webp"]);
5
+ /** Validate before invoking the agent; never silently discard media or truncate base64. */
6
+ export function normalizePluginChatAttachments(value) {
7
+ if (value === undefined)
8
+ return undefined;
9
+ if (!Array.isArray(value) || value.length > MAX_COUNT)
10
+ throw new Error("chat: attachments must contain at most 8 items");
11
+ let totalBytes = 0;
12
+ return value.map((raw) => {
13
+ if (!raw || typeof raw !== "object")
14
+ throw new Error("chat: invalid attachment");
15
+ const item = raw;
16
+ const path = typeof item.path === "string" ? item.path : "";
17
+ if (path.length > 4096 || path.includes("\0"))
18
+ throw new Error("chat: invalid attachment path");
19
+ const name = typeof item.name === "string" ? item.name.slice(0, 255) : undefined;
20
+ const mimeType = typeof item.mimeType === "string" ? item.mimeType.toLowerCase() : undefined;
21
+ if (mimeType && (mimeType.length > 128 || /[\r\n]/.test(mimeType)))
22
+ throw new Error("chat: invalid attachment MIME type");
23
+ const image = item.imageData !== undefined;
24
+ const file = item.fileData !== undefined;
25
+ if (image && file)
26
+ throw new Error("chat: attachment cannot contain both imageData and fileData");
27
+ if (image || file) {
28
+ const data = image ? item.imageData : item.fileData;
29
+ if (typeof data !== "string" ||
30
+ !data ||
31
+ data.length > Math.ceil(MAX_ITEM_BYTES / 3) * 4 ||
32
+ data.length % 4 !== 0 ||
33
+ !/^[A-Za-z0-9+/]*={0,2}$/.test(data) ||
34
+ Buffer.from(data, "base64").toString("base64") !== data) {
35
+ throw new Error("chat: invalid or oversized base64 attachment (maximum 10 MiB)");
36
+ }
37
+ const bytes = Buffer.byteLength(data, "base64");
38
+ if (bytes > MAX_ITEM_BYTES || (totalBytes += bytes) > MAX_TOTAL_BYTES)
39
+ throw new Error("chat: attachment byte budget exceeded (10 MiB each, 20 MiB total)");
40
+ if (image && !IMAGE_MIMES.has(mimeType ?? ""))
41
+ throw new Error("chat: image MIME must be image/png, image/jpeg, image/gif or image/webp");
42
+ return { path: "", name, mimeType, size: bytes, ...(image ? { imageData: data } : { fileData: data }) };
43
+ }
44
+ if (!path.trim() || (item.mode !== undefined && item.mode !== "reference" && item.mode !== "inline"))
45
+ throw new Error("chat: file attachments require a path and reference mode");
46
+ return { path, mode: "reference", name, mimeType };
47
+ });
48
+ }