From f2a293c026042a91e2ef6c747714637a7e8e018e Mon Sep 17 00:00:00 2001 From: liruifengv Date: Thu, 30 Jul 2026 02:26:00 +0800 Subject: [PATCH] feat(cli): tag kimi web requests with a (web) User-Agent suffix kimi web shares the CLI product token and platform, so its outbound requests were indistinguishable from direct CLI runs upstream. Its host identity now carries userAgentSuffix 'web', putting web-UI traffic at kimi-code-cli/ (web) while X-Msh-Platform stays kimi_code_cli. --- .changeset/cli-web-login-identity.md | 2 +- apps/kimi-code/src/cli/sub/web/run.ts | 11 ++++++++--- apps/kimi-code/src/constant/app.ts | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.changeset/cli-web-login-identity.md b/.changeset/cli-web-login-identity.md index 8faec1cd1..d76bc70ba 100644 --- a/.changeset/cli-web-login-identity.md +++ b/.changeset/cli-web-login-identity.md @@ -2,4 +2,4 @@ "@moonshot-ai/kimi-code": patch --- -Send the CLI's device identity headers with OAuth login and token refresh requests from kimi web, and record the host product version in session export manifests. +Send the CLI's device identity headers with OAuth login and token refresh requests from kimi web, tag web-UI requests with a `(web)` User-Agent suffix so upstream can tell them apart from direct CLI traffic, and record the host product version in session export manifests. diff --git a/apps/kimi-code/src/cli/sub/web/run.ts b/apps/kimi-code/src/cli/sub/web/run.ts index b71673d60..26088c05f 100644 --- a/apps/kimi-code/src/cli/sub/web/run.ts +++ b/apps/kimi-code/src/cli/sub/web/run.ts @@ -16,7 +16,7 @@ import { shutdownTelemetry, track } from '@moonshot-ai/kimi-telemetry'; import chalk from 'chalk'; import { type Command } from 'commander'; -import { CLI_SHUTDOWN_TIMEOUT_MS } from '#/constant/app'; +import { CLI_SHUTDOWN_TIMEOUT_MS, WEB_USER_AGENT_SUFFIX } from '#/constant/app'; import { getNativeWebAssetsDir } from '#/native/web-assets'; import { darkColors } from '#/tui/theme/colors'; import { openUrl as defaultOpenUrl } from '#/utils/open-url'; @@ -280,8 +280,13 @@ async function runServerInProcess( serverVersion: version, // The CLI's host identity: feeds the engine's bootstrap client identity // and the derived outbound headers (User-Agent + X-Msh-*), so web-UI - // OAuth flows and model / WebSearch requests carry the CLI identity. - hostIdentity: createKimiCodeHostIdentity(version), + // OAuth flows and model / WebSearch requests carry the CLI identity. The + // `web` User-Agent suffix distinguishes web-UI traffic from direct CLI + // runs upstream (same product token, same platform). + hostIdentity: { + ...createKimiCodeHostIdentity(version), + userAgentSuffix: WEB_USER_AGENT_SUFFIX, + }, logLevel: options.logLevel, logger, debugEndpoints: options.debugEndpoints, diff --git a/apps/kimi-code/src/constant/app.ts b/apps/kimi-code/src/constant/app.ts index 59aa18797..b7cd74939 100644 --- a/apps/kimi-code/src/constant/app.ts +++ b/apps/kimi-code/src/constant/app.ts @@ -10,6 +10,10 @@ export const CLI_UI_MODE = 'shell'; // Telemetry ui_mode for the `kimi web` host. Same product // as the CLI (CLI_USER_AGENT_PRODUCT); the surface is distinguished by ui_mode. export const WEB_UI_MODE = 'web'; +// User-Agent suffix for the `kimi web` host: its requests go out as +// `kimi-code-cli/ (web)` so upstream can tell web-UI traffic +// apart from direct CLI runs without changing the product token or platform. +export const WEB_USER_AGENT_SUFFIX = 'web'; // Give telemetry a short flush window without making CLI exit feel stuck. export const CLI_SHUTDOWN_TIMEOUT_MS = 3000;