跳到正文
DEV Community· Yonto Player·· 1 小時前AI 評分70

AI 智能體由 issue 到合併 PR:規劃、實作與驗證

From an issue to a merged PR with AI agents: plan, build, prove

AI 導讀

作者分享一套以 AI 編碼智能體將 issue 推進至合併 PR 的七步流程,包括重現、調查、規劃、建立 issue、修復、審查及合併。流程要求修改前先在運行中的應用重現問題,並以測試變異、前後截圖或效能數據驗證修復;審查交由未參與改動的另一個智能體執行。多個智能體透過 issue 認領工作並按檔案避免重疊,產品方向及主觀取捨則由作者決定。

正文

I build Yonto Player with AI coding agents, and the part I trust most is not the typing. It is the loop around the typing: a fixed order of steps, written down once, that an agent follows for every change. I want to walk through that loop from the first look at a problem to the merge, and then show how several agents work one queue.

Everything here is Markdown in the repo, and the steps use plain tools (git, the gh command line, a shell and an emulator), so they are not tied to one agent.

The order is the point

The fixing workflow is seven steps: reproduce, investigate, plan, file, fix, review, merge. The skill says the order matters, and each step is there because skipping it can produce a wrong fix.

1. Reproduce. Before reading any code, see the problem happen, and see it the way a viewer hits it, in the running app, not only through a unit test. Capture it. That capture becomes the "before" in the pull request. If the problem cannot be reproduced, the agent says so and stops, because a bug that cannot be reproduced cannot be shown fixed either. A report's explanation of the cause is treated as a hypothesis to measure, not a fact.

2. Investigate. Find the cause, not the place where the symptom stops. The target is a file and line, plus a sentence on why that line produces this symptom. Where it helps, run the code instead of reading it: a throwaway test that prints what a function really returns settles in a minute what an hour of reading argues about. Then look for the same mistake nearby, and check whether the behaviour is already a recorded decision.

3. Plan. Before editing, write down the cause, the change, what could break and what will not be done, and name the alternatives that were rejected. Also decide what will hold the fix, in a preferred order: a compile error, a test that fails when the fix is reverted, or a measurement in the PR.

4. File the issue, even if the fix comes straight after. The issue is the record of what was wrong, and a PR alone does not explain itself a year later.

5. Fix it. One issue, one branch, one PR. A new test is mutated before the PR goes up: break exactly the line it claims to hold and watch it fail. A test that stays green under that is not holding anything.

6. Review, by a fresh agent. 7. Merge. Those two get their own sections below.

An issue is a claim

Several agents can work the same repo, each in its own working copy, and the issue is where they meet. An agent claims an issue with a comment before it starts, and it reads the existing claims first. A simplified sketch of such a comment (the real format is a convention in the repo's skill, and the names here are generic):

Claimed by agent-b.
Files: ViewModel.kt, Screen.kt

The claim names the files the work will touch, in a comment on the issue, so work does not overlap. Issues that touch the same file go to one agent together. Each agent picks its own next item, and none hands work to another. GitHub is where they meet, and the thread keeps the history for an agent that comes back later.

Filing the issue

A filed issue carries what was seen, the evidence, the cause, what should change, and a testing section that includes what must not change. It gets exactly one priority label, ranked by what a viewer loses and not by how hard the fix is. Where the fix is a judgement call and not a correction, the issue names the options and leaves the choice open.

The PR: why, what, how to test

A pull request body has one job: let a reviewer decide without rebuilding my reasoning from the diff. The skill's test of a good body is that a reviewer who reads it and then the diff should find no surprises.

This is a simplified sketch of its shape, with made-up details:

Area: imperative summary            <- the title

## Why
What was wrong, in the viewer's terms: the behaviour, not the code.
Fixes #123

## What
The change, why the obvious approach was not taken, what was left alone,
and anything removed (a deleted test especially).

## How to test
1. Steps in order, with the state to start from.
2. Cases that must not change.
What was verified, and what was not, said plainly.

(before / after screenshots, same screen and same state)

The evidence rule is the one I like most. A change that alters what a viewer sees is not finished without a before and an after, taken on the thing itself, and for performance the evidence is numbers, measured before and after with a control. The control rows go in too, including the ones that do not help the case, because a body that shows only its best rows cannot be trusted.

Before writing any of it, the agent runs the full build and test line without caches, since a cached green may not have run the tests at all. Then it asks one more question: what sentence in the docs does this change make false? It searches for every copy of that claim and fixes them in the same PR, because the docs are what the next agent reads.

A reviewer that did not write it

The review goes to a fresh agent with no part in the change, one focused pass, set to a medium reasoning effort so it stays on the diff and does not turn into an audit. It is told to verify, not to read: build the branch, run the suite, run the mutations the body claims, check the body against the diff, and look at the screen if a viewer would. The reviewer has not seen the code before, but it does get a brief from the author: the two or three things they are least sure of, and a request for one thing the brief did not mention. Where one can be made, the reviewer works in its own worktree, and it changes nothing on the branch, and its verdict goes on the PR in its own words.

One pass is the normal number. A second is for when the first found something worth re-checking, and two is the cap. At the cap every open point is answered in writing: the code stands and why, or it becomes its own issue.

Merge, then keep going

After a clean pass the author reruns the full line, compares test names against the branch's base to catch a test dropped along the way, and merges. Then it checks that the issue actually closed.

The same loop, repeated, is a sweep. An agent reads its own open PRs before the issues, since finished work waiting on a reviewer beats an unstarted issue. Then it takes issues by priority label, skipping what another agent has claimed by file. Anything it notices while fixing is filed straight away and joins the queue. The sweep ends when the queue is empty, not when the first pass is done.

What stays with me

The agents do not decide what to build. Where a fix is a judgement and not a correction, the skill says the call belongs to the person, so the agent states the options and asks. What the product is for, what ships, and anything that is a matter of taste stay mine. What the process buys me is that when I do read a PR, it should carry the reproduction, the cause, the evidence and a cold review, so my time goes on the decisions.

If you want to try this on your own repo, two rules are a good start: reproduce the problem before touching code, and make every PR show its before and after. The rest follows from those.

Read more

來源:DEV Community · dev.to