☰
Warp Oz 云 Agent 集成第三方编程 Agent CLI 实战指南:安装、认证、非交互执行与产物上报
2026/10/1 23:26:16 网站建设 项目流程
  • 桌面应用
  • 开发者工具
  • 人工智能
  • AI 应用
  • AI Agent
  • 代码智能体

【免费下载链接】warp

Warp is an agentic development environment, born out of the terminal.

项目地址:https://gitcode.com/GitHub_Trending/wa/warp
点击查看免费下载

导读

本文围绕 Warp 开源仓库中oz-platform技能包的核心参考文档 third-party-clis.md,系统讲解如何在 Warp 的 Oz 云 Agent 环境中安装、认证并驱动 Claude Code、Codex、Gemini CLI、Amp、Copilot CLI、OpenCode 等主流第三方编程 Agent CLI。读完本文,你将掌握每一款 CLI 的非交互执行模式、密钥注入方式、产物(PR/分支)上报机制,并能直接套用文中的委托 Prompt 模板,把编码类任务完整交给第三方 CLI 执行。


一、定位:Oz 云 Agent 为什么要驱动第三方 CLI

Oz 是 Warp 的云 Agent 平台:通过agent run-cloud启动云端 Agent,在预构建的 Docker 环境(environment)中运行,并可注入密钥、调度周期任务。第三方编程 Agent CLI(如 Claude Code、Codex)是另一类独立工具,它们在-agents标记的预构建镜像中已预装。

关键事实(来自 SKILL.md 与本文档):

  • 带-agents后缀的镜像(如warpdotdev/dev-base:latest-agents、warpdotdev/dev-rust:1.85-agents)预装了 Claude Code、Codex 与 Gemini CLI;
  • 不带-agents的基础标签不包含任何编程 Agent CLI,需要由 Setup 命令自行安装;
  • 云环境(environment)不存储密钥值(如 API Key),必须用secret create命令将密钥注入为环境变量;
  • 文中所有引用 Warp CLI 的命令,其二进制名应替换为父级 skill 中定义的{{warp_cli_binary_name}}值(仓库中 CLI 源码注释以oz为例,见 secret.rs)。

从源码结构看,secret是 crates/warp_cli/src/secret.rs 中定义的子命令族,支持create / delete / update / list,并内置了claude api-key、codex api-key、docker-registry等供应商专用子命令,与本文档中的密钥注入场景一一对应。


二、产物上报机制:report_pr是必经步骤

当第三方 CLI 创建了 PR 或分支时,Oz 不会自动感知。必须在 Warp UI 中展示这些产物,需要显式调用report_pr工具:

  1. Pull Requests:第三方 CLI 创建 PR 后,从它的输出中解析出pr_url与branch,调用report_pr工具登记;
  2. 编写委托 Prompt 时,始终包含两条要求:
    1. 让第三方 CLI 在输出中打印 PR URL 和分支名;
    2. CLI 运行结束后,解析输出并调用report_pr完成登记;
  3. Plans(计划产物):由 Oz Agent 内置的 plan 工具创建时自动登记,无需特殊处理。

通用产物上报 Prompt 模板

Run <CLI> to implement the feature: <CLI> -p "Create a branch, implement the login fix, commit, push, and create a PR using gh CLI. Print the full PR URL and branch name at the end." After <CLI> finishes, find the PR URL and branch name from its output. Then call the report_pr tool with those values so the PR appears as an artifact.

三、Claude Code

项目内容
安装npm install -g @anthropic-ai/claude-code
认证环境变量ANTHROPIC_API_KEY(自动读取)
非交互模式claude -p "<prompt>"
常用参数--output-format json、--allowedTools "Read,Write,Bash(...)"、--append-system-prompt

密钥注入(Oz secret)

{{warp_cli_binary_name}} secret create ANTHROPIC_API_KEY --team --value-file key.txt --description "Anthropic API key for Claude Code"

示例委托 Prompt

Run: claude -p "Analyze the codebase and list potential security issues" --output-format json

产物上报 Prompt

Run Claude Code to implement the feature: claude -p "Create a branch, implement the login fix, commit, push, and create a PR using gh CLI. Print the full PR URL and branch name at the end." After Claude Code finishes, find the PR URL and branch name from its output. Then call the report_pr tool with those values so the PR appears as an artifact.

说明:--allowedTools用于白名单式放行工具(如只允许Read、Write及特定Bash(...)调用);--append-system-prompt可在系统提示后追加自定义指令;--output-format json便于用jq解析结构化输出。


四、Codex CLI

项目内容
安装npm install -g @openai/codex
认证需要显式登录,不支持仅靠环境变量自动生效
登录方式printenv OPENAI_API_KEY \| codex login --with-api-key;也可直接设置CODEX_API_KEY
非交互模式codex exec "<prompt>"
区域端点按需设置OPENAI_BASE_URL(如https://us.api.openai.com/v1)
常用参数--full-auto、--sandbox workspace-write、--json、--skip-git-repo-check

密钥注入(Oz secret)

{{warp_cli_binary_name}} secret create OPENAI_API_KEY --team --value-file key.txt --description "OpenAI API key for Codex CLI"

推荐:把登录写进环境 Setup 命令

建议将printenv OPENAI_API_KEY | codex login --with-api-key配置为环境 Setup 命令,这样 Agent 启动前认证自动完成,无需每次手动登录。

示例委托 Prompt

First authenticate Codex: printenv OPENAI_API_KEY | codex login --with-api-key Then run: codex exec "Refactor the utils module to reduce duplication"

产物上报 Prompt

Authenticate Codex: printenv OPENAI_API_KEY | codex login --with-api-key Then run: codex exec --full-auto "Create a branch, fix the bug, commit, push, and create a PR. Print the PR URL and branch name." After Codex finishes, parse the PR URL and branch name from its output and call report_pr.

提示:--full-auto让 Codex 全自动推进;--sandbox workspace-write允许在工作区内写文件;--json输出结构化结果;--skip-git-repo-check用于非 Git 目录。


五、Gemini CLI

项目内容
安装npm install -g @google/gemini-cli
认证环境变量GEMINI_API_KEY(自动读取),密钥从 Google AI Studio 获取
非交互模式gemini -p "<prompt>"(headless 模式)
常用参数--output-format json、--yolo(自动批准工具操作)

密钥注入(Oz secret)

{{warp_cli_binary_name}} secret create GEMINI_API_KEY --team --value-file key.txt --description "Gemini API key for Gemini CLI"

示例委托 Prompt

Run: gemini -p "Review the test suite and suggest missing edge cases" --output-format json

产物上报 Prompt

Run Gemini CLI: gemini -p "Create a branch, implement the change, commit, push, and create a PR using gh CLI. Print the full PR URL and branch name at the end." --yolo After it finishes, parse the PR URL and branch from the output and call report_pr.

六、Amp(Sourcegraph)

项目内容
安装npm install -g @sourcegraph/amp
认证环境变量AMP_API_KEY(从 ampcode.com 的设置页获取);隔离模式下改用ANTHROPIC_API_KEY
非交互模式amp -x "<prompt>"(execute 模式)
常用参数--dangerously-allow-all(跳过工具审批提示)

密钥注入(Oz secret)

{{warp_cli_binary_name}} secret create AMP_API_KEY --team --value-file key.txt --description "Amp API key"

示例委托 Prompt

Run: amp -x "List all TODO comments in the codebase and group them by priority"

产物上报 Prompt

Run Amp: amp --dangerously-allow-all -x "Create a branch, implement the fix, commit, push, and create a PR using gh CLI. Print the full PR URL and branch name." After Amp finishes, parse the PR URL and branch from the output and call report_pr.

七、Copilot CLI(GitHub)

项目内容
二进制copilot(独立二进制,来自 github/copilot-cli 仓库的 releases)
认证GH_TOKEN或GITHUB_TOKEN,需具有Copilot Requests权限的 fine-grained PAT;也支持COPILOT_GITHUB_TOKEN
非交互模式copilot -p "<prompt>"
常用参数--allow-all-tools
预装状态未预装在 Oz 镜像中,需通过 Setup 命令或 GitHub releases 安装

注意:gh copilot扩展(区别于独立copilot二进制)需要 OAuth 认证,不兼容 PAT,因此云端场景应使用独立二进制。

密钥注入(Oz secret)

{{warp_cli_binary_name}} secret create GH_TOKEN --team --value-file token.txt --description "GitHub PAT with Copilot Requests permission"

示例委托 Prompt

Run: copilot -p "Review the latest changes and suggest improvements" --allow-all-tools

产物上报 Prompt

Run Copilot CLI: copilot -p "Create a branch, implement the fix, commit, push, and create a PR using gh CLI. Print the full PR URL and branch name at the end." --allow-all-tools After Copilot finishes, parse the PR URL and branch from the output and call report_pr.

八、OpenCode

项目内容
安装curl -fsSL https://opencode.ai/install | bash(或使用二进制 release)
认证通过环境变量使用各家 Provider 的 API Key(如ANTHROPIC_API_KEY、OPENAI_API_KEY),也会读取.env文件;可用opencode auth login交互式配置
非交互模式opencode run "<prompt>"或opencode -p "<prompt>"
常用参数-f json(JSON 输出)、-q(安静模式,无 spinner)
预装状态未预装在 Oz 镜像中,需通过 Setup 命令安装

示例委托 Prompt

Run: opencode run "Explain the architecture of this project" -q

OpenCode 在 Oz 镜像中无预装,若需要在云端使用,需在环境 Setup 命令中先行安装,并确保所用 Provider 的 API Key 已通过secret create注入。


九、Droid(Factory):当前不支持云端无头模式

项目内容
安装curl -fsSL https://app.factory.ai/cli | sh
认证需要 Factory 账号:在 CLI 内使用/login,或在 Factory Settings 生成 API Key
无头认证尚未确认支持纯环境变量认证,可能必须交互式登录
非交互模式droid exec "<prompt>"
常用参数--auto low\|medium\|high(权限分级)、--skip-permissions-unsafe
状态当前不支持无头 Oz 环境(因非交互认证方式不明确),已从预构建镜像中排除

计划在 Oz 环境使用 Droid 前,必须先验证其无头认证可行性,否则建议改用上文中其他已支持的 CLI。


十、快速参考表

CLI命令认证环境变量非交互参数是否预装
Claude CodeclaudeANTHROPIC_API_KEY-p是
CodexcodexOPENAI_API_KEYexec是
Gemini CLIgeminiGEMINI_API_KEY-p是
AmpampAMP_API_KEY-x否
Copilot CLIcopilotGH_TOKEN/GITHUB_TOKEN-p否
OpenCodeopencodeProvider 相关run/-p否
Droiddroid无(交互式登录)exec否

十一、密钥注入的源码级原理:oz secret create的参数体系

所有第三方 CLI 的认证最终都依赖环境变量中的 API Key,而这些密钥由 Warp CLI 的secret子命令管理。在 crates/warp_cli/src/secret.rs 中可以看到完整定义:

  • 顶层子命令:create/delete/update/list(见 secret.rs);
  • 通用创建参数(secret.rs):
    • name:密钥名称(位置参数);
    • --value-file/-f:从文件读取密钥值,避免在命令行明文暴露;未提供时从标准输入读取(secret.rs);
    • --description/-d:密钥描述;
    • --team:将密钥归属到团队作用域;--personal则归属个人账户(互斥);
  • 供应商专用子命令(secret.rs):
    • secret create claude api-key <NAME>:Claude/Anthropic 认证密钥;
    • secret create codex api-key <NAME>:Codex/OpenAI 认证密钥(含--base-url可指定区域端点,如https://us.api.openai.com/v1);
    • secret create docker-registry <NAME>:私有镜像仓库凭据。

关于--team的细节:在 crates/warp_cli/src/scope.rs 中,--team是可选值参数——不传值时作用于你的唯一团队,多团队时需写成--team=<UID>(必须用=连接,否则会吞掉后续位置参数)。这些源码行为与本文档中所有--team用例直接对应,保证云端 Agent 能通过环境变量读取到密钥。


十二、启动云 Agent 并委托:agent run-cloud实战

在 crates/warp_cli/src/agent.rs 中,run-cloud子命令定义了visible_alias = "ra"与alias = "run-ambient",其核心参数包括:

  • --prompt/--skill:任务描述或技能基础 Prompt(二选一或组合,见 agent.rs);
  • --environment <ENV_ID>/-e:指定云环境 ID(agent.rs);
  • --name/-n、--title:任务命名与标题;
  • --open:Agent 可用后直接在 Warp 中打开会话;
  • --runner:指定计算资源配置(覆盖环境的默认 runner)。

交互式 Agent 委托模板

交互式 Agent 要启动一个云 Agent 去驱动第三方 CLI 时,不需要把 CLI 语法写进 Prompt:

{{warp_cli_binary_name}} agent run-cloud \ --environment <ENV_ID> \ --prompt 'Read the oz-platform skill for instructions on using Claude Code to solve: Summarize the architecture of this project'

设计原则(见 SKILL.md 的 “Using Third-Party Coding CLIs” 一节):不要把 CLI 命令语法塞进 Prompt,让云 Agent 自行阅读 oz-platform skill 与本文档,再按其规则执行。云 Agent 的运行模型是:

  1. 任务应全部由第三方 CLI 完成——不要用 Warp 内置的edit_files、read_files、grep、codebase_semantic_search等工具替它干活;
  2. 云 Agent 只负责:设置/认证 CLI → 构造 Prompt → 运行并监控 → 调试 CLI 自身问题 → 上报产物(report_pr);
  3. 标准调用链示例(来自 SKILL.md):
# 1. 读取本 skill 与 references/third-party-clis.md 了解 CLI 用法 # 2. 按需完成认证(例如 Codex 需要显式登录;Claude Code 的 ANTHROPIC_API_KEY 已就绪) # 3. 运行 CLI,把全部工作交给它 $ claude -p "Summarize the architecture of this project" # 4. 若创建了 PR,解析输出并上报产物 # 例如:report_pr(pr_url="https://github.com/...", branch="feature-branch")

反模式:不要越俎代庖

# ❌ 不要自己读文件去帮助 CLI $ read_files ... # ❌ 不要自己搜索代码库 $ grep ... # ❌ 不要自己编辑文件 $ edit_files ... # ✅ 正确做法:让第三方 CLI 独立完成整个任务 $ claude -p "Complete the entire task: <user's task>"

十三、选择-agents预构建环境的建议

交互式 Agent 在启动云 Agent 前,应让用户在公开的-agents镜像中选择环境(SKILL.md 中列出了完整清单,示例包括):

  • warpdotdev/dev-base:latest-agents(通用基础环境)
  • warpdotdev/dev-go:1.23-agents、warpdotdev/dev-rust:1.85-agents、warpdotdev/dev-java:21-agents、warpdotdev/dev-dotnet:8.0-agents、warpdotdev/dev-ruby:3.3-agents
  • warpdotdev/dev-web:latest-agents、warpdotdev/dev-full:latest-agents(全量)

也可以询问用户是否复用已有环境,用{{warp_cli_binary_name}} environment list --output-format text查看;若选择公开镜像且尚无对应环境,则用{{warp_cli_binary_name}} environment create ...创建。这些环境已预装最常用的第三方 CLI,能大幅降低 Setup 成本。


结语:一份可复制的云端多 CLI 编排方案

本文档(third-party-clis.md)连同父级 SKILL.md,构成了一套完整的“云端第三方 CLI 编排”方法论:用secret create注入密钥 → 在-agents环境或 Setup 命令中安装 CLI → 用非交互参数(-p/exec/-x/run)执行任务 → 解析输出并调用report_pr上报 PR/分支产物。这套流程既避免了云 Agent 与第三方 CLI 重复劳动,也保证了产物在 Warp UI 中的可见性,可直接迁移到定时调度、GitHub Actions 触发等自动化场景。

  • 桌面应用
  • 开发者工具
  • 人工智能
  • AI 应用
  • AI Agent
  • 代码智能体

【免费下载链接】warp

Warp is an agentic development environment, born out of the terminal.

项目地址:https://gitcode.com/GitHub_Trending/wa/warp
点击查看免费下载

相关推荐

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询