跪拜 Guibai
← All articles
Backend · Artificial Intelligence · Full Stack

Flutter AI Harness: A Repo Template That Gives AI Coding Tools a Readable Engineering Contract

By 达达尼昂 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Most AI coding workflows still rely on chat-window context that evaporates between sessions. This template turns architectural rules, task scope, and verification steps into committed files that multiple AI tools read from a single source of truth, cutting the re-explanation tax and making AI-generated changes auditable in CI.

Summary

AI coding tools generate code quickly but lose coherence when modifications span modules or require iteration. Flutter AI Harness addresses this by making engineering rules a first-class repository artifact: a project contract defines invariants, Commands and Agents describe workflows, and task cards scope each change. A four-layer structure separates stable rules from per-task knowledge, preventing context bloat and configuration drift when multiple AI tools share the same codebase.

The template includes a local e-commerce Demo built with Flutter Pub Workspace and Melos, enforcing strict dependency direction and data-type boundaries. Quality gates are not advisory; Git hooks, static analysis, dependency matrix checks, and CI stages execute them deterministically. UI automation via Marionette runs independently of ordinary tasks, so device-dependent checks never block daily development.

Adoption follows two paths: run the Demo to evaluate the full feedback loop, or let AI read the Harness design and adapt its principles to an existing project. The second path preserves the contract, closed-loop delivery, and verifiable evidence while allowing teams to swap out directories, state management, and platform integrations.

Takeaways
Project contracts, task cards, and quality gates live in the repo as committed files, not in chat history, so every AI tool reads the same engineering facts.
A four-layer structure separates stable invariants (project contract) from per-task knowledge (Skills) and cross-task experience (Memory), preventing context overload.
Dependency direction in the Flutter Workspace is enforced: shell apps depend on features, features depend on data and core, and core packages cannot reference business code.
Data-type boundaries require Fixture payloads, Proto messages, and database rows to convert to Domain Entities through a Mapper layer before reaching Controllers or UI.
Task cards scope every change with explicit acceptance criteria; Reviews are read-only, and fixes enter a separate phase to keep discovery distinct from modification.
UI automation (Spec, Audit, Run) is scheduled independently from ordinary tasks so that device-dependent checks never gate daily development.
Quality gates are executable scripts and Git hooks, not suggestion lists; they check formatting, dependency matrices, adaptation-layer sync, and sensitive information on commit and push.
Adoption for existing projects starts with AI reading the Harness design and producing an adaptation plan, preserving principles while replacing directories, state management, and platform integrations.
Conclusions

Separating task artifacts from long-term Memory prevents the knowledge base from bloating into a second project document that nobody maintains.

Making Reviews read-only and requiring explicit re-review after fixes creates an audit trail that distinguishes what was found from what was actually changed, a distinction most AI-coding workflows lack.

The template deliberately avoids pre-installing Dio, Proto, or Drift until a real consumer exists, treating the control of invalid abstractions as equally important as establishing layering.

Requiring positive and negative Fixtures for every quality gate before it is worth maintaining prevents the gate system from becoming process overhead that teams learn to bypass.

Concepts & terms
Project Contract
A committed file (CLAUDE.md) that defines repository-level invariants: tech stack, directory responsibilities, allowed dependency directions, data boundaries, and rules for generated files. It serves as the single source of truth that all AI tools read.
Task Card
A scoped, named unit of work containing fact sources, dependencies, constraints, and acceptance criteria. Task cards are not bound to a specific producer; developers, Agents, or external tools can create them.
Marionette
A component that connects to a running Flutter Debug App and operates on the Widget Tree to execute UI behavior checks. It does not cover native Android or iOS system interfaces.
Melos
A tool for managing Dart/Flutter monorepos with multiple packages. It handles dependency linking, versioning, and workspace-level commands across packages.
MCP (Model Context Protocol)
A local protocol that allows AI Agents to read real Figma design nodes directly, rather than guessing layouts from screenshots, when a task involves design specifications.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗