WindowsCommandValidator
public class WindowsCommandValidator implements CommandValidator
io/agentscope/core/tool/coding/WindowsCommandValidator.java:48–247Windows 命令校验器,让智能体以受控方式调用外部能力。位于 io.agentscope.core.tool.coding 包,实现 CommandValidator。核心成员包括 validate、extractExecutable、containsMultipleCommands。
Command validator for Windows systems.
Validation Order:
-
Extract executable from command (remove quotes, handle paths with spaces, remove path, remove extensions, convert to lowercase)
-
If no whitelist configured → allow (backward compatible)
-
Check for multiple command separators → reject if found
-
Check relative path safety (commands starting with
.\or./) → reject if escapes current directory -
Check whitelist (case-insensitive) → reject if not in whitelist
Multiple Command Detection: Detects Windows-specific separators:
&, &&, |, ||, newline
(ignores separators within quotes or after escape ^)
Note: Semicolon (;) is NOT a separator in Windows cmd.exe
Executable Extraction:
-
Handles quoted commands (double quotes)
-
Handles paths with spaces (e.g.,
C:\Program Files\app.exe) -
Extracts command name without path (handles both
\and/) -
Removes extensions:
.exe,.bat,.cmd(case-insensitive) -
Converts result to lowercase for consistent matching
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public ValidationResult validate(String command, Set<String> allowedCommands) | 执行校验相关操作。 Performs the validate operation. |
public String extractExecutable(String command) | 设置该参数。 Performs the extract executable operation. |
public boolean containsMultipleCommands(String command) | 设置该参数。 Check if the command contains multiple command separators outside of quotes. |
方法详情Method Detail
validate
public ValidationResult validate(String command, Set<String> allowedCommands)
执行校验相关操作。
Performs the validate operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
command | String | 命令(类型 `String`)。The command. |
allowedCommands | Set<String> | 已允许 Commands(类型 `Set`)。The allowed commands. |
ValidationResultio/agentscope/core/tool/coding/WindowsCommandValidator.java:52–95extractExecutable
public String extractExecutable(String command)
设置该参数。
Performs the extract executable operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
command | String | 命令(类型 `String`)。The command. |
Stringio/agentscope/core/tool/coding/WindowsCommandValidator.java:97–143containsMultipleCommands
public boolean containsMultipleCommands(String command)
设置该参数。
Check if the command contains multiple command separators outside of quotes.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
command | String | 命令到检查。The command to check |
booleanio/agentscope/core/tool/coding/WindowsCommandValidator.java:206–246