Communitygithub.com

MacroCLI 命令行工具

将图形用户界面工作流转换为参数化的命令行可调用宏,智能代理通过稳定的 CLI 接口调用宏,运行时自动选择最优后端执行。

MacroCLI 命令行工具 是什么?

MacroCLI 是一个命令行工具,旨在将复杂的图形用户界面(GUI)工作流抽象为参数化的、可通过 CLI 调用的宏。其核心思想是让 AI 代理完全不直接操作 GUI,而是通过一个稳定的 CLI 接口与宏交互。运行时系统(runtime)会根据宏的定义,自动选择最合适的后端来执行任务,这些后端包括:原生插件/API、文件转换、语义化 UI 控制以及预编译的 GUI 宏回放。该工具特别适合需要将 GUI 操作集成到自动化流程中的场景,比如在 Cursor、Claude Code 等 AI 编程工具中,代理可以调用宏来完成文件导出、JSON 转换、配置修改等原本需要手动点击的任务。MacroCLI 提供了完整的命令组:macro 用于宏的管理和运行,session 用于会话管理,backends 用于查看可用后端。所有命令都支持 `--json` 输出,便于程序化解析。宏定义采用 YAML 格式,可以指定参数、前置条件、步骤、后置条件和输出,并附有 agent_hints 来指示宏的安全等级和副作用。该工具支持 Python 3.10+,通过 pip 安装非常简单。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/HKUDS/CLI-Anything/tree/main/skills/cli-anything-macrocli

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

MacroCLI 命令行工具 是做什么的?

简介

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

安装

cd macrocli/agent-harness
pip install -e .

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

快速入门(面向代理)

# 1. 查看可用的宏
cli-anything-macrocli macro list --json

# 2. 查看宏的参数信息
cli-anything-macrocli macro info export_file --json

# 3. 预检参数(无副作用)
cli-anything-macrocli --dry-run macro run export_file \
    --param output=/tmp/test.txt --json

# 4. 执行宏
cli-anything-macrocli macro run export_file \
    --param output=/tmp/result.txt --json

# 5. 查看可用后端
cli-anything-macrocli backends --json

命令参考

全局标志

标志描述
--json在标准输出上输出机器可读的 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-macrocli backends --json
# 显示: native_api, file_transform, semantic_ui, gui_macro, recovery
# 以及每个后端在当前环境中是否可用。

宏参数

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

cli-anything-macrocli 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/macrocli/macro_definitions/ 目录下的 YAML 文件。使用以下命令创建模板:

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

最小 schema:

name: my_macro
version: "1.0"
description: 这个宏做什么。

parameters:
  output:
    type: string
    required: true
    description: 结果写入位置。
    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  # 或: 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

代理使用规则

  1. 始终使用 --json 以便程序化处理输出。
  2. 在执行有副作用的宏之前,先使用 --dry-run 验证参数。
  3. 检查 success 字段 — 不要仅凭退出码判断成功。
  4. 当 success 为 false 时,读取 error 字段 — 它会说明失败原因。
  5. 在调用 macro run 之前,先使用 macro info <name> 发现参数。
  6. 所有文件参数使用绝对路径。

示例工作流

# 步骤 1:查看可用宏
cli-anything-macrocli macro list --json

# 步骤 2:transform_json 需要哪些参数?
cli-anything-macrocli macro info transform_json --json

# 步骤 3:安全测试
cli-anything-macrocli --dry-run macro run transform_json \
    --param file=/tmp/config.json \
    --param key=theme \
    --param value=dark --json

# 步骤 4:真正执行
cli-anything-macrocli macro run transform_json \
    --param file=/tmp/config.json \
    --param key=theme \
    --param value=dark --json

版本

1.0.0

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

cli-anything-adguardhome

>-

cli-anything-anygen

>-

cli-anything-audacity

>-

cli-anything-blender

>-

cli-anything-browser

Browser automation CLI using DOMShell MCP server. Maps Chrome

cli-anything-calibre

>-

cli-anything-ccswitch

CLI interface for CC Switch — manage AI coding tool configurations from the terminal

cli-anything-chromadb

>-

cli-anything-cloudanalyzer

Command-line interface for CloudAnalyzer — Agent-friendly harness for CloudAnalyzer, a QA platform for mapping, localization, and perception outputs. Supports 27 commands across 8 groups: point cloud evaluation, trajectory evaluation, ground segmentation QA, config-driven quality gates, baseline evolution, processing, visualization, and interactive REPL.

cli-anything-cloudcompare

Command-line interface for CloudCompare — Agent-friendly harness for CloudCompare, the open-source 3D point cloud and mesh processing software. Supports 41 commands across 9 groups: project management, session control, point cloud operations (subsample, filter, segment, analyze), mesh operations, distance computation (C2C, C2M), transformations (ICP, matrix), export (LAS/LAZ/PLY/PCD/OBJ/STL/E57), and interactive REPL.

cli-anything-comfyui

>-

cli-anything-dify-workflow

Wrapper for the Dify workflow DSL CLI. Create, inspect, validate, edit, and export Dify workflow files through a CLI-Anything harness.

cli-anything-drawio

>-

cli-anything-eez-studio

Use EEZ Studio from the command line: inspect and modify native .eez-project files, edit LVGL screens/widgets, manage SCPI commands, and invoke the real EEZ Studio backend for LVGL builds.

cli-anything-eth2-quickstart

>-

cli-anything-exa

>-

cli-anything-firefly-iii

Firefly III CLI - Personal finance management via CLI-Anything

cli-anything-freecad

Complete CLI harness for FreeCAD parametric 3D CAD modeler (258 commands). Covers ALL workbenches: Part (29 primitives + boolean + mirror + loft + sweep), Sketcher (26 cmds: geometry + constraints + editing), PartDesign (38 cmds: pad/pocket/groove/fillet/chamfer/patterns/hole/datum), Assembly (11 cmds), Mesh (16 cmds), TechDraw (15 cmds: views + dimensions + PDF/SVG), Draft (33 cmds: 2D shapes + arrays + transforms), FEM (12 cmds), CAM/CNC (10 cmds), Surface (6 cmds), Spreadsheet (7 cmds), Import (13 formats), Export (17 formats), Measure (12 cmds), Materials (21 presets). Headless FreeCAD export to STEP/IGES/STL/OBJ/DXF/PDF/glTF/3MF.

cli-anything-gimp

>-

cli-anything-godot

>-

相关技能