mcpField
C
cli-anything-openclaw

cli-anything-openclaw

github.com/hkudsAgent 工作流57.6k100 次安装5 周前更新
代码仓库

关于 cli-anything-openclaw

OpenClaw Macro System 的命令行工具,供 Agent 通过参数化宏执行 GUI 工作流,而不直接操作 GUI。它按宏步骤选择可用后端,并提供试运行、会话管理和 YAML 宏定义功能。

主要功能

  1. 01列出宏并查看参数结构
  2. 02运行宏或进行无副作用试运行
  3. 03按步骤选择执行后端
  4. 04校验并创建 YAML 宏
  5. 05查看、保存和列出会话

适用场景

  1. 01检查宏参数后再执行
  2. 02试运行有副作用的宏步骤
  3. 03通过文件转换修改 JSON
  4. 04保存并查看宏运行会话

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/hkuds/cli-anything --skill cli-anything-openclaw

安装后在 Claude Code 中输入/cli-anything-openclaw确认已加载。

详细介绍

OpenClaw 宏系统 CLI

它是什么

OpenClaw 宏系统将有价值的 GUI 工作流转换为可参数化、可通过 CLI 调用的宏。Agent 从不直接操作 GUI —— 它们通过这个稳定的 CLI 调用宏,运行时会将执行路由到最佳的可用后端(原生插件/API、文件转换、语义 UI 控制或预编译的 GUI 宏回放)。

安装

cd openclaw-skill/agent-harness
pip install -e .

要求: Python 3.10+、PyYAML、click、prompt-toolkit。

快速开始(供 Agent 使用)

# 1. See what macros are available
cli-anything-openclaw macro list --json

# 2. Inspect a macro's parameters
cli-anything-openclaw macro info export_file --json

# 3. Dry-run to check params without side effects
cli-anything-openclaw --dry-run macro run export_file \
    --param output=/tmp/test.txt --json

# 4. Execute a macro
cli-anything-openclaw macro run export_file \
    --param output=/tmp/result.txt --json

# 5. See what backends are available
cli-anything-openclaw backends --json

命令参考

全局标志
标志描述
--json在 stdout 上输出机器可读的 JSON
--dry-run模拟所有步骤,跳过副作用
--session-id <id>恢复或创建命名会话
macro 组
命令描述
macro list列出所有可用宏
macro info <name>显示宏 schema(参数、步骤、条件)
macro run <name> --param k=v执行一个宏
macro dry-run <name> --param k=v模拟执行,不产生副作用
macro validate [name]结构验证
macro define <name>生成新的宏 YAML 脚手架
session 组
命令描述
session status显示会话统计信息
session history显示最近的运行历史
session save将会话持久化到磁盘
session list列出所有已保存的会话
backends
cli-anything-openclaw backends --json
# Shows: native_api, file_transform, semantic_ui, gui_macro, recovery
# and whether each is available in the current environment.

宏参数

使用 --param key=value 传递参数。可重复传递多个:

cli-anything-openclaw macro run transform_json \
    --param file=/path/to/data.json \
    --param key=settings.theme \
    --param value=dark \
    --json

输出格式(--json)

设置 --json 时,所有命令均输出 JSON:

{
  "success": true,
  "macro_name": "export_file",
  "output": {
    "exported_file": "/tmp/result.txt"
  },
  "error": "",
  "telemetry": {
    "duration_ms": 312,
    "steps_total": 2,
    "steps_run": 2,
    "backends_used": ["native_api"],
    "dry_run": false
  }
}

失败时("success": false),阅读 "error" 字段了解原因。 失败时退出码为 1。

执行后端

后端根据宏步骤定义自动选择:

后端触发条件用例
native_apibackend: native_api子进程 / shell 命令
file_transformbackend: file_transformXML、JSON、文本文件编辑
semantic_uibackend: semantic_ui辅助功能 / 键盘快捷键
gui_macrobackend: gui_macro预编译的坐标回放
recoverybackend: recovery重试 / 回退编排

编写宏

宏是位于 cli_anything/openclaw/macro_definitions/ 中的 YAML 文件。 使用以下命令生成脚手架:

cli-anything-openclaw macro define my_macro --output \
    cli_anything/openclaw/macro_definitions/examples/my_macro.yaml

最小 schema:

name: my_macro
version: "1.0"
description: What this macro does.

parameters:
  output:
    type: string
    required: true
    description: Where to write results.
    example: /tmp/result.txt

preconditions:
  - file_exists: /path/to/input

steps:
  - id: step1
    backend: native_api
    action: run_command
    params:
      command: [my-app, --export, "${output}"]
    timeout_ms: 30000
    on_failure: fail  # or: skip, continue

postconditions:
  - file_exists: ${output}
  - file_size_gt: [${output}, 100]

outputs:
  - name: result_file
    path: ${output}

agent_hints:
  danger_level: safe  # safe | moderate | dangerous
  side_effects: [creates_file]
  reversible: true

Agent 使用规则

  1. 始终使用 --json 以获得程序化输出。
  2. 使用 --dry-run 验证参数,然后再执行有副作用的宏。
  3. 检查 success 字段 —— 不要仅凭退出码就假定成功。
  4. 当 success 为 false 时阅读 error 字段 —— 它会说明失败原因。
  5. 在调用 macro run 之前使用 macro info <name> 了解参数。
  6. 对所有文件参数使用绝对路径。

示例工作流

# Step 1: What's available?
cli-anything-openclaw macro list --json

# Step 2: What params does transform_json need?
cli-anything-openclaw macro info transform_json --json

# Step 3: Test safely
cli-anything-openclaw --dry-run macro run transform_json \
    --param file=/tmp/config.json \
    --param key=theme \
    --param value=dark --json

# Step 4: Execute for real
cli-anything-openclaw macro run transform_json \
    --param file=/tmp/config.json \
    --param key=theme \
    --param value=dark --json

版本

1.0.0

评论

支持 Markdown