Commit Graph
15 Commits
Author SHA1 Message Date
yishu 00642d4c6b kimi-work 0.1.17: Work's fast output speed, as K3.1 Pro Fast and a Fast switch (#728)
Kimi Work's "High" output speed is a speedOption of a model in the signed-in Work menu. A model whose option has `speedValue: "fast"` and `available: true` gets a `-fast` row ("K3.1 Pro Fast") and magpie's Fast switch (`service_tier: priority`). A request on either goes out with `X-Kimi-Model-Speed: fast`, the header Kimi's own desktop client sends. The menu is now read with the membership sign-in magpie renews, and the unsigned menu never offers fast. A `-fast` suffix comes off only ids the plugin listed itself.

Header checked against the vendor's client. Kimi 3.2.24 macOS was downloaded from kimi.com's own download link, a Developer ID build from Beijing Moonshot Technology (2J9472RW75); dmg sha256 e40df5954aacdfe69f5e56f9d679ef86a7d25f9134769ffe1b7ea382c77ca8fd. In its app.asar:
- `out/renderer/assets/common-DLYgMFK1.js` builds request headers with `x&&(a[uy]=x),t&&(a[fy]=t)`, where `uy="X-Kimi-Context-Length"` and `fy=c(2634)`.
- Decoded with a decoder of our own (the string table is read as data and rotated to the bundle's checksum; no vendor function was run): `c(2634)="X-Kimi-Model-Speed"`.
- The value comes from `DM`: the chosen speedOption's `speedValue` (`c(1967)`), from options the account can select (`"select"`).
- `kimi-agent-Dw2t9ioO.js` passes it as `modelSpeedHeaderValue` into `llmRequestHeaders`, and the daimon bundle carries `llmRequestHeaders` into the turn.
- No wire capture: not taken by the author or by the review.

Run at 69adea99 on a macOS box:
- `bun test packages/kimi-work`: 103 pass, 0 fail.
- `bun scripts/check.mjs kimi-work`: ok.

Broken by hand, each red:
- header value "fast" changed to "high": 1 fail;
- `available===true` dropped: 4 fail;
- header name changed: 1 fail.
The six breaks from the earlier round, at 45dd499 (code unchanged since, comments only), were each red too.

Not tried: a real request from this review's side (no Kimi Work account here), a lower-tier account's menu, and what a fast request costs.
2026-11-05 01:42:35 +08:00
yetone 17e5ef7457 all: load on OpenCode 2.x through a default {id, setup} (#657)
nbczw8750 (#657): trae 0.2.26 on OpenCode 2.2.5 fails with "Plugin
must export a default definition with an id and an effect or setup
function. (cause: SchemaError(Missing key at ["default"]))". 2.x
imports a package's exports["."] (a plugin dir and an npm install
alike) and has no V1 path at all, so every package here that serves
models failed the same way, not only trae.

Every one of the 32 model packages now has:
- opencode2.mjs, exports["."]: a copy of scripts/opencode2.mjs, an
  adapter that runs the package's V1 plugins inside 2.x's promise
  API. Config providers become 2.x providers (package pinned so the
  aisdk sdk hook runs), V1 auth methods become integration methods
  (oauth auto/code with forms; api without authorize as a key method),
  V1 credentials are kept in metadata.v1, the loader's baseURL,
  apiKey, headers and fetch are applied through the sdk hook, an
  auth.set renewal is stored per credential, and credential.switched
  /updated reload the account's own model list.
- opencode.mjs, main: re-exports the V1 plugin functions only.
  OpenCode 1.x and magpie's host.js take main. On 1.x, trae 0.2.26's
  main exported a non-plugin (_internal) and 1.19.5 refused it ("Plugin
  export is not a function"); the new main fixes that too.
- both files in "files"; patch version bumped. devin already had 2.x
  and is unchanged.

scripts/check.mjs fails a model package whose 2.x entry has no default
{id, setup}, whose opencode2.mjs differs from the canonical one, whose
entry is missing from files, or whose main exports a non-plugin.

Run at this head (mote):
- HOME=$(mktemp -d) bun test, as CI runs it: 4900 pass, 0 fail
  (4914 tests, 374 files). A first run set globalThis.fetch for the
  whole process from opencode2.test and failed 528 tests in other
  packages; the block is now set and put back around that file's tests.
- bun scripts/check.mjs: every package passes. With the network
  blocked cloudflare-workers-ai fails on its fetched catalog, the same
  on origin/main.
- Real OpenCode 2.2.5 (npm opencode-ai), sandbox HOME, packed trae
  0.2.27: loads with no error; /api/integration lists trae-cn "Trae CN"
  and trae-global "Trae Global" with their browser sign-ins; `auth
  login` starts the trae.cn authorization and waits (cancelled there);
  with a fake credential POSTed to /api/credential, `opencode models`
  lists trae-cn's six models.
- Real 2.2.5 with a fake V1 key plugin through the same adapter
  against a local fake server: `auth login` with a key, `models`,
  `opencode run` reached /real/v1/chat/completions with the loader's
  "Bearer loader-sk-fake" and header, and printed the fake's reply;
  with @ai-sdk/anthropic it reached /real/v1/messages with x-api-key
  from the loader. This run found the key method missing after 2.x's
  second integration transform (a once-only flag outside the
  transform); fixed, and opencode2.test checks a rebuild.
- Real OpenCode 1.19.5, sandbox HOME, trae 0.2.27: `opencode models`
  lists trae-cn and trae-global models; 0.2.26 failed there.

Broken by hand (scratch copy, bun test scripts/ and check.mjs):
- trae's exports back to "./index.mjs": the trae 2.x test fails
  (default.id undefined), check fails trae with "OpenCode 2.x:
  ./index.mjs has no default {id, setup} (plugins#657)".
- zed's opencode2.mjs changed: the copies test fails, check fails zed
  "differs from scripts/opencode2.mjs".
- the key flag back outside the transform: the 1.x plugin test fails
  on the rebuilt sign-ins (key missing).

Not tried: a real sign-in with a real account on 2.x; Windows (the
reporter's OS); chat.headers, chat.params, usage and tool hooks, which
the adapter doesn't carry to 2.x; the tools/pages packages (calc,
goanyapi, layerfs, search1api, aelios, agent-console, chat,
fingerprint, nowledge-mem, kimi-desktop), which still load only on 1.x.
2026-11-03 13:54:26 +08:00
Changtian Li 280d522830 kimi-work 0.1.15: renew membership tokens and keep existing accounts (#218)
Explicit sign-in now imports Kimi desktop's membership access/refresh pair
when the desktop has one, and magpie renews it through the host's
auth.refresh (conditional commit under the auth-store lock). Accounts saved
through 0.1.14 (reference-only, no pair) keep reading the desktop's web
token for usage, with no reconnect, no import and no refresh spent. The
usage card is one monthly meter, with Code's share as text. Request-body
reads follow the caller's abort signal.

Kept from main (0.1.11 to 0.1.14): callback errors split into no session /
Work 401 / HTTP-timeout-network (#425), per-uid account ids
`Kimi Work · <uid6>` (#440), share-folder-missing as kept (#444),
spent-quota 403 -> 429 (#465).

Reviewed head 96f7f52501082e4747ef649d836d955a8ece3f4c, merged onto
origin/main fdc5002 locally (clean), run on mote (macOS, Bun 1.4.2) with
HOME=$(mktemp -d):
- bun test packages/kimi-work: 99 pass, 0 fail
- bun test (whole repo): 3681 pass, 8 skip, 0 fail
- bun scripts/check.mjs: all packages pass

Broken by hand, each red in packages/kimi-work:
- legacy (no pair) usage throws expired: 7 fail
- callback 401 folded into the generic error: 3 fail
- callback network error folded into "no session": 3 fail
- accountId back to 'Kimi Work (local)': 2 fail
- AuthService 401 marked signIn expired: 2 fail
- refresh hook returning a pair for a legacy account: 2 fail

Version 0.1.15: main has 0.1.14; npm has no kimi-work package (served
from dist, highest 0.1.14), so 0.1.15 is free.

Not tried: a live Kimi sign-in or renewal at this head. The author's
live coexistence evidence is one cycle on 2026-10-24 at f67d742
(COMPATIBILITY.md). The rewritten COMPATIBILITY.md replaces main's 0.1.4
macOS record; that record stays in git history at fdc5002.
2026-10-30 01:34:05 +08:00
yetone 08e3ba8990 kimi-work 0.1.14: a spent allowance's 403 goes out as a 429 (#465)
Kimi answers an account whose allowance is used up with a 403 ("You've
reached your usage limit for this billing cycle", resource_exhausted
"insufficient balance"). The plugin passed it through, magpie read a
403 as a key fault, never rested the account, and kept routing to it
while another account with quota sat idle (kongbai01203: 6+ requests in
20 minutes to the spent one after the other answered 200).

A 403 whose body says resource_exhausted, usage limit, billing cycle,
insufficient balance or quota now goes to magpie as a 429 with Kimi's
body and headers (content-encoding/length dropped, the text is
decoded), the pattern Devin's, Qoder's, Kiro's and Cline's plugins use
for a spent quota. magpie's quotaStatus counts 429 as spent and moves
on. Any other 403 stays a 403 with its body.

Run (on mote, HOME=$(mktemp -d) bun test in packages/kimi-work): 69
pass, 0 fail. bun scripts/check.mjs: exit 0.
Broken by hand: status:spent?429:403 changed to status:403; the three
new spent-allowance tests went red (66 pass, 3 fail), green again with
the fix back.
Not tried: a real spent Kimi Work account. The issue gives Kimi's words
but not the JSON around them, so the fixtures try them in an
OpenAI-style error, a Connect body and a nested Connect error. Not
checked end to end that magpie then rests the account until the cycle
resets (Kimi sends no reset time; magpie's own rest length applies).
2026-10-28 21:02:21 +08:00
yetone eb54fad5b3 kimi-work 0.1.13: a gone share folder is named, and several Kimi users are served (#444, #440)
#444 (kongbai01203): when the folder daimon-storage.json points to was
moved or deleted, 0.1.12 threw its "sign in again" error with
signIn "expired", so magpie showed "登录已失效" and marked the account,
and signing in again in a running Kimi didn't help. Kimi 3.2.21 makes
<shareDir>/daimon only when it provisions at start, and never falls back
to the default folder while a pointer stands (read from its main
process), so the plugin doesn't fall back either. A missing share folder
is now its own error, kimi_work_share_missing, with signIn "kept": it
names the folder and says to put it back (no new sign-in) or to quit and
reopen Kimi, then sign in to Work. The sign-in callback shows the same
text. A share folder that exists but has no config.json is still the
old missing-sign-in error. The plugin's fetch already fails before any
network call; the ~30s 502 the reporter saw is outside the plugin and
was not looked into here.

#440 (kongbai01203): magpie already keeps a second Kimi user beside the
first (settle tells them apart by uid), but the plugin served only the
user Kimi is signed in to, so the first account failed once Kimi
switched. Kimi 3.2.21 keeps one minted Work key per user in
<daimon>/kimi-code-key.json ({"v":2,"keys":[{userId,apiKey,keyId?}]},
the current user first), keeps an entry when it switches users, reuses
it when it switches back, and drops one only on a 401 (DaimonProvision's
#readKeyStore/#upsertKeyStoreEntry/#resolvePersistedKimiCodeApiKey). An
account Kimi has switched away from now uses its key from that file,
read as Kimi reads it (v 2 only, first entry per user). Its allowance
can't be read (Kimi keeps only the current user's web sign-in), so its
usage card says to switch to it, signIn "kept". No key, or a key the
gateway refuses, is kimi_work_account_not_here, marked signed out. Each
account is named "Kimi Work · <first 6 of its hashed uid>" instead of
the shared "Kimi Work (local)". Not done: rotating between accounts or
falling back on quota, which is magpie's routing, not the plugin's.

Run: bun test in packages/kimi-work (65 pass) and the whole repo with
HOME and TMPDIR in a sandbox under magpie-wt (2879 pass, 3 skip, 3 fail:
cursor upstream-words, commandcode no-magpie and layerfs no-magpie,
which fail because the sandbox path itself contains "magpie"; none of
those packages is touched). bun scripts/check.mjs ok.
Broken by hand: index.mjs at origin/main fails the new share-folder,
reporter's D:\KimiData\daimon-share and two-users tests. In the new
code, dropping the share check reds the two #444 tests; ignoring the
key store reds both #440 tests; taking the last entry per user reds the
key-store test; reading usage for an away account reds the two-users
test.
Not tried: a real Kimi with two users (no Kimi install or Kimi account
on this machine); that a minted key still works server-side after Kimi
switches users is read from Kimi's code (it reuses it after a probe),
not seen. Not tried on Windows.
2026-10-27 23:57:54 +08:00
yetone a9779ef864 kimi-work 0.1.12, kimi-desktop 0.1.4: Kimi's sign-in is read where daimon-storage.json points (#425)
Kimi 3.2.21 on Windows, installed on another drive than %APPDATA%'s,
keeps daimon-share at <install drive>\KimiData\daimon-share and writes
%APPDATA%\kimi-desktop\daimon-storage.json ({"version":1,"shareDir":...})
to point there. It writes the same pointer on any system when the user
moves its storage. Both packages read only
%APPDATA%\kimi-desktop\daimon-share, so the sign-in was "not found".

Read from Kimi's own code: Kimi-Setup-3.2.21.exe's app.asar,
out/main/index.js (string table decoded): the shareDir getter is
readPointer(userData) ?? join(userData, "daimon-share"); the pointer
reader takes an absolute shareDir and otherwise the default; the
"install-drive seed" writes the pointer on win32 when installRoot's drive
differs from userData's; driveDataDirName is "KimiData".

Both packages now follow the pointer the same way (unreadable, non-JSON
or non-absolute -> default, as Kimi does). kimi-work's sign-in failure
names the file it looked for, and a failed Work check (network, HTTP)
no longer says no sign-in was found.

Run at this tree (base fc2866f):
- Windows 11 box: installed Kimi 3.2.21 silently to D:\Kimi425, launched
  it once (no sign-in): it wrote daimon-storage.json with shareDir
  D:\KimiData\daimon-share and no daimon-share under %APPDATA%. Under
  bun 1.4.2 there the new desktopFile() is
  D:\KimiData\daimon-share\daimon\config.json; 0.1.11's path does not
  exist. Kimi uninstalled and its folders removed afterwards.
- New tests force win32, darwin and linux paths (tests/desktop-path.test.mjs,
  kimi-desktop/kimi-dir.test.mjs). Broken by hand (pointer ignored):
  3 of 6 kimi-work tests red.
- TMPDIR/HOME sandbox `bun test`: 2791 pass, 3 skip, 0 fail;
  `bun scripts/check.mjs`: ok.

Not tried: a signed-in Kimi on the other drive (no credentials were
entered), so a real Work request from D:\KimiData is untested. The
kimi-desktop adapter reads the folder once when it starts; storage moved
while it runs is seen on the next start.
2026-10-27 15:14:11 +08:00
yetone 1fbe22b3ad kimi-work 0.1.11: a usage read that fails says why on the card and keeps the Work sign-in
泠夜Soul (Discord), latest magpie and kimi-work 0.1.10: the Kimi Work
usage card says only "暂时无法获取额度", with no error anywhere.

Cause: auth.usage threw on every failure. magpie puts a plugin's reason
on the card only when usage returns it as `error` (quotaOfPlugin sets
PluginError; app.js quotaError then says "暂时无法获取额度:<why>"). A
thrown error reaches the card as the bare text, with the reason in a
tooltip. The read uses Kimi's web sign-in (credentials.kimiWeb.accessToken),
not the Work token chat uses. Kimi desktop 3.2.20 rewrites that token in
daimon config.json only while it runs (its token-change sync). Once the
desktop is closed, www.kimi.com answers it 401 "Session expired"
(REASON_INVALID_AUTH_TOKEN), the same stale token 0.1.10 found on the
menu. That 401 was thrown as expired() with signIn "expired", so magpie
also marked the Work account signed out while chat still worked. The
header changes in 0.1.8-0.1.10 aren't the cause: signed out or with a
bad token, GetSubscriptionStats answers the same 401 with or without the
x-msh headers. Their effect with a valid token wasn't seen.

What changed:
- usage never throws on a failed read. It returns
  {windows: [], error, signIn: "kept"}. A 401 says
  "Kimi 网页登录已过期,打开一次 Kimi 桌面版即可刷新额度(对话不受影响)",
  in words that magpie's signInGone doesn't take for a lapsed sign-in.
  Other statuses keep their HTTP code. Each failure is logged without the
  token.
- subscriptionBalance is read in camelCase or snake_case. A balance
  whose amountUsedRatio Connect JSON left out (zero) reads 0% used.
  Before, that gave no window at all. A reply with no balance says so.
  Field names are from the desktop's membership.v2 descriptor:
  subscription_balance is optional in GetSubscriptionStatsResponse.

Run at this tree (origin/main 743e8af + this change), macOS, bun:
- bun test packages/kimi-work: 53 pass, 0 fail. With index.mjs put back
  to 743e8af's: 50 pass, 3 fail, the three usage tests: 403 refused,
  stale web sign-in (fixture: www.kimi.com's literal 401 body, curl
  10-25), and zero-omitted / snake_case / missing balance.
- Live: createPlugin's auth.usage against the real www.kimi.com with a
  stale-shaped web token. New code returns the error above with
  signIn "kept". 743e8af's throws "请先在本机 Kimi 桌面版登录 Work…" with
  signIn "expired".
- HOME=$(mktemp -d) bun test: 2628 pass, 0 fail.
- bun scripts/check.mjs: every plugin ok. git diff --check clean.

Not tried: a signed-in Kimi Work account (none on this machine), so the
reporter's actual failure isn't seen. This release puts it on their card
and in the log. If it's the stale web token, opening Kimi desktop
refreshes it.
2026-10-25 17:13:43 +08:00
yetone 8d687ad519 kimi-work 0.1.10: a menu the web sign-in can't get is asked again without it, so K3.1 Pro stays listed
泠夜Soul (Discord) is on 0.1.9 and still has no K3.1 Pro (k3d1-agent),
with no error and nothing in the log. 0.1.9 was checked only against
the menu signed out.

What was found: provider.models asks the menu (DescribeKimiWorkConfig,
with credentials.kimiWeb.accessToken from Kimi's file) and agent-gw's
/models together, and a failed menu ask was dropped without a word:
the list was then /models' alone, k3-agent and k2d8-preview, which is
exactly the report, on 0.1.7 to 0.1.9 alike. www.kimi.com answers a web
sign-in it doesn't take with 401 "unauthenticated", "invalid user
token" (REASON_INVALID_AUTH_TOKEN), seen on 10-24 with a malformed and
a badly signed token; signed out it answers 200 with the desktop menu.
So a stale kimiWeb token in Kimi's file (the desktop closed, or it
renewed it elsewhere) takes K3.1 Pro away silently. That this is the
reporter's case is not proven: no signed-in account here.

What changed:
- The menu, when the signed-in ask fails (any HTTP status, a timeout,
  or a reply with no models), is asked again without Authorization, as
  the desktop asks it before signing in, with the same x-msh-* headers.
  That reply is the desktop menu, K3.1 Pro first. agent-gw requests and
  usage are unchanged; nothing is retried there.
- Each failure is written to the log (console.warn, so magpie's plugin
  stderr): which ask, and its status or reason, never the token.
- jsonRequest's errors carry the HTTP status, and leaves Authorization
  out when given no token.
- no-magpie.test's fake menu is now the captured desktop menu: an
  empty one is asked twice now, which its request count would miss.

Run at this tree (origin/main df55294 + this change), macOS, bun 1.4.2,
load ~360:
- bun test packages/kimi-work: 51 pass, 0 fail. With index.mjs put back
  to df55294's: 50 pass, 1 fail, the new test (401 / 503 / empty menu
  signed in, desktop menu signed out: expects k3d1-agent "K3.1 Pro" and
  a logged line without the token).
- Live, createPlugin's provider.models with a stale-looking web token
  and a bogus Work token, against the real www.kimi.com and agent-gw,
  darwin and win32: lists k3d1-agent=K3.1 Pro, k2d8-preview, k3-agent
  and logs "DescribeKimiWorkConfig with the web sign-in failed (HTTP
  401); asking it without one". df55294's index.mjs, same script:
  throws the sign-in error (both lists failed, nothing listed).
- HOME=$(mktemp -d) bun test: 2447 pass, 1 fail, layerfs's afterAll
  timing out (#362, layerfs untouched). (A first run with HOME and
  TMPDIR under a path containing "magpie" failed four no-magpie tests
  on that path alone.)
- bun scripts/check.mjs: every plugin ok. git diff --check clean.

Magpie side, read at origin/main 137187a40: a plugin update goes
through Restart, which retires the host and calls changed(), so
forgetProviders drops the cached list and a new host lists again;
keepListed keeps an old list only for a provider that fell back, which
this one never reports. No stale-cache cause there.

Not tried: a signed-in Work account, so whether the reporter's menu
ask fails (401 or otherwise) or succeeds with a menu lacking
k3d1-agent is not known. This release logs which. Not changed: the
desktop interceptor (www.kimi.com's own web bundle, the isDesktop
branch) also sends X-Traffic-Id, x-msh-device-id, x-msh-session-id and
X-Language, and the User-Agent is still Kimi Code's (#363).
2026-10-24 20:09:47 +08:00
yetone df552949e1 kimi-work 0.1.9: the menu is asked with the desktop's headers, so K3.1 Pro (k3d1-agent) is listed
泠夜Soul (Discord) has a Kimi Work membership whose desktop picks
K3.1 Pro, model id k3d1-agent, and magpie's Kimi Work list leaves it
out, on 0.1.7/0.1.8 too, which read DescribeKimiWorkConfig for this.

Cause, seen on the live endpoint (it answers without a sign-in):
DescribeKimiWorkConfig chooses the menu by the caller's x-msh-* headers.
Asked with none, as the plugin asked it (only User-Agent kimi-code-cli),
it answers with the web menu: k3-agent, k3-agent-swarm, k2d8-preview.
Asked as the desktop asks it (x-msh-platform mac or windows, as Kimi's
Connect interceptor sends from the desktop, with x-msh-version), it
answers k3d1-agent "K3.1 Pro", k2d8-preview, k3-agent. Five tries each,
stable. So the menu code was right and its reply was the web's.

What changed:
- www.kimi.com/apiv2 calls (the menu and GetSubscriptionStats, as the
  desktop's interceptor puts them on every apiv2 call) carry
  x-msh-platform (mac on macOS, windows on Windows, web elsewhere, as the
  desktop's own rule), x-msh-version 3.2.20 (the desktop build 0.1.8's
  headers came from) and R-Timezone. agent-gw's headers are unchanged.
- A menu row's reply limit is its requestParams.maxTokens (32768 for
  every model listed today, the value that was hard-coded).
- tests/fixtures/work-config.mac.json and work-config.web.json are the
  two literal replies, captured signed out on 10-24. The new tests have a
  fake that answers as the server does (desktop menu only for mac or
  windows) and check that k3d1-agent is listed as "K3.1 Pro" with
  low/high/max, 262144 context and 32768 output, on darwin and win32.

Run at this tree (origin/main 79e383c + this change), macOS, bun 1.4.2:
- bun test packages/kimi-work: 50 pass, 0 fail. With webHeaders(platform)
  put back to {'User-Agent':UA} by hand: 49 pass, 1 fail (the new menu
  test), so it fails without the fix.
- Live: createPlugin's own provider.models against the real
  DescribeKimiWorkConfig (Authorization taken out, no account here):
  darwin, win32 and linux list k3d1-agent, k2d8-preview, k3-agent. The
  same script on origin/main's index.mjs lists k3-agent, k3-agent-swarm,
  k2d8-preview on all three.
- HOME=$(mktemp -d) bun test: 2446 pass, 1 fail; the fail is layerfs's
  afterAll cleanup timing out at 5s at load ~500 (2 of 3 red alone,
  layerfs untouched), filed as #362.
- bun scripts/check.mjs: every plugin ok. git diff --check clean.

Not tried: a signed-in Work account (none on this machine), so neither
the signed-in menu nor a chat request with k3d1-agent through agent-gw
has been seen; the signed-out menu already lists k3d1-agent, so whether
a tier without it is refused is up to agent-gw. Not changed: the
User-Agent on www.kimi.com is still Kimi Code's, not the desktop
renderer's, which hasn't been captured (#363).
2026-10-24 19:14:00 +08:00
yetone 8310fd2e77 kimi-work 0.1.8: Kimi gets the headers its own Work client sends, not "Magpie Kimi Work provider" (#353)
Every request to agent-gw and kimi.com carried the User-Agent "Magpie Kimi
Work provider/<version>". Kimi 3.2.20's daimon 0.6.10 (the desktop
component that holds the Work credential in daimon-share/daimon/config.json)
builds its agent-gw headers in createDaimonKimiCodeRequestHeaders:
User-Agent kimi-code-cli/<Kimi Code version> (0.36.0, from its
kimi-code.vendor.json; no caller passes a suffix), X-Msh-Device-Id,
X-Msh-Device-Model, X-Msh-Device-Name, X-Msh-Os-Version, X-Msh-Platform
"kimi-code-cli", X-Msh-Version and X-Msh-Daimon-Version 0.6.10. The plugin
sends the same on /models and /chat/completions.

The device id is the daimon's own: a randomUUID it writes once to
<daimon>/runtime/kimi-code/home/device_id. The plugin reads that file and
never writes it (it never writes the desktop app's files); when it is
missing the header is left out. The www.kimi.com reads (membership, and
0.1.7's DescribeKimiWorkConfig menu) get the kimi-code-cli User-Agent
only: those calls are made by Kimi's web page, whose own headers weren't
read.

The test also found magpie's x-magpie-* hint headers going through to
agent-gw on chat requests; they are now dropped.

Run:
- no-magpie.test.mjs: models, the Work menu, chat (with a magpie User-Agent and an
  x-magpie-work-dir coming in) and membership hold no "magpie"; agent-gw
  gets the daimon's headers; the device id is read and never written.
  Both tests red on 0a9415f (0.1.7).
- bun test (package, rebased on 0a9415f): 48 pass. bun scripts/check.mjs kimi-work: ok.
Not tried live: no Kimi Work account here, and Kimi isn't installed on
this Mac or the Windows box.
2026-10-24 17:30:44 +08:00
yetone 0a9415f4ef kimi-work 0.1.7: models come from Work's own menu (DescribeKimiWorkConfig) as well as /models, so K3.1 Pro on the 99 plan is listed
泠夜Soul (Discord #help, 10-24) is on Kimi's 99 membership and the official
Kimi Work desktop has "Kimi K3.1 Pro" picked in its composer, but magpie's
Kimi Work list (0.1.6) leaves it out.

Cause, read from Kimi desktop 3.2.20's main bundle (decoded): the desktop
does not build its Work model menu from agent-gw's /models. It calls the
Connect RPC kimi.gateway.config.v1.ConfigService/DescribeKimiWorkConfig on
https://www.kimi.com/apiv2 with the web sign-in, takes models plus
moreModels, and hands each entry's requestParams.modelId to its agent
(conversations.updateKimiModelList), which sends it to agent-gw as the
model. The plugin listed /models only, so a tier model the menu has and
/models doesn't was never offered. That /models leaves K3.1 Pro out is
inferred from the report (0.1.6 already lists /models in full), not seen
on an account.

What changed:
- provider.models asks both lists at once. Menu entries come first, under
  display.displayName, with id requestParams.modelId; reasoning levels are
  requestParams.reasoningEffortOptions, else daimonModelConfig's
  supportEfforts ("off" is REASONING_EFFORT_NONE there, sent as none);
  image input from its "image_in" capability. Context is capped at the
  standard 262,144 as before: XL is an X-Kimi-Context-Length header the
  desktop sends only when the user picks extended, and this doesn't send it.
- An id both list keeps /models' row under the menu's name. Either list
  failing leaves the other; both failing, or the menu empty with /models
  failing, throws, so magpie keeps the last good list.
- The reply is read in camelCase and in the proto's snake_case names.

The fixture (tests/fixtures/work-config.shape.json) is the reply's shape
from the proto descriptor and the desktop's mapping code. No reply was
captured from an account; k3d1-pro in it is a placeholder id, and the
fixture says so.

Run: bun test packages/kimi-work (46 pass, 0 fail); with the menu call
turned off by hand in index.mjs the two new list tests go red (44 pass,
2 fail); bun scripts/check.mjs kimi-work ok; git diff --check clean.
Not tried: a real Work account (none on this machine or the Windows box),
so neither the menu's reply nor a chat request with K3.1 Pro's id through
agent-gw has been seen. The model-speed header (X-Kimi-Model-Speed) is not
sent either.
2026-10-24 17:28:52 +08:00
yetone 663ce131cb kimi-work 0.1.6: one model's unreadable effort list no longer drops the whole catalog; K2.8 Preview in the fallback
泠夜Soul (Discord #help, 10-24) sees only "K3 · Work" in magpie, while the
Kimi app lists K3.1 Pro and K2.8 Preview for the same membership. "K3 · Work"
is the name of this plugin's static fallback; the live /models catalog names
k3-agent "K3". So the account's live list was not used: the models hook
threw or fell back, and magpie kept the config's one model.

The plugin already lists models from agent-gw's /models, so a model Kimi
adds to the account shows under its own id with no hard-coded list. What
changed:

- modelRows no longer throws the whole catalog away when one model's
  reasoningEffortOptions isn't an array, or an option has no string
  effort or one that isn't a plain word: that model keeps the levels that
  can be read (only levels Kimi lists, none guessed). A non-object entry
  is skipped like an id that can't be used. K3.1 Pro went live on
  2026-10-23, the day before the report, so a new entry in a shape not
  seen before is one way the catalog could have failed. It is not the
  confirmed cause: the user's provider.models error line has not been
  seen.
- The fallback (shown before the list is read, and kept when it can't be)
  offers k2d8-preview beside k3-agent. Both ids come from Work's own
  /models: tests/fixtures/work-models.redacted.json and the 10-17 macOS
  record in COMPATIBILITY.md, and #350 ran real Work requests on both.

Not added: a K3.1 Pro id. Kimi Code's docs name it k3.1-pro, but that is
api.kimi.com/coding's catalog (where K2.8 Preview is kimi-for-coding and
K3 is k3, not k3-agent), not the Work gateway's. Work's id for K3.1 Pro is
not in any vendor source found, so none is invented; the live catalog
will show it once read.

Run: bun test packages/kimi-work (43 pass, 0 fail); the two new tests
fail on origin/main's index.mjs (41 pass, 2 fail) and pass with this one;
bun scripts/check.mjs kimi-work ok; git diff --check clean.
Not tried: a real Work account (none on this machine), so the live
catalog with K3.1 Pro has not been seen.
2026-10-24 15:11:15 +08:00
yetone d324a96e1a kimi-work 0.1.5: tool schemas Kimi's moonshot check refuses go in a shape it takes (#287)
chai-j: every Codex message on Kimi Work failed, 400 "tools.function.
parameters is not a valid moonshot flavored json schema, details: <At
path '$defs.__schema20': when using $ref, type should be defined in the
referenced schema instead of the parent schema>". The plugin passed the
body through as sent. Codex's MCP and app tools are zod's toJSONSchema
with reused schemas as $defs, and zod 4 writes a schema derived from a
reused one as a $ref beside what it changed: z.number().min(0) reused,
then .int() and reused itself, is $defs.__schema1 =
{"type":"integer","maximum":…,"$ref":"#/$defs/__schema0"}. Reproduced
with zod 4.6.7; the fixture is its output.

magpie's own Kimi rewrites (kimiToolEnumTypes, kimiToolRefTypes) are
scoped to api.kimi.com/moonshot hosts and presets, so a plugin's
agent-gw.kimi.com requests never got them. moonshotTools does the class
in the plugin, on tools[].function.parameters only:
- $ref beside a type: a target with no $ref of its own is written in its
  place with the parent's keywords over it (what zod's derived schema
  means: .int() of min(0) is {type:integer,minimum:0,maximum}); otherwise
  the parent's type is left out.
- type beside anyOf is left out (Kimi: "type should be defined in anyOf
  items instead of the parent schema", measured in magpie 129d8b08a).
- enum/const with no type gets its values' type, [T,"null"] with a null
  (magpie #886).
- an untyped $ref target gets the type its keywords or branches say
  (magpie 129d8b08a). Unlike magpie's kimiToolRefTypes, a target that is
  itself a $ref with keywords beside it (Codex App's
  {"format":"uuid","$ref":…}) is left alone, so no type is put beside a
  $ref.
A body with none of these goes byte for byte; a rewrite is deterministic,
so a cached prefix stays one. A Request or byte body is read as text.

Tests: tests/schema.test.mjs, with the zod fixture and Codex App's
automation_update parameters (magpie testdata) checked against the
refusal rules; 4 of its 7 tests fail on 0.1.4's index.mjs (the other
three guard the fixtures and pass-through). Package: 25 pass. Whole repo
the way CI runs it, HOME=$(mktemp -d) bun test at this head: 2056 pass,
0 fail. bun scripts/check.mjs kimi-work: ok.

Not tried: a real Kimi Work account (none here), so the rewritten tools
were never sent to agent-gw.kimi.com's validator, and the reporter's
literal __schema20 wasn't captured; the shape comes from zod's output
and the error text.
2026-10-22 01:54:22 +08:00
kupakupa 6017ebc383 kimi-work 0.1.4: pass 429/5xx through unchanged, 401 marks the sign-in expired (#190)
Kimi Work 0.1.4: a 401 marks the sign-in expired. A 429 or 5xx passes through unchanged (status, headers including Retry-After, and body), so magpie classes rate vs quota from Kimi's own words. A network error keeps its cause code or message.

Reviewed head de33725f5a4cca882852ea69d0d828d5e1f4e605. Every changed line was read. What was run:
- `bun test packages/kimi-work`: 17 pass, 0 fail.
- `bun scripts/check.mjs kimi-work`: ok.
- Run in magpie's plugin host (main 7660399a1, a throwaway internal/gateway test with a sandbox HOME). The plugin was a copy with its BASE, MEMBER and desktop-file path pointed at an httptest fake, and the sign-in went through `plugin.Authorize` then `plugin.Finish` on a synthetic config.json.
  - The stream returned 200.
  - A 429 "Too many requests" returned 429 with Retry-After 7 and type rate_limit_error. A 429 "exceeded your current quota" returned 429 with Kimi's words. A 502 returned 502.
  - A 401 surfaced the expired message.
  - Each upstream request carried only the Work token and the plugin's own User-Agent.
- The endpoint guard (index.mjs:106-109) is unchanged. Its test was removed with the old error-body test, so a follow-up commit adds it back.
2026-10-17 14:05:36 +08:00
kupakupa adcc7252d0 kimi-work: a Kimi desktop Work subscription through the desktop's own sign-in (#171)
Adds kimi-work 0.1.3 (kupakupar): a provider for the Kimi desktop's Work
subscription, using the desktop app's own local sign-in. It stores only
a hashed account reference, rereads the desktop's tokens on each call,
writes nothing to disk and logs nothing.

Re-reviewed at d9fe48d against the last review at fc3e395:
- (1) the desktop credential: decided acceptable (same as WorkBuddy,
  Qoder, ZCode: each user's own allowance).
- (2) macOS record: COMPATIBILITY.md, macOS 26.6.2 arm64, Kimi 3.2.17
  (3.2.17.4), magpie 0.1.1276 (released 2026-10-16 17:11Z, before the
  20:09Z run), Bun 1.4.3. The path and four field names match readDesktop.
- expireTime: resetsAt dropped, window renamed 会员共享额度.
- efforts: every advertised level is kept (redacted real catalog fixture).
- kimi-work-opencode overlap: the README credits it and says not to
  enable both.
- Request input: handled; body, headers and signal are kept, and the
  desktop credential replaces any caller Authorization or Cookie.
- Icon is shipped once (package.json); the UA reads the package version.

Run at d9fe48d, and merged onto origin/main 2ea25b9 together with #169:
- HOME=$(mktemp -d) bun test: 1656 pass, 0 fail (merged: 1668 pass, 0 fail).
- bun test packages/kimi-work: 8 pass.
- bun scripts/check.mjs: ok (kimi-work checked).
- git diff --check, npm pack --dry-run (4 files), node scripts/dist.mjs
  (packs opencode-kimi-work-auth@0.1.3), scripts/new-to-npm.sh (new).
- Broken by hand: String(input) for Request and the old effort allow-list
  each turn their new test red.
- No CI ran on the PR. No real Kimi account or credential was used.
2026-10-17 04:32:42 +08:00