Skip to content

feat(kimi-code): add remote control web tunnel - #3034

Open
sailist wants to merge 10 commits into
MoonshotAI:mainfrom
sailist:feat-000-08-06-rc
Open

feat(kimi-code): add remote control web tunnel#3034
sailist wants to merge 10 commits into
MoonshotAI:mainfrom
sailist:feat-000-08-06-rc

Conversation

@sailist

@sailist sailist commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This change adds the missing client-side support needed to access a local Kimi web session through Remote Control.

Problem

kimi web is currently reachable only from the local machine or through a separately configured network exposure. Kimi Code needs a single-command remote mode that keeps the local server authenticated while bridging browser HTTP and WebSocket traffic through the hosted relay.

What changed

  • Added kimi web --remote-control with --rc as an alias, plus /remote-control and /rc in the TUI.
  • Added an embedded tunnel client for management, HTTP, and WebSocket streams, including OAuth credential lookup, local server authentication, registration errors, and reconnect handling.
  • Rewrote tunneled web asset, API, WebSocket, and session-route paths under the remote device prefix without changing direct local web behavior.
  • Added focused CLI and TUI coverage and a user-facing changeset.

Validation:

  • pnpm --filter @moonshot-ai/kimi-code exec vitest run test/cli/web/remote-control.test.ts test/cli/web/web.test.ts test/tui/commands/web.test.ts
  • pnpm --filter @moonshot-ai/kimi-code run typecheck
  • pnpm --filter @moonshot-ai/kimi-code run build
  • pnpm --filter @moonshot-ai/kimi-code run build:native:js
  • Targeted oxlint on the changed TypeScript files

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b8ef5de

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Aug 18, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@b8ef5de
npx https://pkg.pr.new/@moonshot-ai/kimi-code@b8ef5de

commit: b8ef5de

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5bf88cb3b2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +346 to +348
const http = await this.connectRelay(
`/v1/remote/http?device_id=${encodeURIComponent(this.deviceId)}`,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Observe management closure before opening the HTTP tunnel

If the management socket closes while the /v1/remote/http WebSocket is handshaking, no close listener has been attached yet. After the HTTP connection opens, the client is marked connected and waitForSocketEnd(management) waits for a close event that already occurred; if the HTTP socket remains open, the reconnect loop never runs and the web client's required WebSocket streams cannot be opened. Start observing the management socket before this await, or recheck its ready state afterward.

Useful? React with 👍 / 👎.

Comment on lines +169 to +171
if (contentType.toLowerCase().includes('text/html')) {
const prefixLiteral = JSON.stringify(normalizedPrefix);
const injected = `<script>(function(){var p=${prefixLiteral};try{sessionStorage.setItem('kimi-desktop-server-origin',location.origin+p)}catch(e){}var w=function(f){return function(s,t,u){if(typeof u==='string'&&u.charAt(0)==='/'&&u.indexOf(p)!==0)u=p+u;return f.apply(this,[s,t,u])}};history.pushState=w(history.pushState);history.replaceState=w(history.replaceState)})();</script>`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Make prefix initialization compatible with non-loopback CSP

When Remote Control is combined with a non-loopback bind such as kimi web --remote-control --host, kap-server adds a CSP whose default-src 'self' disallows inline scripts, and the tunnel forwards that header unchanged. The injected bootstrap is therefore blocked, so kimi-desktop-server-origin is never set and the web client sends REST and WebSocket traffic to the relay origin root rather than the device prefix, leaving the remote UI unable to connect. Either reject this option combination or make the bootstrap and forwarded CSP compatible.

Useful? React with 👍 / 👎.

@sailist
sailist force-pushed the feat-000-08-06-rc branch 2 times, most recently from a8e5553 to 1cc0f86 Compare August 21, 2026 01:36
Add CLI and TUI entry points for exposing the local web UI remotely.
Bridge HTTP and WebSocket traffic with local authentication and reconnect handling.
Reconnect when management closes during the HTTP tunnel handshake.
Reject non-loopback Remote Control binds whose CSP blocks path bootstrap.
@sailist
sailist force-pushed the feat-000-08-06-rc branch from 1cc0f86 to 1c4824e Compare August 21, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants