✨ 跟项目能跑起来就差这一步!这次狠狠修了一波: 🩺 修复40+损坏Python文件 - 补全所有缺少的class定义头(plugin-loader-pro、code-reviewer、 http-api/ws-api/http-tcp、webui/dashboard/log-terminal 等) - 修复中文括号、字符串未闭合、缩进错乱等语法问题 🔗 创建符号链接 plugin_bridge -> plugin-bridge - 解决Python模块路径不支持连字符的问题 - 关联修复 plugin-bridge 中错误的 import 路径 🧹 清理废弃代码 - 删除 oss/tui/ 目录(已废弃) - 清理所有 __pycache__ 和 .pyc 缓存文件 ✅ 全量语法检查通过,零错误! 📋 ai.md 新增代码审计报告和分阶段修复计划 🗺️ 所有插件 use() 调用现在走统一路径
58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
def scan_capabilities(plugin_dir):
|
|
capabilities: set[str] = set()
|
|
main_file = plugin_dir / "main.py"
|
|
|
|
if not main_file.exists():
|
|
return capabilities
|
|
|
|
with open(main_file, "r", encoding="utf-8") as f:
|
|
source = f.read()
|
|
|
|
tree = ast.parse(source)
|
|
|
|
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.ClassDef):
|
|
class_name = node.name
|
|
if class_name.endswith("Provider"):
|
|
cap_name = class_name.replace("Provider", "").lower()
|
|
capabilities.add(cap_name)
|
|
elif class_name.endswith("Mixin"):
|
|
cap_name = class_name.replace("Mixin", "").lower()
|
|
capabilities.add(cap_name)
|
|
elif class_name.endswith("Support"):
|
|
cap_name = class_name.replace("Support", "").lower()
|
|
capabilities.add(cap_name)
|
|
|
|
elif isinstance(node, ast.FunctionDef):
|
|
func_name = node.name
|
|
for decorator in node.decorator_list:
|
|
if isinstance(decorator, ast.Name):
|
|
if decorator.id.startswith("provides_"):
|
|
cap_name = decorator.id.replace("provides_", "")
|
|
capabilities.add(cap_name)
|
|
elif isinstance(decorator, ast.Attribute):
|
|
if decorator.attr.startswith("provides_"):
|
|
cap_name = decorator.attr.replace("provides_", "")
|
|
capabilities.add(cap_name)
|
|
|
|
elif isinstance(node, ast.Import):
|
|
for alias in node.names:
|
|
if "circuit" in alias.name.lower() or "breaker" in alias.name.lower():
|
|
capabilities.add("circuit_breaker")
|
|
elif "retry" in alias.name.lower():
|
|
capabilities.add("retry")
|
|
elif "cache" in alias.name.lower():
|
|
capabilities.add("cache")
|
|
|
|
elif isinstance(node, ast.ImportFrom):
|
|
if node.module:
|
|
if "circuit" in node.module.lower() or "breaker" in node.module.lower():
|
|
capabilities.add("circuit_breaker")
|
|
elif "retry" in node.module.lower():
|
|
capabilities.add("retry")
|
|
elif "cache" in node.module.lower():
|
|
capabilities.add("cache")
|
|
|
|
return capabilities
|