kimi-plugin-cc 3.0.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +3 -14
  3. package/README.md +428 -572
  4. package/assets/logo.svg +6 -0
  5. package/cordis.patch.yml +18 -0
  6. package/dist/background-spawn.js +4 -2
  7. package/dist/cli-client.js +105 -66
  8. package/dist/commands/ask.js +27 -12
  9. package/dist/commands/cancel.js +4 -13
  10. package/dist/commands/cli-helpers.js +1 -1
  11. package/dist/commands/pursue.js +3 -2
  12. package/dist/commands/registry.js +7 -26
  13. package/dist/commands/repair-sessions.js +7 -4
  14. package/dist/commands/replay.js +4 -3
  15. package/dist/commands/rescue.js +17 -5
  16. package/dist/commands/review.js +18 -5
  17. package/dist/commands/setup.js +283 -265
  18. package/dist/commands/swarm.js +20 -7
  19. package/dist/companion.js +142 -18
  20. package/dist/help.js +11 -7
  21. package/dist/hook-escape.js +7 -16
  22. package/dist/hooks/approval-hook.js +1762 -124
  23. package/dist/hooks/approval-policy.js +15 -10
  24. package/dist/hooks/config-safety.js +15 -24
  25. package/dist/hooks/hook-timing.js +1 -1
  26. package/dist/hooks/install-paths.js +224 -112
  27. package/dist/hooks/install.js +64 -169
  28. package/dist/hooks/managed-block.js +52 -101
  29. package/dist/job-store.js +117 -49
  30. package/dist/jobs.js +53 -1
  31. package/dist/kimi-engine.js +68 -92
  32. package/dist/kimi-errors.js +1 -1
  33. package/dist/kimi-journal.js +3 -2
  34. package/dist/kimi-releases.js +28 -49
  35. package/dist/kimi-timeouts.js +1 -15
  36. package/dist/kimi-version-probe.js +24 -72
  37. package/dist/logging.js +12 -7
  38. package/dist/mcp/binding.js +13 -4
  39. package/dist/mcp/job-control.js +386 -89
  40. package/dist/mcp/launcher.js +1 -1
  41. package/dist/mcp/operations.js +387 -193
  42. package/dist/mcp/protocol.js +116 -27
  43. package/dist/mcp/skills.js +130 -0
  44. package/dist/mcp/stdio.js +15 -2
  45. package/dist/native-v2-preflight.js +127 -35
  46. package/dist/parsing.js +45 -11
  47. package/dist/paths.js +20 -10
  48. package/dist/plugin-data.js +28 -83
  49. package/dist/read-scope.js +2 -2
  50. package/dist/render.js +13 -38
  51. package/dist/session-references.js +216 -0
  52. package/dist/session-title.js +1 -1
  53. package/dist/surface-routing.js +92 -5
  54. package/dist/swarm-activation.js +26 -137
  55. package/dist/version.js +1 -1
  56. package/docs/migration.md +46 -227
  57. package/docs/models.md +24 -66
  58. package/docs/safety.md +195 -400
  59. package/docs/session-visibility.md +24 -14
  60. package/docs/swarm-recovery.md +26 -20
  61. package/dsh/index.json +54 -0
  62. package/mcp_config.json +10 -0
  63. package/package.json +23 -82
  64. package/plugin.json +19 -0
  65. package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
  66. package/plugins/kimi-codex/.mcp.json +2 -3
  67. package/plugins/kimi-codex/dist/background-spawn.js +4 -2
  68. package/plugins/kimi-codex/dist/cli-client.js +105 -66
  69. package/plugins/kimi-codex/dist/commands/ask.js +27 -12
  70. package/plugins/kimi-codex/dist/commands/cancel.js +4 -13
  71. package/plugins/kimi-codex/dist/commands/cli-helpers.js +1 -1
  72. package/plugins/kimi-codex/dist/commands/pursue.js +3 -2
  73. package/plugins/kimi-codex/dist/commands/registry.js +7 -26
  74. package/plugins/kimi-codex/dist/commands/repair-sessions.js +7 -4
  75. package/plugins/kimi-codex/dist/commands/replay.js +4 -3
  76. package/plugins/kimi-codex/dist/commands/rescue.js +17 -5
  77. package/plugins/kimi-codex/dist/commands/review.js +18 -5
  78. package/plugins/kimi-codex/dist/commands/setup.js +283 -265
  79. package/plugins/kimi-codex/dist/commands/swarm.js +20 -7
  80. package/plugins/kimi-codex/dist/companion.js +142 -18
  81. package/plugins/kimi-codex/dist/help.js +11 -7
  82. package/plugins/kimi-codex/dist/hook-escape.js +7 -16
  83. package/plugins/kimi-codex/dist/hooks/approval-hook.js +1762 -124
  84. package/plugins/kimi-codex/dist/hooks/approval-policy.js +15 -10
  85. package/plugins/kimi-codex/dist/hooks/config-safety.js +15 -24
  86. package/plugins/kimi-codex/dist/hooks/hook-timing.js +1 -1
  87. package/plugins/kimi-codex/dist/hooks/install-paths.js +224 -112
  88. package/plugins/kimi-codex/dist/hooks/install.js +64 -169
  89. package/plugins/kimi-codex/dist/hooks/managed-block.js +52 -101
  90. package/plugins/kimi-codex/dist/job-store.js +117 -49
  91. package/plugins/kimi-codex/dist/jobs.js +53 -1
  92. package/plugins/kimi-codex/dist/kimi-engine.js +68 -92
  93. package/plugins/kimi-codex/dist/kimi-errors.js +1 -1
  94. package/plugins/kimi-codex/dist/kimi-journal.js +3 -2
  95. package/plugins/kimi-codex/dist/kimi-releases.js +28 -49
  96. package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -15
  97. package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -72
  98. package/plugins/kimi-codex/dist/logging.js +12 -7
  99. package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
  100. package/plugins/kimi-codex/dist/mcp/job-control.js +386 -89
  101. package/plugins/kimi-codex/dist/mcp/launcher.js +1 -1
  102. package/plugins/kimi-codex/dist/mcp/operations.js +387 -193
  103. package/plugins/kimi-codex/dist/mcp/protocol.js +116 -27
  104. package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
  105. package/plugins/kimi-codex/dist/mcp/stdio.js +15 -2
  106. package/plugins/kimi-codex/dist/native-v2-preflight.js +127 -35
  107. package/plugins/kimi-codex/dist/parsing.js +45 -11
  108. package/plugins/kimi-codex/dist/paths.js +20 -10
  109. package/plugins/kimi-codex/dist/plugin-data.js +28 -83
  110. package/plugins/kimi-codex/dist/read-scope.js +2 -2
  111. package/plugins/kimi-codex/dist/render.js +13 -38
  112. package/plugins/kimi-codex/dist/session-references.js +216 -0
  113. package/plugins/kimi-codex/dist/session-title.js +1 -1
  114. package/plugins/kimi-codex/dist/surface-routing.js +92 -5
  115. package/plugins/kimi-codex/dist/swarm-activation.js +26 -137
  116. package/plugins/kimi-codex/dist/version.js +1 -1
  117. package/plugins/kimi-codex/scripts/companion.sh +4 -15
  118. package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
  119. package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
  120. package/scripts/companion.sh +4 -15
  121. package/skills/kimi/SKILL.md +77 -0
  122. package/skills/kimi/agents/openai.yaml +6 -0
  123. package/CHANGELOG.md +0 -1402
  124. package/agents/kimi-pursue.md +0 -93
  125. package/agents/kimi-review.md +0 -86
  126. package/agents/kimi-swarm.md +0 -88
  127. package/agents/kimi-task.md +0 -93
  128. package/commands/README.md +0 -14
  129. package/commands/cancel.md +0 -17
  130. package/commands/pursue.md +0 -41
  131. package/commands/replay.md +0 -13
  132. package/commands/result.md +0 -13
  133. package/commands/review.md +0 -40
  134. package/commands/setup.md +0 -25
  135. package/commands/status.md +0 -13
  136. package/commands/swarm.md +0 -45
  137. package/commands/task.md +0 -40
  138. package/dist/commands/review-gate.js +0 -391
  139. package/dist/config.js +0 -22
  140. package/dist/dsh/companion.js +0 -177
  141. package/dist/dsh/index.js +0 -167
  142. package/dist/hooks/review-gate-stop.js +0 -19
  143. package/dist/schemas/review-gate-output.js +0 -41
  144. package/docs/registry-releases.md +0 -228
  145. package/docs/upstream-2.4.1-certification.md +0 -54
  146. package/docs/upstream-2.5.0-certification.md +0 -52
  147. package/docs/upstream-2.5.1-certification.md +0 -47
  148. package/docs/upstream-2.5.2-certification.md +0 -40
  149. package/docs/upstream-2.5.3-certification.md +0 -73
  150. package/docs/upstream-2.6.0-certification.md +0 -65
  151. package/docs/upstream-2.6.2-certification.md +0 -144
  152. package/docs/upstream-2.6.3-certification.md +0 -100
  153. package/docs/upstream-2.7.2-certification.md +0 -113
  154. package/docs/upstream-2.7.3-certification.md +0 -95
  155. package/docs/windows-validation.md +0 -39
  156. package/hooks/README.md +0 -9
  157. package/hooks/hooks.json +0 -16
  158. package/plugins/kimi-codex/dist/commands/review-gate.js +0 -391
  159. package/plugins/kimi-codex/dist/config.js +0 -22
  160. package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
  161. package/plugins/kimi-codex/dist/dsh/index.js +0 -167
  162. package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
  163. package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -41
  164. package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
  165. package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
  166. package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
  167. package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
  168. package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
  169. package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
  170. package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
  171. package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
  172. package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
  173. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -35
  174. package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
  175. package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -35
  176. package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
  177. package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
  178. package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
  179. package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -37
  180. package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
  181. package/plugins/kimi-codex/skills/kimi-task/SKILL.md +0 -37
  182. package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +0 -6
  183. package/plugins/kimi-dsh/LICENSE +0 -201
  184. package/plugins/kimi-dsh/README.md +0 -84
  185. package/plugins/kimi-dsh/cordis.patch.yml +0 -45
  186. package/plugins/kimi-dsh/dist/background-spawn.js +0 -209
  187. package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
  188. package/plugins/kimi-dsh/dist/cli-client.js +0 -1097
  189. package/plugins/kimi-dsh/dist/commands/ask.js +0 -269
  190. package/plugins/kimi-dsh/dist/commands/cancel.js +0 -177
  191. package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -302
  192. package/plugins/kimi-dsh/dist/commands/models.js +0 -139
  193. package/plugins/kimi-dsh/dist/commands/pursue.js +0 -293
  194. package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
  195. package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
  196. package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -266
  197. package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
  198. package/plugins/kimi-dsh/dist/commands/rescue.js +0 -277
  199. package/plugins/kimi-dsh/dist/commands/result.js +0 -72
  200. package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -391
  201. package/plugins/kimi-dsh/dist/commands/review.js +0 -217
  202. package/plugins/kimi-dsh/dist/commands/setup.js +0 -1465
  203. package/plugins/kimi-dsh/dist/commands/status.js +0 -27
  204. package/plugins/kimi-dsh/dist/commands/swarm.js +0 -823
  205. package/plugins/kimi-dsh/dist/commands/worker.js +0 -24
  206. package/plugins/kimi-dsh/dist/companion.js +0 -99
  207. package/plugins/kimi-dsh/dist/config.js +0 -22
  208. package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
  209. package/plugins/kimi-dsh/dist/dsh/index.js +0 -167
  210. package/plugins/kimi-dsh/dist/errors.js +0 -40
  211. package/plugins/kimi-dsh/dist/git.js +0 -216
  212. package/plugins/kimi-dsh/dist/help.js +0 -43
  213. package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
  214. package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -145
  215. package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -295
  216. package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -641
  217. package/plugins/kimi-dsh/dist/hooks/hook-timing.js +0 -48
  218. package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
  219. package/plugins/kimi-dsh/dist/hooks/install.js +0 -405
  220. package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -729
  221. package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
  222. package/plugins/kimi-dsh/dist/job-id.js +0 -12
  223. package/plugins/kimi-dsh/dist/job-store.js +0 -631
  224. package/plugins/kimi-dsh/dist/jobs.js +0 -212
  225. package/plugins/kimi-dsh/dist/kimi-command.js +0 -144
  226. package/plugins/kimi-dsh/dist/kimi-engine.js +0 -770
  227. package/plugins/kimi-dsh/dist/kimi-errors.js +0 -205
  228. package/plugins/kimi-dsh/dist/kimi-home.js +0 -15
  229. package/plugins/kimi-dsh/dist/kimi-journal.js +0 -41
  230. package/plugins/kimi-dsh/dist/kimi-releases.js +0 -144
  231. package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
  232. package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -198
  233. package/plugins/kimi-dsh/dist/logging.js +0 -22
  234. package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
  235. package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -343
  236. package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -263
  237. package/plugins/kimi-dsh/dist/mcp/operations.js +0 -333
  238. package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -277
  239. package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
  240. package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -79
  241. package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
  242. package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
  243. package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
  244. package/plugins/kimi-dsh/dist/model-command.js +0 -34
  245. package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -596
  246. package/plugins/kimi-dsh/dist/package.json +0 -1
  247. package/plugins/kimi-dsh/dist/parsing.js +0 -554
  248. package/plugins/kimi-dsh/dist/paths.js +0 -35
  249. package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
  250. package/plugins/kimi-dsh/dist/process-tree.js +0 -597
  251. package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
  252. package/plugins/kimi-dsh/dist/read-scope.js +0 -435
  253. package/plugins/kimi-dsh/dist/render.js +0 -214
  254. package/plugins/kimi-dsh/dist/rescue-approval.js +0 -1242
  255. package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -41
  256. package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
  257. package/plugins/kimi-dsh/dist/session-title.js +0 -313
  258. package/plugins/kimi-dsh/dist/stream-json.js +0 -344
  259. package/plugins/kimi-dsh/dist/surface-routing.js +0 -21
  260. package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1194
  261. package/plugins/kimi-dsh/dist/swarm-policy.js +0 -74
  262. package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -166
  263. package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
  264. package/plugins/kimi-dsh/dist/types.js +0 -1
  265. package/plugins/kimi-dsh/dist/util.js +0 -28
  266. package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
  267. package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
  268. package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
  269. package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
  270. package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
  271. package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
  272. package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
  273. package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
  274. package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
  275. package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
  276. package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
  277. package/plugins/kimi-dsh/dist/version.js +0 -7
  278. package/plugins/kimi-dsh/package.json +0 -78
  279. package/plugins/kimi-dsh/scripts/companion.sh +0 -37
  280. package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
  281. package/scripts/review-gate-hook.sh +0 -32
@@ -1,277 +0,0 @@
1
- import { formatError, RuntimeError } from "../errors.js";
2
- import { isRecord } from "../util.js";
3
- import { KIMI_PLUGIN_CC_VERSION } from "../version.js";
4
- import { cancelMcpJob, getMcpJobResult, getMcpJobStatus, getMcpTaskView, taskView } from "./job-control.js";
5
- import { launchMcpOperation } from "./launcher.js";
6
- import { buildMcpOperationInvocation, isMcpModelToolName, MCP_TOOL_DEFINITIONS, } from "./operations.js";
7
- import { textResult } from "./tool-result.js";
8
- const MODERN_VERSION = "2026-07-28";
9
- const LEGACY_VERSIONS = new Set(["2024-11-05", "2025-03-26", "2025-06-18", "2025-11-25"]);
10
- const PROTOCOL_VERSION_META = "io.modelcontextprotocol/protocolVersion";
11
- const CLIENT_INFO_META = "io.modelcontextprotocol/clientInfo";
12
- const CLIENT_CAPABILITIES_META = "io.modelcontextprotocol/clientCapabilities";
13
- const TASKS_EXTENSION = "io.modelcontextprotocol/tasks";
14
- const SERVER_INFO_META = "io.modelcontextprotocol/serverInfo";
15
- // Every supported version permits `instructions`: InitializeResult since 2024-11-05, DiscoverResult in 2026-07-28.
16
- export const MCP_SERVER_INSTRUCTIONS = [
17
- "Prefer these tools for detached or long-running Kimi work.",
18
- "Each model tool starts a durable job that keeps running if this connection drops; reconnect and look it up by job_id.",
19
- "Where the host supports MCP tasks, completion arrives as a task notification; otherwise poll kimi_job_status and kimi_job_result with the returned job_id, and stop a job with kimi_job_cancel.",
20
- "kimi_ask, kimi_review and kimi_swarm are read-only. kimi_rescue and kimi_pursue edit the workspace, never git; kimi_swarm_write edits a disposable worktree and returns a patch it never applies.",
21
- "Use a write tool only when the user asked for edits, and kimi_pursue only for an explicitly autonomous objective.",
22
- "A result may carry warnings, such as an uncertified Kimi release or workspace trust being off; relay them to the user.",
23
- ].join(" ");
24
- export function createMcpMessageHandler(env) {
25
- let mode;
26
- return async (message) => {
27
- let requestId = isRecord(message) && "id" in message &&
28
- (typeof message.id === "string" || typeof message.id === "number" || message.id === null)
29
- ? message.id
30
- : null;
31
- try {
32
- const request = parseRequest(message);
33
- if (!request)
34
- return undefined;
35
- requestId = request.id;
36
- const { id, method, params } = request;
37
- if (method === "server/discover") {
38
- requireModernMetadata(params);
39
- mode = "modern";
40
- return response(id, {
41
- resultType: "complete",
42
- supportedVersions: [MODERN_VERSION],
43
- capabilities: { tools: {}, extensions: { [TASKS_EXTENSION]: {} } },
44
- instructions: MCP_SERVER_INSTRUCTIONS,
45
- _meta: { [SERVER_INFO_META]: { name: "kimi-plugin-cc", version: KIMI_PLUGIN_CC_VERSION } },
46
- ttlMs: 0,
47
- cacheScope: "private",
48
- });
49
- }
50
- if (method === "initialize") {
51
- const requested = params.protocolVersion;
52
- if (typeof requested !== "string" || !LEGACY_VERSIONS.has(requested)) {
53
- throw rpcError(-32_602, "Unsupported protocol version", { supportedVersions: [...LEGACY_VERSIONS] });
54
- }
55
- mode = "legacy";
56
- return response(id, {
57
- protocolVersion: requested,
58
- capabilities: { tools: {} },
59
- serverInfo: { name: "kimi-plugin-cc", version: KIMI_PLUGIN_CC_VERSION },
60
- instructions: MCP_SERVER_INSTRUCTIONS,
61
- });
62
- }
63
- if (method === "notifications/initialized")
64
- return undefined;
65
- if (method.startsWith("notifications/"))
66
- return undefined;
67
- if (!mode && hasModernVersion(params))
68
- mode = "modern";
69
- if (!mode)
70
- throw rpcError(-32_002, "Server is not initialized");
71
- const modern = requireProtocolMode(mode, method);
72
- const capabilities = modern ? requireModernMetadata(params) : undefined;
73
- switch (method) {
74
- case "ping":
75
- return response(id, modern ? { resultType: "complete" } : {});
76
- case "tools/list":
77
- return response(id, modern
78
- ? { resultType: "complete", tools: MCP_TOOL_DEFINITIONS, ttlMs: 0, cacheScope: "private" }
79
- : { tools: MCP_TOOL_DEFINITIONS });
80
- case "tools/call":
81
- return response(id, await callTool(env, params, modern, capabilities));
82
- case "tasks/get": {
83
- requireModern(method, modern);
84
- requireTasksCapability(method, capabilities);
85
- const taskId = requiredTaskId(params);
86
- try {
87
- const view = await getMcpTaskView(env, { job_id: taskId });
88
- return response(id, { resultType: "complete", ...view });
89
- }
90
- catch (error) {
91
- if (error instanceof RuntimeError && error.code === "JOB_NOT_FOUND") {
92
- throw rpcError(-32_602, `Unknown task ID: ${taskId}`);
93
- }
94
- throw error;
95
- }
96
- }
97
- case "tasks/cancel": {
98
- requireModern(method, modern);
99
- requireTasksCapability(method, capabilities);
100
- const taskId = requiredTaskId(params);
101
- try {
102
- await cancelMcpJob(env, { job_id: taskId });
103
- return response(id, { resultType: "complete" });
104
- }
105
- catch (error) {
106
- if (error instanceof RuntimeError && error.code === "JOB_NOT_FOUND") {
107
- throw rpcError(-32_602, `Unknown task ID: ${taskId}`);
108
- }
109
- throw error;
110
- }
111
- }
112
- default:
113
- throw rpcError(-32_601, `Method not found: ${method}`);
114
- }
115
- }
116
- catch (error) {
117
- if (isRpcError(error))
118
- return response(requestId, undefined, error);
119
- if (error instanceof RuntimeError) {
120
- return response(requestId, undefined, rpcError(-32_603, formatError(error), error.details));
121
- }
122
- return response(requestId, undefined, rpcError(-32_603, error instanceof Error ? error.message : String(error)));
123
- }
124
- };
125
- }
126
- async function callTool(env, params, modern, capabilities) {
127
- const name = params.name;
128
- if (typeof name !== "string")
129
- throw rpcError(-32_602, "tools/call requires a tool name");
130
- try {
131
- let result;
132
- if (isMcpModelToolName(name)) {
133
- const launched = await launchMcpOperation(buildMcpOperationInvocation(name, params.arguments), env);
134
- if (modern && hasTasksCapability(capabilities))
135
- return taskHandle(launched);
136
- result = launched.job.status === "running"
137
- ? launchResult(launched)
138
- : await getMcpJobResult(env, { job_id: launched.task.task_id });
139
- }
140
- else {
141
- switch (name) {
142
- case "kimi_job_status":
143
- result = await getMcpJobStatus(env, params.arguments);
144
- break;
145
- case "kimi_job_result":
146
- result = await getMcpJobResult(env, params.arguments);
147
- break;
148
- case "kimi_job_cancel":
149
- result = await cancelMcpJob(env, params.arguments);
150
- break;
151
- default:
152
- throw rpcError(-32_602, `Unknown tool: ${name}`);
153
- }
154
- }
155
- return modern ? { resultType: "complete", ...result } : result;
156
- }
157
- catch (error) {
158
- if (isRpcError(error))
159
- throw error;
160
- if (error instanceof RuntimeError) {
161
- const result = textResult(formatError(error), {
162
- error: { code: error.code, stage: error.stage, details: error.details },
163
- }, true);
164
- return modern ? { resultType: "complete", ...result } : result;
165
- }
166
- throw error;
167
- }
168
- }
169
- function launchResult(launched) {
170
- const { task, job } = launched;
171
- const metadata = {
172
- job_id: task.task_id,
173
- operation_kind: task.operation_kind,
174
- workspace: task.workspace_cwd,
175
- status: job.status,
176
- phase: job.phase,
177
- created_at: task.created_at,
178
- };
179
- return textResult(`Started ${task.operation_kind} job ${task.task_id}. This is a launch handle, not the finished answer. Use kimi_job_status and kimi_job_result with this job_id until the job is terminal; use kimi_job_cancel to stop it.`, metadata);
180
- }
181
- function taskHandle({ task, job }) {
182
- const status = job.status === "running" ? "working" : job.status === "cancelled" ? "cancelled" : "completed";
183
- const statusMessage = job.status === "running" ? `${task.operation_kind}: ${job.phase ?? "running"}` : job.summary;
184
- return { resultType: "task", ...taskView(task, job, status, undefined, statusMessage) };
185
- }
186
- function parseRequest(message) {
187
- if (!isRecord(message))
188
- throw new McpJsonRpcError(-32_600, "Invalid JSON-RPC request");
189
- if (!("method" in message))
190
- return undefined;
191
- if (message.jsonrpc !== "2.0" || typeof message.method !== "string" || message.method.length === 0) {
192
- throw new McpJsonRpcError(-32_600, "Invalid JSON-RPC request");
193
- }
194
- if (!("id" in message))
195
- return undefined;
196
- const id = message.id;
197
- if (id !== null && typeof id !== "string" &&
198
- (typeof id !== "number" || !Number.isFinite(id))) {
199
- throw new McpJsonRpcError(-32_600, "Invalid JSON-RPC request ID");
200
- }
201
- const params = message.params === undefined ? {} : message.params;
202
- if (!isRecord(params))
203
- throw new McpJsonRpcError(-32_602, "Request params must be an object");
204
- return { id, method: message.method, params };
205
- }
206
- function requireProtocolMode(mode, method) {
207
- if (mode === "modern")
208
- return true;
209
- if (method === "tasks/get" || method === "tasks/cancel") {
210
- throw new McpJsonRpcError(-32_601, `Method not found: ${method}`);
211
- }
212
- return false;
213
- }
214
- function requireModern(method, modern) {
215
- if (!modern)
216
- throw new McpJsonRpcError(-32_601, `Method not found: ${method}`);
217
- }
218
- function hasModernVersion(params) {
219
- return isRecord(params._meta) && params._meta[PROTOCOL_VERSION_META] === MODERN_VERSION;
220
- }
221
- function requireModernMetadata(params) {
222
- const meta = params._meta;
223
- if (!meta || typeof meta !== "object" || Array.isArray(meta)) {
224
- throw new McpJsonRpcError(-32_602, "Modern MCP requests require protocol metadata");
225
- }
226
- const record = meta;
227
- if (record[PROTOCOL_VERSION_META] !== MODERN_VERSION) {
228
- throw new McpJsonRpcError(-32_022, "Unsupported protocol version", {
229
- supported: [MODERN_VERSION],
230
- requested: record[PROTOCOL_VERSION_META],
231
- });
232
- }
233
- if (record[CLIENT_INFO_META] !== undefined && !isRecord(record[CLIENT_INFO_META])) {
234
- throw new McpJsonRpcError(-32_602, "clientInfo must be an object when supplied");
235
- }
236
- if (!isRecord(record[CLIENT_CAPABILITIES_META])) {
237
- throw new McpJsonRpcError(-32_602, "Modern MCP requests require client capabilities");
238
- }
239
- return record[CLIENT_CAPABILITIES_META];
240
- }
241
- function hasTasksCapability(capabilities) {
242
- if (!capabilities || !isRecord(capabilities.extensions))
243
- return false;
244
- return isRecord(capabilities.extensions[TASKS_EXTENSION]);
245
- }
246
- function requireTasksCapability(method, capabilities) {
247
- if (!hasTasksCapability(capabilities)) {
248
- throw new McpJsonRpcError(-32_021, "Missing required client capability", {
249
- requiredCapabilities: { extensions: { [TASKS_EXTENSION]: {} } },
250
- });
251
- }
252
- }
253
- function requiredTaskId(params) {
254
- if (typeof params.taskId !== "string" || params.taskId.length === 0 || params.taskId.length > 128 || !/^[\x21-\x7e]+$/.test(params.taskId)) {
255
- throw new McpJsonRpcError(-32_602, "taskId must be 1-128 printable ASCII characters without spaces");
256
- }
257
- return params.taskId;
258
- }
259
- function response(id, result, error) {
260
- return error ? { jsonrpc: "2.0", id, error: { code: error.code, message: error.message, ...(error.data !== undefined ? { data: error.data } : {}) } } : { jsonrpc: "2.0", id, result };
261
- }
262
- function rpcError(code, message, data) {
263
- return new McpJsonRpcError(code, message, data);
264
- }
265
- class McpJsonRpcError extends Error {
266
- code;
267
- data;
268
- constructor(code, message, data) {
269
- super(message);
270
- this.code = code;
271
- this.data = data;
272
- this.name = "McpJsonRpcError";
273
- }
274
- }
275
- function isRpcError(error) {
276
- return error instanceof McpJsonRpcError || (error instanceof Error && "code" in error && typeof error.code === "number");
277
- }
@@ -1,8 +0,0 @@
1
- import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
2
- import { createMcpMessageHandler } from "./protocol.js";
3
- import { serveMcpStdio } from "./stdio.js";
4
- export async function runMcpServer(context) {
5
- const paths = resolvePluginPaths(context.env);
6
- await ensurePluginPaths(paths);
7
- await serveMcpStdio(process.stdin, process.stdout, createMcpMessageHandler(context.env));
8
- }
@@ -1,79 +0,0 @@
1
- const MAX_MESSAGE_BYTES = 8 * 1024 * 1024;
2
- export async function serveMcpStdio(input, output, handle) {
3
- let buffer = Buffer.alloc(0);
4
- let writeTail = Promise.resolve();
5
- let writeError;
6
- const pending = new Set();
7
- output.on("error", (error) => { writeError ??= error; });
8
- const write = (message) => {
9
- if (writeError)
10
- return Promise.reject(writeError);
11
- const frame = `${JSON.stringify(message)}\n`;
12
- writeTail = writeTail.then(() => new Promise((resolve, reject) => {
13
- try {
14
- if (output.write(frame))
15
- resolve();
16
- else
17
- output.once("drain", resolve);
18
- }
19
- catch (error) {
20
- reject(error);
21
- }
22
- }));
23
- return writeTail;
24
- };
25
- const track = (promise) => {
26
- const tracked = promise.catch((error) => { writeError ??= error; }).finally(() => pending.delete(tracked));
27
- pending.add(tracked);
28
- };
29
- try {
30
- for await (const chunk of input) {
31
- buffer = Buffer.concat([buffer, Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)]);
32
- for (;;) {
33
- const newline = buffer.indexOf(0x0a);
34
- if (newline < 0)
35
- break;
36
- const line = buffer.subarray(0, newline);
37
- buffer = buffer.subarray(newline + 1);
38
- if (line.length > MAX_MESSAGE_BYTES)
39
- throw new Error("MCP frame exceeds 8 MiB");
40
- const text = line.toString("utf8");
41
- if (text.trim().length === 0)
42
- continue;
43
- let parsed;
44
- try {
45
- parsed = JSON.parse(text);
46
- }
47
- catch {
48
- track(write({ jsonrpc: "2.0", id: null, error: { code: -32_700, message: "Parse error" } }));
49
- continue;
50
- }
51
- track((async () => {
52
- try {
53
- const response = await handle(parsed);
54
- if (response !== undefined)
55
- await write(response);
56
- }
57
- catch (error) {
58
- await write({
59
- jsonrpc: "2.0",
60
- id: null,
61
- error: { code: -32_603, message: error instanceof Error ? error.message : String(error) },
62
- });
63
- }
64
- })());
65
- }
66
- if (buffer.length > MAX_MESSAGE_BYTES)
67
- throw new Error("MCP frame exceeds 8 MiB");
68
- }
69
- }
70
- catch (error) {
71
- await write({ jsonrpc: "2.0", id: null, error: { code: -32_700, message: error instanceof Error ? error.message : String(error) } });
72
- }
73
- finally {
74
- await Promise.all(pending);
75
- await writeTail;
76
- if (writeError)
77
- throw writeError;
78
- }
79
- }
@@ -1,15 +0,0 @@
1
- import { RuntimeError } from "../errors.js";
2
- import { allocateJobId } from "../job-id.js";
3
- import { runModelCommand } from "../model-command.js";
4
- export async function runMcpChild(argv, context) {
5
- const [jobId, ...command] = argv;
6
- if (!jobId || command.length === 0) {
7
- throw new RuntimeError("MCP_INVALID_CHILD", "mcp-child expects a job UUID followed by one model operation.", "mcp.child");
8
- }
9
- const mcpJobId = allocateJobId({ ...context, mcpJobId: jobId });
10
- const result = await runModelCommand(command, { ...context, mcpJobId });
11
- if (result === undefined) {
12
- throw new RuntimeError("MCP_INVALID_CHILD", "mcp-child accepts only the public model operations.", "mcp.child");
13
- }
14
- return result;
15
- }
@@ -1,7 +0,0 @@
1
- export function textResult(text, structuredContent, isError = false) {
2
- return {
3
- content: [{ type: "text", text }],
4
- ...(structuredContent ? { structuredContent } : {}),
5
- isError,
6
- };
7
- }
@@ -1,34 +0,0 @@
1
- import { realpath, stat } from "node:fs/promises";
2
- import path from "node:path";
3
- import { RuntimeError } from "../errors.js";
4
- import { resolveRepoIdentity } from "../git.js";
5
- export async function resolveMcpWorkspace(env, requested) {
6
- const defaultCandidate = env.KIMI_PLUGIN_CC_MCP_WORKSPACE;
7
- const candidate = requested ?? defaultCandidate;
8
- if (!candidate) {
9
- throw new RuntimeError("MCP_WORKSPACE_REQUIRED", "This MCP server has no default workspace. Supply the absolute workspace directory explicitly; Codex calls normally require it.", "mcp.workspace");
10
- }
11
- const cwd = await canonicalDirectory(candidate, "workspace");
12
- if (defaultCandidate) {
13
- const defaultCwd = await canonicalDirectory(defaultCandidate, "host workspace");
14
- const relative = path.relative(defaultCwd, cwd);
15
- if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
16
- throw new RuntimeError("MCP_WORKSPACE_OUTSIDE_DEFAULT", `workspace must be the host workspace or one of its descendants, not ${cwd} (host: ${defaultCwd}).`, "mcp.workspace");
17
- }
18
- }
19
- return { cwd, repo: await resolveRepoIdentity(cwd) };
20
- }
21
- async function canonicalDirectory(candidate, label) {
22
- if (!path.isAbsolute(candidate)) {
23
- throw new RuntimeError("MCP_WORKSPACE_NOT_ABSOLUTE", `${label} must be an absolute existing directory.`, "mcp.workspace");
24
- }
25
- try {
26
- const cwd = await realpath(candidate);
27
- if (!(await stat(cwd)).isDirectory())
28
- throw new Error("not a directory");
29
- return cwd;
30
- }
31
- catch (error) {
32
- throw new RuntimeError("MCP_WORKSPACE_INVALID", `${label} is not an accessible existing directory: ${candidate}`, "mcp.workspace", error instanceof Error ? { cause: error } : undefined);
33
- }
34
- }
@@ -1,34 +0,0 @@
1
- import { runAsk } from "./commands/ask.js";
2
- import { runPursue } from "./commands/pursue.js";
3
- import { runRescue } from "./commands/rescue.js";
4
- import { runReview } from "./commands/review.js";
5
- import { runSwarm } from "./commands/swarm.js";
6
- import { RuntimeError } from "./errors.js";
7
- export async function runModelCommand(argv, context) {
8
- const [command, ...rest] = argv;
9
- switch (command) {
10
- case "review":
11
- return `${await runReview(rest, context, "review")}\n`;
12
- case "ask":
13
- return `${await runAsk(rest, context)}\n`;
14
- case "task": {
15
- const [taskType, ...taskArgs] = rest;
16
- switch (taskType) {
17
- case "rescue":
18
- return runRescue(taskArgs, context);
19
- case "challenge":
20
- return `${await runReview(taskArgs, context, "challenge")}\n`;
21
- case "pursue":
22
- return runPursue(taskArgs, context);
23
- case "swarm":
24
- return runSwarm(taskArgs, context);
25
- default: {
26
- const label = taskType ? `task ${taskType}` : "task";
27
- throw new RuntimeError("NOT_IMPLEMENTED", `Companion subcommand ${label} is not implemented.`, label);
28
- }
29
- }
30
- }
31
- default:
32
- return undefined;
33
- }
34
- }