Add 'AiAgent.detectAgentNames' to return a set of all matched agents#2455
Add 'AiAgent.detectAgentNames' to return a set of all matched agents#2455jmagman wants to merge 4 commits into
Conversation
Package publishingIf you have publishing permissions, you can use the links below to publish the changes after merging this PR.
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
There was a problem hiding this comment.
Code Review
This pull request updates the unified analytics package to support detecting multiple AI agents from environment variables, returning them as a comma-separated string, and introduces a utility function truncateJoinedString to safely truncate the list of agents to 36 characters by discarding entire elements from the end. Feedback on the changes includes splitting comma-separated lists in the AGENT and AI_AGENT environment variables to ensure proper deduplication of agents, and optimizing truncateJoinedString to O(N) complexity by tracking the accumulated length instead of copying and joining lists on every iteration.
PR HealthUnused Dependencies ✔️
For details on how to fix these, see dependency_validator. This check can be disabled by tagging the PR with
Breaking changes
|
| Package | Change | Current Version | New Version | Needed Version | Looking good? |
|---|---|---|---|---|---|
| unified_analytics | Non-Breaking | 8.0.15 | 8.0.16 | 8.1.0 Got "8.0.16" expected >= "8.1.0" (non-breaking changes) |
This check can be disabled by tagging the PR with skip-breaking-check.
API leaks ⚠️
The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
| Package | Leaked API symbol | Leaking sources |
|---|---|---|
| unified_analytics | Condition | survey_handler.dart::Survey::conditionList survey_handler.dart::Survey::new::conditionList |
| unified_analytics | PersistedSurvey | survey_handler.dart::SurveyHandler::fetchPersistedSurveys |
| unified_analytics | GAClient | analytics.dart::Analytics::fake::gaClient analytics.dart::AnalyticsImpl::new::gaClient |
| unified_analytics | UserProperty | analytics.dart::FakeAnalytics::userProperty |
This check can be disabled by tagging the PR with skip-leaking-check.
Changelog Entry ✔️
| Package | Changed Files |
|---|
Changes to files need to be accounted for in their respective changelogs.
This check can be disabled by tagging the PR with skip-changelog-check.
Coverage ⚠️
| File | Coverage |
|---|---|
| pkgs/unified_analytics/lib/src/analytics.dart | 💚 73 % |
| pkgs/unified_analytics/lib/src/constants.dart | 💔 Not covered |
| pkgs/unified_analytics/lib/src/enums.dart | 💚 100 % |
| pkgs/unified_analytics/lib/src/utils.dart | 💚 78 % ⬆️ 3 % |
This check for test coverage is informational (issues shown here will not fail the PR).
This check can be disabled by tagging the PR with skip-coverage-check.
License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
| Files |
|---|
| no missing headers |
All source files should start with a license header.
This check can be disabled by tagging the PR with skip-license-check.
Collect telemetry on which AI agents are calling `flutter` commands, based on environment variables the agents add in their sessions. This uses the `unified_analytics` change dart-lang/tools#2423 There's a conversation in that PR about making `AiAgent.detectAgentName` return a `Set`. I am adding this now dart-lang/tools#2455 (GA needs the user_property list values to be a string delineated by commas anyway, so it's not a breaking change), and then migrate this code over to it. However, I'd like to land this as-is ASAP to make it before the next stable cutoff. Fixes flutter#187623. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Collect telemetry on which AI agents are calling `flutter` commands, based on environment variables the agents add in their sessions. This uses the `unified_analytics` change dart-lang/tools#2423 There's a conversation in that PR about making `AiAgent.detectAgentName` return a `Set`. I am adding this now dart-lang/tools#2455 (GA needs the user_property list values to be a string delineated by commas anyway, so it's not a breaking change), and then migrate this code over to it. However, I'd like to land this as-is ASAP to make it before the next stable cutoff. Fixes flutter#187623. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
|
@reidbaker I don't have permissions to add reviewers, but can you review? |
|
@bwilkerson would you mind reviewing, and publish unified_analytics ? |
bwilkerson
left a comment
There was a problem hiding this comment.
Feel free to ignore my comments and land this as-is.
| required SurveyHandler surveyHandler, | ||
| required bool enableAsserts, | ||
| required bool firstRun, | ||
| String? agent, |
There was a problem hiding this comment.
Consider allowing clients to pass in a list of agents (List<String>). That way,
- this package controls the separator character
- the code doesn't need to deconstruct and reconstruct the value being sent back
- various encoding approaches could be used.
| /// exceed [maxLength]. | ||
| /// | ||
| /// If even the first element exceeds [maxLength], it will be truncated. | ||
| String? truncateJoinedString(String? input, String separator, int maxLength) { |
There was a problem hiding this comment.
I'm not necessarily requesting it, but it would be nice to have an indication of the number of times the list has been truncated, so we know how accurate the data is. For example, we could append ",*" when the list is truncated. Especially given that the agents are always added to the list in the same order, and we always truncate from the end, the agents at the end of the list are more likely to be underrepresented.
One improvement would be to randomize the list before truncating it.
Or, reduce the probability of needing to truncate by encoding the agent names using a fixed-length one or two character code. I'm guessing that we're unlikely to have more agents than can be represented by a single ascii character, but we could use two just to be safe. That would allow us to not truncate unless the list had more than 36 (or 18) agent names (because if they're fixed length we don't need separators), reducing the chance that the list is truncated.
Follow up to comment #2423 (comment) to add multi-agent detection.
Note GA4 user_properties don't support lists as map values, so it needs to be a comma-delineated string. We can split it apart on the query side. This happily also prevents a breaking change.
Truncate the agent string to 36 characters by removing full agent names, instead of truncating in the middle of the name.
Contribution guidelines:
dart format.Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.
Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.