AI-Assisted Development Practices: Specification-First and Document Structuring

    Integrating AI into software development accelerates coding but introduces risks of uncontrolled changes and scope creep. This article explores how to mitigate these risks by establishing a structured collaborative workflow. It details practices such as specification-first design, using test-driven development and automated scripts to define "done," splitting large tasks into isolated subtasks for context management, and converting complex PDF documents into structured Markdown. These strategies ensure AI models align with project goals, produce reliable outputs, and handle large-scale engineering tasks effectively.

    1. Why Process Constraints Are Necessary for AI Programming

    Letting AI modify code directly is fast, but this is also where risks concentrate. Models often start modifying files without fully understanding the requirements, leading to uncontrolled change scopes. While small features might look correct locally, the overall output deviates from the target. In small-scale feature development, these issues can be absorbed through rework. However, in migration projects involving dozens of files and hundreds of changes, it will directly cause the project to fail to converge.

    The key to solving this lies in a clear collaborative workflow. A reusable process typically includes five phases: requirement clarification, specification, task planning, step-by-step execution, and result review. Each phase produces clear deliverables, and you cannot proceed to the next phase until the current one is approved.

    2. Specification-First: Align Before Coding

    The specification is the core of this process. It documents “what to do” and “how to do it” for both developers and models to jointly confirm. A usable specification typically includes the following:

    • Goals and Non-goals: Clarify what problem this change solves and what is out of scope.
    • Interfaces and Data Contracts: Specify inputs, outputs, and error handling methods.
    • Acceptance Criteria: Each criterion should be verifiable through testing or inspection.
    • Open Questions: List uncertainties in advance to prevent the model from making assumptions.

    An example template is as follows:

    1. # Feature Specification: Device Configuration Parsing Module
    2. ## Goals
    3. Migrate the configuration file parsing logic to a new data structure while keeping the output results consistent.
    4. ## Non-goals
    5. - Do not modify the configuration file format
    6. - Do not adjust external interface names
    7. ## Acceptance Criteria
    8. 1. The parsing result of the sample configuration is identical to the old implementation field by field
    9. 2. Illegal fields return a clear error code
    10. 3. Unit test coverage is no lower than the existing baseline
    11. ## Open Questions
    12. - Whether the default value strategy follows the old version

    After the specification is confirmed, break it down into a task plan. Each task in the plan should be small enough to be completed and verified independently. The more specific the task description, the less the model relies on guessing.

    3. Constrain the Definition of “Done” with Tests and Validation

    A common problem in AI programming is that models will claim “done” or “compilation passed” without actually running the relevant commands. The solution is to turn completion criteria into executable checks.

    Test-Driven Development (TDD) is an effective approach. Write failing tests first, then write the implementation code, and finally confirm the tests pass. This approach centers implementation around explicit behaviors and reduces irrelevant changes.

    The debugging phase also requires methodology. When encountering a problem, you should first reproduce it, locate the cause, then fix it, and finally verify the fix. Avoid consecutively trying multiple guess-based modifications, as this makes code changes difficult to trace.

    Pre-completion validation is the final gate. It requires executing builds, running tests, and checking outputs, using actual run results as the basis for the conclusion.

    1. #!/usr/bin/env bash
    2. set -e
    3. echo "[1/3] Execute build"
    4. make build
    5. echo "[2/3] Run unit tests"
    6. make test
    7. echo "[3/3] Check format and static analysis"
    8. make lint

    The script itself is not complex; its value lies in providing a unified and repeatable method to judge “whether it is done.”

    4. Subtask Splitting and Context Isolation

    In large-scale changes, the main conversation context easily gets filled with implementation details. File contents, error logs, and intermediate solutions continuously accumulate, diluting the model’s focus on the overall goal. A common practice is to distribute tasks from the plan to sub-agents with isolated contexts, while the main flow only handles scheduling, aggregation, and acceptance.

    This approach has three benefits:

    • Each subtask only carries the necessary context, reducing interference.
    • Subtasks hand off via clear deliverables, such as code changes, test reports, and summaries.
    • If a subtask fails, you only need to rerun that task without affecting other completed parts.

    Task descriptions can be expressed in a structured format:

    1. task:
    2. id: T-07
    3. title: Migrate register read/write wrapper
    4. inputs:
    5. - spec/register_spec.md
    6. - src/legacy/reg_io.c
    7. outputs:
    8. - src/reg_io.c
    9. - tests/test_reg_io.c
    10. acceptance:
    11. - make test all passed
    12. - External function signatures remain unchanged

    More subtasks are not always better. Tasks with dependencies should be executed sequentially, while independent tasks are suitable for parallel execution. Dependencies should be clearly marked during the planning phase.

    5. Document Structuring: Helping Models Truly Understand Specs

    The accumulated knowledge of many engineering teams exists in PDFs, such as chip specifications, hardware design documents, and platform configuration manuals. These documents are often hundreds of pages long, containing numerous tables, register bit field descriptions, and images.

    When feeding PDFs directly to models, three main issues commonly occur:

    1. Table column misalignment, where cell contents are split apart.
    2. The correspondence between the start/end bits of register fields and their meanings is lost.
    3. Headers, footers, and watermark text mix into the body text, interfering with retrieval results.

    A more reliable approach is to first convert the PDF to Markdown before handing it to the model. Markdown preserves heading hierarchy and table structure, and the text is easy to retrieve and reference. The conversion process usually involves three steps:

    1. Preprocessing: Remove watermarks, headers, footers, and duplicate elements.
    2. Structure Restoration: Identify heading levels, convert tables to Markdown tables, and preserve column names.
    3. Image Processing: Export images and generate reference paths, adding text descriptions for key charts.

    After conversion, sampling validation should be performed, especially for register tables and key parameter tables. Below is a simple validation approach:

    1. def check_register_table(md_text: str) -> list[str]:
    2. """Check if the register table header contains required columns, return a list of issues."""
    3. issues = []
    4. required = ["Offset", "Bit", "Field", "Description"]
    5. header = None
    6. for line in md_text.splitlines():
    7. if line.startswith("|") and "Bit" in line:
    8. header = line
    9. break
    10. if header is None:
    11. return ["Register table header not found"]
    12. for col in required:
    13. if col not in header:
    14. issues.append(f"Header missing column: {col}")
    15. return issues

    Converted files should be stored in a fixed directory (e.g., docs/) and the path should be documented in the project description. This ensures that when the model processes a task, it defaults to reading the structured text rather than guessing the content from the original PDF.

    6. Practical Recommendations

    • Confirm specifications before entering the coding phase; do not skip any phases.
    • Completion criteria must be executable and based on actual run results.
    • Split large tasks into independently verifiable small tasks with clear dependencies.
    • Structure long documents before handing them to the model, and perform sampling validation on key tables.
    • Whenever a model reports “done,” verify the build and test outputs.