agent需要遵从的规范

最核心的 4 层约束体系(必须同时用)

下面这 4 层,是目前成功率最高的组合。

🛡️ 第 1 层:System Prompt = 宪法(不可违背)

做法

你要有一份永远不变、每次对话必注入的 System Prompt。

示例(你可以直接用)

SYSTEM LAW (NON-NEGOTIABL

You are an AI coding agent working inside a constrained repository.

You MUST obey all rules defined in: 1. Code Zones 2. Contracts 3. Agent Operation Docs

You are ONLY allowed to modify files explicitly permitted. You MUST NOT modify core runtime, routing, or contracts unless explicitly instructed.

If a task requires changes outside allowed zones: STOP. Explain why. DO NOT guess or workaround.

Violation of these rules is considered task failure. ```

📌 这一层的关键词是:不可协商(Non-negotiable)

🛡️ 第 2 层:任务前强制「意图声明 + 自检」

这是非常关键、但很多人跳过的一步。

强制流程(你要要求 Agent 先做这个)

Before writing any code, you MU

1. Summarize the task in one sentence. 2. List which code zone(s) you will touch. 3. List which files you will modify. 4. Confirm that all changes are within allowed zones.

Only after this checklist is completed and approved, you may proceed. ```

如果 Agent 这一步就错了,

你直接中断,不让它写代码。

👉 这一步能拦掉 70% 的潜在事故。

🛡️ 第 3 层:文件可见性 = 最强硬约束(如果你能做到)

这是物理级约束,优先级最高。

原则

Agent 看不到的文件,绝不可能误改。

实践方式

  • 只把:
src/zones/content-render/**
  • 暴露给 Agent
  • 核心目录:
core-runtime/
routing/
contracts/
  • 完全不提供上下文

📌 这是比 Prompt 强 10 倍的约束。

🛡️ 第 4 层:违规即失败(Hard Stop)

你要在 Prompt 里明确写出失败条件。

示例

Failure Conditio
  • Modifying files outside allowed zones - Introducing new abstractions not defined in contracts - Refactoring unrelated code - Changing behavior without explicit instruction

If any failure condition is met: STOP and report failure. ```

这会显著减少:

  • “我顺便帮你优化了一下”
  • “我觉得这样更好”

三、你每一次跟 Agent 交流,应该长什么样?(标准模板)

我给你一个完整可复制的交互模板。

🧩 1️⃣ System Prompt(固定,不变)

放你的「宪法 + 区块 + 禁区」

🧩 2️⃣ Context Injection(自动)

  • 当前 zone README
  • 当前 contract
  • 当前 agent 操作文档

👉 只注入“相关区块”的文档

🧩 3️⃣ Task Prompt(你每次写的)

Task:
Add support for rendering Notion "callout" bloc

Constraints: - Only modify files under: src/zones/content-render/ - Follow contract: contracts/content-render.ts - Do not modify routing or data fetching.

Required Process: 1. Pre-flight checklist 2. Then code 3. Then summarize changes ```

🧩 4️⃣ Post-flight Summary(强制)

After completing the task, provide:
1. Files changed
2. Lines changed
3. Why this change is safe
4. What was NOT changed

👉 你 review 的成本会极低。

🧠 Vibe Coding 可维护性 · 全量实践表(2025)

核心目标:
让 Agent“写得快”,但“永远写不坏系统”。

一、代码结构层(Architecture / Repo Design)

二、契约层(Contract / Boundary Design)

三、Agent 操作约束层(Agent Control)

四、文档层(Docs for Agent, not Human)

五、变更管理层(Change Management)

六、测试与验证层(Validation)

七、Prompt 工程层(Meta Control)

八、组织与心智层(最容易被忽略,但最重要)

九、浓缩成 5 条「不可违反原则」(你可以贴墙上)

1. Agent 只能在被授权的区块内写代码

1. 所有重要行为必须有 Contract

1. 任何“顺手优化”都是潜在事故

1. 文档是给 Agent 写的,不是给人看的

1. 架构决定上限,模型只是执行者