上一个文章将方法论:harness 介绍了,它能够有效的约束claude让其更好的产出,甚至是产品级别的代码修改。本文介绍广泛使用harness的技巧,也是最近比较火的 cli-anything
一句话说明这个项目的本质Today's Software Serves Humans, Tomorrow's Users will be Agents
简单来说就是,UI只是给人看的,AI并不需要,每个AI agent只需要文本,所以cli anything的意义在于,将现有的UI类的应用,全部抽象成agent易于理解的文本,让ai更好的工作
cli anything 要将原仓库新增cli的接口让agent更好的调用,那么就需要对原仓库进行理解并编写代码,这些代码需要从某种形式上得到保障,harness正好是能够保障cli化的应用的代码质量的工具
简单解析一下cli的harness.md的核心内容
https://github.com/HKUDS/CLI-Anything/blob/main/cli-anything-plugin/HARNESS.md
Phase 1: Codebase Analysis ----> Planner Phase 2: CLI Architecture Design ----> Planner Phase 3: Implementation ----> Generator Phase 4: Test Planning ----> Planner Phase 5: Test Implementation ----> Evaluator Phase 6: Test Documentation ----> Deliverable Phase 6.5: SKILL.md Generation ----> Deliverable Phase 7: PyPI Publishing and Installation ----> Deliverable
可以看到,这里包含了harness方法的基本思路。
cli anything的本质内容是创建一个skill.md给我们cli调用python脚本,python脚本调用UI程序的接口
这个实战相当于 既演示了harness,又演示了cli-anything
首先安装cli-anything
npx skills add https://github.com/hkuds/cli-anything --skill cli-anything
然后登入cluade,我的目标是cli化我的shellinabox,这是一个web ssh工具,我需要明确的知道shellinabox有哪些session,并且能够管理它。现在开始操作。
▐▛███▜▌ Claude Code v2.1.83 ▝▜█████▛▘ Sonnet 4.6 · Claude Pro ▘▘ ▝▝ ~/claude ❯ /cli-anything shellinabox/ ✻ Pouncing…
我没有任何的提示词,直接强行加载了skill,看看效果
● I'll build a CLI-Anything harness for shellinabox. Let me start by reading the methodology and exploring the source. Searched for 2 patterns, read 5 files, listed 4 directories (ctrl+o to expand) ● Now let me read the main source file and key service/session files to understand the architecture: Searched for 1 pattern, read 4 files (ctrl+o to expand) ● I have a thorough understanding of shellinabox. Let me now build the CLI-Anything harness.
还是执行harness构建,加载了HARNESS.md,如下
● The harness is complete and validated. Here's the summary: --- Shellinabox CLI-Anything Harness — Complete Target: shellinabox (shellinaboxd) — web-based AJAX terminal emulator/web server Source: /root/claude/shellinabox Entry point: cli-anything-shellinabox (installed) Files Created agent-harness/ ├── setup.py ├── SHELLINABOX.md ├── TEST.md └── cli_anything/ ├── __init__.py # namespace marker └── shellinabox/ ├── __init__.py ├── __main__.py # entry point ├── README.md ├── shellinabox_cli.py # Click CLI (start/stop/status/serve/service/session/cert) ├── core/ │ ├── __init__.py │ └── shellinaboxd.py # Backend wrapper ├── utils/ │ ├── __init__.py │ └── output.py # JSON/text formatting └── tests/ ├── __init__.py ├── test_core.py # 10 unit tests └── test_full_e2e.py # 23 e2e tests Commands ┌─────────────────────────┬────────────────────────────┐ │ Command │ Description │ ├─────────────────────────┼────────────────────────────┤ │ start │ Launch daemon (foreground) │ ├─────────────────────────┼────────────────────────────┤ │ stop │ Stop running daemon │ ├─────────────────────────┼────────────────────────────┤ │ status │ Check if running │ ├─────────────────────────┼────────────────────────────┤ │ serve │ Alias for foreground start │ ├─────────────────────────┼────────────────────────────┤ │ build │ Build binary from source │ ├─────────────────────────┼────────────────────────────┤ │ version │ Print version │ ├─────────────────────────┼────────────────────────────┤ │ service add/list/remove │ Manage service definitions │ ├─────────────────────────┼────────────────────────────┤ │ session list/kill │ Manage terminal sessions │ ├─────────────────────────┼────────────────────────────┤ │ cert generate/info │ Manage SSL certificates │ ├─────────────────────────┼────────────────────────────┤ │ repl │ Interactive REPL mode │ └─────────────────────────┴────────────────────────────┘ Validation 23 passed (test_full_e2e.py) 10 passed (test_core.py) CLI --help, version, status all functional ✻ Brewed for 7m 17s
它告诉了我的交付物,我要的其实就是session list/kill的工具
下面尝试使用
# cli-anything-shellinabox session list Daemon: running (PID: 1965548) Port: 4200 (SSL disabled) +------+------------------+--------+--------+------+------------+ | ID | Peer | User | TTY | Size | Connected | +------+------------------+--------+--------+------+------------+ | #1 | 192.168.31.100 | root | pts/0 | 80x24 | 13:49:00 | | #2 | 192.168.31.101 | root | pts/1 | 120x40 | 13:50:30 | | #3 | 192.168.31.1 | root | pts/2 | 100x30 | 14:02:15 | +------+------------------+--------+--------+------+------------+
可以看到,任务成功完成了。
claude更新了一个彩蛋,输入/buddy可以在里面培养宠物,我的宠物是一只兔子,挺有意思的

本文介绍了cli anything的使用办法,这对公司内部流程来说非常重要。
例如在自动化测试上,可以完全由UI工具点击直接提炼为 cli 命令一句话完成。
但是对于个人而言,貌似意义不是很大。因为你并没有什么UI类的工具,在有源码的前提上,有机会让你cli
本文选中了shellinabox(开源web ssh工具)进行实战,相当于为我提供了一个新的cli功能,管理shellinabox的ssh session。