Repository navigation
Send the agent, install method, instance kind and usage error cause in usage analytics #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
curquiza
wants to merge
2
commits into
main
Choose a base branch
from
analytics-usage-context
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+273
−21
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@meilisearch/cli": minor | ||
| --- | ||
|
|
||
| Change usage analytics: send the agent, install method, instance kind and usage error cause; shorter notice. ([#103](https://github.com/meilisearch/cli/pull/103)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # ADR 0024: Usage events name the agent, the install method, the kind of instance and the cause of a usage error, and the notice points to the README | ||
|
|
||
| Status: accepted. Date: 2026-11-29. Extends ADR 0016: four more properties. Replaces the content of the notice of ADR 0016. | ||
|
|
||
| ## Context | ||
|
|
||
| The CLI events of ADR 0016 now feed a PostHog dashboard whose goal is to improve the CLI. It shows four blind spots: | ||
|
|
||
| - **Who runs the CLI without a terminal.** `tty: false` is an agent or a script. The CLI is built for coding agents first, but no event says which agent runs it, or whether an agent runs it at all. | ||
| - **Why a usage error happens.** Without a terminal, `cli_usage` is the most frequent error. It has many causes: an unknown flag, a missing required flag, an invalid value, two flags that cannot go together, or a check of the command itself. The event does not say which one, nor which flag. | ||
| - **Which kind of Meilisearch the CLI talks to.** A local instance, Meilisearch Cloud, or another server. This decides which commands matter most. | ||
| - **How the CLI was installed.** ADR 0017 ships it on npm, Homebrew and archives. Nothing says which channel people use. | ||
|
|
||
| The notice of ADR 0016 lists what is sent and how to turn it off. Each new property makes it longer or out of date. The README already has an analytics section. | ||
|
|
||
| Many coding agents say who they are in the environment. `AI_AGENT` is a shared name: Claude Code sets it to `claude-code_2-1-309_agent`, the name, its version and its mode. Other agents set a variable of their own. `@vercel/detect-agent` (version 1.2.7) keeps the list. | ||
|
|
||
| Alternatives considered: | ||
|
|
||
| - **Send the value of `AI_AGENT` as it is.** It names agents that the CLI does not know yet. But it is free text that any program can set. ADR 0016 sends only fixed ids. | ||
| - **Depend on `@vercel/detect-agent`.** It is updated when a new agent appears. But it is a new dependency for about fifteen lines, and its ids are not ours (rule 9). | ||
| - **Send the host of the instance.** It shows each Cloud region and each company server. But a host can name a customer. ADR 0016 never sends URLs. | ||
| - **Count private networks as local.** `192.168.x` is often a developer's machine. But it is also a company server in production. Only names that mean "this machine" are clear. | ||
| - **Send the flag as typed.** For an unknown flag, it shows the exact guess. But a typo can hold a value, as with `--index=movies` typed as `--idx=movies`. The closest declared flag says the same thing without the risk. `cli_command_not_found` does the same for commands (ADR 0019). | ||
| - **A reason for each check of each command.** Every `cli_usage` that a command throws would need its own id. `other` and the `command` property already point to the place in the code. | ||
|
|
||
| ## Decision | ||
|
|
||
| ### On every event | ||
|
|
||
| - **`agent`**, the coding agent that runs the CLI, as a fixed id: `claude-code`, `cursor`, `cursor-cli`, `codex`, `gemini`, `github-copilot`, `opencode`, `augment`, `antigravity`, `replit` or `devin`. `AI_AGENT` comes first: its part before the first `_` is kept when it is one of these ids, `github-copilot-cli` is `github-copilot`, and any other value is `other`. Without `AI_AGENT`, the variables of `@vercel/detect-agent` 1.2.7 are read in its order, the first match wins, and `/opt/.devin` means `devin`. The property is absent when no agent is found. | ||
| - **`install_method`**, from where the files of the CLI are: `archive` when the Node that runs it is inside the CLI's own folder, `brew` under a `Cellar` folder, `npx` under `_npx`, `pnpm` under a `dlx` folder of pnpm, `npm` under `node_modules/@meilisearch/cli`, else `other`, such as a clone of the repository. | ||
|
|
||
| ### On `cli_command_run` | ||
|
|
||
| - **`target`**, for a command that resolves a Meilisearch project: `cloud` when the host ends with `meilisearch.io`, `local` when it is `localhost`, a name that ends with `.localhost`, `127.x.x.x`, `::1`, `0.0.0.0` or `host.docker.internal`, else `other`. Absent for the other commands. The URL is never sent. | ||
| - **`usage_reason`** and **`usage_flag`**, when `error_code` is `cli_usage`. `usage_reason` is `unknown_flag`, `missing_flag`, `invalid_value`, `flag_conflict` or `other`. `usage_flag` is a flag that the command declares: the flag the error names, or for an unknown flag the declared flag closest to it, when it is close enough to be a typo. It is absent when there is none. `other` is a check of the command itself, after oclif parsed the flags. | ||
|
|
||
| ### The notice | ||
|
|
||
| The notice says that anonymous usage data is sent to improve the CLI, and gives the link to the analytics section of the README: `https://github.com/meilisearch/cli#analytics`. The README says what is sent, then how to turn it off. The notice is still shown once per `analytics.json`, on stderr, when stderr is a terminal. | ||
|
|
||
| ## Consequences | ||
|
|
||
| - The dashboard can split errors without a terminal by agent, and a `cli_usage` by cause and by flag. | ||
| - A new agent is `other` until it is added to the list, in a change that updates `config.md`. | ||
| - oclif does not export its parse errors, so the CLI reads the cause from oclif's messages. A new oclif version that changes a message turns that cause into `other`. The tests of `test/lib/analytics.test.ts` catch it. Only a declared flag name is sent, whatever the message holds. | ||
| - The `cli_usage` errors that the commands throw themselves are `other`, with no flag. If the dashboard shows many of them, a later change can give `MeiliCliError` an optional flag. | ||
| - The archive detection relies on the layout of `oclif pack tarballs`, which puts Node inside the CLI's folder. | ||
| - The README is now the one place that lists what is sent, for humans. `config.md` stays the contract. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that a
127.*hostname is an IPv4 address.For
http://127.example.com:7700, this branch returnslocal. That hostname can identify a remote server. The contract limits this case to127.x.x.xaddresses. Check the address type before applying the prefix rule. Keep127.0.0.1classified aslocal. (raw.githubusercontent.com)