关于 cli-anything-openclaw
OpenClaw Macro System 的命令行工具,供 Agent 通过参数化宏执行 GUI 工作流,而不直接操作 GUI。它按宏步骤选择可用后端,并提供试运行、会话管理和 YAML 宏定义功能。
主要功能
- 01列出宏并查看参数结构
- 02运行宏或进行无副作用试运行
- 03按步骤选择执行后端
- 04校验并创建 YAML 宏
- 05查看、保存和列出会话
适用场景
- 01检查宏参数后再执行
- 02试运行有副作用的宏步骤
- 03通过文件转换修改 JSON
- 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_api | backend: native_api | 子进程 / shell 命令 |
file_transform | backend: file_transform | XML、JSON、文本文件编辑 |
semantic_ui | backend: semantic_ui | 辅助功能 / 键盘快捷键 |
gui_macro | backend: gui_macro | 预编译的坐标回放 |
recovery | backend: 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 使用规则
- 始终使用
--json以获得程序化输出。 - 使用
--dry-run验证参数,然后再执行有副作用的宏。 - 检查
success字段 —— 不要仅凭退出码就假定成功。 - 当
success为 false 时阅读error字段 —— 它会说明失败原因。 - 在调用
macro run之前使用macro info <name>了解参数。 - 对所有文件参数使用绝对路径。
示例工作流
# 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