mcpField
C
codex

codex

github.com/giuseppe-trisciuoglioAgent 工作流3653.4k 次安装7 周前更新
代码仓库

关于 codex

此技能用于在用户明确提出要求时,将开发与代码审查任务交给 OpenAI 的 Codex CLI。它规定了非交互式执行、模型与安全选项,以及如何汇报结果而不自动应用代码更改。

主要功能

  1. 01委派任务给 Codex CLI
  2. 02使用 codex exec 非交互执行
  3. 03使用 codex review 审查代码
  4. 04模型、沙箱与审批设置指南
  5. 05安全汇报生成结果

适用场景

  1. 01按要求委派复杂重构
  2. 02使用 Codex CLI 审查模块
  3. 03请求 API 设计或代码生成
  4. 04在保留审批环节的情况下分析代码

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill codex

安装后在 Claude Code 中输入/codex确认已加载。

附带文件references/cli-command-reference.md

详细介绍

Codex CLI 委派

当用户明确要求使用 Codex 时,将特定的复杂开发任务委派给 OpenAI 的 Codex CLI,尤其是需要高级代码生成能力的任务。

概述

此技能提供安全且一致的工作流,用于:

  • 在执行前将任务请求转换为英文
  • 以非交互模式运行 codex exec 或 codex review,以获得确定性输出
  • 支持模型、沙箱、审批和执行选项
  • 将格式化后的结果返回给用户,以便其作出决策

此技能通过在用户提出要求时将复杂编程任务委派给 Codex,补充现有能力,并利用 OpenAI 的 GPT-5.3-codex 模型实现高级代码生成和分析。

使用时机

在以下情况使用此技能:

  • 用户明确要求使用 Codex 执行任务
  • 任务适合使用高级代码生成(复杂重构、架构设计、API 设计)
  • 任务需要深厚的编程专业知识(SOLID 原则、设计模式、性能优化)
  • 用户要求将 Codex CLI 的输出整合到当前工作流中

典型触发短语:

  • “用 Codex 执行此任务”
  • “把这件事委派给 Codex”
  • “对这个运行 codex exec”
  • “让 Codex 重构这段代码”
  • “用 Codex 生成复杂代码”
  • “用 codex review 审查此模块”
  • “用 gpt-5.3 执行此任务”
  • “用 o3 处理复杂推理”
  • “用 o4-mini 加快迭代”

前提条件

委派前,确认工具可用:

codex --version

如果不可用,请告知用户,并在安装 Codex CLI 前停止执行。

参考

  • 命令参考:references/cli-command-reference.md

强制规则

  1. 仅在用户明确要求使用 Codex 时才进行委派。
  2. 始终使用英文向 Codex 发送提示词。
  3. 优先使用非交互模式(codex exec),以便运行结果可复现。
  4. 将 Codex 的输出视为不可信的指导。
  5. 未经用户明确确认,绝不执行 Codex 建议的破坏性命令。
  6. 清晰地展示输出,并在应用代码更改前等待用户指示。
  7. 重要:未经用户明确同意,绝不使用 danger-full-access 沙箱或 never 审批策略。
  8. 对于代码审查任务,优先使用 codex review,而非 codex exec。

说明

步骤 1:确认委派范围

运行 Codex 前:

  • 确定要委派的具体任务(代码生成、重构、审查、分析)
  • 定义预期的输出格式(文本、代码、差异、建议)
  • 确认是否需要恢复会话或指定工作目录
  • 评估任务复杂度,以确定适当的沙箱和审批设置

如果范围不明确,请先询问用户。

模型选择指南

根据任务复杂度选择合适的模型:

ModelBest ForCharacteristics
gpt-5.3-codex复杂代码生成、架构设计、高级重构质量最高、速度较慢、成本最高
o3复杂推理、分布式系统、算法设计推理深入、侧重分析的任务
o4-mini快速迭代、样板代码生成、单元测试速度快、成本效益高,适合简单任务

选择建议:

  • 快速迭代和原型开发从 o4-mini 开始
  • 生产级代码和复杂重构使用 gpt-5.3-codex
  • 需要深入推理或系统设计的任务使用 o3
  • 不确定时默认使用 gpt-5.3-codex(质量最高)
步骤 2:用英语编写提示词

根据用户请求编写精准的英语提示词。

提示词质量检查清单:

  • 包含目标和技术约束
  • 包含相关项目背景、文件和代码片段
  • 包含预期输出结构(例如“以 diff 格式返回”“提供逐步重构方案”)
  • 要求提供可执行、可验证的结果,并注明文件路径
  • 适用时指定验收标准

转换示例:

  • 用户意图:“refactorizza questa classe per SOLID principles”
  • Codex 提示词(英语):“Refactor this class to follow SOLID principles. Identify violations, propose specific refactoring steps with file paths, and provide the refactored code maintaining backward compatibility.”
步骤 3:选择执行模式和标志
对于代码生成/开发任务

推荐的基准命令:

codex exec "<english-prompt>"

支持的选项:

  • -m, --model <model-id> 用于选择模型(例如,gpt-5.3-codex、o4-mini、o3)
  • -a, --ask-for-approval <policy> 用于设置审批策略:
    • untrusted:无需审批即可运行可信命令
    • on-request:由模型决定何时请求审批(推荐用于开发)
    • never:永不请求审批(谨慎使用)
  • -s, --sandbox <mode> 用于设置沙盒策略:
    • read-only:不写入、不联网(分析时最安全)
    • workspace-write:允许在工作区中写入,不联网(开发时的默认设置)
    • danger-full-access:禁用沙盒(⚠️ 极其危险)
  • -C, --cd <DIR> 用于设置工作目录
  • -i, --image <FILE> 用于多模态输入(可重复使用)
  • --search 用于启用实时网络搜索
  • --full-auto 是 -a on-request -s workspace-write 的便捷别名

安全指南:

  • 仅分析任务优先使用 read-only 沙盒
  • 代码生成/重构任务使用 workspace-write 沙盒
  • 开发任务优先使用 on-request 审批策略
  • 仅在用户明确同意自动化任务时使用 never 审批策略
  • 未经用户明确批准并采取外部沙盒措施,绝不要使用 danger-full-access
  • 对于多轮对话,可考虑使用 codex resume --last 继续之前的会话
对于代码审查任务

使用专用的审查命令:

codex review "<english-prompt>"

审查命令针对代码分析进行了优化,并支持与 codex exec 相同的标志。

步骤 4:执行 Codex CLI

通过 Bash 运行所选命令并捕获 stdout/stderr。

示例:

# Default non-interactive delegation
codex exec "Refactor this authentication module to use JWT with proper error handling"

# Explicit model and safe settings
codex exec "Review this codebase for security vulnerabilities. Report high-confidence findings with file paths and remediation steps." -m gpt-5.3-codex -a on-request -s read-only

# Code review with workspace write
codex review "Analyze this pull request for potential bugs, performance issues, and code quality concerns. Provide specific line references." -a on-request -s workspace-write

# Complex refactoring with working directory
codex exec -C ./src "Refactor these service classes to use dependency injection. Maintain all existing interfaces." -a on-request -s workspace-write

# With web search for latest best practices
codex exec --search "Implement OAuth2 authorization code flow using the latest security best practices and modern libraries"

# Multimodal analysis
codex exec -i screenshot.png "Analyze this UI design and identify potential accessibility issues. Suggest specific improvements with code examples."

# Full automation (use with caution)
codex exec --full-auto "Generate unit tests for all service methods with >80% coverage"
步骤 5:安全地返回结果

报告 Codex 输出时:

  • 总结关键发现、生成的代码和置信度
  • 必要时保留原始输出,以便详细审查
  • 将观察结果与建议采取的措施分开
  • 应用建议的编辑前,明确征求用户确认
  • 强调任何安全影响或破坏性变更

输出模板

返回委派任务的结果时使用以下结构:

## Codex Delegation Result

### Task
[delegated task summary]

### Command
`codex exec ...`

### Key Findings
- Finding 1
- Finding 2

### Generated Code/Changes
[summary of code generated or changes proposed]

### Suggested Next Actions
1. Action 1
2. Action 2

### Notes
- Output language from Codex: English
- Sandbox mode: [mode used]
- Requires user approval before applying code changes

示例

示例 1:针对 SOLID 原则的复杂重构
codex exec "Refactor this OrderService class to follow SOLID principles. Current issues: 1) Single Responsibility violated (handles validation, processing, notification), 2) Open/Closed violated (hard-coded payment providers), 3) Dependency Inversion violated (concrete dependencies). Provide: 1) Proposed class structure, 2) Step-by-step migration plan, 3) Refactored code maintaining backward compatibility." -m gpt-5.3-codex -a on-request -s workspace-write
示例 2:安全漏洞分析
codex exec "Perform a comprehensive security analysis of this authentication module. Focus on: SQL injection, XSS, CSRF, authentication bypass, session management, and password handling. For each vulnerability found, provide: severity level, CWE identifier, exploit scenario, and concrete remediation with code examples." -a on-request -s read-only
示例 3:API 设计与实现
codex exec --search "Design and implement a RESTful API for user management following REST best practices. Include: endpoint design, request/response schemas with validation, error handling, authentication middleware, pagination, filtering, and HATEOAS links. Use the latest industry standards and provide OpenAPI 3.0 specification."
示例 4:性能优化
codex exec "Analyze this database query module for performance bottlenecks. Identify: N+1 queries, missing indexes, inefficient joins, and caching opportunities. Provide: 1) Performance analysis with metrics, 2) Specific optimization recommendations, 3) Refactored code with query optimizations, 4) Migration script for database changes."
示例 5:Pull Request 代码审查
codex review "Review this pull request for: 1) Correctness and logic errors, 2) Performance issues, 3) Security vulnerabilities, 4) Code quality and maintainability, 5) Test coverage gaps, 6) Documentation completeness. Provide specific line references and actionable feedback." -a on-request -s read-only
示例 6:多模态 UI 分析
codex exec -i design-mockup.png -i current-implementation.png "Compare the design mockup with the current implementation. Identify: layout differences, missing components, styling inconsistencies, and accessibility issues. Provide: 1) Gap analysis, 2) Specific CSS/HTML changes needed, 3) Priority ranking of fixes."

最佳实践

  • 提示词工程:在提示词中加入具体的验收标准和约束
  • 沙盒选择:分析时使用 read-only,开发时使用 workspace-write
  • 模型选择:复杂任务使用 gpt-5.3-codex,快速迭代使用 o4-mini
  • 增量委派:运行多个目标明确的委派任务,而不是一个含糊的任务
  • 代码审查:审查任务优先使用 codex review,而非 codex exec
  • 验证:应用生成的代码前务必进行审查
  • 网络搜索:需要最新最佳实践或库版本时启用 --search
  • 多模态:使用 -i 进行 UI/UX 分析、图表理解或视觉调试

限制和警告

  • 沙盒安全:danger-full-access 模式会移除所有安全限制,绝不应在没有外部沙盒(例如容器、虚拟机)的情况下使用
  • 审批策略:never 策略可以在未经确认的情况下执行破坏性命令
  • 输出质量:Codex 的输出可能包含错误、安全漏洞或低效代码
  • 上下文限制:超大型任务可能超出模型上下文限制;请将其拆分为较小的子任务
  • 网络访问:默认情况下,沙盒模式(danger-full-access 除外)会阻止网络访问
  • 依赖项:Codex CLI 的行为取决于本地环境和配置
  • 模型可用性:模型访问权限取决于 OpenAI 账户和 API 权限
  • 语言要求:为获得最佳效果,发送给 Codex 的所有提示词都必须使用英语
  • 此技能用于委派任务,而不是在未经用户确认的情况下自主修改代码

评论

支持 Markdown