Files
plugins/packages/kimi-desktop
kupakupa 646776060f kimi-desktop: Kimi desktop Work as an agent, through its local runtime (#169)
Adds agent-kimi-desktop 0.1.0 (kupakupar): Kimi desktop Work on magpie's
Agents page. It moves the runtime's daimon-kimi-code baseUrl to a
loopback bridge and back, through Kimi's local control API.

Re-reviewed at dd8ed2c against the last review at 6c584bb:
1. menu-hook.cjs and selection.mjs are removed; no injected code ships.
2. No full config backup is written. Only before-menu-models.json (the
   model list and current choice) is kept, and it is removed on a clean
   disconnect.
3. providers.json and settings.json are never opened. The catalog comes
   from the gateway's /v1/models with the agent's key and its registered
   UA "Desktop Kimi Work".
4. No signal handlers and no process.exit. Restore runs on the 'exit'
   event, which fires when magpie closes the host's stdin (host.js
   rl.on("close") -> process.exit(0)). The README gives manual recovery
   after a SIGKILL.
5. macOS record: COMPATIBILITY.md (macOS 26.6.2 arm64, Kimi 3.2.17
   build 3.2.17.4, magpie 0.1.1276, Bun 1.4.3). All four control methods
   succeeded, a streamed request returned 200, and a restore followed.
   The README says what happens when a private method fails.
6. Search and fetch pass Kimi's own request, with its own key, to Kimi's
   own origin, unchanged. This is the user's own account used by that
   user, the same rule as #171, so it is accepted.

Run at dd8ed2c, and merged onto origin/main 2ea25b9 together with #171:
- HOME=$(mktemp -d) bun test: 1660 pass, 0 fail (merged: 1668 pass, 0 fail).
- bun test packages/kimi-desktop: 12 pass.
- bun scripts/check.mjs: ok (it skips agent packages).
- git diff --check, npm pack --dry-run (8 files), node scripts/dist.mjs
  (packs agent-kimi-desktop@0.1.0).
- Broken by hand: re-adding a SIGTERM handler and a full config backup
  turns 3 tests red.
- No CI ran on the PR. No real Kimi or credential was used.
2026-10-17 04:33:01 +08:00
..

Kimi desktop Work agent

Use the ordinary Kimi desktop application's local Work agent with a model selected in Magpie. This is not Kimi Code CLI, a Kimi subscription provider, or a way to spend Kimi Work subscription credits in other agents.

magpie plugin add @magpie-community/agent-kimi-desktop

Open and sign in to Kimi desktop. On Magpie's Agents page select Kimi, pick a model, and connect. The adapter waits for the local Work runtime to be ready and idle, then applies the connection without restarting either application. Use Kimi's Work page. Chat and cloud Claw are outside its scope. The standard Kimi model menu continues to use the model selected in Magpie; this package does not modify Kimi's application resources or install a custom model-menu patch.

Disconnect Kimi in Magpie to restore its original model service address. Existing conversations, login credentials, unrelated settings, and native model entries are preserved.

How it works

The import-free kimi-desktop.agent.js registers the agent using Magpie's agent interface. The Bun entry index.mjs is also necessary: Kimi's actual configuration belongs to its running local runtime, so changing a file alone does not reliably apply a model. It runs a loopback adapter and uses Kimi's authenticated local control API to reload the selected model.

Inference goes to Magpie using Magpie's agent credential. Kimi's web search/fetch tools continue through Kimi's original agent-gw.kimi.com service with Kimi's own credential. Kimi login credentials are never forwarded to Magpie or a third-party model provider. Requests to unknown paths and requests without Kimi authentication are rejected; no system proxy, certificate or firewall settings are changed.

The adapter does not reload a busy Work runtime. If Kimi independently changes its service configuration while connected, adaptation pauses instead of repeatedly overwriting it; disconnect and reconnect in Magpie to retry.

Local files and compatibility

  • ~/.config/magpie-kimi/connection.json: Magpie's selected model and connection.
  • ~/.config/magpie-kimi/status.json: fixed status categories, without credentials.
  • ~/.config/magpie-kimi/adapter-state.json: original service address and connection ownership; no Kimi login credentials.
  • ~/.config/magpie-kimi/before-menu-models.json: one snapshot of the original model list/current choice, removed after a clean disconnect. No full configuration or credential backup is written.
  • Kimi configuration: kimi-desktop/daimon-share/daimon/config.json under the platform's application-support directory.

Verified with Windows 11, Kimi 3.2.17.10 and official Magpie 0.1.1275, including an actual Work request through Magpie. The macOS record verifies real control methods, connect/disconnect restoration and a real streamed bridge request on macOS 26.6.2 arm64, Kimi 3.2.17 build 3.2.17.4 and official Magpie 0.1.1276. That request was initiated by an HTTP test client; a macOS desktop UI-submitted Work turn remains unverified. The supported runtime has provider daimon-kimi-code with original service https://agent-gw.kimi.com/coding/v1; other layouts stop with unsupported_kimi_config.

The private control API is undocumented. Before connecting, the adapter probes models.current; a refused/missing method stops connection without changing the service address. A failed conversations.setModel rolls back that address. Failures of conversations.getKimiModelList or conversations.updateKimiModelList report catalog_sync_failed and preserve the existing catalog rather than inventing a different protocol. In that case the selected-model bridge may remain connected; disconnect it to return to Kimi's service. No vendor app files are patched, and no automatic upgrade to an unknown protocol is attempted.

No Kimi binaries, personal configuration, prompts, account identifiers or credentials are included. There are no runtime dependencies. Tests use isolated temporary directories and synthetic credentials.

bun test packages/kimi-desktop/kimi-desktop.test.mjs

The model catalog is fetched from Magpie's /v1/models with this agent's credential and registered User-Agent. Magpie owns its visibility, picked/hidden models, disables and ordering. The adapter never opens Magpie's providers.json or settings.json. It rechecks the gateway catalog before every inference; removed selections are refused even during a running turn, and an unavailable catalog returns a fixed error instead of falling back to an unrestricted list. This package includes no Electron injection hook or model-menu patch. The icon is Kimi's desktop application icon.

Shutdown and manual recovery

The shared plugin host owns process shutdown. This plugin installs no SIGTERM/SIGINT handler and never calls process.exit. On the host's normal exit event it synchronously restores the original address if the current address is still its own; restart Kimi to reload its runtime. An explicit disconnect while both apps are running additionally restores model selection/list through the control API.

A forced kill, power loss or a broken private API can leave Kimi pointing at an inactive loopback bridge. To recover without starting Magpie:

  1. Close Kimi normally. In ~/.config/magpie-kimi/connection.json, set enabled to false so the adapter does not reconnect when Magpie next starts.
  2. Open Kimi's config.json at the application-support path above. Only if model.providers["daimon-kimi-code"].baseUrl equals bridgeURL in adapter-state.json, change that one field to the same state's originalBase (normally https://agent-gw.kimi.com/coding/v1). Leave credentials and all unrelated fields untouched; do not replace the whole document from an old backup.
  3. If model.current starts with magpie-local-, set it to current from before-menu-models.json if that alias still exists in model.models; otherwise choose an existing native daimon-kimi-code alias, such as k3-agent or k2d8-preview. Remove only model.models keys beginning with magpie-local- if present. Reopen Kimi; it refreshes its native model catalog.

Older experimental packages created full backups/before-connect-*.json copies, which can contain Kimi credentials. This package creates no such files and does not silently delete existing user backups. After recovery, users can remove those older copies locally. Do not upload them in an issue or PR.