From d1c1826dd343fffa311835e946d5965768ff7d64 Mon Sep 17 00:00:00 2001 From: Jaime Wren Date: Fri, 28 Aug 2026 12:37:10 -0700 Subject: [PATCH 1/2] Add proactive Flutter hot reload rule https://github.com/dart-lang/ai/issues/498 Adds proactive Flutter hot reload rules (rules/flutter-hot-reload.md and rules/flutter-hot-reload.mdc) to automatically trigger hot reload or hot restart when Dart and Flutter files are modified during agent sessions. Problem: During AI-driven development workflows: - Out-of-Sync Execution: Agents modify source code on disk but do not update the active running session, leaving the simulator/device screen stale. - Context Switching Friction: Users must leave the chat interface to manually initiate a reload ('r'/'R') in the terminal or IDE. Solution: - Adds a glob-triggered rule on `**/*.dart` that instructs agents to discover running apps via DTD and execute hot reload (for widget/UI changes) or hot restart (for fundamental logic/state initialization). - Defines skip criteria for test files and comment/doc-only edits. --- rules/flutter-hot-reload.md | 20 ++++++++++++++++++++ rules/flutter-hot-reload.mdc | 21 +++++++++++++++++++++ rules/hot_reload.md | 10 ---------- rules/hot_reload.mdc | 9 --------- 4 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 rules/flutter-hot-reload.md create mode 100644 rules/flutter-hot-reload.mdc delete mode 100644 rules/hot_reload.md delete mode 100644 rules/hot_reload.mdc diff --git a/rules/flutter-hot-reload.md b/rules/flutter-hot-reload.md new file mode 100644 index 0000000..498c127 --- /dev/null +++ b/rules/flutter-hot-reload.md @@ -0,0 +1,20 @@ +--- +description: Proactively connect to running Dart/Flutter apps and trigger hot reload or hot restart upon editing .dart files. +trigger: glob +globs: "**/*.dart" +--- + +# Proactive Flutter Hot Reload Rule + +Whenever you edit or modify any `.dart` file in this project: + +1. **When to Skip**: + - **Tests**: Do not trigger hot reload or hot restart when modifying test files (e.g., `test/**`, `*_test.dart`). Run tests using `flutter test` instead. + - **Comments & Documentation**: Do not trigger hot reload or hot restart when changes only affect comments, docstrings, or whitespace. + +2. **Discover & Connect**: + - Discover active running application instances using the `dtd` tool (or `list_running_apps` / `vm_service`). + +3. **Trigger Hot Reload / Hot Restart**: + - Execute `hot_reload` immediately after making changes to UI widgets or simple methods. + - Execute `hot_restart` if fundamental logic, stateful widgets or logic affecting variables that stateful widgets use, state initialization, or `main()` was modified. diff --git a/rules/flutter-hot-reload.mdc b/rules/flutter-hot-reload.mdc new file mode 100644 index 0000000..3210574 --- /dev/null +++ b/rules/flutter-hot-reload.mdc @@ -0,0 +1,21 @@ +--- +description: Proactively connect to running Dart/Flutter apps and trigger hot reload or hot restart upon editing .dart files. +trigger: glob +globs: "**/*.dart" +alwaysApply: false +--- + +# Proactive Flutter Hot Reload Rule + +Whenever you edit or modify any `.dart` file in this project: + +1. **When to Skip**: + - **Tests**: Do not trigger hot reload or hot restart when modifying test files (e.g., `test/**`, `*_test.dart`). Run tests using `flutter test` instead. + - **Comments & Documentation**: Do not trigger hot reload or hot restart when changes only affect comments, docstrings, or whitespace. + +2. **Discover & Connect**: + - Discover active running application instances using the `dtd` tool (or `list_running_apps` / `vm_service`). + +3. **Trigger Hot Reload / Hot Restart**: + - Execute `hot_reload` immediately after making changes to UI widgets or simple methods. + - Execute `hot_restart` if fundamental logic, stateful widgets or logic affecting variables that stateful widgets use, state initialization, or `main()` was modified. diff --git a/rules/hot_reload.md b/rules/hot_reload.md deleted file mode 100644 index 68bc31b..0000000 --- a/rules/hot_reload.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -trigger: glob -globs: *.dart -description: Proactively connect to apps and hot reload ---- - -Whenever you make edits to any Dart or Flutter files in this project: -1. Proactively connect to the running application using the `dtd` tool and its subcommands. Make sure to read the schema for this tool. -2. Trigger a hot reload using the `hot_reload` tool to push the changes immediately. -3. If no app is running, inform the user but do not let it stop you from completing the code edits. diff --git a/rules/hot_reload.mdc b/rules/hot_reload.mdc deleted file mode 100644 index e97ded5..0000000 --- a/rules/hot_reload.mdc +++ /dev/null @@ -1,9 +0,0 @@ ---- -globs: *.dart -alwaysApply: false ---- - -Whenever you make edits to any Dart or Flutter files in this project: -1. Proactively connect to the running application using the `dtd` tool and its subcommands. Make sure to read the schema for this tool. -2. Trigger a hot reload using the `hot_reload` tool to push the changes immediately. -3. If no app is running, inform the user but do not let it stop you from completing the code edits. From e6a140a3ec1f876939162e739a683f8cfb0182aa Mon Sep 17 00:00:00 2001 From: Jaime Wren Date: Fri, 28 Aug 2026 14:02:25 -0700 Subject: [PATCH 2/2] Address PR feedback: refine hot restart triggers and fix .mdc frontmatter - Remove unsupported `trigger: glob` key from `flutter-hot-reload.mdc`. - Refine reload vs. restart rules to allow hot reload on stateful widget build methods and restrict hot restart to state initialization, global state, and root lifecycle changes. --- rules/flutter-hot-reload.md | 4 ++-- rules/flutter-hot-reload.mdc | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/rules/flutter-hot-reload.md b/rules/flutter-hot-reload.md index 498c127..02a957d 100644 --- a/rules/flutter-hot-reload.md +++ b/rules/flutter-hot-reload.md @@ -16,5 +16,5 @@ Whenever you edit or modify any `.dart` file in this project: - Discover active running application instances using the `dtd` tool (or `list_running_apps` / `vm_service`). 3. **Trigger Hot Reload / Hot Restart**: - - Execute `hot_reload` immediately after making changes to UI widgets or simple methods. - - Execute `hot_restart` if fundamental logic, stateful widgets or logic affecting variables that stateful widgets use, state initialization, or `main()` was modified. + - Execute `hot_reload` immediately after making changes to UI widgets (including `build` methods of stateful widgets) or simple methods. + - Execute `hot_restart` if fundamental logic, state initialization (e.g., `initState`), global/static state, or `main()` was modified. diff --git a/rules/flutter-hot-reload.mdc b/rules/flutter-hot-reload.mdc index 3210574..344de63 100644 --- a/rules/flutter-hot-reload.mdc +++ b/rules/flutter-hot-reload.mdc @@ -1,6 +1,5 @@ --- description: Proactively connect to running Dart/Flutter apps and trigger hot reload or hot restart upon editing .dart files. -trigger: glob globs: "**/*.dart" alwaysApply: false --- @@ -17,5 +16,5 @@ Whenever you edit or modify any `.dart` file in this project: - Discover active running application instances using the `dtd` tool (or `list_running_apps` / `vm_service`). 3. **Trigger Hot Reload / Hot Restart**: - - Execute `hot_reload` immediately after making changes to UI widgets or simple methods. - - Execute `hot_restart` if fundamental logic, stateful widgets or logic affecting variables that stateful widgets use, state initialization, or `main()` was modified. + - Execute `hot_reload` immediately after making changes to UI widgets (including `build` methods of stateful widgets) or simple methods. + - Execute `hot_restart` if fundamental logic, state initialization (e.g., `initState`), global/static state, or `main()` was modified.