AI Coding SOP 严格开发交付标准 v2

把 AI Coding 从"对话式写代码"提升为"文档驱动的可交付开发过程"。默认原则:标准先完整,执行可裁剪。裁剪必须有理由,不能无记录地省略。

一、SOP 总览

本 SOP 是面向 AI Coding 的严格开发交付标准。它不是提示词集合,也不是单一前端流程,而是一套从需求、设计、开发、测试、集成、部署到验收交付的完整文档和执行规范。

基本原则

  1. 文档是执行上下文——文档不是事后归档,而是 Agent 工作的输入。没有文档,Agent 会猜;文档不完整,Agent 会补脑;文档冲突,Agent 会随机选择。
  2. 标准完整,执行裁剪——SOP 默认定义完整交付物。实际项目可按规模裁剪,但必须记录裁剪理由和风险。
  3. Codex 默认拥有工程所有权——除非用户明确另行指定,Codex 负责最终生产代码实现、验证和交付总结。
  4. 设计和开发分离,但不能脱节——设计方案必须足够工程化,能被映射到组件、接口、数据模型、测试用例和验收标准。
  5. 证据优先于声明——不能只说"已完成""已测试""页面正常"。必须记录命令、结果、截图、报告或人工验收结论。

两种执行模式

维度Codex-only(默认)Design-Agent + Codex(条件)
触发条件所有开发任务用户提供设计 Agent 的前端设计产物
Design Agent 负责不适用前端设计交付物:UI Spec、原型、Tokens、组件规范
Codex 负责全流程:需求、设计、开发、测试、交付生产代码、系统设计、数据库、接口、测试、交付
切换规则默认模式必须检测 + 用户确认,不可静默切换

完整交付链路

任务输入
范围与裁剪
PRD
需求分析
系统设计
数据库设计
接口设计
前端设计
安全设计
测试用例
开发计划
任务拆解
开发执行
代码审查
测试报告
集成报告
部署回滚
验收报告
交付总结

二、裁剪等级

L0:小修小改

文案修改、样式微调、单文件 bug 修复。最低要求:任务摘要 + 实现计划 + 验证报告 + 交付总结。

L1:小功能

单页面功能、单接口改动、风险低。最低要求:PRD/需求摘要 + 简版系统设计 + 开发计划 + 测试用例 + 测试报告 + 交付总结。

L2:标准功能

常规业务功能、前后端协作、涉及数据读写。最低要求:PRD + 需求分析 + 系统设计 + 测试用例 + 开发计划 + 开发日志 + 测试报告 + 交付总结。

L3:多模块功能

跨多个模块、涉及数据库迁移、外部系统集成。最低要求:L2 全量 + 完整数据库/接口/前端/安全设计 + 代码审查 + 集成报告 + 部署回滚计划 + 验收报告。

L4:生产级、核心业务、高风险

支付、账号、数据安全、高并发。要求:L3 全量 + 风险登记表 + 安全审查 + 性能测试 + 迁移演练 + 回滚演练 + 发布审批。

裁剪矩阵

交付物L0L1L2L3L4
00-tailoring-decision必须必须必须必须必须
01-prd可合并必须必须必须必须
02-requirements-analysis可省略简版必须必须必须
03-system-design可合并简版必须必须必须
04-database-design条件条件条件必须必须
05-api-integration-design条件条件条件必须必须
06-frontend-design条件条件条件必须必须
07-security-permission-design条件条件条件必须必须
08-test-case-design简版必须必须必须必须
09-development-plan必须必须必须必须必须
10-task-breakdown可省略简版必须必须必须
11-development-log可省略简版必须必须必须
12-code-review-report可省略条件推荐必须必须
13-test-report必须必须必须必须必须
14-integration-report可省略条件条件必须必须
15-deployment-rollback-plan可省略条件条件必须必须
16-acceptance-report可合并简版必须必须必须
17-delivery-summary必须必须必须必须必须

说明:"条件"=涉及该领域变更就必须写;"可合并"=可合并进同级文档;"简版"=可短但必须覆盖目标/决策/风险/门禁;"可省略"=必须在裁剪决策中说明。


三、阶段门禁

  • 需求未确认 → 不进入设计
  • 设计未确认 → 不进入开发计划
  • 开发计划未确认 → 不开始编码
  • 测试用例缺失 → 不声明实现完成
  • 测试报告缺失 → 不进入交付
  • 验收报告缺失 → 不关闭任务
  • 涉及前端,没有视觉 QA → 不声明完成
  • 涉及数据库,没有迁移和回滚说明 → 不进入发布
  • 涉及外部接口,没有契约和失败策略 → 不进入集成

完成定义

  • 功能满足 PRD 验收标准
  • 代码符合系统设计
  • 数据库和接口变更有记录
  • 测试用例执行完成
  • 测试报告记录证据
  • 前端变更完成视觉 QA
  • 交付总结明确风险和后续项
  • 裁剪项均有记录

四、过程文档清单

推荐目录结构:docs/tasks/YYYY-MM-DD-task-name/

每份文档必须包含 YAML frontmatter,状态规则:draft → ready → approved → blocked/superseded

编号文档目标触发条件
00tailoring-decision确定任务等级和裁剪范围所有任务
01prd定义做什么、为谁做、什么算成功L1+ 必须
02requirements-analysis把 PRD 转成可设计的问题清单L2+ 必须
03system-design定义系统如何组织和协作系统变化时
04database-design定义数据结构、迁移和回滚数据库变更时
05api-integration-design定义系统之间如何交互前后端或外部系统交互时
06frontend-design定义前端结构、视觉、交互和状态UI 改动时
07security-permission-design定义权限、安全和审计边界用户/权限/敏感数据变更时
08test-case-design定义如何证明系统正确所有任务(L0 可简版)
09development-plan把设计转成可执行开发计划所有任务
10task-breakdown把开发计划拆成可执行任务L2+
11development-log记录开发过程中的真实决策和偏离L2+
12code-review-report记录代码审查结果L3+
13test-report记录测试证据所有任务
14integration-report记录集成验证结果多模块/外部系统时
15deployment-rollback-plan定义如何发布和如何撤回部署/迁移/配置变更时
16acceptance-report记录验收结果L2+
17delivery-summary给未来维护者留下最终索引所有任务

五、设计方案文档标准

完整设计包包含:03-system-design + 04-database-design + 05-api-integration-design + 06-frontend-design + 07-security-permission-design + 08-test-case-design + 15-deployment-rollback-plan

03-system-design 核心章节

Context / Goals / Non-Goals / Current Architecture / Target Architecture / Module Boundaries / Data Flow / State Flow / Core Workflows / Error Handling / Dependencies / Configuration / Observability / Performance / Rollback Strategy / Risks / Open Questions

04-database-design 核心章节

Data Requirements / Entity Relationship / Tables / Fields / Constraints / Indexes / Query Patterns / Migration Plan / Backfill Plan / Seed Data / Data Permissions / Data Consistency / Rollback Plan / Risks

05-api-integration-design 核心章节

Integration Scope / API Contract / Request/Response Schema / Error Codes / Authentication / Authorization / Idempotency / Retry Policy / Timeout Policy / Rate Limit / Versioning / Contract Tests / Mock Strategy / Risks

06-frontend-design 核心章节

Page Goals / Target Users / Information Architecture / User Flow / Layout / Component Inventory / State Inventory / Responsive Behavior / Design Tokens / Accessibility / Empty-Loading-Error States / Visual QA Criteria / Risks

视觉禁区(必须明确禁止)


六、Codex-only 开发 SOP(默认模式)

Codex-only 是默认开发模式。除非用户提供设计 Agent 的前端设计产物并确认切换,否则所有开发工程都按本模式执行。

适用场景

后端开发、全栈功能、内部工具、管理后台、数据平台、MVP、常规业务功能、已有设计系统的前端项目。

标准流程

1. 读取 AGENTS.md
2. 判断任务等级
3. 生成裁剪决策
4. 生成 PRD
5. 需求分析
6. 设计方案
7. 测试用例
8. 开发计划
9. 用户确认
10. 执行开发
11. 开发日志
12. 测试验证
13. 生成报告
14. 交付总结

开发前门禁

前端任务特殊要求

Codex-only 中的前端设计必须包含:信息架构、页面结构、组件清单、状态清单、响应式策略、视觉禁区、截图验收标准。

完成前必须有:桌面截图 QA、移动端截图 QA、文本溢出检查、状态检查。

Codex 必须避免:把所有内容做成 card、使用无意义渐变和发光装饰、工具型页面做成营销页、只写代码不看截图。


七、Design-Agent + Codex 开发 SOP

Design-Agent + Codex 是条件模式。它只在前端设计部分引入设计 Agent,其余开发交付流程仍由 Codex 负责。

触发条件

当检测到以下任一内容时,Codex 应询问用户是否切换:

角色边界

维度Design AgentCodex
负责视觉方向、原型、UI Design Spec、Design Tokens、Component Spec、响应式说明、交互状态说明、视觉验收标准裁剪决策、PRD、需求分析、系统设计、数据库设计、接口设计、安全设计、将设计映射到组件和代码、开发计划、生产代码、测试报告、集成报告、交付总结
不负责修改生产代码、决定后端架构、决定数据库结构、绕过 Codex 测试和交付流程前端视觉设计(由 Design Agent 提供)

Design Agent 必需交付物

design/ui-design-spec.md + design/design-agent-handoff.md + design/prototype.md

推荐:visual-direction.md + design-tokens.md + component-spec.md + screenshots/

Codex 设计审查清单


八、开发与测试标准

09-development-plan 质量标准

11-development-log 质量标准

13-test-report 命令记录标准

必须记录实际命令,例如 npm run lintnpm testnpm run build。不能只写"已测试""测试通过""页面正常"。

视觉 QA 报告

前端任务必须在测试报告或单独视觉 QA 报告中记录:桌面视口、移动端视口、截图位置、视觉层级检查、响应式检查、文本溢出检查、状态检查、AI 模板感检查。

检查项:是否过多卡片、是否方块堆叠、是否视觉层级不清、是否使用无意义渐变、是否缺少 hover/focus/disabled/loading 状态、是否移动端遮挡或溢出。


九、AGENTS 自动应用规则

要让 SOP 自动应用,需要把规则写入项目 AGENTS.md 或全局 Codex 指令。

可自动化的范围

不可保证的范围

AGENTS.md 推荐配置

# AI Coding SOP

## Default SOP
All development tasks default to Codex-only SOP.

Codex must not start implementation until it has:
1. Determined task level: L0, L1, L2, L3, or L4.
2. Created or updated `00-tailoring-decision.md`.
3. Produced the required process documents for that level.
4. Produced `09-development-plan.md`.
5. Produced `08-test-case-design.md`.

## Task Levels
- L0: tiny fix or isolated change
- L1: small feature
- L2: standard feature
- L3: multi-module feature
- L4: production-critical or high-risk change

Tailoring is allowed, but every omitted document must be listed in
`00-tailoring-decision.md` with a reason and risk.

## Design-Agent Detection
If detected, Codex must ask:
"I detected design-agent frontend artifacts. Should I switch to
Design-Agent + Codex SOP for this task?"
Codex must not switch silently.

## Completion Gate
Codex must not claim completion unless:
- required process documents exist or are explicitly tailored out
- implementation matches approved design
- tests were run or skipped with a documented reason
- `13-test-report.md` exists
- frontend changes have visual QA evidence
- `17-delivery-summary.md` exists

任务启动检查

  1. Is this a development task?
  2. What is the task level?
  3. Which documents are required?
  4. Which documents can be tailored out?
  5. Is frontend involved?
  6. Are design Agent artifacts present?
  7. Should the user confirm Design-Agent + Codex mode?
  8. Is implementation allowed to start?

完成前检查

  1. Did I satisfy PRD acceptance criteria?
  2. Did I follow system design?
  3. Did I document database/API/frontend/security changes?
  4. Did I maintain development log when required?
  5. Did I run tests?
  6. Did I document skipped tests?
  7. Did I produce delivery summary?
  8. If frontend changed, did I verify desktop and mobile UI?

十、模板集合

以下是各文档的模板结构,可直接复制使用。每个文档都必须包含 YAML frontmatter。

00-tailoring-decision.md

---
title: "Tailoring Decision - TASK"
type: "tailoring"
status: "ready"
owner: "codex"
mode: "codex-only"
level: "L2"
task: "YYYY-MM-DD-task-name"
created: "YYYY-MM-DD"
updated: "YYYY-MM-DD"
related: []
---

# Tailoring Decision

## Task
## Level
## Mode
## Rationale

## Required Documents

## Tailored-Out Documents

| Document | Reason | Risk |
|---|---|---|

## User Confirmation

01-prd.md

# PRD

## Background
## Target Users
## User Problem
## Goals
## Non-Goals
## User Flow
## Functional Scope
## Acceptance Criteria
## Constraints
## Risks
## Open Questions

03-system-design.md

# System Design

## Context
## Goals
## Non-Goals
## Current Architecture
## Target Architecture
## Module Boundaries
## Data Flow
## State Flow
## Core Workflows
## Error Handling
## Dependencies
## Configuration
## Observability
## Performance Considerations
## Rollback Strategy
## Risks
## Open Questions

06-frontend-design.md

# Frontend Design

## Page Goals
## Target Users
## Information Architecture
## User Flow
## Layout
## Component Inventory
## State Inventory
## Responsive Behavior
## Design Tokens
## Accessibility
## Empty Loading Error States
## Visual QA Criteria
## Risks

08-test-case-design.md

# Test Case Design

## Test Scope
## Acceptance Criteria Mapping
## Unit Tests
## Integration Tests
## E2E Tests
## Visual Tests
## Accessibility Tests
## Security Tests
## Performance Tests
## Regression Tests
## Manual Verification
## Out of Scope

09-development-plan.md

# Development Plan

## Inputs
## Scope
## Out of Scope
## File Changes
## Implementation Steps
## Database Steps
## API Steps
## Frontend Steps
## Security Steps
## Test Steps
## Verification Commands
## Rollback Points
## Risks

11-development-log.md

# Development Log

## YYYY-MM-DD HH:mm
### Action
### Files Changed
### Decisions
### Problems
### Resolution
### Deviations
### Next

13-test-report.md

# Test Report

## Environment
## Commands
## Results
## Failed Cases
## Fixes
## Not Run
## Residual Risks
## Conclusion

17-delivery-summary.md

# Delivery Summary

## Task
## Mode and Level
## Completed Work
## Files Changed
## Documents
## Verification
## Deployment Status
## Known Limitations
## Risks
## Follow-Up

一句话总结

AI Coding SOP 的核心价值:把 AI 编码从"能跑就行"提升为"可交付、可维护、可追溯"的工程实践。文档不是形式,而是执行上下文——没有文档,Agent 会猜;有文档,Agent 能执行。
← 返回工具栏

需要定制 SOP?

我可以根据你的项目特点,定制专属的 AI 开发交付标准

发邮件