fix: 统一 Shell 审批开关语义
- 关闭 Shell 审批时移除命令级审批策略与强制审批元数据 - 补充适配器与运行时回归测试
This commit is contained in:
@@ -119,7 +119,10 @@ public class AgentOperateToolAdapter {
|
||||
toolkit.registerAgentTool(shellTool);
|
||||
AgentToolSpec shellToolSpec = toolSpec(
|
||||
spec, EXECUTE_SHELL_COMMAND_TOOL, "Execute shell command.", true);
|
||||
shellToolSpec.setApprovalPolicy(shellTool::approvalEvaluation);
|
||||
if (shellToolSpec.isApprovalRequired()) {
|
||||
// 命令级审批策略服从 Agent 的 Shell 审批开关;关闭后仅保留安全校验。
|
||||
shellToolSpec.setApprovalPolicy(shellTool::approvalEvaluation);
|
||||
}
|
||||
toolSpecs.add(shellToolSpec);
|
||||
}
|
||||
default -> throw new AgentRuntimeException("Unsupported agent operate tool type: " + type);
|
||||
@@ -157,7 +160,7 @@ public class AgentOperateToolAdapter {
|
||||
toolSpec.setVisibility(AgentToolVisibility.VISIBLE);
|
||||
toolSpec.setApprovalRequired(approvalRequired);
|
||||
toolSpec.setApprovalRequest(approvalRequest(operateSpec, approvalRequired));
|
||||
toolSpec.setMetadata(metadata(operateSpec));
|
||||
toolSpec.setMetadata(metadata(operateSpec, approvalRequired));
|
||||
return toolSpec;
|
||||
}
|
||||
|
||||
@@ -173,11 +176,11 @@ public class AgentOperateToolAdapter {
|
||||
return defaultRequest;
|
||||
}
|
||||
|
||||
private Map<String, Object> metadata(AgentOperateToolSpec spec) {
|
||||
private Map<String, Object> metadata(AgentOperateToolSpec spec, boolean approvalRequired) {
|
||||
Map<String, Object> metadata = new LinkedHashMap<>();
|
||||
metadata.put("operateTool", true);
|
||||
metadata.put("operateToolType", spec.getType().name());
|
||||
if (spec.getType() == AgentOperateToolType.SHELL) {
|
||||
if (spec.getType() == AgentOperateToolType.SHELL && approvalRequired) {
|
||||
metadata.put("forceApprovalCommands", List.of("rm"));
|
||||
metadata.put("forceApprovalCommandArgument", "command");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user