Explorar o código

docs: clarify telemetry channel status and usage previews

Expose all three telemetry channel settings, scope previews to usage
events, and document independent opt-ins and automatic diagnostics.
Include the matching CLI regression test.
saladday hai 2 meses
pai
achega
30dd6f27f1

+ 18 - 8
docs/telemetry.md

@@ -1,6 +1,6 @@
-# TUI usage telemetry
+# Telemetry
 
 
-MCode's TUI usage telemetry is disabled by default. No business telemetry client is created and no business telemetry request is sent until the user opts in.
+All automatic telemetry uploads are disabled by default and each requires its own opt-in: TUI usage events (`telemetry.enabled`), runtime performance metrics (`telemetry.metrics`), and automatic error diagnostics (`telemetry.diagnostics`). Opting in to usage events does not authorize the other two channels. Login, model requests, update checks, and user-submitted feedback are separate product actions and are not controlled by these switches.
 
 
 ## Turn it on or off
 ## Turn it on or off
 
 
@@ -8,19 +8,21 @@ Add this to the active profile's `config.yaml`, normally `~/.minimax-code/config
 
 
 ```yaml
 ```yaml
 telemetry:
 telemetry:
-  enabled: true
+  enabled: true      # TUI usage events (anonymous, described below)
+  metrics: false     # Runtime counters, gauges, and histograms
+  diagnostics: false # Account-linked TUI and LLM error diagnostics
 ```
 ```
 
 
-Remove the setting or set it to `false` to turn reporting off. Either environment variable below also turns it off and takes precedence over the config file:
+Remove a setting or set it to `false` to turn that channel off. Either environment variable below turns **all channels** off and takes precedence over the config file:
 
 
 ```sh
 ```sh
 MCODE_DISABLE_TELEMETRY=1 mcode
 MCODE_DISABLE_TELEMETRY=1 mcode
 DO_NOT_TRACK=1 mcode
 DO_NOT_TRACK=1 mcode
 ```
 ```
 
 
-Inspect the effective setting with `mcode telemetry status`. Run `mcode telemetry preview` to see a representative decoded request. Preview does not send a request. When telemetry is disabled, preview shows `request: null`.
+Inspect the effective setting of every channel with `mcode telemetry status`. Run `mcode telemetry preview` to see a representative decoded usage-event request. Preview does not send a request. When usage telemetry is disabled, preview shows `request: null`, independently of the metrics and diagnostics settings.
 
 
-## Data sent
+## Usage-event data sent
 
 
 The HTTP body is `application/x-www-form-urlencoded` with two fields:
 The HTTP body is `application/x-www-form-urlencoded` with two fields:
 
 
@@ -68,7 +70,7 @@ MCode does not send account IDs, device IDs, workspace paths or names, session I
 
 
 As with any network request, the receiving server can observe transport metadata such as the source IP address. The client does not add that value to the event payload. `mcode telemetry preview` displays the decoded envelope.
 As with any network request, the receiving server can observe transport metadata such as the source IP address. The client does not add that value to the event payload. `mcode telemetry preview` displays the decoded envelope.
 
 
-## Destinations
+## Usage-event destinations
 
 
 The destination depends on region and build environment:
 The destination depends on region and build environment:
 
 
@@ -79,4 +81,12 @@ The destination depends on region and build environment:
 
 
 The client keeps pending events only in memory and does not write them to disk. This repository does not define or verify server-side retention. Keep telemetry disabled when that policy does not meet your requirements.
 The client keeps pending events only in memory and does not write them to disk. This repository does not define or verify server-side retention. Keep telemetry disabled when that policy does not meet your requirements.
 
 
-This page covers TUI usage telemetry. Login, model requests, update checks, user-submitted feedback, and bounded error diagnostics have separate network behavior described in [TUI capability coverage](tui-capabilities.md).
+## Runtime performance metrics
+
+`telemetry.metrics: true` enables the built-in cloud metrics transport: metric names, timestamps, counter/gauge/histogram values, and low-cardinality labels (runtime owner and mode, version, and per-instrument dimensions such as model, tool, or outcome). No account credential is attached. Production destinations are `https://agent.minimax.cn/matrix/api/v1/metrics/batch` (China) and `https://agent.minimax.io/matrix/api/v1/metrics/batch` (global). Metrics stay in memory; when the channel is disabled, no cloud reporter is created.
+
+## Automatic error diagnostics
+
+`telemetry.diagnostics: true` authorizes both TUI incident reports and LLM request-failure reports. Both additionally require a signed-in account: the transport uses the account's Bearer token and a `user_id` query parameter, so these reports are **account-linked** even though their contents are minimized and encrypted. The minimization schemas are described in [TUI capability coverage](tui-capabilities.md#diagnostic-upload-privacy). Both use `/minimax-cloud/api/v1/observability/desktop-errors/batch` on the regional MiniMax host. When the channel is disabled, TUI incidents are written as local-only files (7 days / 200 files) that are never uploaded, and LLM failure reports are dropped before buffering.
+
+Server-side retention for any channel is not defined or verified by this repository. Login, model requests, update checks, and user-submitted feedback have separate network behavior described in [TUI capability coverage](tui-capabilities.md).

+ 2 - 2
docs/tui-capabilities.md

@@ -14,8 +14,8 @@ The evidence column summarizes the historical TUI 0.3.11 restoration record from
 | Managed connectors | Cloud client, permissions, and invocation adapters restored | Connector runtime and cloud transport tests; actual tool discovery passed; business writes not run |
 | Managed connectors | Cloud client, permissions, and invocation adapters restored | Connector runtime and cloud transport tests; actual tool discovery passed; business writes not run |
 | Updates | Update entry points, install-source detection, and signature verification restored; public packages use public npm | Update application and service tests; no real installation / upgrade on the development machine |
 | Updates | Update entry points, install-source detection, and signature verification restored; public packages use public npm | Update application and service tests; no real installation / upgrade on the development machine |
 | Feedback and diagnostic uploads | Reviewed feedback text and minimized diagnostic summaries | Synthetic fixtures exercise session collection and capture/decode the final ZIP upload; no live uploads or real content |
 | Feedback and diagnostic uploads | Reviewed feedback text and minimized diagnostic summaries | Synthetic fixtures exercise session collection and capture/decode the final ZIP upload; no live uploads or real content |
-| Automatic LLM error reports | Bounded diagnostic facts minimized before encryption | Synthetic provider errors and native Headers; final HTTP batches captured and decrypted locally |
-| Telemetry | Disabled by default; explicit opt-in with environment overrides; account, device, workspace, session, model, and command identifiers removed | Privacy regression tests intercept and decode requests locally; no live upload |
+| Automatic LLM error reports | Disabled by default; requires `telemetry.diagnostics` opt-in; bounded diagnostic facts minimized before encryption | Synthetic provider errors and native Headers; final HTTP batches captured and decrypted locally |
+| Telemetry | Usage, metrics, and diagnostics each disabled by default with separate opt-ins; `MCODE_DISABLE_TELEMETRY` / `DO_NOT_TRACK` override all channels; usage-event identifiers removed | Privacy regression tests intercept and decode requests locally; no live upload |
 | Auto permissions | Cloud classifier restored; local rules and confirmation on failure retained | Classifier client, permission facade, and sandbox tests |
 | Auto permissions | Cloud classifier restored; local rules and confirmation on failure retained | Classifier client, permission facade, and sandbox tests |
 | Model catalog | Online catalog and bundled snapshot fallback restored | Actual build boundary checks and offline startup; online catalog contents not accepted |
 | Model catalog | Online catalog and bundled snapshot fallback restored | Actual build boundary checks and offline startup; online catalog contents not accepted |
 | Files, shell, subagents, sessions, headless, ACP | Actual runtime retained | BYOK, file reads, session resume, ACP, sandbox, and status protocol tests |
 | Files, shell, subagents, sessions, headless, ACP | Actual runtime retained | BYOK, file reads, session resume, ACP, sandbox, and status protocol tests |

+ 10 - 6
packages/tui/src/cli/telemetry-command.ts

@@ -23,16 +23,20 @@ export function runMcodeTelemetryCommand(
 ): string {
 ): string {
   const environment = dependencies.environment ?? process.env;
   const environment = dependencies.environment ?? process.env;
   const config = (dependencies.readConfig ?? getConfig)();
   const config = (dependencies.readConfig ?? getConfig)();
-  const policy = resolveMcodeBusinessTelemetryPolicy({
-    configEnabled: config.telemetry.enabled,
-    environment,
-  });
+  const channel = (configEnabled: boolean | undefined) =>
+    resolveMcodeBusinessTelemetryPolicy({ configEnabled, environment });
+  const policy = channel(config.telemetry.enabled);
   const status = {
   const status = {
     enabled: policy.enabled,
     enabled: policy.enabled,
     configured: policy.configured,
     configured: policy.configured,
     blockedBy: policy.blockedBy ?? null,
     blockedBy: policy.blockedBy ?? null,
     configFile: (dependencies.readConfigPath ?? getConfigPath)(),
     configFile: (dependencies.readConfigPath ?? getConfigPath)(),
-    optInSetting: { telemetry: { enabled: true } },
+    channels: {
+      usage: policy,
+      metrics: channel(config.telemetry.metrics),
+      diagnostics: channel(config.telemetry.diagnostics),
+    },
+    optInSetting: { telemetry: { enabled: true, metrics: true, diagnostics: true } },
     optOutEnvironment: ['MCODE_DISABLE_TELEMETRY=1', 'DO_NOT_TRACK=1'],
     optOutEnvironment: ['MCODE_DISABLE_TELEMETRY=1', 'DO_NOT_TRACK=1'],
   };
   };
   if (action === 'status') return `${JSON.stringify(status, null, 2)}\n`;
   if (action === 'status') return `${JSON.stringify(status, null, 2)}\n`;
@@ -41,7 +45,7 @@ export function runMcodeTelemetryCommand(
       {
       {
         ...status,
         ...status,
         request: null,
         request: null,
-        message: 'Telemetry is disabled. No business telemetry request will be sent.',
+        message: 'Usage telemetry is disabled. No business telemetry request will be sent.',
       },
       },
       null,
       null,
       2,
       2,

+ 17 - 0
packages/tui/test/unit/business-telemetry-privacy.test.ts

@@ -176,6 +176,23 @@ describe('business telemetry privacy', () => {
     expect(createTelemetry).toHaveBeenCalledOnce();
     expect(createTelemetry).toHaveBeenCalledOnce();
   });
   });
 
 
+  it('distinguishes disabled usage previews from enabled metrics and diagnostics', () => {
+    const output = JSON.parse(runMcodeTelemetryCommand('preview', '0.4.12', {
+      environment: {},
+      readConfig: () => ({ telemetry: { enabled: false, metrics: true, diagnostics: true } }),
+      readConfigPath: () => '/tmp/config.yaml',
+    }));
+    expect(output).toMatchObject({
+      request: null,
+      channels: {
+        usage: { enabled: false },
+        metrics: { enabled: true },
+        diagnostics: { enabled: true },
+      },
+      message: 'Usage telemetry is disabled. No business telemetry request will be sent.',
+    });
+  });
+
   it('reports disabled status and exposes status and preview CLI subcommands', async () => {
   it('reports disabled status and exposes status and preview CLI subcommands', async () => {
     const output = runMcodeTelemetryCommand('preview', '0.4.12', {
     const output = runMcodeTelemetryCommand('preview', '0.4.12', {
       environment: {},
       environment: {},