Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ linters:

misspell:
locale: US
ignore-rules:
# The SSP telemetry contract spells this outcome with two l's.
- cancelled

errorlint:
# %w wrapping is preferred but legacy %v errors are still acceptable
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Earlier entries pre-date this convention and only carry their version's compare

## [Unreleased]

### Added

- Report `savedPreference`, `transportConfigured`, and `captureActive` in telemetry status output. `enabled` continues to reflect runtime opt-outs ([#76](https://github.com/AgoraIO/cli/pull/76)).

### Changed

- Rename the `project show --json` token debug status to `signalingTokenDebugEnabled` and remove the misleading token capability warning from `project doctor`. Update consumers of the old `tokenEnabled` result field.
Expand Down
14 changes: 14 additions & 0 deletions docs/automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,20 @@ Safe branch fields by command shape:
- Show/create/update: `projectId`, `feature`, `configId`, `enabled`, `eventIds`, `urlRegion`
- Delete: `projectId`, `feature`, `configId`, `deleted`

### `telemetry status`, `telemetry enable`, `telemetry disable`

The `telemetry` result reports these fields:

- `action` identifies the operation as `status`, `enable`, or `disable`.
- `configPath` is the local configuration file path.
- `doNotTrack` indicates whether `DO_NOT_TRACK` is set to a non-empty value.
- `savedPreference` is the configured telemetry preference.
- `enabled` combines the preference and runtime opt-outs.
- `transportConfigured` indicates whether a valid collector URL is configured.
- `captureActive` requires both `enabled` and `transportConfigured`.

The `agora.telemetry.status` MCP tool returns the same fields.

### `config path`

Example:
Expand Down
129 changes: 71 additions & 58 deletions docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,80 +4,93 @@ title: Telemetry

# Telemetry

Agora CLI telemetry is limited to operational diagnostics such as command
failures and local log metadata. It **never** includes OAuth tokens, app
certificates, dotenv secrets, or project env values. Field redaction is
enforced by `redactTelemetryFields` in
[`internal/cli/telemetry.go`](https://github.com/AgoraIO/cli/blob/main/internal/cli/telemetry.go),
which matches the `token | secret | password | api[_-]?key | authorization`
key pattern (case-insensitive) and replaces the value with the literal
`[REDACTED]`.

> **Status (current release):** the on/off contract below is fully
> wired. The transport (Sentry SDK) is not yet linked into the binary,
> so all telemetry calls are no-ops at runtime. The next release will
> wire Sentry; the surface and field schema will not change.
Agora CLI can report Recipes usage, init stages/results and project creation
results to the CLI BFF, which forwards allowlisted events to PostHog. Capture is
enabled by default when a valid collector URL is configured, unless the user
opts out. The embedded collector URL is currently empty; deployment and release
configuration are required before production capture is active.

Events contain a random local installation ID, a per-operation ID, CLI version,
OS/architecture, coarse AI-tool categories, public recipe/template IDs, timings
and structured results. Project/init events can include validated Agora App IDs.
An installation profile can be created in PostHog. Agora App IDs can be
associated with Agora projects and companies. OAuth tokens, App Certificates, project names, source code, conversation
content, local paths and raw errors are not included.

Recipe init attempts are labeled as Recipe usage even if the catalog lookup
fails. Only attempts with a confirmed public catalog entry include a Recipe ID.
When reporting per-Recipe results, show unconfirmed attempts separately.
An existing target directory is reported as a local validation failure.

## Delivery

Each instrumented shell command collects its events in memory and flushes them
when the operation finishes. MCP flushes after each instrumented tool call,
independently of other calls and without waiting for the MCP server to exit.

The CLI passes one JSON batch through stdin to a detached sender subprocess.
The sender makes one HTTP request with a ten-second timeout. The business
command waits only for a local handoff of at most 100 ms, not for the network
response. Telemetry failures do not change business output or exit codes.

The complete request is limited to 64 KiB. There is no separate event-count or
per-event size cap. If an operation exceeds the request limit, its entire batch
is dropped. There is no disk queue or retry. A crash or forced termination before
handoff can lose all events for that operation; long-running operations are not
visible in telemetry until they finish. Successful delivery is best effort and
does not prove that PostHog has made the events available for queries.

The sender honors `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` and their lowercase
forms, as the business HTTP client does. It also preserves `SSL_CERT_FILE` and
`SSL_CERT_DIR` for custom certificate authorities. Other parent environment
variables are not inherited. Business authorization headers are not attached to
telemetry requests, and redirects are not followed.

## Inspect or change the setting

Telemetry is enabled by default in the local config.

```bash
agora telemetry status
agora telemetry disable
agora telemetry enable
```

For scripts, prefer JSON:

```bash
agora telemetry status --json
agora telemetry disable --json
agora telemetry enable --json
```

## Opt-out signals
`savedPreference` reports the configured preference. `enabled` also accounts
for runtime opt-outs. `transportConfigured` reports whether a valid collector
URL is configured. `captureActive` requires both `enabled` and
`transportConfigured`. It tracks whether capture can start.

The CLI honors **all** of the following — any one of them disables
telemetry for the current process:
Shell commands print a first-use disclosure to stderr unless quiet mode
suppresses it. MCP includes the disclosure in its initialization instructions
when a collector is configured. MCP hosts decide how to present instructions.
The disclosure provides notice. The first instrumented call can collect events
when capture is active.

| Signal | Notes |
|--------|-------|
| `DO_NOT_TRACK=<any non-empty>` | Standard cross-tool convention. Also suppresses local file logs for that process. |
| `AGORA_SENTRY_ENABLED=0` | Hard env override. Wins over the config file. |
| `agora telemetry disable` | Persists `telemetryEnabled: false` to the config. |
| `agora config update --telemetry-enabled=false` | Equivalent to `agora telemetry disable`. |
Any of these signals disables capture:

```bash
DO_NOT_TRACK=1 agora project list --json
AGORA_SENTRY_ENABLED=0 agora init my-app --template nextjs --json
```
| Signal | Effect |
|--------|--------|
| `DO_NOT_TRACK=<any non-empty>` | Runtime opt-out. Also suppresses local file logs. |
| `AGORA_TELEMETRY_ENABLED=0` | Runtime opt-out for usage capture. |
| `AGORA_SENTRY_ENABLED=0` | Runtime opt-out honored by usage capture. |
| `agora telemetry disable` | Saves `telemetryEnabled: false`. |
| `agora config update --telemetry-enabled=false` | Saves the same preference. |

## Field schema
Shell commands use their startup preference. A running MCP server rereads the
saved preference when each tool call starts. A preference change does not alter
an operation that has already started.

The wire-up plan documents the **exact** field set the Sentry-backed
sink will send. Until then the table below is forward-looking; treat it
as the specification, not the production behavior:
## Collector configuration

| Field | Type | Example | Notes |
|-----------------|--------|------------------------------------|-------|
| `command` | string | `"project create"` | Stable label from `agora introspect --json`. |
| `exitCode` | int | `1` | Process exit code at failure. |
| `commitSha` | string | `"abc1234"` | Build-time injected. |
| `os` | string | `"darwin/arm64"` | Runtime, not host-specific. |
| `installMethod` | string | `"installer"` / `"npm"` / `"brew"` | From the install provenance receipt. |
| `agentLabel` | string | `"cursor"` | From `agent_infer.go`. |
`AGORA_TELEMETRY_URL` overrides the release-embedded collector URL. Only HTTPS
URLs, or HTTP URLs on loopback for local verification, are accepted. URLs with
credentials, query parameters or fragments are rejected.

Explicitly **never** sent:
The existing operational-diagnostics sink is separate from these usage events;
its Sentry transport remains a placeholder. Usage capture does not require an
OAuth login or a client-side PostHog API key.

- OAuth tokens or session refresh tokens.
- Agora App Certificate values.
- Project names or App IDs (use opaque hashes if needed in the future).
- Local file paths beyond the rotating log file path basename.

## Where the config lives
The configuration location is available with:

```bash
agora config path
```

The same directory holds the rotating log file (`agora-cli.log`) and
the project list cache used by shell completion.
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ go 1.26.6
require (
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
golang.org/x/sys v0.47.0
golang.org/x/term v0.45.0
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
golang.org/x/sys v0.47.0 // indirect
)
require github.com/inconshreveable/mousetrap v1.1.0 // indirect
6 changes: 4 additions & 2 deletions internal/cli/agent_infer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ func agentLabelFromOSEnv(env map[string]string) string {
switch {
case nonEmptyEnv(env, "CURSOR_AGENT"):
return "cursor"
case nonEmptyEnv(env, "CLAUDE_CODE"):
case nonEmptyEnv(env, "CLAUDE_CODE") || nonEmptyEnv(env, "CLAUDECODE"):
return "claude-code"
case hasEnvPrefix(env, "CLINE_"):
return "cline"
case hasEnvPrefix(env, "WINDSURF_"):
return "windsurf"
case hasEnvPrefix(env, "OPENAI_CODEX_"):
case nonEmptyEnv(env, "CODEX_THREAD_ID") || hasEnvPrefix(env, "OPENAI_CODEX_"):
return "codex"
case nonEmptyEnv(env, "KIRO_SESSION_ID"):
return "kiro"
case hasEnvPrefix(env, "AIDER_"):
return "aider"
default:
Expand Down
13 changes: 12 additions & 1 deletion internal/cli/agent_infer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ func TestAgentLabelFromOSEnv(t *testing.T) {
}{
{name: "explicit wins", env: map[string]string{"AGORA_AGENT": "custom", "CURSOR_AGENT": "1"}, want: "custom"},
{name: "disabled", env: map[string]string{"AGORA_AGENT_DISABLE_INFER": "1", "CURSOR_AGENT": "1"}, want: ""},
{name: "explicit wins over codex", env: map[string]string{"AGORA_AGENT": "custom", "CODEX_THREAD_ID": "thread-123"}, want: "custom"},
{name: "disabled codex", env: map[string]string{"AGORA_AGENT_DISABLE_INFER": "1", "CODEX_THREAD_ID": "thread-123"}, want: ""},
{name: "cursor", env: map[string]string{"CURSOR_AGENT": "1"}, want: "cursor"},
{name: "claude code", env: map[string]string{"CLAUDE_CODE": "1"}, want: "claude-code"},
{name: "cline", env: map[string]string{"CLINE_SESSION": "abc"}, want: "cline"},
{name: "windsurf", env: map[string]string{"WINDSURF_SESSION": "abc"}, want: "windsurf"},
{name: "codex", env: map[string]string{"OPENAI_CODEX_SESSION": "abc"}, want: "codex"},
{name: "codex thread", env: map[string]string{"CODEX_THREAD_ID": "thread-123"}, want: "codex"},
{name: "codex legacy", env: map[string]string{"OPENAI_CODEX_SESSION": "abc"}, want: "codex"},
{name: "codex empty thread", env: map[string]string{"CODEX_THREAD_ID": ""}, want: ""},
{name: "aider", env: map[string]string{"AIDER_AUTO_COMMITS": "false"}, want: "aider"},
{name: "empty", env: map[string]string{}, want: ""},
}
Expand All @@ -37,6 +41,13 @@ func TestAgoraUserAgentInfersCursorAgent(t *testing.T) {
}
}

func TestAgoraUserAgentInfersCodexThread(t *testing.T) {
got := agoraUserAgent(map[string]string{"CODEX_THREAD_ID": "thread-123"})
if got != "agora-cli/"+version+" agent/codex" {
t.Fatalf("unexpected user agent: %q", got)
}
}

// TestDecideShouldPromptForLoginYesFlagDoesNotBypassGuards is the
// regression test for the bug where `--yes` / AGORA_NO_INPUT used to
// short-circuit the JSON/CI/non-TTY guards in shouldPromptForLogin and
Expand Down
Loading
Loading