跪拜 Guibai
← All articles
AI Programming · OpenAI · AIGC

A Five-Stage AI Coding Workflow That Keeps You in Control

By 全栈弄潮儿 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Most developers use AI for isolated code generation but lack a repeatable process that catches contradictions, SQL injection, and false-passing tests before they reach production. This workflow gives a low-ceremony, copy-pasteable structure that works with any LLM and any stack, without requiring an automation platform.

Summary

Ad-hoc AI prompting across a feature's lifecycle produces contradictory output and unverified code. A structured workflow solves this by locking AI into five distinct stages: requirement analysis, plan-then-code implementation, test scenario generation, diff-based code review, and documentation from verified behavior. Each stage ends with a human checkpoint before the next begins.

The workflow uses a small product-search feature as a concrete example. Before any code is written, AI extracts ambiguities — case sensitivity, whitespace handling, error UI — and the developer codifies the answers into a shared constraint document. Implementation is split into plan-first, code-second steps, with parameterized queries enforced by explicit constraints. Testing focuses on catching false passes: status-code-only checks, missing empty-value coverage, and assertions too broad to fail.

A project-level context template (tech stack, conventions, constraints, acceptance criteria) reduces repetition and keeps AI aligned across sessions. The article also supplies a simplified seven-step daily checklist and a final pre-submission checklist that explicitly forbids sending keys, user data, or unauthorized code to AI.

Takeaways
AI works best as an assistant for organizing, spotting gaps, drafting, and checking — not as an autonomous delivery system.
Before writing any code, have AI list ambiguities in the requirement; turn the answers into a short constraint document that becomes the shared context for all later stages.
Always ask AI for an implementation plan first, then generate code for one small part at a time to keep changes verifiable and rollback simple.
Test scenarios must cover normal, boundary, and exception cases; watch for false passes that only check status codes or lack assertions on business fields.
Code review works best when you submit a git diff alongside the confirmed requirements, and demand specific evidence — problem location, severity, impact, suggestion, verification method — not a vague summary.
Generate documentation only from already-implemented and verified behavior; never write docs first and force code to match.
Set an explicit checkpoint at each stage: confirm the output before moving on, so early errors don't cascade.
Maintain a project context template (stack, conventions, constraints, acceptance criteria) and fill in only the task-specific parts per session; never include secrets, user data, or production-sensitive information.
A simplified daily flow — state goal, find unclear points, confirm scope, code one piece, run and test, review diff, update docs — covers most tasks; high-risk features need all five stages plus manual review.
Three common mistakes: letting AI do the whole project at once, skipping checks between stages, and having AI self-review its own output without fresh requirements.
Conclusions

The workflow's core insight is that AI's value in coding is not raw generation speed but making each small output quickly understandable, verifiable, and usable — speed of comprehension beats speed of generation.

The constraint-document pattern (a short, human-curated spec derived from AI-flagged ambiguities) is a lightweight alternative to formal spec documents and works as prompt context across multiple sessions.

The article treats AI self-review as a distinct risk: without re-supplying requirements and acceptance criteria, the model can repeat its own earlier misunderstandings, making review a rubber stamp.

The explicit ban on submitting keys, user data, or unauthorized code to AI in the final checklist acknowledges a security boundary that many workflow guides omit.

Concepts & terms
Parameterized query
A SQL query where user input is passed as bound parameters rather than concatenated into the query string, preventing SQL injection by separating code from data.
False-passing test
A test that passes but doesn't actually verify correct behavior — e.g., checking only that no exception was thrown, or asserting on status codes while ignoring business fields and edge cases.
Constraint document
A short, human-written spec derived from AI-flagged requirement ambiguities, used as shared prompt context across coding, testing, and review stages to keep AI output consistent.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗