Skip to content

[anolisa] feat(cli): implement anolisa adapter command family (list/install/remove/scan) #794

@kongche-jbw

Description

@kongche-jbw

现状

anolisa adapter 命令族当前全部返回 not_implemented

// crates/anolisa-cli/src/commands/adapter.rs
pub fn handle(args: AdapterArgs, _ctx: &CliContext) -> Result<(), CliError> {
    Err(CliError::not_implemented(command))
}

4 个子命令均未实现:

  • adapter list — 列出已注册的 adapters
  • adapter install <component> <framework> — 安装组件到框架的 adapter
  • adapter remove <component> <framework> — 移除 adapter
  • adapter scan — 自动检测可用的 adapter 集成

已有的基础设施

底层模块已经为 adapter 功能做了充分准备,只差 CLI 层的实现:

1. Manifest Schema(manifest.rs

ComponentManifest 已有 adapters: Vec<AdapterSpec> 字段,AdapterSpec 包含完整的 schema:

pub struct AdapterSpec {
    pub name: Option<String>,
    pub framework: Option<String>,    // "cosh" / "openclaw" / "hermes"
    pub kind: Option<String>,         // "first-party" / "third-party" / "protocol"
    pub plugin_id: Option<String>,    // 框架原生插件 ID
    pub source: Option<String>,       // 组件产物中的源路径
    pub dest: Option<String>,         // 布局占位符展开后的目标路径
    pub detect: BTreeMap<String, toml::Value>,  // 框架检测 hints
}

2. State Tracking(state.rs

ObjectKind::Adapter 已存在,可以追踪 adapter 的安装状态(Installed / Partial / Disabled / Failed / Adopted)、文件所有权、备份等。

3. 已声明的 Adapters

多个 runtime manifest 已声明 [[adapters]]

组件 目标框架 kind
tokenless cosh, openclaw, hermes first-party / third-party
agent-sec-core cosh, openclaw, hermes
agent-memory cosh, openclaw
ws-ckpt cosh

示例(tokenless.toml):

[[adapters]]
framework = "openclaw"
kind = "third-party"
source = "target/release/openclaw-plugin/"
dest = "{datadir}/adapters/tokenless/openclaw/"
detect = { binary = "openclaw" }

4. Contract Lint(contract_lint.rs

已有 lint_adapters() 函数校验 adapter 声明的结构合法性。

实现要求

adapter list

  • installed.toml 状态文件中读取 ObjectKind::Adapter 对象
  • 表格化输出:组件名、框架、kind、状态、安装路径
  • 支持 --json 输出

adapter install <component> <framework>

  • 从 manifest catalog 中查找组件的 [[adapters]] 声明(匹配 framework)
  • 执行 adapter 安装:将 source 路径的文件/目录复制到 dest(展开 {datadir} 等占位符)
  • 写入 installed.toml 状态(ObjectKind::Adapter
  • 如果 adapter 有 detect 字段,先检测目标框架是否可用(不可用则 warn 或 error)
  • 支持 --dry-run 输出安装计划
  • 记录 central audit log

adapter remove <component> <framework>

  • installed.toml 查找对应 adapter 对象
  • 删除 adapter 安装的文件(参考 disable/uninstall 的 rollback 逻辑)
  • 更新状态文件
  • 支持 --purge 清理配置
  • 支持 --dry-run

adapter scan

  • 遍历所有已安装组件的 manifest,收集 [[adapters]] 声明
  • 对每个 adapter 的 detect 字段执行探测(binary 存在性、paths 检查)
  • 输出:哪些 adapter 可用、哪些不可用、原因
  • 支持 --json

相关文件

  • crates/anolisa-cli/src/commands/adapter.rs — CLI handler(待实现)
  • crates/anolisa-core/src/manifest.rsAdapterSpec 定义
  • crates/anolisa-core/src/state.rsObjectKind::Adapter 状态追踪
  • crates/anolisa-core/src/contract_lint.rs — adapter 声明校验
  • manifests/runtime/tokenless.toml — adapter 声明示例
  • manifests/runtime/agent-sec-core.toml — adapter 声明示例
  • manifests/runtime/agent-memory.toml — adapter 声明示例
  • manifests/runtime/ws-ckpt.toml — adapter 声明示例

设计注意事项

  1. {datadir} 占位符展开:adapter 的 dest 使用 {datadir} 等布局占位符,需要从 FsLayout 展开为实际路径
  2. detect 探测逻辑detect 是 free-form BTreeMap<String, toml::Value>,需要实现通用的探测框架(binary 检查、path 检查、命令检查)
  3. 与 enable 流程的关系anolisa enable <capability> 安装组件后,是否自动安装该组件声明的 adapters?还是必须手动 adapter install?需要明确语义
  4. 幂等性:重复 adapter install 应该是幂等的(已安装则 skip 或 update)
  5. 事务性:adapter install/remove 应该复用现有的 transaction 机制

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions