pi-web-ui 0.111.0 → 0.112.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 (77) hide show
  1. package/CHANGELOG.md +55 -2
  2. package/bin/frp-manager.mjs +9 -2
  3. package/dist/server/agent-service.js +1325 -488
  4. package/dist/server/approval-audit.js +119 -0
  5. package/dist/server/approval-default-rules.js +4 -4
  6. package/dist/server/approval-rules.js +42 -17
  7. package/dist/server/attachment-store.js +8 -8
  8. package/dist/server/canvas/canvas-agent-tool.js +6 -0
  9. package/dist/server/canvas/canvas-orchestrator.js +88 -21
  10. package/dist/server/client-state.js +28 -0
  11. package/dist/server/delegate-mode.js +6 -3
  12. package/dist/server/delegate-task.js +18 -3
  13. package/dist/server/dispatch-domain-handlers.js +3 -0
  14. package/dist/server/dsh/dsh-agent-service.js +242 -11
  15. package/dist/server/dsh/dsh-serialize.js +1 -1
  16. package/dist/server/durable/durable-driver.js +75 -9
  17. package/dist/server/durable/durable-loader.js +1 -14
  18. package/dist/server/durable/durable-models.js +107 -0
  19. package/dist/server/durable/index.js +0 -4
  20. package/dist/server/engine-probe.js +76 -37
  21. package/dist/server/eval-tool.js +28 -3
  22. package/dist/server/goal-service.js +7 -0
  23. package/dist/server/index.js +344 -56
  24. package/dist/server/json-utils.js +57 -0
  25. package/dist/server/marker-service.js +8 -0
  26. package/dist/server/message-window.js +43 -10
  27. package/dist/server/model-admin.js +68 -106
  28. package/dist/server/model-resolver.js +66 -44
  29. package/dist/server/plan-manager.js +3 -6
  30. package/dist/server/plugin-api-catalog.js +1 -0
  31. package/dist/server/plugin-assets.js +238 -0
  32. package/dist/server/plugin-facilities.js +22 -0
  33. package/dist/server/plugin-ui-slots.js +1 -0
  34. package/dist/server/plugins.js +199 -5
  35. package/dist/server/preset-fields.js +25 -1
  36. package/dist/server/preset-share.js +5 -2
  37. package/dist/server/prompt-assembler.js +2 -1
  38. package/dist/server/prompt-composer.js +18 -8
  39. package/dist/server/protocol-version.js +1 -1
  40. package/dist/server/queue-utils.js +156 -0
  41. package/dist/server/sdk-builtin-extensions.js +85 -0
  42. package/dist/server/server-config.js +66 -0
  43. package/dist/server/session-parser.js +49 -13
  44. package/dist/server/session-search.js +4 -3
  45. package/dist/server/settings-service.js +38 -5
  46. package/dist/server/soft-cap.js +8 -6
  47. package/dist/server/subagent-helpers.js +22 -1
  48. package/dist/server/subagent-notify.js +93 -0
  49. package/dist/server/subagent-security-gate.js +282 -0
  50. package/dist/server/subagent-templates.js +8 -0
  51. package/dist/server/subagents.js +144 -17
  52. package/dist/server/terminals.js +196 -8
  53. package/dist/server/text-quote.js +61 -0
  54. package/dist/server/tool-approval.js +63 -4
  55. package/dist/server/tool-guards.js +208 -0
  56. package/dist/server/tool-host-factories.js +46 -10
  57. package/dist/server/tool-overrides.js +21 -11
  58. package/dist/server/universal/driver-base.js +8 -0
  59. package/dist/server/universal/drivers/claude-code.js +20 -3
  60. package/dist/server/universal/drivers/dsh-driver.js +3 -0
  61. package/dist/server/universal/index.js +0 -1
  62. package/dist/server/universal/universal-session.js +87 -10
  63. package/dist/server/worktree-service.js +189 -1
  64. package/docs/dsh-engine.md +1 -5
  65. package/package.json +1 -1
  66. package/plugin-sdk/client-utils.mjs +192 -5
  67. package/plugin-sdk/index.d.ts +63 -1
  68. package/plugin-sdk/index.mjs +94 -0
  69. package/plugin-sdk/package.json +5 -1
  70. package/plugins/catalog.json +11 -0
  71. package/web/dist/assets/{TerminalPanel-BiUNySMA.js → TerminalPanel-Dqr1dK28.js} +1 -1
  72. package/web/dist/assets/index-Dh8BX-lP.js +720 -0
  73. package/web/dist/assets/index-DqrC1I_a.css +1 -0
  74. package/web/dist/index.html +11 -2
  75. package/web/dist/sw.js +1 -1
  76. package/web/dist/assets/index-B0ajS__T.js +0 -697
  77. package/web/dist/assets/index-BHik5WGG.css +0 -1
@@ -80,9 +80,18 @@ export function toSubagentSnapshot(conv) {
80
80
  catch {
81
81
  // session being replaced — report defaults
82
82
  }
83
+ let thinkingLevel;
84
+ try {
85
+ thinkingLevel = conv.session.thinkingLevel ?? conv.subagentThinking;
86
+ }
87
+ catch {
88
+ thinkingLevel = conv.subagentThinking;
89
+ }
83
90
  const fullPrompt = conv.subagentPrompt ?? "";
84
91
  const sm = conv.session.sessionManager;
85
92
  const isPersisted = !conv.isSubagent || (typeof sm?.isPersisted === "function" && sm.isPersisted());
93
+ const m = conv.session.model;
94
+ const modelKey = m ? `${m.provider}/${m.id}` : (conv.subagentTemplate?.model ?? undefined);
86
95
  return {
87
96
  convId: conv.id,
88
97
  type: conv.subagentType ?? "general",
@@ -95,12 +104,24 @@ export function toSubagentSnapshot(conv) {
95
104
  error,
96
105
  canceled,
97
106
  messageCount,
98
- model: conv.session.model?.id,
107
+ model: modelKey,
108
+ thinkingLevel,
99
109
  output: conv.session.getLastAssistantText() ?? "",
100
110
  parentId: conv.parentId,
101
111
  persisted: isPersisted,
102
112
  handoffTo: conv.peerHandoffTo ? [...conv.peerHandoffTo] : undefined,
103
113
  handoffFrom: conv.peerHandoffFrom ? [...conv.peerHandoffFrom] : undefined,
114
+ worktree: conv.subagentWorktree
115
+ ? {
116
+ path: conv.subagentWorktree.worktreePath,
117
+ branch: conv.subagentWorktree.branch,
118
+ cleanedUp: Boolean(conv.subagentWorktree.cleanedUp),
119
+ isDirty: conv.subagentWorktree.isDirty,
120
+ uncommittedCount: conv.subagentWorktree.uncommittedCount,
121
+ aheadCount: conv.subagentWorktree.aheadCount,
122
+ error: conv.subagentWorktree.error,
123
+ }
124
+ : undefined,
104
125
  };
105
126
  }
106
127
  /** 列举并排序子代理快照集合 */
@@ -0,0 +1,93 @@
1
+ // ---------------------------------------------------------------------------
2
+ // subagent-notify.ts — 子代理终态自动通知与结构化交付契约(issue #713)
3
+ // ---------------------------------------------------------------------------
4
+ // 负责:
5
+ // 1. extractSubagentConclusion: 提炼子代理输出的核心结论(保留首尾重点,折叠冗余日志)
6
+ // 2. formatSubagentsCompletionNotice: 将批处理/防抖收敛的一组终态子代理格式化为
7
+ // 高信噪比、低 Token 占用的父对话唤醒汇报
8
+ // ---------------------------------------------------------------------------
9
+ import { pick } from "./i18n.js";
10
+ import { subagentRunOutcome } from "./subagent-helpers.js";
11
+ /**
12
+ * 从子代理的长文本输出中提取核心结论:
13
+ * - 输出较短(<= 20 行)时原样返回;
14
+ * - 输出较长时保留前 3 行任务概况与后 15 行最终总结/结论,中间过程性输出自适应折叠;
15
+ * - 空输出给出可读占位符。
16
+ */
17
+ export function extractSubagentConclusion(output, lang = "en") {
18
+ const trimmed = (output ?? "").trim();
19
+ if (!trimmed) {
20
+ return lang === "zh" ? "(无输出结果)" : "(no output produced)";
21
+ }
22
+ const lines = trimmed.split("\n");
23
+ if (lines.length <= 20) {
24
+ return trimmed;
25
+ }
26
+ const head = lines.slice(0, 3).join("\n");
27
+ const tail = lines.slice(-15).join("\n");
28
+ const omitted = lines.length - 18;
29
+ const omitMarker = lang === "zh"
30
+ ? `… [中间省略 ${omitted} 行过程日志,完整转录可通过 get_result 查看] …`
31
+ : `… [${omitted} lines omitted, full transcript available via get_result] …`;
32
+ return `${head}\n${omitMarker}\n${tail}`;
33
+ }
34
+ /** 短 id(前 8 字符) */
35
+ function shortId(id) {
36
+ return id.slice(0, 8);
37
+ }
38
+ /**
39
+ * 格式化聚合的一组终态子代理为父对话的入站通知。
40
+ * 多个子代理同时完成时合成一条结构化汇报,避免碎片化打断父对话。
41
+ */
42
+ export function formatSubagentsCompletionNotice(subagents, lang = "en", fallbackOriginalParentId) {
43
+ if (subagents.length === 0)
44
+ return "";
45
+ const count = subagents.length;
46
+ const fallbackNote = fallbackOriginalParentId
47
+ ? pick(lang, `(原父对话 ${shortId(fallbackOriginalParentId)} 已不在,转至当前活跃对话继续)\n`, `(Original parent chat ${shortId(fallbackOriginalParentId)} is gone; redirected here)\n`, "subagents.notify.fallback", { parentId: shortId(fallbackOriginalParentId) })
48
+ : "";
49
+ const titleHeader = pick(lang, `[子代理执行完成通知] 共有 ${count} 个子代理已完成:`, `[Subagent Completion Notice] ${count} subagent(s) completed:`, "subagents.notify.header", { count });
50
+ const items = subagents.map((conv) => {
51
+ const sId = shortId(conv.id);
52
+ const type = conv.subagentType ?? "general";
53
+ const roleModel = conv.session.model
54
+ ? `${conv.session.model.provider}/${conv.session.model.id}`
55
+ : conv.subagentTemplate?.model || "default";
56
+ const thinking = conv.session.thinkingLevel ?? conv.subagentThinking ?? "default";
57
+ const metaTag = `${type} · ${roleModel}:${thinking}`;
58
+ const outcome = subagentRunOutcome(conv);
59
+ let statusLabel;
60
+ if (outcome.error) {
61
+ statusLabel = pick(lang, `❌ 运行失败(${outcome.error})`, `❌ Failed (${outcome.error})`, "subagents.notify.status.failed", { error: outcome.error });
62
+ }
63
+ else if (outcome.canceled) {
64
+ statusLabel = pick(lang, "⚠️ 已中止", "⚠️ Canceled", "subagents.notify.status.canceled");
65
+ }
66
+ else {
67
+ statusLabel = pick(lang, "✅ 正常完成", "✅ Done", "subagents.notify.status.done");
68
+ }
69
+ const rawOutput = conv.session.getLastAssistantText() ?? "";
70
+ const conclusion = extractSubagentConclusion(rawOutput, lang);
71
+ const indentedConclusion = conclusion
72
+ .split("\n")
73
+ .map((l) => ` > ${l}`)
74
+ .join("\n");
75
+ const taskLine = conv.title ? ` - ${pick(lang, "目标", "Goal", "subagents.notify.goal")}: ${conv.title}\n` : "";
76
+ let wtLine = "";
77
+ if (conv.subagentWorktree) {
78
+ const wt = conv.subagentWorktree;
79
+ if (wt.cleanedUp) {
80
+ wtLine = ` - ${pick(lang, "工作树隔离", "Worktree isolation", "subagents.notify.worktree")}: ${pick(lang, "无文件修改,临时工作树已自动清理", "No changes made; temporary worktree cleaned up", "subagents.notify.worktree.cleaned")}\n`;
81
+ }
82
+ else {
83
+ wtLine =
84
+ ` - ${pick(lang, "工作树隔离", "Worktree isolation", "subagents.notify.worktree")}: ` +
85
+ pick(lang, `已保留分支 ${wt.branch}(${wt.uncommittedCount ?? 0} 处未提交修改,${wt.aheadCount ?? 0} 个新提交)`, `Preserved branch ${wt.branch} (${wt.uncommittedCount ?? 0} uncommitted, ${wt.aheadCount ?? 0} commits ahead)`, "subagents.notify.worktree.preserved", { branch: wt.branch, uncommitted: wt.uncommittedCount ?? 0, ahead: wt.aheadCount ?? 0 }) +
86
+ `\n - ${pick(lang, "工作树路径", "Worktree path", "subagents.notify.worktree.path")}: ${wt.worktreePath}\n`;
87
+ }
88
+ }
89
+ return `- **${sId}**(${metaTag})— ${statusLabel}\n${taskLine}${wtLine} - ${pick(lang, "产出摘要", "Summary", "subagents.notify.summary")}:\n${indentedConclusion}`;
90
+ });
91
+ const footer = pick(lang, '\n如需调取子代理完整对话转录与工具执行详情,可调用 subagent(action="get_result", runId="<id>")。', '\nFor full transcripts or detailed tool logs, call subagent(action="get_result", runId="<id>").', "subagents.notify.footer");
92
+ return `${fallbackNote}${titleHeader}\n\n${items.join("\n\n")}${footer}`;
93
+ }
@@ -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",