Rose
← 返回Back

首页Home / 文章Writing

AI + 工程AI & engineering2026-11-28

模块交给 AI,全局留给自己Modules to the AI, the big picture to me

学长提醒我要做模块化、端口化的开发。回头看自己的几个项目,我发现:不做好项目管理,AI 写得越快,屎山堆得越快。A senior student told me to build in modules with clear ports. Looking back at my own projects, I realised: without project management, the faster the AI writes, the faster the mess piles up.

学长的一句话One sentence from a senior student

今天一位学长跟我说:要做好模块化、端口化的开发。每个模块让 AI 自己去写、自己去审;系统和全局层面的东西,由我自己来把关。Today a senior student told me: build things in a modular way, with clear ports between the modules. Let the AI write and review each module by itself; the system-level, big-picture decisions are mine to own.

我听完的第一反应是:这正好对上了我最近踩过的好几个坑。我也越来越确定一件事:如果不做好项目管理这一步,AI 很容易写出屎山代码。My first reaction was that this explained several holes I’d fallen into recently. And it made me more sure of one thing: without project management, AI will very easily write you a mountain of spaghetti code.

这篇也算是对上一篇文章的接续。那篇最后我说,用 AI 做项目时,“想法”和“结果”之间是个黑箱,我不知道该在哪里插手。学长这句话给了我一个答案的雏形:在模块的边界上插手。This is also a follow-up to my last post, which ended with the “black box” between my idea and the AI’s result — I didn’t know where to step in. This advice gives me the start of an answer: step in at the boundaries between modules.

为什么 AI 特别容易写出屎山Why AI is especially good at making a mess

AI 写代码非常快。但速度是双向的:没有约束的时候,乱的速度也一样快。我总结了几个原因:AI writes code very fast. But speed cuts both ways: without constraints, the mess grows just as fast. Here’s why, as far as I can tell:

  • 只顾眼前这个需求。你让它加一个功能,它会用最快的方式让这个功能跑起来,不会主动考虑以后好不好改。每一步都局部最优,加起来就是全局混乱。It optimises for the request in front of it. Ask for a feature and it takes the quickest path to make it work, without asking whether it’ll be easy to change later. Every step is locally optimal; together they add up to chaos.
  • 重复造轮子。它看不到或记不住项目里已有的工具函数,同样的逻辑写三遍,每遍还略有不同。It reinvents the wheel. It can’t see, or doesn’t remember, helpers that already exist, so the same logic gets written three times — each slightly different.
  • 习惯打补丁,而不是改结构。遇到问题时,它更可能加一个 if 绕过去,而不是回头想设计是不是错了。It patches instead of restructuring. When something breaks, it’s more likely to add another if than to ask whether the design is wrong.
  • 对话之间没有记忆。这次定好的约定,换一个对话、换一个 agent 就不知道了。It has no memory between sessions. Whatever we agreed on in one conversation is gone in the next one, or with the next agent.

真实案例一:这个网站的导航丢了两次Case 1: this website lost its navigation twice

你现在看的这个网站,就是一个现成的例子。它有一部分页面是由一个 Python 生成器生成的,文章页则是手写的。好几个 AI agent 先后维护过它。The site you’re reading is a ready-made example. Some of its pages are produced by a Python generator; the articles are written by hand. Several AI agents have maintained it at different times.

问题出在这里:有的 agent 直接手改了生成出来的 HTML(比如在导航里加上“文章”),另一个 agent 后来重新跑了一遍生成器,手改的内容就被整体覆盖掉了。导航里的“文章”入口就这样丢过两次。还有一次,一个提交用旧的页面头部覆盖了 10 个页面,同样把导航弄丢了,第二天才发现。Here’s what happened: one agent edited the generated HTML directly (for example, adding “Writing” to the nav), and later another agent re-ran the generator, which overwrote the hand edits wholesale. The “Writing” link vanished from the nav twice that way. Another time, a single commit pasted an old page header over 10 pages and dropped the link again — nobody noticed until the next day.

每个 agent 单独看,做的事都“没错”:一个在加导航,一个在重新生成页面。错在没有人规定清楚:页面头部到底归谁管。同一份东西有两个来源,谁最后写,谁就赢。Looked at one by one, every agent did something “correct”: one added a nav item, the other regenerated pages. What was wrong was that nobody had decided who owns the page header. The same thing had two sources, and whoever wrote last won.

最后的解决办法不是“让 AI 更小心”,而是一个结构上的决定:把所有手改的内容都并进生成器,让生成器成为这些页面唯一的来源;再在交接文档里写明“生成出来的页面不许手改,文章页生成器不碰”。边界划清楚之后,这个问题就没再出现过。The fix wasn’t “make the AI more careful.” It was a structural decision: fold every hand edit into the generator so it becomes the single source for those pages, and write down in the handoff doc that generated pages must not be hand-edited, while article pages are off-limits to the generator. Once the boundary was clear, the problem stopped.

真实案例二:用文件代替记忆Case 2: files instead of memory

我平时和几个 AI agent 在同一个共享文件夹里协作,同一个项目经常由不同的 agent 接力完成,比如我的 Antigravity 用量面板,就是从 Codex 交接给 Claude 的。I work with several AI agents in one shared folder, and the same project is often passed from one agent to another — my Antigravity usage dashboard, for instance, was handed over from Codex to Claude.

为了解决“AI 没有记忆”的问题,我定了两条规矩:To deal with the “no memory” problem, I set two rules:

  • 每个项目都必须有一份交接文档:现在是什么状态、先读哪些文件、怎么运行、有哪些坑。新来的 agent 第一件事就是读它,改完再更新它。上面导航丢失的教训,就写在这个网站的交接文档里。Every project must have a handoff doc: its current state, which files to read first, how to run it, and the known traps. A new agent reads it first and updates it when done. The lesson about the lost navigation above is written in this site’s handoff doc.
  • 共同的约定写进一份约定文件,比如提交代码时用什么身份署名,哪些仓库只在本地、哪些要推到 GitHub。Shared conventions go in a conventions file — for example, which identity to sign commits with, and which repositories stay local versus get pushed to GitHub.

这其实也是一种“端口”:交接文档就是项目和下一个 agent 之间的接口。接口写清楚了,换谁来接手都不容易跑偏。In a way, this is also a “port”: the handoff doc is the interface between a project and whichever agent comes next. When that interface is clear, it matters much less who picks the work up.

真实案例三:模块边界该由人来定Case 3: a human should draw the module boundaries

在我的 Claude 堡垒项目里,我们打算加一个自检工具,用来检查被隔离的机器是不是真的隔离好了。最直接的写法是在那台机器上装好运行环境,直接跑检查脚本。In my Claude Fortress project, we planned a self-check tool to verify that an isolated machine is really isolated. The obvious approach would be to install a runtime on that machine and run a checking script there.

但这样做恰好违背了项目本身的目的:为了检查隔离,先往隔离的机器上装东西。最后定下的方案是拆成两个模块:目标机器上只负责收集信息,评估放到主机或离线页面上去做,两者之间只通过一份收集结果来交接。But that defeats the purpose of the project: installing things on an isolated machine in order to check its isolation. The design we settled on splits it into two modules: the target machine only collects information, and the evaluation happens on the host or in an offline page, with a single collected report passed between them.

每个模块内部怎么写,AI 都能做得很好。但“这里要切一刀”这个决定,来自对整个项目目标的理解,这正是学长说的“全局由我把关”。The AI can do a fine job inside each module. But the decision to “cut here” comes from understanding what the whole project is for — exactly the “big picture is mine” part of the advice.

我现在的做法How I work now

把这些合在一起,我现在用 AI 做项目大概是这样分工的:Putting it together, this is roughly how I split the work with AI now:

我负责My part

  • 开工前写一份架构说明:有哪些模块,每个模块管什么,模块之间的接口长什么样。这份文件由我拍板,放进 git。Write a short architecture note before starting: which modules exist, what each one is responsible for, and what the interfaces between them look like. I sign off on it, and it lives in git.
  • 规定“谁拥有什么”:每一份东西只能有一个来源。Decide who owns what: every piece of the project has exactly one source.
  • 验收时只看三件事:接口有没有被改,模块边界有没有被越过,测试有没有通过。Check three things on review: were interfaces changed, were module boundaries crossed, do the tests pass.

AI 负责The AI’s part

  • 以模块为单位接任务,任务要小而具体:不是“做一个用户系统”,而是“在这个模块里加一个函数,输入什么,输出什么”。Take tasks one module at a time, small and specific: not “build a user system,” but “add a function to this module that takes X and returns Y.”
  • 不许擅自改接口,要改先提出来,由我决定。Never change an interface on its own — propose it, and I decide.
  • 模块内部自己写、自己审,并用自动化测试证明它做对了。光说一句“我检查过了”不算数。Write and review the inside of the module, and prove it works with automated tests. “I checked it” doesn’t count.

一些习惯A few habits

  • 小步提交 git。AI 把东西改乱了,就直接回滚,不在烂代码上继续修。Commit in small steps. If the AI makes a mess, roll back instead of patching on top of it.
  • 每做完几个功能,专门花一轮让 AI 找重复代码和该拆的模块。只加不减,迟早会变成屎山。Every few features, spend a round just having the AI look for duplicated code and modules that should be split. Only ever adding things is how spaghetti happens.
  • 看到 AI 第二次、第三次往同一个地方加特殊判断,就停下来。这通常说明设计本身有问题,该我回到全局去想。When the AI adds a special case to the same spot for the second or third time, stop. It usually means the design is wrong, and it’s my job to go back to the big picture.

还要补的一课:全局判断从哪来The lesson I still need: where big-picture judgement comes from

说“全局由我把关”很容易,难的是我真的要懂全局。作为一个大一学生,我的架构经验还很少。上面三个案例里,有两个都是先出了问题,我才知道那里该有一条边界。Saying “the big picture is mine” is easy; the hard part is actually understanding it. As a first-year student, I don’t have much architecture experience yet. In two of the three cases above, I only learned a boundary belonged there after something broke.

所以我打算这样练:遇到需要做架构决定的时候,不让 AI 直接给一个方案,而是让它给两三种,分别说清楚好处和代价,由我来选,并且写下我为什么这么选。这样每一次把关,本身也是一次练习。So here’s how I plan to practise: whenever an architectural decision comes up, I won’t let the AI hand me one answer. I’ll ask for two or three options with their trade-offs, pick one myself, and write down why. That way every review is also practice.

AI 是一个执行力极强、但没有长期判断的队友。代码质量的上限,取决于我给它搭的框架有多清楚。AI is a teammate with enormous execution power and no long-term judgement. How good the code gets is capped by how clear the frame I build around it is.