42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
"""Agent 名称解析(兼容 Vercel skills CLI 别名)。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from skiff.paths import ALL_TARGETS
|
|
|
|
AGENT_ALIASES: dict[str, str] = {
|
|
"cursor": "cursor",
|
|
"claude": "claude",
|
|
"claude-code": "claude",
|
|
"codex": "codex",
|
|
"opencode": "opencode",
|
|
"*": "*",
|
|
}
|
|
|
|
AGENT_CHOICES = sorted({*ALL_TARGETS, *AGENT_ALIASES.keys()})
|
|
|
|
|
|
def flatten_agent_args(groups: list[list[str]] | None) -> list[str] | None:
|
|
if not groups:
|
|
return None
|
|
flat = [item for group in groups for item in group]
|
|
return flat or None
|
|
|
|
|
|
def resolve_agent_args(agents: list[str] | None) -> list[str]:
|
|
if not agents or agents == ["*"] or "*" in agents:
|
|
return list(ALL_TARGETS)
|
|
|
|
resolved: list[str] = []
|
|
for raw in agents:
|
|
key = raw.lower()
|
|
if key == "*":
|
|
return list(ALL_TARGETS)
|
|
target = AGENT_ALIASES.get(key)
|
|
if target is None:
|
|
choices = ", ".join(AGENT_CHOICES)
|
|
raise SystemExit(f"未知 agent: {raw!r},可选: {choices}")
|
|
if target != "*" and target not in resolved:
|
|
resolved.append(target)
|
|
return resolved
|