From dd08a4cfd846cc66ea6f39e97889c699272b32e2 Mon Sep 17 00:00:00 2001 From: qer Date: Sat, 11 Jul 2026 23:18:18 +0800 Subject: [PATCH] fix(cli): seed host identity headers into the experimental v2 server The v2 boot path (kimi server run with the experimental flag) now seeds the CLI's Kimi identity headers (User-Agent + X-Msh-* device identity) into the engine through kap-server's seeds option, so outbound model, WebSearch, and FetchURL requests carry the same identity as direct CLI runs. kap-server's own package version is 0.0.0, so the identity has to come from the CLI. --- .changeset/v2-server-host-headers.md | 5 +++++ apps/kimi-code/src/cli/sub/server/run.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .changeset/v2-server-host-headers.md diff --git a/.changeset/v2-server-host-headers.md b/.changeset/v2-server-host-headers.md new file mode 100644 index 000000000..e19b86c80 --- /dev/null +++ b/.changeset/v2-server-host-headers.md @@ -0,0 +1,5 @@ +--- +"@moonshot-ai/kimi-code": patch +--- + +Send the CLI identity headers (User-Agent and device identity) with outbound requests from the experimental v2 server, matching direct CLI runs. diff --git a/apps/kimi-code/src/cli/sub/server/run.ts b/apps/kimi-code/src/cli/sub/server/run.ts index 1828d4049..63386b7a6 100644 --- a/apps/kimi-code/src/cli/sub/server/run.ts +++ b/apps/kimi-code/src/cli/sub/server/run.ts @@ -26,7 +26,12 @@ import { openUrl as defaultOpenUrl } from '#/utils/open-url'; import { getDataDir } from '#/utils/paths'; import { initializeServerTelemetry } from '../../telemetry'; -import { createKimiCodeHostIdentity, getHostPackageRoot, getVersion } from '../../version'; +import { + buildKimiDefaultHeaders, + createKimiCodeHostIdentity, + getHostPackageRoot, + getVersion, +} from '../../version'; import { accessUrlLines, buildOpenableUrl, @@ -406,6 +411,7 @@ async function runServerInProcess( // its agent-core-v2 engine are only resolved when the flag is on. const { createServerLogger: createServerV2Logger, startServer: startServerV2 } = await import('@moonshot-ai/kap-server'); + const { hostRequestHeadersSeed } = await import('@moonshot-ai/agent-core-v2'); const logger = createServerV2Logger({ level: options.logLevel }); const v2 = await startServerV2({ host: options.host, @@ -418,6 +424,10 @@ async function runServerInProcess( allowRemoteTerminals: options.allowRemoteTerminals, allowedHosts: options.allowedHosts, disableAuth: options.dangerousBypassAuth, + // Seed the CLI's Kimi identity headers so the v2 engine's outbound + // requests (model, WebSearch, FetchURL) carry the same User-Agent + + // X-Msh-* identity as direct CLI runs. + seeds: hostRequestHeadersSeed(buildKimiDefaultHeaders(version)), webAssetsDir: serverWebAssetsDir(), }); // v2's connection registry exposes no count-change hook, so forward