Skip to content

Add 'AiAgent.detectAgentNames' to return a set of all matched agents#2455

Open
jmagman wants to merge 4 commits into
dart-lang:mainfrom
jmagman:detectAgentNames-set
Open

Add 'AiAgent.detectAgentNames' to return a set of all matched agents#2455
jmagman wants to merge 4 commits into
dart-lang:mainfrom
jmagman:detectAgentNames-set

Conversation

@jmagman

@jmagman jmagman commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

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.

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

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.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Package publishing

If you have publishing permissions, you can use the links below to publish the changes after merging this PR.

Package Version Status Publish tag (post-merge)
package:api_summary 0.1.0-wip WIP (no publish necessary)
package:bazel_worker 1.1.5 already published at pub.dev
package:benchmark_harness 2.4.0 already published at pub.dev
package:boolean_selector 2.1.2 already published at pub.dev
package:browser_launcher 1.2.0-wip WIP (no publish necessary)
package:cli_config 0.2.1-wip WIP (no publish necessary)
package:cli_util 0.5.1 already published at pub.dev
package:clock 1.1.3-wip WIP (no publish necessary)
package:code_builder 4.12.0-wip WIP (no publish necessary)
package:coverage 1.15.1 already published at pub.dev
package:csslib 1.0.2 already published at pub.dev
package:extension_discovery 2.1.0 already published at pub.dev
package:file 7.0.2-wip WIP (no publish necessary)
package:file_testing 3.1.0-wip WIP (no publish necessary)
package:glob 2.1.3 already published at pub.dev
package:graphs 2.4.0-wip WIP (no publish necessary)
package:html 0.15.7-wip WIP (no publish necessary)
package:io 1.1.0-wip WIP (no publish necessary)
package:json_rpc_2 4.1.0 already published at pub.dev
package:markdown 7.4.0 ready to publish markdown-v7.4.0
package:mime 2.1.0-wip WIP (no publish necessary)
package:oauth2 2.0.5 already published at pub.dev
package:package_config 3.0.0 already published at pub.dev
package:pool 1.5.3-wip WIP (no publish necessary)
package:process 5.0.5 (error) pubspec version (5.0.5) and changelog (5.0.6-wip) don't agree
package:pub_semver 2.2.0 already published at pub.dev
package:pubspec_parse 1.6.0-wip WIP (no publish necessary)
package:source_map_stack_trace 2.1.3-wip WIP (no publish necessary)
package:source_maps 0.10.14-wip WIP (no publish necessary)
package:source_span 1.10.2 already published at pub.dev
package:sse 4.2.1-wip WIP (no publish necessary)
package:stack_trace 1.12.2-wip (error) pubspec version (1.12.2-wip) and changelog (1.12.2-dev) don't agree
package:stream_channel 2.1.4 already published at pub.dev
package:stream_transform 2.1.2-wip WIP (no publish necessary)
package:string_scanner 1.4.2-wip WIP (no publish necessary)
package:term_glyph 1.2.3-wip WIP (no publish necessary)
package:test_reflective_loader 0.6.0 ready to publish test_reflective_loader-v0.6.0
package:timing 1.0.2 already published at pub.dev
package:unified_analytics 8.0.16 ready to publish unified_analytics-v8.0.16
package:watcher 1.2.2-wip WIP (no publish necessary)
package:yaml 3.1.4-wip WIP (no publish necessary)
package:yaml_edit 2.2.4 already published at pub.dev

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkgs/unified_analytics/lib/src/enums.dart
Comment thread pkgs/unified_analytics/lib/src/utils.dart
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

PR Health

Unused Dependencies ✔️
Package Status
unified_analytics ✔️ All dependencies utilized correctly.

For details on how to fix these, see dependency_validator.

This check can be disabled by tagging the PR with skip-unused-dependencies-check.

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.

@jmagman
jmagman marked this pull request as ready for review July 6, 2026 20:01
@jmagman
jmagman requested review from a team and bkonyi as code owners July 6, 2026 20:01
@bkonyi
bkonyi requested review from bwilkerson and removed request for a team and bkonyi July 6, 2026 20:30
pull Bot pushed a commit to NOUIY/flutter that referenced this pull request Jul 7, 2026
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
Rusino pushed a commit to Rusino/flutter that referenced this pull request Jul 7, 2026
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
@jmagman

jmagman commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@reidbaker I don't have permissions to add reviewers, but can you review?

@reidbaker
reidbaker self-requested a review July 14, 2026 22:52
@jmagman

jmagman commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@bwilkerson would you mind reviewing, and publish unified_analytics ?

@bwilkerson bwilkerson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to ignore my comments and land this as-is.

required SurveyHandler surveyHandler,
required bool enableAsserts,
required bool firstRun,
String? agent,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants