AS AgentScopeAPI 手册 / API Reference

WindowsCommandValidator

public class WindowsCommandValidator implements CommandValidator
源码Source io/agentscope/core/tool/coding/WindowsCommandValidator.java:48–247

Windows 命令校验器,让智能体以受控方式调用外部能力。位于 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.

参数Parameters
名称Name类型Type说明Description
commandString命令(类型 `String`)。The command.
allowedCommandsSet<String>已允许 Commands(类型 `Set`)。The allowed commands.
返回Returns ValidationResult
返回ValidationResult。Returns validation result.
源码Source io/agentscope/core/tool/coding/WindowsCommandValidator.java:52–95

extractExecutable

public String extractExecutable(String command)

设置该参数。

Performs the extract executable operation.

参数Parameters
名称Name类型Type说明Description
commandString命令(类型 `String`)。The command.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/tool/coding/WindowsCommandValidator.java:97–143

containsMultipleCommands

public boolean containsMultipleCommands(String command)

设置该参数。

Check if the command contains multiple command separators outside of quotes.

参数Parameters
名称Name类型Type说明Description
commandString命令到检查。The command to check
返回Returns boolean
返回布尔值,表示判断结果。true if multiple commands are detected, false otherwise
源码Source io/agentscope/core/tool/coding/WindowsCommandValidator.java:206–246

继承成员Inherited Members

继承自Methods inherited from CommandValidator
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.