feat(kimi-code): add remote control web tunnel - #3034
Conversation
🦋 Changeset detectedLatest commit: b8ef5de The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
There was a problem hiding this comment.
💡 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".
| const http = await this.connectRelay( | ||
| `/v1/remote/http?device_id=${encodeURIComponent(this.deviceId)}`, | ||
| ); |
There was a problem hiding this comment.
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 👍 / 👎.
| 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>`; |
There was a problem hiding this comment.
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 👍 / 👎.
a8e5553 to
1cc0f86
Compare
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.
1cc0f86 to
1c4824e
Compare
# Conflicts: # apps/kimi-code/src/tui/commands/types.ts # apps/kimi-code/test/tui/commands/registry.test.ts
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 webis 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
kimi web --remote-controlwith--rcas an alias, plus/remote-controland/rcin the TUI.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.tspnpm --filter @moonshot-ai/kimi-code run typecheckpnpm --filter @moonshot-ai/kimi-code run buildpnpm --filter @moonshot-ai/kimi-code run build:native:jsoxlinton the changed TypeScript filesChecklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.