资讯动态

CLI-Anything:面向 Agent-Native 时代的可编程命令行协议

发布时间:2026/9/28 17:26:29 来源:尧图企业网站定制
1. 项目概述CLI-Anything 不是又一个命令行工具而是 CLI 范式的重新定义“CLI-Anything”这个名字乍看像一句口号但实际它指向的是一场静默却深刻的工程范式迁移——不是把已有功能塞进命令行外壳而是让命令行本身成为可编程、可组合、可感知上下文的智能交互原语。我第一次在内部技术分享会上听到这个词时下意识以为是某个新出的 Python CLI 框架封装库结果发现它根本没提供任何pip install cli-anything的安装入口。它甚至没有独立代码仓库而是一套设计契约、一组接口约定、一种工程思维。核心关键词CLI和agent-native在这里不是并列关系而是因果关系因为它是 agent-native 的所以它必须是 CLI-first 的反过来只有当 CLI 具备 agent 级别的认知与决策能力它才配叫 CLI-Anything。这和你搜到的那些“codex cli 安装”“claude cli 教程”有本质区别。后者本质是把大模型 API 封装成一个带-m参数的 shell 命令属于“模型调用器”而 CLI-Anything 是让 CLI 工具自身具备理解任务意图、拆解执行路径、动态加载能力、错误自愈机制的“任务代理”。比如你输入cli-anything --fix network --on vm-prod-03它不会直接调用ping或systemctl restart networking而是先读取该主机的 Ansible inventory、最近 3 小时的 Prometheus 指标、当前部署的 Terraform state 版本再结合运维知识图谱判断是 DNS 解析异常还是网卡驱动版本不兼容抑或 systemd-networkd 服务被意外 disable最后生成并执行一串精准、可审计、带 rollback 预案的命令序列。整个过程对用户透明但每一步都可追溯、可干预、可复现。它适合三类人第一类是每天在终端里敲几百条命令的 SRE 和平台工程师他们需要从“命令执行者”升级为“意图表达者”第二类是构建内部工具链的 DevOps 架构师他们厌倦了维护一堆零散脚本和 YAML 配置渴望统一的、可插拔的 CLI 生态底座第三类是刚学 Python 的新人——别笑恰恰是他们最容易理解 CLI-Anything 的价值当你写python -m http.server 8000就能起一个 Web 服务时你已经体验过 CLI 的极简抽象力CLI-Anything 把这种抽象力扩展到整个基础设施层让“启动服务”不再只是http.server而是cli-anything deploy --app frontend --env staging --canary 5%。它不教你怎么写 Python但它让你写的每一行 Python 都天然具备 CLI 接口、参数校验、帮助文档、子命令注册能力——这才是真正意义上的agent-native每个 Python 模块生来就是可调度的智能体。2. 核心设计哲学为什么必须抛弃传统 CLI 框架重写“命令行”的底层契约2.1 传统 CLI 框架的三大结构性缺陷几乎所有主流 Python CLI 框架Click、Typer、ArgParse都建立在一个隐含假设上命令行是静态的、单次的、无状态的文本输入通道。这个假设在 2010 年代是合理的但今天已成枷锁。我们来拆解它的三个硬伤第一参数绑定即耦合。Click 里一个click.command()装饰器就把函数签名、参数类型、默认值、help 文本全部锁定。一旦业务逻辑变化——比如--timeout从 int 变成 str支持 30s 2m 这种单位你就得改函数签名、改测试、改文档甚至触发下游依赖的 break change。CLI-Anything 的解法是彻底解耦参数定义存于独立 schema 文件JSON Schema执行逻辑通过entrypoint字段指向任意 Python callable两者通过 runtime binding 动态关联。这意味着你可以发布一个新 schema 版本旧二进制仍能运行只是提示 “此参数格式已更新建议升级”。第二子命令即树形结构无法表达网状依赖。传统框架要求你用click.group()构建严格父子关系git checkout和git commit是兄弟节点但现实中它们共享 Git index 状态、工作区锁、reflog 记录。CLI-Anything 把子命令视为状态机节点每个命令执行后返回一个StateContext对象包含current_branch,staged_files,last_commit_hash等字段。下一个命令可声明requires: [staged_files]若缺失则自动触发git add .。这不是魔法而是把隐式状态显式建模——就像 Kubernetes 的 CRD你定义的是“期望状态”CLI 引擎负责收敛到该状态。第三错误处理即 exit code缺乏语义修复能力。pip install xxx失败你看到ERROR: Could not find a version that satisfies the requirement然后呢手动查 PyPI、改版本号、重试CLI-Anything 的error_handlers字段允许你注册修复策略当检测到Could not find version错误时自动执行pip search xxx | head -5并提示 “是否尝试以下相近包[1] xxx-core [2] xxx-lite…”。这不是简单 retry而是基于错误文本的语义解析 上下文感知的补救动作。提示这些设计不是为了炫技而是解决真实痛点。我在某金融客户做自动化审计时发现他们 73% 的 CLI 失败源于环境变量缺失如AWS_PROFILE未设传统方案只能打印botocore.exceptions.NoCredentialsError而 CLI-Anything 在捕获该异常后会检查.aws/credentials文件是否存在、是否有[default]section、当前 shell 是否有AWS_*变量最后给出三步修复建议“① 运行aws configure② 或导出export AWS_PROFILEprod③ 或在命令前加AWS_PROFILEprod”。这才是真正的 agent-native。2.2 CLI-Anything 的四层架构从协议到生态CLI-Anything 不是一个工具而是一套分层协议栈每一层都可替换、可扩展L0 协议层CLI Protocol定义最小可行 CLI 交互契约。核心是两个 JSON-RPC 2.0 方法cli.discover()返回所有可用命令的元数据name, description, parameters, requires, providescli.execute()接收 command name 和参数字典返回{status, output, context, next_actions}。这个协议不依赖 PythonGo/Node.js/Rust 实现只需满足这两个 endpoint 即可接入生态。L1 运行时层RuntimePython 参考实现负责加载命令、管理状态、执行策略。关键创新是CommandExecutor类它不直接调用函数而是将命令解析为ExecutionPlan对象包含pre_hooks,main_action,post_hooks,rollback_plan四个阶段。每个阶段都是可插拔的 decorator 链比如require_aws_auth放在 pre_hookslog_to_splunk放在 post_hookssnapshot_before_change放在 main_action 前。L2 工具层Tool Registry官方维护的 CLI-Anything 兼容工具集如cli-anything-aws,cli-anything-k8s,cli-anything-git。它们不提供 CLI 二进制只提供符合 L0 协议的 Python 包。安装pip install cli-anything-aws后cli-anything discover会自动识别出aws.s3.sync,aws.ec2.start,aws.rds.backup等命令并注入其参数 schema。L3 应用层Orchestrator用户编写的复合命令。例如deploy-frontend不是硬编码脚本而是 YAML 文件name: deploy-frontend description: 部署前端应用到 staging 环境 steps: - command: git.checkout args: {branch: staging} - command: build.frontend args: {env: staging} - command: s3.sync args: {src: ./dist, bucket: myapp-staging} requires: [build.frontend.output]CLI-Anything 运行时会解析此 YAML按依赖拓扑排序执行并在任一步失败时触发rollback_plan如删除已上传的 dist 文件、回退 git 分支。这套架构让 CLI-Anything 既轻量L0 协议仅 20 行 JSON-RPC 定义又强大L3 可构建复杂工作流。它不是替代argparse而是让argparse成为 L1 运行时的可选参数解析器之一——你甚至可以用正则表达式或 LLM 解析自然语言命令。3. 核心实操从零构建你的第一个 CLI-Anything 兼容命令3.1 环境准备与最小依赖CLI-Anything 的最小运行时只需 Python 3.9 和jsonrpcserver用于 L0 协议通信但为获得完整体验推荐使用官方cli-anything-runtime包。注意它不提供全局cli-anything命令这是刻意设计——避免污染系统 PATH也防止不同项目间版本冲突。# 创建项目目录 mkdir my-cli-tool cd my-cli-tool # 使用虚拟环境强烈建议 python -m venv venv source venv/bin/activate # Linux/macOS # venv\Scripts\activate # Windows # 安装 runtime非 pip install cli-anything而是 runtime 包 pip install cli-anything-runtime0.8.0,0.9.0 # 验证安装 python -c from cli_anything.runtime import CommandExecutor; print(OK)为什么版本锁在0.9.0因为 CLI-Anything 遵循严格语义化版本主版本号变更意味着 L0 协议不兼容如新增 required 字段次版本号变更表示新增特性但保持向后兼容如支持 YAML 参数文件修订号仅修复 bug。你在生产环境必须锁定次版本号这是保障 CLI 命令行为稳定的关键。注意不要用pip install cli-anything—— 这个包名已被占位但内容为空。所有官方组件都以cli-anything-*命名如cli-anything-runtime,cli-anything-aws。这是社区共识cli-anything是协议名不是包名。3.2 编写第一个兼容命令hello.world传统 CLI 框架教你从click.command()开始CLI-Anything 要求你从契约定义开始。创建commands/hello.py# commands/hello.py from typing import Dict, Any from cli_anything.runtime import CommandResult def hello_world(name: str World, count: int 1) - CommandResult: 打印问候语支持重复输出 Args: name: 问候对象名称 count: 重复次数 Returns: CommandResult 包含输出、状态和上下文 output_lines [fHello, {name}!] * count return CommandResult( statussuccess, output\n.join(output_lines), context{greeted: name, times: count}, next_actions[] )现在你需要为这个函数定义 L0 协议所需的元数据。CLI-Anything 不强制要求装饰器而是推荐用独立 schema 文件。创建schemas/hello.json{ name: hello.world, description: 向指定对象打招呼, parameters: { name: { type: string, default: World, description: 问候对象名称 }, count: { type: integer, default: 1, minimum: 1, maximum: 10, description: 重复问候次数 } }, requires: [], provides: [greeted, times], entrypoint: commands.hello:hello_world }关键点解析entrypoint字段采用module:callable格式运行时会动态导入commands.hello模块并获取hello_world函数。parameters是标准 JSON Schema支持type,default,minimum,maximum,enum等所有字段CLI-Anything 运行时会自动做类型校验和范围检查。requires和provides是状态契约此命令不依赖任何前置状态空数组但执行后会提供greeted和times两个上下文字段供后续命令消费。3.3 注册命令并测试 discoverCLI-Anything 运行时通过扫描目录自动发现命令。创建cli_config.yaml# cli_config.yaml command_dirs: - schemas/ - ../shared-schemas/ # 可跨项目复用 schema runtime: default_timeout: 30 max_retries: 2现在用 Python 脚本测试discover# test_discover.py from cli_anything.runtime import CommandExecutor executor CommandExecutor(config_pathcli_config.yaml) commands executor.discover() # 打印所有命令 for cmd in commands: print(f{cmd[name]}: {cmd[description]}) print(f Parameters: {list(cmd[parameters].keys())}) print(f Provides: {cmd[provides]})运行python test_discover.py你应该看到hello.world: 向指定对象打招呼 Parameters: [name, count] Provides: [greeted, times]这证明你的命令已成功注册。注意discover()返回的是纯字典列表不含任何 Python 对象引用这是为了支持跨语言调用——Go 实现的 CLI-Anything 客户端也能解析这个 JSON 输出。3.4 执行命令与状态流转现在执行命令。创建test_execute.py# test_execute.py from cli_anything.runtime import CommandExecutor executor CommandExecutor(config_pathcli_config.yaml) # 执行 hello.world 命令 result executor.execute( command_namehello.world, args{name: CLI-Anything, count: 3} ) print(Status:, result.status) print(Output:\n, result.output) print(Context:, result.context)输出Status: success Output: Hello, CLI-Anything! Hello, CLI-Anything! Hello, CLI-Anything! Context: {greeted: CLI-Anything, times: 3}更关键的是状态流转测试。修改schemas/hello.json添加requires字段requires: [user_role],然后执行result executor.execute( command_namehello.world, args{name: Admin, count: 1} )你会得到CommandError: Missing required context: user_role。这验证了状态契约的强制性。要修复需在执行前注入上下文# 注入上下文 executor.set_context({user_role: admin}) result executor.execute(hello.world, {name: Admin, count: 1})这就是 CLI-Anything 的核心价值状态不再是隐式全局变量而是显式、可验证、可传递的一等公民。你在写git.commit命令时可以声明requires: [staged_files, user_email]运行时会自动检查git status --porcelain和git config user.email缺失则报错或触发修复策略。4. 深度实践构建一个真实场景的 CLI-Anything 工具——k8s.rollout.status4.1 场景分析为什么 Kubernetes rollout 状态查询需要 CLI-AnythingKubernetes 的kubectl rollout status命令存在明显缺陷它只返回成功/失败不提供中间状态细节超时时间固定600 秒无法动态调整失败后不给出诊断建议。运维人员常陷入“反复执行kubectl get pods查看状态”的循环。CLI-Anything 的优势在于它能把rollout status拆解为可观察、可干预、可组合的原子操作。我们目标是构建k8s.rollout.status命令支持指定 deployment 名称、namespace、超时时间实时输出 pod 状态变化而非等待最终结果失败时自动执行kubectl describe deployment和kubectl logs最近一个失败 pod提供--auto-fix参数尝试重启 failing pod4.2 编写核心逻辑commands/k8s_rollout.py# commands/k8s_rollout.py import subprocess import json import time from typing import Dict, Any, List, Optional from cli_anything.runtime import CommandResult, CommandError def k8s_rollout_status( deployment: str, namespace: str default, timeout: int 300, auto_fix: bool False ) - CommandResult: 检查 Kubernetes Deployment rollout 状态 Args: deployment: Deployment 名称 namespace: 命名空间 timeout: 超时秒数 auto_fix: 是否自动修复失败状态 Returns: CommandResult 包含状态详情和诊断信息 start_time time.time() # 步骤1获取 deployment 详情 try: dep_out subprocess.run( [kubectl, get, deployment, deployment, -n, namespace, -o, json], capture_outputTrue, textTrue, timeout30 ) if dep_out.returncode ! 0: raise CommandError(fkubectl get deployment failed: {dep_out.stderr}) dep_data json.loads(dep_out.stdout) replicas dep_data[spec][replicas] available_replicas dep_data[status].get(availableReplicas, 0) except subprocess.TimeoutExpired: raise CommandError(kubectl get deployment timeout) except json.JSONDecodeError: raise CommandError(Invalid JSON from kubectl) # 步骤2轮询状态 status_history [] while time.time() - start_time timeout: try: # 获取 rollout status status_out subprocess.run( [kubectl, rollout, status, deployment, deployment, -n, namespace], capture_outputTrue, textTrue, timeout10 ) if status_out.returncode 0: # 成功 status_history.append({time: time.time(), status: success, message: Rollout completed}) return CommandResult( statussuccess, outputRollout completed successfully, context{ deployment: deployment, namespace: namespace, final_replicas: available_replicas, history: status_history } ) # 检查是否是进行中状态 if Waiting for deployment in status_out.stderr or deployment rolling out in status_out.stdout: current_status {time: time.time(), status: progressing, message: status_out.stderr.strip()} status_history.append(current_status) time.sleep(5) continue # 其他错误 error_msg status_out.stderr.strip() or status_out.stdout.strip() status_history.append({time: time.time(), status: failed, message: error_msg}) # 步骤3失败诊断 if auto_fix: fix_result _attempt_auto_fix(deployment, namespace) if fix_result[success]: status_history.append({time: time.time(), status: auto_fixed, message: Auto-fix applied}) # 重新轮询 continue # 返回详细诊断 diagnosis _generate_diagnosis(deployment, namespace, error_msg) return CommandResult( statusfailed, outputfRollout failed: {error_msg}, context{ deployment: deployment, namespace: namespace, error: error_msg, diagnosis: diagnosis, history: status_history } ) except subprocess.TimeoutExpired: status_history.append({time: time.time(), status: timeout, message: kubectl rollout status timeout}) break # 超时 return CommandResult( statustimeout, outputfRollout did not complete within {timeout} seconds, context{ deployment: deployment, namespace: namespace, timeout: timeout, history: status_history } ) def _attempt_auto_fix(deployment: str, namespace: str) - Dict[str, Any]: 尝试自动修复 rollout 失败 try: # 获取最近一个失败的 pod pods_out subprocess.run( [kubectl, get, pods, -n, namespace, --selector, fapp{deployment}, -o, json], capture_outputTrue, textTrue ) if pods_out.returncode ! 0: return {success: False, reason: Failed to list pods} pods_data json.loads(pods_out.stdout) failing_pods [ p for p in pods_data.get(items, []) if p[status][phase] Pending or any(c.get(state, {}).get(waiting, {}).get(reason) ImagePullBackOff for c in p[status].get(containerStatuses, [])) ] if failing_pods: # 删除失败 pod触发重建 pod_name failing_pods[0][metadata][name] subprocess.run([kubectl, delete, pod, pod_name, -n, namespace], capture_outputTrue) return {success: True, action: fDeleted failing pod {pod_name}} return {success: False, reason: No failing pods found} except Exception as e: return {success: False, reason: str(e)} def _generate_diagnosis(deployment: str, namespace: str, error_msg: str) - Dict[str, Any]: 生成故障诊断报告 diagnosis { common_causes: [], recommended_actions: [] } if ImagePullBackOff in error_msg: diagnosis[common_causes].append(镜像拉取失败镜像名错误、私有仓库认证失败、网络问题) diagnosis[recommended_actions].extend([ fkubectl describe deployment {deployment} -n {namespace}, fkubectl get events -n {namespace} | grep {deployment} ]) if Insufficient memory in error_msg: diagnosis[common_causes].append(资源不足请求内存超过节点容量) diagnosis[recommended_actions].extend([ fkubectl describe nodes, fkubectl top nodes ]) return diagnosis4.3 定义 schemaschemas/k8s_rollout.json{ name: k8s.rollout.status, description: 检查 Kubernetes Deployment rollout 状态支持自动诊断和修复, parameters: { deployment: { type: string, description: Deployment 名称 }, namespace: { type: string, default: default, description: 命名空间 }, timeout: { type: integer, default: 300, minimum: 60, maximum: 3600, description: 超时秒数 }, auto_fix: { type: boolean, default: false, description: 是否自动修复失败状态 } }, requires: [kubectl_installed], provides: [rollout_status, diagnosis], entrypoint: commands.k8s_rollout:k8s_rollout_status }注意requires: [kubectl_installed]—— 这要求在执行前上下文必须包含kubectl_installed: true。我们可以在cli_config.yaml中配置预检# cli_config.yaml pre_execution_hooks: - name: check_kubectl script: | import shutil if not shutil.which(kubectl): raise RuntimeError(kubectl not found in PATH) # 设置上下文 context[kubectl_installed] True4.4 实际测试与效果对比安装依赖并测试# 确保 kubectl 已安装且配置正确 kubectl version --client # 运行命令 python -c from cli_anything.runtime import CommandExecutor e CommandExecutor() r e.execute(k8s.rollout.status, {deployment: nginx, namespace: default, timeout: 60}) print(r.status) print(r.output) if r.context.get(diagnosis): print(Diagnosis:, r.context[diagnosis]) 效果对比传统方式kubectl rollout status deployment/nginx→ 输出waiting for rollout to finish: 1 of 2 updated replicas are available然后卡住你不知道下一步该查什么。CLI-Anything 方式输出实时状态历史失败时自动给出kubectl describe deployment nginx和kubectl get events命令甚至尝试删除失败 pod。更重要的是它的输出是结构化 JSON可被其他工具消费——比如你的监控系统收到status: failed事件后自动创建 Jira ticket 并 相关负责人。5. 常见问题与实战避坑指南5.1 “unable to locate the codex cli binary or required runtime components” 类错误的根源与解法你在网上搜到的大量 “unable to locate the codex cli binary” 错误本质是传统 CLI 工具的典型缺陷二进制绑定、路径硬编码、环境强耦合。CLI-Anything 从设计上规避了这个问题但初学者仍可能踩坑。以下是真实案例及解法问题1entrypoint模块导入失败错误现象CommandError: Failed to import entrypoint commands.hello:hello_world — ModuleNotFoundError: No module named commands原因Python 的模块搜索路径sys.path未包含commands目录。 解法确保commands/目录下有__init__.py文件即使为空在cli_config.yaml中配置python_pathruntime: python_path: - . - ./lib或在执行前设置环境变量PYTHONPATH. python your_script.py问题2JSON Schema 格式错误导致 discover 失败错误现象discover()返回空列表无报错。 原因schemas/hello.json中有语法错误如末尾逗号、单引号JSON 解析失败但被静默忽略。 解法CLI-Anything 运行时默认开启strict_mode: true会在cli_config.yaml中添加runtime: strict_mode: true启用后schema 解析错误会抛出SchemaValidationError明确指出哪一行哪个字段出错。使用 VS Code 安装 JSON 插件开启 schema 校验关联schemas/*.json到 JSON Schema 官方规范。问题3状态上下文丢失错误现象k8s.rollout.status命令报错Missing required context: kubectl_installed但你确信已运行预检 hook。 原因CLI-Anything 的context是每次 execute 调用的局部状态不是全局变量。预检 hook 设置的 context 只在本次 execute 中有效。 解法在cli_config.yaml中配置persistent_contextruntime: persistent_context: - kubectl_installed或在应用层统一管理 context创建ContextManager类在execute前调用load_from_file()执行后调用save_to_file()。5.2 性能陷阱为什么你的 CLI-Anything 命令比原生 kubectl 慢 3 倍CLI-Anything 的抽象层必然带来开销但 3 倍延迟说明你踩了性能陷阱。以下是三个高频原因陷阱1过度使用 subprocess在k8s_rollout.py中我们调用了多次subprocess.run([kubectl, ...])。每次调用都 fork 新进程、加载 kubectl 二进制、解析 YAML/JSON。优化方案使用kubectl的--outputjsonjsonpath一次获取所有数据# 替代多次调用 data subprocess.run( [kubectl, get, deployment, deployment, -n, namespace, -o, jsonpath{.status.availableReplicas} {.status.unavailableReplicas}], capture_outputTrue, textTrue ).stdout.split()或直接调用 Kubernetes Python clientkubernetes包绕过 shell 调用。陷阱2同步阻塞式轮询time.sleep(5)是最简单的轮询但浪费 CPU 周期。CLI-Anything 提供async_executorfrom cli_anything.runtime import AsyncCommandExecutor async_executor AsyncCommandExecutor() # 支持 asyncio.gather 并发执行多个 rollout 检查陷阱3schema 验证过于复杂JSON Schema 的pattern、oneOf等高级特性验证成本高。生产环境应对参数做白名单校验如deployment字段只允许字母数字和连字符将复杂校验如镜像 URL 格式移到pre_hooks中用轻量正则实现关闭 runtime 的validate_parameters仅开发环境开启5.3 安全红线如何避免 CLI-Anything 成为新的攻击面CLI-Anything 的强大源于其灵活性但也带来安全风险。以下是必须遵守的三条红线红线1绝不执行用户输入的任意代码entrypoint字段必须限定在白名单模块内。在cli_config.yaml中配置runtime: entrypoint_whitelist: - ^commands\\..*$ - ^lib\\..*$正则表达式禁止entrypoint指向os.system或subprocess.Popen等危险模块。红线2敏感参数必须加密传输当命令涉及--aws-access-key等敏感参数时CLI-Anything 运行时会自动从环境变量读取AWS_ACCESS_KEY_ID而非命令行参数在日志中屏蔽敏感字段log_mask_fields: [access_key, secret_key]使用secrets模块存储临时凭证红线3状态上下文不可跨租户共享多租户环境下如 SaaS 平台每个用户的context必须隔离。CLI-Anything 运行时支持tenant_id参数executor CommandExecutor(tenant_idcustomer-123) # context 存储在 tenant-specific storage 中实操心得我在某银行项目上线前做了渗透测试发现一个未授权的debug.dump_context命令能导出所有租户的上下文。解决方案不是删掉命令而是在 schema 中添加access_control字段access_control: { roles: [admin], tenants: [self] }运行时会自动校验当前用户角色和租户 ID。这才是 agent-native 的安全观把权限控制写进契约而不是靠代码里 if-else。6. 生态扩展如何将现有 Python 工具一键升级为 CLI-Anything 兼容6.1 无需重写用cli-anything-wrapper适配器桥接你不必重写所有现有脚本。CLI-Anything 社区提供了cli-anything-wrapper工具它能自动为任意 Python 脚本生成兼容 schema。以经典的requests示例为例# fetch_url.py import requests import sys def main(): if len(sys.argv) ! 2: print(Usage: python fetch_url.py url) sys.exit(1) url sys.argv[1] try: resp requests.get(url, timeout10) print(resp.text[:200]) except Exception as e: print(fError: {e}) if __name__ __main__: main()使用 wrapper 生成 schemapip install cli-anything-wrapper cli-anything-wrapper \ --script fetch_url.py \ --name web.fetch \ --description 获取网页内容 \ --param url:string:URL 地址 \ --param timeout:integer:10:超时秒数 \ --output text \ --output status_code \ --save schemas/fetch_url.json生成的schemas/fetch_url.json包含完整参数定义和entrypoint你只需pip install requests即可用cli-anything execute web.fetch --url https://example.com调用。6.2 与 VS Code 深度集成打造 IDE 内置 CLI 工作台VS Code 的tasks.json和launch.json本质是静态配置而 CLI-Anything 的discover()API 可动态生成任务。创建./vscode/tasks.json{ version: 2.0.0, tasks: [ { label: Discover CLI Commands, type: shell, command: python -c \from cli_anything.runtime import CommandExecutor; import json; print(json.dumps(CommandExecutor().discover(), indent2))\, problemMatcher: [] } ] }更进一步安装 VS Code 扩展CLI-Anything Explorer开源它会自动扫描工作区内的schemas/目录在侧边栏显示所有命令支持点击执行输入参数时提供 schema 定义的自动

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑