插件发现与启用:ServiceLoader→manifest→apply→expose

插件发现与启用:ServiceLoader→manifest→apply→expose 由 Archify 生成的时序图。 ① ExtensionRegistry.discover() ② loader.load() → ServiceLoader.load(Ai4jExtension) DiscoveredExtension 列表(META-INF/services) ③ extension.manifest() → id/能力声明 ④ enable(extensionId) ⑤ applyEnabledExtensions → ext.apply(context) ⑥ 注册 tool/command/skill/prompt/guardrail/hook ⑦ exposeTool(toolId) 显式放行 ⑧ snapshot():只含 enabled+exposed 的贡献面 宿主启动方 · 启用入口 · 时序参与者 宿主启动方 启用入口 Registry · ExtensionRegistry · 时序参与者 Registry ExtensionRegistry Loader · ServiceLoader 实现 · 时序参与者 Loader ServiceLoader 实现 Ai4jExtension · manifest + apply · 时序参与者 Ai4jExtension manifest + apply ExtContext · 六类注册表 · 时序参与者 ExtContext 六类注册表 图例 默认消息

发现即声明

  • • ServiceLoaderExtensionLoader 走标准 ServiceLoader 机制(META-INF/services),可传自定义 ClassLoader
  • • manifest() 提供 extensionId 与能力声明;discovered map 按 id 归一化登记,重复 id 拒绝

两道显式门

  • • enable(id) 只标记启用并触发 apply——贡献写进 ExtensionContext 各类注册表
  • • 工具要进宿主可见面还需 exposeTool(toolId) 白名单:enabled 但未 exposed 的工具不进 snapshot

校验与示例

  • • ExtensionValidator/ExtensionValidationReport 产出带 severity 的 issues;ExtensionToolSchemaValidator 校验工具 schema
  • • 官方示例 ai4j-plugin-ask-user:宿主中介的 ask-user 工具 + 命令 + Skill + Prompt 全套贡献