跳到正文
DEV Community· Nic Flemmer·· 4 小時前AI 評分44

兩個編碼智能體應否同時編輯同一個檔案?

Should two coding agents ever edit the same file?

AI 導讀

開源應用 Styx 以警告而非檔案鎖處理多個編碼智能體修改同一檔案的情況,提示雙方先協調檔案負責者,並可互相傳訊息。若兩個分支合併至 main 時仍有衝突,衝突會交回造成衝突的智能體,並附上雙方意圖。文章亦探討應避免檔案重疊、在合併時處理衝突,還是鎖定檔案,以及如何處理 lockfile 和 migration。

正文

Nic Flemmer

Say you split a feature between two coding agents: one builds the /orders endpoint, the other builds the page that calls it. Each works on its own branch in its own copy of the repo, so neither can overwrite the other's files while they work.

The collisions come anyway, usually in the same few places: package.json, a lockfile, a migration, a route table.

In the tool I'm building I went for warnings rather than locks. When one agent changes a file the other has already changed, both chats get one line naming the other task. For those shared files the line is firmer and asks the two to agree on one owner first. The agents can also message each other, so they can settle it themselves. And if two branches still conflict when main comes in, the conflict goes back to the agent that made it, with both sides' intent.

The case for a hard lock is that it's simple: the first agent to touch a file owns it until it lands. The cost is that the second agent has to wait or work around a file it needs, and a lock held by an agent that's stuck blocks everyone.

So I'm curious how others handle it. If you run more than one agent on a codebase, do you split the work so files never overlap, let them collide and sort it out at merge time, or lock files? And what do you do about the shared ones, like lockfiles and migrations?

(I'm building Styx, an open-source app that does the warnings part.)

來源:DEV Community · dev.to