pi-web-ui 0.111.0 → 0.113.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 (88) hide show
  1. package/CHANGELOG.md +92 -2
  2. package/bin/frp-manager.mjs +9 -2
  3. package/bin/pi-web-ui.mjs +325 -45
  4. package/dist/server/agent-service-daemon.js +29 -4
  5. package/dist/server/agent-service.js +1527 -510
  6. package/dist/server/approval-audit.js +119 -0
  7. package/dist/server/approval-default-rules.js +4 -4
  8. package/dist/server/approval-rules.js +42 -17
  9. package/dist/server/attachment-store.js +8 -8
  10. package/dist/server/canvas/canvas-agent-tool.js +8 -0
  11. package/dist/server/canvas/canvas-orchestrator.js +128 -22
  12. package/dist/server/canvas/pstack-skills-data.js +498 -0
  13. package/dist/server/client-state.js +28 -0
  14. package/dist/server/delegate-mode.js +6 -3
  15. package/dist/server/delegate-task.js +18 -3
  16. package/dist/server/dispatch-domain-handlers.js +39 -11
  17. package/dist/server/dsh/dsh-agent-service.js +294 -15
  18. package/dist/server/dsh/dsh-serialize.js +1 -1
  19. package/dist/server/durable/durable-driver.js +112 -107
  20. package/dist/server/durable/durable-event-projector.js +253 -0
  21. package/dist/server/durable/durable-loader.js +1 -14
  22. package/dist/server/durable/durable-models.js +107 -0
  23. package/dist/server/durable/index.js +0 -4
  24. package/dist/server/engine-probe.js +111 -48
  25. package/dist/server/eval-tool.js +28 -3
  26. package/dist/server/goal-service.js +7 -0
  27. package/dist/server/index.js +371 -57
  28. package/dist/server/json-utils.js +57 -0
  29. package/dist/server/marker-service.js +8 -0
  30. package/dist/server/message-window.js +43 -10
  31. package/dist/server/model-admin.js +247 -163
  32. package/dist/server/model-resolver.js +66 -44
  33. package/dist/server/plan-manager.js +3 -6
  34. package/dist/server/plugin-api-catalog.js +1 -0
  35. package/dist/server/plugin-assets.js +238 -0
  36. package/dist/server/plugin-facilities.js +22 -0
  37. package/dist/server/plugin-ui-slots.js +1 -0
  38. package/dist/server/plugins.js +209 -11
  39. package/dist/server/preset-fields.js +25 -1
  40. package/dist/server/preset-share.js +5 -2
  41. package/dist/server/prompt-assembler.js +2 -1
  42. package/dist/server/prompt-composer.js +18 -8
  43. package/dist/server/protocol-version.js +1 -1
  44. package/dist/server/queue-utils.js +156 -0
  45. package/dist/server/remote-ssh-service.js +110 -12
  46. package/dist/server/sdk-builtin-extensions.js +85 -0
  47. package/dist/server/serialize.js +1 -1
  48. package/dist/server/server-config.js +66 -0
  49. package/dist/server/session-parser.js +49 -13
  50. package/dist/server/session-search.js +4 -3
  51. package/dist/server/settings-service.js +74 -53
  52. package/dist/server/setup-page.js +632 -0
  53. package/dist/server/skill-discovery.js +361 -59
  54. package/dist/server/skill-maintenance.js +231 -0
  55. package/dist/server/skill-tool.js +32 -3
  56. package/dist/server/soft-cap.js +30 -6
  57. package/dist/server/subagent-helpers.js +22 -1
  58. package/dist/server/subagent-notify.js +93 -0
  59. package/dist/server/subagent-security-gate.js +282 -0
  60. package/dist/server/subagent-templates.js +8 -0
  61. package/dist/server/subagents.js +390 -48
  62. package/dist/server/terminals.js +196 -8
  63. package/dist/server/text-quote.js +61 -0
  64. package/dist/server/tool-approval.js +63 -4
  65. package/dist/server/tool-guards.js +208 -0
  66. package/dist/server/tool-host-factories.js +48 -10
  67. package/dist/server/tool-manager.js +106 -28
  68. package/dist/server/tool-overrides.js +21 -11
  69. package/dist/server/universal/driver-base.js +8 -0
  70. package/dist/server/universal/drivers/claude-code.js +116 -7
  71. package/dist/server/universal/drivers/dsh-driver.js +3 -0
  72. package/dist/server/universal/index.js +0 -1
  73. package/dist/server/universal/universal-session.js +106 -10
  74. package/dist/server/worktree-service.js +189 -1
  75. package/docs/dsh-engine.md +1 -5
  76. package/package.json +1 -1
  77. package/plugin-sdk/client-utils.mjs +192 -5
  78. package/plugin-sdk/index.d.ts +63 -1
  79. package/plugin-sdk/index.mjs +94 -0
  80. package/plugin-sdk/package.json +5 -1
  81. package/plugins/catalog.json +21 -0
  82. package/web/dist/assets/{TerminalPanel-BiUNySMA.js → TerminalPanel-3wojLfLk.js} +2 -2
  83. package/web/dist/assets/index-A8YXwnpZ.js +2008 -0
  84. package/web/dist/assets/index-BwL7qBh6.css +1 -0
  85. package/web/dist/index.html +11 -2
  86. package/web/dist/sw.js +1 -1
  87. package/web/dist/assets/index-B0ajS__T.js +0 -697
  88. package/web/dist/assets/index-BHik5WGG.css +0 -1
@@ -0,0 +1,282 @@
1
+ import { pick } from "./i18n.js";
2
+ import { bashCommandIsReadOnly } from "./plan-mode.js";
3
+ import { goalReviewBashAllowed } from "./goal-review-gate.js";
4
+ /** 常见只读角色关键词(转小写后包含即判定为 readonly)。 */
5
+ const READONLY_ROLE_KEYWORDS = ["explore", "scout", "research", "oracle", "librarian", "reader"];
6
+ /** 常见审查验证角色关键词(转小写后包含即判定为 verify)。 */
7
+ const VERIFY_ROLE_KEYWORDS = ["review", "audit", "verify", "inspector"];
8
+ /**
9
+ * 解析并推导子代理的安全模式:
10
+ * 1. 优先使用模板显式声明的 securityMode;
11
+ * 2. 其次根据模板名或 type 关键词兜底(保障老用户无 securityMode 字段的模板或直接传 type 时自然生效);
12
+ * 3. 缺省返回 "normal"。
13
+ */
14
+ export function resolveSecurityMode(nameOrType, template) {
15
+ if (template?.securityMode && template.securityMode !== "normal") {
16
+ return template.securityMode;
17
+ }
18
+ const candidate = `${template?.name ?? ""} ${nameOrType ?? ""}`.trim().toLowerCase();
19
+ if (!candidate)
20
+ return "normal";
21
+ for (const kw of VERIFY_ROLE_KEYWORDS) {
22
+ if (candidate.includes(kw))
23
+ return "verify";
24
+ }
25
+ for (const kw of READONLY_ROLE_KEYWORDS) {
26
+ if (candidate.includes(kw))
27
+ return "readonly";
28
+ }
29
+ return "normal";
30
+ }
31
+ /** 别名映射:将调用方可能传入的泛称归一化为实际注册的工具名。 */
32
+ const TOOL_NAME_ALIASES = {
33
+ terminal: "bash",
34
+ shell: "bash",
35
+ sh: "bash",
36
+ cmd: "bash",
37
+ exec: "bash",
38
+ cli: "bash",
39
+ grep: "grep",
40
+ find: "find",
41
+ read: "read",
42
+ view: "read",
43
+ cat: "read",
44
+ };
45
+ /**
46
+ * 宽容解析 delegate_task 的 required_tools 文本。
47
+ * 支持:
48
+ * - 逗号/分号/空白分隔:"read, grep, find"
49
+ * - 换行列表:"- read\n- grep"
50
+ * - 预设代称识别:"read-only" / "readonly" -> 返回空 allowedTools 但可标明预设意图
51
+ *
52
+ * @param raw 模型传入的原始输入
53
+ * @param availableTools 当前环境可用工具名集合(可选,若提供则校验合法性)
54
+ */
55
+ export function parseRequiredTools(raw, availableTools) {
56
+ if (typeof raw !== "string" || !raw.trim()) {
57
+ return {};
58
+ }
59
+ const text = raw.trim();
60
+ // 特殊标记识别
61
+ const lower = text.toLowerCase();
62
+ const requestedReadOnly = lower.includes("read-only") || lower.includes("readonly") || lower.includes("reader");
63
+ // 匹配单词 token(支持连字符与下划线,如 edit_soft)
64
+ const matches = text.match(/[A-Za-z0-9_-]+/g) || [];
65
+ const availableSet = availableTools instanceof Set ? availableTools : availableTools ? new Set(availableTools) : null;
66
+ const seen = new Set();
67
+ const allowedTools = [];
68
+ const unrecognized = [];
69
+ for (const item of matches) {
70
+ const token = item.trim().toLowerCase();
71
+ // 跳过常见的介词、连接词与预设代称关键词
72
+ if ([
73
+ "and",
74
+ "or",
75
+ "with",
76
+ "only",
77
+ "tools",
78
+ "tool",
79
+ "the",
80
+ "for",
81
+ "read-only",
82
+ "readonly",
83
+ "reader",
84
+ "none",
85
+ "all",
86
+ ].includes(token)) {
87
+ continue;
88
+ }
89
+ const mapped = TOOL_NAME_ALIASES[token] ?? token;
90
+ if (seen.has(mapped))
91
+ continue;
92
+ seen.add(mapped);
93
+ if (availableSet) {
94
+ if (availableSet.has(mapped)) {
95
+ allowedTools.push(mapped);
96
+ }
97
+ else {
98
+ unrecognized.push(token);
99
+ }
100
+ }
101
+ else {
102
+ allowedTools.push(mapped);
103
+ }
104
+ }
105
+ return {
106
+ allowedTools: allowedTools.length > 0 ? allowedTools : undefined,
107
+ unrecognized: unrecognized.length > 0 ? unrecognized : undefined,
108
+ requestedReadOnly,
109
+ };
110
+ }
111
+ /** 目标模式与只读模式下公认的硬写类工具名。 */
112
+ export const SUBAGENT_WRITE_TOOL_NAMES = new Set([
113
+ "write",
114
+ "create",
115
+ "create_file",
116
+ "write_file",
117
+ "edit",
118
+ "edit_file",
119
+ "edit_soft",
120
+ "apply_patch",
121
+ "patch",
122
+ "patch_tool",
123
+ "str_replace",
124
+ "str_replace_editor",
125
+ "multi_edit",
126
+ "notebook_edit",
127
+ "mv",
128
+ "move",
129
+ "cp",
130
+ "copy",
131
+ "mkdir",
132
+ "rm",
133
+ "rmdir",
134
+ "delete",
135
+ "delete_file",
136
+ "touch",
137
+ "chmod",
138
+ "chown",
139
+ "codemode",
140
+ "powershell",
141
+ ]);
142
+ /** 交互式终端输入工具:受限模式下必须禁用,防止通过交互输入写命令绕过检测。 */
143
+ export const SUBAGENT_TERMINAL_INPUT_TOOLS = new Set([
144
+ "terminal_input",
145
+ "terminal_key",
146
+ "terminal_create",
147
+ "terminal_close",
148
+ ]);
149
+ /** 越权派发工具:受限子代理禁止再派生/操控其他子代理。 */
150
+ export const SUBAGENT_DISPATCH_TOOLS = new Set(["delegate_task"]);
151
+ /** bash 类工具名。 */
152
+ const BASH_TOOL_NAMES = new Set(["bash", "bash_execute", "run_command", "shell", "terminal", "terminal_exec"]);
153
+ /** 取工具参数中的命令字段。 */
154
+ function commandOf(params) {
155
+ if (!params || typeof params !== "object")
156
+ return "";
157
+ const p = params;
158
+ for (const key of ["command", "cmd", "script", "input"]) {
159
+ const v = p[key];
160
+ if (typeof v === "string" && v.trim() !== "")
161
+ return v;
162
+ }
163
+ return "";
164
+ }
165
+ /**
166
+ * 校验子代理对指定工具的调用是否违规(纯函数)。
167
+ *
168
+ * @param mode 子代理的安全模式
169
+ * @param toolName 被调用的工具名
170
+ * @param params 调用参数
171
+ * @param allowedTools 显式工具白名单集合(若设置)
172
+ */
173
+ export function subagentSecurityDenial(mode, toolName, params, allowedTools) {
174
+ const name = (toolName ?? "").trim();
175
+ if (!name)
176
+ return undefined;
177
+ // 1. 显式白名单门控(若配置了 allowedTools)
178
+ if (allowedTools && allowedTools.size > 0 && !allowedTools.has(name)) {
179
+ return {
180
+ kind: "not-allowed-tool",
181
+ reason: `受限子代理:工具 "${name}" 不在本次任务允许的工具白名单内(仅限:${[...allowedTools].join(", ")})。`,
182
+ reasonEn: `Restricted subagent: tool "${name}" is not in the allowed tool whitelist for this task (only: ${[...allowedTools].join(", ")}).`,
183
+ };
184
+ }
185
+ // normal 模式下不追加写拦截与 bash 只读限制
186
+ if (mode === "normal") {
187
+ return undefined;
188
+ }
189
+ // 2. 派发工具拦截(只读/审查子代理禁止派发或操纵同伴,防止安全穿透)
190
+ if (SUBAGENT_DISPATCH_TOOLS.has(name)) {
191
+ return {
192
+ kind: "dispatch-tool",
193
+ reason: `受限子代理(${mode}):禁止调用派发工具 "${name}"。请在当前会话内独立完成分析与核实并返回结论。`,
194
+ reasonEn: `Restricted subagent (${mode}): dispatch tool "${name}" is blocked. Complete inspection and return findings within this session.`,
195
+ };
196
+ }
197
+ if (name === "subagent") {
198
+ const action = typeof params === "object" && params !== null ? params.action : undefined;
199
+ const act = typeof action === "string" ? action.trim().toLowerCase() : "";
200
+ // 只放行只读查询类 action,拦截 spawn/steer/stop/handoff/wait_all
201
+ if (act !== "get_result" && act !== "list" && act !== "templates") {
202
+ return {
203
+ kind: "dispatch-tool",
204
+ reason: `受限子代理(${mode}):禁止调用 subagent(action="${act || "spawn"}") 派生或操控其他子代理。`,
205
+ reasonEn: `Restricted subagent (${mode}): subagent(action="${act || "spawn"}") is blocked in restricted mode.`,
206
+ };
207
+ }
208
+ }
209
+ // 3. 硬写类工具拦截
210
+ if (SUBAGENT_WRITE_TOOL_NAMES.has(name)) {
211
+ return {
212
+ kind: "write-tool",
213
+ reason: `受限子代理(${mode}):当前属于只读/审查模式,禁止调用写工具 "${name}"。请使用 read/grep/只读命令进行核实。`,
214
+ reasonEn: `Restricted subagent (${mode}): write tool "${name}" is blocked in read/verify mode. Use read/grep/read-only commands to inspect.`,
215
+ };
216
+ }
217
+ // 4. 交互式终端输入拦截(防绕过)
218
+ if (SUBAGENT_TERMINAL_INPUT_TOOLS.has(name)) {
219
+ return {
220
+ kind: "terminal-input",
221
+ reason: `受限子代理(${mode}):禁止使用交互式终端输入工具 "${name}"。请使用一次性 bash 只读命令。`,
222
+ reasonEn: `Restricted subagent (${mode}): interactive terminal tool "${name}" is blocked. Use one-shot read-only bash commands instead.`,
223
+ };
224
+ }
225
+ // 5. Bash 命令动态审查拦截
226
+ if (BASH_TOOL_NAMES.has(name)) {
227
+ const cmd = commandOf(params);
228
+ if (!cmd.trim()) {
229
+ return {
230
+ kind: "bash-write",
231
+ reason: `受限子代理(${mode}):不接受无命令的 bash 调用。`,
232
+ reasonEn: `Restricted subagent (${mode}): empty bash calls are rejected.`,
233
+ };
234
+ }
235
+ if (mode === "readonly") {
236
+ // 严格只读模式:必须过 bashCommandIsReadOnly
237
+ if (!bashCommandIsReadOnly(cmd)) {
238
+ return {
239
+ kind: "bash-write",
240
+ reason: `只读侦察子代理(readonly):命令被阻断(仅允许纯只读命令,如 ls/cat/grep/git diff/git log 等):\`${cmd.slice(0, 160)}\`。`,
241
+ reasonEn: `Read-only subagent (readonly): command blocked (only pure read-only commands allowed, e.g. ls/cat/grep/git diff/git log): \`${cmd.slice(0, 160)}\`.`,
242
+ };
243
+ }
244
+ }
245
+ else if (mode === "verify") {
246
+ // 审查验证模式:允许只读命令 + 测试套件(goalReviewBashAllowed)
247
+ if (!goalReviewBashAllowed(cmd)) {
248
+ return {
249
+ kind: "bash-write",
250
+ reason: `审查验证子代理(verify):命令被阻断(仅允许只读命令与测试套件,禁止重定向写或破坏性操作):\`${cmd.slice(0, 160)}\`。`,
251
+ reasonEn: `Verification subagent (verify): command blocked (only read-only and test runner commands allowed, no redirect writes or destructive ops): \`${cmd.slice(0, 160)}\`.`,
252
+ };
253
+ }
254
+ }
255
+ }
256
+ return undefined;
257
+ }
258
+ /**
259
+ * 将工具包裹上子代理安全门禁(withSubagentSecurityGate)。
260
+ */
261
+ export function withSubagentSecurityGate(def, getSecurityInfo, getLang) {
262
+ return {
263
+ ...def,
264
+ execute: (async (...args) => {
265
+ const info = getSecurityInfo();
266
+ const mode = info.mode ?? "normal";
267
+ const allowedTools = info.allowedTools;
268
+ if (mode !== "normal" || (allowedTools && allowedTools.size > 0)) {
269
+ const params = args[1];
270
+ const denied = subagentSecurityDenial(mode, def.name, params, allowedTools);
271
+ if (denied) {
272
+ return {
273
+ content: [{ type: "text", text: pick(getLang(), denied.reason, denied.reasonEn) }],
274
+ details: { guardDenied: true, subagentSecurityDenied: true, kind: denied.kind },
275
+ isError: true,
276
+ };
277
+ }
278
+ }
279
+ return def.execute(...args);
280
+ }),
281
+ };
282
+ }
@@ -154,6 +154,7 @@ export const DEFAULT_TEMPLATES = [
154
154
  model: "",
155
155
  thinkingLevel: "",
156
156
  enabled: true,
157
+ securityMode: "verify",
157
158
  },
158
159
  {
159
160
  name: "implement",
@@ -199,6 +200,7 @@ export const DEFAULT_TEMPLATES = [
199
200
  model: "",
200
201
  thinkingLevel: "",
201
202
  enabled: true,
203
+ securityMode: "normal",
202
204
  },
203
205
  {
204
206
  name: "research",
@@ -240,6 +242,7 @@ export const DEFAULT_TEMPLATES = [
240
242
  model: "",
241
243
  thinkingLevel: "",
242
244
  enabled: true,
245
+ securityMode: "readonly",
243
246
  },
244
247
  {
245
248
  name: "scout",
@@ -285,6 +288,7 @@ export const DEFAULT_TEMPLATES = [
285
288
  model: "",
286
289
  thinkingLevel: "",
287
290
  enabled: true,
291
+ securityMode: "readonly",
288
292
  },
289
293
  {
290
294
  name: "audit",
@@ -312,6 +316,7 @@ export const DEFAULT_TEMPLATES = [
312
316
  model: "",
313
317
  thinkingLevel: "",
314
318
  enabled: true,
319
+ securityMode: "verify",
315
320
  },
316
321
  {
317
322
  name: "delegate",
@@ -366,6 +371,7 @@ export const DEFAULT_TEMPLATES = [
366
371
  model: "",
367
372
  thinkingLevel: "",
368
373
  enabled: true,
374
+ securityMode: "readonly",
369
375
  },
370
376
  {
371
377
  name: "librarian",
@@ -391,6 +397,7 @@ export const DEFAULT_TEMPLATES = [
391
397
  model: "",
392
398
  thinkingLevel: "",
393
399
  enabled: true,
400
+ securityMode: "readonly",
394
401
  },
395
402
  {
396
403
  name: "explore",
@@ -424,6 +431,7 @@ export const DEFAULT_TEMPLATES = [
424
431
  model: "",
425
432
  thinkingLevel: "",
426
433
  enabled: true,
434
+ securityMode: "readonly",
427
435
  },
428
436
  {
429
437
  name: "metis",