改动 AI 生成代码前要保存的 7 件事与交接模板
Before You Change One Line of AI-Generated Code, Save These 7 Things
作者提出在让 AI 修改代码前先做一次项目交接,列出 7 项内容:保存可回滚的工作版本、精确描述改动、写下预期行为、列出相关文件、记录已知问题、记录已尝试的失败方案、声明不可更改的约束。文末给出可复制的 AI_HANDOFF.md 模板,并提醒检查 diff、跑测试,失败时回到检查点而不是无限叠加修补。作者披露其团队开发 9xchat,该模板不依赖特定工具。
Before You Change One Line of AI-Generated Code, Save These 7 Things
Your app works. You ask AI for one small change.
Suddenly, the layout breaks, a button stops responding, and a feature you finished yesterday has disappeared.
So you paste the error into a fresh chat. The model suggests another fix. You try it.
Now you have two problems and no clear way back.
AI-assisted coding makes changes easy to generate. It does not automatically make them safe to apply.
Before your next change, spend five minutes creating a small project handoff. You don’t need a particular tool for this. A Markdown file in your repository works.
**
- Save the current working version**
Make sure you can undo the next change.
If you use Git, review your working tree and create a checkpoint commit containing only the intended files. Don’t accidentally include secrets, generated files, or unrelated changes.
If you don’t use version control yet, back up the project before editing it. Git is worth learning early.
A chat history is not a code backup.
2. Describe the exact change
“Improve this dashboard” leaves a lot open to interpretation.
Try:
Add a date filter above the activity table. Keep the existing layout and table behavior unchanged.
Give AI a boundary as well as a goal. A narrowly defined task is easier to review and test.
3. Write down the expected behavior
Describe what success looks like in terms someone can check.
For example:
When a user selects a start and end date:
- Show only activity within that range.
- Include both boundary dates.
- Display an empty state if nothing matches.
- Clearing the filter restores all activity.
This gives you a basis for tests instead of relying on “it looks right.”
4. Identify the relevant files
Provide the files involved in the behavior, not just the file where you noticed the problem.
For a filter, that might include the UI component, data-fetching logic, and existing tests.
If you’re unsure, ask AI to inspect the project and identify the relevant files before making edits. Review its proposed scope.
Avoid sharing credentials, private user data, or production secrets.
5. List the known issues
Not every problem appeared because of the latest change.
Record existing bugs so you can distinguish a regression from something that was already broken.
Known issues:
- Mobile table overflow already exists.
- Loading state needs improvement.
- Export is not implemented.
This also helps prevent the model from expanding a small task into an unsolicited cleanup project.
6. Record what you already tried
A failed approach is useful information.
Instead of saying “we tried that,” explain the attempt and the result:
Tried:
Filtering after pagination.
Result:
Some matching records were omitted because only the current page
was being filtered.
Decision:
Apply the filter before pagination.
Keep observations separate from guesses. “This request returned a 500” is evidence. “The database must be broken” is a hypothesis.
7. Say what must not change
Protect the decisions that matter:
- Public API behavior
- Authentication rules
- Database schema
- Existing dependencies
- Unrelated UI components
These aren’t guarantees. You still need to inspect the diff. But explicit constraints make it easier to spot when a proposed fix goes beyond the task.
A copyable project handoff
Save this as AI_HANDOFF.md, or keep it wherever your team maintains project notes.
Current task
Working checkpoint
Commit or backup:
Requested change
One specific outcome:
Expected behavior
-
Relevant files
Known issues
Previous attempts
- Attempt:
- Observed result:
- Decision:
Constraints
What must not change:
Verification
Tests and manual checks to run:
Keep it short. Update it when the work changes.
An outdated handoff can mislead an AI just as easily as an incomplete prompt.
Where knowledge bases, skills, and agents help
Once you have reliable project information, workspace features can make it easier to use.
A knowledge base can keep requirements and decisions accessible. A skill can define a repeatable review process, such as checking regressions and missing tests before suggesting stylistic changes. An agent can work through steps such as inspecting files, proposing a change, and helping verify the result.
But none of those replaces a recoverable code checkpoint or your review of the diff.
Disclosure: Our team at 123sudo builds 9xchat. Its knowledge base, separate memory scopes, skills, and agentic workflows are designed to help keep relevant context available across tasks and models. The handoff above is useful whether you use our workspace or something else.
**
Before you accept the change**
Check the diff. Run the relevant tests. Exercise the main workflow.
If something fails, return to the checkpoint rather than stacking speculative fixes indefinitely.
The goal isn’t to write a perfect prompt. It’s to make each change understandable, reviewable, and reversible.
**
Before your next AI-generated edit, copy the handoff template and fill it in for one real task.**
ai, #programming, #beginners,
来源:Google AI:DEV 作者专属(RSS) · dev.to
