From 2b1236ae6351af25ab004dcef41b6d6d31eea0e0 Mon Sep 17 00:00:00 2001 From: VectorPeak <73048950+VectorPeak@users.noreply.github.com> Date: Mon, 6 Jul 2026 00:52:37 +0800 Subject: [PATCH] fix(kimi-code): format IPv6 server origins correctly --- .changeset/server-ipv6-origin.md | 5 +++++ apps/kimi-code/src/cli/sub/server/shared.ts | 8 +++++++- apps/kimi-code/test/cli/server/server.test.ts | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .changeset/server-ipv6-origin.md diff --git a/.changeset/server-ipv6-origin.md b/.changeset/server-ipv6-origin.md new file mode 100644 index 000000000..dd7636082 --- /dev/null +++ b/.changeset/server-ipv6-origin.md @@ -0,0 +1,5 @@ +--- +"@moonshot-ai/kimi-code": patch +--- + +Format IPv6 server host literals with brackets when building server origins. diff --git a/apps/kimi-code/src/cli/sub/server/shared.ts b/apps/kimi-code/src/cli/sub/server/shared.ts index aa2b686ce..6d2a3218f 100644 --- a/apps/kimi-code/src/cli/sub/server/shared.ts +++ b/apps/kimi-code/src/cli/sub/server/shared.ts @@ -10,6 +10,8 @@ import { join } from 'node:path'; import type { ServerLogLevel } from '@moonshot-ai/server'; +import { formatHostForUrl } from './networks'; + export const LOCAL_SERVER_HOST = '127.0.0.1'; export const DEFAULT_LAN_HOST = '0.0.0.0'; export const DEFAULT_SERVER_HOST = LOCAL_SERVER_HOST; @@ -158,7 +160,11 @@ export function parseLogLevel(raw: string | undefined): ServerLogLevel { } export function serverOrigin(host: string, port: number): string { - return `http://${host}:${port}`; + const formattedHost = + host.startsWith('[') && host.endsWith(']') + ? host + : formatHostForUrl(host, host.includes(':') ? 'IPv6' : 'IPv4'); + return `http://${formattedHost}:${port}`; } /** Strip `/api/v1` and trailing slashes so user-supplied origins are uniform. */ diff --git a/apps/kimi-code/test/cli/server/server.test.ts b/apps/kimi-code/test/cli/server/server.test.ts index b6ee71f95..848ed16d0 100644 --- a/apps/kimi-code/test/cli/server/server.test.ts +++ b/apps/kimi-code/test/cli/server/server.test.ts @@ -669,6 +669,13 @@ describe('shared parsers stay strict', () => { expect(parseLogLevel(undefined)).toBe('info'); expect(parseLogLevel('debug')).toBe('debug'); }); + + it('wraps IPv6 hosts when formatting server origins', async () => { + const { serverOrigin } = await import('#/cli/sub/server/shared'); + expect(serverOrigin('::1', 58627)).toBe('http://[::1]:58627'); + expect(serverOrigin('127.0.0.1', 58627)).toBe('http://127.0.0.1:58627'); + expect(serverOrigin('[::1]', 58627)).toBe('http://[::1]:58627'); + }); }); describe('server web asset directory resolution', () => {