Skip to content

Harness engineering beginner tutorial, from 0 to 1

Rewrite all lecture prose to remove AI-sounding tone

sanbuphyb6997546f4b9
diff --git a/docs/en/lectures/lecture-01-why-capable-agents-still-fail/index.md b/docs/en/lectures/lecture-01-why-capable-agents-still-fail/index.md
index 81719cf..8f2ed0c 100644
--- a/docs/en/lectures/lecture-01-why-capable-agents-still-fail/index.md
+++ b/docs/en/lectures/lecture-01-why-capable-agents-still-fail/index.md
@@ -1,60 +1,54 @@
-[中文版本 →](../../../zh/lectures/lecture-01-why-capable-agents-still-fail/)
+[中文版 →](../../../zh/lectures/lecture-01-why-capable-agents-still-fail/)
> Code examples: [code/](https://github.com/walkinglabs/learn-harness-engineering/blob/main/docs/en/lectures/lecture-01-why-capable-agents-still-fail/code/)
-> Practice project: [Project 01. Prompt-only vs. rules-first](./../../projects/project-01-baseline-vs-minimal-harness/index.md)
+> Practice project: [Project 01. Prompt-Only vs. Rules-First: How Much Difference Does a Harness Make](./../../projects/project-01-baseline-vs-minimal-harness/index.md)
# Lecture 01. Strong Models Don't Mean Reliable Execution
-You consider yourself well-traveled in the AI world — Claude Pro subscription, GPT-4o API key, SWE-bench leaderboard numbers memorized. One day you finally hand a real project to an AI agent, brimming with confidence. The result? It adds a feature but breaks the tests, fixes a bug but introduces two more, runs for 20 minutes and proudly declares "done" — and you look at the code and it's not what you asked for at all.
+As of late 2025, the strongest coding agents on SWE-bench Verified achieve roughly a 50-60% pass rate. That number sounds decent at first glance — but don't celebrate just yet. Those are carefully selected tasks with clear issue descriptions and ready-made test cases. Hand the agent your everyday requirements instead — vague specs, no existing tests, implicit business rules scattered across the codebase — and the pass rate only drops further. You hand off a task brimming with confidence, the agent runs for 20 minutes and tells you "all done," and you look at the code: it added a feature but broke the tests, fixed a bug but introduced new ones, and it's not even what you asked for.
-Your first instinct? "This model isn't good enough. Time to upgrade." Hold on. Before you reach for your wallet, consider that the problem might not be the model at all.
-
-Let's look at some numbers. As of late 2025, the strongest coding agents on SWE-bench Verified achieve roughly 50-60%. And that's on carefully selected tasks with clear issue descriptions and existing test cases. Move to your daily development environment — vague requirements, no existing tests, implicit business rules scattered everywhere — and that number only goes down.
-
-But behind these numbers lies a counterintuitive truth.
+When this happens, most people's first reaction is "the model isn't good enough — let me try a more expensive one." Before you reach for your wallet, consider that the problem might not be the model at all.
## Same Horse, Different Fates
-Anthropic ran a controlled experiment. Same prompt ("build a 2D retro game maker"), same model (Opus 4.5). First run: bare, no support — 20 minutes, $9, the game's core features didn't work at all. Second run: full harness (planner + generator + evaluator three-agent architecture) — 6 hours, $200, the game was playable.
+Anthropic ran a controlled experiment that illustrates the point perfectly. Same prompt ("build a 2D retro game editor"), same model (Opus 4.5), two runs. First run: bare, no support — 20 minutes, $9, the game's core features didn't work. Second run: full harness — a planner, generator, evaluator three-agent architecture — 6 hours, $200, the game was fully playable.
They didn't change the model. Opus 4.5 was still Opus 4.5. What changed was the tack.
-OpenAI's 2025 harness engineering article puts it plainly: Codex in a well-harnessed repository goes from "unreliable" to "reliable." Note their wording — not "a bit better," but a qualitative shift. Like a thoroughbred: you can ride it without proper tack, but you won't go far, won't go fast, and falling off is no surprise. The harness is that full set of tack — **everything in the engineering infrastructure outside the model weights.**
+OpenAI's 2025 harness engineering article puts it even more bluntly. They said that Codex in a well-harnessed repository goes from "unreliable" straight to "reliable." Note the wording — not "a bit better," but a qualitative leap. Harness here means **all the engineering infrastructure beyond the model weights.**
## Where Agents Actually Get Stuck
-So what specifically goes wrong?
+The specific failure modes really come down to just a handful.
-The most common: you never clearly defined the task. You say "add a search feature," and the agent's understanding is completely different from yours — search what? Full-text or structured? Pagination? Highlighting? You didn't specify, so the agent guesses. A correct guess is luck; a wrong one costs more to fix than being specific would have cost in the first place. It's like walking into a restaurant and telling the chef "I'll have fish" — whether you get it braised, steamed, or in a hot pot is entirely up to chance.
+The first type: the task was never clearly defined in the first place. "Add a search feature" — that sentence means almost nothing. Search what? Full-text or structured queries? Should results be paginated? Highlighted? You didn't spell it out, so the agent has to guess. A correct guess is luck; a wrong one means rework that costs several times more than being specific would have in the first place.
-Even when you do specify, the project has implicit architectural conventions the agent doesn't know. Your team standardized on SQLAlchemy 2.0 syntax, but the agent writes 1.x code by default. All API endpoints must use OAuth 2.0 authentication, but that rule only exists in your head and a Slack message from three months ago. The agent can't see these — it's not that it doesn't want to comply, it literally doesn't know these rules exist.
+Architectural conventions are another hidden pitfall. Your whole team uses the new SQLAlchemy 2.0 syntax, but the agent writes 1.x code by default. All API endpoints must go through OAuth 2.0 authentication, but that rule only exists in your head and a Slack message from three months ago. The agent has no idea — it's not that it doesn't want to comply, it literally has never seen the rule.
-The environment is a trap too. Incomplete dev environment, missing dependencies, wrong tool versions. The agent burns precious context window on `pip install` failures and Node version mismatches instead of solving your actual task. Like hiring a skilled carpenter but forgetting to provide a hammer, nails, or a level workbench — no matter how talented, they can't do the job.
+The environment is a frequent source of trouble too. Incomplete dev setup, missing dependencies, wrong tool versions — the agent burns precious context window on `pip install` errors and Node version conflicts instead of doing the actual work you gave it.
-Even more common: there's simply no way to verify. No tests, no lint, or verification commands never communicated to the agent. The agent writes code, looks at it, decides it's fine, says "done." It's like asking a student to submit homework with no answer key — they think they got it right, but when you grade it there's a pile of errors. Anthropic also observed an interesting phenomenon: when agents sense context is running low, they rush to finish, skip verification, and choose a simple solution over the optimal one. They call it "context anxiety" — the same thing that happens when you realize time is almost up on an exam and start randomly guessing on the remaining multiple-choice questions.
+Even more common is the complete absence of verification. No tests, no lint, or verification commands that were never communicated to the agent. The agent writes code, looks it over, decides it seems fine, and declares completion. Anthropic also observed an interesting phenomenon: when agents sense their context is running low, they rush to finish, skip verification steps, and choose a simple solution over the optimal one. They call this "context anxiety."
-Long tasks spanning sessions are even worse — all discoveries from the previous session are lost, and every new session has to re-explore the project structure and re-understand the code organization. Agents without persistent state see failure rates spike sharply on tasks exceeding 30 minutes.
+Tasks that span multiple sessions fare even worse. All discoveries from the previous session are lost. Every new session has to re-explore the project structure and re-understand the code organization. Agents without persistent state see failure rates spike sharply on tasks exceeding 30 minutes.
## Key Terminology
-With these scenarios in mind, these concepts are no longer just jargon:
+With the scenarios above in mind, these concepts are no longer just jargon:
-- **Capability Gap**: The huge gulf between model performance on benchmarks and performance on real tasks. A 50-60% pass rate on SWE-bench Verified means nearly half of real issues can't be resolved.
+- **Capability Gap**: The huge gulf between model performance on benchmarks and performance on real tasks. A 50-60% pass rate on SWE-bench Verified means nearly half of real issues go unresolved.
- **Harness**: Everything outside the model — instructions, tools, environment, state management, verification feedback. If it's not model weights, it's harness. What we've been calling the "tack."
-- **Harness-Induced Failure**: The model has enough capability, but the execution environment has structural defects. Anthropic's controlled experiment already proved this.
-- **Verification Gap**: The gap between the agent's confidence in its output and actual correctness. The agent says "I'm done" when it's not done — this is the most common failure mode.
+- **Harness-Induced Failure**: The model has sufficient capability, but the execution environment has structural defects. Anthropic's controlled experiment already proved this.
+- **Verification Gap**: The gap between the agent's confidence in its output and actual correctness. The agent says "I'm done" when it's not — this is the most common failure mode.
- **Diagnostic Loop**: Execute, observe failure, attribute to a specific harness layer, fix that layer, re-execute. This is the core methodology of harness engineering.
-- **Definition of Done**: A set of machine-verifiable conditions — tests pass, lint is clean, type checks pass. Without an explicit definition of done, the agent will invent its own.
+- **Definition of Done**: A set of conditions that can be verified by command — tests pass, lint is clean, type checks pass. Without an explicit definition of done, the agent will invent its own.
## When Things Fail, Fix the Harness First
-Core principle: **When things fail, don't swap the model first — check the harness.** If the same model succeeds on similar, well-structured tasks, assume it's a harness problem. It's like a car breaking down — you don't immediately suspect the engine. You check if it's out of gas first.
-
-Concrete steps:
+There is really only one core principle: **When things fail, don't swap the model first — check the harness.** If the same model succeeds on similar, well-structured tasks, assume it's a harness problem.
-**Attribute every failure to a specific layer.** Don't just say "the model sucks." Ask: was the task unclear? Was context insufficient? Were there no verification methods? Map each failure to one of the five failure layers: task specification, context provision, execution environment, verification feedback, and state management. These are the practical diagnostic layers, not the six glossary terms above. Build this habit, and you'll find "the model isn't good enough" appearing less and less in your logs.
+What does this look like in practice? Attribute every failure to a specific layer. Don't just say "the model isn't good enough." Ask yourself: was the task unclear? Was context insufficient? Were there no verification methods? Map each failure to one of the five defense layers — task specification, context provision, execution environment, verification feedback, state management. Build this habit, and you'll find "the model isn't good enough" appearing less and less in your logs.
-**Write an explicit Definition of Done for every task.** Don't say "add a search feature." Say:
+Then, write an explicit Definition of Done for every task. Don't say "add a search feature." Spell it out:
```
Completion criteria:
- New endpoint GET /api/search?q=xxx
@@ -64,19 +58,15 @@ Completion criteria:
- Type checking passes (mypy --strict)
```
-**Create an AGENTS.md file.** Put it in the repo root to tell the agent the project's tech stack, architectural conventions, and verification commands. This is the first step in harness engineering and the highest-ROI step you can take. One `AGENTS.md` file might be more effective than upgrading to a more expensive model — I'm not joking.
+Place an `AGENTS.md` file in the repo root, telling the agent about the project's tech stack, architectural conventions, and verification commands. This is the first step in harness engineering, and the one with the highest return on investment. One `AGENTS.md` file might be more effective than upgrading to a more expensive model — and that's not a joke.
-**Build a diagnostic loop.** Don't treat failures as "the model being dumb again." Treat them as signals that your harness has a defect. Each failure, identify the layer, fix it, never fail that way again. After a few rounds, your harness gets stronger and agent performance stabilizes. Like road repair — every pothole you fill makes the next stretch smoother.
-
-**Quantify improvements.** Keep a simple log: did each task succeed or fail, and which layer caused the failure. After a few rounds you'll see which layer is the bottleneck — focus your energy there.
+From there, build a diagnostic loop. Don't treat failures as "the model being dumb again." Treat them as signals that your harness has exposed a defect. Each failure, identify the layer, fix it, and never fail that way again. After a few rounds, your harness gets stronger and agent performance stabilizes. A simple log is enough — for each task, did it succeed or fail, and which layer caused the failure. After a few rounds you'll see which layer is the bottleneck, and you can focus your energy there.
## The Million-Line Experiment
-OpenAI ran an aggressive experiment in 2025: use Codex to build a complete internal product from an empty git repository. Five months later, the repo had roughly one million lines of code — application logic, infrastructure, tooling, documentation, internal dev tools — all agent-generated. Three engineers drove Codex, opening and merging about 1,500 PRs. An average of 3.5 PRs per person per day.
-
-The key constraint: **humans never write code directly.** This wasn't a gimmick — it was designed to force the team to figure out what changes when the engineer's primary job is no longer writing code, but designing environments, expressing intent, and building feedback loops.
+In 2025, three engineers at OpenAI started an experiment. The rules were simple: they wouldn't write code themselves — only Codex would. Starting from an empty git repository, five months later the repo contained roughly one million lines of code. Application logic, infrastructure, tooling, documentation — all agent-generated. The three engineers opened a total of 1,500 PRs, an average of 3.5 per person per day.
-Early progress was slower than expected. Not because Codex wasn't capable, but because the environment wasn't complete enough — the agent lacked necessary tools, abstractions, and internal structures to advance high-level objectives. The engineers' work became: breaking large goals into small building blocks (design, code, review, test), letting the agent assemble them, then using those blocks to unlock more complex tasks. When something failed, the fix was almost never "try harder" — it was "what capability is the agent missing, and how do we make it both understandable and executable?"
+Early progress was surprisingly slow. Codex wasn't bad — it just lacked tools and structures complete enough to drive toward high-level objectives. The three engineers gradually found the pattern: break large goals into small building blocks — design, code, review, test — let the agent assemble them one by one, then use those blocks to compose more complex tasks. Whenever something went wrong, the problem was almost never "not trying hard enough." It was always "what is the agent still missing, and can that missing capability be supplied in a way that is both understandable and executable?"
This experiment directly proves this lecture's core thesis: **the same model produces fundamentally different output in a bare environment versus one with a complete harness.** The model didn't change. The environment did.
@@ -84,7 +74,7 @@ This experiment directly proves this lecture's core thesis: **the same model pro
## A More Down-to-Earth Example
-A team used Claude Sonnet to add a new API endpoint to a mid-sized Python web app (FastAPI + PostgreSQL + Redis, ~15,000 lines of code).
+A team used Claude Sonnet to add new API endpoints to a mid-sized Python web app (FastAPI + PostgreSQL + Redis, ~15,000 lines of code).
Initially they gave only one sentence: "add user preferences endpoints under `/api/v2/users`." The result? The agent spent 40% of its context window exploring the repo structure, produced code that looked reasonable but didn't follow the project's error handling patterns, used old SQLAlchemy syntax, and declared completion while the endpoint had runtime errors. The next session had to redo all the discovery work.
@@ -94,11 +84,11 @@ They didn't change the model. They changed the harness.
## Key Takeaways
-- Model capability and execution reliability are different things. A thoroughbred still needs good tack.
-- When things fail, check the harness first, then the model. Swapping models is the most expensive option — and often it's not even a model problem.
-- Every failure is a signal: your harness has a structural defect. Find it, fix it.
-- Five defense layers: task specification, context provision, execution environment, verification feedback, state management. Check them systematically, like a doctor ruling out the most common causes first.
-- One `AGENTS.md` file might be more effective than upgrading to a more expensive model. Seriously.
+- Model capability and execution reliability are two different things. Even a thoroughbred needs good tack.
+- When things fail, check the harness first, then the model. Swapping models is the most expensive option — and more often than not, it's not even a model problem.
+- Every failure is a signal: your harness has a structural defect. Find it and fix it.
+- Don't just say "the model isn't good enough." Work through the five layers systematically: task not clearly defined, insufficient context, misconfigured environment, missing verification, loss of state between sessions. Nine times out of ten the problem lives in one of those layers.
+- One `AGENTS.md` file might be more effective than upgrading to a more expensive model.
## Further Reading
@@ -110,7 +100,7 @@ They didn't change the model. They changed the harness.
## Exercises
-1. **Comparison experiment**: Pick a codebase you know well and a non-trivial modification task. First, run the agent with no harness support and record failures. Then add an `AGENTS.md` with explicit verification commands and run again with the same agent. Compare results, attributing each failure to one of the five defense layers.
+1. **Comparison experiment**: Pick a codebase you know well and a non-trivial modification task. First, run the agent with no harness support and record failures. Then add an `AGENTS.md` and explicit verification commands, and run again with the same agent. Compare the two results, attributing each failure to one of the five defense layers.
2. **Verification gap measurement**: Pick 5 coding tasks. After each task, record whether the agent claims completion, then verify actual correctness with independent tests. Calculate the proportion of times the agent claims done when it's actually not done — that's your verification gap. Then think: what verification commands would reduce this proportion?
diff --git a/docs/en/lectures/lecture-02-what-a-harness-actually-is/index.md b/docs/en/lectures/lecture-02-what-a-harness-actually-is/index.md
index c6efadd..60feb9a 100644
--- a/docs/en/lectures/lecture-02-what-a-harness-actually-is/index.md
+++ b/docs/en/lectures/lecture-02-what-a-harness-actually-is/index.md
@@ -1,43 +1,43 @@
-[中文版本 →](../../../zh/lectures/lecture-02-what-a-harness-actually-is/)
+[中文版 →](../../../zh/lectures/lecture-02-what-a-harness-actually-is/)
> Code examples: [code/](https://github.com/walkinglabs/learn-harness-engineering/blob/main/docs/en/lectures/lecture-02-what-a-harness-actually-is/code/)
> Practice project: [Project 01. Prompt-only vs. rules-first](./../../projects/project-01-baseline-vs-minimal-harness/index.md)
-# Lecture 02. What Harness Actually Means
+# Lecture 02. What a Harness Actually Is
-The word "harness" gets thrown around a lot in AI coding agent circles, but honestly, most people mean "a prompt file" when they say harness. That's not a harness. It's like opening a restaurant with nothing but ingredients — no stove, no knives, no recipes, no plating workflow. That's not a restaurant. That's a refrigerator.
+The word "harness" gets thrown around a lot in AI coding agent circles, but most of the time, when people say "harness," they really just mean a prompt file. A prompt file is not a harness.
-This lecture gives you a precise, actionable harness definition. Not an academic abstraction, but a framework you can use today: a harness consists of five subsystems, each with clear responsibilities and evaluation criteria.
+This lecture gives harness a precise, actionable definition — not an academic abstraction, but a framework you can put to work today. A harness consists of five subsystems: instructions, tools, environment, state, and feedback. Each subsystem has clear responsibilities and evaluation criteria.
## Start with an Analogy
-Imagine you're a newly hired engineer dropped into a project with zero documentation. No README, no comments in the code, nobody tells you how to run tests, CI config is buried somewhere. Can you write good code? Maybe — if you're smart enough and patient enough. But you'll spend enormous time on "figuring out what this project is about" rather than "solving the problem."
+Imagine you are a newly hired engineer, dropped into a project with zero documentation. No README, no comments in the code, nobody tells you how to run tests, CI config is buried somewhere. Can you write good code? Maybe — if you are smart enough and patient enough. But you will spend an enormous amount of time on "figuring out what this project is about" rather than on "solving the problem."
-An AI agent faces the exact same situation. And it's worse — you can at least ask a colleague. The agent can only see files you put in front of it and commands it can execute. It can't tap someone on the shoulder and ask "hey, which version of the ORM does this project use?"
+An AI agent faces the exact same predicament, and it is even worse. You can at least ask a colleague. The agent can only see the files you put in front of it and the commands it can execute.
-OpenAI frames the core principle as "the repo IS the spec" — all necessary context should be in the repository, delivered through structured instruction files, explicit verification commands, and clear directory organization. Anthropic's long-running agents documentation emphasizes state persistence, explicit recovery paths, and structured progress tracking. The two companies focus on different aspects, but they're saying the same thing: **everything in the engineering infrastructure outside the model determines how much of the model's capability actually gets realized.**
+OpenAI frames the core principle of harness engineering as "the repo IS the spec" — all necessary context should live in the repository, delivered through structured instruction files, explicit verification commands, and clear directory organization. Anthropic's long-running agents documentation emphasizes state persistence, explicit recovery paths, and structured progress tracking. The two companies focus on different aspects, but they are saying the same thing: **everything in the engineering infrastructure outside the model determines how much of the model's capability actually gets realized.**
-Look at some tools you already know:
+Look at a few tools you already know:
-**Claude Code** embodies harness thinking. It reads `CLAUDE.md` from your repo (recipe shelf), can run shell commands (knife rack), executes in your local environment (stove), maintains session history (prep station), and can run tests and see results (quality check window). But if you don't tell it how to run tests, the quality check window is broken — nobody knows whether the dish is fully cooked.
+**Claude Code** embodies harness thinking. It reads `CLAUDE.md` from your repo, can run shell commands, executes in your local environment, maintains session history, and can run tests to see results. But if you do not tell it how to run tests, it has no way to verify whether it did things right.
-**Cursor** follows similar logic. Its `.cursorrules` file is the recipe shelf, the terminal is the knife rack, it reads your project structure and lint config for the stove. But Cursor's state management is relatively weak — close the IDE and reopen it, and the previous context is gone.
+**Cursor** follows similar logic. Its `.cursorrules` file is its instruction source, the terminal is its tool, and it can read your project structure and lint config. However, Cursor's state management is relatively weak — close the IDE and reopen it, and the previous context is gone.
-**Codex** (OpenAI's coding agent) uses git worktrees to isolate each task's runtime environment, paired with a local observability stack (logs, metrics, traces), so every change is verified in an independent environment. In repos with `AGENTS.md` and clear verification commands, it performs far better than in "bare" repos.
+**Codex** (OpenAI's coding agent) uses git worktrees to isolate each task's runtime environment, paired with a local observability stack (logs, metrics, traces), so every change is verified in an independent environment. It performs far better in repos with an `AGENTS.md` and clear verification commands than in "bare" repos.
-**AutoGPT** is the cautionary tale — lack of structured state management leads to context accumulation in long tasks, and lack of precise feedback mechanisms causes the agent to loop. Many people say AutoGPT "doesn't work," but really it's AutoGPT's harness that doesn't work — give a chef a broken stove and even the best ingredients won't produce a meal.
+**AutoGPT** is the cautionary tale. Its lack of structured state management causes context to accumulate endlessly during long tasks, and its lack of precise feedback mechanisms causes the agent to loop. Many people say AutoGPT "doesn't work," but really it is the harness that does not work.
## Core Concepts
-- **What is a harness**: Everything in the engineering infrastructure outside the model weights. OpenAI distills the engineer's core job into three things: designing environments, expressing intent, and building feedback loops. Anthropic calls their Claude Agent SDK a "general-purpose agent harness."
-- **The repo is the single source of truth**: Anything the agent can't see, for all practical purposes, doesn't exist. OpenAI treats the repo as the "system of record" — all necessary context must live there, through structured files and clear directory organization.
-- **Give a map, not a manual**: OpenAI's experience — `AGENTS.md` should be a directory page, not an encyclopedia. Around 100 lines is enough. If it doesn't fit, split it into the `docs/` directory and let the agent read on demand.
+- **What is a harness**: Everything in the engineering infrastructure outside the model weights. OpenAI distills the engineer's core job into three things: designing environments, expressing intent, and building feedback loops. Anthropic directly calls their Claude Agent SDK a "general-purpose agent harness."
+- **The repo is the single source of truth**: Anything the agent cannot see, for all practical purposes, does not exist. OpenAI treats the repo as the "system of record" — all necessary context must live there, delivered through structured files and clear directory organization.
+- **Give a map, not a manual**: OpenAI's experience is that `AGENTS.md` should be a directory page, not an encyclopedia. Around 100 lines is enough. If it does not fit, split it into a `docs/` directory and let the agent read on demand.
- **Constrain, don't micromanage**: A good harness uses executable rules to constrain the agent, rather than enumerating instructions one by one. OpenAI says "enforce invariants, don't micromanage implementation"; Anthropic found that agents confidently praise their own work, and the solution is to separate "the person who does the work" from "the person who checks the work."
-- **Remove components one at a time**: To quantify each harness component's marginal contribution, remove them one at a time and see which removal causes the biggest performance drop. Anthropic used this method and found that as models get stronger, some components stop being critical — but new ones always emerge.
+- **Remove components one at a time**: To quantify each harness component's marginal contribution, remove them one at a time and see which removal causes the biggest performance drop. This tells you which components are most valuable right now, and it also reveals which ones are not yet contributing meaningfully. Anthropic used this method and discovered that as models get stronger, some components stop being critical — but new critical components always emerge.
## The Five-Subsystem Harness Model
-Back to the kitchen analogy. A complete kitchen has five functional areas, and a harness has five subsystems:
+Back to the analogy. A harness has five subsystems:
```mermaid
flowchart LR
@@ -49,15 +49,15 @@ flowchart LR
Checks --> Agent
```
-**Instruction subsystem (recipe shelf)**: Create `AGENTS.md` (or `CLAUDE.md`) containing a project overview and purpose (one sentence), tech stack and versions (Python 3.11, FastAPI 0.100+, PostgreSQL 15), first-run commands (`make setup`, `make test`), non-negotiable hard constraints ("All APIs must use OAuth 2.0"), and links to more detailed documentation.
+**Instruction subsystem**: Create `AGENTS.md` (or `CLAUDE.md`) containing a project overview and purpose, tech stack and versions, first-run commands, non-negotiable hard constraints, and links to more detailed documentation.
-**Tool subsystem (knife rack)**: Ensure the agent has sufficient tool access. Don't disable shell for "security" — if the agent can't even run `pip install`, how is it supposed to work? But don't open everything either — follow least-privilege principles.
+**Tool subsystem**: Ensure the agent has sufficient tool access. Do not disable shell for "security reasons" — if the agent cannot even run `pip install`, how is it supposed to get anything done? But do not open everything either — follow the principle of least privilege.
-**Environment subsystem (stove)**: Make the environment state self-describing. Use `pyproject.toml` or `package.json` to lock dependencies, `.nvmrc` or `.python-version` for runtime versions, Docker or devcontainers for reproducibility.
+**Environment subsystem**: Make the environment state self-describing. Use `pyproject.toml` or `package.json` to lock dependencies, `.nvmrc` or `.python-version` to specify runtime versions, and Docker or devcontainers to make the environment reproducible.
-**State subsystem (prep station)**: Long tasks need progress tracking. Use a simple `PROGRESS.md` file recording: what's done, what's in progress, what's blocked. Update before each session ends, read when the next session starts.
+**State subsystem**: Long tasks must have progress tracking. Use a simple `PROGRESS.md` file recording: what is done, what is in progress, what is blocked. Update before each session ends; read when the next session starts.
-**Feedback subsystem (quality check window)**: This is the highest-ROI subsystem. Explicitly list verification commands in `AGENTS.md`:
+**Feedback subsystem**: This is the highest-ROI subsystem. Explicitly list verification commands in `AGENTS.md`:
```
Verification commands:
- Tests: pytest tests/ -x
@@ -66,31 +66,31 @@ Verification commands:
- Full verification: make check (includes all above)
```
-Missing any subsystem is like missing a functional area in the kitchen — you can still cook, but it's always awkward.
+Missing any one of the five subsystems means an incomplete harness, and the agent will always feel awkward to use.
-**Quantifying harness component value**: Use an "isometric model control" ablation. Keep the model fixed, remove subsystems one at a time, and measure which removal causes the biggest performance drop. The largest drop identifies the component with the highest marginal contribution in that task; it does not automatically identify the bottleneck. A near-zero drop also needs interpretation: the component may be redundant, poorly designed, or simply not exercised by that task. To diagnose bottlenecks, use failure logs and attribution first, then use ablation as supporting evidence: was the failure caused by unclear task intent, insufficient context, unreproducible environment, missing verification feedback, or broken state management?
+**Quantifying harness component value**: Use an "ablation experiment under the same model." Keep the model fixed, remove the five subsystems one at a time, and see which subsystem's removal causes the biggest performance drop. The component with the largest drop has the highest marginal contribution for the current task and is worth prioritizing. Whether to strengthen it depends on failure attribution, not just the size of the drop. Components with near-zero impact should not be dismissed outright: they may be redundant, poorly designed, or simply not exercised by the current task. This experiment answers "which component is most valuable right now" — it cannot, by itself, prove "where the bottleneck is." To truly locate a bottleneck, you must first examine failure records and attributions: was the task unclear, was context insufficient, was the environment unreproducible, was verification feedback missing, or was state management broken? Component ablation results can only serve as supporting evidence.
## A Team's Real Story
-A team used GPT-4o on a TypeScript + React frontend app (~20,000 lines of code). They went through four stages — essentially adding kitchen equipment one piece at a time:
+A team used GPT-4o to develop a TypeScript + React frontend application (~20,000 lines of code). They went through four stages, which were essentially adding harness components one at a time:
-**Stage 1 — Empty kitchen**: Only a basic project description in README. 1 out of 5 runs succeeded (20%). Main failures: chose wrong package manager (npm vs yarn), didn't follow component naming conventions, couldn't run tests.
+**Stage 1**: Only a basic project description in the README. 1 out of 5 runs succeeded (20%). Main failures: chose the wrong package manager (npm vs yarn), did not follow component naming conventions, could not run tests.
-**Stage 2 — Recipe shelf installed**: Added `AGENTS.md` with tech stack versions, naming conventions, key architecture decisions. Success rate rose to 60%. Remaining failures were mainly environment issues and missing verification.
+**Stage 2**: Added `AGENTS.md` specifying tech stack versions, naming conventions, and key architecture decisions. Success rate rose to 60%. Remaining failures were mainly from environment issues and missing verification.
-**Stage 3 — Quality check window opened**: Listed verification commands in `AGENTS.md`: `yarn test && yarn lint && yarn build`. Success rate rose to 80%.
+**Stage 3**: Listed verification commands in `AGENTS.md`: `yarn test && yarn lint && yarn build`. Success rate rose to 80%.
-**Stage 4 — Prep station ready**: Introduced progress file templates where agents recorded completed and incomplete work each run. Success rate stabilized at 80-100%.
+**Stage 4**: Introduced progress file templates where the agent recorded completed and incomplete work each run. Success rate stabilized at 80-100%.
-Four iterations, the model didn't change at all, success rate went from 20% to near 100%. That's the power of harness engineering. You didn't buy more expensive ingredients — you just organized the kitchen properly.
+Four iterations, the model did not change at all, and success rate went from 20% to near 100%. You did not switch to a better model — what changed was the harness.
## Key Takeaways
-- Harness = Instructions + Tools + Environment + State + Feedback. Five subsystems, like a kitchen's five functional areas — all essential.
-- If it's not model weights, it's harness. Your harness determines how much model capability gets realized.
-- Among the five subsystems, the feedback subsystem usually has the lowest investment and highest return. Get your verification commands right first — the quality check window is the most worthwhile upgrade.
-- Use "isometric model control" to quantify marginal contribution; use failure logs and attribution, not ablation alone, to locate the real bottleneck.
-- Harness rots like code does. Audit regularly, pay down harness debt like you pay down technical debt.
+- Harness = Instructions + Tools + Environment + State + Feedback. All five subsystems are essential.
+- If it is not model weights, it is harness. Your harness determines how much of the model's capability gets realized.
+- Among the five subsystems, the feedback subsystem usually has the lowest investment and highest return. Get your verification commands right first.
+- Use "ablation experiments under the same model" to quantify each subsystem's marginal contribution; to locate the real bottleneck, rely on failure records and attribution, not ablation alone.
+- Harness rots like code does. Audit regularly, and pay down harness debt just like you pay down technical debt.
## Further Reading
@@ -102,8 +102,8 @@ Four iterations, the model didn't change at all, success rate went from 20% to n
## Exercises
-1. **Five-tuple harness audit**: Take a project where you use an AI agent and do a complete audit using the five-tuple framework. Score each subsystem 1-5. Find the lowest-scoring subsystem, spend 30 minutes improving it, then observe the change in agent performance.
+1. **Five-tuple harness audit**: Take a project where you currently use an AI agent and do a complete audit using the five-tuple framework. Score each subsystem 1-5. Find the lowest-scoring subsystem, spend 30 minutes improving it, and then observe the change in agent performance.
-2. **Component-value ablation under the same model**: Pick one model and one challenging task. Sequentially remove instructions (delete AGENTS.md), remove feedback (don't provide verification commands), remove state (no progress files) — remove only one at a time and measure the performance drop. Use the results to rank subsystem marginal value. If you want to find a bottleneck, pair the ranking with failure logs and attribution instead of treating the largest drop as the answer by itself.
+2. **Component-value ablation under the same model**: Pick one model and one challenging task. Sequentially remove instructions (delete AGENTS.md), remove feedback (do not provide verification commands), remove state (no progress files) — removing only one at a time, and measure the performance drop. Use the results to rank each subsystem's marginal value for the current task. If you want to find the bottleneck, you must also record failure logs and do root-cause attribution alongside the ablation.
-3. **Affordance analysis**: Find a scenario where the agent in your project "wants to do something but can't" (e.g., knows it should use parameterized queries but doesn't know your project's ORM patterns). Analyze whether this is a Gulf of Execution (doesn't know how) or Gulf of Evaluation (doesn't know if it's right), then design a harness improvement to bridge it.
+3. **Affordance analysis**: Find a scenario in your project where the agent "wants to do something but can't" (e.g., knows it should use parameterized queries but does not know your project's ORM patterns). Analyze whether this is a Gulf of Execution (does not know how to operate) or a Gulf of Evaluation (does not know whether it did things right), then design a harness improvement to bridge the gap.
diff --git a/docs/en/lectures/lecture-03-why-the-repository-must-become-the-system-of-record/index.md b/docs/en/lectures/lecture-03-why-the-repository-must-become-the-system-of-record/index.md
index b59d885..a3fecdc 100644
--- a/docs/en/lectures/lecture-03-why-the-repository-must-become-the-system-of-record/index.md
+++ b/docs/en/lectures/lecture-03-why-the-repository-must-become-the-system-of-record/index.md
@@ -1,47 +1,47 @@
-[中文版本 →](../../../zh/lectures/lecture-03-why-the-repository-must-become-the-system-of-record/)
+[中文版 →](../../../zh/lectures/lecture-03-why-the-repository-must-become-the-system-of-record/)
> Code examples: [code/](https://github.com/walkinglabs/learn-harness-engineering/blob/main/docs/en/lectures/lecture-03-why-the-repository-must-become-the-system-of-record/code/)
-> Practice project: [Project 02. Agent-readable workspace](./../../projects/project-02-agent-readable-workspace/index.md)
+> Practice project: [Project 02. Make the Agent Read the Project and Pick Up Where It Left Off](./../../projects/project-02-agent-readable-workspace/index.md)
-# Lecture 03. Make the Repository Your Single Source of Truth
+# Lecture 03. Making the Repository the Single Source of Truth
-Your team's architecture decisions are scattered across Confluence, Slack, Jira, and a few senior engineers' heads. For humans this barely works — you can ask a colleague, search chat history, dig through docs. If all else fails, you can corner someone in the break room. But for an AI agent, information that's not in the repository simply does not exist.
+Your team's architecture decisions are scattered across Confluence, Slack, Jira, and a few senior engineers' heads. For humans this barely works — you can ask a colleague, search chat logs, dig through documentation, and if all else fails, you can corner someone in the break room. But for an AI agent, information that's not in the repository simply does not exist.
-This isn't an exaggeration. Think about what an agent's inputs actually are: system prompts and task descriptions, file contents from the repository, and tool execution output. That's it. Your Slack history, Jira tickets, Confluence pages, and that architecture decision you discussed with a colleague over coffee on Friday afternoon — the agent can't see any of it. It can't "go ask someone" or "search the chat history." It's an engineer locked inside the repository — everything outside, it knows nothing about.
+This isn't an exaggeration. An agent has only three sources of input: system prompts and task descriptions, file contents from the repository, and tool execution output. Your Slack history, Jira tickets, Confluence pages, and that architecture decision you hashed out with a colleague on Friday afternoon — the agent can't see any of it. It can't "go ask someone" or "search the chat logs." Its entire working world is the repository itself. Everything outside, it knows nothing about.
-So the question becomes: are you going to give this engineer a good map?
+So the real question is: are you going to give it a map that's good enough?
## What Belongs on the Map
-OpenAI states this bluntly: **information that doesn't exist in the repo, doesn't exist for the agent.** They call this the "repo as spec" principle — the repository itself is the highest-authority specification document.
+OpenAI states this plainly in their harness engineering article: **information that doesn't exist in the repo, doesn't exist for the agent.** They call this the "repo as spec" principle — the repository itself is the highest-authority specification document.
-Anthropic's long-running agents documentation echoes this: persistent state is a necessary condition for long-task continuity. Cross-session knowledge recoverability directly determines task success rates. And this state must exist in the repository — because that's the only stable, accessible storage the agent has.
+Anthropic's long-running agents documentation echoes a similar point: persistent state is a necessary condition for long-task continuity, and cross-session knowledge recoverability directly determines task success rates. And this state must exist in the repository — because that's the only stable, reliably accessible storage the agent has.
-You might think: "Our team is small, knowledge is in everyone's heads, and it works fine." Sure, for humans. But if you're using an agent, accept this fact: the agent can't ask people. Everything it needs to know must be written down and placed where it can find it.
+You might think: "Our team is small, knowledge lives in everyone's heads, and it works fine." True enough — for humans. But if you want to use an agent, you have to accept one fact: the agent can't ask people. Everything it needs to know must be written down, placed somewhere it can find it.
-This isn't about "writing more documentation." It's about "putting decision information in the right place." A 50-line `ARCHITECTURE.md` in the `src/api/` directory is ten thousand times more useful than a 500-page design document in Confluence that nobody maintains. It's like a hand-drawn office map taped to your desk versus a beautiful architectural blueprint locked in a filing cabinet — the former is right there when you need it; the latter is technically superior but useless in the moment.
+This isn't a "write more documentation" problem — it's a "put decision information in the right place" problem. A 50-line `ARCHITECTURE.md` sitting in the `src/api/` directory is far more useful than a 500-page design document in Confluence that nobody maintains. Proximity matters more than length, because information is only truly useful when it's right at hand the moment you need it.
## Knowledge Visibility
```mermaid
flowchart LR
- Slack["Rules in Slack"] --> Write["Write them into repo files<br/>AGENTS.md / ARCHITECTURE.md / PROGRESS.md"]
+ Slack["Rules in Slack"] --> Write["Write into repo files<br/>AGENTS.md / ARCHITECTURE.md / PROGRESS.md"]
Confluence["Rules in Confluence"] --> Write
- Heads["Rules in people's heads"] --> Write
- Jira["Rules in Jira tickets"] --> Write
+ Heads["Rules in engineers' heads"] --> Write
+ Jira["Rules in Jira"] --> Write
Write --> Repo["Repository files"]
Repo --> Agent["New agent session<br/>reads the repo directly"]
- Warning["If a rule is not in the repo,<br/>the agent cannot see it"] --> Agent
+ Warning["If a rule isn't in the repo,<br/>the agent can't see it"] --> Agent
```
-How do you test whether your map is good enough? Run a "cold-start test": open a brand new agent session using only repo contents, and see if it can answer five basic questions:
+How do you test whether your map is good enough? Run a "cold-start test": open a brand-new agent session, give it only the repository contents, and see if it can answer five basic questions.
```mermaid
flowchart TB
Q1["What is this system?"] --> A1["AGENTS.md / README"]
Q2["How is it organized?"] --> A2["ARCHITECTURE.md / module docs"]
Q3["How do I run it?"] --> A3["Makefile / init.sh / package scripts"]
- Q4["How do I verify it?"] --> A4["Test, lint, and check commands"]
+ Q4["How do I verify it?"] --> A4["Test, lint, check commands"]
Q5["Where are we now?"] --> A5["PROGRESS.md / feature list / git history"]
A1 --> Ready["A new session can start work<br/>without asking a human"]
@@ -51,26 +51,26 @@ flowchart TB
A5 --> Ready
```
-If it can't answer, the map has blank spots. Where the map is blank, the agent guesses — wrong guesses become bugs, excessive guessing wastes context. And every new session guesses all over again. The cost of guessing is always higher than the cost of drawing the map properly in the first place.
+If it can't answer, the map has blank spots. Where the map is blank, the agent has to guess — wrong guesses become bugs, excessive guessing wastes context. And every new session has to guess all over again. The cost of guessing is always far higher than the cost of drawing the map properly in the first place.
## Core Concepts
-- **Knowledge Visibility Gap**: The proportion of total project knowledge that's NOT in the repository. The bigger the gap, the higher the agent's failure rate. How much implicit knowledge about this project lives in your head? Count it all, then see how much made it into the repo — the difference is your visibility gap.
-- **System of Record**: The code repository as the authoritative source for project decisions, architecture constraints, execution state, and verification standards. The repo has the final word, nowhere else counts. Like a map that marks "road closed" — you won't go down that road. But if that information only exists in Old Zhang's head, you have to ask Old Zhang every time.
-- **Cold-Start Test**: The five questions above. How many it can answer is how complete your map is.
-- **Discovery Cost**: How much context budget the agent burns to find a key piece of information in the repo. The more hidden the information, the higher the discovery cost, and the less budget left for the actual task. Hiding critical information in a README ten directory levels deep is like locking the fire extinguisher in a basement safe — it exists, but you can't find it when you need it.
-- **Knowledge Decay Rate**: The proportion of knowledge entries that become stale per unit of time. Documentation going out of sync with code is the biggest enemy — worse than no documentation at all.
+- **Knowledge Visibility Gap**: The proportion of total project knowledge that's NOT in the repository. The bigger the gap, the higher the agent's failure rate. You can estimate it like this: count all the implicit knowledge about this project that lives in people's heads, then see how much of it actually made it into the repo. The difference is your visibility gap.
+- **System of Record**: The code repository as the authoritative source for project decisions, architecture constraints, execution state, and verification standards. The repo has the final say — nowhere else counts. If the information "this road is closed" only lives in Old Zhang's head, then every single time you have to ask Old Zhang. Write it in the repo, and nobody has to ask.
+- **Cold-Start Test**: The five questions from the previous section. How many the agent can answer is how complete your map is.
+- **Discovery Cost**: How much context budget the agent burns to find a single key piece of information in the repo. The more hidden the information, the higher the discovery cost, and the less budget remains for the actual task. Critical information should be placed where the agent sees it first — not buried ten directory levels deep.
+- **Knowledge Decay Rate**: The proportion of knowledge entries in the repo that become stale per unit of time. Documentation drifting out of sync with code is the biggest enemy — worse than no documentation at all is documentation that's out of date.
- **ACID Analogy**: Applying database transaction principles (Atomicity, Consistency, Isolation, Durability) to agent state management. We'll expand on this below.
## How to Draw a Good Map
-**Principle 1: Knowledge lives next to code.** A rule about API endpoint authentication belongs next to the API code, not buried in a giant global document. Put a short doc in each module directory explaining that module's responsibilities, interfaces, and special constraints. Like library shelf labels — you want history books, go straight to the shelf marked "History." No need to search the entire library.
+**Principle 1: Knowledge lives next to code.** A rule about API endpoint authentication belongs next to the API code, not buried in a giant global document. Put a short doc in each module directory explaining that module's responsibilities, interfaces, and special constraints. The module directory itself is a natural index — when the agent reaches the code, it also reaches the constraints, no searching required.
-**Principle 2: Use a standardized entry file.** `AGENTS.md` (or `CLAUDE.md`) is the agent's "landing page." It doesn't need to contain all information, but it must let the agent quickly answer three questions: "What is this project," "How do I run it," and "How do I verify it." 50-100 lines is enough.
+**Principle 2: Use a standardized entry file.** `AGENTS.md` (or `CLAUDE.md`) is the agent's "landing page." It doesn't need to contain all information, but it must let the agent quickly answer three questions: "What is this project," "How do I run it," and "How do I verify it." 50–100 lines is enough.
-**Principle 3: Minimal but complete.** Every piece of knowledge should have a clear use case. If removing a rule doesn't affect the agent's decision quality, that rule shouldn't exist. But every question from the cold-start test must have an answer. This is a delicate balance — not too much, not too little, just enough.
+**Principle 3: Minimal but complete.** Every piece of knowledge should have a clear use case. If removing a rule doesn't affect the agent's decision quality, that rule shouldn't exist. But every question from the cold-start test must have an answer. This is an ongoing balance to maintain — not too much, not too little, just enough.
-**Principle 4: Update with code.** Bind knowledge updates to code changes. The simplest approach: put architecture docs in the corresponding module directory. When you modify code, you naturally see the doc. After code changes, CI can remind you to check if docs need updating.
+**Principle 4: Update with code.** Bind knowledge updates to code changes. The simplest approach: put architecture docs in the corresponding module directory. When you modify code, you naturally notice the doc. After code changes, CI can remind you to check whether the docs need updating.
**Concrete repo structure**:
@@ -91,34 +91,34 @@ project/
## Managing Agent State with ACID Principles
-This analogy comes from database transaction management — you might think it's overcomplicating things, but it actually gives you a very practical framework:
+This analogy comes from database transaction management. You might feel like this is overcomplicating things, but it actually provides a very practical framework:
- **Atomicity**: Each "logical operation" (e.g., "add new endpoint and update tests") gets one git commit. If it fails midway, `git stash` to roll back. All or nothing — no "half done."
-- **Consistency**: Define "consistent state" verification predicates — all tests pass, lint reports zero errors. The agent runs verification after each operation; inconsistent intermediate states don't get committed. Like a bank transfer — you can't debit without crediting.
-- **Isolation**: When multiple agents work concurrently, design state files to avoid race conditions. Simple approach: each agent uses its own progress file, or use git branches for isolation. Two chefs can't season the same pot simultaneously — who takes responsibility when it's over-salted?
-- **Durability**: Critical project knowledge lives in git-tracked files. Temporary state can stay in session memory, but cross-session knowledge must be persisted to files. What's in your head doesn't count — only what's on paper counts.
+- **Consistency**: Define "consistent state" verification predicates — all tests pass, lint reports zero errors. The agent runs verification after each operation; inconsistent intermediate states should not be committed. After an operation, the system should be in a verifiably correct state.
+- **Isolation**: When multiple agents work concurrently, design state files to avoid race conditions. Simple approach: each agent uses its own progress file, or use git branches for isolation. Concurrent writes to the same file are a common source of trouble.
+- **Durability**: Critical project knowledge lives in git-tracked files. Temporary state can stay in session memory, but knowledge that must survive across sessions has to be written to files. What's in your head doesn't count — only what's written down counts.
## A Real Transformation Story
-A team maintained an e-commerce platform with ~30 microservices. Architecture decisions (inter-service communication protocols, data consistency strategies, API versioning rules) were scattered across: Confluence (partially outdated), Slack (hard to search), a few senior engineers' heads (not scalable), and sporadic code comments (not systematic).
+A team maintained an e-commerce platform with roughly 30 microservices. Architecture decisions — inter-service communication protocols, data consistency strategies, API versioning rules — were scattered across: Confluence (partially outdated), Slack (hard to search), a few senior engineers' heads (not scalable), and sporadic code comments (not systematic).
-After introducing AI agents, 70% of tasks required human intervention. Nearly every failure involved the agent violating some "everyone knows but nobody wrote down" implicit constraint. It's like a new employee whom nobody told "you need to post your lunch order in the group chat" — they guess wrong, get scolded, but after the scolding still nobody tells them the rule.
+After introducing AI agents, 70% of tasks required human intervention. Nearly every failure involved the agent violating some implicit constraint that "everyone knows but nobody ever wrote down." The agent had no way to know what it didn't know — it could only act on its own understanding, and then step right into the trap.
The team executed a transformation:
1. Created `AGENTS.md` in the repo root with project overview, tech stack versions, and global hard constraints
-2. Added `ARCHITECTURE.md` in each microservice directory describing responsibilities, interfaces, and dependencies
-3. Created a centralized `CONSTRAINTS.md` with hard constraints in explicit "MUST/MUST NOT" language
+2. Added `ARCHITECTURE.md` in each microservice directory describing that service's responsibilities, interfaces, and dependencies
+3. Created a centralized `CONSTRAINTS.md` using explicit "MUST / MUST NOT" language for hard constraints
4. Added `PROGRESS.md` in each service directory tracking current work status
After transformation: the same agent could answer all key project questions on cold start, and task completion quality improved significantly.
## Key Takeaways
-- Knowledge not in the repo doesn't exist for the agent. Putting critical decisions in the repo is the most basic harness investment — draw a good map so you don't get lost.
-- Use the "cold-start test" to evaluate repo quality: can a fresh session answer five basic questions using only repo contents?
-- Knowledge should be near code, minimal but complete, and updated with code. It's not about writing more docs — it's about putting information in the right place.
-- Use ACID principles for agent state: atomic commits, consistency verification, concurrency isolation, durable critical knowledge.
-- Knowledge decay is the biggest enemy. Documentation out of sync with code is more dangerous than no documentation — it sends the agent in the wrong direction while they think they're right.
+- Knowledge not in the repo doesn't exist for the agent. Putting critical decision information into the repository is the most fundamental harness investment — draw a good map so you don't get lost.
+- Use the "cold-start test" to evaluate repo quality: can a brand-new session answer five basic questions using only repo contents?
+- Knowledge should be near code, minimal but complete, and updated together with code. It's not about writing more docs — it's about putting information in the right place.
+- Use ACID principles for agent state: atomic commits, consistency verification, concurrency isolation, and durable critical knowledge.
+- Knowledge decay is the biggest enemy. Out-of-date documentation is more dangerous than no documentation at all — it sends the agent in the wrong direction while the agent thinks it's on the right track.
## Further Reading
@@ -130,8 +130,8 @@ After transformation: the same agent could answer all key project questions on c
## Exercises
-1. **Cold-start test**: Open a completely fresh agent session in your project (no verbal context, repo contents only). Ask it five questions: What is this system? How is it organized? How do I run it? How do I verify it? What's the current progress? Record what it can't answer, then improve the repo until it can.
+1. **Cold-start test**: Open a completely fresh agent session in your project (provide no verbal context whatsoever), let it see only the repository contents, then ask it five questions: What is this system? How is it organized? How do I run it? How do I verify it? What's the current progress? Record which ones it can't answer, then improve the repo until it can answer all of them.
-2. **Knowledge externalization quantification**: List all decisions and constraints important for development work in your project. Mark each as inside or outside the repo. Calculate your knowledge visibility gap (proportion outside repo). Make a plan to get it below 10%.
+2. **Knowledge externalization quantification**: List all decisions and constraints important to development work in your project. Mark each item as inside or outside the repo. Calculate your knowledge visibility gap (the proportion of items outside the repo). Make a plan to bring the gap below 10%.
-3. **ACID assessment**: Evaluate your project's state management using this lecture's ACID analogy. Atomicity — can agent operations be cleanly rolled back? Consistency — is there "consistent state" verification? Isolation — do concurrent agents step on each other? Durability — is all cross-session knowledge persisted?
+3. **ACID assessment**: Evaluate your project's state management using this lecture's ACID analogy. Atomicity — can agent operations be cleanly rolled back? Consistency — does the repo have "consistent state" verification? Isolation — do multiple concurrent agents step on each other's toes? Durability — is all cross-session knowledge properly persisted?
diff --git a/docs/en/lectures/lecture-04-why-one-giant-instruction-file-fails/index.md b/docs/en/lectures/lecture-04-why-one-giant-instruction-file-fails/index.md
index 7006c9b..bfe7bf4 100644
--- a/docs/en/lectures/lecture-04-why-one-giant-instruction-file-fails/index.md
+++ b/docs/en/lectures/lecture-04-why-one-giant-instruction-file-fails/index.md
@@ -1,65 +1,65 @@
-[中文版本 →](../../../zh/lectures/lecture-04-why-one-giant-instruction-file-fails/)
+[中文版 →](../../../zh/lectures/lecture-04-why-one-giant-instruction-file-fails/)
> Code examples: [code/](https://github.com/walkinglabs/learn-harness-engineering/blob/main/docs/en/lectures/lecture-04-why-one-giant-instruction-file-fails/code/)
> Practice project: [Project 02. Agent-readable workspace](./../../projects/project-02-agent-readable-workspace/index.md)
# Lecture 04. Split Instructions Across Files
-You got serious about harness engineering — good for you. You created an `AGENTS.md` and packed every rule, constraint, and lesson learned you could think of into it. One month later the file bloated to 300 lines, two months 450 lines, three months 600 lines. Then you notice the agent's performance is actually getting worse — on a simple bug fix, the agent burns tons of context processing irrelevant deployment instructions; a critical security constraint buried at line 300 gets ignored outright; three contradictory code style rules mean the agent picks one at random each time.
+You started taking harness engineering seriously — good. You created an `AGENTS.md` and packed in every rule, constraint, and lesson learned you could think of. One month later the file had ballooned to 300 lines, two months 450, three months 600. Then you notice the agent's performance is actually getting worse: on a simple bug fix, the agent burns through huge amounts of context processing irrelevant deployment instructions; a critical security constraint buried at line 300 gets ignored outright; three contradictory code style rules mean the agent picks one at random each time.
-This is the "giant instruction file" trap. It's like overpacking a suitcase — everything seems useful, so you cram it all in until the zipper is about to burst. Finding your change of underwear means emptying the entire bag. You carried a full suitcase, but you actually used maybe a third of what's inside.
+This is the "giant instruction file" trap. Everything seems useful, so you cram it all in, and finding one specific rule means rifling through the entire file. You wrote 600 lines, but only a third of it is relevant to the task at hand.
## The Vicious Cycle at the Root
-The most common vicious cycle goes like this: agent makes a mistake, you say "add a rule to prevent this," add it to AGENTS.md, it works temporarily, agent makes a different mistake, add another rule, repeat, file bloats out of control.
+The most common vicious cycle goes like this: the agent makes a mistake, you say "add a rule to prevent this," you add it to AGENTS.md, and it works — temporarily. Then the agent makes a different mistake, so you add another rule. Repeat until the file bloats out of control.
-This isn't your fault. It's a very natural reaction — "add a rule" each time something goes wrong feels reasonable, like tossing one more thing into your bag every time you leave the house "just in case." But the cumulative effect is disastrous. Let's look at what goes wrong specifically.
+This is a perfectly natural reaction. "Add a rule" every time something goes wrong feels reasonable. But the cumulative effect is disastrous. Let's look at exactly what goes wrong.
-**Context budget gets eaten alive.** The agent's context window is finite. Say your agent has a 200K token window (Claude's standard). A bloated instruction file might eat 10-20K tokens. Seems like there's still plenty of room? But a complex task might need to read dozens of source files, tool execution output also takes context, and conversation history accumulates. By the time the agent needs to understand the code, the budget is already tight — like a suitcase so full of "just in case" items that there's no room for your laptop.
+**Context budget gets eaten alive.** The agent's context window is finite. Say your agent has a 200K token window (Claude's standard). A bloated instruction file might consume 10-20K tokens. Seems like there's still plenty of headroom? But a complex task might need to read dozens of source files, tool execution output also takes up context, and conversation history keeps accumulating. By the time the agent actually needs to understand the code, the budget is already exhausted.
-**Lost in the middle.** The "Lost in the Middle" paper (Liu et al., 2023) clearly demonstrated that LLMs utilize information in the middle of long texts significantly less effectively than at the beginning or end. Your AGENTS.md is 600 lines, and line 300 says "all database queries must use parameterized queries" — that's a security hard constraint. But it's buried in the middle, and the agent will almost certainly ignore it. Like that bottle of sunscreen at the bottom of your overstuffed suitcase — you know it's there, you dig three times, can't find it, end up buying another one.
+**Lost in the middle.** The "Lost in the Middle" paper (Liu et al., 2023) clearly demonstrated that LLMs utilize information in the middle of long texts significantly less effectively than at the beginning or end. Your AGENTS.md is 600 lines long, and line 300 says "all database queries must use parameterized queries" — that's a security hard constraint. But it's buried in the middle, and the agent will almost certainly ignore it.
-**Priority conflicts.** The file mixes non-negotiable hard constraints ("never use eval()"), important design guidelines ("prefer functional style"), and a specific historical lesson ("fixed a WebSocket memory leak last week, watch for similar patterns"). These three rules have completely different importance levels, but they look identical in the file. The agent has no reliable signal to distinguish — like your passport and charging cable jumbled together in the suitcase, no way to tell which is more urgent.
+**Priority conflicts.** The file mixes non-negotiable hard constraints ("never use eval()"), important design guidelines ("prefer functional style"), and a specific historical lesson ("fixed a WebSocket memory leak last week, watch for similar patterns"). These three rules have completely different importance levels, but in the file they all look identical. The agent has no reliable signal to distinguish which is a red line and which is merely a suggestion.
-**Maintenance decay.** Large files are inherently hard to maintain. Outdated instructions rarely get deleted — because the consequences of deletion are uncertain ("maybe something else depends on this rule?"), while adding new instructions feels free. The result: the file only grows, never shrinks, and signal-to-noise ratio continuously declines. This is exactly like technical debt accumulation in software.
+**Maintenance decay.** Large files are inherently hard to maintain. Outdated instructions rarely get deleted, because the consequences of deletion are uncertain ("maybe something else depends on this rule?"), but adding new instructions feels cost-free. The result: the file only grows, never shrinks, and the signal-to-noise ratio steadily declines. This is the same problem as technical debt accumulation in software.
-**Contradiction accumulation.** Instructions added at different times start contradicting each other — one says "use TypeScript strict mode," another says "some legacy files allow any types." The agent randomly picks one to follow each time. Like your mom saying "dress warm" and your dad saying "don't wear too much," and you standing at the door not knowing who to listen to.
+**Contradiction accumulation.** Instructions added at different times start contradicting each other — one says "use TypeScript strict mode," another says "some legacy files are allowed to use any." The agent picks one at random each time.
## Core Concepts
-- **Instruction Bloat**: When an instruction file occupies more than 10-15% of the context window, it starts crowding out budget for code reading and task reasoning. A 600-line `AGENTS.md` might consume 10,000-20,000 tokens — that's 8-15% of a 128K window eaten before the agent even starts.
-- **Lost in the Middle Effect**: Liu et al.'s 2023 research proved that LLMs use information in the middle of long texts significantly less effectively than information at the beginning or end. A critical constraint buried at line 300 of a 600-line file has a very high probability of being effectively ignored.
+- **Instruction Bloat**: When an instruction file occupies 10-15% of the context window, it starts crowding out budget for code reading and task reasoning. A 600-line `AGENTS.md` might consume 10,000-20,000 tokens — that's 8-15% of a 128K window.
+- **Lost in the Middle Effect**: Liu et al.'s 2023 research showed that LLMs utilize information in the middle of long texts significantly less effectively than information at the beginning or end. A critical constraint buried at line 300 of a 600-line file has a very high probability of being ignored.
- **Instruction Signal-to-Noise Ratio (SNR)**: The proportion of instructions in a file that are relevant to the current task. Being forced to read 50 lines of deployment instructions during a bug fix — that's low SNR.
-- **Routing File**: A short entry file whose core function is pointing the agent to more detailed docs, not containing everything itself. 50-200 lines is plenty.
+- **Routing File**: A short entry file whose purpose is to guide the agent toward more detailed documentation, rather than containing everything itself. 50-200 lines is sufficient.
- **Progressive Disclosure**: Give overview information first, detailed information when needed. Good harness design is like good UI design — don't dump all options on the user at once.
-- **Priority Ambiguity**: When all instructions appear in the same format and location, the agent can't distinguish non-negotiable hard constraints from suggestive soft guidelines.
+- **Priority Ambiguity**: When all instructions appear in the same format and location, the agent cannot distinguish non-negotiable hard constraints from suggestive soft guidelines.
## Instruction Architecture
```mermaid
flowchart LR
- Mono["One 600-line AGENTS.md"] --> MonoLoad["Even a small bug fix<br/>must read deploy rules and old notes"]
- MonoLoad --> MonoRisk["Important rules buried in the middle<br/>are easy to miss"]
+ Mono["One giant AGENTS.md"] --> MonoLoad["Even a small bug fix<br/>means reading all deploy rules and old notes"]
+ MonoLoad --> MonoRisk["Critical rules buried in the middle<br/>easily missed"]
- Router["Short AGENTS.md"] --> Topics["Load API / DB / testing docs<br/>only when this task needs them"]
+ Router["Short AGENTS.md"] --> Topics["Read API / DB / testing docs<br/>only when this task needs them"]
Topics --> RoutedResult["More context left for code reading<br/>and verification"]
```
```mermaid
flowchart TB
File["600-line instruction file"] --> Top["Top section<br/>quick start + hard constraints"]
- File --> Mid["Middle section<br/>critical security rule at line 300"]
+ File --> Mid["Middle section<br/>security rule at line 300"]
File --> Bot["Bottom section<br/>explicit end-of-file checklist"]
- Top --> Seen["High chance of recall"]
+ Top --> Seen["High probability of recall"]
Bot --> Seen
- Mid --> Missed["High chance of being diluted or missed"]
+ Mid --> Missed["High probability of being diluted or ignored"]
```
## How to Split
-Core principle: keep frequently-needed information at hand, tuck away occasionally-needed information, and leave behind what you'll never use.
+Core principle: keep frequently-needed information at hand, tuck away occasionally-needed information, and don't carry what you'll never use.
-The entry file `AGENTS.md` stays at 50-200 lines, containing only the most frequently used items — project overview (one or two sentences), first-run commands (`make setup && make test`), global hard constraints (no more than 15 non-negotiable rules), and links to topic documents (one-line description + applicability condition).
+The entry file `AGENTS.md` stays at 50-200 lines, containing only the most essential items: a project overview (one or two sentences that make it clear what this is), first-run commands (`make setup && make test`), global hard constraints (no more than 15 non-negotiable rules), and links to topic documents (one-line description plus applicability condition).
```markdown
# AGENTS.md
@@ -83,37 +83,37 @@ Python 3.11 FastAPI backend, PostgreSQL 15 database.
- Testing Standards (`docs/testing-standards.md`) — Reference when writing tests
```
-Each topic document is 50-150 lines, organized by subject in the `docs/` directory or next to the corresponding module. The agent only reads them when needed. Like packing cubes in a suitcase — underwear in one cube, toiletries in another, chargers in a third. Finding things doesn't require emptying the whole bag.
+Each topic document is 50-150 lines, organized by subject in the `docs/` directory or next to the corresponding module. The agent only reads them when needed. Think of it like packing cubes for your luggage — underwear in one cube, toiletries in another, chargers in a third. Finding what you need doesn't require emptying the entire bag.
-Some information is better placed directly in the code — type definitions, interface comments, explanations in config files. The agent naturally sees these when reading code, no need to duplicate in instructions.
+Some information is better placed directly in the code — type definitions, interface comments, explanations in config files. The agent naturally sees these when reading code, so there's no need to duplicate them in instructions.
-Every instruction should have a source ("why was this rule added?"), an applicability condition ("when is this rule needed?"), and an expiry condition ("under what circumstances can this rule be removed?"). Audit regularly, remove outdated, redundant, and contradictory entries. Manage your instructions like you manage code dependencies — unused dependencies should be deleted, otherwise they just slow the system down.
+Every instruction should document its source ("why was this rule added?"), applicability condition ("when is this rule needed?"), and expiry condition ("under what circumstances can this rule be removed?"). Audit regularly and delete outdated, redundant, or contradictory entries. Manage your instructions the way you manage code dependencies — unused dependencies should be removed, otherwise they only slow the system down.
-If an instruction must be in the entry file, put it at the top or bottom — never the middle. The "lost in the middle" effect tells us that LLMs use information at the extremes significantly better than in the center. But the better approach is to move instructions to topic documents for on-demand loading.
+If an instruction absolutely must be in the entry file, put it at the top or bottom, never in the middle. The "lost in the middle" effect tells us that LLMs utilize information at the extremes of a long text significantly better than in the center. But the better approach is to move instructions into topic documents for on-demand loading.
-Both OpenAI and Anthropic implicitly support the splitting approach. OpenAI says entry files should be "short and routing-oriented," Anthropic says long-running agent control information should be "concise and high-priority." Both are saying the same thing: don't stuff everything into one file. A suitcase needs organizing, not just brute-force cramming.
+Both OpenAI and Anthropic implicitly endorse this split approach. OpenAI says entry files should be "short and routing-oriented," while Anthropic says control information for long-running agents should be "concise and high-priority." Both are saying the same thing: don't stuff everything into a single file.
## Real-World Example
-A SaaS team's `AGENTS.md` ballooned from 50 lines to 600. Contents mixed tech stack versions, coding standards, historical bug fix notes, API usage guides, deployment procedures, and team members' personal preferences — the entire suitcase bursting at the seams.
+A SaaS team's `AGENTS.md` ballooned from 50 lines to 600. The contents mixed together tech stack versions, coding standards, historical bug fix notes, API usage guides, deployment procedures, and team members' personal preferences — everything was in there, but finding the part relevant to the current task was a slog.
-Agent performance started declining noticeably: during simple bug fixes the agent spent lots of context processing irrelevant deployment instructions; the security constraint "all database queries must use parameterized queries" was buried at line 300 and frequently ignored; three contradictory code style rules caused random agent behavior.
+Agent performance started declining noticeably: during simple bug fixes the agent spent significant context processing irrelevant deployment instructions; the security constraint "all database queries must use parameterized queries" was buried at line 300 and frequently ignored; three contradictory code style rules caused the agent to pick one at random.
-The team executed a "suitcase reorganization":
+The team executed a split refactoring:
1. `AGENTS.md` trimmed to 80 lines: only project overview, run commands, and 15 global hard constraints
2. Created topic documents: `docs/api-patterns.md` (120 lines), `docs/database-rules.md` (60 lines), `docs/testing-standards.md` (80 lines)
3. Added topic document links in the routing file
-4. Historical notes either converted to test cases or deleted
+4. Historical notes either converted to test cases or deleted outright
-After refactoring: same task set success rate went from 45% to 72%. Security constraint compliance went from 60% to 95% — because it moved from the file middle to the routing file top, no longer "lost in the middle."
+After refactoring: success rate on the same task set improved from 45% to 72%. Security constraint compliance rose from 60% to 95%, because the rule moved from the middle of the file to the top of the routing file — no longer "lost in the middle."
## Key Takeaways
-- "Add a rule" is short-term pain relief, long-term poison. Before adding a rule, ask: would this be better in a topic document? Don't just keep cramming things into the suitcase.
-- The entry file is a router, not an encyclopedia. 50-200 lines with overview, hard constraints, and links only.
-- Leverage the "lost in the middle" effect: important info goes at the top or bottom; unimportant info moves to topic documents.
-- Manage instruction bloat like technical debt. Regular audits, every instruction needs a source, applicability condition, and expiry condition.
-- After splitting, SNR improves and the agent spends more context budget on actual tasks instead of processing irrelevant instructions.
+- "Add a rule" is short-term pain relief and long-term poison. Before adding any rule, consider whether it belongs in a topic document instead.
+- The entry file is a router, not an encyclopedia. 50-200 lines — overview, hard constraints, and links only.
+- Leverage the "lost in the middle" effect: put important information at the top or bottom, and move less critical items to topic documents.
+- Manage instruction bloat the way you manage technical debt. Regular audits, and every instruction should have a source, applicability condition, and expiry condition.
+- After splitting, SNR improves and the agent spends more of its context budget on the actual task instead of processing irrelevant instructions.
## Further Reading
@@ -125,8 +125,8 @@ After refactoring: same task set success rate went from 45% to 72%. Security con
## Exercises
-1. **SNR audit**: Take your current entry instruction file and list all instruction entries. Pick 5 different common task types and mark whether each instruction is relevant to that task. Calculate SNR for each task type. Instructions that are noise for most tasks should move to topic documents.
+1. **SNR Audit**: Take your current entry instruction file and list all instruction entries. Pick 5 different common task types and mark whether each instruction is relevant to that task. Calculate the SNR for each task type. Instructions that are noise for most tasks should be moved to topic documents.
-2. **Progressive disclosure refactor**: If you have an instruction file over 300 lines, split it into: (a) a routing file under 100 lines, (b) 3-5 topic documents. Run the same set of tasks (at least 5) before and after, compare success rates.
+2. **Progressive Disclosure Refactor**: If you have an instruction file over 300 lines, split it into: (a) a routing file under 100 lines, (b) 3-5 topic documents. Run the same set of tasks (at least 5) before and after refactoring, and compare success rates.
-3. **Lost in the middle verification**: In a long instruction file, place a critical constraint at the top, middle, and bottom respectively, running the same task set each time (at least 5 runs per position). See if there's a difference in compliance rate. You might be surprised by how strong the position effect is.
+3. **Lost in the Middle Verification**: In a long instruction file, place a critical constraint at the top, middle, and bottom respectively, running the same task set each time (at least 5 runs per position). See if there's a difference in compliance rate. You might be surprised by how strong the position effect is.
diff --git a/docs/en/lectures/lecture-05-why-long-running-tasks-lose-continuity/index.md b/docs/en/lectures/lecture-05-why-long-running-tasks-lose-continuity/index.md
index 6095d01..336369d 100644
--- a/docs/en/lectures/lecture-05-why-long-running-tasks-lose-continuity/index.md
+++ b/docs/en/lectures/lecture-05-why-long-running-tasks-lose-continuity/index.md
@@ -1,27 +1,25 @@
-[中文版本 →](../../../zh/lectures/lecture-05-why-long-running-tasks-lose-continuity/)
+[中文版 →](../../../zh/lectures/lecture-05-why-long-running-tasks-lose-continuity/)
> Code examples: [code/](https://github.com/walkinglabs/learn-harness-engineering/blob/main/docs/en/lectures/lecture-05-why-long-running-tasks-lose-continuity/code/)
> Practice project: [Project 03. Multi-session continuity](./../../projects/project-03-multi-session-continuity/index.md)
-# Lecture 05. Keep Context Alive Across Sessions
+# Lecture 05. Keeping Context Alive Across Sessions
-You ask Claude Code to implement a complete feature. It runs for 30 minutes, does most of the work, but context is running low. You start a new session to continue — and discover it doesn't remember what decisions were made last time, why option A was chosen over option B, which files were already modified, or what state the tests are in. It spends 15 minutes re-exploring the project, and might be inconsistent with the previous approach.
+You ask Claude Code to implement a complete feature. It runs for 30 minutes, does most of the work, but context is running low. You start a new session to continue — and discover it doesn't remember what decisions were made last time, why option A was chosen over option B, which files were already modified, or what state the tests are in. It spends 15 minutes re-exploring the project, and might take an inconsistent approach from last time.
-Imagine if you were a craftsman who forgot everything each morning upon waking. You'd have to reacquaint yourself with the entire construction site — which wall is half-built, why red bricks were chosen over blue ones, where the plumbing runs got to. Worse, you might tear out a window that was already installed yesterday, simply because you didn't remember it was done.
-
-This is exactly the predicament AI coding agents face in cross-session tasks. This lecture explains why agents "black out" during long tasks, and how structured state persistence can make them like a craftsman who keeps a reliable daily journal — still amnesiac, but the journal remembers everything.
+This is the real dilemma AI coding agents face in cross-session tasks. This lecture explains why agents "lose the thread" during long tasks, and how structured state persistence lets a new session quickly pick up where the last one left off.
## Context Windows: Not Infinite
-Context windows are finite. This isn't solvable by model upgrades — even if window sizes grow to 1M tokens, complex tasks will still exhaust them. Because agents aren't just generating code; they're understanding codebases, tracking their own decision history, processing tool output, and maintaining conversation context. All this information grows faster than window expansion.
+Context windows are finite. This isn't a problem that model upgrades can solve — even if window sizes grow to 1M tokens, complex tasks will still exhaust them. Agents aren't just generating code; they're understanding codebases, tracking their own decision history, processing tool output, and maintaining conversation context. All this information grows faster than window expansion.
-A deeper problem: information the agent produces isn't uniformly important. Intermediate reasoning steps contain the "why" of decisions — why option B was chosen over A, why this library instead of that one, why a particular optimization was skipped. The final output only contains the "what" — the code itself. Compaction strategies usually preserve the latter but lose the former. The next session sees the code but doesn't know why it's written that way, and might "optimize" away a deliberate design decision.
+A deeper problem: the information agents produce isn't uniformly important. Intermediate reasoning steps contain the "why" of decisions — why option A was chosen over B, why this library instead of that one, why a particular optimization was skipped. The final output only contains the "what" — the code itself. Compaction strategies usually preserve the latter but lose the former. The next session sees the code but doesn't know why it's written that way, and might "optimize" away a deliberate design decision.
-Anthropic discovered something fascinating in their long-running agent research: when agents sense context is running low, they exhibit "premature convergence" behavior — rushing to finish current work, skipping verification steps, or choosing a simple solution over the optimal one. It's like realizing time is running out on an exam and quickly guessing on the remaining multiple-choice questions. Anthropic calls this "context anxiety."
+Anthropic observed something interesting in their long-running agent research: when agents sense context is running low, they exhibit "premature convergence" behavior — rushing to finish current work, skipping verification steps, or choosing a simple solution over the optimal one. Anthropic calls this "context anxiety."
## Session Continuity Flow
-Without continuity artifacts, every new session is a disaster:
+Without continuity artifacts, every new session has to start from scratch:
```mermaid
flowchart LR
@@ -50,30 +48,30 @@ flowchart LR
## Core Concepts
-- **Context windows are finite**: No matter what window size is claimed (128K, 200K, 1M), long tasks will eventually exhaust them. After exhaustion, either compaction (losing information) or reset (new session) is required. Both lose something.
-- **Continuity artifacts**: Persisted state files that let a new session unambiguously resume where the last one left off. The basic form: progress log + verification record + next actions. That craftsman's journal.
-- **Rebuild cost**: The time a new session needs to reach an executable state. Good harnesses can compress rebuild cost from 15 minutes to 3 minutes.
-- **Drift**: The gap between the agent's understanding and the actual state of the code repository. Every session boundary introduces drift; without control, it compounds.
-- **Context anxiety**: A phenomenon observed by Anthropic — agents exhibit premature convergence behavior when approaching perceived context limits, ending tasks early to avoid information loss. It's an irrational resource anxiety.
-- **Compaction vs reset**: Compaction summarizes context within the same session (keeps "what," may lose "why"); reset opens a new session rebuilding from persisted state (clean but depends on artifact completeness).
+- **Context windows are finite**: No matter what window size is claimed (128K, 200K, 1M), long tasks will eventually exhaust them. After exhaustion, either compaction (losing information) or reset (starting a new session) is required — both lose something.
+- **Continuity artifacts**: Persisted state files that let a new session unambiguously resume where the last one left off. The most basic form includes progress logs, verification records, and next actions.
+- **Rebuild cost**: The time a new session needs to reach an executable state. A good harness can compress rebuild cost from 15 minutes to 3 minutes.
+- **Drift**: The gap between the agent's understanding and the actual state of the code repository. Every session boundary introduces drift; without control, it compounds session after session.
+- **Context anxiety**: A phenomenon observed by Anthropic — agents exhibit premature convergence behavior when approaching context limits, ending tasks early to avoid information loss. At its core, it's an irrational resource anxiety.
+- **Compaction vs. reset**: Compaction summarizes context within the same session (keeps "what," may lose "why"); reset opens a new session rebuilding from persisted state (clean but depends on artifact completeness).
## What Happens When Continuity Breaks
-The previous session spent significant context budget analyzing three approaches and choosing option B. This session's agent doesn't know about that analysis and might re-decide based on incomplete information — potentially choosing option A. Like the amnesiac craftsman who doesn't remember why red bricks were chosen, looks at the blue ones today and thinks they're prettier, and tears down yesterday's wall to rebuild.
+The previous session spent significant context budget analyzing three approaches and choosing option B. This session's agent doesn't know about that analysis and might re-decide based on incomplete information — potentially choosing option A. Same information, different conclusion, because the decision-making context is gone.
-Even worse is duplicate work. The agent isn't sure whether certain work was already completed and does it again. Or worse — does half of it, discovers a conflict with the existing implementation, and has to rework. On a construction site, two teams can't build the same wall simultaneously — but without progress records, the new crew has no idea someone is already working on it.
+Even worse is duplicate work. The agent isn't sure whether certain work was already completed and does it again. Or worse — does half of it, discovers a conflict with the existing implementation, and has to rework. Without progress records, the new session has no idea what's already been done.
-Over several sessions, the implementation direction may have silently drifted from the original requirements. Each new session has a slightly different understanding of the project goals. Like a game of telephone — after ten people pass the message, "pick me up a coffee" might become "buy me a coffee machine."
+Over several sessions, the implementation direction may have silently drifted from the original requirements. Each new session has a slightly different understanding of the project goals. Each deviation compounds on the last, and the final result may be far removed from the original intent.
There's also the verification gap. The previous session's verification results (which tests pass, which fail, why they fail) weren't recorded. The new session has to re-run all verification to understand the current state. Every session re-diagnoses from scratch, every time wasting precious context.
Both OpenAI and Anthropic emphasize structured state persistence in their documentation. OpenAI's harness engineering article treats the repository as an "operational record" — every operation's results should leave traceable evidence in the repo. Anthropic's long-running agents documentation specifically recommends "handoff files" — structured documents containing current state, known issues, and next actions.
-## A Journal for the Amnesiac Craftsman
+## Practical Approaches to State Persistence
-Core approach: **Treat the agent like a brilliant engineer with amnesia.** Before it "clocks out," it must write down critical information so the next "shift" agent can pick up quickly.
+Core approach: **Treat the agent like an engineer whose short-term memory gets wiped at every session.** Before it "clocks out," it must write down critical information so the next "shift" agent can pick up quickly.
-**Tool 1: Progress file (PROGRESS.md).** The most basic continuity artifact — the core of the journal:
+**Tool 1: Progress file (PROGRESS.md).** The most basic continuity artifact:
```markdown
# Project Progress
@@ -101,7 +99,7 @@ Core approach: **Treat the agent like a brilliant engineer with amnesia.** Befor
3. Update API documentation
```
-**Tool 2: Decision log (DECISIONS.md).** Record important design decisions and reasons. No need for detailed design documents — just "what decision, why, when" — the memos in the journal:
+**Tool 2: Decision log (DECISIONS.md).** Record important design decisions and reasons. No need for detailed design documents — just "what decision, why, when":
```markdown
# Design Decisions
@@ -129,17 +127,17 @@ Core approach: **Treat the agent like a brilliant engineer with amnesia.** Befor
3. Commit all completed work
```
-**Mixed strategy**: Not every task needs a context reset. Short tasks (under 30 minutes) can complete within one session. Long tasks (spanning sessions) must use progress files and decision logs for continuity. Decision criterion: if a task needs more than 60% of the window, start preparing handoff.
+**Mixed strategy**: Not every task needs a context reset. Short tasks (under 30 minutes) can complete within one session. Long tasks (spanning sessions) must use progress files and decision logs for continuity. Decision criterion: if a task needs more than 60% of the window, start preparing the handoff.
-### Deep Dive on Context Anxiety
+### A Deeper Look at Context Anxiety
-Anthropic's March 2026 research further revealed the specific manifestations of context anxiety: on Sonnet 4.5, when context approaches the window limit, the agent shows strong "premature convergence" behavior. It's like realizing time is almost up on an exam and quickly filling in random answers on the multiple choice.
+Anthropic's March 2026 research further revealed the specific manifestations of context anxiety: on Sonnet 4.5, when context approaches the window limit, the agent shows strong "premature convergence" behavior.
Two strategies address this:
**Compaction**: Summarizing early conversation within the same session. Advantage: maintains continuity, the agent can see "what." Disadvantage: "why" is often lost in summaries — why option B was chosen over A, why a particular optimization was skipped. More critically, compaction doesn't eliminate context anxiety — the agent knows context was once large, and psychologically still tends to rush to closure.
-**Context reset**: Completely clearing context, opening a new session, rebuilding from persisted artifacts. Advantage: clean mental state — the new session has no "I'm running out of time" anxiety. Disadvantage: depends on the completeness of handoff artifacts. If the journal is missing critical information, the new session may waste time going in the wrong direction.
+**Context reset**: Completely clearing context, opening a new session, rebuilding from persisted artifacts. Advantage: clean mental state — the new session has no "I'm running out of time" anxiety. Disadvantage: depends on the completeness of handoff artifacts. If the progress file is missing critical information, the new session may waste time going in the wrong direction.
Anthropic's actual data: for Sonnet 4.5, context anxiety is severe enough that compaction alone isn't sufficient — context reset becomes a critical component of harness design. But for Opus 4.5, this behavior is greatly diminished, and compaction can manage context without relying on resets. This means: **harness design needs specific understanding of the target model, not a one-size-fits-all template.**
@@ -149,18 +147,18 @@ Anthropic's actual data: for Sonnet 4.5, context anxiety is severe enough that c
An agent was tasked with implementing a blog system with user authentication — 12 feature points, estimated 5 sessions needed.
-**Baseline without the journal**: Session 1 implemented the user model and basic routes. Session 2 started without the agent remembering the auth middleware's interface contract, spending ~15 minutes inferring the previous design intent. By session 3, accumulated drift caused the agent to start reimplementing already-completed features. By session 5, the repo contained lots of redundant code but the core auth feature still hadn't passed end-to-end tests. Only 7 of 12 feature points completed, 3 with hidden correctness issues. Like the craftsman who never writes in his journal — by day five, the construction site is chaos, some walls built twice, some that should have been built never started.
+**Baseline without continuity artifacts**: Session 1 implemented the user model and basic routes. Session 2 started without the agent remembering the auth middleware's interface contract, spending ~15 minutes inferring the previous design intent. By session 3, accumulated drift caused the agent to start reimplementing already-completed features. By session 5, the repo contained lots of redundant code but the core auth feature still hadn't passed end-to-end tests. Only 7 of 12 feature points completed, 3 with hidden correctness issues.
-**With the journal**: Using progress files, decision logs, verification records, and git checkpoints. State report updated automatically at each session end. Session 2's rebuild cost dropped to ~3 minutes. By session 5, all 12 feature points completed and verified.
+**With continuity artifacts**: Using progress files, decision logs, verification records, and git checkpoints. State report updated automatically at each session end. Session 2's rebuild cost dropped to ~3 minutes. By session 5, all 12 feature points completed and verified.
-Quantitative comparison: rebuild time reduced ~78%, feature completion rate from 58% to 100%, hidden defect rate from 43% down to 8%. The craftsman is still amnesiac, but with the journal, each day starts from where yesterday stopped, not from zero.
+Quantitative comparison: rebuild time reduced ~78%, feature completion rate from 58% to 100%, hidden defect rate from 43% down to 8%.
## Key Takeaways
-- Context windows are a finite resource. Long tasks will span sessions, and sessions will lose information — like the craftsman who forgets each day, this is objective reality.
-- The solution isn't bigger windows — it's better state persistence. Progress files + decision logs + git checkpoints — give the amnesiac craftsman a reliable journal.
-- Treat the agent like an engineer with amnesia: before "clocking out," write down what was done, why, and what's next.
-- Rebuild cost is the key metric. Good harnesses should get new sessions to an executable state within 3 minutes.
+- Context windows are a finite resource. Long tasks will span sessions, and sessions will lose information — this is objective reality.
+- The solution isn't bigger windows — it's better state persistence. Progress files, decision logs, and git checkpoints work together to let new sessions pick up where previous ones left off.
+- Treat the agent like an engineer whose short-term memory gets wiped every session: before "clocking out," write down what was done, why, and what's next.
+- Rebuild cost is the key metric. A good harness should get new sessions to an executable state within 3 minutes.
- Mixed strategy: short tasks within sessions, long tasks with structured artifacts for continuity.
## Further Reading
diff --git a/docs/en/lectures/lecture-06-why-initialization-needs-its-own-phase/index.md b/docs/en/lectures/lecture-06-why-initialization-needs-its-own-phase/index.md
index afe5558..18ecbb2 100644
--- a/docs/en/lectures/lecture-06-why-initialization-needs-its-own-phase/index.md
+++ b/docs/en/lectures/lecture-06-why-initialization-needs-its-own-phase/index.md
@@ -1,33 +1,33 @@
-[中文版本 →](../../../zh/lectures/lecture-06-why-initialization-needs-its-own-phase/)
+[中文版 →](../../../zh/lectures/lecture-06-why-initialization-needs-its-own-phase/)
> Code examples: [code/](https://github.com/walkinglabs/learn-harness-engineering/blob/main/docs/en/lectures/lecture-06-why-initialization-needs-its-own-phase/code/)
> Practice project: [Project 03. Multi-session continuity](./../../projects/project-03-multi-session-continuity/index.md)
-# Lecture 06. Initialize Before Every Agent Session
+# Lecture 06. Make the Agent Initialize Before Every Work Session
-You start a new agent session and say "add a search feature." It jumps straight into coding — admirable enthusiasm. After 20 minutes it discovers the test framework isn't configured properly, spends another 10 fixing that, then the database migration script format is wrong, more fiddling. The search feature eventually gets added, but the whole session was inefficient — most time went to "figuring out how this project works" rather than writing the search feature.
+You start a new agent session and tell it "add a search feature." It jumps straight into coding — admirable enthusiasm. After 20 minutes it discovers the test framework isn't configured properly, spends another 10 minutes fixing that, then finds the database migration script format is wrong, more fiddling. The search feature does get added in the end, but the whole session was inefficient. Most of the time went to "figuring out how this project works" rather than writing the search feature itself.
-The better approach: before letting the agent start working, use a separate phase to get the base environment ready, verification commands passing, and project structure understood. It's like building a house — you don't pour the foundation and put up walls simultaneously. If you do, the walls go up before the foundation has cured, and the whole building has to be torn down and started over. Pour the foundation first, let it cure, then build the walls — clean and efficient.
+The better approach: before letting the agent start working, use a separate phase to get the base environment ready, run verification commands through, and understand the project structure. Initialization work should not be crammed together with feature implementation — they are two fundamentally different kinds of tasks.
-This lecture explains why initialization must be a separate phase, not mixed in with implementation.
+This lecture discusses why initialization must be a separate phase, not mixed in with implementation.
-## Foundation and Walls: Two Fundamentally Different Jobs
+## Two Fundamentally Different Kinds of Work
-Initialization and implementation have completely different optimization targets. The implementation phase optimizes for: maximizing the quantity and quality of verified features. The initialization phase optimizes for: maximizing the reliability and efficiency of all subsequent implementation.
+Initialization and implementation have completely different optimization targets. The implementation phase aims to maximize the quantity and quality of verified features. The initialization phase aims to maximize the reliability and efficiency of all subsequent implementation.
-When you mix initialization and implementation, the agent faces a multi-objective optimization problem — simultaneously building infrastructure and writing feature code. Without explicit priority setting, the agent naturally gravitates toward writing code (because that's directly visible output) while sacrificing infrastructure (because its value only shows in subsequent sessions). It's like telling a construction crew to simultaneously pour the foundation and build the walls — they'll probably rush to build walls because walls are visible and demonstrable. But a house with a bad foundation has systemic problems down the line.
+When you mix initialization and implementation, the agent faces a multi-objective optimization problem: it has to simultaneously build infrastructure and write feature code. Without explicit priority setting, the agent naturally gravitates toward writing code (because that's directly visible output) while sacrificing infrastructure (because its value only shows up in subsequent sessions). The result: infrastructure doesn't get built solidly, and the reliability of the feature code suffers as well.
## Initialization Lifecycle
```mermaid
flowchart TB
- subgraph Wrong["Mixed session (wrong)"]
+ subgraph Wrong["Mixed into one session (wrong)"]
W1["Start feature work immediately"] --> W2["Discover env and test gaps mid-task"]
W2 --> W3["Accumulate unverified code"]
W3 --> W4["Next session must rediscover project state"]
end
- subgraph Right["Dedicated initialization (right)"]
+ subgraph Right["Dedicated initialization phase (right)"]
R1["Session 1: environment runnable"] --> R2["Example test passing"]
R2 --> R3["Bootstrap contract + task list written"]
R3 --> R4["Clean checkpoint committed"]
@@ -37,34 +37,34 @@ flowchart TB
## What Happens When You Mix Them
-The most direct problem: the foundation doesn't set properly. The agent spends 80% of its effort on feature code and 20% casually setting up some infrastructure. The test framework is configured but never verified, lint rules are set but too loose, no progress file created. These defects aren't obvious in the first session (because the agent still remembers what it did), but they surface in the second session — the new agent doesn't know how to run, test, or where things stand. Shoddy foundation, shaky building.
+The most direct problem: infrastructure doesn't get built solidly. The agent spends 80% of its effort on feature code and the remaining 20% casually setting up some infrastructure. The test framework is configured but never verified, lint rules are set but too loose, no progress file created. These defects aren't obvious in the first session (because the agent still remembers what it did), but they surface in the second session: the new agent doesn't know how to run the project, how to test, or where things stand.
-A more hidden cost is "unverified accumulation" — feature code written before the test framework is configured is code without verification. When you finally go back to add tests for that code, you might discover the design was wrong from the start — had you known, you would have implemented it differently. Like tiling over wet concrete — when you discover the floor isn't level, all the tiles have to be pried up and redone.
+A more hidden cost is "unverified accumulation." Feature code written before the test framework is properly configured — when you finally go back to add tests, you might discover the design itself was flawed. Had you known earlier, you would have implemented it differently. The more code written up front, the more has to be torn down and redone later.
-Session budget is being wasted too. Initialization work (configuring environments, setting up tests, understanding project structure) consumes significant budget, leaving less for actual feature implementation. Result: the first session only completes half the features, and the second session has to start over understanding the project. Budget spent on the foundation, but the foundation isn't solid either — neither goal achieved.
+Context budget is being wasted too. Initialization work (configuring environments, setting up tests, understanding project structure) consumes a large chunk of the budget, leaving less for actual feature implementation. The result: the first session only completes half the features, and the second session still has to start from scratch understanding the project. Budget was spent on initialization, but initialization wasn't done well either — the worst of both worlds.
-The most easily overlooked problem is implicit assumption landmines. Decisions the agent makes during initialization (which test framework, how to organize directories, dependency management) — if not explicitly recorded, subsequent sessions can't understand these choices. Worse, subsequent sessions might make contradictory choices. The first construction crew used a concrete foundation, the second crew doesn't know and drove wooden pilings into it — the foundation cracks.
+The most easily overlooked problem is implicit assumption landmines. Decisions the agent makes during initialization (which test framework, how to organize directories, dependency management) — if not explicitly recorded, subsequent sessions may make contradictory choices. The first session chose Vitest as the test framework, but the second session's agent doesn't know and introduces Jest. Two test frameworks coexist, and maintenance costs double.
-Anthropic's long-running application development research explicitly recommends separating initialization from implementation. Their experimental data: projects using a dedicated initialization phase showed 31% higher feature completion rates in multi-session scenarios compared to mixed approaches. The key insight — time invested in the initialization phase is fully recovered in the next 3-4 sessions. The more solid the foundation, the faster the walls go up.
+Anthropic's long-running application development research explicitly recommends separating initialization from implementation. Their experimental data: projects using a dedicated initialization phase showed 31% higher feature completion rates in multi-session scenarios compared to mixed approaches. And the time invested in the initialization phase is fully recovered within the next 3-4 sessions.
-OpenAI's Codex harness engineering guide also emphasizes the "repository as operational record" principle — establish clear operational structure from the first run, or every new session has to re-infer project conventions.
+OpenAI's Codex harness engineering guide also emphasizes the "repository as operational record" principle: establish clear operational structure from the very first run, or every new session has to re-infer project conventions.
## Core Concepts
-- **Initialization Phase**: The first phase in the agent's lifecycle — no feature implementation, only establishing prerequisites for all subsequent implementation phases. The output isn't code, it's infrastructure.
-- **Bootstrap Contract**: The conditions under which a project can be unambiguously operated by a fresh agent session — can start, can test, can see progress, can pick up next steps. Four conditions, all required.
-- **Cold Start vs Warm Start**: Cold start is from an empty directory where the agent must guess project structure; warm start is from a template or existing project where infrastructure is already in place. Warm start far outperforms cold start — like starting work on a site with running water and electricity versus beginning from a barren wasteland.
-- **Handoff Readiness**: The project is in a state at any given moment where a fresh agent can take over. No verbal explanation needed — just repo contents.
+- **Initialization Phase**: The first phase in the agent's lifecycle — it only establishes the prerequisites for subsequent implementation, with no feature development. Its output is infrastructure, not business code.
+- **Bootstrap Contract**: The conditions under which a project can be unambiguously operated by a fresh agent session: can start, can test, can see progress, can pick up next steps. Four conditions, all required.
+- **Cold Start vs Warm Start**: Cold start is from an empty directory where the agent must infer project structure on its own; warm start is from a template or existing project where infrastructure is already in place. Warm start far outperforms cold start.
+- **Handoff Readiness**: The project is in a state at any given moment where a fresh agent can take over. No verbal explanation needed — just looking at the repo contents is enough to continue working.
- **Time to First Verification**: The time from project start until the first feature point passes verification. This is the core metric for measuring initialization efficiency.
-- **Downstream Usability**: The best measure of initialization quality — the proportion of subsequent sessions that can successfully execute tasks without relying on implicit knowledge.
+- **Downstream Usability**: The proportion of subsequent sessions that can successfully execute tasks without relying on implicit knowledge. This is the best measure of initialization quality.
## How to Do Initialization Right
**Treat initialization as a dedicated phase.** The first session does only initialization — no business feature code at all. Initialization produces:
-**1. Runnable environment.** The project starts, dependencies are installed, no environment issues. Foundation poured, no cracks.
+**1. Runnable environment.** The project starts, dependencies are installed, no environment issues.
-**2. Verifiable test framework.** At least one example test passes. This proves the test framework itself is properly configured — like standing a pillar on the foundation to prove it can bear weight.
+**2. Verifiable test framework.** At least one example test passes, proving the test framework itself is properly configured.
**3. Bootstrap contract document.** A clear document telling subsequent sessions:
```markdown
@@ -109,9 +109,9 @@ OpenAI's Codex harness engineering guide also emphasizes the "repository as oper
**5. Git commit as checkpoint.** After initialization completes, commit a clean checkpoint. All subsequent work starts from this checkpoint.
-**Warm start strategy**: Don't start from an empty directory. Use a project template (create-react-app, fastapi-template, etc.) to preset standard directory structure, dependency configuration, and test framework. Bake common initialization steps into the template, leaving only project-specific initialization work. Like starting work on a site with running water and electricity — ten thousand times better than beginning from a barren wasteland.
+**Warm start strategy**: Don't start from an empty directory. Use a project template (create-react-app, fastapi-template, etc.) to preset standard directory structure, dependency configuration, and test framework. Bake common initialization steps into the template, leaving only project-specific initialization work.
-**Initialization completion criteria**: Not "how much code was written," but whether the bootstrap contract's four conditions are met — can start, can test, can see progress, can pick up next steps. Use this checklist to validate initialization:
+**Initialization completion criteria**: Not "how much code was written," but whether the bootstrap contract's four conditions are all met: can start, can test, can see progress, can pick up next steps. Use this checklist to validate initialization:
```markdown
## Initialization Acceptance Checklist
@@ -124,21 +124,21 @@ OpenAI's Codex harness engineering guide also emphasizes the "repository as oper
## Real-World Example
-Two initialization approaches for a React frontend project:
+Two initialization approaches for a React frontend project, compared:
-**Mixed approach (pouring foundation and building walls simultaneously)**: The agent simultaneously created project scaffolding and implemented the first feature in session 1. At session end, the repo had runnable code but: no explicit start/test command documentation, no progress tracking file, no task breakdown. Session 2 spent ~20 minutes inferring project structure, test framework, and build process — like a new construction crew arriving at a site, not knowing how far the foundation got or where the plumbing runs are, having to dig holes one by one to find out.
+**Mixed approach**: The agent simultaneously created project scaffolding and implemented the first feature in session 1. At session end, the repo had runnable code but no explicit start/test command documentation, no progress tracking file, no task breakdown. Session 2 spent about 20 minutes inferring project structure, test framework, and build process.
-**Dedicated initialization (foundation first)**: Session 1 did only initialization — created directory structure from a template, configured the test framework (Vitest + React Testing Library), wrote and verified one example test, created the bootstrap contract document and task breakdown file, committed the initial checkpoint. Session 2's rebuild time was under 3 minutes, and it started working directly from the task list — the crew arrives, glances at the blueprint, and knows exactly where to pick up.
+**Dedicated initialization**: Session 1 did only initialization — created directory structure from a template, configured the test framework (Vitest + React Testing Library), wrote and verified one example test, created the bootstrap contract document and task breakdown file, committed the initial checkpoint. Session 2's rebuild time was under 3 minutes, and it started working directly from the task list.
-Full project cycle comparison: the mixed approach's total rebuild time (across all sessions) was ~60% more than the dedicated initialization approach. The extra 20 minutes spent on initialization was recovered many times over in subsequent sessions. Like a solid foundation making the walls go up faster — slow is fast.
+Full project cycle comparison: the mixed approach's total rebuild time (across all sessions) was about 60% more than the dedicated initialization approach. The extra 20 minutes spent on initialization was recovered many times over in subsequent sessions. Invest a bit more time up front to do initialization properly, and subsequent efficiency is actually higher.
## Key Takeaways
-- Initialization and implementation have different optimization targets — mixing them just drags both down. Pour the foundation first, then build the walls.
-- Initialization's output isn't code, it's infrastructure: runnable environment, verifiable tests, bootstrap contract, task breakdown.
+- Initialization and implementation have different optimization targets — mixing them only drags both down.
+- Initialization's output isn't business code, it's infrastructure: runnable environment, verifiable tests, bootstrap contract, task breakdown.
- Validate initialization with the bootstrap contract's four conditions: can start, can test, can see progress, can pick up next steps.
- Warm start beats cold start. Use project templates to preset standardized infrastructure.
-- Time invested in initialization is fully recovered in the next 3-4 sessions. This isn't extra cost — it's upfront investment. The more solid the foundation, the faster the building goes up.
+- Time invested in initialization is fully recovered in the next 3-4 sessions. This isn't extra cost — it's upfront investment.
## Further Reading
@@ -150,8 +150,8 @@ Full project cycle comparison: the mixed approach's total rebuild time (across a
## Exercises
-1. **Bootstrap contract design**: Write a complete bootstrap contract for a project you're developing. Then open a completely fresh agent session, show it only repo contents (no verbal context), and have it try to start the project, run tests, and understand current progress. Record every problem it encounters — each one corresponds to a missing clause in your bootstrap contract.
+1. **Bootstrap contract design**: Write a complete bootstrap contract for a project you're developing. Then open a completely fresh agent session, show it only repo contents (no verbal context at all), and have it try to start the project, run tests, and understand current progress. Record every problem it encounters — each one corresponds to a missing clause in your bootstrap contract.
-2. **Comparison experiment**: Pick a moderately complex new project. Approach A: let the agent initialize and do first implementation simultaneously. Approach B: spend one session on dedicated initialization, start implementation in session 2. After 4 sessions, compare: time to first verification, rebuild cost, feature completion rate.
+2. **Comparison experiment**: Pick a moderately complex new project. Approach A: let the agent initialize and do first implementation simultaneously. Approach B: spend one session on dedicated initialization, start implementation in session 2. After 4 sessions, compare time to first verification, rebuild cost, and feature completion rate.
3. **Initialization acceptance checklist**: Design an initialization acceptance checklist for your project. Have a fresh agent session execute each checklist item and record which pass and which fail. The failing items are where your harness needs strengthening.
diff --git a/docs/en/lectures/lecture-07-why-agents-overreach-and-under-finish/index.md b/docs/en/lectures/lecture-07-why-agents-overreach-and-under-finish/index.md
index 5fd9c47..7912d6b 100644
--- a/docs/en/lectures/lecture-07-why-agents-overreach-and-under-finish/index.md
+++ b/docs/en/lectures/lecture-07-why-agents-overreach-and-under-finish/index.md
@@ -1,19 +1,19 @@
-[中文版本 →](../../../zh/lectures/lecture-07-why-agents-overreach-and-under-finish/)
+[中文版 →](../../../zh/lectures/lecture-07-why-agents-overreach-and-under-finish/)
> Code examples: [code/](https://github.com/walkinglabs/learn-harness-engineering/blob/main/docs/en/lectures/lecture-07-why-agents-overreach-and-under-finish/code/)
-> Practice project: [Project 04. Runtime feedback and scope control](./../../projects/project-04-incremental-indexing/index.md)
+> Practice project: [Project 04. Use runtime feedback to correct agent behavior](./../../projects/project-04-incremental-indexing/index.md)
# Lecture 07. Draw Clear Task Boundaries for Agents
You tell Claude Code to "add user authentication to this project," and it starts modifying the database schema, writing routes, changing frontend components, and — while it's at it — refactoring the error-handling middleware. Two hours later you check: 12 files modified, 800 lines of new code, and not a single feature works end-to-end.
-Biting off more than you can chew — this saying applies to AI agents especially well. Agents are born with an impulse to "do a little extra" — they see related things and just handle them along the way, like someone who goes to the supermarket for a bottle of soy sauce and comes out pushing a full cart. The problem is, humans who buy too much just waste money; agents doing too many things simultaneously means none of them get done properly.
+Agents are born with an impulse to "do a little extra" — they see related things and just handle them along the way. The problem is, doing too many things at once almost guarantees none of them get done well.
Anthropic's "Effective harnesses for long-running agents" engineering blog states clearly: when prompts are too broad, agents tend to "start multiple things at once" rather than "finish one thing first." OpenAI's Codex engineering practices found the same — tasks without explicit scope controls see completion rates plummet. This is not a model problem — it's a harness problem. You didn't draw the boundary.
## Attention Is a Finite Resource
-This isn't a metaphor — it's math. Assume the agent's context capacity is C and it activates k tasks simultaneously. Each task gets an average of C/k reasoning resources. When C/k drops below the minimum threshold needed to complete a single task, none of them get finished. Your stomach is only so big — stuff ten dumplings in at once and you won't digest them all, you'll just get ten cases of indigestion.
+This isn't a metaphor — it's math. Assume the agent's context capacity is C and it activates k tasks simultaneously. Each task gets an average of C/k reasoning resources. When C/k drops below the minimum threshold needed to complete a single task, none of them get finished.
Claude Code's real behavior is telling. Ask it to "add user registration" and it might:
@@ -24,7 +24,7 @@ Claude Code's real behavior is telling. Ask it to "add user registration" and it
5. Notice the error handling is inconsistent, so refactor the global error middleware
6. See the test file structure is messy, so reorganize the directory
-Six steps later, every one is half-done. No end-to-end verification, complex coupling between the half-baked code, and the next session to pick up the pieces will be completely lost. Like someone cooking six dishes simultaneously — every dish is in the pan but none has been plated. They all burn.
+Six steps later, every one is half-done. No end-to-end verification, complex coupling between the half-baked code, and the next session to pick up the pieces will be completely lost.
Anthropic's experimental data directly supports this: agents using a "small next step" strategy (equivalent to WIP=1) show a 37% higher task completion rate than agents using broad prompts. More interestingly, the number of lines of code generated by agents is weakly negatively correlated with actual feature completion — more code written, fewer features completed. Biting off more than you can chew, proven by data.
@@ -52,20 +52,20 @@ flowchart TB
## Core Concepts
-- **Overreach**: The agent activates more tasks in a single session than optimal. It's quantifiable — doing 5 features with 0 passing end-to-end is overreach.
+- **Overreach**: The agent activates more tasks in a single session than optimal. This isn't subjective — it's quantifiable: doing 5 features with 0 passing end-to-end is overreach.
- **Under-finish**: The ratio of tasks that pass end-to-end verification, out of all activated tasks, falls below threshold. Code written but tests not passing is under-finish.
-- **WIP Limit (Work-in-Progress Limit)**: From Kanban methodology. Core idea: limit how many tasks are in-flight at once. For agents, WIP=1 is the safest default — finish one before starting the next. Like a buffet — don't pile your plate, finish one plate then go back for the next.
+- **WIP Limit (Work-in-Progress Limit)**: From Kanban methodology. Core idea: limit how many tasks are in-flight at once. For agents, WIP=1 is the safest default — finish one before starting the next.
- **Completion Evidence**: The verifiable condition a task must satisfy to move from "in progress" to "done." Without this, agents substitute "the code looks fine" for "the behavior passes tests."
- **Scope Surface**: A DAG structure where each node is a work unit and edges are dependencies. States are limited to four: not_started, active, blocked, passing.
- **Completion Pressure**: The constraining force the harness exerts through WIP limits and completion evidence requirements, forcing the agent to finish the current task before starting a new one.
-## Overreach and Under-finish Are Symbiotic
+## Overreach and Under-finish Are Two Sides of the Same Coin
These two problems aren't independent — they amplify each other. Overreach dilutes attention, diluted attention causes under-finish, and the half-finished code left behind increases system complexity, which further drives overreach in the next task. A vicious cycle.
In Kanban terms: Little's Law tells us L = lambda * W. If work-in-progress L is too high (doing too many things at once), the lead time W for each task inevitably increases. For agents, this means each feature takes longer from start to verified completion, and the probability of failure grows.
-This is an old problem in the human world too — Steve McConnell documented in *Rapid Development* that scope creep is the leading cause of project failure. But humans at least have the intuition of "I've done enough." Agents have none. Generating the next idea costs the model almost nothing in extra tokens — writing "let me fix this too while I'm here" barely registers — but every additional modification dilutes the agent's attention. Like a buffet where each extra plate has near-zero marginal cost, but your stomach only has so much capacity.
+This is an old problem in the human world too. Steve McConnell documented in *Rapid Development* that scope creep is the leading cause of project failure. But humans at least have the intuition of "I've done enough." Agents have none. Generating the next idea costs the model almost nothing — writing "let me fix this too while I'm here" barely costs extra tokens, but every additional modification dilutes the agent's attention.
## How to Do It Right
@@ -80,8 +80,6 @@ This is the most direct and effective method. In your harness, tell the agent ex
- Don't "also refactor" feature B while implementing feature A
```
-Like eating at a buffet — one plate at a time, finish it before going back for more.
-
### 2. Define Explicit Completion Evidence for Every Task
Done is not "code is written" — it's "behavior verification passes." In your feature list, every entry needs a verification command:
@@ -104,15 +102,15 @@ The harness should continuously track VCR (Verified Completion Rate) = verified
A REST API project with 8 features, two strategies compared:
-**Buffet mode (unconstrained)**: Agent activates 5 features simultaneously in session 1. Produces ~800 lines across 12 files. End-to-end test pass rate: 20% — only user registration works. The other 4 features: database schema created but missing validation logic, routes defined but returning wrong response formats. Like someone cooking six dishes at once, only one is barely edible. By end of session 3, only 3 of 8 features complete.
+**Unconstrained mode**: Agent activates 5 features simultaneously in session 1. Produces ~800 lines across 12 files. End-to-end test pass rate: 20% — only user registration works. The other 4 features: database schema created but missing validation logic, routes defined but returning wrong response formats. By end of session 3, only 3 of 8 features complete.
-**Single-plate mode (WIP=1)**: Agent works on user registration only in session 1. Produces ~200 lines across 4 files. End-to-end tests: 100% passing. Commits a clean, verified implementation. By end of session 4, 7 of 8 features complete (the 8th blocked by an external dependency).
+**WIP=1 mode**: Agent works on user registration only in session 1. Produces ~200 lines across 4 files. End-to-end tests: 100% passing. Commits a clean, verified implementation. By end of session 4, 7 of 8 features complete (the 8th blocked by an external dependency).
-Result: less total code (800 vs 1200 lines) but more effective code. Completion rate: 87.5% vs 37.5%. Take one bite at a time, and you actually eat more.
+Result: less total code (800 vs 1200 lines) but more effective code. Completion rate: 87.5% vs 37.5%.
## Key Takeaways
-- **WIP=1 is the default safe setting for agent harnesses** — finish one, then start the next; don't try to parallelize. You can't become fat in one bite.
+- **WIP=1 is the default safe setting for agent harnesses** — finish one, then start the next; don't try to parallelize.
- **Completion evidence must be executable** — "the code looks fine" doesn't count; "curl returns 201" does.
- **The scope surface must be externalized as a file** — not just mentioned in conversation, but recorded in a machine-readable format in the repo.
- **Overreach and under-finish are symbiotic** — solving one solves the other.
@@ -129,6 +127,6 @@ Result: less total code (800 vs 1200 lines) but more effective code. Completion
1. **Task Atomization**: Pick a broad requirement (e.g., "implement a user management system") and break it into at least 5 atomic work units. For each unit, specify: (a) a single behavior description, (b) an executable verification command, (c) dependencies. Check whether the decomposition satisfies the WIP=1 constraint.
-2. **Comparison Experiment**: Run the same project twice — once without constraints, once with enforced WIP=1. Compare: verified completion rate, total lines of code, effective code ratio.
+2. **Comparison Experiment**: Run the same project twice — once without constraints, once with enforced WIP=1. Compare verified completion rate, total lines of code, and effective code ratio.
3. **Completion Evidence Audit**: Review a recent agent run's output, classifying each code change as "completed behavior," "incomplete behavior," or "scaffolding." Add missing verification commands for each incomplete behavior.
diff --git a/docs/en/lectures/lecture-08-why-feature-lists-are-harness-primitives/index.md b/docs/en/lectures/lecture-08-why-feature-lists-are-harness-primitives/index.md
index e58b5f7..a1f03b0 100644
--- a/docs/en/lectures/lecture-08-why-feature-lists-are-harness-primitives/index.md
+++ b/docs/en/lectures/lecture-08-why-feature-lists-are-harness-primitives/index.md
@@ -1,38 +1,41 @@
-[中文版本 →](../../../zh/lectures/lecture-08-why-feature-lists-are-harness-primitives/)
+[中文版 →](../../../zh/lectures/lecture-08-why-feature-lists-are-harness-primitives/)
> Code examples: [code/](https://github.com/walkinglabs/learn-harness-engineering/blob/main/docs/en/lectures/lecture-08-why-feature-lists-are-harness-primitives/code/)
> Practice project: [Project 04. Runtime feedback and scope control](./../../projects/project-04-incremental-indexing/index.md)
# Lecture 08. Use Feature Lists to Constrain What the Agent Does
-You ask an agent to build an e-commerce site. After it finishes, it tells you "done." You look at the code — user authentication works, but the checkout button in the shopping cart does nothing, and the payment flow isn't connected at all. The problem: you never told it what "done" means, so it used its own standard — "I wrote a lot of code and it looks fairly complete."
+You ask an agent to build an e-commerce site. After it finishes, it tells you "done." You look at the code — user authentication works, but the checkout button in the shopping cart does nothing, and the payment flow isn't connected at all. Where did things go wrong? You never told it what "done" means, so it used its own standard: "I wrote a lot of code and it looks fairly complete."
- Feature lists, in many people's eyes, are just a memo — write things down so you don't forget, then toss it aside. But in the harness world, a feature list isn't a memo for humans — it's the backbone of the entire harness. The scheduler relies on it to pick tasks, the verifier relies on it to judge completion, the handoff reporter relies on it to generate summaries. Break the backbone and the whole body is paralyzed.
+Feature lists, in many people's eyes, are just a memo — write things down so you don't forget, then toss them aside. But in the harness world, a feature list isn't a memo for humans. It's the foundational structure the entire harness is built on. The scheduler relies on it to pick tasks, the verifier relies on it to judge completion, and the handoff reporter relies on it to generate summaries. Without it, these components have no shared consensus to depend on.
Both Anthropic and OpenAI emphasize: **artifacts must be externalized.** Feature state must live in a machine-readable file in the repo, not in unstructured conversation text.
## Agents Don't Know What "Done" Means
-Neither Claude Code nor Codex automatically knows what you mean by "done." You say "add a shopping cart feature," and the model's interpretation might be "write a Cart component and an addToCart method." But you meant "the user can browse products, add to cart, and complete checkout end-to-end." This understanding gap persists without a feature list. The agent uses its own implicit standard — usually "the code has no obvious syntax errors." What you need is end-to-end behavioral verification. Like asking a friend to buy you fruit — you say "get some fruit" and they come back with lemons. Their fruit and your fruit are not the same fruit.
+Neither Claude Code nor Codex automatically knows what you mean by "done." You say "add a shopping cart feature," and the model's interpretation might be "write a Cart component and an addToCart method." But you meant "the user can browse products, add to cart, and complete checkout end-to-end."
+
+This understanding gap persists without a feature list. The agent uses its own implicit standard — usually "the code has no obvious syntax errors." What you need is end-to-end behavioral verification. Without a list, the two sides will never agree on what "done" means.
Look at this common progress note:
```
Did user auth, shopping cart mostly done, still need payments
```
-Can a new agent session answer these questions from this note? What does "mostly done" mean? Which tests did the cart pass? What's blocking payments? The answer to all is "nobody knows." Like telling your doctor "my stomach hurts, been okay lately" — what medicine can they prescribe?
-The result: the new session spends 20 minutes inferring project state, and may re-implement completed features. Anthropic's engineering data shows that good progress records reduce session startup diagnostic time by 60-80%.
+Can a new agent session answer these questions from this note? What does "mostly done" mean? Which tests did the cart pass? What's blocking payments? The answer to all is "nobody knows."
+
+The result: the new session spends 20 minutes inferring project state, and may end up re-implementing completed features. Anthropic's engineering data shows that good progress records reduce session startup diagnostic time by 60-80%.
## Feature State Machine
```mermaid
flowchart LR
- Feature["One feature row"] --> Behavior["Behavior<br/>for example: POST /cart/items returns 201"]
+ Feature["One feature row"] --> Behavior["Behavior<br/>e.g.: POST /cart/items returns 201"]
Feature --> Check["Verification command<br/>the exact check to run"]
Feature --> State["State<br/>not_started / active / blocked / passing"]
- Behavior --> Complete["Only with all three fields<br/>is the feature row usable"]
+ Behavior --> Complete["All three fields present<br/>the feature row is usable"]
Check --> Complete
State --> Complete
```
@@ -42,7 +45,7 @@ flowchart LR
List["feature_list.json / features.md"] --> Scheduler["Pick the next not_started item"]
Scheduler --> Agent["Agent works on that one item"]
Agent --> Verifier["Run that item's verification command"]
- Verifier -->|pass| Passing["Mark it passing<br/>and write the evidence"]
+ Verifier -->|pass| Passing["Mark it passing<br/>and attach evidence"]
Verifier -->|fail| Active["Keep it active"]
Verifier -->|dependency issue| Blocked["Mark it blocked"]
Passing --> Handoff["Update handoff note<br/>and current progress"]
@@ -51,10 +54,10 @@ flowchart LR
## Core Concepts
-- **Feature lists are harness primitives**: Not "optional planning tools," but foundational data structures that all other harness components depend on. Like database table structures — you can't say "let's skip primary keys."
-- **Triple structure**: Each feature item is a `(behavior description, verification command, current state)` triple. Missing any element makes the item incomplete.
+- **Feature lists are harness primitives**: Not "optional planning tools," but foundational data structures that all other harness components depend on. The scheduler, verifier, and handoff reporter all need to read the feature list to function.
+- **Triple structure**: Each feature item contains three elements: `(behavior description, verification command, current state)`. The behavior tells the agent what to do, the verification tells it what counts as done, and the state tells it where things stand. Missing any element makes the item incomplete.
- **State machine model**: Each feature item has four states — `not_started`, `active`, `blocked`, `passing`. State transitions are controlled by the harness, not freely changed by the agent.
-- **Pass-state gating**: The only way a feature moves from `active` to `passing` is by verification command executing successfully. This is irreversible — once `passing`, it can't go back. Like passing an exam means you passed, you can't retroactively change the score.
+- **Pass-state gating**: The only way a feature moves from `active` to `passing` is by the verification command executing successfully. This transition is irreversible — once `passing`, it can't go back.
- **Single source of truth**: All information about "what needs to be done" must derive from one feature list. No contradictions between the feature list and conversation history.
- **Back-pressure**: The number of features that haven't passed yet is the pressure the harness exerts on the agent. Zero pressure = project complete.
@@ -62,14 +65,16 @@ flowchart LR
Documents are for humans to read; primitives are for systems to execute. Documents can be ignored; primitives can't be bypassed.
-Think of it like database trigger constraints vs. application-layer checks: the former is enforced by the database engine, no SQL can skip it; the latter depends on application code correctness and can be accidentally bypassed. Feature lists as harness primitives are Specifically, the feature list serves four harness components:
+Think of it like database trigger constraints versus application-layer checks: the former is enforced by the database engine — no SQL can skip it. The latter depends on application code correctness and can be accidentally bypassed. Feature lists as harness primitives play the same role as database-level constraints — the agent cannot bypass them.
+
+Specifically, the feature list serves four harness components:
-1. **Scheduler**: Reads states, picks the next `not_started` feature. Like a factory production planning system.
-2. **Verifier**: Executes verification commands, decides whether to allow state transitions. Like quality inspection.
-3. **Handoff reporter**: Automatically generates session handoff summaries from the feature list. Like an automatic shift-change report.
-4. **Progress tracker**: Tallies state distribution, provides project health metrics. Like a dashboard.
+1. **Scheduler**: Reads states, picks the next `not_started` feature.
+2. **Verifier**: Executes verification commands, decides whether to allow state transitions.
+3. **Handoff reporter**: Automatically generates session handoff summaries from the feature list.
+4. **Progress tracker**: Tallies state distribution, provides project health metrics.
-## How to Do It Right
+## How to Do It
### 1. Define a Minimal Feature List Format
@@ -87,7 +92,7 @@ You don't need a complex system — a structured Markdown or JSON file works. Th
### 2. Let the Harness Control State Transitions
-The agent can't directly change a feature's state to `passing`. It can only submit a verification request; the harness executes the verification command and decides whether to allow the transition. This is "pass-state gating."
+The agent can't directly change a feature's state to `passing`. It can only submit a verification request. The harness executes the verification command and decides whether to allow the transition. This is "pass-state gating."
### 3. Write the Rules in CLAUDE.md
@@ -101,37 +106,37 @@ The agent can't directly change a feature's state to `passing`. It can only subm
### 4. Calibrate Granularity
-Each feature item should be scoped to "completable in one session." Too broad and it won't finish; too narrow and the management overhead grows. "User can add items to cart" is good granularity. "Implement the shopping cart" is too broad. "Create the name field on the Cart model" is too narrow. Like cutting a steak — not the whole piece, and not ground meat.
+Each feature item should be scoped to "completable in one session." Too broad and it won't finish; too narrow and the management overhead grows. "User can add items to cart" is good granularity. "Implement the shopping cart" is too broad. "Create the name field on the Cart model" is too narrow.
## Real-World Case
An e-commerce platform with 10 features. Two tracking approaches compared:
-**Memo mode**: Agent uses unstructured notes. After 3 sessions, notes become "did user auth and product list, shopping cart mostly done but has bugs, payments not started." New session needs 20 minutes to infer state, ultimately re-implements completed features. Like your shopping list saying "milk, bread, and that thing" — at the store, you still don't know what to buy.
+**Memo mode**: The agent uses unstructured notes to track progress. After 3 sessions, the notes become "did user auth and product list, shopping cart mostly done but has bugs, payments not started." A new session needs 20 minutes to infer state, and ultimately re-implements completed features.
-**Backbone mode**: Every feature has a clear state and verification command. New session reads the feature list and in 3 minutes knows: F01-F05 are `passing`, F06 is `active`, F07-F10 are `not_started`. Picks up from F06 directly, zero rework.
+**Structured mode**: Every feature has a clear state and verification command. A new session reads the feature list and in 3 minutes knows: F01-F05 are `passing`, F06 is `active` (in progress), F07-F10 are `not_started`. It picks up directly from F06, with zero rework.
Quantified result: projects using structured feature lists show 45% higher feature completion rate than free-form tracking, with zero duplicate implementations.
## Key Takeaways
-- **Feature lists are the harness's backbone**, not memos for humans. Scheduler, verifier, and handoff reporter all depend on them.
-- **Every feature item must have the triple**: behavior description + verification command + current state. Missing one element makes it incomplete — like a three-legged stool missing a leg.
-- **State transitions are controlled by the harness** — the agent can't change states on its own. Passing verification = the only upgrade path.
-- **The feature list is the project's single source of truth** — all "what to do" information derives from one list.
-- **Calibrate granularity to "completable in one session."**
+- **Feature lists are the harness's foundational structure**, not memos for humans. The scheduler, verifier, and handoff reporter all depend on them.
+- **Every feature item must have the triple**: behavior description + verification command + current state. Missing one element makes it incomplete.
+- **State transitions are controlled by the harness** — the agent can't change states on its own. Passing verification is the only upgrade path.
+- **The feature list is the project's single source of truth** — all "what to do" information derives from it.
+- **Calibrate granularity to "completable in one session."** Too broad and it won't finish; too narrow and you can't manage it.
## Further Reading
- [Building Effective Agents - Anthropic](https://www.anthropic.com/research/building-effective-agents) — Explicitly identifies feature list as the "core data structure" for controlling agent scope
- [Harness Engineering - OpenAI](https://openai.com/index/harness-engineering/) — Emphasizes the principle of "externalizing artifacts"
-- [Design by Contract - Bertrand Meyer](https://www.goodreads.com/book/show/130439.Object_Oriented_Software_Construction) — Contract design principles, the theoretical foundation of feature lists
+- [Design by Contract - Bertrand Meyer](https://www.goodreads.com/book/show/130439.Object_Oriented_Software_Construction) — Design by contract principles, the theoretical foundation of feature lists
- [How Google Tests Software](https://www.goodreads.com/book/show/13563030-how-google-tests-software) — Test pyramid and behavioral specification engineering practices
## Exercises
1. **Feature List Design**: Define a minimal feature list JSON schema. Include: id, behavior description, verification command, current state, evidence reference. Use it to describe a real project with 5 features.
-2. **Verification Strictness Comparison**: Pick 3 features and design both a "loose" verification (e.g., "code has no syntax errors") and a "strict" verification (e.g., "end-to-end test passes"). Compare false positive rate under each approach.
+2. **Verification Strictness Comparison**: Pick 3 features and design both a "loose" verification (e.g., "code has no syntax errors") and a "strict" verification (e.g., "end-to-end test passes"). Compare false positive rates under each approach.
3. **Single Source Principle Audit**: Review an existing agent project and check for scope information that contradicts the feature list (implicit requirements in conversations, TODO comments in code, etc.). Design a plan to unify all information into the feature list.
diff --git a/docs/en/lectures/lecture-09-why-agents-declare-victory-too-early/index.md b/docs/en/lectures/lecture-09-why-agents-declare-victory-too-early/index.md
index 8cbb667..85b782c 100644
--- a/docs/en/lectures/lecture-09-why-agents-declare-victory-too-early/index.md
+++ b/docs/en/lectures/lecture-09-why-agents-declare-victory-too-early/index.md
@@ -1,21 +1,19 @@
-[中文版本 →](../../../zh/lectures/lecture-09-why-agents-declare-victory-too-early/)
+[中文版 →](../../../zh/lectures/lecture-09-why-agents-declare-victory-too-early/)
> Code examples for this lecture: [code/](https://github.com/walkinglabs/learn-harness-engineering/blob/main/docs/en/lectures/lecture-09-why-agents-declare-victory-too-early/code/)
> Hands-on practice: [Project 05. Let the agent verify its own work](./../../projects/project-05-grounded-qa-verification/index.md)
# Lecture 9. Preventing Agents from Declaring Victory Too Early
-You ask an agent to implement a "password reset" feature. It modifies the database schema, writes the API endpoint, adds the email template, runs unit tests (all pass), and then confidently tells you "it's done." When you actually try to run it—the password reset link can't be sent (missing email service config), the database migration fails halfway through (schema inconsistency), and the end-to-end flow hasn't been executed even once.
+You ask an agent to implement a "password reset" feature. It modifies the database schema, writes the API endpoint, adds the email template, runs the unit tests (all pass), and then confidently tells you "it's done." But when you actually try to run it—the password reset link can't be sent because the email service config is missing; the database migration fails halfway through, leaving the schema in an inconsistent state; and the end-to-end flow hasn't been executed even once.
-This feeling shouldn't be unfamiliar—it's like filling up the entire exam paper, confidently being the first to hand it in, only to fail when the grades come out. Just because the paper is full doesn't mean the answers are right.
-
-This isn't an isolated incident. The classic 2017 ICML paper by Guo et al. proved: **modern neural networks are systematically overconfident**—the confidence reported by models is significantly higher than their actual accuracy. The same applies to AI coding agents: they "feel" they're done, but in reality, they're far from it. Your harness must replace the agent's "feelings" with externalized, execution-based verification.
+This isn't an isolated incident. The classic 2017 ICML paper by Guo et al. proved: **modern neural networks are systematically overconfident**—the confidence reported by models is significantly higher than their actual accuracy. AI coding agents are no different. They "feel" done, but in reality they're far from it. Your harness must replace the agent's "feelings" with externalized, execution-based verification.
## The Slippery Slope
-Premature completion declarations almost always follow the same pattern: the code looks okay—syntax is correct, logic seems reasonable, and static analysis shows no obvious errors. But the harness doesn't enforce comprehensive execution verification, so the agent skips actually running it or only runs partial tests. It runs unit tests but skips integration tests; it runs tests but doesn't check coverage. Ultimately, "the code looks fine" is taken as evidence that "the feature is complete." And the exam paper is handed in.
+Premature completion declarations almost always follow the same playbook: the code looks okay—syntax is correct, logic seems reasonable, static analysis shows no obvious errors. But the harness doesn't enforce comprehensive execution verification, so the agent skips actually running it or only runs partial tests. It runs unit tests but skips integration tests; it runs tests but doesn't check coverage. In the end, "the code looks fine" is taken as evidence that "the feature is complete."
-Information is lost at every step. From task specifications to code implementation to runtime behavior, every transformation can introduce bias, and every skipped verification exacerbates the information asymmetry.
+Information is lost at every step. From task specification to code implementation to runtime behavior, every transformation can introduce bias, and every skipped verification compounds the information asymmetry.
## Three-Layer Termination Check
@@ -36,51 +34,51 @@ flowchart LR
## Core Concepts
-- **Premature Completion Declaration**: The agent asserts the task is complete, but unmet correctness specifications still exist. The core issue: the agent judges based on local confidence at the code level, while system-level correctness requires global verification.
-- **Confidence Calibration Bias**: The systematic gap between the agent's self-reported confidence in completion and the actual completion quality. For complex multi-file tasks, this bias is significantly positive—the agent is always more confident than it actually performs. Just like a student who always overestimates their score after an exam.
+- **Premature Completion Declaration**: The agent asserts the task is complete, but unmet correctness specifications remain. The core problem is that the agent judges based on local, code-level confidence, while system-level correctness requires global verification.
+- **Confidence Calibration Bias**: A systematic gap between the agent's self-reported completion confidence and the actual completion quality. For complex multi-file tasks, this bias is significantly positive—the agent is consistently more confident than its actual performance warrants.
- **Termination Criteria**: A clear, executable set of judgment conditions defined in the harness. The agent must satisfy all conditions before declaring completion. "Done" shifts from a subjective judgment to an objective determination.
-- **Verification-Validation Dual Gate**: The first verification layer checks "did the code correctly implement the specified behavior"; the second validation layer checks "does the system-level behavior meet the end-to-end requirements". Both must pass to be considered complete.
-- **Runtime Feedback Signals**: Logs, process states, and health checks from program execution. This is the objective basis for the harness to judge completion quality.
-- **Completion Priority Constraint**: First verify functional correctness, then handle performance, and finally address style. Refactoring is forbidden until core functionality is verified.
+- **Verification-Validation Dual Gate**: The first layer (verification) checks whether the code correctly implements the specified behavior; the second layer (validation) checks whether system-level behavior meets end-to-end requirements. Both must pass before the task is considered complete.
+- **Runtime Feedback Signals**: Logs, process states, and health checks from program execution—these form the objective basis for the harness to judge completion quality.
+- **Completion Priority Constraint**: First verify functional correctness, then address performance, and finally handle style. No refactoring is allowed until core functionality has been verified.
## Passing Unit Tests ≠ Task Complete
-This is the most common trap, and the most dangerous one. The agent wrote the code, ran the unit tests, got all greens, and said "done." But the design philosophy of unit tests—isolating the tested unit and mocking dependencies—is exactly what makes them incapable of detecting cross-component issues:
+This is the most common trap, and the most dangerous one. The agent writes code, runs unit tests, sees all greens, and says "done." But the design philosophy of unit tests—isolating the tested unit and mocking dependencies—is precisely what makes them incapable of detecting cross-component issues:
-**Interface Mismatch**: The file path passed by the render process to the preload script is a relative path, but the preload script expects an absolute path. Their respective unit tests both used mocks and passed. The issue is only discovered during end-to-end testing. Just like every musician in a band practicing perfectly on their own, only to realize they are in different keys when playing together.
+**Interface Mismatch**: The renderer passes a relative file path to the preload script, but the preload script expects an absolute path. Their respective unit tests both use mocks and both pass. The issue only surfaces during end-to-end testing.
-**State Propagation Errors**: A database migration changes the table schema, but the ORM caching layer still holds cache entries for the old schema. Unit tests provide a fresh mock environment every time, which won't expose this cross-layer state inconsistency.
+**State Propagation Errors**: A database migration changes the table schema, but the ORM's caching layer still holds cache entries for the old schema. Unit tests run in a fresh mock environment every time, so this kind of cross-layer state inconsistency never surfaces.
-**Environment Dependency**: The code behaves correctly in the test environment (where everything is mocked) but fails in the real environment due to configuration differences, network latency, or service unavailability. Like singing perfectly in the rehearsal room, but encountering audio equipment issues on stage.
+**Environment Dependency**: Code behaves correctly in the test environment (where everything is mocked) but fails in the real environment due to configuration differences, network latency, or service unavailability.
### "Refactoring While We're at It" is Poison to Completion Judgment
-Claude Code has a common behavioral pattern: it starts refactoring code, optimizing performance, and improving style before the core functionality has passed verification. Knuth's quote, "Premature optimization is the root of all evil," takes on new meaning in the agent scenario—refactoring alters the boundary between verified and unverified code, potentially breaking previously implicitly correct code paths. It's like re-copying your multiple-choice answers for better formatting before you've finished the math essay questions—not only does it waste time, but you might copy them wrong.
+Claude Code has a common behavioral pattern: it starts refactoring code, optimizing performance, and improving style before the core functionality has passed verification. Knuth's adage that "premature optimization is the root of all evil" takes on new meaning in the agent scenario—refactoring shifts the boundary between verified and unverified code, potentially breaking code paths that were previously implicitly correct.
### Systematic Bias in Self-Evaluation
-Anthropic discovered a deeper failure pattern in their 2026 research: **when an agent is asked to evaluate its own work, it systematically provides overly positive evaluations—even when a human observer would consider the quality clearly substandard.** This is like asking a student to grade their own exam—they will always be particularly lenient with their own answers.
+Anthropic discovered a deeper failure pattern in their 2026 research: **when an agent is asked to evaluate its own work, it systematically provides overly positive assessments—even when a human observer would judge the quality as clearly substandard.**
-This issue is especially severe in subjective tasks (such as design aesthetics)—whether a "layout is exquisite" is a judgment call, and the agent reliably skews positive. Even on tasks with verifiable results, the agent's performance can be hindered by poor judgment.
+This problem is especially severe on subjective tasks (such as design aesthetics). Whether a "layout is polished" is a judgment call, and the agent reliably skews positive. Even on tasks with verifiable outcomes, the agent's poor judgment degrades its performance.
-The solution isn't to make the agent "more objective"—the same model generating and evaluating inherently favors being generous to itself. **The solution is to separate the "worker" from the "checker".** Just like a student shouldn't grade their own exam—you need an independent grader.
+The solution isn't to make the agent "more objective." The same model both generates and evaluates, so it is inherently inclined to be generous with itself. **The solution is to separate the "worker" from the "checker."**
-An independent evaluating agent, specifically tuned to be "picky", is far more effective than having the generating agent evaluate itself. Experimental data from Anthropic:
+An independent evaluation agent, specifically tuned to be "nitpicky," is far more effective than having the generating agent evaluate itself. Anthropic's experimental data:
| Architecture | Runtime | Cost | Core Features Working? |
|--------------|---------|------|------------------------|
-| Single Agent (bare run) | 20 mins | $9 | No (game entities unresponsive to input) |
-| Three Agents (planner + generator + evaluator) | 6 hours | $200 | Yes (game is fully playable) |
+| Single agent (bare run) | 20 mins | $9 | No (game entities unresponsive to input) |
+| Three agents (planner + generator + evaluator) | 6 hours | $200 | Yes (game is fully playable) |
-This is the exact same model (Opus 4.5) with the exact same prompt ("build a 2D retro game editor"). The only difference is the harness—from "running bare" to "planner expands requirements → generator implements feature by feature → evaluator performs actual click testing using Playwright".
+This is the exact same model (Opus 4.5) with the exact same prompt ("build a 2D retro game editor"). The only difference is the harness: from "running bare" to "planner expands requirements → generator implements feature by feature → evaluator performs actual click testing using Playwright."
> Source: [Anthropic: Harness design for long-running application development](https://www.anthropic.com/engineering/harness-design-long-running-apps)
-## How to Prevent Premature Hand-ins
+## How to Prevent Premature Completion Declarations
### 1. Externalize Termination Judgment
-The completion judgment shouldn't be made by the agent itself. The harness must independently execute termination validation, using runtime signals as input, not the agent's confidence. Write this clearly in `CLAUDE.md`:
+The completion judgment should not be made by the agent itself. The harness independently executes termination validation, using runtime signals as input rather than the agent's confidence. In CLAUDE.md, you can spell this out:
```
## Definition of Done
@@ -95,19 +93,19 @@ The completion judgment shouldn't be made by the agent itself. The harness must
### 2. Build a Three-Layer Termination Validation
-- **Layer 1: Syntax and Static Analysis**. Lowest cost, least information, but must pass. This is the bare minimum check—you must spell the words right before we look at anything else.
-- **Layer 2: Runtime Behavior Verification**. Test execution, app startup checks, critical path validation. This is the core evidence of completion. It's not enough to just write it; it must run.
-- **Layer 3: System-Level Confirmation**. End-to-end testing, integration validation, user scenario simulation. The final line of defense against premature declarations. It's not enough to run; it must run correctly.
+- **Layer 1: Syntax and Static Analysis**. Lowest cost, least information, but must pass. This is the bare minimum—you need to spell the words correctly before reading further.
+- **Layer 2: Runtime Behavior Verification**. Test execution, application startup checks, critical path validation. This is the core evidence of completion—not just written, but runnable.
+- **Layer 3: System-Level Confirmation**. End-to-end testing, integration validation, user scenario simulation. The last line of defense against premature declarations—not just runnable, but correct.
-### 3. Design Good "Red Pen Markups" for Agents
+### 3. Provide Actionable Error Feedback to the Agent
-OpenAI introduced a particularly effective pattern during their Codex practice: **error messages for agents should include fix instructions**. Don't just draw a big red cross like a lazy grader; be like a good teacher and write "here's how you should change this" in the margins. Don't use `"Test failed"`, but use `"Test failed: POST /api/reset-password returned 500. Check that the email service config exists in environment variables. The template file should be at templates/reset-email.html."` This specific, actionable feedback allows the agent to self-correct without human intervention.
+OpenAI introduced a particularly effective pattern in their Codex practice: **error messages written for agents should include repair instructions**. Don't just tell the agent "it's wrong"—point out exactly what's wrong and how to fix it. Don't use `"Test failed"`, use `"Test failed: POST /api/reset-password returned 500. Check that the email service config exists in environment variables. The template file should be at templates/reset-email.html."` This kind of specific, actionable feedback lets the agent self-correct without human intervention.
### 4. Capture Runtime Signals
Effective runtime signals include:
- Did the application successfully start and reach a ready state?
-- Did the critical feature paths execute successfully at runtime?
+- Did critical feature paths execute successfully at runtime?
- Were database writes, file operations, and other side effects correct?
- Were temporary resources cleaned up?
@@ -115,18 +113,18 @@ Effective runtime signals include:
**Task**: Implement user password reset functionality. Involves database operations, email sending, and API endpoint modifications.
-**Premature hand-in path**: Agent modifies database schema, writes API endpoint, adds email template, runs unit tests (passes), and declares completion. The exam paper is completely filled out.
+**Premature hand-in path**: The agent modifies the database schema, writes the API endpoint, adds the email template, runs unit tests (all pass), and declares completion. It looks like a lot was done, but the critical steps were all skipped.
-**Actual point deductions**: (1) End-to-end flow untested—the actual sending and verification of the reset link was never confirmed. (2) Database migration failed after partial execution, causing schema inconsistency. (3) Email service config was missing in the target environment.
+**Actual omissions**: (1) End-to-end flow untested—the actual sending and verification of the reset link was never confirmed. (2) Database migration failed after partial execution, leaving the schema inconsistent. (3) Email service configuration was missing in the target environment.
-**Harness intervention**: Termination validation enforced—(1) Start the full app to verify reset endpoint accessibility; (2) Execute the full reset flow; (3) Verify database state consistency. All defects were found within the session, saving 5-10x the cost of subsequent fixes. The independent grader found the real issues.
+**Harness intervention**: Termination validation is enforced—(1) start the full application to verify the reset endpoint is accessible; (2) execute the complete reset flow; (3) verify database state consistency. All defects were discovered within the session, saving 5-10x the cost of post-hoc fixes.
## Key Takeaways
-- **Agents are systematically overconfident**—confidence calibration bias is an objective reality. Filling out the exam paper doesn't mean you got it right.
-- **Completion judgment must be externalized**—the harness verifies independently; don't trust the agent's "feelings". Students cannot grade their own exams.
-- **All three layers of validation are essential**—syntax passing, behavior passing, system passing, progressing layer by layer.
-- **Error messages should be like a good teacher's red pen markup**—include specific fix steps so the agent can self-correct.
+- **Agents are systematically overconfident**—confidence calibration bias is an objective reality. Code being written doesn't mean it was written correctly.
+- **Completion judgment must be externalized**—the harness verifies independently. Don't trust the agent's "feelings."
+- **All three layers of validation are essential**: syntax passes, behavior passes, system passes—layer by layer, no shortcuts.
+- **Error messages should include specific repair steps**, enabling the agent to self-correct rather than just telling it "it's wrong."
- **No refactoring until core functionality is verified**—the completion priority constraint is the key to preventing premature optimization.
## Further Reading
@@ -138,8 +136,8 @@ Effective runtime signals include:
## Exercises
-1. **Termination Validation Function Design**: Design a complete termination validation for a task involving a database migration and API modification. List the required runtime signals and the pass/fail criteria for each signal. Run it on a real task and record what hidden issues it finds.
+1. **Termination Validation Function Design**: Design a complete termination validation for a task involving database migration and API modifications. List the required runtime signals and the pass/fail criteria for each. Run it on a real task and record which hidden issues it discovers.
-2. **Calibration Bias Measurement**: Choose 10 different types of coding tasks, and record the agent's self-reported completion confidence vs. the actual completion quality. Calculate the bias value and analyze its relationship with task complexity.
+2. **Calibration Bias Measurement**: Select 10 coding tasks of different types. Record the agent's self-reported completion confidence versus the actual completion quality. Calculate the bias and analyze its relationship with task complexity.
-3. **Multi-Layer Defense Experiment**: Run three configurations on the same set of tasks—(a) static analysis only, (b) add unit testing, (c) full three-layer validation. Compare the proportion of premature completion declarations and the number of uncaught defects.
\ No newline at end of file
+3. **Multi-Layer Defense Experiment**: Run three configurations on the same set of tasks: (a) static analysis only, (b) add unit testing, (c) full three-layer validation. Compare the proportion of premature completion declarations and the number of uncaught defects.
diff --git a/docs/en/lectures/lecture-10-why-end-to-end-testing-changes-results/index.md b/docs/en/lectures/lecture-10-why-end-to-end-testing-changes-results/index.md
index c7c75ac..720f430 100644
--- a/docs/en/lectures/lecture-10-why-end-to-end-testing-changes-results/index.md
+++ b/docs/en/lectures/lecture-10-why-end-to-end-testing-changes-results/index.md
@@ -1,35 +1,33 @@
-[中文版本 →](../../../zh/lectures/lecture-10-why-end-to-end-testing-changes-results/)
+[中文版 →](../../../zh/lectures/lecture-10-why-end-to-end-testing-changes-results/)
> Code examples for this lecture: [code/](https://github.com/walkinglabs/learn-harness-engineering/blob/main/docs/en/lectures/lecture-10-why-end-to-end-testing-changes-results/code/)
> Hands-on practice: [Project 05. Let the agent verify its own work](./../../projects/project-05-grounded-qa-verification/index.md)
-# Lecture 10. Only End-to-End Testing is True Verification
+# Lecture 10. Only a Full Pipeline Run Counts as Real Verification
-You ask the agent to add a file export feature to an Electron app. It writes the render process component, the preload script, and the service layer logic. The unit tests for each component pass perfectly. The agent says, "It's done." When you actually click the export button—the file path format is wrong, the progress bar doesn't update, and exporting large files causes a memory leak. Five component boundary defects, and the unit tests didn't catch a single one.
+You ask the agent to add a file export feature to an Electron app. It writes the renderer component, the preload script, and the service layer logic. Unit tests for every component pass. The agent says "done." You actually click the export button — the file path format is wrong, the progress bar doesn't respond, and exporting large files leaks memory. Five component boundary defects, and unit tests didn't catch a single one.
-It's like a choir rehearsal—each voice part sounds perfect when sung individually, but when they sing together, the sopranos are half a beat faster than the basses, and the accompaniment is a semitone off from the main melody. Each part is "correct" on its own, but the whole thing is out of tune.
+Each part looks "correct" on its own, but problems surface the moment they are wired together. Google's Testing Pyramid tells us that a large base of unit tests is essential, but stopping there means you will systematically miss component interaction issues. For AI coding agents this problem is even worse, because agents tend to run only the fastest tests and then declare completion. **Only end-to-end testing can prove the absence of system-level defects.**
-Google's Testing Pyramid tells us: a large number of unit tests are the foundation, but if you stop there, you will systematically miss component interaction issues. For AI coding agents, this problem is even more severe—agents tend to run only the fastest tests and then declare completion. **Only end-to-end testing can prove that system-level defects don't exist.**
+## The Blind Spots of Unit Tests
-## The Blind Spots of Unit Testing
+The design philosophy of unit testing is isolation: mock dependencies, focus on the unit under test. This philosophy makes unit tests fast and precise, but it also creates systematic blind spots. Every module performs perfectly in isolation, yet the following categories of problems only surface when everything actually runs together:
-The design philosophy of unit testing is isolation—mocking dependencies and focusing solely on the unit under test. This philosophy makes unit testing fast and precise, but it also creates systematic blind spots. It's like having each voice part practice with headphones on during a choir rehearsal—it sounds fine to them, but the issues only emerge when they come together:
+**Interface Mismatch**: The renderer passes the preload script a relative file path, but the preload script expects an absolute path. Their respective unit tests both use mocks and both pass. The problem is only discovered when the end-to-end flow is exercised.
-**Interface Mismatch**: The file path passed by the render process to the preload script is a relative path, but the preload script expects an absolute path. Their respective unit tests both used mocks and passed. The issue is only discovered when the end-to-end flow is executed—just like two voice parts practicing independently and feeling fine, only to realize during the ensemble that one is singing in 4/4 time and the other in 3/4 time.
+**State Propagation Errors**: A database migration changes the table schema, but the ORM caching layer still holds cache entries with the old schema. Unit tests spin up a fresh mock environment every time, so they never expose this kind of cross-layer state inconsistency.
-**State Propagation Errors**: A database migration changes the table schema, but the ORM caching layer still holds cache entries for the old schema. Unit tests provide a completely new mock environment every time, which won't expose this cross-layer state inconsistency. It's like changing the lyrics of a song, but someone is still singing the old version.
+**Resource Lifecycle Issues**: The acquisition and release of file handles, database connections, and network sockets span multiple components. Unit tests create and tear down independent resources for each test case, so they never surface resource contention or leaks.
-**Resource Lifecycle Issues**: The acquisition and release of file handles, database connections, and network sockets span multiple components. Unit tests create and destroy independent resources for each test, failing to expose resource contention or leaks. It's like each voice part taking turns using the microphones during rehearsal, but when everyone goes on stage together, there aren't enough mics.
+**Environment Dependency**: Code behaves correctly in the test environment (where everything is mocked) but fails in the real environment due to configuration differences, network latency, or service unavailability.
-**Environment Dependency**: The code behaves correctly in the test environment (where everything is mocked) but fails in the real environment due to configuration differences, network latency, or service unavailability. Like singing perfectly in the rehearsal room, but encountering audio feedback and wind interference at an outdoor festival.
+## End-to-End Testing Not Only Changes Results — It Changes Behavior
-## End-to-End Testing Not Only Changes Results, It Changes Behavior
+This is something many people overlook: when an agent knows its work will be validated by end-to-end tests, its coding behavior shifts.
-This is something many people fail to realize: when an agent knows its work will be subjected to end-to-end testing, its coding behavior changes.
-
-1. **Considering Component Interactions**: While writing code, it will think about "how this interface connects with upstream," rather than just focusing on a single function. Just like knowing you'll eventually sing together, you'll pay attention to other voice parts during practice.
-2. **Respecting Architectural Boundaries**: In systems with architectural constraints, end-to-end testing forces the agent to adhere to boundary rules. Like sheet music marked with "crescendo here," you have to follow it.
-3. **Handling Error Paths**: End-to-end tests usually include failure scenarios, forcing the agent to consider exception handling. It's like simulating "what if the mic suddenly dies" during rehearsal, so you know what to do.
+1. **Considering component interactions**: While writing code it starts asking "how does this interface connect with the upstream?" rather than focusing on a single function in isolation.
+2. **Respecting architectural boundaries**: In systems with architectural constraints, end-to-end tests force the agent to follow boundary rules.
+3. **Handling error paths**: End-to-end tests typically include failure scenarios, which pushes the agent to think about exception handling.
## Testing Pyramid and Review Feedback Promotion
@@ -52,36 +50,36 @@ flowchart TB
```mermaid
flowchart LR
Review["Review feedback:<br/>renderer cannot import fs directly"] --> Rule["Add a direct fs import check"]
- Rule --> Message["Tell agent in error message<br/>to move file access to preload"]
- Message --> Harness["Add this check to harness"]
- Harness --> Stronger["Will fail immediately next time"]
+ Rule --> Message["Tell the agent in the error message<br/>to move file access to preload"]
+ Message --> Harness["Add this check to the harness"]
+ Harness --> Stronger["Next violation fails immediately"]
```
-In Codex engineering practices, OpenAI emphasizes: **error messages written for agents must include fix instructions.** Don't just write `"Direct filesystem access in renderer"`; write `"Direct filesystem access in renderer. All file operations must go through the preload bridge. Move this call to preload/file-ops.ts and invoke it via window.api."` This turns architectural rules into an auto-correction loop. Like a choir conductor who doesn't just say "you sang that wrong," but instead says "you were half a beat fast here, listen to the altos' rhythm, and come in at measure 32."
+OpenAI emphasizes in its Codex engineering practices: **error messages written for agents must include fix instructions.** Instead of writing `"Direct filesystem access in renderer"`, write `"Direct filesystem access in renderer. All file operations must go through the preload bridge. Move this call to preload/file-ops.ts and invoke it via window.api."` This turns architectural rules into an auto-correction loop. Error messages don't just tell you "what went wrong" — they tell you "how to fix it," enabling the agent to correct itself autonomously.
## Core Concepts
-- **Component Boundary Defects**: Component A and B both pass their unit tests, but their interaction produces incorrect behavior. This is the type of issue end-to-end testing is best at catching—like choir parts that are individually correct but out of tune together.
-- **Testing Adequacy Gradient**: Defects caught by unit tests <= defects caught by integration tests <= defects caught by end-to-end tests. Each layer up increases detection capability.
-- **Architectural Boundary Enforcement Rules**: Turning rules from architecture documents (like "render process cannot access the file system directly") into executable, automated checks. From "written on paper" to "running in CI."
-- **Review Feedback Promotion**: Converting repeated code review comments into automated tests. Every time a recurring issue is found, add a rule, and the harness automatically grows stronger. Like a conductor turning common rehearsal mistakes into warm-up exercises—the next time the same mistake is made, the exercise itself exposes it without the conductor needing to say a word.
-- **Agent-Oriented Error Messages**: Failure messages shouldn't just state "what went wrong," but also tell the agent exactly how to fix it. This turns test failures into self-correcting feedback loops.
+- **Component Boundary Defects**: Component A and B each pass their unit tests, but their interaction produces incorrect behavior. This is the category of issue that end-to-end testing excels at catching.
+- **Testing Adequacy Gradient**: Defects detectable by unit tests <= defects detectable by integration tests <= defects detectable by end-to-end tests. Detection capability increases with each layer.
+- **Architectural Boundary Enforcement Rules**: Turning rules from architecture documents (such as "the renderer process must not access the filesystem directly") into executable, automated checks — going from "written on paper" to "running in CI."
+- **Review Feedback Promotion**: Converting recurring code review comments into automated tests. Every time a new category of repeated issue is found, add a rule, and the harness grows stronger automatically.
+- **Agent-Oriented Error Messages**: Failure messages should not merely state "what went wrong" but also tell the agent exactly how to fix it, turning test failures into self-correcting feedback loops.
## How to Do It
-### 0. Define Architectural Boundaries First, Then Write E2E Tests
+### 0. Define Architectural Boundaries Before Writing E2E Tests
-The prerequisite for end-to-end testing is clear system boundaries. If the architecture is a plate of spaghetti, end-to-end testing will only prove "this plate of spaghetti runs," it won't tell you where design intents were violated. It's like a choir that hasn't even divided into voice parts—no amount of rehearsal will make it sound good.
+The prerequisite for end-to-end testing is that the system has clear boundaries. If the architecture is a tangled mess, end-to-end testing will only prove "the whole mess runs" without telling you where design intent was violated.
-OpenAI's experience: **for codebases generated by agents, architectural constraints must be early prerequisites established on day one, not something to consider when the team grows larger.** The reason is simple—agents will copy existing patterns in the repository, even if those patterns are uneven or suboptimal. Without architectural constraints, the agent will introduce more deviations in every session.
+OpenAI's experience: **for agent-generated codebases, architectural constraints must be established as early prerequisites on day one — not something to think about once the team has grown.** The reason is straightforward: agents copy existing patterns in the repository, even when those patterns are inconsistent or suboptimal. Without architectural constraints, agents introduce more drift with every session.
-OpenAI adopted a "Layered Domain Architecture"—each business domain is divided into fixed layers: Types → Config → Repo → Service → Runtime → UI. Dependencies flow strictly forward, and cross-domain concerns enter through explicit Providers interfaces. Any other dependencies are forbidden and mechanically enforced via custom linting.
+OpenAI adopted a "Layered Domain Architecture," where each business domain is divided into fixed layers: Types -> Config -> Repo -> Service -> Runtime -> UI. Dependencies flow strictly forward, and cross-domain concerns enter through explicit Providers interfaces. Any other dependency is forbidden and mechanically enforced via custom linting.
-Key principle: **Enforce invariants, don't micromanage implementation.** For example, require "data is parsed at the boundary," but don't dictate which library to use. Error messages must include fix instructions—not just saying "violation," but telling the agent exactly how to change it.
+Key principle: **Enforce invariants; don't micromanage implementation.** For example, require that "data is parsed at the boundary," but don't prescribe which library to use. Error messages must include fix instructions — not just saying "violation," but telling the agent concretely how to change it.
> Source: [OpenAI: Harness engineering: leveraging Codex in an agent-first world](https://openai.com/index/harness-engineering/)
-### 1. Harness Must Include an End-to-End Layer
+### 1. The Harness Must Include an End-to-End Layer
Make it explicit in your validation flow: for tasks involving cross-component changes, passing end-to-end tests is a prerequisite for completion:
@@ -98,7 +96,7 @@ Make it explicit in your validation flow: for tasks involving cross-component ch
Every architectural constraint should have a corresponding test or lint rule:
```bash
-# Check if the render process directly calls Node.js APIs
+# Check whether the renderer process directly calls Node.js APIs
grep -r "require('fs')" src/renderer/ && exit 1 || echo "OK: no direct fs access in renderer"
```
@@ -114,15 +112,15 @@ FIX: Move file operations to src/preload/file-ops.ts and call via window.api.rea
### 4. Establish a Review Feedback Promotion Process
-Every time a new type of agent error is found during code review, turn it into an automated check. A month later, your harness will be significantly stronger than at the start of the month. It's like rehearsal notes for a choir—recording issues found in every rehearsal so they can be checked before the next one. Over time, common errors decrease, and the music becomes more harmonious.
+Every time you discover a new category of agent error during code review, turn it into an automated check. A month later your harness will be far stronger than it was at the start of the month.
## Real-World Case
-**Task**: Implement a file export feature in an Electron app. Involves render process UI, preload script filesystem proxy, and service layer data transformation.
+**Task**: Implement a file export feature in an Electron app. Involves renderer process UI, preload script filesystem proxy, and service layer data transformation.
-**Singing parts individually (Unit tests passed)**: Render component tests (passed, file operations mocked), preload script tests (passed, filesystem mocked), service layer tests (passed, data source mocked). Agent declares completion.
+**Unit test phase**: Renderer component tests (passed, file operations mocked), preload script tests (passed, filesystem mocked), service layer tests (passed, data source mocked). Agent declares completion.
-**Singing together (Defects revealed by End-to-End tests)**:
+**Defects revealed by end-to-end tests**:
| Defect | Description | Unit Test | E2E |
|--------|-------------|-----------|-----|
@@ -132,27 +130,27 @@ Every time a new type of agent error is found during code review, turn it into a
| Permission Issue | Different permissions in packaged environment | Missed | Caught |
| Error Propagation | Service layer exceptions didn't reach UI layer | Missed | Caught |
-All 5 defects were caught by end-to-end tests, while unit tests caught none. The cost was an increase in test time from 2 seconds to 15 seconds—completely acceptable in an agent workflow. No matter how well each part sings individually, it can't beat a full ensemble rehearsal.
+All 5 defects were caught by end-to-end tests; unit tests caught none. The trade-off was test time increasing from 2 seconds to 15 seconds — perfectly acceptable in an agent workflow.
## Key Takeaways
-- **Unit tests are systematically blind to component boundary defects**—their isolation design is exactly what prevents them from detecting interaction issues. Everyone singing correctly doesn't mean the choir isn't out of tune.
-- **End-to-end testing not only detects defects, it changes agent coding behavior**—making it focus more on integration and boundaries.
-- **Architectural rules must be executable**—not written in a document waiting to be read, but automatically checked on every commit.
-- **Error messages must be designed for agents**—including specific steps on "how to fix it" to form a self-correcting loop.
-- **Review feedback promotion makes the harness automatically stronger**—every category of captured defect becomes a permanent line of defense.
+- **Unit tests are systematically blind to component boundary defects**: their isolation design is precisely what prevents them from detecting interaction issues.
+- **End-to-end testing not only detects defects, it changes how agents write code**: it shifts focus toward integration and boundaries.
+- **Architectural rules must be executable**: not written in a document waiting for someone to read them, but automatically checked on every commit.
+- **Error messages must be designed for agents**: include concrete "how to fix" steps to form a self-correcting feedback loop.
+- **Review feedback promotion makes the harness automatically stronger**: every captured defect category becomes a permanent line of defense.
## Further Reading
- [How Google Tests Software - Whittaker et al.](https://www.goodreads.com/book/show/13563030-how-google-tests-software) — The classic source of the Testing Pyramid model
-- [Harness Engineering - OpenAI](https://openai.com/index/harness-engineering/) — Engineering practices for automated execution of architectural constraints
+- [Harness Engineering - OpenAI](https://openai.com/index/harness-engineering/) — Engineering practices for automated enforcement of architectural constraints
- [Chaos Engineering - Netflix (Basiri et al.)](https://ieeexplore.ieee.org/document/7466237) — Proactively injecting failures to verify system resilience
-- [QuickCheck - Claessen & Hughes](https://www.cs.tufts.edu/~nr/cs257/archive/john-hughes/quick.pdf) — Property testing methodology, sitting between example testing and formal verification
+- [QuickCheck - Claessen & Hughes](https://www.cs.tufts.edu/~nr/cs257/archive/john-hughes/quick.pdf) — Property testing methodology, sitting between example-based testing and formal verification
## Exercises
-1. **Cross-Component Defect Detection**: Pick a modification task involving at least three components. First, run only unit tests and record the results, then run end-to-end tests. Analyze which type of cross-layer interaction issue each additionally discovered defect belongs to.
+1. **Cross-Component Defect Detection**: Pick a modification task involving at least three components. First run only unit tests and record the results, then run end-to-end tests. Analyze each additionally discovered defect and classify which type of cross-layer interaction issue it represents.
-2. **Architectural Rule Automation**: Pick an architectural constraint from your project and turn it into an executable check (with an agent-oriented error message). Integrate it into the harness and verify its effectiveness with a baseline task.
+2. **Architectural Rule Automation**: Pick an architectural constraint from your project and turn it into an executable check (complete with an agent-oriented error message). Integrate it into the harness and verify its effectiveness using a baseline task.
-3. **Review Feedback Promotion**: Find a recurring comment type from your code review history and convert it into an automated check using the five-step process. Compare the frequency of the issue before and after the promotion.
\ No newline at end of file
+3. **Review Feedback Promotion**: Find a recurring comment type from code review history and convert it into an automated check following the five-step process. Compare the frequency of that issue category before and after the promotion.
diff --git a/docs/en/lectures/lecture-11-why-observability-belongs-inside-the-harness/index.md b/docs/en/lectures/lecture-11-why-observability-belongs-inside-the-harness/index.md
index 6593df8..bca8172 100644
--- a/docs/en/lectures/lecture-11-why-observability-belongs-inside-the-harness/index.md
+++ b/docs/en/lectures/lecture-11-why-observability-belongs-inside-the-harness/index.md
@@ -1,84 +1,88 @@
-[中文版本 →](../../../zh/lectures/lecture-11-why-observability-belongs-inside-the-harness/)
+[中文版 →](../../../zh/lectures/lecture-11-why-observability-belongs-inside-the-harness/)
> Code examples: [code/](https://github.com/walkinglabs/learn-harness-engineering/blob/main/docs/en/lectures/lecture-11-why-observability-belongs-inside-the-harness/code/)
-> Practice project: [Project 06. Complete harness (Capstone)](./../../projects/project-06-runtime-observability-and-debugging/index.md)
+> Practice project: [Project 06. Build a Complete Agent Harness](./../../projects/project-06-runtime-observability-and-debugging/index.md)
-# Lecture 11. Make the Agent's Runtime Observable
+# Lecture 11. Making the Agent's Runtime Observable
-## What Problem Does This Lecture Solve?
+You ask an agent to implement a feature. It runs for 20 minutes, touches a pile of files, then tells you "done, but two tests are failing." You ask why — "not sure, might be a timing issue." You ask which critical paths it changed — "let me look at the code..."
-You ask an agent to implement a feature. It runs for 20 minutes, modifies a bunch of files, then tells you "done, but two tests are failing." You ask why they're failing — "not sure, might be a timing issue." You ask which critical paths it changed — "let me look at the code..."
+This scenario is all too common, and the root cause isn't the agent's capability — it's the harness's lack of observability. When an agent executes a task without visibility into the actual runtime state, every decision it makes is essentially a guess.
-This isn't about the agent lacking capability. It's about your harness not providing enough observability. **Without observability, agents make decisions under uncertainty, evaluations become subjective judgments, and retries become blind wandering.** Both OpenAI and Anthropic define reliability as an evidence problem — the harness must expose runtime behavior and evaluation signals in a form that can guide the next decision.
+**Without observability, agents make decisions under uncertainty, evaluations become subjective judgments, and retries become blind wandering.** Both OpenAI and Anthropic frame reliability as an evidence problem: the harness must expose runtime behavior and evaluation signals in a form that can actually guide the next decision.
-## Core Concepts
+## The Real Cost of Missing Observability
-- **Runtime observability**: System-level signals — logs, traces, process events, health checks. Answers "what did the system do."
-- **Process observability**: Visibility into harness decision artifacts — plans, scoring rubrics, acceptance criteria. Answers "why should this change be accepted."
-- **Task trace**: A complete decision-path record from task start to completion, analogous to request tracing in distributed systems. Every step the agent takes, with context, is recorded.
-- **Sprint contract**: A short-term agreement negotiated before coding begins — specifying task scope, verification standards, and exclusions. The core tool for process observability.
-- **Evaluator rubric**: Transforms quality evaluation from subjective judgment into evidence-based structured scoring. Makes different evaluators produce similar results for the same output.
-- **Layered observability**: System-layer and process-layer observability designed simultaneously and reinforcing each other. Runtime signals explain behavior; process artifacts explain intent.
+When a harness lacks observability, four categories of problems appear systematically.
-## Layered Observability
+**Cannot distinguish "correct" from "looks correct."** A function looks perfectly right in code review — correct syntax, sound logic. But at runtime, a boundary-condition handling error produces incorrect results under specific inputs. Only runtime traces can reveal that the actual execution path deviated from expectations. Code review shows "what was written"; runtime tracing shows "what actually ran." You need both.
-```mermaid
-flowchart LR
- Contract["Write down the task first<br/>what to change / what not to change / pass criteria"] --> Generator["Generator"]
- Generator --> Signals["Collect app logs, traces,<br/>and health checks while it runs"]
- Contract --> Review["Check the result item by item<br/>behavior / tests / boundaries"]
- Signals --> Review
- Review --> Verdict["Point to the failed check<br/>and where to fix it"]
- Verdict --> Generator
-```
+**Evaluation becomes mysticism.** Without scoring rubrics and acceptance criteria, evaluators (human or agent) have to rely on implicit assumptions. The same output can get wildly different assessments from different evaluators. Quality evaluation becomes non-reproducible.
-## Why This Happens
+**Retries become blind guesses.** When the agent doesn't know why something failed, its retry direction is random. It might hammer away in the wrong direction — fixing unrelated code paths while ignoring the real root cause. Every blind retry burns tokens and time.
-### The Real Cost of Missing Observability
+**Session handoff information cliff.** When incomplete work is handed to the next session, missing observability means the new session has to diagnose the system state from scratch. Anthropic's observations of long-running agents show that this redundant diagnosis can eat up 30-50% of total session time.
-When a harness lacks observability, four types of problems systematically appear:
+## A Real Claude Code Scenario
-**Cannot distinguish "correct" from "looks correct"**: A function looks perfectly right during code review — correct syntax, sound logic. But at runtime, an edge case handling error produces incorrect results under specific inputs. Only runtime traces can reveal that the actual execution path deviated from expectations.
+Consider a harness using a "planner-generator-evaluator" three-role workflow, executing the task "add dark mode to the app."
-**Evaluation becomes mysticism**: Without scoring rubrics and acceptance criteria, evaluators (human or agent) rely on implicit assumptions. The same output might get wildly different evaluations from different assessors. Quality assessment becomes non-reproducible.
+**Without observability:** The planner outputs a vague description. The generator implements dark mode based on that vagueness, but the result doesn't match the planner's implicit expectations. The evaluator rejects it based on their own implicit standards but can't articulate what's specifically wrong — just "it doesn't feel right." The generator retries blindly on vague rejection reasons. The cycle repeats 3-4 times, taking about 45 minutes, and barely produces an acceptable output.
-**Retries become blind guesses**: When the agent doesn't know why something failed, retry direction is random. It might try repeatedly in the wrong direction — fixing unrelated code paths while ignoring the actual failure root cause. Every blind retry costs tokens and time.
+**With full observability:** The planner outputs a sprint contract listing which components to modify, verification standards for each, and exclusions (e.g., no print styles). The generator implements according to the contract, and runtime observability records each component's style loading and application process. The evaluator uses a scoring rubric to evaluate dimension by dimension, citing specific evidence: "Button color contrast is insufficient (WCAG AA standard 4.5:1, measured 2.1:1)." One iteration produces a high-quality result, in about 15 minutes.
-**Session handoff information cliff**: When incomplete work is handed to the next session, missing observability means the new session must diagnose system state from scratch. Anthropic's long-running agent observations show this redundant diagnosis can consume 30-50% of total session time.
+3x efficiency difference. The only variable is observability.
-### A Real Claude Code Scenario
+## Layered Observability
-Imagine a harness using a "planner-generator-evaluator" three-role workflow, executing an "add dark mode to the app" task.
+Observability isn't just "add more logging." It operates on two layers, and both are essential.
-**Without observability**: The planner outputs a vague description. The generator implements dark mode based on that vagueness, but it doesn't match the planner's implicit expectations. The evaluator rejects based on their own implicit standards but can't articulate what's specifically wrong. The generator retries blindly based on vague rejection reasons. The cycle repeats 3-4 times, taking about 45 minutes, producing a barely acceptable output.
+```mermaid
+flowchart LR
+ Contract["Define the task upfront<br/>which files to change / what not to touch / pass criteria"] --> Generator["Generator"]
+ Generator --> Signals["Collect at runtime<br/>logs / traces / health checks"]
+ Contract --> Review["Check item by item against the list<br/>functionality / tests / boundaries"]
+ Signals --> Review
+ Review --> Verdict["Point out which item failed<br/>and where to fix it"]
+ Verdict --> Generator
+```
+
+**Runtime observability:** System-level signals — logs, traces, process events, health checks. Answers "what did the system do."
-**With full observability**: The planner outputs a sprint contract — listing which components to modify, verification standards for each, and exclusions (no print styles). The generator implements according to the contract. Runtime observability records each component's style loading and application process. The evaluator uses a scoring rubric to evaluate dimension by dimension, with specific evidence citations. One iteration produces a high-quality result, in about 15 minutes.
+**Process observability:** Visibility into harness decision artifacts — plans, scoring rubrics, acceptance criteria. Answers "why should this change be accepted."
-3x efficiency difference. The only change is observability.
+## Core Concepts
+
+- **Runtime observability**: System-level signals including logs, traces, process events, and health checks. Answers "what did the system do."
+- **Process observability**: Visibility into harness decision artifacts including plans, scoring rubrics, and acceptance criteria. Answers "why should this change be accepted."
+- **Task trace**: A complete decision-path record from task start to completion, analogous to request tracing in distributed systems. Every step the agent takes, along with its context, is recorded — so when something goes wrong, you can replay the entire process.
+- **Sprint contract**: A short-term agreement negotiated before coding begins, specifying task scope, verification standards, and exclusions. The core tool for process observability.
+- **Evaluator rubric**: Transforms quality evaluation from subjective judgment into evidence-based structured scoring, enabling different evaluators to reach similar conclusions for the same output.
+- **Layered observability**: System-layer and process-layer observability designed simultaneously and reinforcing each other. Runtime signals explain behavior; process artifacts explain intent.
-### Why Agents Can't Solve This Themselves
+## Why Agents Can't Solve This Themselves
-You might be thinking: "Can't the agent just print its own logs?" The problems are:
+You might be thinking: "Can't the agent just print its own logs?" The problem is:
-1. The agent doesn't know what it doesn't know — it won't proactively record signals it doesn't realize it needs.
-2. Log formats are inconsistent — different sessions use different log formats, making systematic analysis impossible.
-3. Process observability can't be solved by logs — sprint contracts and scoring rubrics are structured artifacts that need harness-level support.
+1. **Agents don't know what they don't know.** They won't proactively record signals they don't realize they need. Without harness-level constraints, agents only log what they think is important — and what they think is important is usually not enough.
+2. **Log formats are inconsistent.** Different sessions use different log formats, making systematic analysis impossible.
+3. **Process observability can't be solved by logging.** Sprint contracts and scoring rubrics are structured artifacts that require harness-level support — adding a few print statements won't cut it.
-## How to Do It Right
+## How to Build Observability
### 1. Build Runtime Signal Collection into the Harness
-Don't rely on the agent to print its own logs. The harness should automatically collect these signals:
+Don't rely on the agent to print its own logs. The harness should automatically collect the following signals:
- **Application lifecycle**: Startup, ready, running, shutdown phase states
-- **Feature path execution**: Records of critical path execution, including entry points, checkpoints, and exits
+- **Feature path execution**: Execution records for critical paths, including entry points, checkpoints, and exits
- **Data flow**: Records of data flowing between components
- **Resource utilization**: Abnormal resource usage patterns (e.g., continuously growing memory)
- **Errors and exceptions**: Full error context, not just error messages
### 2. Implement Sprint Contracts
-Before each task starts, the generator and evaluator (which may be different invocations of the same agent) negotiate a contract:
+Before each task begins, the generator and evaluator (which may be different invocations of the same agent) negotiate a contract that defines what to build and what "done" looks like:
```markdown
# Sprint Contract: Dark Mode Support
@@ -116,26 +120,41 @@ Turn "is it good or not" into quantifiable scoring:
Create a trace for each harness session, a span for each task, and sub-spans for each verification step. Use standard attributes to annotate key information. This way observability data integrates with standard toolchains (Jaeger, Zipkin).
-## Real-World Case
+## Anthropic's Three-Agent Architecture Experiment
+
+In March 2026, Anthropic published a systematic harness experiment. They ran the same task ("build a browser-based DAW using the Web Audio API") with three different architectures and recorded detailed phase-by-phase data:
+
+| Agent & Phase | Duration | Cost |
+|---------------|----------|------|
+| Planner | 4.7 min | $0.46 |
+| Build round 1 | 2 hr 7 min | $71.08 |
+| QA round 1 | 8.8 min | $3.24 |
+| Build round 2 | 1 hr 2 min | $36.89 |
+| QA round 2 | 6.8 min | $3.09 |
+| Build round 3 | 10.9 min | $5.88 |
+| QA round 3 | 9.6 min | $4.06 |
+| **Total** | **3 hr 50 min** | **$124.70** |
+
+Each of the three agents had a distinct role, and each played a clear part in observability:
+
+**Planner:** Receives a 1-4 sentence user requirement and expands it into a full product spec. It was instructed to "be bold in scope" and "focus on product context and high-level technical design rather than detailed technical implementation." The reasoning: if the planner prematurely specifies granular technical details and gets them wrong, those errors cascade downstream. A better approach is to constrain deliverables and let the agent find its own path during execution.
+
+**Generator:** Implements feature by feature, sprint by sprint. Before each sprint, it negotiates a sprint contract with the evaluator defining what "done" means for that feature block. It then implements according to the contract, self-evaluates, and hands off to QA.
-A harness using a planner-generator-evaluator workflow, executing "add dark mode support":
+**Evaluator:** Uses Playwright MCP to interact with the running app like a real user — testing UI functionality, API endpoints, and database state. It scores each sprint across four dimensions: product depth, functionality, visual design, and code quality. Each dimension has a hard threshold — if any falls short, the sprint fails and the generator receives detailed feedback for fixes.
-**Unobservable version**: 3-4 rounds of blind retries, 45 minutes, barely acceptable output. Evaluator says "it doesn't feel right" but can't say what specifically. Generator wastes significant time in wrong directions.
+Example feedback from QA round 1: "This is a visually impressive app with good AI integration, but several core DAW features are presentational only, lacking interaction depth: clips can't be dragged/moved, there's no instrument UI panel (synth knobs, drum pads), and no visual effects editor (EQ curves, compressor meters)." These aren't edge cases — they're the core interactions that make a DAW usable. Specific, evidence-backed feedback — not "it doesn't feel right."
-**Fully observable version**:
-- Sprint contract clarifies scope, standards, and exclusions
-- Runtime traces record each component's style loading process
-- Scoring rubric provides dimension-by-dimension structured evaluation
-- One iteration produces high-quality results, 15 minutes
+The evaluator wasn't always this sharp. Early versions would identify reasonable issues, then talk themselves into dismissing those issues as not severe, ultimately approving the work. The fix: read the evaluator's logs, find the points where its judgment diverged from human judgment, and update the QA prompt to address those specific problems. After several rounds of this development loop, the evaluator's scoring became reliable.
-3x efficiency improvement, more stable quality, reproducible evaluations.
+> Source: [Anthropic: Harness design for long-running application development](https://www.anthropic.com/engineering/harness-design-long-running-apps)
## Key Takeaways
-- **Observability is a harness architecture property** — not a feature added after the fact, but a core capability that must be considered during design.
-- **Both observability layers are essential** — runtime signals explain "what happened," process artifacts explain "why it was done this way."
-- **Sprint contracts front-load alignment** — preventing "the generator built something the evaluator immediately rejects for foreseeable reasons."
-- **Scoring rubrics make evaluation reproducible** — different evaluators produce similar scores for the same output.
+- **Observability is a harness architecture property.** It's not a feature you add after the fact — it's a core capability that must be designed in from the start.
+- **Both observability layers are essential.** Runtime signals explain "what happened," process artifacts explain "why it was done this way."
+- **Sprint contracts front-load alignment.** They prevent the generator from building something the evaluator immediately rejects for foreseeable reasons.
+- **Scoring rubrics make evaluation reproducible.** Different evaluators produce similar scores for the same output.
- **Missing observability wastes 30-50% of session time on redundant diagnosis.**
## Further Reading
@@ -151,4 +170,4 @@ A harness using a planner-generator-evaluator workflow, executing "add dark mode
2. **Sprint Contract Practice**: Write a sprint contract for a real task. Have the agent execute according to the contract, and compare efficiency and quality with and without the contract.
-3. **Task Trace Construction**: Record every step of an agent's operations during a complete coding task. Annotate with OpenTelemetry semantic conventions. Analyze information bottlenecks in the trace — which steps lack sufficient signal support for decisions.
\ No newline at end of file
+3. **Task Trace Construction**: Record every step an agent takes during a complete coding task. Annotate using OpenTelemetry semantic conventions. Analyze the trace for information bottlenecks — which steps lack sufficient signal support for their decisions.
diff --git a/docs/en/lectures/lecture-12-why-every-session-must-leave-a-clean-state/index.md b/docs/en/lectures/lecture-12-why-every-session-must-leave-a-clean-state/index.md
index 0e00606..6f2be17 100644
--- a/docs/en/lectures/lecture-12-why-every-session-must-leave-a-clean-state/index.md
+++ b/docs/en/lectures/lecture-12-why-every-session-must-leave-a-clean-state/index.md
@@ -1,26 +1,33 @@
-[中文版本 →](../../../zh/lectures/lecture-12-why-every-session-must-leave-a-clean-state/)
+[中文版 →](../../../zh/lectures/lecture-12-why-every-session-must-leave-a-clean-state/)
> Code examples: [code/](https://github.com/walkinglabs/learn-harness-engineering/blob/main/docs/en/lectures/lecture-12-why-every-session-must-leave-a-clean-state/code/)
-> Practice project: [Project 06. Complete harness (Capstone)](./../../projects/project-06-runtime-observability-and-debugging/index.md)
+> Practice project: [Project 06. Build a Complete Agent Workspace](./../../projects/project-06-runtime-observability-and-debugging/index.md)
-# Lecture 12. Clean Handoff at the End of Every Session
+# Lecture 12. Leave a Clean Handoff at the End of Every Session
-## What Problem Does This Lecture Solve?
+Your agent runs all afternoon, modifies 20 files, commits the code, and the session ends. The next agent session starts up and immediately discovers: build is broken, tests are red, temporary debug files are scattered everywhere, the feature list hasn't been updated, and progress is completely opaque. The first 30 minutes of the new session are spent entirely on "figuring out what the last session actually did."
-Your agent runs all afternoon, modifies 20 files, commits the code, session ends. The next agent session starts and immediately discovers: build is broken, tests are red, temporary debug files are everywhere, the feature list wasn't updated, and progress is completely unclear. The new session spends its first 30 minutes just figuring out "what did the last session actually do."
+Both OpenAI and Anthropic state clearly: **long-term reliability depends on operational discipline, not just single-run success.** The quality of state at the end of each session directly determines the next session's efficiency.
-Both OpenAI and Anthropic state clearly: **long-term reliability depends on operational discipline, not just single-run success.** The quality of state at session exit directly determines the next session's efficiency. Think of it like Git best practices — every commit should be an atomic, compilable change, not a pile of half-finished code.
+## Entropy Growth Is the Default State
-## Core Concepts
+Lehman's laws of software evolution tell us that systems undergoing continuous change will inevitably grow more complex unless actively managed. This is especially true for AI coding agents. Every session introduces changes, and without cleanup at exit, technical debt accumulates exponentially.
-- **Clean state**: The system satisfies five conditions at session end — build passes, tests pass, progress recorded, no stale artifacts, startup path available. Missing any one means the session isn't "done."
-- **Session integrity**: Analogous to database transactions — either fully commit and leave a clean state, or roll back to the last consistent state. No middle ground.
-- **Quality document**: An active artifact that continuously records quality ratings for each module. Not a one-time assessment, but a tracker showing whether the codebase is getting stronger or weaker over time.
-- **Cleanup loop**: A regular maintenance session aimed at systematically reducing entropy in the codebase. Not an emergency fix, but routine operations.
-- **Harness simplification**: As model capabilities improve, periodically remove harness components that are no longer necessary. A constraint essential today may be unnecessary overhead in three months.
-- **Idempotent cleanup**: Cleanup operations produce the same result regardless of how many times they run. Ensures cleanup remains safe even in failure-retry scenarios.
+During five months of Codex experiments, OpenAI observed something striking: **agents copy patterns already present in the repository, even when those patterns are inconsistent or suboptimal.** Over time, this copying inevitably leads to drift. The first person leaves a coffee cup in the common area; the second person figures "it's already messy" and leaves another; a week later the table is buried under cups. A codebase works the same way.
+
+The OpenAI team initially spent 20% of every Friday manually cleaning up "AI slop," but this approach clearly doesn't scale. They eventually arrived at a systematic solution:
+
+1. **Encode "golden rules" into the repository**: Rules like "prefer the shared utility package over hand-rolled ad-hoc helpers" (keep invariants centralized) and "don't YOLO-guess data structures" (validate boundaries or depend on typed SDKs). These rules are concrete, mechanical, and automatically checkable.
+2. **Establish periodic cleanup workflows**: A fleet of background Codex tasks that regularly scan for deviations, update quality scores, and open targeted refactoring PRs. Most can be reviewed and auto-merged within a minute.
+3. **Capture human taste once, enforce it continuously**: Review comments, refactoring PRs, and user-facing bugs are all translated into documentation updates or encoded directly into tooling. When documentation isn't enough, promote the rule into code.
+
+Technical debt is a high-interest loan. Continuously paying it off in small increments is almost always better than letting it accumulate into one massive payoff event.
+
+> Source: [OpenAI: Harness engineering: leveraging Codex in an agent-first world](https://openai.com/index/harness-engineering/)
-## Five Dimensions of Clean State
+## Clean State: More Than "The Code Compiles"
+
+Clean state isn't simply "the code compiles." Building without errors is the most basic requirement — the next session shouldn't have to fix build errors first. All tests must pass too, including tests that existed before the session; the session is responsible for not breaking existing functionality. And this should be verified in CI, not just "works on my machine."
```mermaid
flowchart LR
@@ -36,25 +43,36 @@ flowchart LR
Fix --> Build
```
+But that's still not enough. Current progress must be recorded in machine-readable artifacts: completed subtasks with their passing criteria, in-progress but incomplete subtasks with current state, and not-yet-started subtasks. Good progress records can reduce session startup diagnostic time by 60–80%. Temporary artifacts — debug logs, temporary files, commented-out code, TODO markers — must also be cleaned up, because they increase cognitive load for the next session. The standard startup path must remain functional too. Can the next session start working without manual intervention? Environment initialization, codebase loading, context acquisition, task selection — none of these paths can be broken.
+
```mermaid
flowchart LR
- Dirty["Session ends with<br/>red tests / temp files / no progress update"] --> Diagnose["Next session first has to<br/>figure out what happened"]
- Diagnose --> Fragile["New work starts on a messy repo"]
+ Dirty["Session ends with<br/>red tests / temp files not deleted / no progress recorded"] --> Diagnose["Next session first has to<br/>figure out what happened"]
+ Diagnose --> Fragile["Then continues modifying<br/>an already messy repo"]
Fragile --> More["More debug files, more broken checks,<br/>more unclear progress"]
More --> Dirty
- Clean["Session ends with<br/>green tests / updated progress / temp files removed"] --> Fast["Next session can start coding immediately"]
- Fast --> Stable["No need to rescue the repo first"]
+ Clean["Session ends with<br/>green tests / progress updated / temp files deleted"] --> Fast["Next session opens the repo<br/>and can keep coding"]
+ Fast --> Stable["No need to fight fires first"]
Stable --> Clean
```
-## Why This Happens
+## Core Concepts
+
+- **Clean state**: The system must satisfy five conditions at session end — build passes, tests pass, progress recorded, no stale artifacts, startup path available. Missing any one means the session isn't "done."
+- **Session integrity**: Analogous to database transactions — either fully commit and leave a clean state, or roll back to the last consistent state. No middle ground.
+- **Quality document**: An active artifact that continuously records quality ratings for each module. Not a one-time assessment, but a tracker showing whether the codebase is getting stronger or weaker over time.
+- **Cleanup loop**: A regular maintenance session aimed at systematically reducing entropy in the codebase. Not an emergency fix, but routine operations.
+- **Harness simplification**: As model capabilities improve, periodically remove harness components that are no longer necessary. A constraint essential today may be unnecessary overhead in three months.
+- **Idempotent cleanup**: Cleanup operations produce the same result regardless of how many times they run, ensuring cleanup remains safe even in failure-retry scenarios.
+
+## "Clean Up Later" Means Never Clean Up
-### Entropy Growth Is the Default State
+The most common mental trap is "no time to clean up this session, I'll do it next time." But the next agent session doesn't know what you left behind — it sees a mess of code and uncertain state. It'll spend significant time inferring "which parts of this code are intentional and which are temporary."
-Lehman's laws of software evolution tell us: systems undergoing continuous change will inevitably increase in complexity unless actively managed. This is especially true for AI coding agents — every session introduces changes, and without cleanup at exit, technical debt accumulates exponentially.
+Worse, every session has its own task objectives. The new session is there to do new work, not clean up the previous session's mess. It'll ignore the chaos and start new work on top of it, introducing even more chaos. This is entropy's positive feedback loop.
-Real data is telling. A project developed with agents for 12 weeks, without cleanup strategy:
+The numbers tell the story. A project developed with agents for 12 weeks, without a cleanup strategy:
- Week 1: Build pass rate 100%, test pass rate 100%, new session startup 5 min
- Week 4: Build 95%, tests 92%, startup 15 min
@@ -68,29 +86,9 @@ Same project with a cleanup strategy:
After 12 weeks: build pass rate differs by 29 percentage points, new session startup time differs by 85%. This is not theoretical — it's an observed difference.
-### Five Dimensions of Clean State
-
-Clean state isn't just "the code compiles." It's five dimensions evaluated together:
-
-**Build dimension**: Does the code build without errors? This is the most basic — the next session shouldn't have to fix build errors first.
-
-**Test dimension**: Do all tests pass? Including tests that existed before the session — the session is responsible for not breaking existing functionality. And it should be verified in CI, not just "works on my machine."
-
-**Progress dimension**: Is current progress recorded in a machine-readable artifact? Completed subtasks with their passing criteria, in-progress but incomplete subtasks with current state, not-yet-started subtasks. Good progress records reduce 60-80% of session startup diagnostic time.
-
-**Artifact dimension**: Are there stale or ambiguous temporary artifacts? Debug logs, temporary files, commented-out code, TODO markers — all of these increase cognitive load for the next session.
-
-**Startup dimension**: Is the standard startup path available? Can the next session start working without manual intervention? Environment initialization, codebase loading, context acquisition, task selection — these paths must not be broken.
-
-### "Clean Up Later" Means Never Clean Up
-
-The most common mental trap is "no time to clean up this session, I'll do it next time." But the next agent session doesn't know what you left behind — it sees a mess of code and uncertain state. It'll spend significant time inferring "which parts of this code are intentional and which are temporary."
-
-Worse, every session has its own task objectives. The new session is there to do new work, not clean up the previous session's mess. It'll ignore the chaos and start new work on top of it, introducing more chaos on top of chaos. This is entropy's positive feedback loop.
-
-## How to Do It Right
+## How to Do It
-### 1. Clean State as a Completion Requirement
+### 1. Clean State Is a Necessary Condition for Completion
Define explicitly in the harness: **session completion = task passes verification AND clean state check passes.** Missing either one means the session isn't complete. Write in CLAUDE.md:
@@ -107,9 +105,9 @@ Define explicitly in the harness: **session completion = task passes verificatio
Combine two cleanup modes:
-**Immediate cleanup (at end of every session)**: Clean up temporary artifacts created during the session, update feature list state, ensure build and tests pass. This is "reference counting" cleanup.
+**Immediate cleanup (at end of every session)**: Clean up temporary artifacts created during the session, update feature list state, ensure build and tests pass. This is "reference counting" cleanup — clean up as soon as you're done using something.
-**Periodic cleanup (weekly)**: Full-system scan — handle accumulated structural issues, update quality documents, run benchmark tests to detect drift. This is "tracing" cleanup.
+**Periodic cleanup (weekly)**: Full-system scan — handle accumulated structural issues, update quality documents, run benchmark tests to detect drift. This is "tracing" cleanup — a comprehensive maintenance pass done on a regular cadence.
### 3. Maintain a Quality Document
@@ -137,13 +135,19 @@ New sessions read this document and immediately know where to prioritize. Fix th
### 4. Periodically Simplify the Harness
-An important insight from Anthropic: **every harness component exists because the model can't reliably do something on its own. But as models improve, these assumptions become outdated.** A constraint essential three months ago may be unnecessary overhead today.
+Every harness component exists because the model couldn't reliably do something on its own. But as models improve, these assumptions become outdated.
+
+Anthropic's experiments demonstrated this directly. Their initial harness included a sprint-splitting mechanism — breaking work into small chunks for Sonnet 4.5 to complete one at a time. When Opus 4.6 shipped, the model's native capabilities could handle work decomposition autonomously, making sprint construction unnecessary overhead. After removing it, the builder agent could work continuously for over two hours without drifting — and was actually smoother.
+
+But the evaluator told a different story. Even with Opus 4.6's stronger capabilities, when tasks approached the model's capability boundary, the evaluator still provided real value — catching the generator's missing functionality and stub implementations. This means the evaluator isn't a fixed yes/no decision; it depends on where task difficulty sits relative to model capability.
-Recommended practice: Every month, pick one harness component, temporarily disable it, and run benchmark tasks. If results don't degrade, remove it permanently. If they do, restore it or replace with a lighter alternative.
+**Recommended practice**: Every month, pick one harness component, temporarily disable it, and run benchmark tasks. If results don't degrade, remove it permanently. If they do, restore it or replace it with a lighter alternative.
+
+A deeper principle: **as models improve, the interesting combinations in a harness don't shrink — they shift.** Problems that previously required explicit solutions get absorbed by model capabilities, but new capability boundaries open up harness design spaces that were previously impossible. The AI engineer's job is to continuously find the next valuable combination.
### 5. Cleanup Operations Must Be Idempotent
-Cleanup scripts should be safe to run repeatedly:
+Cleanup scripts should be safe to run repeatedly — running them one more time shouldn't produce side effects:
```bash
# Idempotent cleanup operations
@@ -152,23 +156,29 @@ git checkout -- .env.local # Restore to known state
npm run test # Verify cleanup didn't break anything
```
+### 6. High Throughput Changes the Merge Philosophy
+
+When agent output far exceeds human review capacity, the traditional merge philosophy needs adjustment. The OpenAI team's experience: in an environment where an agent opens 3.5 PRs per day (and later even more), minimizing blocking merge gates is the right call. PRs should be short-lived; test flakiness is usually resolved with subsequent runs rather than indefinitely blocking progress. In a system where the cost of fixing is low and the cost of waiting is high, moving fast with fast fixes is a better strategy than slow confirmation.
+
+**Caveat**: This is irresponsible in a low-throughput environment. But when agent output far exceeds human attention, it's often the correct tradeoff. The key criterion: **average cost of fixing a bug vs. average cost of waiting for a human to review a PR.** When the former is lower than the latter, fast merging is the right call.
+
## Real-World Case
An Electron app developed with agents over 12 weeks, comparing two approaches:
-**Without cleanup strategy** (control group): Week 12, build pass rate 68%, test pass rate 61%, new session startup 60+ min, stale artifacts 103.
+**Without cleanup strategy** (control group): Week 12, build pass rate 68%, test pass rate 61%, new session startup 60+ min, 103 stale artifacts.
-**With cleanup strategy** (experimental group): Full clean-state check at every session end + weekly cleanup loop. Week 12, build pass rate 97%, test pass rate 95%, new session startup 9 min, stale artifacts 11.
+**With cleanup strategy** (experimental group): Full clean-state check at every session end, plus a weekly cleanup loop. Week 12, build pass rate 97%, test pass rate 95%, new session startup 9 min, 11 stale artifacts.
-By week 12, the experimental group's build pass rate is 29 percentage points higher, test pass rate 34 points higher, and new session startup time 85% lower.
+By week 12, the experimental group's build pass rate was 29 percentage points higher, test pass rate 34 points higher, and new session startup time 85% lower. Each session spent an extra 5 minutes on cleanup, but over 12 weeks that saved dozens of hours of chaos.
## Key Takeaways
- **Clean state is a necessary condition for session completion** — not optional housekeeping, but part of the "definition of done."
-- **All five dimensions are required** — build, tests, progress, artifacts, startup — each must be explicitly checked.
-- **Quality documents make codebase health trackable** — you can only fix what you know is degrading.
+- **All five dimensions are non-negotiable** — build, tests, progress, artifacts, startup — each must be explicitly checked.
+- **Quality documents make codebase health trackable** — you can only proactively fix what you know is degrading.
- **Periodically simplify the harness** — as model capabilities improve, remove constraints that are no longer needed.
-- **"Clean up later" equals never cleaning up** — entropy growth is the default; only active cleanup counteracts it.
+- **"Clean up later" equals never cleaning up.** Entropy growth is the default state; only active cleanup counteracts it.
## Further Reading
@@ -179,8 +189,8 @@ By week 12, the experimental group's build pass rate is 29 percentage points hig
## Exercises
-1. **Clean State Checklist**: Design a session exit checklist for your codebase covering all five dimensions. Apply it across 5 consecutive sessions and record violations per dimension.
+1. **Clean State Checklist**: Design a session exit checklist for your codebase covering all five dimensions. Apply it across 5 consecutive sessions and record the number of violations per dimension.
2. **Benchmark Comparison**: Use a fixed task set with two harness variants (with/without clean state requirements). Compare completion rate, retry count, and defect escape rate.
-3. **Harness Simplification Practice**: Pick one harness component, temporarily disable it, and run benchmark tasks. Compare results with and without it. Decide whether to keep, remove, or replace.
\ No newline at end of file
+3. **Harness Simplification Practice**: Pick one harness component, temporarily disable it, and run benchmark tasks. Compare results with and without it. Decide whether to keep, remove, or replace.
diff --git a/docs/zh/lectures/lecture-01-why-capable-agents-still-fail/index.md b/docs/zh/lectures/lecture-01-why-capable-agents-still-fail/index.md
index 2a2d3dd..e11c7db 100644
--- a/docs/zh/lectures/lecture-01-why-capable-agents-still-fail/index.md
+++ b/docs/zh/lectures/lecture-01-why-capable-agents-still-fail/index.md
@@ -5,35 +5,31 @@
# 第一讲. 模型能力强,不等于执行可靠
-你说你也算见过世面的人了——Claude Pro 订着,GPT-4o 的 API key 也有,SWE-bench 排行榜上的数字你比谁都清楚。有一天你终于想让 AI agent 帮你改一个真实的项目,信心满满地交代下去。结果呢?加了功能但测试挂了,改了 bug 但引入了新 bug,跑了 20 分钟然后自信满满地说"完成了"——你一看代码,根本不是你要的东西。
+截至 2025 年底,最强的 coding agent 在 SWE-bench Verified 上的通过率大约在 50-60%。这个数字听起来还不错,但别急着高兴——那些都是精心挑选过的任务,有明确的 issue 描述,有现成的测试用例。等你把自己日常的需求丢过去,需求模糊、没有现成测试、隐含的业务规则散落在各处,通过率只会更低。你信心满满地交代一个任务,agent 跑了 20 分钟后告诉你"做完了",你一看代码,加了功能但测试挂了,改了 bug 但引入了新 bug,根本不是你要的东西。
-这时候你的第一反应是什么?"这模型不行,得换一个更贵的。"且慢。先别急着掏钱包。问题可能根本不在模型身上。
-
-让我们先看一组数据。截至 2025 年底,最强的 coding agent 在 SWE-bench Verified 上的通过率大约在 50-60%。这还是精心挑选过的、有明确 issue 描述和测试用例的任务。换到你日常开发的场景——需求模糊、没有现成测试、隐含的业务规则散落在各处——这个数字只会更低。
-
-但这组数据背后藏着一个反直觉的事实。
+遇到这种情况,大多数人的第一反应是"这模型不行,换一个更贵的"。先别急着掏钱包。问题可能不在模型身上。
## 同一匹马,两种命运
-Anthropic 做过一个对照实验。同一个 prompt("做一个 2D 复古游戏编辑器"),同一个模型(Opus 4.5)。第一次让它裸跑——20 分钟,花了 $9,游戏核心功能根本跑不起来。第二次给它配上完整的 harness(planner + generator + evaluator 三 agent 架构)——6 小时,花了 $200,游戏可以正常游玩。
+Anthropic 做过一个对照实验,很能说明问题。同一个 prompt,"做一个 2D 复古游戏编辑器",同一个模型 Opus 4.5,跑了两次。第一次裸跑,20 分钟花了 $9,游戏核心功能跑不起来。第二次配上了完整的 harness——planner、generator、evaluator 三 agent 架构——6 小时花了 $200,游戏可以正常游玩。
-模型没换。Opus 4.5 还是那个 Opus 4.5。换的是马具。
+Opus 4.5 还是那个 Opus 4.5,模型没有换。换的是马具。
-OpenAI 在 2025 年发布的 harness engineering 文章里说得更直白:Codex 在一个 harness 搭得好的仓库里,表现能从"不可靠"变成"可靠"。注意他们的用词——不是"好了一点",是质变。就像一匹千里马,没马具你也能骑,但控不稳、走不远、摔下来也不稀奇。harness 就是那整套马具——**模型权重之外的一切工程基础设施**。
+OpenAI 在 2025 年的 harness engineering 文章里把这件事说得更直白。他们说 Codex 在一个 harness 搭得好的仓库里,表现能从"不可靠"直接跳到"可靠"。注意这个用词——不是"好了一点",是质变。harness 这个词在这里的意思就是**模型权重之外的一切工程基础设施**。
## agent 到底卡在哪
-那具体是什么在出问题?
+具体的失败模式其实就那么几种。
-最常见的:你根本没把任务说清楚。你说"加个搜索功能",agent 理解的跟你完全不一样——搜什么?全文本还是结构化?要不要分页?要不要高亮?你没说清楚,agent 就自己猜。猜对了是运气,猜错了你再改,改的成本比一开始说清楚还高。这就像你去饭馆跟师傅说"来个鱼",端上来是红烧还是清蒸还是酸菜——全看运气。
+头一种是任务压根没交代清楚。"加个搜索功能"——这话说了等于没说。搜索的对象是什么?全文本还是结构化查询?结果要不要分页、要不要高亮?你没说明白,agent 就只好自己猜。猜对了算运气好,猜错了你再改,来回一折腾,比一开始说清楚多花好几倍的时间。
-就算你说清了,项目里隐含的架构约定 agent 也不知道。你们团队统一用 SQLAlchemy 2.0 的新语法,但 agent 默认写了 1.x 的代码。所有 API 端点必须走 OAuth 2.0 认证,但这个规则只存在于你脑子里和一个三个月前的 Slack 消息里。Agent 看不到这些——它不是不想遵守,是压根不知道有这回事。
+架构约定也是暗坑。你们全组都用 SQLAlchemy 2.0 的新语法,但 agent 默认写了 1.x 的代码;所有 API 端点必须走 OAuth 2.0 认证,可这条规矩只存在于你脑子里和三个月前一条 Slack 消息里。Agent 压根不知道有这么回事,不是不想遵守,是真没见过。
-环境也是个坑。开发环境配置不完整、依赖缺了、工具版本不对。Agent 把宝贵的上下文窗口花在了 `pip install` 失败、Node 版本不对这些事上,而不是解决你的核心任务。就好比你让一个木匠来干活,结果锤子没带、钉子找不到、工作台还是歪的——手艺再好也使不上劲。
+环境也常常出问题。开发环境配置不完整、依赖缺了、工具版本不对,agent 把宝贵的上下文窗口花在了 `pip install` 报错、Node 版本冲突这些事上,真正该干的活反而没精力做。
-更常见的:压根没有验证手段。没有测试、没有 lint、或者验证命令根本没告诉 agent。Agent 写完代码,自己看了看觉得没问题,就说完成了。这就像让学生交作业但不给答案检查——他自己觉得自己做对了,但批改的时候一堆错误。Anthropic 还观察到一个有意思的现象:当 agent 感觉上下文快满了,它们会匆忙结束当前工作,跳过验证步骤,选一个简单的方案而不是最优方案。他们把这叫"上下文焦虑"——跟你考试时发现时间快到了赶紧随便选几个选择题是一回事。
+更常见的是压根没有验证手段。没有测试、没有 lint、或者验证命令根本没告诉 agent。Agent 写完代码,自己看了看觉得没问题,就说完成了。Anthropic 还观察到一个有意思的现象:当 agent 感觉上下文快满了,它们会匆忙结束当前工作,跳过验证步骤,选一个简单的方案而不是最优方案。他们把这叫"上下文焦虑"。
-长任务跨会话就更惨了——上次会话的发现全丢了,每个新会话都得重新探索项目结构、理解代码组织。缺乏持久化状态的 agent 在超过 30 分钟的任务中失败率急剧上升。
+至于跨会话的长任务就更惨了。上次会话的发现全丢了,每个新会话都得重新探索项目结构、理解代码组织。缺乏持久化状态的 agent 在超过 30 分钟的任务中失败率急剧上升。
## 关键名词解释
@@ -48,13 +44,11 @@ OpenAI 在 2025 年发布的 harness engineering 文章里说得更直白:Code
## 遇到失败,先修 harness
-核心原则:**遇到失败,先别换模型,先检查 harness。** 如果同一个模型在类似的结构良好的任务中能成功,那优先假设是 harness 的问题。这就像汽车抛锚——你不会第一时间怀疑是发动机坏了,你会先看看是不是没油了。
-
-具体怎么做:
+核心原则只有一条:**遇到失败,先别换模型,先检查 harness。** 如果同一个模型在类似的结构良好的任务中能成功,那优先假设是 harness 的问题。
-**每次失败都归因到具体层。** 不要笼统地说"模型不行",而是问:是任务没说清楚?是上下文不够?是没有验证手段?把每次失败归到五层防御:任务规范、上下文供给、执行环境、验证反馈、状态管理。这里说的是实操诊断用的五层防御,不是上面那组六个术语。养成这个习惯,你会发现"模型不行"这个结论在你的日志里出现得越来越少。
+具体怎么做?每次失败都归因到具体层。不要笼统地说"模型不行",问自己:是任务没说清楚?是上下文不够?是没有验证手段?把每次失败归到五层防御里——任务规范、上下文供给、执行环境、验证反馈、状态管理。养成这个习惯,你会发现"模型不行"这个结论在日志里出现得越来越少。
-**给每个任务写显式的完成定义。** 不要说"加个搜索功能",要说:
+然后,给每个任务写显式的完成定义。不要说"加个搜索功能",要说清楚:
```
完成标准:
- 新增 GET /api/search?q=xxx 端点
@@ -64,21 +58,17 @@ OpenAI 在 2025 年发布的 harness engineering 文章里说得更直白:Code
- 类型检查通过(mypy --strict)
```
-**创建 AGENTS.md 文件。** 在仓库根目录放一个文件,告诉 agent 这个项目的技术栈、架构约定、验证命令。这是 harness 工程的第一步,也是投入产出比最高的一步。一个 `AGENTS.md` 文件可能比你换一个更贵的模型更有效——我不是在开玩笑。
+在仓库根目录放一个 `AGENTS.md` 文件,告诉 agent 这个项目的技术栈、架构约定、验证命令。这是 harness 工程的第一步,也是投入产出比最高的一步。一个 `AGENTS.md` 文件可能比你换一个更贵的模型更有效——这话不是开玩笑。
-**建立诊断循环。** 不要把失败当作"模型又犯傻了",而是当作"harness 又暴露了一个缺陷"的信号。每次失败 → 定位层 → 修补 → 下次不再犯。几轮下来,你的 harness 会越来越强,agent 的表现会稳定提升。就像修路——每填一个坑,下一段路就更平坦。
-
-**量化改进。** 记个简单的日志:每个任务成功了没有,失败了是哪一层的问题。跑几轮之后你就能看出来哪个层是瓶颈,集中火力修那个层。
+再往后,建立诊断循环。不要把失败当成"模型又犯傻了",把它当作"harness 又暴露了一个缺陷"的信号。每次失败,定位到某一层,修补,下次不再犯。几轮下来,你的 harness 会越来越强,agent 的表现也会稳定提升。顺手记个简单的日志就行——每个任务成功了没有,失败了是哪一层的问题。跑几轮之后你就能看出来哪个层是瓶颈,集中火力修那个层。
## 一百万行代码的实验
-OpenAI 在 2025 年做了一个激进的实验:用 Codex 从一个空的 git 仓库起步,构建一个完整的内部产品。五个月后,这个仓库有大约 100 万行代码——应用逻辑、基础设施、工具、文档、内部开发工具——全部由 agent 生成。三个工程师驱动 Codex,开了大约 1,500 个 PR 并合并。平均每人每天 3.5 个 PR。
-
-这个实验的关键约束是:**人类永远不直接写代码。** 这不是噱头,而是为了逼团队搞清楚——当工程师的主要工作不再是写代码,而是设计环境、表达意图、构建反馈回路时,到底什么变了?
+2025 年,OpenAI 的三个工程师开始了一项实验。规则很简单:他们不写代码,只让 Codex 写。从一个空的 git 仓库起步,五个月下来,仓库里有了大约 100 万行代码。应用逻辑、基础设施、工具、文档——全是 agent 生成的。三个工程师一共开了 1,500 个 PR,平均每人每天 3.5 个。
-早期进展比预期慢。不是 Codex 不行,而是环境不够完整——agent 缺少必要的工具、抽象和内部结构来推进高层次目标。工程师的工作变成了:把大目标拆成小积木(设计、编码、审查、测试),让 agent 去搭建,然后用这些积木解锁更复杂的任务。当某件事失败了,修复几乎从来不是"更努力",而是"agent 缺什么能力,怎么让它既可理解又可执行"。
+起初的进展出乎意料地慢。Codex 并不差,但它缺少足够完整的工具和结构去推进那些高层次的目标。三个工程师慢慢摸到了门道:把大的目标拆成小的积木块——设计、编码、审查、测试——让 agent 逐个搭建,再用这些积木去组合更复杂的任务。每当某件事做砸了,问题几乎从来不是"不够努力",而是 agent 还缺什么——缺的能力能不能用一种既可理解又可执行的方式补上去。
-这个实验直接证明了本讲的核心论点:**同一个模型,在空白环境里和在有完整 harness 的环境里,产出有本质差异。** 模型没变,变的是环境。
+这个实验直接印证了本讲的核心论点:**同一个模型,在空白环境里和在有完整 harness 的环境里,产出有本质差异。** 模型没变,变的是环境。
> 来源:[OpenAI: Harness engineering: leveraging Codex in an agent-first world](https://openai.com/index/harness-engineering/)
@@ -94,11 +84,11 @@ OpenAI 在 2025 年做了一个激进的实验:用 Codex 从一个空的 git
## 带走什么
-- 模型能力和执行可靠性是两回事。千里马也得配上好马具。
-- 失败的时候先看 harness,再看模型。换模型是成本最高的选择——而且很多时候根本不是模型的问题。
+- 模型能力和执行可靠性是两回事,千里马也得配上好马具。
+- 失败的时候先看 harness,再看模型。换模型是成本最高的选择,而且很多时候根本不是模型的问题。
- 每次失败都是一个信号:你的 harness 有结构性缺陷。把它找出来、修掉。
-- 五层防御:任务规范、上下文供给、执行环境、验证反馈、状态管理。逐层排查,就像医生看病先检查最常见的病因。
-- 一个 `AGENTS.md` 文件可能比你换一个更贵的模型更有效。真的。
+- 遇到失败不要笼统地说"模型不行"。任务没交代清楚、上下文不够、环境没配好、验证手段缺失、上一个会话做到哪了新会话接不上,五个地方逐个排查,问题十有八九出在其中一层。
+- 一个 `AGENTS.md` 文件可能比你换一个更贵的模型更有效。
## 延伸阅读
diff --git a/docs/zh/lectures/lecture-02-what-a-harness-actually-is/index.md b/docs/zh/lectures/lecture-02-what-a-harness-actually-is/index.md
index 24ffcd7..5ea87f9 100644
--- a/docs/zh/lectures/lecture-02-what-a-harness-actually-is/index.md
+++ b/docs/zh/lectures/lecture-02-what-a-harness-actually-is/index.md
@@ -5,39 +5,39 @@
# 第二讲. Harness 到底是什么
-"harness"这个词在 AI coding agent 的圈子里被用得越来越多了,但说实话,大部分人说的 harness 其实就只是"一个 prompt 文件"。这不是 harness。就像你开了一家餐厅,只有食材——没有灶台、没有刀具、没有菜谱、没有出菜流程——那不叫餐厅,那叫冰箱。
+"harness"这个词在 AI coding agent 的圈子里被用得越来越多了,但大部分人说 harness 的时候,其实指的是一个 prompt 文件。一个 prompt 文件不是 harness。
-这节课要给你一个精确的、可操作的 harness 定义。不是学术论文里的抽象概念,而是你今天就能拿去用的框架:harness 由五个子系统组成,就像一个完整厨房里的五个功能区——菜谱架、刀具架、灶台、备菜台、和出菜检查口。每个子系统都有明确的职责和评判标准。
+这节课要给 harness 一个精确的、可操作的定义。不是学术论文里的抽象概念,而是你今天就能拿去用的框架。harness 由五个子系统组成:指令、工具、环境、状态、反馈。每个子系统都有明确的职责和评判标准。
## 先讲一个类比
想象你是一个刚入职的工程师,被丢进一个没有任何文档的项目里。没有 README,代码里没有注释,没有人告诉你怎么跑测试,CI 配置文件藏在某个角落里。你能写出好代码吗?也许能——如果你足够聪明又足够有耐心。但你会花大量时间在"搞清楚这个项目是怎么回事"上,而不是在"解决问题"上。
-AI agent 面对的困境一模一样。而且更糟——你至少可以问同事,agent 只能看到你放在它面前的文件和它能执行的命令。它不能拍拍同事的肩膀问"哎,这个项目的 ORM 用的是哪个版本?"
+AI agent 面对的困境一模一样,甚至更糟。你至少可以问同事,agent 只能看到你放在它面前的文件和它能执行的命令。
-OpenAI 在他们的 harness engineering 文章里把 harness 的核心原则表述为"仓库即规范"——所有必要的上下文都应该在仓库里,通过结构化的指令文件、明确的验证命令和清晰的目录组织来呈现。Anthropic 的 long-running agents 文档则更侧重状态持久化、显式恢复路径和结构化的进度跟踪。两家公司的侧重点不同,但都在说同一件事:**模型之外的一切工程基础设施,决定了模型能力能被发挥多少。**
+OpenAI 在他们的 harness engineering 文章里把 harness 的核心原则表述为"仓库即规范",所有必要的上下文都应该在仓库里,通过结构化的指令文件、明确的验证命令和清晰的目录组织来呈现。Anthropic 的 long-running agents 文档则更侧重状态持久化、显式恢复路径和结构化的进度跟踪。两家公司的侧重点不同,但说的是同一件事:**模型之外的一切工程基础设施,决定了模型能力能被发挥多少。**
看看几个你熟悉的工具:
-**Claude Code** 的设计就体现了 harness 思想。它会读你仓库里的 `CLAUDE.md`(菜谱架),能用 shell 跑命令(刀具架),在你的本地环境里执行(灶台),有会话历史(备菜台),能跑测试看结果(出菜检查口)。但如果你不告诉它怎么跑测试,出菜检查口就是断的——菜做没做熟谁也不知道。
+**Claude Code** 的设计就体现了 harness 思想。它会读你仓库里的 `CLAUDE.md`,能用 shell 跑命令,在你的本地环境里执行,有会话历史,能跑测试看结果。但如果你不告诉它怎么跑测试,它就没法验证自己做得对不对。
-**Cursor** 也是类似的逻辑。它的 `.cursorrules` 文件是菜谱架,终端是刀具架,它能读你的项目结构和 lint 配置是灶台。但 Cursor 的状态管理相对弱——你关掉 IDE 再打开,上次的上下文就没了。
+**Cursor** 也是类似的逻辑。`.cursorrules` 文件是它的指令来源,终端是它的工具,它能读你的项目结构和 lint 配置。不过 Cursor 的状态管理相对弱,你关掉 IDE 再打开,上次的上下文就没了。
**Codex**(OpenAI 的 coding agent)用 git worktree 隔离每个任务的运行环境,配合本地的可观测性栈(日志、指标、追踪),让每个变更都在独立的环境中验证。它在有 `AGENTS.md` 和清晰验证命令的仓库里,表现远超在"裸"仓库里。
-**AutoGPT** 则是反面教材——缺乏结构化的状态管理导致长任务中上下文不断累积,缺乏精确的反馈机制导致 agent 陷入循环。很多人说 AutoGPT "不行",但其实是它的 harness 不行——你给它一个破灶台,再好的食材也做不出菜来。
+**AutoGPT** 则是反面教材。缺乏结构化的状态管理导致长任务中上下文不断累积,缺乏精确的反馈机制导致 agent 陷入循环。很多人说 AutoGPT "不行",但其实是它的 harness 不行。
## 核心概念
- **什么是 harness**:模型权重之外的一切工程基础设施。OpenAI 把工程师的核心工作概括为三件事:设计环境、表达意图、构建反馈循环。Anthropic 直接把 Claude Agent SDK 称为"通用 agent harness"。
-- **仓库是唯一事实来源**:agent 看不到的东西,对它来说就不存在。OpenAI 把仓库当作"记录系统"——所有必要的上下文都必须在仓库里,通过结构化的文件和清晰的目录组织来呈现。
-- **给地图,不给说明书**:OpenAI 的经验——`AGENTS.md` 应该是目录页,不是百科全书。100 行左右就够了,放不下就拆分到 `docs/` 目录里,让 agent 按需去读。
+- **仓库是唯一事实来源**:agent 看不到的东西,对它来说就不存在。OpenAI 把仓库当作"记录系统",所有必要的上下文都必须在仓库里,通过结构化的文件和清晰的目录组织来呈现。
+- **给地图,不给说明书**:OpenAI 的经验是 `AGENTS.md` 应该是目录页,不是百科全书。100 行左右就够了,放不下就拆分到 `docs/` 目录里,让 agent 按需去读。
- **约束而非微操**:好的 harness 用可执行的规则来约束 agent,而不是在指令里逐条叮嘱。OpenAI 说"执行不变量,不要微管实现";Anthropic 发现 agent 会自信地夸赞自己的工作,解决方案是把"干活的人"和"检查的人"分开。
- **逐个组件拆除法**:想量化 harness 各组件的边际贡献,就逐个移除,看哪个移除后性能下降最多。它能告诉你哪些组件当前最有价值,也能暴露哪些组件暂时贡献不明显。Anthropic 用这个方法发现:随着模型变强,某些组件不再关键,但总会有新的关键组件出现。
## Harness 五子系统模型
-回到厨房的类比。一个完整的厨房有五个功能区,harness 也有五个子系统:
+回到类比。harness 有五个子系统:
```mermaid
flowchart LR
@@ -49,15 +49,15 @@ flowchart LR
Checks --> Agent
```
-**指令子系统(菜谱架)**:创建 `AGENTS.md`(或 `CLAUDE.md`),内容包括项目概览和目的(一句话说清楚这是什么)、技术栈和版本(Python 3.11、FastAPI 0.100+、PostgreSQL 15)、首次运行命令(`make setup`、`make test`)、不可违反的硬约束("所有 API 必须走 OAuth 2.0")、指向更详细文档的链接。
+**指令子系统**:创建 `AGENTS.md`(或 `CLAUDE.md`),内容包括项目概览和目的、技术栈和版本、首次运行命令、不可违反的硬约束、指向更详细文档的链接。
-**工具子系统(刀具架)**:确保 agent 有足够的工具访问权限。不要因为"安全考虑"把 shell 给禁了——agent 连 `pip install` 都跑不了,还怎么干活?但也别什么都开放,按最小权限原则来。
+**工具子系统**:确保 agent 有足够的工具访问权限。不要因为"安全考虑"把 shell 给禁了,agent 连 `pip install` 都跑不了,还怎么干活?但也别什么都开放,按最小权限原则来。
-**环境子系统(灶台)**:让环境状态自描述。用 `pyproject.toml` 或 `package.json` 锁定依赖,用 `.nvmrc` 或 `.python-version` 指定运行时版本,用 Docker 或 devcontainer 让环境可重现。
+**环境子系统**:让环境状态自描述。用 `pyproject.toml` 或 `package.json` 锁定依赖,用 `.nvmrc` 或 `.python-version` 指定运行时版本,用 Docker 或 devcontainer 让环境可重现。
-**状态子系统(备菜台)**:长任务必须有进度跟踪。用一个简单的 `PROGRESS.md` 文件记录:哪些做完了,哪些在做,哪些被阻塞。每个会话结束前更新,下一个会话开始时读取。
+**状态子系统**:长任务必须有进度跟踪。用一个简单的 `PROGRESS.md` 文件记录:哪些做完了,哪些在做,哪些被阻塞。每个会话结束前更新,下一个会话开始时读取。
-**反馈子系统(出菜检查口)**:这是投入产出比最高的子系统。在 `AGENTS.md` 里显式列出验证命令:
+**反馈子系统**:这是投入产出比最高的子系统。在 `AGENTS.md` 里显式列出验证命令:
```
验证命令:
- 测试:pytest tests/ -x
@@ -66,31 +66,31 @@ flowchart LR
- 完整验证:make check(包含以上全部)
```
-五个子系统缺一个,就像厨房里少了一个功能区——菜还是能做,但总是别扭。
+五个子系统缺一个,harness 就不完整,agent 用起来总会别扭。
**量化 harness 组件价值的方法**:用"等模型对照下的组件拆除实验"。保持模型不变,逐个移除五个子系统,看哪个子系统缺失时性能下降最多。下降最多的组件,说明它在当前任务里边际贡献最大,值得优先保留;是否要加强它,取决于失败归因,而不是只看下降幅度。几乎没有影响的组件,也不能直接判定为无用:它可能是冗余、设计失效,或还没有被这个任务充分触发。这个实验回答的是"当前哪个组件最有价值",不能单独证明"瓶颈在哪里"。真正定位瓶颈,要先看失败记录和归因:任务没说清楚、上下文不足、环境不可复现、验证反馈缺失,还是状态管理断裂;组件拆除结果只能作为辅助证据。
## 一个团队的真实经历
-一个团队用 GPT-4o 开发一个 TypeScript + React 前端应用(约 20,000 行代码)。他们经历了四个阶段——其实就是在一件一件地添置厨具:
+一个团队用 GPT-4o 开发一个 TypeScript + React 前端应用(约 20,000 行代码)。他们经历了四个阶段,其实就是在一件一件地添置 harness 的组件:
-**阶段 1——空厨房**:只有 README 里的基本项目描述。5 次运行成功 1 次(20%)。主要失败:选错了包管理器(npm vs yarn)、没遵循组件命名约定、跑不了测试。
+**阶段 1**:只有 README 里的基本项目描述。5 次运行成功 1 次(20%)。主要失败:选错了包管理器(npm vs yarn)、没遵循组件命名约定、跑不了测试。
-**阶段 2——装上菜谱架**:添加 `AGENTS.md`,写明技术栈版本、命名约定、关键架构决策。成功率升到 60%。剩余失败主要来自环境问题和验证缺失。
+**阶段 2**:添加 `AGENTS.md`,写明技术栈版本、命名约定、关键架构决策。成功率升到 60%。剩余失败主要来自环境问题和验证缺失。
-**阶段 3——开起出菜检查口**:在 `AGENTS.md` 里列出验证命令 `yarn test && yarn lint && yarn build`。成功率升到 80%。
+**阶段 3**:在 `AGENTS.md` 里列出验证命令 `yarn test && yarn lint && yarn build`。成功率升到 80%。
-**阶段 4——备菜台就位**:引入进度文件模板,agent 在每次运行中记录完成和未完成的工作。成功率稳定在 80-100%。
+**阶段 4**:引入进度文件模板,agent 在每次运行中记录完成和未完成的工作。成功率稳定在 80-100%。
-四次迭代,模型一个字没改,成功率从 20% 到接近 100%。这就是 harness 工程的力量。你没有换更贵的食材,你只是把厨房收拾利索了。
+四次迭代,模型一个字没改,成功率从 20% 到接近 100%。你没有换更好的模型,变的只是 harness。
## 关键要点
-- Harness = 指令 + 工具 + 环境 + 状态 + 反馈。五个子系统,就像厨房的五个功能区,缺一不可。
-- 不是模型权重的部分全是 harness。你的 harness 决定了模型能力能被发挥多少。
-- 五个子系统中,反馈子系统通常是投入最少、回报最高的。先把验证命令写清楚——出菜检查口是最值得先装的。
+- Harness = 指令 + 工具 + 环境 + 状态 + 反馈,五个子系统缺一不可。
+- 不是模型权重的部分全是 harness,你的 harness 决定了模型能力能被发挥多少。
+- 五个子系统中,反馈子系统通常是投入最少、回报最高的。先把验证命令写清楚。
- 用"等模型对照下的组件拆除实验"量化各子系统的边际贡献;定位真正瓶颈要靠失败记录和归因,不能只靠拆除实验。
-- Harness 和代码一样会腐化。定期审计,像还技术债一样还 harness 债。
+- Harness 和代码一样会腐化,定期审计,像还技术债一样还 harness 债。
## 延伸阅读
diff --git a/docs/zh/lectures/lecture-03-why-the-repository-must-become-the-system-of-record/index.md b/docs/zh/lectures/lecture-03-why-the-repository-must-become-the-system-of-record/index.md
index 7628177..e9d1889 100644
--- a/docs/zh/lectures/lecture-03-why-the-repository-must-become-the-system-of-record/index.md
+++ b/docs/zh/lectures/lecture-03-why-the-repository-must-become-the-system-of-record/index.md
@@ -5,21 +5,21 @@
# 第三讲. 让代码仓库成为唯一的事实来源
-你团队的架构决策散落在 Confluence、Slack、Jira、和几个资深工程师的脑子里。对人类来说这勉强够用——你可以问同事、搜聊天记录、翻文档。实在不行还能去茶水间堵人。但对 AI agent 来说,不在仓库里的信息等于不存在。
+你团队的架构决策散落在 Confluence、Slack、Jira、和几个资深工程师的脑子里。对人类来说这勉强够用,你可以问同事、搜聊天记录、翻文档,实在不行还能去茶水间堵人。但对 AI agent 来说,不在仓库里的信息等于不存在。
-这不是夸张。想想 agent 的输入都有什么:系统提示和任务描述、仓库里的文件内容、以及工具执行的输出。就这三样。你的 Slack 历史、Jira 工单、Confluence 页面、和周五下午跟同事在茶水间聊的架构决定——agent 全都看不到。它不能"去问一下",也不能"搜一下聊天记录"。它就是一个被关在仓库里的工程师——仓库外面的事,它一概不知。
+这不是夸张。Agent 的输入只有三样东西:系统提示和任务描述、仓库里的文件内容、工具执行的输出。你的 Slack 历史、Jira 工单、Confluence 页面、和周五下午跟同事聊的架构决定,agent 全都看不到。它不能"去问一下",也不能"搜一下聊天记录"。它的整个工作世界就是仓库本身,仓库外面的事它一概不知。
-所以问题变成了:你给不给这个工程师一张好地图?
+所以问题变成了:你给不给它一张足够好的地图?
## 地图上该画什么
-OpenAI 在他们的 harness engineering 文章里把这个问题说得非常直白:**仓库里不存在的信息,对 agent 来说等于不存在。** 他们把这称为"仓库即规范"原则——仓库本身就是最高权威的规范文档。
+OpenAI 在他们的 harness engineering 文章里把这个问题说得非常直白:**仓库里不存在的信息,对 agent 来说等于不存在。** 他们把这称为"仓库即规范"原则,即仓库本身就是最高权威的规范文档。
-Anthropic 的 long-running agents 文档也强调了类似的观点:持久化状态是长任务连续性的必要条件。跨会话的知识可恢复性直接决定了任务成功率。而这些状态必须存在于仓库中——因为那是 agent 唯一稳定可访问的存储。
+Anthropic 的 long-running agents 文档也强调了类似的观点:持久化状态是长任务连续性的必要条件,跨会话的知识可恢复性直接决定了任务成功率。而这些状态必须存在于仓库中,因为那是 agent 唯一稳定可访问的存储。
你可能会想:"我们团队人少,知识都在大家脑子里,这不也工作得好好的吗?"没错,对人类来说确实可以。但你要用 agent,就得接受一个事实:agent 不能问人。所有它需要知道的东西,都必须写下来,放在它能找到的地方。
-这不是"写更多文档"的问题。这是"把决策信息放到正确的位置"的问题。一份在 `src/api/` 目录下、50 行的 `ARCHITECTURE.md`,比一份在 Confluence 里、500 页但没人维护的设计文档有用一万倍。就好比一张贴在你工位上的、手画的办公室走法图,比一份精美的、放在档案室里的建筑蓝图实用得多——因为前者在你需要的时候就在手边。
+这不是"写更多文档"的问题,而是"把决策信息放到正确的位置"的问题。一份在 `src/api/` 目录下、50 行的 `ARCHITECTURE.md`,比一份在 Confluence 里、500 页但没人维护的设计文档有用得多。就近放置的价值远大于篇幅长短,因为信息只有在你需要的时候就在手边,才能真正发挥作用。
## 知识可见性
@@ -34,7 +34,7 @@ flowchart LR
Warning["规则不写进仓库<br/>agent 就看不见"] --> Agent
```
-怎么检验你的地图画得够不够好?做一个"冷启动测试":开一个全新的 agent 会话,只看仓库内容,看它能不能回答五个基本问题:
+怎么检验你的地图画得够不够好?做一个"冷启动测试":开一个全新的 agent 会话,只让它看仓库内容,看它能不能回答五个基本问题。
```mermaid
flowchart TB
@@ -51,24 +51,24 @@ flowchart TB
A5 --> Ready
```
-如果它答不上来,说明地图上有空白。空白的地方,agent 就得自己猜——猜错了就是 bug,猜多了就浪费上下文。每个新会话都要猜一遍,猜的成本远高于一开始就把地图画好的成本。
+如果它答不上来,说明地图上有空白。空白的地方,agent 就得自己猜,猜错了就是 bug,猜多了就浪费上下文。每个新会话都要猜一遍,猜的成本远高于一开始就把地图画好。
## 核心概念
-- **知识可见性缺口**:项目总知识中不在仓库里的比例。缺口越大,agent 失败的概率越高。你脑子里有多少关于这个项目的隐性知识?把它们全算上,再看有多少写进了仓库——两者的差距就是你的可见性缺口。
-- **系统记录(System of Record)**:代码仓库作为项目决策、架构约束、执行状态和验证标准的权威信息源。仓库说了算,别的地方说了不算。就像地图上标注了"此路不通",你就不会再往那条路走——但如果这个信息只在老张的脑子里,你每次都得问老张。
+- **知识可见性缺口**:项目总知识中不在仓库里的比例。缺口越大,agent 失败的概率越高。你可以这样估算:把脑子里关于这个项目的隐性知识全算上,再看有多少写进了仓库,两者的差距就是可见性缺口。
+- **系统记录(System of Record)**:代码仓库作为项目决策、架构约束、执行状态和验证标准的权威信息源。仓库说了算,别的地方说了不算。如果"此路不通"这个信息只在老张的脑子里,那每次都得问老张。写进仓库,谁都不用问。
- **冷启动测试**:上一节说的五个问题。能回答几个,你的地图就画了几分。
-- **发现成本**:agent 为了在仓库里找到一条关键信息需要消耗多少上下文。信息放得越隐蔽,发现成本越高,留给实际任务的预算越少。把关键信息藏在十层目录深处的 README 里,就像把灭火器锁在地下室的保险柜里——不是没有,是用的时候找不到。
-- **知识衰减率**:仓库中单位时间内变得过时的知识条目比例。文档和代码脱节是最大的敌人——比没有文档更危险的是过时的文档。
+- **发现成本**:agent 为了在仓库里找到一条关键信息需要消耗多少上下文。信息放得越隐蔽,发现成本越高,留给实际任务的预算越少。关键信息应该放在 agent 最先看到的位置,而不是藏在十层目录深处。
+- **知识衰减率**:仓库中单位时间内变得过时的知识条目比例。文档和代码脱节是最大的敌人,比没有文档更危险的是过时的文档。
- **ACID 类比**:把数据库的事务管理原则(原子性、一致性、隔离性、持久性)用到 agent 的状态管理上。后面会展开讲。
## 怎么画好这张地图
-**原则 1:知识靠近代码。** 一条关于 API 端点认证的规则,应该放在 API 代码旁边,而不是藏在一个巨大的全局文档里。每个模块目录下放一个简短的文档,说清楚这个模块的职责、接口和特殊约束。就像图书馆的书架标签——你想找历史类书籍,直接去标着"历史"的书架,不用把整个图书馆翻一遍。
+**原则 1:知识靠近代码。** 一条关于 API 端点认证的规则,应该放在 API 代码旁边,而不是藏在一个巨大的全局文档里。每个模块目录下放一个简短的文档,说清楚这个模块的职责、接口和特殊约束。模块目录本身就是天然的索引,agent 读到代码就能读到约束,不用到处翻找。
**原则 2:用标准化的入口文件。** `AGENTS.md`(或 `CLAUDE.md`)是 agent 的"着陆页"。它不需要包含所有信息,但必须能让 agent 快速回答"这是什么项目"、"怎么跑"、"怎么验证"这三个问题。50-100 行就够了。
-**原则 3:最小但完备。** 每条知识都应该有明确的使用场景。如果你删掉某条规则不影响 agent 的决策质量,那这条规则就不应该存在。但冷启动测试中的每个问题都必须有答案。这是一个精妙的平衡——不多不少,刚好够用。
+**原则 3:最小但完备。** 每条知识都应该有明确的使用场景。如果你删掉某条规则不影响 agent 的决策质量,那这条规则就不应该存在。但冷启动测试中的每个问题都必须有答案。这是一个需要持续调整的平衡,不多不少,刚好够用。
**原则 4:和代码一起更新。** 把知识更新跟代码变更绑定在一起。最简单的方法:把架构文档放在对应的模块目录里。改代码的时候自然会看到文档,改代码之后 CI 提醒你检查文档是否需要更新。
@@ -91,18 +91,18 @@ project/
## 用 ACID 原则管理 agent 状态
-这个类比来自数据库的事务管理——你可能觉得这是在把简单的事情搞复杂,但实际上它给了你一个非常实用的框架:
+这个类比来自数据库的事务管理。你可能会觉得这是在把简单的事情搞复杂,但它确实提供了一个非常实用的框架:
- **原子性**:每次"逻辑操作"(比如"添加新端点并更新测试")用一个 git commit 原子化。中途挂了就 `git stash` 回滚。要么全做,要么不做,没有"做了一半"。
-- **一致性**:定义"一致状态"的验证谓词——所有测试通过、lint 无报错。Agent 每次操作后跑验证,不一致的中间状态不要 commit。就像银行转账——你不能只扣款不入账。
-- **隔离性**:多个 agent 并发工作时,状态文件要避免竞争条件。简单方案:每个 agent 用独立的进度文件,或者用 git 分支隔离。两个厨师不能同时往同一口锅里放盐——放重了谁负责?
+- **一致性**:定义"一致状态"的验证谓词,比如所有测试通过、lint 无报错。Agent 每次操作后跑验证,不一致的中间状态不要 commit。操作完系统应该处于可验证的正确状态。
+- **隔离性**:多个 agent 并发工作时,状态文件要避免竞争条件。简单方案:每个 agent 用独立的进度文件,或者用 git 分支隔离。并发写入同一文件是出问题的常见原因。
- **持久性**:关键的项目知识用 git 跟踪的文件持久化。临时状态可以只在会话内存里,但跨会话必须的知识必须写到文件里。脑子里的不算,写在纸上的才算。
## 一个真实的改造故事
一个团队维护一个包含约 30 个微服务的电商平台。架构决策(服务间通信协议、数据一致性策略、API 版本化规则)散落在:Confluence(部分过时)、Slack(难以搜索)、几个资深工程师的脑子里(不可扩展)、以及零星的代码注释(不系统)。
-引入 AI agent 后,70% 的任务需要人工干预。几乎每次失败都涉及 agent 违反了某个"所有人都知道但从未写入仓库"的隐性约束。这就像一个新来的员工,没人告诉他"中午点外卖要在群里接龙"——他自己猜,猜错了被骂,但骂完了还是没人告诉他规则。
+引入 AI agent 后,70% 的任务需要人工干预。几乎每次失败都涉及 agent 违反了某个"所有人都知道但从未写入仓库"的隐性约束。Agent 没有办法知道它不知道的事情,只能按自己的理解去做,结果就踩了坑。
团队执行了改造:
1. 仓库根目录创建 `AGENTS.md`,写明项目概览、技术栈版本、全局硬约束
@@ -114,11 +114,11 @@ project/
## 关键要点
-- 不在仓库里的知识对 agent 来说等于不存在。把关键决策信息放进仓库是最基本的 harness 投资——画好地图,才不会迷路。
+- 不在仓库里的知识对 agent 来说等于不存在。把关键决策信息放进仓库是最基本的 harness 投资,画好地图才不会迷路。
- 用"冷启动测试"检验仓库质量:全新会话能不能只看仓库回答五个基本问题。
- 知识要靠近代码、最小但完备、跟代码一起更新。不是写更多文档,是把信息放到正确的位置。
- 用 ACID 原则管理 agent 状态:原子提交、一致性验证、隔离并发、持久化关键知识。
-- 知识衰减是最大敌人。过时的文档比没有文档更危险——它会让 agent 走错方向还以为自己是对的。
+- 知识衰减是最大敌人。过时的文档比没有文档更危险,它会让 agent 走错方向还以为自己是对的。
## 延伸阅读
@@ -134,4 +134,4 @@ project/
2. **知识外置化量化**:列出你的项目中所有对开发工作重要的决策和约束。标注每个条目是在仓库内还是仓库外。算一下你的知识可见性缺口有多大(不在仓库里的占总数的比例)。制定计划把缺口降到 10% 以下。
-3. **ACID 准则评估**:用本讲的 ACID 类比评估你的项目状态管理。原子性——agent 的操作能不能干净地回滚?一致性——仓库有没有"一致状态"的验证?隔离性——多 agent 并发时会不会互相踩脚?持久性——跨会话的知识是不是都持久化了?
+3. **ACID 准则评估**:用本讲的 ACID 类比评估你的项目状态管理。原子性:agent 的操作能不能干净地回滚?一致性:仓库有没有"一致状态"的验证?隔离性:多 agent 并发时会不会互相踩脚?持久性:跨会话的知识是不是都持久化了?
diff --git a/docs/zh/lectures/lecture-04-why-one-giant-instruction-file-fails/index.md b/docs/zh/lectures/lecture-04-why-one-giant-instruction-file-fails/index.md
index af859ac..8df07c6 100644
--- a/docs/zh/lectures/lecture-04-why-one-giant-instruction-file-fails/index.md
+++ b/docs/zh/lectures/lecture-04-why-one-giant-instruction-file-fails/index.md
@@ -5,34 +5,34 @@
# 第四讲. 把指令拆分到不同文件里
-你开始认真对待 harness 了——好事。你建了个 `AGENTS.md`,把你能想到的所有规则、约束、历史教训都塞了进去。一个月后这个文件膨胀到了 300 行,两个月 450 行,三个月 600 行。然后你发现 agent 的表现反而变差了——改一个小 bug,agent 花大量上下文处理无关的部署指令;关键的安全约束埋在第 300 行,被直接忽略了;文件里有三条互相矛盾的代码风格规则,agent 每次随机选一条。
+你开始认真对待 harness 了,这很好。你建了个 `AGENTS.md`,把能想到的所有规则、约束、历史教训都塞了进去。一个月后这个文件膨胀到了 300 行,两个月 450 行,三个月 600 行。然后你发现 agent 的表现反而变差了:改一个小 bug,agent 花大量上下文处理无关的部署指令;关键的安全约束埋在第 300 行,被直接忽略了;文件里有三条互相矛盾的代码风格规则,agent 每次随机选一条。
-这就是"巨型指令文件"陷阱。就像你往行李箱里塞东西——觉得什么都有用,什么都往里装,结果拉链快崩了,想找换洗内衣得把整个箱子翻一遍。带了一箱子东西,但真正用上的可能只有三分之一。
+这就是"巨型指令文件"陷阱。觉得什么都有用,什么都往里装,结果想找一条具体规则得把整个文件翻一遍。写了 600 行,但真正跟当前任务相关的可能只有三分之一。
## 问题的根源:一个恶性循环
-最常见的恶性循环是这样的:agent 犯了个错 → 你说"加条规则防止这个" → 加到 AGENTS.md → 暂时管用 → agent 又犯了另一个错 → 再加一条 → 重复 → 文件膨胀到不可控。
+最常见的恶性循环是这样的:agent 犯了个错,你说"加条规则防止这个",加到 AGENTS.md,暂时管用。然后 agent 又犯了另一个错,再加一条。重复下去,文件膨胀到不可控。
-这不是你的错。这是一个非常自然的反应——每次出问题就"加条规则"感觉很合理,就像每次出门忘带东西就往包里多塞一样。但累积效应是灾难性的。让我们看看具体出了什么问题。
+这其实是很自然的反应,每次出问题就"加条规则"感觉很合理。但累积效应是灾难性的。让我们看看具体出了什么问题。
-**上下文预算被吃掉了。** Agent 的上下文窗口是有限的。假设你的 agent 有 200K tokens 的窗口(Claude 的标准),一个膨胀的指令文件可能占掉 10-20K。看起来还有不少余量?但一个复杂的任务可能需要读几十个源文件、工具执行的输出也占上下文、对话历史也在累积。到真正需要理解代码的时候,预算已经不够了——就像你的行李箱塞满了"万一用得着"的东西,结果放不下真正需要带的电脑了。
+**上下文预算被吃掉了。** Agent 的上下文窗口是有限的。假设你的 agent 有 200K tokens 的窗口(Claude 的标准),一个膨胀的指令文件可能占掉 10-20K。看起来还有不少余量?但一个复杂的任务可能需要读几十个源文件,工具执行的输出也占上下文,对话历史也在累积。到真正需要理解代码的时候,预算已经不够了。
-**中间迷失。** "Lost in the Middle"这篇论文(Liu et al., 2023)清楚地证明了:LLM 对长文本中间部分的信息利用效率显著低于两端。你的 AGENTS.md 有 600 行,第 300 行写的是"所有数据库查询必须用参数化查询"——这是安全硬约束。但它被埋在中间,agent 几乎一定会忽略它。就像你的行李箱里那瓶防晒霜——明明在最底层,但你翻三遍也找不到,最后又去买了一瓶。
+**中间迷失。** "Lost in the Middle"这篇论文(Liu et al., 2023)清楚地证明了:LLM 对长文本中间部分的信息利用效率显著低于两端。你的 AGENTS.md 有 600 行,第 300 行写的是"所有数据库查询必须用参数化查询",这是安全硬约束。但它被埋在中间,agent 几乎一定会忽略它。
-**优先级冲突。** 文件里混合了不可违反的硬约束("不得使用 eval()")、重要的设计指导("优先使用函数式风格")、和某个特定场景的历史教训("上周修了一个 WebSocket 内存泄漏,注意类似的模式")。这三条规则的重要性完全不同,但在文件里看起来一模一样。Agent 没有可靠的信号来区分——就像行李箱里护照和充电线混在一起,看不出哪个更紧急。
+**优先级冲突。** 文件里混合了不可违反的硬约束("不得使用 eval()")、重要的设计指导("优先使用函数式风格")、和某个特定场景的历史教训("上周修了一个 WebSocket 内存泄漏,注意类似的模式")。这三条规则的重要性完全不同,但在文件里看起来一模一样。Agent 没有可靠的信号来区分哪个是红线,哪个只是建议。
-**维护衰减。** 大文件天生难维护。指令过时了没人删——因为删除的后果不确定("也许别的地方依赖这条规则?"),但加新指令是无成本的。结果文件只增不减,信噪比持续下降。这和软件里的技术债务积累一模一样。
+**维护衰减。** 大文件天生难维护。指令过时了没人删,因为删除的后果不确定("也许别的地方依赖这条规则?"),但加新指令是无成本的。结果文件只增不减,信噪比持续下降。这和软件里的技术债务积累是同一个问题。
-**矛盾累积。** 不同时期加的指令之间开始出现矛盾——一条说"用 TypeScript 严格模式",另一条说"某些遗留文件允许用 any"。Agent 每次随机选一条遵循。就像你妈说"穿厚点",你爸说"别穿太多",你站在门口不知道听谁的。
+**矛盾累积。** 不同时期加的指令之间开始出现矛盾:一条说"用 TypeScript 严格模式",另一条说"某些遗留文件允许用 any"。Agent 每次随机选一条遵循。
## 核心概念
-- **指令膨胀**:当指令文件占用了超过上下文窗口 10-15% 的时候,它就开始挤占代码阅读和任务推理的预算。600 行的 `AGENTS.md` 可能占用 10,000-20,000 tokens——对 128K 的窗口来说,这就吃掉了 8-15%。
-- **中间迷失效应**:Liu 等人 2023 年的研究证明,LLM 对长文本中间部分的信息利用效率显著低于两端。埋在 600 行文件中间第 300 行的关键约束,被有效忽略的概率非常高。
-- **指令信噪比(SNR)**:文件中与当前任务相关的指令占总指令的比例。做 bug 修复时被要求读 50 行部署指令——SNR 很低。
-- **路由文件**:短小的入口文件,核心功能是引导 agent 去找更详细的文档,而不是自己包含所有内容。50-200 行就够了。
+- **指令膨胀**:指令文件一旦占到上下文窗口的 10-15%,就开始挤占代码阅读和任务推理的预算。一个 600 行的 `AGENTS.md` 可能占用 10,000-20,000 tokens,对 128K 的窗口来说就是 8-15%。
+- **中间迷失效应**:Liu 等人 2023 年的研究表明,LLM 对长文本中间部分的信息利用效率明显低于两端。埋在 600 行文件第 300 行的关键约束,被忽略的概率非常高。
+- **指令信噪比(SNR)**:文件中与当前任务相关的指令占总指令的比例。做 bug 修复时被要求读 50 行部署指令,SNR 就很低。
+- **路由文件**:短小的入口文件,作用是引导 agent 去找更详细的文档,而不是自己包含所有内容。50-200 行就够了。
- **渐进式披露**:先给概要信息,需要的时候再给详细信息。好的 harness 设计和好的 UI 设计一样,不把所有选项一次性砸到用户脸上。
-- **优先级模糊度**:当所有指令以相同格式和位置呈现时,agent 分不清哪些是不可违反的硬约束,哪些是建议性的软约束。
+- **优先级模糊度**:当所有指令以相同格式和位置呈现时,agent 分不清哪些是不可违反的硬约束,哪些只是建议性的软约束。
## 指令文件架构
@@ -59,7 +59,7 @@ flowchart TB
核心原则:常用信息放手边,偶尔用的收起来,用不上的别带。
-入口文件 `AGENTS.md` 控制在 50-200 行,只放最常用的东西——项目概览(一两句话说清楚这是什么)、首次运行命令(`make setup && make test`)、全局硬约束(不超过 15 条不可违反的规则)、指向专题文档的链接(一行描述 + 适用条件)。
+入口文件 `AGENTS.md` 控制在 50-200 行,只放最常用的东西:项目概览(一两句话说清楚这是什么)、首次运行命令(`make setup && make test`)、全局硬约束(不超过 15 条不可违反的规则)、指向专题文档的链接(一行描述加适用条件)。
```markdown
# AGENTS.md
@@ -83,36 +83,36 @@ Python 3.11 FastAPI 后端,PostgreSQL 15 数据库。
- 测试标准 (`docs/testing-standards.md`) — 编写测试时参考
```
-每个专题文档 50-150 行,按主题放在 `docs/` 目录下或对应模块目录旁。Agent 只在需要时才去读。就像行李箱里的收纳袋——内衣一个袋,洗漱一个袋,充电器一个袋。找东西不用翻整个箱子。
+每个专题文档 50-150 行,按主题放在 `docs/` 目录下或对应模块目录旁。Agent 只在需要时才去读。用收纳袋整理行李的思路:内衣一个袋,洗漱一个袋,充电器一个袋,找东西不用翻整个箱子。
-还有些信息直接放在代码里更合适——类型定义、接口注释、配置文件里的说明。Agent 读代码的时候自然能看到,不用再在指令里重复一遍。
+还有些信息直接放在代码里更合适,比如类型定义、接口注释、配置文件里的说明。Agent 读代码的时候自然能看到,不用再在指令里重复一遍。
-每条指令都应该标明来源("为什么加这条规则?")、适用条件("这条规则在什么时候需要?")、过期条件("什么情况下可以删掉这条规则?")。定期审计,删掉过时的、冗余的、矛盾的条目。像管理代码依赖一样管理你的指令——用不上的依赖就该删掉,不然它们只会拖慢系统。
+每条指令都应该标明来源("为什么加这条规则?")、适用条件("这条规则在什么时候需要?")、过期条件("什么情况下可以删掉这条规则?")。定期审计,删掉过时的、冗余的、矛盾的条目。像管理代码依赖一样管理你的指令,用不上的依赖就该删掉,不然它们只会拖慢系统。
-如果某条指令必须在入口文件里,放顶部或底部——不要放中间。"中间迷失"效应告诉我们,LLM 对长文本中间部分的信息利用效率显著低于两端。但更好的做法是把指令放到专题文档里,让 agent 按需加载。
+如果某条指令必须在入口文件里,放顶部或底部,不要放中间。"中间迷失"效应告诉我们,LLM 对长文本中间部分的信息利用效率显著低于两端。但更好的做法是把指令放到专题文档里,让 agent 按需加载。
-OpenAI 和 Anthropic 都隐性支持拆分的做法。OpenAI 说入口文件应"短小且以路由为导向",Anthropic 说长运行 agent 的控制信息应"简洁且高优先级"。两家都在说同一件事:别把什么都塞进一个文件里。行李箱得整理,不能只靠蛮力塞。
+OpenAI 和 Anthropic 都隐性支持拆分的做法。OpenAI 说入口文件应"短小且以路由为导向",Anthropic 说长运行 agent 的控制信息应"简洁且高优先级"。两家都在说同一件事:别把什么都塞进一个文件里。
## 实际案例
-一个 SaaS 团队的 `AGENTS.md` 从最初的 50 行膨胀到 600 行。内容混合了技术栈版本、编码规范、历史 bug 修复笔记、API 使用说明、部署流程、和团队成员的个人偏好——整个行李箱塞得满满当当,拉链都快崩了。
+一个 SaaS 团队的 `AGENTS.md` 从最初的 50 行膨胀到 600 行。内容混合了技术栈版本、编码规范、历史 bug 修复笔记、API 使用说明、部署流程、和团队成员的个人偏好,什么都有,但很难快速找到跟当前任务相关的部分。
Agent 表现开始明显下降:简单 bug 修复任务中 agent 花大量上下文处理无关的部署指令;安全约束"所有数据库查询必须用参数化查询"埋在第 300 行,经常被忽略;三条矛盾的代码风格规则导致 agent 随机选择。
-团队执行了"行李箱整理":
+团队做了一次拆分重构:
1. `AGENTS.md` 裁剪到 80 行:只保留项目概览、运行命令、15 条全局硬约束
2. 创建专题文档:`docs/api-patterns.md`(120 行)、`docs/database-rules.md`(60 行)、`docs/testing-standards.md`(80 行)
3. 路由文件添加指向专题文档的链接
4. 历史笔记要么转成测试用例,要么删除
-重构后:同一任务集的成功率从 45% 提升到 72%。安全约束遵循率从 60% 提升到 95%——因为从文件中间移到了路由文件顶部,不再被"中间迷失"了。
+重构后:同一任务集的成功率从 45% 提升到 72%。安全约束遵循率从 60% 提升到 95%,因为规则从文件中间移到了路由文件顶部,不再被"中间迷失"了。
## 关键要点
-- "加条规则"是短期的止痛药,长期的毒药。每次加规则前想想:这条规则放专题文档是不是更合适?——别什么都往行李箱里塞。
-- 入口文件是路由器,不是百科全书。50-200 行,只放概览、硬约束、和链接。
+- "加条规则"是短期的止痛药,长期的毒药。每次加规则前想想,这条规则放专题文档是不是更合适。
+- 入口文件是路由器,不是百科全书。50-200 行,只放概览、硬约束和链接。
- 利用"中间迷失"效应:重要信息放文件顶部或底部,不重要的移到专题文档。
-- 像管理技术债一样管理指令膨胀。定期审计,每条指令要有来源、适用条件、和过期条件。
+- 像管理技术债一样管理指令膨胀。定期审计,每条指令要有来源、适用条件和过期条件。
- 拆分之后信噪比提升,agent 把更多上下文预算花在实际任务上,而不是处理无关指令。
## 延伸阅读
diff --git a/docs/zh/lectures/lecture-05-why-long-running-tasks-lose-continuity/index.md b/docs/zh/lectures/lecture-05-why-long-running-tasks-lose-continuity/index.md
index 537d7e4..d4f9388 100644
--- a/docs/zh/lectures/lecture-05-why-long-running-tasks-lose-continuity/index.md
+++ b/docs/zh/lectures/lecture-05-why-long-running-tasks-lose-continuity/index.md
@@ -7,21 +7,19 @@
你让 Claude Code 帮你实现一个完整的功能,它跑了 30 分钟,做了大部分工作,但上下文快满了。你开个新会话继续,然后发现:它不记得上次做了什么决策、为什么选了方案 A 而不是方案 B、哪些文件已经改过、测试跑到什么状态了。它得花 15 分钟重新探索一遍项目,而且可能跟上次的做法不一致。
-想象一下,如果你是一个工匠,每天早上醒来都不记得昨天干了什么。你得重新认识整个工地——哪面墙砌了一半、为什么用的是红砖而不是青砖、水电管道走到哪了。更糟的是,你可能会把昨天已经装好的窗户拆了重来,因为你不记得它已经装过了。
-
-这就是 AI coding agent 在跨会话任务中面对的困境。本节课讲为什么 agent 会"断片",以及如何通过结构化的状态持久化让它像一个每天坚持写日记的工匠——虽然还是会失忆,但日记本里记着一切。
+这是 AI coding agent 在跨会话任务中面对的真实困境。本节课讲为什么 agent 会"断片",以及如何通过结构化的状态持久化,让新会话能快速接上上次的工作。
## 上下文窗口:不是无限的
-上下文窗口是有限的。这不是一个可以通过模型升级解决的问题——即使窗口大小增长到 1M tokens,复杂任务依然会用完。因为 agent 不只是在生成代码,它还要理解代码库、跟踪自己的决策历史、处理工具输出、维护对话上下文。这些信息加起来增长得比窗口扩容快得多。
+上下文窗口是有限的。这不是一个可以通过模型升级解决的问题,即使窗口大小增长到 1M tokens,复杂任务依然会用完。因为 agent 不只是在生成代码,它还要理解代码库、跟踪自己的决策历史、处理工具输出、维护对话上下文。这些信息加起来增长得比窗口扩容快得多。
-更深层的问题:agent 产生的信息不是均匀重要的。中间推理步骤包含决策的"为什么"——为什么选了方案 A 而不是方案 B,为什么用了这个库而不是那个库,为什么跳过了某个优化。最终输出只包含"是什么"——代码本身。压缩策略通常保留后者但丢了前者。下一个会话看到代码但不知道为什么这么写,可能会"优化"掉一个有意为之的设计决策。
+更深层的问题在于,agent 产生的信息不是均匀重要的。中间推理步骤包含决策的"为什么",比如为什么选了方案 A 而不是方案 B,为什么用了这个库而不是那个库,为什么跳过了某个优化。最终输出只包含"是什么",即代码本身。压缩策略通常保留后者但丢了前者。下一个会话看到代码却不知道为什么这么写,可能会"优化"掉一个有意为之的设计决策。
-Anthropic 在他们的长运行 agent 研究中发现了一个很有意思的现象:当 agent 感觉上下文快满了,它们会表现出一种"过早收敛"的行为——匆忙结束当前工作,跳过验证步骤,或者选一个简单的方案而不是最优方案。这就像你考试时发现时间快到了,赶紧随便选几个选择题一样。Anthropic 把这叫"上下文焦虑"。
+Anthropic 在长运行 agent 研究中观察到一个有意思的现象:当 agent 感觉上下文快满了,它们会表现出"过早收敛"的行为,匆忙结束当前工作,跳过验证步骤,或者选一个简单的方案而不是最优方案。Anthropic 把这叫"上下文焦虑"。
## 会话连续性流程
-没有连续性工件的时候,每个新会话都是一场灾难:
+没有连续性工件的时候,每个新会话都要重新摸索:
```mermaid
flowchart LR
@@ -50,30 +48,30 @@ flowchart LR
## 核心概念
-- **上下文窗口是有限的**:不管模型吹多大的窗口(128K、200K、1M),长任务总会用完。用完之后要么压缩(丢信息),要么重置(开新会话)。两种方式都会丢东西。
-- **连续性工件**:持久化的状态文件,让新会话能无歧义地恢复到上次离开的地方。最基本的形式:进度日志 + 验证记录 + 下一步行动。就是那个工匠的日记本。
+- **上下文窗口是有限的**:不管模型宣称多大的窗口(128K、200K、1M),长任务总会用完。用完之后要么压缩(丢信息),要么重置(开新会话),两种方式都会丢东西。
+- **连续性工件**:持久化的状态文件,让新会话能无歧义地恢复到上次离开的地方。最基本的形式包括进度日志、验证记录和下一步行动。
- **重建成本**:新会话恢复到可执行状态所需的时间。好的 harness 能把重建成本从 15 分钟压到 3 分钟。
- **漂移(Drift)**:agent 的理解跟代码仓库实际状态之间的偏差。每次会话边界都会引入漂移,不加控制会越漂越远。
-- **上下文焦虑**:Anthropic 观察到的现象——agent 在接近上下文限制时表现异常,过早结束任务以避免信息丢失。是一种非理性的资源焦虑。
-- **压缩 vs 重置**:压缩是在同一个会话里把上下文摘要化(保留"是什么",可能丢了"为什么");重置是开新会话从持久化状态重建(干净但依赖工件完备性)。
+- **上下文焦虑**:Anthropic 观察到的现象,agent 在接近上下文限制时表现异常,过早结束任务以避免信息丢失,本质上是一种非理性的资源焦虑。
+- **压缩 vs 重置**:压缩是在同一个会话里把上下文摘要化,保留"是什么"但可能丢了"为什么";重置是开新会话从持久化状态重建,状态干净但依赖工件的完备性。
## 连续性断了以后会发生什么
-上个会话花了很多上下文预算分析了三种方案的优劣,最终选了方案 B。这个会话的 agent 不知道这个分析过程,可能基于不完整的信息重新做了决策——而且可能选了方案 A。就像那个失忆的工匠不记得为什么选了红砖,今天看着觉得青砖更好看,就把昨天的墙拆了重砌。
+上个会话花了很多上下文预算分析了三种方案的优劣,最终选了方案 B。这个会话的 agent 不知道这个分析过程,可能基于不完整的信息重新做了决策,而且可能选了方案 A。同样的信息,不同的结论,因为做决策的上下文丢了。
-更要命的是重复劳动。Agent 不确定某项工作是否已完成,重新做了一遍。或者更糟——做了一半发现跟已有的实现冲突,需要返工。工地上不能两拨人同时砌同一面墙——但在没有进度记录的情况下,新来的人完全不知道这面墙已经有人在砌了。
+更要命的是重复劳动。Agent 不确定某项工作是否已完成,重新做了一遍。或者更糟,做了一半发现跟已有的实现冲突,需要返工。在没有进度记录的情况下,新会话完全不知道哪些工作已经有人做过了。
-几个会话累积下来,实现方向可能已经悄悄偏离了原始需求。每个新会话对项目目标的理解都略有偏差,就像传话游戏——经过十个人传话,"帮我买杯咖啡"可能变成了"帮我买个咖啡机"。
+几个会话累积下来,实现方向可能已经悄悄偏离了原始需求。每个新会话对项目目标的理解都略有偏差,偏差一层层叠加,最终的结果可能跟最初的意图相去甚远。
还有验证缺口。上个会话的验证结果(哪些测试通过、哪些失败、为什么失败)没有记录,新会话得重新跑一遍验证才能了解当前状态。每次都重新诊断,每次都浪费宝贵的上下文。
-OpenAI 和 Anthropic 都在他们的文档里强调了结构化状态持久化的重要性。OpenAI 的 harness engineering 文章把仓库当作"操作记录"——每次操作的结果都应该在仓库里留下可追溯的痕迹。Anthropic 的 long-running agents 文档则更具体地建议使用"交接文件"——包含当前状态、已知问题和下一步行动的结构化文档。
+OpenAI 和 Anthropic 都在他们的文档里强调了结构化状态持久化的重要性。OpenAI 的 harness engineering 文章把仓库当作"操作记录",每次操作的结果都应该在仓库里留下可追溯的痕迹。Anthropic 的 long-running agents 文档则更具体地建议使用"交接文件",包含当前状态、已知问题和下一步行动的结构化文档。
-## 给失忆工匠的日记本
+## 状态持久化的实践方法
-核心思路:**把 agent 当成一个会失忆的超级工程师来管理。** 每次它要"下班"之前,必须把关键信息写下来,让下一个"接班"的 agent 能快速上手。
+核心思路:**把 agent 当成一个每次会话都会清空短期记忆的工程师来管理。** 每次它要"下班"之前,必须把关键信息写下来,让下一个"接班"的 agent 能快速上手。
-**工具 1:进度文件(PROGRESS.md)**。这是最基本的连续性工件——日记本的核心部分:
+**工具 1:进度文件(PROGRESS.md)**。这是最基本的连续性工件:
```markdown
# 项目进度
@@ -101,7 +99,7 @@ OpenAI 和 Anthropic 都在他们的文档里强调了结构化状态持久化
3. 更新 API 文档
```
-**工具 2:决策日志(DECISIONS.md)**。记录重要的设计决策和原因。不需要详细的设计文档,只需要"什么决策、为什么、什么时候做的"——这是日记本里的备忘:
+**工具 2:决策日志(DECISIONS.md)**。记录重要的设计决策和原因。不需要详细的设计文档,只需要"什么决策、为什么、什么时候做的":
```markdown
# 设计决策
@@ -112,34 +110,34 @@ OpenAI 和 Anthropic 都在他们的文档里强调了结构化状态持久化
- 约束: 缓存 TTL 设为 5 分钟,写入时主动失效
```
-**工具 3:git 提交作为检查点。** 每完成一个原子工作单元就提交。commit message 要说清楚做了什么和为什么。这是免费的、自动版本化的状态快照。
+**工具 3:git 提交作为检查点。** 每完成一个原子工作单元就提交,commit message 要说清楚做了什么和为什么。这是免费的、自动版本化的状态快照。
-**工具 4:init.sh 或 harness 的初始化流程。** 在 `AGENTS.md` 里写明每天"上班"和"下班"的流程:
+**工具 4:init.sh 或 harness 的初始化流程。** 在 `AGENTS.md` 里写明每次"上班"和"下班"的流程:
```markdown
-## 每次会话开始时(上班打卡)
+## 每次会话开始时(上班)
1. 读 PROGRESS.md 了解当前状态
2. 读 DECISIONS.md 了解重要决策
3. 跑 make check 确认仓库处于一致状态
4. 从 PROGRESS.md 的"下一步"部分继续工作
-## 每次会话结束前(下班打卡)
+## 每次会话结束前(下班)
1. 更新 PROGRESS.md
2. 跑 make check 确认一致状态
3. 提交所有已完成的工作
```
-**混合策略**:不需要每次都重置上下文。短任务(30 分钟以内)可以在同一个会话里完成。长任务(跨会话)必须用进度文件和决策日志来维持连续性。判断标准:如果任务需要的上下文超过窗口的 60%,就开始准备交接。
+**混合策略**:不需要每次都重置上下文。短任务(30 分钟以内)可以在同一个会话里完成,长任务(跨会话)必须用进度文件和决策日志来维持连续性。判断标准:如果任务需要的上下文超过窗口的 60%,就开始准备交接。
### 上下文焦虑的深层分析
-Anthropic 在 2026 年 3 月发布的研究进一步揭示了上下文焦虑的具体表现:在 Sonnet 4.5 上,当上下文接近窗口限制时,agent 会表现出强烈的"过早收敛"行为。这就像考试时发现时间快到了,赶紧随便填选择题。
+Anthropic 在 2026 年 3 月发布的研究进一步揭示了上下文焦虑的具体表现:在 Sonnet 4.5 上,当上下文接近窗口限制时,agent 会表现出强烈的"过早收敛"行为。
针对这个现象,有两种策略:
-**压缩(Compaction)**:在同一个会话里把早期对话摘要化。优点是保留连续性,agent 能看到"是什么"。缺点是"为什么"经常在摘要中丢失——为什么选了方案 B 而非 A,为什么跳过了某个优化。更关键的是,压缩并不能消除上下文焦虑——agent 知道上下文曾经很大,心理上仍然倾向于加速收尾。
+**压缩(Compaction)**:在同一个会话里把早期对话摘要化。优点是保留连续性,agent 能看到"是什么"。缺点是"为什么"经常在摘要中丢失,比如为什么选了方案 B 而非 A,为什么跳过了某个优化。更关键的是,压缩并不能消除上下文焦虑,agent 知道上下文曾经很大,心理上仍然倾向于加速收尾。
-**重置(Context Reset)**:完全清空上下文,开一个新会话,从持久化工件重建。优点是干净的心理状态——新会话没有"我快没时间了"的焦虑。缺点是依赖交接工件的完备性。如果日记本里漏了关键信息,新会话可能在错误方向上浪费时间。
+**重置(Context Reset)**:完全清空上下文,开一个新会话,从持久化工件重建。优点是干净的心理状态,新会话没有"我快没时间了"的焦虑。缺点是依赖交接工件的完备性,如果进度文件里漏了关键信息,新会话可能在错误方向上浪费时间。
Anthropic 的实际数据:对于 Sonnet 4.5,上下文焦虑足够严重,以至于压缩单独不够用,上下文重置成为 harness 设计的关键组件。但对于 Opus 4.5,这种行为大幅减弱,可以不依赖重置而靠压缩管理上下文。这意味着:**harness 设计需要对目标模型有具体的理解,而不是套用通用模板。**
@@ -149,17 +147,17 @@ Anthropic 的实际数据:对于 Sonnet 4.5,上下文焦虑足够严重,
一个 agent 被要求实现一个带用户认证的博客系统,12 个功能点,预计需要 5 个会话。
-**没有日记本的基线**:会话 1 实现了用户模型和基础路由。会话 2 开始时,agent 不记得认证中间件的接口约定,花了约 15 分钟推断上次的设计意图。到会话 3,累积漂移导致 agent 开始重复已实现的功能。到会话 5,仓库有大量冗余代码,但核心认证功能仍未通过端到端测试。12 个功能点只完成了 7 个,其中 3 个有隐含的正确性问题。就像那个没写日记的工匠——到了第五天,工地上一团乱,有些墙砌了两遍,有些该砌的根本没砌。
+**没有连续性工件的基线**:会话 1 实现了用户模型和基础路由。会话 2 开始时,agent 不记得认证中间件的接口约定,花了约 15 分钟推断上次的设计意图。到会话 3,累积漂移导致 agent 开始重复已实现的功能。到会话 5,仓库有大量冗余代码,但核心认证功能仍未通过端到端测试。12 个功能点只完成了 7 个,其中 3 个有隐含的正确性问题。
-**有日记本的对照**:使用进度文件、决策日志、验证记录和 git 检查点。每个会话结束时自动更新状态报告。会话 2 的重建成本降到约 3 分钟。到会话 5,所有 12 个功能点完成且通过验证。
+**有连续性工件的对照**:使用进度文件、决策日志、验证记录和 git 检查点。每个会话结束时自动更新状态报告。会话 2 的重建成本降到约 3 分钟。到会话 5,所有 12 个功能点完成且通过验证。
-定量对比:重建时间减少约 78%,功能完成率从 58% 提升到 100%,隐含缺陷率从 43% 降到 8%。工匠还是那个会失忆的工匠,但有了日记本,他的每一天都从昨天停下的地方开始,而不是从零开始。
+定量对比:重建时间减少约 78%,功能完成率从 58% 提升到 100%,隐含缺陷率从 43% 降到 8%。
## 关键要点
-- 上下文窗口是有限的资源。长任务一定会跨会话,跨会话一定会丢信息——这就像工匠每天都会失忆一样,是客观现实。
-- 解决方案不是更大的窗口,而是更好的状态持久化。进度文件 + 决策日志 + git 检查点——给失忆的工匠一个靠谱的日记本。
-- 把 agent 当成会失忆的工程师来管理:每次"下班"前写清楚做了什么、为什么、下一步做什么。
+- 上下文窗口是有限的资源。长任务一定会跨会话,跨会话一定会丢信息,这是客观现实。
+- 解决方案不是更大的窗口,而是更好的状态持久化。进度文件、决策日志、git 检查点,三者配合让新会话能接上之前的工作。
+- 把 agent 当成每次会话都会清空短期记忆的工程师来管理:每次"下班"前写清楚做了什么、为什么、下一步做什么。
- 重建成本是关键指标。好的 harness 应该让新会话在 3 分钟内恢复到可执行状态。
- 混合策略:短任务在会话内完成,长任务用结构化工件维持连续性。
diff --git a/docs/zh/lectures/lecture-06-why-initialization-needs-its-own-phase/index.md b/docs/zh/lectures/lecture-06-why-initialization-needs-its-own-phase/index.md
index a253a6b..47a43fb 100644
--- a/docs/zh/lectures/lecture-06-why-initialization-needs-its-own-phase/index.md
+++ b/docs/zh/lectures/lecture-06-why-initialization-needs-its-own-phase/index.md
@@ -5,17 +5,17 @@
# 第六讲. 让 agent 每次工作前先初始化
-你开了一个新的 agent 会话,让它"帮我加个搜索功能"。它上来就开始改代码——精神可嘉。改了 20 分钟发现测试框架没配好,又花 10 分钟搞测试框架,然后发现数据库迁移脚本格式不对,又折腾了一会儿。最后搜索功能倒是加了,但整个会话的效率很低——大部分时间花在了"搞清楚这个项目怎么运作"上,而不是写搜索功能。
+你开了一个新的 agent 会话,让它"帮我加个搜索功能"。它上来就开始改代码,精神可嘉。改了 20 分钟发现测试框架没配好,又花 10 分钟搞测试框架,然后发现数据库迁移脚本格式不对,又折腾了一会儿。最后搜索功能倒是加了,但整个会话的效率很低,大部分时间花在了"搞清楚这个项目怎么运作"上,而不是写搜索功能本身。
-更好的做法是:在让 agent 开始干活之前,先用一个独立的阶段把基础环境搭好、验证命令跑通、项目结构搞清楚。就像盖房子——你不能边打地基边砌墙,不然墙砌到一半地基还没干,整栋楼都得推倒重来。先打地基,地基干了,再砌墙,一气呵成。
+更好的做法是,在让 agent 开始干活之前,先用一个独立的阶段把基础环境搭好、验证命令跑通、项目结构搞清楚。初始化工作不应该和功能实现挤在一起,它们是两种性质完全不同的任务。
-这节课讲的就是为什么初始化必须是独立的阶段,不能跟实现混在一起。
+这节课要讨论的就是,为什么初始化必须是独立的阶段,不能跟实现混在一起。
-## 地基和墙:两种完全不同的工作
+## 两种不同的工作
-初始化和实现的优化目标完全不同。实现阶段的目标是:最大化已验证功能的数量和质量。初始化阶段的目标是:最大化后续所有实现的可靠性和效率。
+初始化和实现的优化目标完全不同。实现阶段的目标是最大化已验证功能的数量和质量,初始化阶段的目标则是最大化后续所有实现的可靠性和效率。
-当你把初始化和实现混在一起的时候,agent 面临一个多目标优化问题——它要同时搭基础设施和写功能代码。在没有显式优先级设定的情况下,agent 自然倾向于写代码(因为那是直接可见的产出),而牺牲基础设施(因为它的价值只能在后续会话中体现)。这就像让施工队同时打地基和砌墙——他们大概率会急着砌墙,因为墙看得见、能交差。但地基没打好的房子,后面出的问题是系统性的。
+当你把初始化和实现混在一起的时候,agent 面临一个多目标优化问题:它要同时搭基础设施和写功能代码。在没有显式优先级设定的情况下,agent 自然倾向于写代码(因为那是直接可见的产出),而牺牲基础设施(因为它的价值只能在后续会话中体现)。结果就是基础设施没搭牢,功能代码的可靠性也打了折扣。
## 初始化生命周期
@@ -37,34 +37,34 @@ flowchart TB
## 混在一起做会怎样
-最直接的问题:地基打不牢。Agent 花了 80% 的精力写功能代码,剩下 20% 随便搭了点基础设施。测试框架配了但没验证过,lint 规则设了但太宽松,进度文件没创建。这些缺陷在第一个会话里不明显(因为 agent 还记得它做了什么),但到第二个会话就暴露了——新 agent 不知道项目怎么跑、怎么测、做到哪了。地基不牢,地动山摇。
+最直接的问题是基础设施搭不牢。Agent 花了 80% 的精力写功能代码,剩下 20% 随便搭了点基础设施。测试框架配了但没验证过,lint 规则设了但太宽松,进度文件没创建。这些缺陷在第一个会话里不明显(因为 agent 还记得它做了什么),但到第二个会话就暴露了:新 agent 不知道项目怎么跑、怎么测、做到哪了。
-更隐蔽的代价是"未验证的累积"——在测试框架配好之前写的功能代码,等回头补测试的时候可能发现设计上就有问题,早知道的话应该用不同的方式实现。就像在地基没干的时候就开始贴瓷砖,等发现地面不平时,瓷砖全得撬掉重来。
+更隐蔽的代价是"未验证的累积"。在测试框架配好之前写的功能代码,等回头补测试的时候可能发现设计上就有问题,早知道的话应该用不同的方式实现。前面写的代码越多,后面需要推翻重来的就越多。
-上下文预算也在被浪费。初始化工作(配环境、配测试、理解项目结构)消耗了大量预算,留给实际功能实现的反而不够了。结果第一个会话只完成了一半的功能,第二个会话还得从头理解项目。预算花在了打地基上,但地基也没打好——两头都没占着。
+上下文预算也在被浪费。初始化工作(配环境、配测试、理解项目结构)消耗了大量预算,留给实际功能实现的反而不够了。结果第一个会话只完成了一半的功能,第二个会话还得从头理解项目。预算花在了初始化上,但初始化也没做好,两头都没占着。
-最容易被忽略的是隐式假设埋下的雷。Agent 在初始化过程中做的决策(用什么测试框架、目录怎么组织、依赖怎么管理)如果不显式记录下来,后续会话就可能做出矛盾的选择。第一个施工队用的是水泥地基,第二个施工队不知道,往上面打了木桩——地基直接裂了。
+最容易被忽略的是隐式假设埋下的雷。Agent 在初始化过程中做的决策(用什么测试框架、目录怎么组织、依赖怎么管理)如果不显式记录下来,后续会话就可能做出矛盾的选择。第一个会话选了 Vitest 做测试框架,第二个会话的 agent 不知道,又引入了 Jest,两套测试框架共存,维护成本翻倍。
-Anthropic 在他们的长运行应用开发研究中明确建议把初始化和实现分离。他们的实验数据:使用独立初始化阶段的项目,多会话场景中的功能完成率比混合方式高 31%。关键是——初始化阶段投入的时间在后续 3-4 个会话中就能完全收回。地基打得越扎实,上面的楼盖得越快。
+Anthropic 在他们的长运行应用开发研究中明确建议把初始化和实现分离。他们的实验数据:使用独立初始化阶段的项目,多会话场景中的功能完成率比混合方式高 31%。而且初始化阶段投入的时间在后续 3-4 个会话中就能完全收回。
-OpenAI 的 Codex harness engineering 指南也强调"仓库作为操作记录"的原则——第一次运行就要建立清晰的操作结构,否则每次新会话都得重新推断项目约定。
+OpenAI 的 Codex harness engineering 指南也强调"仓库作为操作记录"的原则:第一次运行就要建立清晰的操作结构,否则每次新会话都得重新推断项目约定。
## 核心概念
-- **初始化阶段**:agent 生命周期中的第一个阶段,不做功能实现,只建立后续所有实现阶段的执行前提。输出不是代码,而是基础设施。
-- **自举契约**:一个项目能被全新 agent 会话无歧义操作的条件——能启动、能测试、能看进度、能接手下一步。四个条件缺一不可。
-- **冷启动 vs 热启动**:冷启动是从空目录开始,agent 要猜项目结构;热启动是从模板或已有项目开始,基础设施已经就位。热启动的效果远好于冷启动——就像在有水电的工地上开工,比在荒郊野岭从头搞起快得多。
+- **初始化阶段**:agent 生命周期中的第一个阶段,只建立后续实现所需的执行前提,不做功能开发。它的产出是基础设施,而不是业务代码。
+- **自举契约**:一个项目能被全新 agent 会话无歧义操作的条件:能启动、能测试、能看进度、能接手下一步。四个条件缺一不可。
+- **冷启动 vs 热启动**:冷启动是从空目录开始,agent 需要自行推断项目结构;热启动是从模板或已有项目开始,基础设施已经就位。热启动的效果远好于冷启动。
- **交接就绪性**:项目在任何时刻都处于"可以被全新 agent 接手"的状态。不需要口头解释,只看仓库内容就能接着干。
-- **首次验证时间**:从项目开始到第一个功能点通过验证的时间。这是衡量初始化效率的核心指标。
-- **下游可用性**:初始化质量的最佳衡量标准——后续会话不需要依赖隐式知识就能成功执行任务的比例。
+- **首次验证时间**:从项目开始到第一个功能点通过验证的时间,是衡量初始化效率的核心指标。
+- **下游可用性**:后续会话不需要依赖隐式知识就能成功执行任务的比例,这是初始化质量的最佳衡量标准。
## 怎么做好初始化
**把初始化当作一个独立的阶段来执行。** 第一个会话只做初始化,不写任何业务功能代码。初始化的产出是:
-**1. 可运行的环境。** 项目能启动、依赖都装好、没有环境问题。地基浇好了,没裂缝。
+**1. 可运行的环境。** 项目能启动、依赖都装好、没有环境问题。
-**2. 可验证的测试框架。** 至少有一个示例测试能通过。这证明测试框架本身是配对的——就像地基上立了一根柱子,证明地基能承重。
+**2. 可验证的测试框架。** 至少有一个示例测试能通过,证明测试框架本身是配好的。
**3. 自举契约文档。** 一个明确的文档告诉后续会话:
```markdown
@@ -109,9 +109,9 @@ OpenAI 的 Codex harness engineering 指南也强调"仓库作为操作记录"
**5. Git 提交作为检查点。** 初始化完成后提交一个干净的 checkpoint。后续所有工作都从这个 checkpoint 开始。
-**热启动策略**:不要从空目录开始。用一个项目模板(create-react-app、fastapi-template 等)预置好标准的目录结构、依赖配置和测试框架。把通用的初始化步骤预置到模板里,只留下项目特有的初始化工作。就像在有通水通电的工地上开工,比从荒郊野岭开始强一万倍。
+**热启动策略**:不要从空目录开始。用一个项目模板(create-react-app、fastapi-template 等)预置好标准的目录结构、依赖配置和测试框架。把通用的初始化步骤预置到模板里,只留下项目特有的初始化工作。
-**初始化的完成条件**:不是"写了多少代码",而是自举契约的四个条件都满足了——能启动、能测试、能看进度、能接手下一步。用这个检查清单验收初始化:
+**初始化的完成条件**:不是"写了多少代码",而是自举契约的四个条件都满足了:能启动、能测试、能看进度、能接手下一步。用这个检查清单验收初始化:
```markdown
## 初始化验收清单
@@ -126,19 +126,19 @@ OpenAI 的 Codex harness engineering 指南也强调"仓库作为操作记录"
一个 React 前端项目的两种初始化方式对比:
-**混合方式(边打地基边砌墙)**:agent 在第一个会话中同时做了项目脚手架创建和首个功能实现。会话结束时,仓库有可运行的代码,但:没有显式的启动/测试命令文档、没有进度跟踪文件、没有任务分解。第二个会话花了约 20 分钟推断项目结构、测试框架和构建流程——就像新来的施工队看着一片工地,不知道地基打到什么程度、水电管道走到哪了,只能一个个挖开来看。
+**混合方式**:agent 在第一个会话中同时做了项目脚手架创建和首个功能实现。会话结束时,仓库有可运行的代码,但没有显式的启动和测试命令文档、没有进度跟踪文件、没有任务分解。第二个会话花了约 20 分钟推断项目结构、测试框架和构建流程。
-**独立初始化(先打地基)**:第一个会话只做初始化——用项目模板创建目录结构、配置测试框架(Vitest + React Testing Library)、写一个示例测试并验证通过、创建自举契约文档和任务分解文件、提交初始检查点。第二个会话的重建时间不到 3 分钟,直接从任务列表开始工作——施工队来了,看了一眼施工图就知道从哪里接着干。
+**独立初始化**:第一个会话只做初始化,用项目模板创建目录结构、配置测试框架(Vitest + React Testing Library)、写一个示例测试并验证通过、创建自举契约文档和任务分解文件、提交初始检查点。第二个会话的重建时间不到 3 分钟,直接从任务列表开始工作。
-整个项目周期对比:混合方式的总重建时间(跨所有会话)比独立初始化多约 60%。独立初始化多花的那 20 分钟在后续会话中被成倍收回。就像地基打得扎实,上面盖楼的效率反而更高——慢即是快。
+整个项目周期对比:混合方式的总重建时间(跨所有会话)比独立初始化多约 60%。独立初始化多花的那 20 分钟在后续会话中被成倍收回。前期多投入一点时间把初始化做扎实,后续的效率反而更高。
## 关键要点
-- 初始化和实现的优化目标不同,混在一起只会互相拖后腿。先打地基,再砌墙。
-- 初始化的产出不是代码,是基础设施:可运行的环境、可验证的测试、自举契约、任务分解。
+- 初始化和实现的优化目标不同,混在一起只会互相拖后腿。
+- 初始化的产出不是业务代码,而是基础设施:可运行的环境、可验证的测试、自举契约、任务分解。
- 用"自举契约"的四个条件验收初始化:能启动、能测试、能看进度、能接手下一步。
-- 热启动优于冷启动。用项目模板预置标准化的基础设施。
-- 初始化投入的时间会在后续 3-4 个会话中完全收回。这不是额外的成本,是前期投资——地基打得越扎实,楼盖得越快。
+- 热启动优于冷启动,用项目模板预置标准化的基础设施。
+- 初始化投入的时间会在后续 3-4 个会话中完全收回,这不是额外的成本,而是前期投资。
## 延伸阅读
@@ -150,8 +150,8 @@ OpenAI 的 Codex harness engineering 指南也强调"仓库作为操作记录"
## 练习
-1. **自举契约设计**:为一个你正在开发的项目写一个完整的自举契约。然后开一个全新的 agent 会话,只给它看仓库内容(不给任何口头上下文),让它尝试启动项目、跑测试、了解当前进度。记录它遇到的问题——每个问题都对应自举契约中缺失的一个条款。
+1. **自举契约设计**:为你正在开发的项目写一个完整的自举契约。然后开一个全新的 agent 会话,只给它看仓库内容(不给任何口头上下文),让它尝试启动项目、跑测试、了解当前进度。记录它遇到的问题,每个问题都对应自举契约中缺失的一个条款。
-2. **对比实验**:选一个中等复杂度的新项目。方式 A:让 agent 初始化和首次实现同时做。方式 B:先花一个会话做独立初始化,第二个会话开始实现。在 4 个会话后对比:首次验证时间、重建成本、功能完成率。
+2. **对比实验**:选一个中等复杂度的新项目。方式 A 让 agent 初始化和首次实现同时做,方式 B 先花一个会话做独立初始化,第二个会话再开始实现。在 4 个会话后对比首次验证时间、重建成本和功能完成率。
-3. **初始化验收清单**:为你的项目设计一个初始化验收清单。让一个全新的 agent 会话执行清单上的每一项,记录哪些项通过了、哪些没通过。没通过的项就是你的 harness 需要补强的地方。
+3. **初始化验收清单**:为你的项目设计一个初始化验收清单,让一个全新的 agent 会话逐项执行,记录哪些项通过了、哪些没通过。没通过的项就是 harness 需要补强的地方。
diff --git a/docs/zh/lectures/lecture-07-why-agents-overreach-and-under-finish/index.md b/docs/zh/lectures/lecture-07-why-agents-overreach-and-under-finish/index.md
index 3fe2d03..0aa1eb0 100644
--- a/docs/zh/lectures/lecture-07-why-agents-overreach-and-under-finish/index.md
+++ b/docs/zh/lectures/lecture-07-why-agents-overreach-and-under-finish/index.md
@@ -5,15 +5,15 @@
# 第七讲. 给 agent 划清每次任务的边界
-你让 Claude Code "给这个项目加上用户认证功能",结果它同时开始改数据库 schema、写路由、改前端组件、还顺手重构了错误处理中间件。两个小时后你一看——12 个文件被修改,800 行新代码,但没有一个功能是端到端跑通的。
+你让 Claude Code "给这个项目加上用户认证功能",结果它同时开始改数据库 schema、写路由、改前端组件,还顺手重构了错误处理中间件。两个小时后一看,12 个文件被修改,800 行新代码,但没有一个功能是端到端跑通的。
-贪多嚼不烂,这句话放到 AI agent 身上格外贴切。Agent 天生就有"多做一点"的冲动——看到相关的事情就顺手一起做了,和那种在超市本来只打算买瓶酱油、结果推着满满一车出来的人一个德行。问题是,人类买了太多东西最多浪费钱,agent 同时做太多事情则是每一件都做不好。
+Agent 天生就有"多做一点"的冲动:看到相关的事情就顺手一起做了。问题是,同时做太多事情,结果往往每一件都做不好。
-Anthropic 在 "Effective harnesses for long-running agents" 工程博客中明确指出:当提示太宽泛时,agent 倾向于"同时启动多件事"而非"先做完一件事"。OpenAI 在 Codex 工程实践中也发现,没有显式范围控制的任务,完成率会暴跌。这不是模型的问题——是你没有在 harness 里给它划清边界。
+Anthropic 在 "Effective harnesses for long-running agents" 工程博客中明确指出:当提示太宽泛时,agent 倾向于"同时启动多件事"而非"先做完一件事"。OpenAI 在 Codex 工程实践中也发现,没有显式范围控制的任务,完成率会暴跌。这不是模型的问题,而是你没有在 harness 里给它划清边界。
## 注意力是有限的资源
-这不是比喻,是数学。假设 agent 的上下文容量为 C,同时激活 k 个任务,每个任务平均获得 C/k 的推理资源。当 C/k 低于完成单个任务所需的最小阈值时,所有任务都做不完。这就像你的胃就那么大——同时塞十个包子进去,不是一个都消化不了,而是十个都消化不良。
+这不是比喻,是数学。假设 agent 的上下文容量为 C,同时激活 k 个任务,每个任务平均获得 C/k 的推理资源。当 C/k 低于完成单个任务所需的最小阈值时,所有任务都做不完。
Claude Code 的真实行为很说明问题。你让它"添加用户注册功能",它很可能这样做:
@@ -24,9 +24,9 @@ Claude Code 的真实行为很说明问题。你让它"添加用户注册功能"
5. 注意到错误处理不统一,于是重构全局错误中间件
6. 看到测试文件结构不清晰,于是重组目录结构
-6 步之后,每一个都是半成品。没有端到端验证,代码之间耦合复杂,下一个会话来接手时会一脸懵。就像一个人同时炒六道菜,每道菜都下了锅但没有一道出锅——全糊了。
+6 步之后,每一个都是半成品。没有端到端验证,代码之间耦合复杂,下一个会话来接手时会一脸懵。
-Anthropic 的实验数据直接支持这一点:使用"小下一步"策略(等价于 WIP=1)的 agent,任务完成率比使用宽泛提示的 agent 高 37%。更有意思的是,agent 生成的代码行数和实际完成的功能数量呈弱负相关——写得越多,完成得越少。贪多嚼不烂,数据为证。
+Anthropic 的实验数据直接支持这一点:使用"小下一步"策略(等价于 WIP=1)的 agent,任务完成率比使用宽泛提示的 agent 高 37%。更有意思的是,agent 生成的代码行数和实际完成的功能数量呈弱负相关,写得越多,完成得越少。贪多嚼不烂,数据为证。
## WIP=1 工作流
@@ -52,20 +52,20 @@ flowchart TB
## 核心概念
-- **过度延伸(Overreach)**:agent 在一次会话中激活的任务数量超过最优值。它不是主观判断,而是可量化的——同时做 5 个功能但 0 个跑通,就是 overreach。
+- **过度延伸(Overreach)**:agent 在一次会话中激活的任务数量超过最优值。这不是主观判断,而是可以量化的:同时做 5 个功能但 0 个跑通,就是 overreach。
- **不足完成(Under-finish)**:已启动的任务中,通过端到端验证的比例低于阈值。写了代码但没跑通测试,就是 under-finish。
-- **WIP 限制(Work-in-Progress Limit)**:来自 Kanban 方法论。核心思想:限制同时在进行的任务数量。对于 agent,WIP=1 是最安全的默认值——做完一个再做下一个。就像自助餐厅不要一次拿太多盘子,吃完一盘再去拿下一盘。
+- **WIP 限制(Work-in-Progress Limit)**:来自 Kanban 方法论,核心思想是限制同时在进行的任务数量。对于 agent,WIP=1 是最安全的默认值,做完一个再做下一个。
- **完成证据(Completion Evidence)**:一个任务从"进行中"变成"已完成"必须满足的可验证条件。没有这个,agent 会用"代码看起来没问题"代替"行为通过测试"。
- **范围表面(Scope Surface)**:一个 DAG 结构,每个节点是一个工作单元,边是依赖关系。状态只有四种:未开始、进行中、阻塞、已通过。
- **完成压力(Completion Pressure)**:harness 通过 WIP 限制和完成证据要求共同产生的约束力,迫使 agent 先完成当前任务再开始新任务。
## Overreach 和 Under-finish 是一对难兄难弟
-这两个问题不是独立的,而是互相加剧。overreach 导致注意力分散,注意力分散导致 under-finish,under-finish 留下的半成品代码又增加了系统复杂度,进一步导致下一个任务的 overreach。恶性循环。
+这两个问题不是独立的,而是互相加剧。overreach 导致注意力分散,注意力分散导致 under-finish,under-finish 留下的半成品代码又增加了系统复杂度,进一步导致下一个任务的 overreach,形成恶性循环。
-用 Kanban 的语言说:Little 法则告诉我们 L = lambda * W。如果在制品数量 L 过大(同时做太多事),每个任务的前置时间 W 必然增加。对于 agent 来说,这意味着每个功能从开始到验证通过的时间被拉长,失败概率被放大。
+用 Kanban 的语言说:Little 法则告诉我们 L = lambda * W。如果在制品数量 L 过大(同时做太多事),每个任务的前置时间 W 必然增加。对 agent 来说,这意味着每个功能从开始到验证通过的时间被拉长,失败概率被放大。
-这在人类世界也是老问题了——Steve McConnell 在《Rapid Development》中记录,范围蔓延是项目失败的首要原因。但人类至少有"我已经做得够多了"的直觉,agent 完全没有。生成下一个想法的成本对模型来说太低了——写一行"顺便把这个也改了"几乎不消耗额外 token,但每个额外的修改都会稀释 agent 的注意力。就像在自助餐厅里,每多拿一个盘子的边际成本几乎为零,但你的胃只有那么大。
+这在人类世界也是老问题了。Steve McConnell 在《Rapid Development》中记录,范围蔓延是项目失败的首要原因。但人类至少有"我已经做得够多了"的直觉,agent 完全没有。生成下一个想法的成本对模型来说太低了,写一行"顺便把这个也改了"几乎不消耗额外 token,但每个额外的修改都会稀释 agent 的注意力。
## 怎么做才对
@@ -80,8 +80,6 @@ flowchart TB
- 不要在实现功能 A 时"顺便"重构功能 B
```
-就像吃自助餐——一次只拿一盘,吃完再去拿。
-
### 2. 给每个任务定义显式的完成证据
完成不是"代码写完了",而是"行为验证通过了"。在你的功能列表里,每个条目都要有验证命令:
@@ -104,19 +102,19 @@ harness 应该持续跟踪 VCR(Verified Completion Rate)= 已通过验证的
一个 8 个功能点的 REST API 项目,两种策略对比:
-**自助餐模式(无约束)**:agent 在第一个会话同时启动 5 个功能。产出约 800 行代码,涉及 12 个文件。端到端测试通过率只有 20%——只有用户注册跑通了。其余 4 个功能:数据库 schema 建了但缺验证逻辑,路由定义了但返回格式错误。就像一个人同时炒六道菜,只有一道勉强能吃。到第 3 个会话结束,8 个功能只完成 3 个。
+**无约束模式**:agent 在第一个会话同时启动 5 个功能。产出约 800 行代码,涉及 12 个文件。端到端测试通过率只有 20%,只有用户注册跑通了。其余 4 个功能:数据库 schema 建了但缺验证逻辑,路由定义了但返回格式错误。到第 3 个会话结束,8 个功能只完成 3 个。
-**单盘模式(WIP=1)**:agent 在第一个会话只做用户注册。产出约 200 行代码,涉及 4 个文件。端到端测试 100% 通过。提交干净的、已验证的实现。到第 4 个会话结束,8 个功能完成 7 个(第 8 个因外部依赖被阻塞)。
+**WIP=1 模式**:agent 在第一个会话只做用户注册。产出约 200 行代码,涉及 4 个文件。端到端测试 100% 通过。提交干净的、已验证的实现。到第 4 个会话结束,8 个功能完成 7 个(第 8 个因外部依赖被阻塞)。
-结果:总代码量更少(800 行 vs 1200 行),但有效代码更多。完成率 87.5% vs 37.5%。一口一口吃,反而吃得最多。
+结果:总代码量更少(800 行 vs 1200 行),但有效代码更多。完成率 87.5% vs 37.5%。
## 关键要点
-- **WIP=1 是 agent harness 的默认安全设置**——做完一个再做下一个,不要试图并行。一口吃不成胖子。
-- **完成证据必须是可执行的**——"代码看起来没问题"不算完成,"curl 返回 201"才算。
-- **范围表面必须外部化为文件**——不能只在对话里说,必须在仓库里有机器可读的记录。
-- **overreach 和 under-finish 是共生问题**——解决一个就解决了另一个。
-- **"少做但做完"永远优于"多做但做半"**——agent 代码行数和功能完成率呈负相关。质量永远比数量重要。
+- **WIP=1 是 agent harness 的默认安全设置**:做完一个再做下一个,不要试图并行。
+- **完成证据必须是可执行的**:"代码看起来没问题"不算完成,"curl 返回 201"才算。
+- **范围表面必须外部化为文件**:不能只在对话里说,必须在仓库里有机器可读的记录。
+- **overreach 和 under-finish 是共生问题**:解决一个就解决了另一个。
+- **"少做但做完"永远优于"多做但做半"**:agent 代码行数和功能完成率呈负相关,质量永远比数量重要。
## 延伸阅读
@@ -129,6 +127,6 @@ harness 应该持续跟踪 VCR(Verified Completion Rate)= 已通过验证的
1. **任务原子化练习**:选一个宽泛需求(如"实现用户管理系统"),把它拆成至少 5 个原子工作单元。每个单元写清楚:(a) 单一行为描述,(b) 可执行的验证命令,(c) 依赖关系。检查是否满足 WIP=1 的约束。
-2. **对比实验**:在同一个项目上跑两次——一次不给约束,一次强制 WIP=1。比较:验证完成率、总代码行数、有效代码比例。
+2. **对比实验**:在同一个项目上跑两次,一次不给约束,一次强制 WIP=1。比较验证完成率、总代码行数、有效代码比例。
3. **完成证据审计**:回顾一个最近的 agent 运行结果,把每个代码变更分类为"已完成行为"、"未完成行为"或"脚手架"。给每个未完成行为补充缺失的验证命令。
diff --git a/docs/zh/lectures/lecture-08-why-feature-lists-are-harness-primitives/index.md b/docs/zh/lectures/lecture-08-why-feature-lists-are-harness-primitives/index.md
index c039747..d64543f 100644
--- a/docs/zh/lectures/lecture-08-why-feature-lists-are-harness-primitives/index.md
+++ b/docs/zh/lectures/lecture-08-why-feature-lists-are-harness-primitives/index.md
@@ -5,9 +5,9 @@
# 第八讲. 用功能清单约束 agent 该做什么
-你让 agent 做一个电商网站,跑完之后它告诉你"做完了"。你打开代码一看——用户认证有了,但购物车的结算按钮点了没反应,支付流程根本没接上。问题是:你从来没告诉它"做完"的标准是什么,所以它用自己的标准——"代码写了不少,看起来挺完整"。
+你让 agent 做一个电商网站,跑完之后它告诉你"做完了"。你打开代码一看,用户认证有了,但购物车的结算按钮点了没反应,支付流程根本没接上。问题出在哪?你从来没告诉它"做完"的标准是什么,所以它用自己的标准来判断,"代码写了不少,看起来挺完整"。
-功能清单(feature list)在很多人眼里就是个备忘录——写下来怕忘了,写完扔在一边。但在 harness 的世界里,功能清单不是给人看的备忘录,而是整个 harness 的脊梁骨。调度器靠它选任务,验证器靠它判完成,交接器靠它生成报告。脊梁骨断了,全身都瘫。
+功能清单(feature list)在很多人眼里就是个备忘录,写下来怕忘了,写完扔在一边。但在 harness 的世界里,功能清单不是给人看的备忘录,而是整个 harness 的基础结构。调度器靠它选任务,验证器靠它判完成,交接器靠它生成报告。没有它,这些组件就没有可以依赖的共识。
Anthropic 和 OpenAI 都强调:**工件必须外部化**。功能状态必须是仓库里机器可读的文件,不能是对话里的非结构化描述。
@@ -15,7 +15,7 @@ Anthropic 和 OpenAI 都强调:**工件必须外部化**。功能状态必须
Claude Code 和 Codex 都不会自动知道你心目中的"做完"是什么意思。你说"加一个购物车功能",模型的理解可能是"写一个 Cart 组件和 addToCart 方法"。而你的意思是"用户能从浏览商品到下单支付完整走通"。
-这个理解鸿沟在没有功能清单的情况下会持续存在。agent 用自己的隐式标准判断完成——通常是"代码没有明显的语法错误"。而你需要的是端到端的行为验证。就像你让朋友帮你买菜,说"买点水果",他拎了一袋柠檬回来——他要的水果,你要的水果,不是一个水果。
+这个理解鸿沟在没有功能清单的情况下会持续存在。agent 用自己的隐式标准判断完成,通常是"代码没有明显的语法错误"。而你需要的是端到端的行为验证。没有清单,双方对"做完"的理解始终是对不上的。
看看这种常见的进度记录:
@@ -23,7 +23,7 @@ Claude Code 和 Codex 都不会自动知道你心目中的"做完"是什么意
做了用户认证、购物车基本完成了、还需要做支付
```
-新的 agent 会话看到这个记录,能回答以下问题吗?"基本完成"意味着什么?购物车通过了哪些测试?支付的阻塞条件是什么?答案都是"不知道"。就像你看病时跟医生说"我肚子疼,最近还行",医生能开出什么药来?
+新的 agent 会话看到这个记录,能回答以下问题吗?"基本完成"意味着什么?购物车通过了哪些测试?支付的阻塞条件是什么?答案都是"不知道"。
结果是:新会话花 20 分钟推断项目状态,最终可能重复实现已完成的功能。Anthropic 的工程实践数据表明,好的进度记录可以减少 60-80% 的会话启动诊断时间。
@@ -54,10 +54,10 @@ flowchart LR
## 核心概念
-- **功能清单是 harness 原语**:它不是"可选的规划工具",而是其他所有 harness 组件依赖的基础数据结构。就像数据库里的表结构——你不能说"要不我们省掉主键吧",省掉了整个系统就散架了。
-- **三元组结构**:每个功能项是 `(行为描述, 验证命令, 当前状态)` 的三元组。缺了任何一项,这个功能项就不完整。行为描述告诉 agent 做什么,验证命令告诉它怎么算做完,状态告诉它现在到哪了。
-- **状态机模型**:每个功能项有四种状态——`not_started`、`active`、`blocked`、`passing`。状态转移由 harness 控制,不是 agent 想改就能改。
-- **通过状态门控**:功能从 `active` 变成 `passing` 的唯一方式是验证命令执行成功。这是不可逆的——`passing` 了就不能退回去。就像考试及格了就是及格了,不能事后改成分数。
+- **功能清单是 harness 原语**:它不是"可选的规划工具",而是其他所有 harness 组件依赖的基础数据结构。调度器、验证器、交接器都要读取它才能工作。
+- **三元组结构**:每个功能项包含三个要素:`(行为描述, 验证命令, 当前状态)`。行为描述告诉 agent 做什么,验证命令告诉它怎么算做完,状态告诉它现在到哪了。缺了任何一项,这个功能项就不完整。
+- **状态机模型**:每个功能项有四种状态:`not_started`、`active`、`blocked`、`passing`。状态转移由 harness 控制,不是 agent 想改就能改。
+- **通过状态门控**:功能从 `active` 变成 `passing` 的唯一方式是验证命令执行成功。这个转移是不可逆的,`passing` 了就不能退回去。
- **单一权威来源**:项目里关于"该做什么"的所有信息,必须从一个功能清单派生。不能出现功能清单和对话记录矛盾的情况。
- **反向压力**:还没通过的功能项数量就是 harness 对 agent 施加的压力。压力归零 = 项目完成。
@@ -65,14 +65,14 @@ flowchart LR
文档是给人看的,原语是给系统用的。文档可以被忽略,原语不能被绕过。
-类比数据库的触发器约束和应用层的检查逻辑:前者由数据库引擎强制执行,任何 SQL 都无法跳过;后者依赖于应用代码的正确性,可能被意外绕过。功能清单作为 harness 原语,就是数据库级别的约束——agent 不能绕过它。
+可以类比数据库的触发器约束和应用层的检查逻辑:前者由数据库引擎强制执行,任何 SQL 都无法跳过;后者依赖于应用代码的正确性,可能被意外绕过。功能清单作为 harness 原语,承担的就是数据库级别的约束角色,agent 不能绕过它。
具体来说,功能清单服务四个 harness 组件:
-1. **调度器**:读状态,选下一个 `not_started` 的功能。就像工厂的排产系统——看完订单才知道下一步做什么。
-2. **验证器**:执行验证命令,判断是否允许状态转移。就像质检——不是你说合格就合格,得通过检验。
-3. **交接报告器**:从功能清单自动生成会话交接摘要。就像换班时自动生成的交接表——不用手写,系统自己出。
-4. **进度追踪器**:统计各状态分布,提供项目健康度指标。就像仪表盘——一眼看出项目走到哪了。
+1. **调度器**:读状态,选下一个 `not_started` 的功能。
+2. **验证器**:执行验证命令,判断是否允许状态转移。
+3. **交接报告器**:从功能清单自动生成会话交接摘要。
+4. **进度追踪器**:统计各状态分布,提供项目健康度指标。
## 怎么做
@@ -92,7 +92,7 @@ flowchart LR
### 2. 让 harness 控制状态转移
-agent 不能直接把状态改成 `passing`。它只能提交验证请求,harness 执行验证命令,根据结果决定是否允许状态转移。这就是"通过状态门控"——不是你说考过了就考过了,得看成绩单。
+agent 不能直接把状态改成 `passing`。它只能提交验证请求,harness 执行验证命令,根据结果决定是否允许状态转移。这就是"通过状态门控"。
### 3. 在 CLAUDE.md 里写清楚规则
@@ -101,29 +101,29 @@ agent 不能直接把状态改成 `passing`。它只能提交验证请求,harn
- 功能清单文件: /docs/features.md
- 每次只激活一个功能项
- 功能项验证命令必须通过才能标为 passing
-- 不要修改功能清单的状态——由验证脚本自动更新
+- 不要修改功能清单的状态,由验证脚本自动更新
```
### 4. 粒度校准
-每个功能项应该是"一次会话能完成"的范围。太粗了做不完,太细了管理开销大。"用户可以添加商品到购物车"是一个好粒度,"实现购物车"太粗了,"创建 Cart 模型的 name 字段"太细了。就像切牛排——不能整块啃,也不能切成肉沫。
+每个功能项应该是"一次会话能完成"的范围。太粗了做不完,太细了管理开销大。"用户可以添加商品到购物车"是一个好粒度,"实现购物车"太粗了,"创建 Cart 模型的 name 字段"太细了。
## 实际案例
一个电商平台的开发任务,10 个功能项。对比两种追踪方式:
-**备忘录模式**:agent 用非结构化笔记记录进度。3 个会话后,笔记变成了"做了用户认证和商品列表、购物车基本完成但还有 bug、支付没开始"。新会话需要 20 分钟推断状态,最终重复实现了已完成的功能。就像你的购物清单上写着"牛奶、面包、还有那个什么来着"——到超市了你还是不知道要买什么。
+**备忘录模式**:agent 用非结构化笔记记录进度。3 个会话后,笔记变成了"做了用户认证和商品列表、购物车基本完成但还有 bug、支付没开始"。新会话需要 20 分钟推断状态,最终重复实现了已完成的功能。
-**脊梁骨模式**:每个功能项有明确的状态和验证命令。新会话读取功能清单,3 分钟内知道:F01-F05 是 `passing`,F06 是 `active`(正在做),F07-F10 是 `not_started`。直接从 F06 继续,零重复。
+**结构化模式**:每个功能项有明确的状态和验证命令。新会话读取功能清单,3 分钟内知道:F01-F05 是 `passing`,F06 是 `active`(正在做),F07-F10 是 `not_started`。直接从 F06 继续,零重复。
定量结果:使用结构化功能清单的项目,功能完成率比自由形式高 45%,零重复实现。
## 关键要点
-- **功能清单是 harness 的脊梁骨**,不是给人看的备忘录。调度器、验证器、交接器都依赖它。
-- **每个功能项必须有三元组**:行为描述 + 验证命令 + 当前状态。缺一项就不完整——就像三条腿的凳子少一条腿。
-- **状态转移由 harness 控制**,agent 不能自己改状态。通过验证 = 唯一的升级路径。
-- **功能清单是项目的单一权威来源**——任何关于"该做什么"的信息都从这里派生。
+- **功能清单是 harness 的基础结构**,不是给人看的备忘录。调度器、验证器、交接器都依赖它。
+- **每个功能项必须有三元组**:行为描述 + 验证命令 + 当前状态。缺一项就不完整。
+- **状态转移由 harness 控制**,agent 不能自己改状态。通过验证是唯一的升级路径。
+- **功能清单是项目的单一权威来源**,任何关于"该做什么"的信息都从这里派生。
- **粒度控制在"一次会话能完成"的范围**。太粗做不完,太细管不过来。
## 延伸阅读
diff --git a/docs/zh/lectures/lecture-09-why-agents-declare-victory-too-early/index.md b/docs/zh/lectures/lecture-09-why-agents-declare-victory-too-early/index.md
index d9ab4db..ca03c2d 100644
--- a/docs/zh/lectures/lecture-09-why-agents-declare-victory-too-early/index.md
+++ b/docs/zh/lectures/lecture-09-why-agents-declare-victory-too-early/index.md
@@ -5,17 +5,15 @@
# 第九讲. 防止 agent 提前宣告完成
-你让 agent 实现"密码重置"功能。它改了数据库 schema、写了 API 端点、加了邮件模板,跑了单元测试(全部通过),然后自信地告诉你"做完了"。你实际一跑——密码重置链接发不出去(邮件服务配置缺失)、数据库迁移半途失败(schema 不一致)、端到端流程根本没走过一遍。
+你让 agent 实现"密码重置"功能。它改了数据库 schema、写了 API 端点、加了邮件模板,跑了单元测试全部通过,然后自信地告诉你"做完了"。你实际一跑才发现:密码重置链接发不出去,邮件服务配置缺失;数据库迁移半途失败,schema 不一致;端到端流程根本没走过一遍。
-这种感觉你一定不陌生——考试时把卷子写得满满当当,信心满满地第一个交卷,结果成绩出来不及格。卷子写满了,不代表做对了。
-
-这不是偶然事件。Guo 等人 2017 年在 ICML 上的经典论文证明:**现代神经网络系统性地过度自信**——模型自报的置信度显著高于实际准确率。AI 编码 agent 也一样:它"觉得"做完了,但实际上差得远。你的 harness 必须用外部化的、基于执行的验证来替代 agent 的"感觉"。
+这不是偶然事件。Guo 等人 2017 年在 ICML 上的经典论文证明:**现代神经网络系统性地过度自信**,模型自报的置信度显著高于实际准确率。AI 编码 agent 也一样,它"觉得"做完了,但实际上差得远。你的 harness 必须用外部化的、基于执行的验证来替代 agent 的"感觉"。
## 滑坡效应
-过早完成声明几乎总是一样的套路:代码看着还行——语法正确、逻辑似乎合理,静态检查没有明显错误。但 harness 没有强制要求全面执行验证,agent 跳过了实际运行或只跑了部分测试。跑了单元测试但跳过集成测试,跑了测试但没检查覆盖率。最后"代码看起来没问题"就被当作了"功能已完成"的证据。交卷了。
+过早完成声明几乎总是一样的套路:代码看着还行,语法正确、逻辑似乎合理,静态检查没有明显错误。但 harness 没有强制要求全面执行验证,agent 跳过了实际运行或只跑了部分测试。跑了单元测试但跳过集成测试,跑了测试但没检查覆盖率。最后"代码看起来没问题"就被当作了"功能已完成"的证据。
-每一步都在丢失信息。从任务规范到代码实现到运行时行为,每次转换都可能引入偏差,而每次跳过的验证都加剧了信息不对称。
+每一步都在丢失信息。从任务规范到代码实现,再到运行时行为,每次转换都可能引入偏差,每次跳过的验证都加剧了信息不对称。
## 三层终止检查
@@ -36,51 +34,51 @@ flowchart LR
## 核心概念
-- **过早完成声明**:agent 断言任务完成,但实际上存在未满足的正确性规范。核心问题:agent 依据代码层面的局部信心做判断,系统级正确性需要全局验证。
-- **置信度校准偏差**:agent 自报的完成信心与实际完成质量之间的系统性差距。对复杂多文件任务,这个偏差显著为正——agent 总是比实际做得更自信。就像学生考完试估分总是偏高。
-- **终止标准**:一组明确的、可执行的判定条件,定义在 harness 里。agent 必须满足所有条件才能声明完成。"完成"从主观判断变成了客观判定。
-- **验证-确认双闸门**:第一层验证检查"代码是否正确实现了指定行为";第二层确认检查"系统级行为是否满足端到端需求"。两层都通过才算完成。
-- **运行时反馈信号**:来自程序执行的日志、进程状态、健康检查。这是 harness 判定完成质量的客观基础。
+- **过早完成声明**:agent 断言任务完成,但实际上存在未满足的正确性规范。问题出在 agent 依据代码层面的局部信心做判断,而系统级正确性需要全局验证。
+- **置信度校准偏差**:agent 自报的完成信心与实际完成质量之间存在系统性差距。复杂多文件任务中,这个偏差显著为正,agent 总是比实际做得更自信。
+- **终止标准**:一组明确的、可执行的判定条件,定义在 harness 里。agent 必须满足所有条件才能声明完成,"完成"从主观判断变成了客观判定。
+- **验证-确认双闸门**:第一层验证检查代码是否正确实现了指定行为,第二层确认检查系统级行为是否满足端到端需求,两层都通过才算完成。
+- **运行时反馈信号**:来自程序执行的日志、进程状态、健康检查,这是 harness 判定完成质量的客观基础。
- **完成优先级约束**:先验证功能正确性,再处理性能,最后管风格。核心功能没验证通过之前,不许做重构。
## 单元测试通过 ≠ 任务完成
-这是最常见的陷阱,也是最危险的一个。agent 写了代码,跑了单元测试,全部绿色,然后说"做完了"。但单元测试的设计哲学——隔离被测单元、模拟依赖——恰好使其无法检测跨组件问题:
+这是最常见的陷阱,也是最危险的一个。agent 写了代码,跑了单元测试,全部绿色,然后说"做完了"。但单元测试的设计哲学是隔离被测单元、模拟依赖,这恰好使其无法检测跨组件问题:
-**接口不匹配**:渲染进程传给预加载脚本的文件路径是相对路径,但预加载脚本期望绝对路径。各自的单元测试都用了 mock,都通过了。只有端到端跑通时才发现问题。就像乐队里每个乐手各自练习都完美,但合在一起才发现定调不一样。
+**接口不匹配**:渲染进程传给预加载脚本的文件路径是相对路径,但预加载脚本期望绝对路径。各自的单元测试都用了 mock,都通过了,只有端到端跑通时才发现问题。
**状态传播错误**:数据库迁移改了表结构,但 ORM 的缓存层还持有旧结构的缓存条目。单元测试每次都是全新的 mock 环境,不会暴露这种跨层状态不一致。
-**环境依赖性**:代码在测试环境(一切 mock)行为正确,在真实环境因配置差异、网络延迟、服务不可用而失败。就像在排练室唱得很好,上台演出时音响设备出了问题。
+**环境依赖性**:代码在测试环境(一切 mock)行为正确,在真实环境因配置差异、网络延迟、服务不可用而失败。
### "顺便重构"是完成判定的毒药
-Claude Code 有一个常见行为模式:在核心功能还没验证通过时就开始重构代码、优化性能、改进风格。Knuth 说的"过早优化是万恶之源"在 agent 场景中有了新含义——重构会改变已完成验证和未完成验证之间的边界,可能破坏之前隐式正确的代码路径。就像你数学大题还没做完,就跑去把前面选择题的答案重新抄一遍格式——浪费时间不说,还可能抄错了。
+Claude Code 有一个常见行为模式:在核心功能还没验证通过时就开始重构代码、优化性能、改进风格。Knuth 说的"过早优化是万恶之源"在 agent 场景中有了新含义,重构会改变已完成验证和未完成验证之间的边界,可能破坏之前隐式正确的代码路径。
### 自我评价的系统性偏差
-Anthropic 在 2026 年的研究中发现了一个更深层的失败模式:**当 agent 被要求评估自己的工作时,它系统性地过度正面评价——即使人类观察者认为质量明显不达标。** 这就像让学生自己给自己判卷——对自己的答案总是特别宽容。
+Anthropic 在 2026 年的研究中发现了一个更深层的失败模式:**当 agent 被要求评估自己的工作时,它系统性地过度正面评价,即使人类观察者认为质量明显不达标。**
-这个问题在主观任务(如设计审美)上尤其严重——"布局是否精致"是一个判断题,agent 可靠地偏向正面。即使在有可验证结果的任务上,agent 也会因为判断失误而影响表现。
+这个问题在主观任务(如设计审美)上尤其严重,"布局是否精致"是一个判断题,agent 可靠地偏向正面。即使在有可验证结果的任务上,agent 也会因为判断失误而影响表现。
-解决方案不是让 agent "更客观"——同一个模型既生成又评估,内在地倾向对自己慷慨。**解决方案是把"干活的人"和"检查的人"分开。** 就像考试不能让学生自己批改自己的卷子——得有个独立的阅卷老师。
+解决方案不是让 agent "更客观"。同一个模型既生成又评估,内在地倾向对自己慷慨。**解决方案是把"干活的人"和"检查的人"分开。**
-一个独立的评估 agent,经过专门调校为"挑剔"之后,比让生成 agent 自我评估有效得多。Anthropic 的实验数据:
+一个独立的评估 agent,经过专门调校为"挑剔"之后,比让生成 agent 自我评估有效得多。Anthropic 的实验数据如下:
| 架构 | 运行时长 | 成本 | 核心功能是否可用 |
|------|---------|------|---------------|
| 单 agent 裸跑 | 20 分钟 | $9 | 否(游戏实体无法响应输入) |
| 三 agent(planner + generator + evaluator) | 6 小时 | $200 | 是(游戏可以正常游玩) |
-这是同一个模型(Opus 4.5),同一段提示词("做一个 2D 复古游戏编辑器")。区别只在 harness——从"裸奔"到"planner 扩展需求 → generator 逐功能实现 → evaluator 用 Playwright 实际点击测试"。
+这是同一个模型(Opus 4.5),同一段提示词("做一个 2D 复古游戏编辑器")。区别只在 harness:从"裸奔"到"planner 扩展需求 → generator 逐功能实现 → evaluator 用 Playwright 实际点击测试"。
> 来源:[Anthropic: Harness design for long-running application development](https://www.anthropic.com/engineering/harness-design-long-running-apps)
-## 怎么防止提前交卷
+## 怎么防止过早声明完成
### 1. 外部化终止判定
-完成判定不应该由 agent 自己做。harness 独立执行终止校验,输入是运行时信号,不是 agent 的置信度。在 CLAUDE.md 里写清楚:
+完成判定不应该由 agent 自己做。harness 独立执行终止校验,输入是运行时信号,不是 agent 的置信度。在 CLAUDE.md 里可以写清楚:
```
## 完成定义
@@ -95,13 +93,13 @@ Anthropic 在 2026 年的研究中发现了一个更深层的失败模式:**
### 2. 构建三层终止校验
-- **第一层:语法与静态分析**。成本最低,信息量最小,但必须通过。这是最低限度的检查——字都没写错才能往下看。
-- **第二层:运行时行为验证**。测试执行、应用启动检查、关键路径验证。这是核心完成证据。不仅要写了,还要能跑。
-- **第三层:系统级确认**。端到端测试、集成验证、用户场景模拟。防止过早声明的最后一道防线。不仅要能跑,还要跑对。
+- **第一层:语法与静态分析**。成本最低,信息量最小,但必须通过。这是最低限度的检查,字都没写错才能往下看。
+- **第二层:运行时行为验证**。测试执行、应用启动检查、关键路径验证。这是核心完成证据,不仅要写了,还要能跑。
+- **第三层:系统级确认**。端到端测试、集成验证、用户场景模拟。这是防止过早声明的最后一道防线,不仅要能跑,还要跑对。
-### 3. 为 agent 设计好的"红笔批注"
+### 3. 给 agent 提供可操作的错误反馈
-OpenAI 在 Codex 实践中提出了一个特别有效的模式:**给 agent 写的错误消息要包含修复指导**。不要像阅卷老师只画个大红叉,要像好老师一样在旁边写上"这里应该怎么改"。不要用 `"Test failed"`,而用 `"Test failed: POST /api/reset-password returned 500. Check that the email service config exists in environment variables. The template file should be at templates/reset-email.html."` 这种具体的、可操作的反馈让 agent 能自我修正,而不需要人类介入。
+OpenAI 在 Codex 实践中提出了一个特别有效的模式:**给 agent 写的错误消息要包含修复指导**。不要只告诉它"错了",而是明确指出哪里错了、应该怎么改。不要用 `"Test failed"`,而用 `"Test failed: POST /api/reset-password returned 500. Check that the email service config exists in environment variables. The template file should be at templates/reset-email.html."` 这种具体的、可操作的反馈让 agent 能自我修正,而不需要人类介入。
### 4. 捕获运行时信号
@@ -115,19 +113,19 @@ OpenAI 在 Codex 实践中提出了一个特别有效的模式:**给 agent 写
**任务**:实现用户密码重置功能。涉及数据库操作、邮件发送和 API 端点修改。
-**提前交卷路径**:agent 修改数据库 schema、编写 API 端点、添加邮件模板、跑单元测试(通过)、声明完成。卷子写得满满当当。
+**提前交卷路径**:agent 修改数据库 schema、编写 API 端点、添加邮件模板、跑单元测试(通过)、声明完成。看起来做了很多,但关键环节都跳过了。
-**实际扣分项**:(1) 端到端流程未测试——重置链接的实际发送和验证未确认。(2) 数据库迁移在部分执行后失败,导致 schema 不一致。(3) 邮件服务配置在目标环境中缺失。
+**实际遗漏项**:(1) 端到端流程未测试,重置链接的实际发送和验证未确认。(2) 数据库迁移在部分执行后失败,导致 schema 不一致。(3) 邮件服务配置在目标环境中缺失。
-**harness 介入**:终止校验强制执行——(1) 启动完整应用验证重置端点可访问;(2) 执行完整重置流程;(3) 验证数据库状态一致性。所有缺陷在会话内被发现,节省了 5-10 倍的后续修复成本。独立阅卷老师批出了真正的问题。
+**harness 介入**:终止校验强制执行,(1) 启动完整应用验证重置端点可访问;(2) 执行完整重置流程;(3) 验证数据库状态一致性。所有缺陷在会话内被发现,节省了 5-10 倍的后续修复成本。
## 关键要点
-- **agent 系统性地过度自信**——置信度校准偏差是客观存在的。卷子写满了不代表做对了。
-- **完成判定必须外部化**——harness 独立验证,不信任 agent 的"感觉"。不能让学生自己批自己的卷子。
-- **三层校验缺一不可**——语法通过、行为通过、系统通过,层层递进。
-- **错误消息要像好老师的红笔批注**——包含具体修复步骤,让 agent 能自我修正。
-- **核心功能验证通过之前不许重构**——完成优先级约束是防止过早优化的关键。
+- **agent 系统性地过度自信**,置信度校准偏差是客观存在的。代码写完了不代表做对了。
+- **完成判定必须外部化**,harness 独立验证,不信任 agent 的"感觉"。
+- **三层校验缺一不可**:语法通过、行为通过、系统通过,层层递进。
+- **错误消息要包含具体修复步骤**,让 agent 能自我修正,而不是只告诉它"错了"。
+- **核心功能验证通过之前不许重构**,完成优先级约束是防止过早优化的关键。
## 延伸阅读
@@ -142,4 +140,4 @@ OpenAI 在 Codex 实践中提出了一个特别有效的模式:**给 agent 写
2. **校准偏差测量**:选 10 个不同类型的编码任务,记录 agent 的自报完成信心和实际完成质量。计算偏差值,分析它和任务复杂度的关系。
-3. **多层防御实验**:对同一组任务跑三种配置——(a) 仅静态分析,(b) 加单元测试,(c) 完整三层校验。比较过早完成声明的比例和未捕获缺陷的数量。
+3. **多层防御实验**:对同一组任务跑三种配置:(a) 仅静态分析,(b) 加单元测试,(c) 完整三层校验。比较过早完成声明的比例和未捕获缺陷的数量。
diff --git a/docs/zh/lectures/lecture-10-why-end-to-end-testing-changes-results/index.md b/docs/zh/lectures/lecture-10-why-end-to-end-testing-changes-results/index.md
index d68568a..10ddcaf 100644
--- a/docs/zh/lectures/lecture-10-why-end-to-end-testing-changes-results/index.md
+++ b/docs/zh/lectures/lecture-10-why-end-to-end-testing-changes-results/index.md
@@ -5,31 +5,29 @@
# 第十讲. 跑通完整流程才算真正验证
-你让 agent 给 Electron 应用加一个文件导出功能。它写了渲染进程组件、预加载脚本、服务层逻辑,每个组件的单元测试都通过了。agent 说"做完了"。你实际一点击导出按钮——文件路径格式不对、进度条没反应、大文件导出时内存泄漏。5 个组件边界缺陷,单元测试一个都没发现。
+你让 agent 给 Electron 应用加一个文件导出功能。它写了渲染进程组件、预加载脚本、服务层逻辑,每个组件的单元测试都通过了。agent 说"做完了"。你实际一点击导出按钮,文件路径格式不对、进度条没反应、大文件导出时内存泄漏。5 个组件边界缺陷,单元测试一个都没发现。
-这就像一个合唱团排练——每个声部单独唱的时候都完美,但合在一起的时候,女高音比男低音快了半拍,伴奏的调子和主旋律差了半个音。每个部分都"对"了,但整体跑调了。
-
-Google 的测试金字塔告诉我们:大量单元测试是基础,但如果你止步于此,就会系统性地漏掉组件交互问题。对于 AI 编码 agent 来说,这个问题更严重——agent 倾向于只跑最快的测试然后宣告完成。**只有端到端测试能证明系统级缺陷不存在**。
+每个部分单独看都"对"了,但拼在一起就出了问题。Google 的测试金字塔告诉我们,大量单元测试是基础,但如果你止步于此,就会系统性地漏掉组件交互问题。对于 AI 编码 agent 来说,这个问题更严重,因为 agent 倾向于只跑最快的测试然后宣告完成。**只有端到端测试能证明系统级缺陷不存在**。
## 单元测试的盲区
-单元测试的设计哲学是隔离——模拟依赖,专注被测单元。这个哲学使单元测试快速且精确,但也制造了系统性的盲区。就像合唱排练时每个声部戴着耳机对着伴奏唱——听着都挺好,但真正合在一起才发现问题:
+单元测试的设计哲学是隔离:模拟依赖,专注被测单元。这个哲学使单元测试快速且精确,但也制造了系统性的盲区。每个模块在隔离环境中表现完美,但真正拼在一起运行时才会暴露以下几类问题:
-**接口不匹配**:渲染进程传给预加载脚本的文件路径是相对路径,但预加载脚本期望绝对路径。各自的单元测试都用了 mock,都通过了。只有端到端跑通时才发现问题——就像两个声部各自练的时候都觉得节奏没问题,一合才发现一个用 4/4 拍一个用 3/4 拍。
+**接口不匹配**:渲染进程传给预加载脚本的文件路径是相对路径,但预加载脚本期望绝对路径。各自的单元测试都用了 mock,都通过了。只有端到端跑通时才发现问题。
-**状态传播错误**:数据库迁移改了表结构,但 ORM 的缓存层还持有旧结构的缓存条目。单元测试每次都是全新的 mock 环境,不会暴露这种跨层状态不一致。就像换了一首歌的歌词,但有人还在唱旧版本。
+**状态传播错误**:数据库迁移改了表结构,但 ORM 的缓存层还持有旧结构的缓存条目。单元测试每次都是全新的 mock 环境,不会暴露这种跨层状态不一致。
-**资源生命周期问题**:文件句柄、数据库连接、网络套接字的获取和释放跨越多个组件。单元测试为每个测试创建和销毁独立资源,不会暴露资源竞争或泄漏。就像排练时每个声部轮流用麦克风,但演出时所有声部同时上台——话筒不够用了。
+**资源生命周期问题**:文件句柄、数据库连接、网络套接字的获取和释放跨越多个组件。单元测试为每个测试创建和销毁独立资源,不会暴露资源竞争或泄漏。
-**环境依赖性**:代码在测试环境(一切 mock)行为正确,在真实环境因配置差异、网络延迟、服务不可用而失败。就像排练厅里唱得好好的,到了户外音乐节风一吹话筒一啸叫就全乱了。
+**环境依赖性**:代码在测试环境(一切 mock)行为正确,在真实环境因配置差异、网络延迟、服务不可用而失败。
## 端到端测试不仅改变结果,还改变行为
这是很多人没意识到的一点:当 agent 知道它的工作要过端到端测试时,它的编码行为会改变。
-1. **考虑组件交互**:写代码时会想"这个接口和上游怎么对接",而不是只关注单个函数。就像知道最终要合在一起唱,练习的时候就会注意听其他声部。
-2. **尊重架构边界**:有架构约束的系统里,端到端测试迫使 agent 遵守边界规则。就像乐谱上标注了"此处渐强",你得跟着来。
-3. **处理错误路径**:端到端测试通常包含故障场景,迫使 agent 考虑异常处理。就像排练时模拟了"话筒突然没声了"的情况,你知道该怎么做。
+1. **考虑组件交互**:写代码时会想"这个接口和上游怎么对接",而不是只关注单个函数。
+2. **尊重架构边界**:有架构约束的系统里,端到端测试迫使 agent 遵守边界规则。
+3. **处理错误路径**:端到端测试通常包含故障场景,迫使 agent 考虑异常处理。
## 测试金字塔与审查反馈提升
@@ -57,27 +55,27 @@ flowchart LR
Harness --> Stronger["以后再犯会第一时间报错"]
```
-OpenAI 在 Codex 工程实践中强调:**为 agent 写的错误消息必须包含修复指导**。不写 `"Direct filesystem access in renderer"`,而写 `"Direct filesystem access in renderer. All file operations must go through the preload bridge. Move this call to preload/file-ops.ts and invoke it via window.api."` 这把架构规则变成了自动修正的闭环。就像合唱排练时指挥不只说"你唱错了",而是说"这里你快了半拍,听一下女低音的节奏,在第 32 小节进入"。
+OpenAI 在 Codex 工程实践中强调:**为 agent 写的错误消息必须包含修复指导**。不写 `"Direct filesystem access in renderer"`,而写 `"Direct filesystem access in renderer. All file operations must go through the preload bridge. Move this call to preload/file-ops.ts and invoke it via window.api."` 这把架构规则变成了自动修正的闭环。错误消息不只是告诉你"出了什么问题",还要告诉你"该怎么改",让 agent 能够自主完成修正。
## 核心概念
-- **组件边界缺陷**:组件 A 和 B 各自单元测试通过,但它们的交互产生了不正确的行为。这是端到端测试最擅长捕获的问题类型——合唱里各声部单独都对但合起来跑调的那种。
+- **组件边界缺陷**:组件 A 和 B 各自单元测试通过,但它们的交互产生了不正确的行为。这是端到端测试最擅长捕获的问题类型。
- **测试充分性梯度**:单元测试能检测的缺陷 <= 集成测试能检测的缺陷 <= 端到端测试能检测的缺陷。每往上一层,检测能力增强。
-- **架构边界执行规则**:把架构文档里的规则(如"渲染进程不能直接访问文件系统")变成可执行的自动化检查。从"写在纸上"变成"跑在 CI 里"。
-- **审查反馈提升**:把重复出现的代码审查意见转化为自动化测试。每次发现重复问题就加一条规则,harness 会自动变强。就像合唱排练时指挥把常见的错误编成练习曲——下次再犯同样的错误,不用指挥说,练习曲自己就暴露了。
-- **面向 agent 的错误消息**:失败信息不只是说"出了什么问题",还要告诉 agent 具体怎么修。这把测试失败变成自我修正的反馈循环。
+- **架构边界执行规则**:把架构文档里的规则(如"渲染进程不能直接访问文件系统")变成可执行的自动化检查,从"写在纸上"变成"跑在 CI 里"。
+- **审查反馈提升**:把重复出现的代码审查意见转化为自动化测试。每次发现重复问题就加一条规则,harness 会自动变强。
+- **面向 agent 的错误消息**:失败信息不只是说"出了什么问题",还要告诉 agent 具体怎么修,把测试失败变成自我修正的反馈循环。
## 怎么做
### 0. 先定好架构边界,再写端到端测试
-端到端测试的前提是系统有清晰的边界。如果架构是一团面条,端到端测试只会证明"这团面条整体能跑",不会告诉你哪里违反了设计意图。就像合唱团如果连分声部都没分好,排练再多也是乱唱。
+端到端测试的前提是系统有清晰的边界。如果架构是一团面条,端到端测试只会证明"这团面条整体能跑",不会告诉你哪里违反了设计意图。
-OpenAI 的经验:**对 agent 生成的代码库,架构约束必须是第一天就建立的早期前置条件,不是等团队规模大了再考虑的事。** 原因很直接——agent 会复制仓库中已有的模式,即使那些模式是不均匀的或次优的。没有架构约束,agent 会在每次会话中引入更多偏差。
+OpenAI 的经验:**对 agent 生成的代码库,架构约束必须是第一天就建立的早期前置条件,不是等团队规模大了再考虑的事。** 原因很直接:agent 会复制仓库中已有的模式,即使那些模式是不均匀的或次优的。没有架构约束,agent 会在每次会话中引入更多偏差。
-OpenAI 采用了"分层领域架构"——每个业务领域被分成固定的层:Types → Config → Repo → Service → Runtime → UI。依赖方向严格向前,跨领域关注点通过显式的 Providers 接口进入。任何其他依赖都是禁止的,并且通过自定义 lint 机械执行。
+OpenAI 采用了"分层领域架构",每个业务领域被分成固定的层:Types → Config → Repo → Service → Runtime → UI。依赖方向严格向前,跨领域关注点通过显式的 Providers 接口进入。任何其他依赖都是禁止的,并且通过自定义 lint 机械执行。
-关键原则:**执行不变量,不微管实现。** 比如要求"数据在边界解析",但不规定用哪个库。错误消息要包含修复指导——不只是说"违规了",而是告诉 agent 具体怎么改。
+关键原则:**执行不变量,不微管实现。** 比如要求"数据在边界解析",但不规定用哪个库。错误消息要包含修复指导,不只是说"违规了",而是告诉 agent 具体怎么改。
> 来源:[OpenAI: Harness engineering: leveraging Codex in an agent-first world](https://openai.com/index/harness-engineering/)
@@ -114,15 +112,15 @@ FIX: Move file operations to src/preload/file-ops.ts and call via window.api.rea
### 4. 建立审查反馈提升流程
-每次在代码审查中发现新类型的 agent 错误,就把它变成自动化检查。一个月后你的 harness 会比月初强得多。就像合唱团的排练笔记——每次排练发现的问题都记下来,下次排练前先检查这些点。久而久之,常见错误越来越少,音乐越来越和谐。
+每次在代码审查中发现新类型的 agent 错误,就把它变成自动化检查。一个月后你的 harness 会比月初强得多。
## 实际案例
**任务**:在 Electron 应用中实现文件导出功能。涉及渲染进程 UI、预加载脚本文件系统代理、服务层数据转换。
-**各声部单独唱(单元测试通过)**:渲染组件测试(通过,mock 文件操作)、预加载脚本测试(通过,mock 文件系统)、服务层测试(通过,mock 数据源)。agent 声明完成。
+**单元测试阶段**:渲染组件测试(通过,mock 文件操作)、预加载脚本测试(通过,mock 文件系统)、服务层测试(通过,mock 数据源)。agent 声明完成。
-**合唱合在一起(端到端测试揭示的缺陷)**:
+**端到端测试揭示的缺陷**:
| 缺陷 | 描述 | 单元测试 | 端到端 |
|------|------|---------|--------|
@@ -132,15 +130,15 @@ FIX: Move file operations to src/preload/file-ops.ts and call via window.api.rea
| 权限问题 | 打包环境权限不同 | 未检测 | 检测 |
| 错误传播 | 服务层异常未到 UI 层 | 未检测 | 检测 |
-5 个缺陷全部被端到端测试捕获,单元测试一个都没发现。代价是测试时间从 2 秒增加到 15 秒——在 agent 工作流里完全可以接受。每个声部单独唱得再好,也比不上一次完整的合唱排练。
+5 个缺陷全部被端到端测试捕获,单元测试一个都没发现。代价是测试时间从 2 秒增加到 15 秒,在 agent 工作流里完全可以接受。
## 关键要点
-- **单元测试对组件边界缺陷系统性盲视**——它们的隔离设计恰好使其无法检测交互问题。每个人唱得都对,不代表合唱不跑调。
-- **端到端测试不仅检测缺陷,还改变 agent 的编码行为**——让它更关注集成和边界。
-- **架构规则必须可执行**——不是写在文档里等人来看,而是每次提交自动检查。
-- **错误消息要面向 agent 设计**——包含"怎么修"的具体步骤,形成自我修正闭环。
-- **审查反馈提升让 harness 自动变强**——每个被捕获的缺陷类别都变成永久防线。
+- **单元测试对组件边界缺陷系统性盲视**:它们的隔离设计恰好使其无法检测交互问题。
+- **端到端测试不仅检测缺陷,还改变 agent 的编码行为**:让它更关注集成和边界。
+- **架构规则必须可执行**:不是写在文档里等人来看,而是每次提交自动检查。
+- **错误消息要面向 agent 设计**:包含"怎么修"的具体步骤,形成自我修正闭环。
+- **审查反馈提升让 harness 自动变强**:每个被捕获的缺陷类别都变成永久防线。
## 延伸阅读
diff --git a/docs/zh/lectures/lecture-11-why-observability-belongs-inside-the-harness/index.md b/docs/zh/lectures/lecture-11-why-observability-belongs-inside-the-harness/index.md
index 7667573..259bcbf 100644
--- a/docs/zh/lectures/lecture-11-why-observability-belongs-inside-the-harness/index.md
+++ b/docs/zh/lectures/lecture-11-why-observability-belongs-inside-the-harness/index.md
@@ -7,35 +7,35 @@
你让 agent 做一个功能,它跑了 20 分钟,改了一堆文件,然后告诉你"做完了但有两个测试失败"。你问它为什么失败,它说"不太确定,可能是时序问题"。你问它改了哪些关键路径,它说"让我看看代码……"。
-这不是 agent 能力不够,是你的 harness 没有给它装仪表盘。想象你在开一辆没有仪表盘的车——没有速度表、没有油量表、没有发动机故障灯。你能开,但你不知道开多快、还剩多少油、发动机是不是快爆了。技术再好的司机,蒙着眼也得出事。
+这种情况很常见,根源不在 agent 的能力,而在 harness 缺乏可观测性。agent 执行任务时,如果看不到运行时的实际状态,就只能凭猜测做决策。
-**没有可观测性,agent 在不确定状态中做决策,评估变成主观判断,重试变成盲目摸索。** OpenAI 和 Anthropic 都将可靠性定义为证据问题——harness 必须以可指导下一步决策的形式暴露运行时行为和评估信号。
+**没有可观测性,agent 在不确定状态中做决策,评估变成主观判断,重试变成盲目摸索。** OpenAI 和 Anthropic 都将可靠性定义为证据问题,harness 必须以可指导下一步决策的形式暴露运行时行为和评估信号。
## 可观测性缺失的真实代价
-当 harness 缺乏可观测性时,四类问题系统性出现:
+当 harness 缺乏可观测性时,四类问题会系统性出现。
-**无法区分"正确"和"看似正确"**:一个函数在代码审查时看起来完全正确——语法对、逻辑通。但运行时因为边界条件处理错误,在特定输入下产生了不正确结果。只有运行时追踪能揭示实际执行路径偏离了预期。就像一个演员排练时台词全对了,但上台演出时灯光一打,表情和走位全都变了——你不看现场是发现不了的。
+**无法区分"正确"和"看似正确"**:一个函数在代码审查时看起来完全正确,语法对、逻辑通。但运行时因为边界条件处理错误,在特定输入下产生了不正确结果。只有运行时追踪能揭示实际执行路径偏离了预期。代码审查看的是"写了什么",运行时追踪看的是"实际跑了什么",两者缺一不可。
-**评估变成玄学**:没有评分标准和验收条件时,评估者(人或 agent)依赖隐式假设。同一个输出,不同评估者可能给出截然不同的评价。质量评估不可复现。就像体操比赛没有评分标准——这个裁判觉得你的动作优雅,那个裁判觉得你落地不稳,谁说了算?
+**评估变成玄学**:没有评分标准和验收条件时,评估者(人或 agent)只能依赖隐式假设。同一个输出,不同评估者可能给出截然不同的评价,质量评估不可复现。
-**重试变成盲猜**:agent 不知道为什么失败时,重试方向是随机的。它可能在错误的方向上反复尝试——修复了不相关的代码路径而忽略真正的故障根源。就像你开车发现车跑偏了,但你没有仪表盘——你猜是轮胎的问题换了轮胎,实际是方向盘的 alignment 出了问题。每次盲重试都消耗 token 和时间。
+**重试变成盲猜**:agent 不知道为什么失败时,重试方向是随机的。它可能在错误的方向上反复尝试,修复了不相关的代码路径而忽略真正的故障根源。每次盲重试都消耗 token 和时间。
-**会话交接信息断崖**:当未完成的工作移交给下一个会话时,缺乏可观测性意味着新会话必须从零诊断系统状态。Anthropic 的长期运行 agent 观察表明,这种重复诊断可能占会话总时间的 30-50%。就像换班司机上车发现没有交接记录——他得花半小时检查油量、胎压、发动机状态才能出发。
+**会话交接信息断崖**:当未完成的工作移交给下一个会话时,缺乏可观测性意味着新会话必须从零诊断系统状态。Anthropic 的长期运行 agent 观察表明,这种重复诊断可能占会话总时间的 30-50%。
## Claude Code 的真实场景
-想象一个使用"计划者-生成者-评估者"三角色工作流的 harness,执行"为应用添加暗色模式"任务。
+来看一个使用"计划者-生成者-评估者"三角色工作流的 harness,执行"为应用添加暗色模式"任务。
-**没有仪表盘**:计划者输出模糊描述。生成者根据模糊描述实现暗色模式,但和计划者的隐式预期不一致。评估者基于自己的隐式标准拒绝,但说不出具体哪里不对——"感觉不太对"。生成者基于模糊拒绝理由盲重试。循环 3-4 次,总耗时约 45 分钟,最终勉强产出。
+**没有可观测性**:计划者输出模糊描述,生成者根据模糊描述实现暗色模式,但和计划者的隐式预期不一致。评估者基于自己的隐式标准拒绝,但说不出具体哪里不对,只有一句"感觉不太对"。生成者基于模糊拒绝理由盲重试,循环 3-4 次,总耗时约 45 分钟,最终勉强产出。
-**有完整仪表盘**:计划者输出冲刺合同——列明要改哪些组件、每个组件的验证标准、排除项(不处理打印样式)。生成者按合同实现。运行时可观测性记录每个组件的样式加载和应用过程。评估者用评分标准逐维度评估,附具体证据引用——"按钮颜色对比度不足(WCAG AA 标准 4.5:1,实测 2.1:1)"。一次迭代出高质量结果,总耗时约 15 分钟。
+**有完整可观测性**:计划者输出冲刺合同,列明要改哪些组件、每个组件的验证标准、排除项(不处理打印样式)。生成者按合同实现,运行时可观测性记录每个组件的样式加载和应用过程。评估者用评分标准逐维度评估,附具体证据引用:"按钮颜色对比度不足(WCAG AA 标准 4.5:1,实测 2.1:1)"。一次迭代出高质量结果,总耗时约 15 分钟。
-效率差 3 倍。区别只在可观测性——给车装上了仪表盘。
+效率差 3 倍,区别只在可观测性。
## 双层可观测性
-可观测性不是"多打点日志"那么简单。它分两层,缺一不可:
+可观测性不是"多打点日志"那么简单。它分两层,缺一不可。
```mermaid
flowchart LR
@@ -47,28 +47,28 @@ flowchart LR
Verdict --> Generator
```
-**运行时可观测性**:系统层的信号——日志、追踪、进程事件、健康检查。回答"系统做了什么"。这是你车上的仪表盘——速度、油量、发动机温度。
+**运行时可观测性**:系统层的信号,包括日志、追踪、进程事件、健康检查,回答"系统做了什么"。
-**过程可观测性**:harness 决策工件的可见性——计划、评分标准、验收条件。回答"为什么这个变更应该被接受"。这是你的导航系统——不光知道现在在哪,还知道为什么走这条路。
+**过程可观测性**:harness 决策工件的可见性,包括计划、评分标准、验收条件,回答"为什么这个变更应该被接受"。
## 核心概念
-- **运行时可观测性**:系统层的信号——日志、追踪、进程事件、健康检查。回答"系统做了什么"。
-- **过程可观测性**:harness 决策工件的可见性——计划、评分标准、验收条件。回答"为什么这个变更应该被接受"。
-- **任务轨迹**:一个任务从开始到完成的完整决策路径记录,类似分布式系统中的请求追踪。agent 的每一步操作及其上下文都被记录。就像黑匣子——出了问题可以回放完整过程。
-- **冲刺合同**:编码开始前协商的短期协议——明确任务范围、验证标准、排除项。是过程可观测性的核心工具。
-- **评估评分标准**:把质量评估从主观判断变成基于证据的结构化评分。使不同评估者对同一输出产生相似结论。就像体操比赛的评分标准——有了它,十个裁判的分才不会差太远。
+- **运行时可观测性**:系统层的信号,包括日志、追踪、进程事件、健康检查,回答"系统做了什么"。
+- **过程可观测性**:harness 决策工件的可见性,包括计划、评分标准、验收条件,回答"为什么这个变更应该被接受"。
+- **任务轨迹**:一个任务从开始到完成的完整决策路径记录,类似分布式系统中的请求追踪。agent 的每一步操作及其上下文都被记录,出了问题可以回放完整过程。
+- **冲刺合同**:编码开始前协商的短期协议,明确任务范围、验证标准、排除项。是过程可观测性的核心工具。
+- **评估评分标准**:把质量评估从主观判断变成基于证据的结构化评分,使不同评估者对同一输出产生相似结论。
- **双层可观测性**:系统层和过程层同时设计、相互增强。运行时信号解释行为,过程工件解释意图。
## 为什么 agent 自己解决不了这个问题
你可能在想:"agent 不能自己打日志吗?" 问题在于:
-1. **agent 不知道它不知道什么**——它不会主动记录自己没意识到需要的信号。就像你不知道油箱快漏了的时候,你不会去看油量表——因为你压根不知道该看。
-2. **日志格式不统一**——不同会话用不同的日志格式,无法做系统化分析。就像十个司机各写各的交接记录,格式都不一样,下一个司机看不懂。
-3. **过程可观测性不是日志能解决的**——冲刺合同和评分标准是结构化的工件,需要 harness 层面的支持。不是多 print 几行就能搞定的。
+1. **agent 不知道它不知道什么**:它不会主动记录自己没意识到需要的信号。没有 harness 层面的约束,agent 只会记录它认为重要的东西,而它认为重要的东西往往不够。
+2. **日志格式不统一**:不同会话用不同的日志格式,无法做系统化分析。
+3. **过程可观测性不是日志能解决的**:冲刺合同和评分标准是结构化的工件,需要 harness 层面的支持,不是多 print 几行就能搞定的。
-## 怎么装仪表盘
+## 怎么搭建可观测性
### 1. 在 harness 里内置运行时信号采集
@@ -82,7 +82,7 @@ flowchart LR
### 2. 实施冲刺合同
-在每个任务开始前,生成者和评估者(可能是同一个 agent 的不同调用)协商一份合同——就像施工队开工前签的施工协议:
+在每个任务开始前,生成者和评估者(可能是同一个 agent 的不同调用)协商一份合同,明确这次要做什么、怎么做算通过:
```markdown
# 冲刺合同: 暗色模式支持
@@ -104,7 +104,7 @@ flowchart LR
### 3. 建立评估评分标准
-把"好不好"变成可量化的评分——就像给体操比赛定评分标准:
+把"好不好"变成可量化的评分:
```markdown
# 评分标准
@@ -137,24 +137,24 @@ Anthropic 在 2026 年 3 月发布了一项系统性的 harness 实验。他们
三个 agent 各司其职,每个都有明确的可观测性角色:
-**Planner(规划者)**:接收一段 1-4 句话的用户需求,扩展成完整产品规格。被要求"大胆设定范围"并且"专注于产品上下文和高层技术设计,而不是详细的技术实现"。原因是:如果 planner 过早指定了粒度技术细节且搞错了,错误会级联到下游实现。更好的做法是约束交付物,让 agent 在执行中自己找到路径。就像建筑设计师只画效果图和结构图,不规定每块砖怎么砌。
+**Planner(规划者)**:接收一段 1-4 句话的用户需求,扩展成完整产品规格。被要求"大胆设定范围"并且"专注于产品上下文和高层技术设计,而不是详细的技术实现"。原因是:如果 planner 过早指定了粒度技术细节且搞错了,错误会级联到下游实现。更好的做法是约束交付物,让 agent 在执行中自己找到路径。
-**Generator(生成者)**:按 sprint 逐个功能实现。每个 sprint 前和 evaluator 协商一份 sprint 合同——约定这个功能块"做完"的标准。然后按合同实现,自评后交给 QA。按合同施工,不按感觉施工。
+**Generator(生成者)**:按 sprint 逐个功能实现。每个 sprint 前和 evaluator 协商一份 sprint 合同,约定这个功能块"做完"的标准。然后按合同实现,自评后交给 QA。
-**Evaluator(评估者)**:用 Playwright MCP 像用户一样点击运行中的应用,测试 UI 功能、API 端点和数据库状态。对每个 sprint 按四个维度评分——产品深度、功能性、视觉设计和代码质量。每个维度有硬性阈值,任一不达标则 sprint 失败,generator 收到详细反馈后修复。就像验收工程师拿着验收标准逐项检查——不达标就打回去重做。
+**Evaluator(评估者)**:用 Playwright MCP 像用户一样点击运行中的应用,测试 UI 功能、API 端点和数据库状态。对每个 sprint 按四个维度评分:产品深度、功能性、视觉设计和代码质量。每个维度有硬性阈值,任一不达标则 sprint 失败,generator 收到详细反馈后修复。
-QA 第 1 轮反馈的示例——"这是一个视觉上令人印象深刻的应用,AI 集成工作良好,但核心 DAW 功能有几个是展示性的,没有交互深度:剪辑不能拖拽/移动,没有乐器 UI 面板(合成器旋钮、鼓垫),没有视觉效果编辑器(EQ 曲线、压缩器仪表)"。这些不是边缘情况——它们是让 DAW 可用的核心交互。具体的、有证据的反馈,不是"感觉不对"。
+QA 第 1 轮反馈的示例:"这是一个视觉上令人印象深刻的应用,AI 集成工作良好,但核心 DAW 功能有几个是展示性的,没有交互深度:剪辑不能拖拽/移动,没有乐器 UI 面板(合成器旋钮、鼓垫),没有视觉效果编辑器(EQ 曲线、压缩器仪表)"。这些不是边缘情况,它们是让 DAW 可用的核心交互。具体的、有证据的反馈,不是"感觉不对"。
-Evaluator 不是一开始就这么强。早期版本会识别出合理的问题,然后说服自己这些问题不严重,最终批准工作。调校方式是:读 evaluator 的日志,找到它的判断和人类判断分叉的地方,更新 QA 的 prompt 解决那些问题。经过几轮这种开发循环,evaluator 的评分才变得合理。就像训练一个新验收工程师——一开始他太宽容,出了几次事故后学会了严格。
+Evaluator 不是一开始就这么强。早期版本会识别出合理的问题,然后说服自己这些问题不严重,最终批准工作。调校方式是:读 evaluator 的日志,找到它的判断和人类判断分叉的地方,更新 QA 的 prompt 解决那些问题。经过几轮这种开发循环,evaluator 的评分才变得合理。
> 来源:[Anthropic: Harness design for long-running application development](https://www.anthropic.com/engineering/harness-design-long-running-apps)
## 关键要点
-- **可观测性是 harness 的架构属性**——不是事后添加的功能,而是设计时必须考虑的核心能力。仪表盘不是可选配件,是出厂标配。
-- **双层可观测性缺一不可**——运行时信号解释"发生了什么",过程工件解释"为什么这样做"。速度表和导航系统各有各的用处。
-- **冲刺合同前置对齐工作**——防止"生成者做了评估者因可预见原因立即拒绝的东西"。施工协议要在开工前签,不是完工后补。
-- **评分标准让评估可复现**——不同评估者对同一输出产生相似评分。有了评分标准,十个裁判的分才不会差太远。
+- **可观测性是 harness 的架构属性**:不是事后添加的功能,而是设计时必须考虑的核心能力。
+- **双层可观测性缺一不可**:运行时信号解释"发生了什么",过程工件解释"为什么这样做"。
+- **冲刺合同前置对齐工作**:防止"生成者做了评估者因可预见原因立即拒绝的东西"。
+- **评分标准让评估可复现**:不同评估者对同一输出产生相似评分。
- **可观测性缺失导致 30-50% 的会话时间浪费在重复诊断上**。
## 延伸阅读
diff --git a/docs/zh/lectures/lecture-12-why-every-session-must-leave-a-clean-state/index.md b/docs/zh/lectures/lecture-12-why-every-session-must-leave-a-clean-state/index.md
index 0483de8..d468e88 100644
--- a/docs/zh/lectures/lecture-12-why-every-session-must-leave-a-clean-state/index.md
+++ b/docs/zh/lectures/lecture-12-why-every-session-must-leave-a-clean-state/index.md
@@ -5,31 +5,29 @@
# 第十二讲. 每次会话结束前都做好交接
-你的 agent 跑了一下午,改了 20 个文件,提交了代码,会话结束。下一个 agent 会话开始,一上来就发现:构建失败了、测试红了、临时调试文件到处都是、功能清单没更新、进度完全不清楚。新会话的前 30 分钟全花在"搞清楚上一个会话到底干了什么"上。
-
-这就像大学宿舍——你不倒垃圾,下一个室友进来就得替你收拾。他本来的计划是复习考试,结果先花半小时收拾你留下的烂摊子。更要命的是,收拾完了他也不想复习了——环境太差,心情也差。
+你的 agent 跑了一下午,改了 20 个文件,提交了代码,会话结束。下一个 agent 会话启动后,立刻发现构建失败、测试变红、临时调试文件散落各处、功能清单没有更新、进度完全不明。新会话的前 30 分钟全部花在"搞清楚上一个会话到底做了什么"上面。
OpenAI 和 Anthropic 都明确指出:**长期可靠性取决于操作纪律,不仅是单次运行的成功。** 每个会话结束时的状态质量,直接决定下一个会话的效率。
## 熵增是默认状态
-Lehman 的软件演化定律告诉我们:持续变更的系统,除非主动管理,否则复杂性必然增加。这对 AI 编码 agent 尤其成立——agent 每次会话都会引入变更,如果不在退出时清理,技术债务会指数级累积。宿舍不打扫,脏衣服和外卖盒只会越堆越多,不会自己消失。
+Lehman 的软件演化定律告诉我们,持续变更的系统除非主动管理,否则复杂性必然增加。这对 AI 编码 agent 尤其成立。agent 每次会话都会引入变更,如果不在退出时清理,技术债务会指数级累积。
-OpenAI 在 5 个月的 Codex 实验中观察到:**agent 会复制仓库中已有的模式——即使那些模式是不均匀的或次优的。** 随着时间的推移,这种复制必然导致漂移。就像宿舍里的公共区域——第一个人在桌上放了一个杯子,第二个人觉得"反正已经乱了"又放了一个,一周后桌上堆满了。
+OpenAI 在 5 个月的 Codex 实验中观察到:**agent 会复制仓库中已有的模式,即使那些模式是不均匀的或次优的。** 随着时间的推移,这种复制必然导致漂移。第一个人在公共区域放了一个杯子,第二个人觉得"反正已经乱了"又放了一个,一周后桌上就堆满了。代码库也一样。
-OpenAI 团队最初花每周五(20% 的工作时间)手动清理 "AI slop"。不出所料,这种方式不可扩展。就像宿舍每周大扫除一次——其他六天的脏乱差还是得忍。他们的解决方案是:
+OpenAI 团队最初每周五花 20% 的工作时间手动清理 "AI slop",但这种方式显然不可扩展。他们最终找到了系统性的解决方案:
1. **把"黄金原则"编码进仓库**:比如"优先使用共享工具包而非手写的 ad-hoc 辅助函数"(保持不变量集中)、"不要 YOLO 式地猜数据结构"(验证边界或依赖类型化 SDK)。这些原则是具体的、机械的、可自动检查的。
-2. **建立周期性的清理流程**:一组后台 Codex 任务定期扫描偏差,更新质量评分,开针对性的重构 PR。大多数可以在一分钟内审查并自动合并。就像宿舍安装了自动扫地机器人——不用你动手,定期清理。
-3. **人类品味捕获一次,持续执行**:审查意见、重构 PR、用户侧 bug 都被转化为文档更新或直接编码到工具中。当文档不够用时,把规则提升为代码。就像把宿舍公约从"口头约定"变成"贴在门上的检查表"。
+2. **建立周期性的清理流程**:一组后台 Codex 任务定期扫描偏差,更新质量评分,开针对性的重构 PR。大多数可以在一分钟内审查并自动合并。
+3. **人类品味捕获一次,持续执行**:审查意见、重构 PR、用户侧 bug 都被转化为文档更新或直接编码到工具中。当文档不够用时,就把规则提升为代码。
-这个机制就像垃圾回收——技术债是高息贷款,持续小额还清几乎总是比攒到一次性爆发好得多。
+技术债是高息贷款,持续小额还清几乎总是比攒到一次性爆发好得多。
> 来源:[OpenAI: Harness engineering: leveraging Codex in an agent-first world](https://openai.com/index/harness-engineering/)
-## 清洁状态:不只看地上有没有垃圾
+## 清洁状态:不只是"代码能编译"
-清洁状态不是单一的"代码能编译"。代码能无错构建——这是最基本的,下一个会话不应该先修构建错误。就像你搬出去的时候水电不能是断的。所有测试也得通过,包括会话之前就存在的测试——会话有责任不破坏已有功能。而且要在 CI 环境验证,不是"在我机器上通过"。
+清洁状态不是单一的"代码能编译"。代码能无错构建是最基本的要求,下一个会话不应该先修构建错误。所有测试也得通过,包括会话之前就存在的测试,会话有责任不破坏已有功能。而且要在 CI 环境验证,不是"在我机器上通过"。
```mermaid
flowchart LR
@@ -45,7 +43,7 @@ flowchart LR
Fix --> Build
```
-但这还不够。当前进度必须记录在机器可读的工件中——已完成的子任务和通过标准、进行中但未完成的子任务和当前状态、尚未开始的子任务。好的进度记录减少 60-80% 的会话启动诊断时间。调试日志、临时文件、注释掉的代码、TODO 标记这些临时工件得清理干净,它们增加下一个会话的认知负担。标准启动路径也必须可用——下一个会话能不能不人工干预就开始工作?环境初始化、代码库加载、上下文获取、任务选择,这些路径不能被破坏。
+但这还不够。当前进度必须记录在机器可读的工件中:已完成的子任务和通过标准、进行中但未完成的子任务和当前状态、尚未开始的子任务。好的进度记录可以减少 60-80% 的会话启动诊断时间。调试日志、临时文件、注释掉的代码、TODO 标记这些临时工件也得清理干净,因为它们会增加下一个会话的认知负担。标准启动路径同样必须可用。下一个会话能不能不人工干预就开始工作?环境初始化、代码库加载、上下文获取、任务选择,这些路径不能被破坏。
```mermaid
flowchart LR
@@ -61,20 +59,20 @@ flowchart LR
## 核心概念
-- **清洁状态**:会话结束时系统满足五个条件——构建通过、测试通过、进度已记录、无过时工件、启动路径可用。缺一个都不算"做完"。
-- **会话完整性**:类比数据库事务——要么全部提交并留下清洁状态,要么回滚到上一致状态。没有中间地带。
-- **质量文档**:对每个模块的质量等级做持续记录的活跃工件。不是一次性评估,而是跟踪代码库是变强了还是变弱了。
-- **清理循环**:定期的维护会话,目标是系统性减少代码库中的熵。不是紧急修复,而是常规运维——就像宿舍的每周值日表。
-- **harness 简化**:随着模型能力提升,定期移除不再必要的 harness 组件。今天必要的约束,三个月后可能是多余的开销。
-- **幂等清理**:清理操作无论执行多少次都产生相同结果。确保清理在失败重试场景中仍然安全。
+- **清洁状态**:会话结束时系统需要满足五个条件:构建通过、测试通过、进度已记录、无过时工件、启动路径可用。缺一个都不算"做完"。
+- **会话完整性**:可以类比数据库事务,要么全部提交并留下清洁状态,要么回滚到上一个一致状态,没有中间地带。
+- **质量文档**:对每个模块的质量等级做持续记录的活跃工件。它不是一次性评估,而是跟踪代码库到底是变强了还是变弱了。
+- **清理循环**:定期的维护会话,目标是系统性减少代码库中的熵。不是紧急修复,而是常规运维。
+- **harness 简化**:随着模型能力提升,定期移除不再必要的 harness 组件。今天必要的约束,三个月后可能就是多余的开销。
+- **幂等清理**:清理操作无论执行多少次都产生相同结果,确保清理在失败重试场景中仍然安全。
## "以后再清理"是永远不清理
-最常见的心理陷阱是"这次来不及清理了,下次再弄"。但下次的 agent 不知道你上次留下了什么——它看到的是一堆混乱的代码和不确定的状态。它会花大量时间推断"这堆代码里哪些是有意的,哪些是临时的"。
+最常见的心理陷阱是"这次来不及清理了,下次再弄"。但下次的 agent 并不知道你上次留下了什么,它看到的只是一堆混乱的代码和不确定的状态。它会花大量时间推断"这堆代码里哪些是有意的,哪些是临时的"。
-更糟的是,每个会话都有自己的任务目标。新会话来的时候是要做新功能的,不是来清理上一个会话的烂摊子的。它会忽略混乱直接开始新工作,然后在混乱的基础上引入更多混乱。这是熵增的正反馈循环——就像宿舍越乱你越不想收拾,越不收拾越乱,最后谁都不想回宿舍了。
+更糟的是,每个会话都有自己的任务目标。新会话来的时候是要做新功能的,不是来清理上一个会话遗留问题的。它会忽略混乱直接开始新工作,然后在混乱的基础上引入更多混乱。这是一个熵增的正反馈循环。
-数据为证。一个使用 agent 持续开发 12 周的项目,没有清洁策略的情况下:
+数据可以说明问题。一个使用 agent 持续开发 12 周的项目,没有清洁策略的情况下:
- 第 1 周:构建通过率 100%,测试通过率 100%,新会话启动 5 分钟
- 第 4 周:构建 95%,测试 92%,启动 15 分钟
@@ -86,13 +84,13 @@ flowchart LR
- 第 1 周:100%,100%,5 分钟
- 第 12 周:97%,95%,9 分钟
-12 周后,构建通过率差 29 个百分点,新会话启动时间差 85%。这不是理论推导,是实际可观测到的差异。每周不倒垃圾的宿舍和每周倒垃圾的宿舍,12 周后的差距是惊人的。
+12 周后,构建通过率差 29 个百分点,新会话启动时间差 85%。这不是理论推导,是实际可观测到的差异。
## 怎么做
### 1. 清洁状态是完成的必要条件
-在 harness 里明确定义:**会话完成 = 任务通过验证 AND 清洁状态检查通过。** 缺任何一个,会话不算完成。在 CLAUDE.md 里写:
+在 harness 里明确定义:**会话完成 = 任务通过验证 AND 清洁状态检查通过。** 缺任何一个,会话都不算完成。在 CLAUDE.md 里可以这样写:
```
## 会话退出检查清单
@@ -107,13 +105,13 @@ flowchart LR
结合两种清理模式:
-**即时清理(每个会话结束时)**:清理本次会话创建的临时工件、更新功能清单状态、确保构建和测试通过。这是"引用计数式"清理——用完就清。就像吃完饭马上洗碗,不留到第二天。
+**即时清理(每个会话结束时)**:清理本次会话创建的临时工件、更新功能清单状态、确保构建和测试通过。这是"引用计数式"清理,用完就清。
-**定期清理(每周一次)**:全系统扫描——处理累积的结构性问题、更新质量文档、运行基准测试检测漂移。这是"追踪式"清理——定期做一次大扫除。
+**定期清理(每周一次)**:全系统扫描,处理累积的结构性问题、更新质量文档、运行基准测试检测漂移。这是"追踪式"清理,定期做一次全面维护。
### 3. 维护质量文档
-质量文档是对每个模块持续评分的活跃工件——就像宿舍的卫生检查评分表:
+质量文档是对每个模块持续评分的活跃工件:
```markdown
# 质量文档
@@ -133,23 +131,23 @@ flowchart LR
- 代码规范: 部分遵循
```
-新会话读这个文档就知道优先处理哪里。质量评分最低的模块先修。就像卫生检查表上标记了"需要重点打扫的区域"——下一个值日生知道重点在哪里。
+新会话读这个文档就知道优先处理哪里。质量评分最低的模块先修。
### 4. 定期简化 harness
-harness 里的每个组件之所以存在,是因为模型无法独立做好某件事。但随着模型改进,这些假设会过时。就像你大一的时候需要学长带着选课,到了大三你自己就知道怎么选了——学长的作用变小了,但有些事情你还是需要问。
+harness 里的每个组件之所以存在,是因为模型在某个方面无法独立做好。但随着模型改进,这些假设会过时。
Anthropic 的实验直接展示了这一点。他们最初的 harness 包含 sprint 拆分机制——把工作分成小块让 Sonnet 4.5 逐个完成。当 Opus 4.6 发布后,模型的原生能力已经可以自主处理工作分解,sprint 构造变成了不必要的开销。移除后,builder agent 能连续工作超过两小时而不会跑偏,反而更流畅。
但 evaluator 的情况不同。即使 Opus 4.6 能力更强,在任务接近模型能力边界时,evaluator 仍然提供了实际价值——捕获 generator 的遗漏功能和存根实现。这意味着 evaluator 不是一个固定的是/否决策,而是取决于任务难度相对于模型能力的位置。
-**推荐做法**:每月挑一个 harness 组件,暂时禁用它,跑基准任务。如果结果没退化,永久移除。如果退化了,恢复或用更轻量的替代。就像定期检查宿舍公约——大四了还在执行"每天 10 点熄灯"就不太合理了。
+**推荐做法**:每月挑一个 harness 组件,暂时禁用它,跑基准任务。如果结果没退化,永久移除。如果退化了,恢复或用更轻量的替代。
-一个更具体的原则:**随着模型改进,harness 的有趣组合不是变少了,而是移动了。** 以前必须解决的问题被模型能力覆盖了,但新的能力边界打开了以前不可能的 harness 设计。AI 工程师的工作是持续找到下一个有价值的组合。
+一个更具体的原则:**随着模型改进,harness 的有趣组合不是变少了,而是移动了。** 以前必须解决的问题被模型能力覆盖了,但新的能力边界打开了以前不可能的 harness 设计空间。AI 工程师的工作是持续找到下一个有价值的组合。
### 5. 清理操作必须幂等
-清理脚本要能安全地重复执行——就像打扫卫生,扫两遍比扫一遍更干净,但不会更脏:
+清理脚本要能安全地重复执行,多跑一次不会产生副作用:
```bash
# 幂等的清理操作
@@ -160,27 +158,27 @@ npm run test # 验证清理未破坏功能
### 6. 高吞吐量改变了 merge 哲学
-当 agent 的产出远超人类审查能力时,传统的 merge 哲学需要调整。OpenAI 团队的经验:在一个 agent 每天开 3.5 个 PR(且后来增加到更多)的环境里,最小化阻塞式 merge gate 是正确的。PR 应该短命。测试 flake 通常用后续运行解决,而不是无限期阻塞进度。在一个修正成本很低、等待成本很高的系统里,快速前进 + 快速修正是比缓慢确认更好的策略。
+当 agent 的产出远超人类审查能力时,传统的 merge 哲学需要调整。OpenAI 团队的经验:在一个 agent 每天开 3.5 个 PR(且后来增加到更多)的环境里,最小化阻塞式 merge gate 是正确的做法。PR 应该短命,测试 flake 通常用后续运行解决,而不是无限期阻塞进度。在一个修正成本很低、等待成本很高的系统里,快速前进加上快速修正是比缓慢确认更好的策略。
-**注意**:这在低产出环境里是不负责任的。但在 agent 产出远超人类注意力的环境里,这往往是正确的权衡。关键判断标准:**修正一个 bug 的平均成本 vs 等待人类审查一个 PR 的平均成本。** 前者低于后者时,快速合并是对的。
+**注意**:这在低产出环境里是不负责任的。但在 agent 产出远超人类注意力的环境里,这往往是正确的权衡。关键判断标准:**修正一个 bug 的平均成本 vs 等待人类审查一个 PR 的平均成本。** 当前者低于后者时,快速合并是对的。
## 实际案例
一个使用 agent 持续开发的 Electron 应用,12 周演化过程的对比数据:
-**无清洁策略(对照组)**——从不倒垃圾的宿舍:第 12 周,构建通过率 68%,测试通过率 61%,新会话启动 60+ 分钟,过时工件 103 个。
+**无清洁策略(对照组)**:第 12 周,构建通过率 68%,测试通过率 61%,新会话启动 60+ 分钟,过时工件 103 个。
-**有清洁策略(实验组)**——每天值日的宿舍:每个会话结束时执行完整清洁检查 + 每周清理循环。第 12 周,构建通过率 97%,测试通过率 95%,新会话启动 9 分钟,过时工件 11 个。
+**有清洁策略(实验组)**:每个会话结束时执行完整清洁检查,加上每周清理循环。第 12 周,构建通过率 97%,测试通过率 95%,新会话启动 9 分钟,过时工件 11 个。
-到第 12 周,实验组的构建通过率比对照组高 29 个百分点,测试通过率高 34 个百分点,新会话启动时间减少 85%。每天多花 5 分钟打扫卫生,12 周后省下了几十个小时的混乱时间。
+到第 12 周,实验组的构建通过率比对照组高 29 个百分点,测试通过率高 34 个百分点,新会话启动时间减少 85%。每个会话多花 5 分钟做清理,12 周下来省下了几十个小时的混乱时间。
## 关键要点
-- **清洁状态是会话完成的必要条件**——不是可选的善后工作,是"完成定义"的一部分。你不倒垃圾,下一个室友就得替你倒。
-- **五个维度缺一不可**——构建、测试、进度、工件、启动,每个都要显式检查。
-- **质量文档让代码库健康可追踪**——知道哪里在退化才能主动修复。卫生检查表不是形式主义,是让你知道哪块地还没拖。
-- **定期简化 harness**——随着模型能力提升,移除不再必要的约束。大四了就别执行大一的宿舍公约了。
-- **"以后再清理"等于永远不清理**——熵增是默认状态,只有主动的清洁操作才能对抗它。
+- **清洁状态是会话完成的必要条件**,不是可选的善后工作,而是"完成定义"的一部分。
+- **五个维度缺一不可**:构建、测试、进度、工件、启动,每个都要显式检查。
+- **质量文档让代码库健康可追踪**,知道哪里在退化才能主动修复。
+- **定期简化 harness**:随着模型能力提升,移除不再必要的约束。
+- **"以后再清理"等于永远不清理**。熵增是默认状态,只有主动的清洁操作才能对抗它。
## 延伸阅读