Add hooks for the root repo#186578
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
There was a problem hiding this comment.
Code Review
This pull request introduces agent hooks for Dart formatting and analysis, adds the dart_hooks package as a dependency in dev/tools/pubspec.yaml, and updates the project's lock file. Feedback indicates that the hook commands require an explicit --package-config flag to resolve the dart_hooks package from the correct context. Additionally, the timeout for the analysis hook should be increased to avoid intermittent failures, and the pubspec.lock file needs correction as dart_hooks is currently misidentified as a transitive dependency.
| "Stop": [ | ||
| { | ||
| "type": "command", | ||
| "command": "../bin/cache/dart-sdk/bin/dart --packages=../.dart_tool/package_config.json run dart_hooks:agent_dart_format --source hook --log", |
There was a problem hiding this comment.
This whole pattern looks strange, it looks like a case for dart install and executables
https://dart.dev/tools/dart-install
https://dart.dev/tools/pub/pubspec#executables
There was a problem hiding this comment.
Would you like me to figure out dart install and executables before landing this change?
There was a problem hiding this comment.
Does this mean that we will always run dart format? That seems like an odd pattern to me if so (though let me know if I am misunderstanding). What if the latest prompt is me asking a clarification question which involves no changes do code, or if my latest request is changes to kotlin/java/c++/BUILD.gn/pubspec.yaml/etc exclusively. Will it mean the agent will run dart format always in those cases?
This specific pr means if you open the internal version of antigravity to the root of flutter/flutter and when the agent thinks it is done working it will run Q: "What if the latest prompt is me asking a clarification question which involves no changes do code" Assuming you have the internal version of antigravity open to the root directory. When the agent thinks it is done the scripts will run and see no modified dart files and exit cleanly. If you have modified dart code then format and analyze will run on the files you have modified. Q: "If my latest request is changes to kotlin/java/c++/BUILD.gn/pubspec.yaml/etc exclusively [will it run analyze and format]?" the scripts will run and detect no changed dart files and move on. If your latest request touched kotlin files and you have modified non committed dart files they will be formatted and analyzed. We are limited by the lifecycle events that the internal version of antigravity gives us. To my knowledge, on 2026-05-15, there are no ways to get the files the agent thinks it touched. We could run on file write but agents modify files with sed and scripts and I didnt want to run on every write only when the agent thinks it is "done". Frequently in my experience the agent will run Finally lets say you are working on a test that explicitly needs checked in files that have analyzer warnings. The nice thing about the script as authored is you can check those files in and they will not be analyzed. This exposes a failure mode where the agent can check things in before analyze and formatting them but I wanted an easy to describe bypass path. I hope that helps. |
This seems surprising to me. Is this not what additions to the context window such as In general I'm somewhat suspicious of making opinionated global configurations of everyone's agents. If we believe we should always run these commands, why do we choose this hook instead of a git pre submit hook (similar to the engine formatting hook that doesn't allow you to push unformatted code, even to your local branch) |
It is what they are attempting to solve and failing to solve. Markdown no matter how aggressively or repeatedly insisted upon can be lost under large context windows and agent do just decide to not follow those instructions. If what you want is deterministic then hooks are one of the few ways to have determinism in an agentic development environment. We dont have the ability to run evals in an IDE right now but from personal experience this is one of the best things you can do to get your agent to author better dart before you look at it. Best of all it is mostly invisible. "In general I'm somewhat suspicious of making opinionated global configurations of everyone's agents." Fair enough and that is what the review process is for. It is also why I went with what I considered to be the least controversial hooks to start with. If format and analyze fail (which happens a bunch on initial cl upload) then basically all our test get spun up and fail so it prevents you from even seeing what your code breaks. Q: "why do we choose this hook instead of a git pre submit hook?" Pre submit hooks impact everyone's flow and these only impact agentic flows. The benefit is that the amount of time this adds to what humans are sitting and waiting on is rounded down to zero because you should not be watching your agent work you should be reviewing what happens when it is finished. Where as I might commit work that is in a partial state when I need to change branches. You can get around precommit hooks but you have introduced frustration to a human workflow. |
|
@gmackall go/flutter-pr-186578-context |
gmackall
left a comment
There was a problem hiding this comment.
I think the implementation here would make this change pretty annoying in the bad path. An example:
Recently I made added a new platform view test dart file in dev/integration_tests/android_engine_test/lib/hcpp/ designed to test out some local changes.
I swapped back and forth the master branch and my branch with changes to test out the functionality.
Then I ask a clarifying question about the java changes of my implementation. The agent spends some time thinking and replies. Then the hooks fire and format and analyze my local, untracked test file.
This hijacks the window, replaces the reply with notes about how it fixed analyze and format failures, and notable hides the entire original reply deep in the "worked for N minutes" section (it's not revealed by scrolling up, you need to know to expand the work log and then find it amidst the tool calls and thinking). This is extremely annoying, and would be very confusing to someone who is unfamiliar with this configuration and is focusing only on non-dart changes at the moment (and asked a question unrelated to dart).
|
My recap of what @gmackall and I talked about out of band. ##Specific use case that in theory could be made worse.
I consider this no different than the skills, mcp servers, rules and agents.md files we already include which are based on their ability to make the agents we have right now better. ##Places we agree
Possible avenues forward
|
Add hooks for analyze and format to the flutter root .agents directory.
Hooks are a deterministic way to tie into the agent lifecycle in the google internal version of antigravity.
Stop means when the agent is done run the scrips defined. The scripts included are dart code that limits the format and analyze scope to only files modified in git that are below the directory that contains .agents. This pr runs for the whole repo but if you were to add it to a sub directory and open the internal version of antigravity there it would not run on git changes that were outside of that scope.
If you open your editor to a sub folder as of today 2026-05-15 the hooks will not run.
This does not work with claude but could in the future flutter/skills#140.
Most importantly if you have been struggling with your agent stopping with code that has analyzer or formatting warnings then these hooks could help you be less frustrated.
Pre-launch Checklist
///).