答案在于:质量不是"评估"出来的,而是"引导"和"约束"出来的。
核心机制:五层质量保证体系
质量保证的五个层次(无"评估"层!质量是在执行过程中保证的,不是事后评估的)
- 第1层: System Prompt 引导 ------ 告诉 AI "怎么做对"
- 第2层: 工具约束 ------ 限制 AI "不能乱来"
- 第3层: 实时反馈循环 ------ 让 AI "自己发现错误"
- 第4层: 上下文增强 ------ 帮 AI "理解更多背景"
- 第5层: 模型内建能力 ------ AI "本身就知道什么是好"
第1层:System Prompt 引导
1.1 专业性原则
文件路径:packages/opencode/src/session/prompt/anthropic.txt
sql
# Professional objectivity
Prioritize technical accuracy and truthfulness over validating the user's beliefs.
Focus on facts and problem-solving, providing direct, objective technical info
without any unnecessary superlatives, praise, or emotional validation.
作用:防止 AI 为了讨好用户而产生低质量的"迎合型"输出。
1.2 任务管理要求
vbnet
# Task Management
You have access to the TodoWrite tools to help you manage and plan tasks.
Use these tools VERY frequently to ensure that you are tracking your tasks...
If you do not use this tool when planning, you may forget to do important tasks -
and that is unacceptable.
作用:强制 AI 追踪任务进度,防止遗漏步骤。
1.3 迭代修正要求(Beast 模式)
文件路径:packages/opencode/src/session/prompt/beast.txt
vbnet
You are opencode, an agent - please keep going until the user's query is
completely resolved...
You MUST iterate and keep going until the problem is solved.
Take your time and think through every step - remember to check your solution
rigorously and watch out for boundary cases... Your solution must be perfect.
Failing to test your code sufficiently rigorously is the NUMBER ONE failure mode...
作用:要求 AI 持续工作直到问题完全解决,强制自我验证。
1.4 验证流程要求(Gemini 模式)
文件路径:packages/opencode/src/session/prompt/gemini.txt
markdown
## Software Engineering Tasks
1. Understand: Think about the user's request...
2. Plan: Build a coherent and grounded plan...
3. Implement: Use the available tools...
4. Verify (Tests): If applicable and feasible, verify the changes...
5. Verify (Standards): VERY IMPORTANT: After making code changes, execute the
project-specific build, linting and type-checking commands...
作用:明确定义验证步骤,强制执行构建、lint 和类型检查。
第2层:工具约束
2.1 参数验证
文件路径:packages/opencode/src/tool/tool.ts
javascript
toolInfo.execute = async (args, ctx) => {
try {
toolInfo.parameters.parse(args) // Zod schema 验证
} catch (error) {
throw new Error(
`The ${id} tool was called with invalid arguments: ${error}.
Please rewrite the input so it satisfies the expected schema.`
)
}
}
作用:阻止 AI 使用错误参数,错误信息引导 AI 修正。
2.2 LSP 实时诊断
文件路径:packages/opencode/src/tool/edit.ts
javascript
// 编辑后立即检查
await LSP.touchFile(filePath, true)
const diagnostics = await LSP.diagnostics()
const errors = issues.filter((item) => item.severity === 1)
if (errors.length > 0) {
output += `\n\nLSP errors detected, please fix:\n${errors}`
}
作用:每次编辑后自动检查语法错误,强制 AI 修复。
2.3 Bash 安全协议
文件路径:packages/opencode/src/tool/bash.txt
sql
Git Safety Protocol:
- NEVER update the git config
- NEVER run destructive git commands (push --force, hard reset...)
- NEVER skip hooks (--no-verify, --no-gpg-sign...)
- NEVER force push to main/master
- CRITICAL: If commit FAILED, NEVER amend - fix the issue and create a NEW commit
作用:防止 AI 执行危险操作,保护代码安全。
2.4 Edit 工具的智能匹配
文件路径:packages/opencode/src/tool/edit.ts
arduino
// 8种匹配策略,按优先级尝试
const REPLACERS = [
SimpleReplacer, // 精确匹配
LineTrimmedReplacer, // 行尾空白容错
BlockAnchorReplacer, // 块锚点匹配(Levenshtein 距离)
WhitespaceNormalizedReplacer, // 空白规范化
IndentationFlexibleReplacer, // 缩进容错
EscapeNormalizedReplacer, // 转义字符容错
TrimmedBoundaryReplacer, // 边界空白容错
ContextAwareReplacer, // 上下文感知
]
// 相似度阈值
const MULTIPLE_CANDIDATES_SIMILARITY_THRESHOLD = 0.3
作用:容错但严格,当出现歧义时要求 AI 提供更多上下文。
第3层:实时反馈循环
3.1 错误反馈给 AI 修正
反馈循环流程
-
AI 编辑代码
-
系统自动执行 LSP 检查
-
分支判断:
- 有错误:返回错误信息给 AI("LSP errors detected, please fix: ...")→ AI 根据错误信息自我修正(不需要系统评估,AI 自己就知道要改)→ 循环回到步骤1
- 无错误:返回 "Edit applied successfully" → 流程结束
3.2 文件时间戳验证
python
await FileTime.assert(ctx.sessionID, filePath)
作用:确保 AI 编辑的是最新版本文件,防止基于过期内容修改。
3.3 智能建议
javascript
if (suggestions.length > 0) {
throw new Error(
`File not found: ${filepath}
Did you mean one of these?
${suggestions.join("\n")}`
)
}
作用:文件不存在时提供相似文件名建议,帮助 AI 快速找到正确文件。
第4层:上下文增强
4.1 指令文件自动加载
文件路径:packages/opencode/src/tool/read.ts
javascript
const instructions = await InstructionPrompt.resolve(ctx.messages, filepath)
if (instructions.length > 0) {
output += `\n\n<system-reminder>
${instructions.map((i) => i.content).join("\n\n")}
</system-reminder>`
}
作用:读取文件时自动加载 .instruction.md,为 AI 提供项目特定指导。
4.2 Plan 模式只读约束
文件路径:packages/opencode/src/session/prompt/plan.txt
sql
CRITICAL: Plan mode ACTIVE - you are in READ-ONLY phase. STRICTLY FORBIDDEN:
ANY file edits, modifications, or system changes...
This ABSOLUTE CONSTRAINT overrides ALL other instructions...
作用:规划阶段强制只读,防止意外修改。
4.3 最大步数保护
文件路径:packages/opencode/src/session/prompt/max-steps.txt
diff
CRITICAL - MAXIMUM STEPS REACHED
The maximum number of steps allowed has been reached.
Response must include:
- Statement that maximum steps have been reached
- Summary of what has been accomplished
- List of remaining tasks
- Recommendations for next steps
作用:防止无限循环,强制 AI 汇报进度。
第5层:模型内建能力
5.1 训练数据中的质量标准
LLM 在训练时已经学习了:
- 什么是好的代码(代码风格、最佳实践)
- 什么是正确的语法
- 如何调试和修复错误
- 如何测试代码
5.2 RLHF 对齐
通过人类反馈强化学习:
- AI 知道什么样的回答更受欢迎
- AI 知道如何自我检查和修正
- AI 有"质量感知"能力
5.3 这就是关键
AI 模型本身就"知道"什么是好的输出
这来自:
-
- 数万亿 token 的代码训练数据
-
- 人类标注的偏好数据
-
- 强化学习的奖励信号
系统不需要"评估"质量,因为 AI 已经内化了质量标准
完整流程图
-
用户提出需求
-
第1层: System Prompt 引导("请持续迭代直到问题解决"、"请验证你的代码"、"请使用专业工具")
-
第5层: AI 内建能力(AI 知道什么是好代码(训练数据 + RLHF))
-
AI 决定执行哪些工具
-
第2层: 工具约束(参数验证、安全协议、匹配策略)
-
第4层: 上下文增强(加载指令文件、获取项目上下文)
-
工具执行
-
第3层: 实时反馈(LSP 检查 → 有错误?返回给 AI;命令失败?返回 exitCode 给 AI;参数错误?返回错误信息给 AI)
-
分支判断:
- 有错误:AI 自己修正(不需要系统评估,AI 内建能力知道怎么改)→ 循环回到"工具执行"步骤
- 无错误:AI 返回结果(finish_reason = "stop")→ 流程结束
核心答案
为什么不做质量评估还能产生好结果?
传统软件测试思路:执行 → 评估结果 → 如果不好就修正
OpenCode/Claude Code 思路:引导 + 约束 + 反馈 → AI 自己就知道怎么做好
关键区别:
-
- 不是"事后评估",而是"过程引导"
-
- 不是"系统判断好坏",而是"AI 自己判断"
-
- 不是"发现错误后修正",而是"错误实时反馈让 AI 自修"
五层机制共同作用
| 层次 | 机制 | 作用 |
|---|---|---|
| Prompt 引导 | 告诉 AI 怎么做对 | 方向正确 |
| 工具约束 | 限制 AI 不能乱来 | 行为可控 |
| 实时反馈 | 让 AI 自己发现错误 | 自我修正 |
| 上下文增强 | 帮 AI 理解更多背景 | 决策准确 |
| 模型能力 | AI 本身知道什么是好 | 质量内化 |
总结:这就是"不评估也能做好"的秘密------质量是在执行过程中保证的,而不是事后评估的。