Commit Graph
4 Commits
Author SHA1 Message Date
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
yetone 3e966bb4b5 kimi-work: test that the Work token goes only to the official chat endpoint
#190 dropped the old guard assertion with the error-body test it lived in.
The guard (index.mjs:106-109) is unchanged; this puts its test back and
widens it: another host, another path, a query, credentials in the URL and
GET are all refused before any fetch.

Run: bun test packages/kimi-work (18 pass); bun scripts/check.mjs kimi-work
(ok). Removing url.search from the guard turns this test red.
2026-10-17 14:07:29 +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