关于 cli-anything
cli-anything 是一项技能,可为源代码可访问的 GUI 应用生成基于 Click 的命令行接口,供开发者和 Agent 通过命令控制应用。它生成的接口包含 JSON 输出、交互式 REPL 和测试套件。
主要功能
- 01通过七阶段流程生成命令行接口
- 02将 GUI 操作映射到后端 API
- 03提供 JSON 输出和交互式 REPL
- 04生成 pytest 测试套件
- 05优化、测试、验证和列出接口
适用场景
- 01为本地源码应用构建命令行接口
- 02根据 GitHub 源码地址生成接口
- 03通过命令自动执行 GUI 应用任务
- 04测试并优化生成的命令行接口
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ terrylica/ cc-skills --skill cli-anything安装后在 Claude Code 中输入/cli-anything确认已加载。
详细介绍
CLI-Anything 参考文档
为任何具有可访问源代码的 GUI 应用自动生成可投入生产、可由 Agent 控制的 CLI 界面。7 阶段流水线将 GUI 操作映射到后端 API,并生成基于 Click 的工具框架,支持 --json 输出模式、交互式 REPL 和 pytest 测试套件。
源代码:https://github.com/HKUDS/CLI-Anything 许可证:MIT | Python:3.10+ | 测试:11 个应用共 1,508 项通过
自我演进的技能:此技能会在使用过程中不断改进。如果说明有误、参数发生偏差,或需要使用变通方法,请立即修复此文件,不要拖延。仅针对真实且可复现的问题进行更新。
安装
方法 1:Claude Code Marketplace(推荐)
/plugin marketplace add HKUDS/CLI-Anything
/plugin install cli-anything
方法 2:手动安装 Claude Code
git clone https://github.com/HKUDS/CLI-Anything.git
cp -r CLI-Anything/cli-anything-plugin ~/.claude/plugins/cli-anything
# Reload in Claude Code:
/reload-plugins
方法 3:OpenCode — 全局
git clone https://github.com/HKUDS/CLI-Anything.git
cp CLI-Anything/opencode-commands/*.md ~/.config/opencode/commands/
cp CLI-Anything/cli-anything-plugin/HARNESS.md ~/.config/opencode/commands/
方法 4:OpenCode — 项目级
cp CLI-Anything/opencode-commands/*.md .opencode/commands/
cp CLI-Anything/cli-anything-plugin/HARNESS.md .opencode/commands/
生成新的 CLI 工具框架
# From local source path
/cli-anything ./gimp
# From GitHub URL (auto-cloned)
/cli-anything https://github.com/blender/blender
# Claude Code variant (plugin command)
/cli-anything ./inkscape
# OpenCode variant
/cli-anything ./libreoffice
所有命令
| 命令 | 平台 | 用途 |
|---|---|---|
/cli-anything <path-or-url> | Claude Code | 构建完整的 7 阶段工具框架 |
/cli-anything:refine <path> [focus] | Claude Code | 通过差距分析进行扩展 |
/cli-anything:test <path-or-url> | Claude Code | 运行测试 + 更新 TEST.md |
/cli-anything:validate <path-or-url> | Claude Code | 验证 HARNESS.md 标准 |
/cli-anything:list [--path dir] [--depth n] [--json] | Claude Code | 查找已安装的 CLI-Anything 工具 |
/cli-anything ./gimp | OpenCode | 构建工具框架 |
/cli-anything-refine ./gimp | OpenCode | 优化工具框架 |
/cli-anything-test ./gimp | OpenCode | 运行测试 |
/cli-anything-validate ./gimp | OpenCode | 验证标准 |
/cli-anything-list | OpenCode | 列出已安装的工具 |
针对重点进行优化
# Broad gap analysis
/cli-anything:refine ./gimp
# Targeted domain expansion
/cli-anything:refine ./gimp "batch processing and filters"
/cli-anything:refine ./blender "rendering pipeline and animations"
/cli-anything:refine ./libreoffice "spreadsheet formulas and macros"
安装生成的 CLI
cd <software>/agent-harness
pip install -e .
# Verify PATH entry created
which cli-anything-gimp
cli-anything-gimp --help
使用生成的 CLI
所有生成的 CLI 都采用一致的界面模式。
GIMP 示例
# Help
cli-anything-gimp --help
# Create project
cli-anything-gimp project new --width 1920 --height 1080 -o poster.json
# Machine-readable JSON output (for agent consumption)
cli-anything-gimp --json layer add -n "Background" --type solid --color "#1a1a2e"
# Interactive REPL
cli-anything-gimp
# Stateful workflow with --project flag
cli-anything-gimp --project poster.json layer add -n "Logo" --type group
cli-anything-gimp --project poster.json export render output.png --format png
LibreOffice 示例
# New document
cli-anything-libreoffice document new -o report.json --type writer
# Populate document
cli-anything-libreoffice --project report.json writer add-heading -t "Q1 Report" --level 1
cli-anything-libreoffice --project report.json writer add-table --rows 4 --cols 3
# Export
cli-anything-libreoffice --project report.json export render output.pdf -p pdf --overwrite
# JSON output
cli-anything-libreoffice --json document info --project report.json
Blender 示例
cli-anything-blender scene new -o scene.json
cli-anything-blender --project scene.json object add --type mesh --mesh-type CUBE
cli-anything-blender --project scene.json render image output.png --engine CYCLES
cli-anything-blender --json scene info --project scene.json
Inkscape 示例
cli-anything-inkscape document new --width 800 --height 600 -o design.json
cli-anything-inkscape --project design.json shape add rect --x 10 --y 10 --w 200 --h 100
cli-anything-inkscape --project design.json export render output.svg
cli-anything-inkscape --json document info --project design.json
输出模式
每条命令都支持两种输出模式:
| 模式 | 用法 | 适用对象 |
|---|---|---|
| 人类可读(默认) | cli-anything-gimp layer add ... | 终端 / 人类 |
| 机器可读 JSON | cli-anything-gimp --json layer add ... | AI Agent、脚本 |
--json 标志始终是第一个参数,位于所有子命令之前。
交互式 REPL
不带子命令运行 CLI 即可进入:
cli-anything-gimp
cli-anything-blender
cli-anything-libreoffice
REPL 功能:
- 50 层撤销 / 重做栈
- 持久化命令历史记录
- ANSI 256 色输出(软件专属强调色)
- 表格渲染、进度指示器
- 可交互使用所有子命令
运行测试
# Standard pytest run
cd <software>/agent-harness
python3 -m pytest cli_anything/<software>/tests/ -v
# Validate the installed binary is invoked (not just the module)
CLI_ANYTHING_FORCE_INSTALLED=1 python3 -m pytest cli_anything/<software>/tests/ -v -s
# Coverage
python3 -m pytest cli_anything/<software>/tests/ --cov=cli_anything/<software>
# Per-software examples
cd gimp/agent-harness && python3 -m pytest cli_anything/gimp/tests/ -v
cd blender/agent-harness && python3 -m pytest cli_anything/blender/tests/ -v
cd libreoffice/agent-harness && python3 -m pytest cli_anything/libreoffice/tests/ -v
环境变量
| 变量 | 用途 |
|---|---|
CLI_ANYTHING_FORCE_INSTALLED=1 | 强制测试使用实际安装的二进制文件(验证 which cli-anything-<software> 能正确解析,而不只是导入模块) |
支持的应用(共 11 个,1,508 项测试)
| 应用程序 | 类别 | 入口点 |
|---|---|---|
| GIMP | 创意(光栅) | cli-anything-gimp |
| Blender | 创意(3D) | cli-anything-blender |
| Inkscape | 创意(矢量) | cli-anything-inkscape |
| Audacity | 媒体(音频) | cli-anything-audacity |
| LibreOffice | 生产力 | cli-anything-libreoffice |
| OBS Studio | 媒体(直播) | cli-anything-obs-studio |
| Kdenlive | 媒体(视频) | cli-anything-kdenlive |
| Shotcut | 媒体(视频) | cli-anything-shotcut |
| Zoom | 通信 | cli-anything-zoom |
| Draw.io | 图表绘制 | cli-anything-drawio |
| AnyGen | AI 内容 | cli-anything-anygen |
7 阶段流水线(HARNESS.md)
/cli-anything 在底层触发的流程:
| 阶段 | 名称 | 执行内容 |
|---|---|---|
| 1 | 源代码获取 | 接受本地路径或 GitHub URL;必要时克隆 |
| 2 | 代码库分析 | 映射 GUI 操作 → 后端 API;盘点现有 CLI 工具;记录数据模型 |
| 3 | CLI 架构设计 | 选择交互模式(有状态 REPL + 子命令);定义命令组;规划 --json 输出 |
| 4 | 实现 | 构建基于 Click 的 CLI,使用 cli_anything.<software> 命名空间;通过共享的 ReplSkin 实现 REPL |
| 5 | 测试规划 | 编写 TEST.md,在编写代码前列出计划的测试清单 |
| 6 | 测试实现 | 单元测试(合成数据)+ E2E 测试(真实软件输出)+ 子进程测试 |
| 7 | 发布到 PyPI | 使用 find_namespace_packages() 编写 setup.py;设置 console_scripts 入口点 |
基本规则:CLI 必须将渲染任务委托给真实软件,绝不能用 Python 重新实现功能。目标软件是硬依赖项。
生成的 Harness 结构
每个生成的 CLI 都采用以下布局(PEP 420 命名空间包):
<software>/agent-harness/
├── setup.py # find_namespace_packages(), entry_points
├── <SOFTWARE>.md # Software-specific SOP
└── cli_anything/ # NO __init__.py (namespace package)
└── <software>/
├── __init__.py
├── __main__.py
├── <software>_cli.py # Main Click entry point
├── core/ # Domain modules (project, session, export, ...)
├── utils/
│ └── repl_skin.py # Shared REPL UI (copied from plugin)
└── tests/
├── TEST.md # Test inventory (written in phase 5)
├── test_core.py # Unit tests
└── test_full_e2e.py # E2E + subprocess tests
为何使用命名空间包:cli_anything/ 中没有 __init__.py,因此多个单独安装的 CLI 可以在同一 cli_anything.* 命名空间下共存,互不冲突。
输出验证标准
测试通过魔数和内容分析验证真实输出:
| 输出类型 | 验证方式 |
|---|---|
%PDF- 魔数字节 + 非零大小 | |
| OOXML(.docx、.xlsx) | ZIP 结构验证 |
| CSV | 数据行数 + 列检查 |
| 图像 | Pillow 像素值分析 |
| 音频 | RMS 电平检查(非静音) |
前置条件清单
运行 /cli-anything <path> 前:
- 已安装 Python 3.10+
- 已安装目标软件(硬依赖项——渲染时将调用该软件)
- 可以访问源代码(本地路径或公开的 GitHub URL)
- 可用
click>=8.0.0(通过pip install -e .安装) - 可用
Pillow>=10.0.0、prompt-toolkit>=3.0.0 - 可用
pytest以运行测试
关键文件参考
| 文件 | 用途 |
|---|---|
cli-anything-plugin/HARNESS.md | 完整方法文档(30K 个字符) |
cli-anything-plugin/QUICKSTART.md | 快速入门指南 |
cli-anything-plugin/repl_skin.py | 共享 REPL UI 类(18K,ANSI 256 色) |
cli-anything-plugin/commands/cli-anything.md | /cli-anything 斜杠命令定义 |
cli-anything-plugin/commands/refine.md | /cli-anything:refine 命令 |
cli-anything-plugin/commands/test.md | /cli-anything:test 命令 |
cli-anything-plugin/commands/validate.md | /cli-anything:validate 命令 |
cli-anything-plugin/commands/list.md | /cli-anything:list 命令 |
执行后反思
此技能完成后,关闭前请检查:
- 命令是否成功? — 如果没有,请修复导致失败的指令或错误表。
- 参数或输出是否发生变化? — 如果底层工具的接口有所变化,请相应更新用法示例和参数表。
- 是否需要变通处理? — 如果你不得不临时变通(使用不同标志、增加额外步骤),请更新此 SKILL.md,避免下次调用时遇到同样的问题。
仅在问题真实且可复现时更新,不要臆测。