---
title: "How to Safely Migrate Dart Code to Primary Constructors with a Deterministic CLI"
url: https://daily.dev/posts/how-to-safely-migrate-dart-code-to-primary-constructors-with-a-deterministic-cli-rypnwjjwx
source_url: https://codewithandrea.com/articles/safely-migrate-primary-constructors
type: article
source: "Code with Andrea"
published: 2026-06-12T08:48:24.331Z
updated: 2026-06-25T02:15:16.473Z
tags: ["ai-agents", "dart", "flutter"]
reading_time: 14
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Safely Migrate Dart Code to Primary Constructors with a Deterministic CLI

**[Code with Andrea](https://daily.dev/sources/codewithandrea)** · 14 min read · 0 upvotes · 0 comments

## Summary

Dart 3.12 introduced experimental primary constructors that reduce boilerplate. This post documents a week-long engineering journey to build a deterministic CLI tool for safely migrating codebases to this new syntax. The author first tried an LLM agent skill but found it unreliable, token-intensive (200k+ tokens, 20+ minutes), and inconsistent across runs. Observing that GPT-4 was spontaneously building a Dart AST parser to solve the problem pointed toward the right approach: a deterministic CLI using Dart's analyzer package. The tool implements 3 migration rules but 31 skip rules to ensure safety. Key lessons include: 'it compiles' ≠ 'it's correct'; feeding agents the official language spec beats feeding them examples; and the best architecture separates deterministic migration logic (CLI) from adaptive orchestration (agent). The resulting CLI migrates ~100K lines in under a second with identical results every run, and can be orchestrated by a cheap model like Haiku rather than requiring frontier models.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://codewithandrea.com/articles/safely-migrate-primary-constructors>

## Similar posts on daily.dev

- [How I Used AI Agents to Migrate my Entire Site to Astro](https://daily.dev/posts/how-i-used-ai-agents-to-migrate-my-entire-site-to-astro-ba6sfp5qn) · Code with Andrea · 1 upvotes · 0 comments

---

Tags: [#ai-agents](https://daily.dev/tags/ai-agents), [#dart](https://daily.dev/tags/dart), [#flutter](https://daily.dev/tags/flutter)

[View this post on daily.dev](https://daily.dev/posts/how-to-safely-migrate-dart-code-to-primary-constructors-with-a-deterministic-cli-rypnwjjwx)
