- 核心功能从 store/ 迁移至 oss/core/ 框架层 - 实现 NBPF 包格式:多重签名(Ed25519+RSA-PSS+HMAC)+ 多重加密(AES-256-GCM) - 实现 NIR 编译器:基于 compile()+marshal 的跨平台中间表示 - 新增 nebula nbpf CLI 命令组(pack/unpack/verify/sign/keygen) - 新增 19 个 NBPF 测试用例,覆盖全链路 - 彻底重写 README,大型项目标准框架风格,所有图表使用 SVG - 更新 LICENSE 版权声明 - 清理旧版 store 插件目录(已迁移至 oss/core)
62 lines
2.5 KiB
Python
62 lines
2.5 KiB
Python
import ast
|
|
|
|
# 启发式能力扫描:通过 AST 分析插件源码,基于命名约定和导入推断插件提供的能力
|
|
# 这是一种轻量级的静态分析,不执行任何代码,仅用于快速发现插件可能提供的能力
|
|
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
|