Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/rc-local-ui-token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Include the server token in the Remote Control Local UI link so it opens already signed in.
8 changes: 7 additions & 1 deletion apps/kimi-code/src/cli/sub/web/remote-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getVersion } from '../../version';
import { darkColors } from '../../../tui/theme/colors';
import { supportsHyperlinks, toTerminalHyperlink } from '../../../utils/terminal-hyperlink';
import type { RemoteControlStatus } from '@moonshot-ai/remote-control';
import { buildOpenableUrl, splitTokenFragment } from './access-urls';

export {
acquireRemoteControlLock,
Expand Down Expand Up @@ -32,6 +33,7 @@ export type {
export interface RemoteControlOutputOptions {
readonly url: string;
readonly localOrigin: string;
readonly localServerToken: string;
readonly deviceName: string;
readonly qrCode: string;
readonly pngPath: string;
Expand All @@ -41,12 +43,16 @@ export function formatRemoteControlOutput(options: RemoteControlOutputOptions):
const title = (text: string): string => chalk.bold.hex(darkColors.primary)(text);
const label = (text: string): string => chalk.bold.hex(darkColors.textDim)(text);
const accent = (text: string): string => chalk.hex(darkColors.accent)(text);
const dim = (text: string): string => chalk.hex(darkColors.textDim)(text);
const muted = (text: string): string => chalk.hex(darkColors.textMuted)(text);
const status = (text: string): string => chalk.hex(darkColors.success)(text);
const link = (url: string): string =>
supportsHyperlinks() ? toTerminalHyperlink(accent(url), url) : accent(url);
const docs = toTerminalHyperlink('docs', 'https://kimi.com/code/docs/remote-control');
const feedback = toTerminalHyperlink('feedback', 'https://kimi.com/code/feedback');
const [localBase, localFrag] = splitTokenFragment(
buildOpenableUrl(options.localOrigin, options.localServerToken),
);
return [
'',
` ${title('Kimi Remote Control ready')} ${muted(getVersion())}`,
Expand All @@ -62,7 +68,7 @@ export function formatRemoteControlOutput(options: RemoteControlOutputOptions):
'',
options.qrCode.trimEnd().replaceAll(/^/gm, ' '),
` ${label('QR code PNG: ')}${options.pngPath} ${muted('(open this if the QR above does not scan)')}`,
` ${label('Local UI: ')}${muted(options.localOrigin)} ${muted('(LAN: --host)')}`,
` ${label('Local UI: ')}${accent(localBase)}${dim(localFrag)} ${muted('(LAN: --host)')}`,
'',
` ${docs} ${muted('·')} ${feedback}`,
` ${label('Logs: ')}${muted('off (--log-level info)')} ${muted('·')} ${label('Stop: ')}${muted('Ctrl+C')}`,
Expand Down
1 change: 1 addition & 0 deletions apps/kimi-code/src/cli/sub/web/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export async function handleWebCommand(
formatRemoteControlOutput({
url: remoteControl.url,
localOrigin: origin,
localServerToken: token,
deviceName: remoteControl.deviceName,
qrCode: qrCode.terminal,
pngPath: qrCode.pngPath,
Expand Down
1 change: 1 addition & 0 deletions apps/kimi-code/src/tui/commands/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export async function handleRemoteControlCommand(host: SlashCommandHost): Promis
formatRemoteControlOutput({
url,
localOrigin: origin,
localServerToken: token,
deviceName: remoteControl.deviceName,
qrCode: qrCode.terminal,
pngPath: qrCode.pngPath,
Expand Down
4 changes: 4 additions & 0 deletions apps/kimi-code/test/cli/web/remote-control.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Remote Control output', () => {
const outputOptions = {
url: 'https://example.test/devices/example-device/?rc=1&from=kimi_code_cli',
localOrigin: 'http://127.0.0.1:1234',
localServerToken: 'example-token',
deviceName: 'example-device',
qrCode: 'QR\n',
pngPath: '/tmp/example-qr.png',
Expand All @@ -32,6 +33,8 @@ describe('Remote Control output', () => {
.replaceAll(/\u001B\[[0-9;]*m/g, '');
expect(plain).toContain(`open ${url}`);
expect(plain).not.toContain('exampl…');
expect(plain).toContain('http://127.0.0.1:1234/#token=example-token');
expect(output).toContain('#token=example-token');
expect(output).toContain('Connected to example.test');
expect(output).toContain('This device:');
expect(output).not.toContain('Manage devices');
Expand All @@ -48,6 +51,7 @@ describe('Remote Control output', () => {
vi.stubEnv('FORCE_HYPERLINK', '0');
const output = formatRemoteControlOutput(outputOptions);
expect(output).toContain(`open ${outputOptions.url}`);
expect(output).toContain('#token=example-token');
expect(output).not.toContain('exampl…vice');
expect(output).not.toContain('Manage devices');
});
Expand Down
7 changes: 5 additions & 2 deletions apps/kimi-code/test/tui/commands/web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,11 @@ describe('handleRemoteControlCommand', () => {
const png = readFileSync(pngPath);
expect(png.subarray(0, 8)).toEqual(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]));
expect(png).toEqual(await QRCode.toBuffer(sessionUrl));
expect(written).not.toContain('local-server-token');
expect(written).not.toContain('#token=');
expect(written).toContain(
'Local UI: http://127.0.0.1:58627/#token=local-server-token',
);
expect(written).not.toContain(`${entryUrl}#token=`);
expect(written).not.toContain(`${sessionUrl}#token=`);
expect(close).toHaveBeenCalledOnce();
} finally {
writeSpy.mockRestore();
Expand Down
Loading