fix: 实现 Agent 修复验证闭环
This commit is contained in:
+13
-1
@@ -7,7 +7,7 @@ from backend.diagnosis import KUBECTL
|
||||
|
||||
|
||||
READ_ONLY_VERBS = {
|
||||
"api-resources", "api-versions", "auth", "cluster-info", "describe",
|
||||
"api-resources", "api-versions", "auth", "cluster-info", "config", "describe",
|
||||
"diff", "explain", "get", "logs", "top", "version", "wait",
|
||||
}
|
||||
WRITE_OR_INTERACTIVE_VERBS = {
|
||||
@@ -69,9 +69,21 @@ def _find_verb(args: list[str]) -> str:
|
||||
raise ValueError("无法识别 kubectl 操作类型")
|
||||
|
||||
|
||||
READ_ONLY_CONFIG_SUBCOMMANDS = {"current-context", "get-clusters", "get-contexts", "get-users", "view"}
|
||||
|
||||
|
||||
def classify_kubectl_command(command: str) -> CommandDecision:
|
||||
args = parse_kubectl_command(command)
|
||||
verb = _find_verb(args)
|
||||
if verb == "config":
|
||||
try:
|
||||
verb_index = args.index(next(arg for arg in args if arg.lower() == "config"))
|
||||
subcommand = args[verb_index + 1].lower()
|
||||
except (StopIteration, ValueError, IndexError):
|
||||
return CommandDecision("write", True, verb, args)
|
||||
if subcommand in READ_ONLY_CONFIG_SUBCOMMANDS:
|
||||
return CommandDecision("read", False, verb, args)
|
||||
return CommandDecision("write", True, verb, args)
|
||||
if verb in READ_ONLY_VERBS:
|
||||
return CommandDecision("read", False, verb, args)
|
||||
if verb in WRITE_OR_INTERACTIVE_VERBS:
|
||||
|
||||
Reference in New Issue
Block a user