kimi-plugin-cc 2.7.3 → 3.1.0

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 (317) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +3 -16
  3. package/README.md +428 -515
  4. package/assets/logo.svg +6 -0
  5. package/cordis.patch.yml +18 -0
  6. package/dist/background-spawn.js +14 -19
  7. package/dist/cli-client.js +163 -105
  8. package/dist/commands/ask.js +44 -96
  9. package/dist/commands/cancel.js +11 -59
  10. package/dist/commands/cli-helpers.js +102 -1
  11. package/dist/commands/models.js +2 -3
  12. package/dist/commands/pursue.js +8 -21
  13. package/dist/commands/registry.js +7 -26
  14. package/dist/commands/repair-sessions.js +121 -12
  15. package/dist/commands/replay.js +4 -3
  16. package/dist/commands/rescue.js +29 -87
  17. package/dist/commands/result.js +7 -1
  18. package/dist/commands/review.js +28 -18
  19. package/dist/commands/setup.js +813 -462
  20. package/dist/commands/status.js +2 -2
  21. package/dist/commands/swarm.js +112 -125
  22. package/dist/commands/worker.js +1 -2
  23. package/dist/companion.js +145 -19
  24. package/dist/git.js +1 -9
  25. package/dist/help.js +13 -9
  26. package/dist/hook-escape.js +7 -16
  27. package/dist/hooks/approval-hook.js +1766 -87
  28. package/dist/hooks/approval-policy.js +86 -19
  29. package/dist/hooks/config-safety.js +31 -64
  30. package/dist/hooks/hook-timing.js +48 -0
  31. package/dist/hooks/install-paths.js +179 -107
  32. package/dist/hooks/install.js +126 -53
  33. package/dist/hooks/managed-block.js +121 -127
  34. package/dist/job-store.js +206 -166
  35. package/dist/jobs.js +66 -19
  36. package/dist/kimi-command.js +74 -1
  37. package/dist/kimi-engine.js +198 -127
  38. package/dist/kimi-errors.js +15 -70
  39. package/dist/kimi-home.js +6 -0
  40. package/dist/kimi-journal.js +42 -0
  41. package/dist/kimi-releases.js +123 -0
  42. package/dist/kimi-timeouts.js +2 -16
  43. package/dist/kimi-version-probe.js +24 -108
  44. package/dist/logging.js +12 -7
  45. package/dist/mcp/binding.js +13 -4
  46. package/dist/mcp/job-control.js +390 -95
  47. package/dist/mcp/launcher.js +13 -7
  48. package/dist/mcp/operations.js +405 -179
  49. package/dist/mcp/protocol.js +124 -33
  50. package/dist/mcp/skills.js +130 -0
  51. package/dist/mcp/stdio.js +18 -4
  52. package/dist/model-command.js +5 -3
  53. package/dist/native-v2-preflight.js +243 -80
  54. package/dist/parsing.js +211 -243
  55. package/dist/paths.js +28 -10
  56. package/dist/plugin-data.js +28 -83
  57. package/dist/process-tree.js +35 -24
  58. package/dist/read-scope.js +435 -0
  59. package/dist/render.js +58 -46
  60. package/dist/rescue-approval.js +461 -84
  61. package/dist/session-references.js +216 -0
  62. package/dist/session-title.js +26 -6
  63. package/dist/stream-json.js +1 -3
  64. package/dist/surface-routing.js +108 -0
  65. package/dist/swarm-activation.js +74 -188
  66. package/dist/swarm-policy.js +2 -1
  67. package/dist/swarm-recovery.js +2 -1
  68. package/dist/util.js +28 -0
  69. package/dist/version.js +1 -1
  70. package/docs/migration.md +45 -206
  71. package/docs/models.md +24 -66
  72. package/docs/safety.md +198 -353
  73. package/docs/session-visibility.md +25 -13
  74. package/docs/swarm-recovery.md +26 -20
  75. package/dsh/index.json +54 -0
  76. package/mcp_config.json +10 -0
  77. package/package.json +23 -82
  78. package/plugin.json +19 -0
  79. package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
  80. package/plugins/kimi-codex/.mcp.json +3 -3
  81. package/plugins/kimi-codex/dist/background-spawn.js +14 -19
  82. package/plugins/kimi-codex/dist/cli-client.js +163 -105
  83. package/plugins/kimi-codex/dist/commands/ask.js +44 -96
  84. package/plugins/kimi-codex/dist/commands/cancel.js +11 -59
  85. package/plugins/kimi-codex/dist/commands/cli-helpers.js +102 -1
  86. package/plugins/kimi-codex/dist/commands/models.js +2 -3
  87. package/plugins/kimi-codex/dist/commands/pursue.js +8 -21
  88. package/plugins/kimi-codex/dist/commands/registry.js +7 -26
  89. package/plugins/kimi-codex/dist/commands/repair-sessions.js +121 -12
  90. package/plugins/kimi-codex/dist/commands/replay.js +4 -3
  91. package/plugins/kimi-codex/dist/commands/rescue.js +29 -87
  92. package/plugins/kimi-codex/dist/commands/result.js +7 -1
  93. package/plugins/kimi-codex/dist/commands/review.js +28 -18
  94. package/plugins/kimi-codex/dist/commands/setup.js +813 -462
  95. package/plugins/kimi-codex/dist/commands/status.js +2 -2
  96. package/plugins/kimi-codex/dist/commands/swarm.js +112 -125
  97. package/plugins/kimi-codex/dist/commands/worker.js +1 -2
  98. package/plugins/kimi-codex/dist/companion.js +145 -19
  99. package/plugins/kimi-codex/dist/git.js +1 -9
  100. package/plugins/kimi-codex/dist/help.js +13 -9
  101. package/plugins/kimi-codex/dist/hook-escape.js +7 -16
  102. package/plugins/kimi-codex/dist/hooks/approval-hook.js +1766 -87
  103. package/plugins/kimi-codex/dist/hooks/approval-policy.js +86 -19
  104. package/plugins/kimi-codex/dist/hooks/config-safety.js +31 -64
  105. package/plugins/kimi-codex/dist/hooks/hook-timing.js +48 -0
  106. package/plugins/kimi-codex/dist/hooks/install-paths.js +179 -107
  107. package/plugins/kimi-codex/dist/hooks/install.js +126 -53
  108. package/plugins/kimi-codex/dist/hooks/managed-block.js +121 -127
  109. package/plugins/kimi-codex/dist/job-store.js +206 -166
  110. package/plugins/kimi-codex/dist/jobs.js +66 -19
  111. package/plugins/kimi-codex/dist/kimi-command.js +74 -1
  112. package/plugins/kimi-codex/dist/kimi-engine.js +198 -127
  113. package/plugins/kimi-codex/dist/kimi-errors.js +15 -70
  114. package/plugins/kimi-codex/dist/kimi-home.js +6 -0
  115. package/plugins/kimi-codex/dist/kimi-journal.js +42 -0
  116. package/plugins/kimi-codex/dist/kimi-releases.js +123 -0
  117. package/plugins/kimi-codex/dist/kimi-timeouts.js +2 -16
  118. package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -108
  119. package/plugins/kimi-codex/dist/logging.js +12 -7
  120. package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
  121. package/plugins/kimi-codex/dist/mcp/job-control.js +390 -95
  122. package/plugins/kimi-codex/dist/mcp/launcher.js +13 -7
  123. package/plugins/kimi-codex/dist/mcp/operations.js +405 -179
  124. package/plugins/kimi-codex/dist/mcp/protocol.js +124 -33
  125. package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
  126. package/plugins/kimi-codex/dist/mcp/stdio.js +18 -4
  127. package/plugins/kimi-codex/dist/model-command.js +5 -3
  128. package/plugins/kimi-codex/dist/native-v2-preflight.js +243 -80
  129. package/plugins/kimi-codex/dist/parsing.js +211 -243
  130. package/plugins/kimi-codex/dist/paths.js +28 -10
  131. package/plugins/kimi-codex/dist/plugin-data.js +28 -83
  132. package/plugins/kimi-codex/dist/process-tree.js +35 -24
  133. package/plugins/kimi-codex/dist/read-scope.js +435 -0
  134. package/plugins/kimi-codex/dist/render.js +58 -46
  135. package/plugins/kimi-codex/dist/rescue-approval.js +461 -84
  136. package/plugins/kimi-codex/dist/session-references.js +216 -0
  137. package/plugins/kimi-codex/dist/session-title.js +26 -6
  138. package/plugins/kimi-codex/dist/stream-json.js +1 -3
  139. package/plugins/kimi-codex/dist/surface-routing.js +108 -0
  140. package/plugins/kimi-codex/dist/swarm-activation.js +74 -188
  141. package/plugins/kimi-codex/dist/swarm-policy.js +2 -1
  142. package/plugins/kimi-codex/dist/swarm-recovery.js +2 -1
  143. package/plugins/kimi-codex/dist/util.js +28 -0
  144. package/plugins/kimi-codex/dist/version.js +1 -1
  145. package/plugins/kimi-codex/scripts/companion.sh +4 -15
  146. package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
  147. package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
  148. package/scripts/companion.sh +4 -15
  149. package/skills/kimi/SKILL.md +77 -0
  150. package/skills/kimi/agents/openai.yaml +6 -0
  151. package/CHANGELOG.md +0 -1333
  152. package/agents/kimi-ask.md +0 -89
  153. package/agents/kimi-challenge.md +0 -86
  154. package/agents/kimi-pursue.md +0 -93
  155. package/agents/kimi-rescue.md +0 -92
  156. package/agents/kimi-review.md +0 -86
  157. package/agents/kimi-swarm-write.md +0 -96
  158. package/agents/kimi-swarm.md +0 -86
  159. package/commands/README.md +0 -16
  160. package/commands/ask.md +0 -38
  161. package/commands/cancel.md +0 -17
  162. package/commands/challenge.md +0 -35
  163. package/commands/pursue.md +0 -41
  164. package/commands/replay.md +0 -13
  165. package/commands/rescue.md +0 -38
  166. package/commands/result.md +0 -13
  167. package/commands/review.md +0 -35
  168. package/commands/setup.md +0 -23
  169. package/commands/status.md +0 -13
  170. package/commands/swarm.md +0 -44
  171. package/dist/commands/not-implemented.js +0 -4
  172. package/dist/commands/review-gate.js +0 -390
  173. package/dist/config.js +0 -22
  174. package/dist/dsh/companion.js +0 -177
  175. package/dist/dsh/index.js +0 -169
  176. package/dist/hooks/review-gate-stop.js +0 -19
  177. package/dist/schemas/review-gate-output.js +0 -43
  178. package/docs/registry-releases.md +0 -228
  179. package/docs/upstream-2.4.1-certification.md +0 -54
  180. package/docs/upstream-2.5.0-certification.md +0 -52
  181. package/docs/upstream-2.5.1-certification.md +0 -47
  182. package/docs/upstream-2.5.2-certification.md +0 -40
  183. package/docs/upstream-2.5.3-certification.md +0 -73
  184. package/docs/upstream-2.6.0-certification.md +0 -65
  185. package/docs/upstream-2.6.2-certification.md +0 -144
  186. package/docs/upstream-2.6.3-certification.md +0 -100
  187. package/docs/upstream-2.7.2-certification.md +0 -113
  188. package/docs/upstream-2.7.3-certification.md +0 -83
  189. package/docs/windows-validation.md +0 -39
  190. package/hooks/README.md +0 -9
  191. package/hooks/hooks.json +0 -16
  192. package/plugins/kimi-codex/dist/commands/not-implemented.js +0 -4
  193. package/plugins/kimi-codex/dist/commands/review-gate.js +0 -390
  194. package/plugins/kimi-codex/dist/config.js +0 -22
  195. package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
  196. package/plugins/kimi-codex/dist/dsh/index.js +0 -169
  197. package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
  198. package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -43
  199. package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
  200. package/plugins/kimi-codex/skills/kimi-ask/SKILL.md +0 -35
  201. package/plugins/kimi-codex/skills/kimi-ask/agents/openai.yaml +0 -6
  202. package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
  203. package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
  204. package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +0 -34
  205. package/plugins/kimi-codex/skills/kimi-challenge/agents/openai.yaml +0 -6
  206. package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
  207. package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
  208. package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
  209. package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
  210. package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +0 -34
  211. package/plugins/kimi-codex/skills/kimi-rescue/agents/openai.yaml +0 -6
  212. package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
  213. package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
  214. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -34
  215. package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
  216. package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -34
  217. package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
  218. package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
  219. package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
  220. package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -35
  221. package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
  222. package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +0 -36
  223. package/plugins/kimi-codex/skills/kimi-swarm-write/agents/openai.yaml +0 -6
  224. package/plugins/kimi-dsh/LICENSE +0 -201
  225. package/plugins/kimi-dsh/README.md +0 -83
  226. package/plugins/kimi-dsh/cordis.patch.yml +0 -45
  227. package/plugins/kimi-dsh/dist/background-spawn.js +0 -216
  228. package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
  229. package/plugins/kimi-dsh/dist/cli-client.js +0 -1078
  230. package/plugins/kimi-dsh/dist/commands/ask.js +0 -336
  231. package/plugins/kimi-dsh/dist/commands/cancel.js +0 -216
  232. package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -201
  233. package/plugins/kimi-dsh/dist/commands/models.js +0 -140
  234. package/plugins/kimi-dsh/dist/commands/not-implemented.js +0 -4
  235. package/plugins/kimi-dsh/dist/commands/pursue.js +0 -307
  236. package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
  237. package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
  238. package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -160
  239. package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
  240. package/plugins/kimi-dsh/dist/commands/rescue.js +0 -347
  241. package/plugins/kimi-dsh/dist/commands/result.js +0 -66
  242. package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -390
  243. package/plugins/kimi-dsh/dist/commands/review.js +0 -220
  244. package/plugins/kimi-dsh/dist/commands/setup.js +0 -1129
  245. package/plugins/kimi-dsh/dist/commands/status.js +0 -27
  246. package/plugins/kimi-dsh/dist/commands/swarm.js +0 -849
  247. package/plugins/kimi-dsh/dist/commands/worker.js +0 -25
  248. package/plugins/kimi-dsh/dist/companion.js +0 -97
  249. package/plugins/kimi-dsh/dist/config.js +0 -22
  250. package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
  251. package/plugins/kimi-dsh/dist/dsh/index.js +0 -169
  252. package/plugins/kimi-dsh/dist/errors.js +0 -40
  253. package/plugins/kimi-dsh/dist/git.js +0 -224
  254. package/plugins/kimi-dsh/dist/help.js +0 -43
  255. package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
  256. package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -104
  257. package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -233
  258. package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -665
  259. package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
  260. package/plugins/kimi-dsh/dist/hooks/install.js +0 -210
  261. package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -684
  262. package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
  263. package/plugins/kimi-dsh/dist/job-id.js +0 -12
  264. package/plugins/kimi-dsh/dist/job-store.js +0 -659
  265. package/plugins/kimi-dsh/dist/jobs.js +0 -217
  266. package/plugins/kimi-dsh/dist/kimi-command.js +0 -71
  267. package/plugins/kimi-dsh/dist/kimi-engine.js +0 -675
  268. package/plugins/kimi-dsh/dist/kimi-errors.js +0 -260
  269. package/plugins/kimi-dsh/dist/kimi-home.js +0 -9
  270. package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
  271. package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -234
  272. package/plugins/kimi-dsh/dist/logging.js +0 -22
  273. package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
  274. package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -345
  275. package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -257
  276. package/plugins/kimi-dsh/dist/mcp/operations.js +0 -301
  277. package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -275
  278. package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
  279. package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -78
  280. package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
  281. package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
  282. package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
  283. package/plugins/kimi-dsh/dist/model-command.js +0 -32
  284. package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -525
  285. package/plugins/kimi-dsh/dist/package.json +0 -1
  286. package/plugins/kimi-dsh/dist/parsing.js +0 -620
  287. package/plugins/kimi-dsh/dist/paths.js +0 -27
  288. package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
  289. package/plugins/kimi-dsh/dist/process-tree.js +0 -586
  290. package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
  291. package/plugins/kimi-dsh/dist/render.js +0 -177
  292. package/plugins/kimi-dsh/dist/rescue-approval.js +0 -865
  293. package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -43
  294. package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
  295. package/plugins/kimi-dsh/dist/session-title.js +0 -293
  296. package/plugins/kimi-dsh/dist/stream-json.js +0 -346
  297. package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1197
  298. package/plugins/kimi-dsh/dist/swarm-policy.js +0 -73
  299. package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -165
  300. package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
  301. package/plugins/kimi-dsh/dist/types.js +0 -1
  302. package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
  303. package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
  304. package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
  305. package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
  306. package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
  307. package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
  308. package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
  309. package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
  310. package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
  311. package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
  312. package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
  313. package/plugins/kimi-dsh/dist/version.js +0 -7
  314. package/plugins/kimi-dsh/package.json +0 -78
  315. package/plugins/kimi-dsh/scripts/companion.sh +0 -37
  316. package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
  317. package/scripts/review-gate-hook.sh +0 -32
@@ -1,242 +1,430 @@
1
1
  import { RuntimeError } from "../errors.js";
2
- import { parseDurationMs, validateThinkingEffort } from "../parsing.js";
2
+ import { kimiVersionsWith } from "../kimi-releases.js";
3
+ import { MAX_SESSION_REFERENCES, parseDurationMs, SESSION_REFERENCE_ID_MAX, validateThinkingEffort } from "../parsing.js";
4
+ const DEFAULT_WAIT_TIMEOUT_MIN_MS = 1_000;
5
+ const MAX_WAIT_TIMEOUT_MS = 86_400_000;
3
6
  const WORKSPACE_PROPERTY = {
4
7
  type: "string",
5
- description: "Absolute workspace directory. Required when the host does not configure a default; Codex normally supplies it explicitly.",
8
+ description: "Absolute workspace directory. Required when the host does not configure a default.",
6
9
  };
7
10
  const MODEL_PROPERTY = {
8
11
  type: "string",
9
- description: "One configured Kimi model alias. Omit to preserve the normal session default; never guess an alias.",
12
+ description: "Configured Kimi model alias. Omit to use the default model; never guess an alias.",
10
13
  };
11
14
  const THINKING_PROPERTY = {
12
15
  type: "string",
13
- description: "Per-run thinking-effort request such as off, low, medium, or high. Provider/model support varies and is not observable by the plugin.",
16
+ description: "Per-run thinking-effort request (off, low, medium, high). Not observable on the wire.",
14
17
  };
15
18
  const BUDGET_PROPERTY = {
16
19
  type: "string",
17
- description: "Finite duration such as 30m, 1h, or 90s; bare numbers mean minutes. Maximum 24h. Background operation does not extend it.",
20
+ description: "Finite duration such as 30m, 1h, or 90s; bare numbers mean minutes. Maximum 24h.",
21
+ };
22
+ const WAIT_PROPERTIES = {
23
+ wait: {
24
+ type: "boolean",
25
+ description: "Wait for completion and return the result directly (default true on standard calls; set false to get job_id immediately for parallel fan-out).",
26
+ },
27
+ wait_timeout_ms: {
28
+ type: "integer",
29
+ minimum: DEFAULT_WAIT_TIMEOUT_MIN_MS,
30
+ maximum: MAX_WAIT_TIMEOUT_MS,
31
+ description: "Maximum milliseconds this call waits before returning a running handle (job keeps running in background; poll with kimi_job).",
32
+ },
33
+ };
34
+ const REFERENCE_PROPERTIES = {
35
+ referenced_sessions: {
36
+ type: "array",
37
+ items: { type: "string" },
38
+ description: "Up to 8 earlier job IDs or Kimi session IDs whose main logs Kimi may consult.",
39
+ },
18
40
  };
19
41
  const COMMON_PROPERTIES = {
20
42
  workspace: WORKSPACE_PROPERTY,
21
43
  model: MODEL_PROPERTY,
22
44
  thinking: THINKING_PROPERTY,
23
45
  budget: BUDGET_PROPERTY,
46
+ ...WAIT_PROPERTIES,
24
47
  };
25
- const RESUME_PROPERTIES = {
26
- fresh: {
48
+ const READ_SCHEMA = schema({
49
+ mode: {
50
+ type: "string",
51
+ enum: ["ask", "review", "challenge", "swarm"],
52
+ description: "ask (default): explain/investigate; review: defect review of diff; challenge: adversarial design critique; swarm: read-only parallel fan-out.",
53
+ },
54
+ prompt: {
55
+ type: "string",
56
+ description: "User question, review focus, or swarm objective, preserved verbatim. Required for ask (unless resume is set) and swarm.",
57
+ },
58
+ ...COMMON_PROPERTIES,
59
+ base: {
60
+ type: "string",
61
+ description: "Git base ref for review/challenge (committed branch diff; incompatible with uncommitted=true).",
62
+ },
63
+ uncommitted: {
27
64
  type: "boolean",
28
- description: "Start a fresh Kimi session. Incompatible with resume and resume_latest.",
65
+ description: "Review uncommitted/untracked working-tree changes (default for review/challenge; incompatible with base).",
29
66
  },
30
67
  resume: {
31
68
  type: "string",
32
- description: "Resume this job ID or Kimi session ID with the standard continuation instruction. Do not also supply prompt.",
69
+ description: "Resume session for ask: \"last\" (latest repo session, may pair with prompt) or a job/session ID (no prompt).",
70
+ },
71
+ read_roots: {
72
+ type: "array",
73
+ items: { type: "string" },
74
+ description: "Additional absolute directories Kimi may read outside workspace.",
33
75
  },
34
- resume_latest: {
76
+ network: {
35
77
  type: "boolean",
36
- description: "Resume the latest matching session for this repository. May be combined with a new prompt.",
78
+ description: "Enable web search and URL fetch (file reads remain confined to workspace + read_roots). Default false.",
37
79
  },
38
- };
39
- const PROMPT_PROPERTY = {
40
- type: "string",
41
- description: "The complete user request, preserved verbatim. Required except when resume or resume_latest supplies the continuation context.",
42
- };
43
- const OBJECTIVE_PROPERTY = {
44
- type: "string",
45
- description: "The complete objective, preserved verbatim.",
46
- };
47
- const FOCUS_PROPERTY = {
48
- type: "string",
49
- description: "Optional review focus or adversarial framing, preserved verbatim.",
50
- };
51
- const BASE_PROPERTY = {
52
- type: "string",
53
- description: "Optional Git base ref. The committed branch diff is authoritative; dirty current files are not treated as committed snapshots.",
54
- };
55
- const TURNS_PROPERTY = {
56
- type: "integer",
57
- minimum: 1,
58
- description: "Soft turn-count hint included in the objective. The finite budget is the hard bound.",
59
- };
60
- const CAP_PROPERTY = {
61
- type: "integer",
62
- minimum: 1,
63
- description: "Soft hint for total subagent count, not a hook-enforced limit.",
64
- };
65
- const MAX_CONCURRENCY_PROPERTY = {
66
- type: "integer",
67
- minimum: 1,
68
- description: "Concurrent worker limit on exact Kimi Code 2.6.2/2.6.3/2.7.2/2.7.3: one runs directly; larger values bound each native swarm wave. Older certified versions limit normal launches only and recovery can exceed it. Distinct from the soft total cap.",
69
- };
70
- const START_RESULT_GUIDANCE = "Task-capable clients receive an MCP task. Other clients receive a job ID immediately after launch; use kimi_job_status and kimi_job_result until terminal, and kimi_job_cancel to stop. Do not present a launch handle as the finished answer.";
71
- function schema(properties, required = []) {
72
- return { type: "object", properties, required, additionalProperties: false };
73
- }
74
- const OPERATION_SPECS = {
75
- kimi_ask: {
76
- kind: "ask",
77
- command: ["ask"],
78
- write: false,
79
- summary: "Start an independent read-only Kimi repository explanation.",
80
- inputSchema: schema({ ...COMMON_PROPERTIES, prompt: PROMPT_PROPERTY, ...RESUME_PROPERTIES }),
80
+ cap: {
81
+ type: "integer",
82
+ minimum: 1,
83
+ maximum: 25,
84
+ description: "Soft hint for total swarm subagent count.",
81
85
  },
82
- kimi_review: {
83
- kind: "review",
84
- command: ["review"],
85
- write: false,
86
- summary: "Start an independent read-only Kimi review of working-tree changes, including untracked files, or a committed base diff.",
87
- inputSchema: schema({ ...COMMON_PROPERTIES, base: BASE_PROPERTY, focus: FOCUS_PROPERTY }),
86
+ max_concurrency: {
87
+ type: "integer",
88
+ minimum: 1,
89
+ maximum: 16,
90
+ description: `Maximum simultaneous swarm workers on Kimi Code ${kimiVersionsWith("bounded-swarm").join("/")}+ (1 runs directly).`,
88
91
  },
89
- kimi_challenge: {
90
- kind: "challenge",
91
- command: ["task", "challenge"],
92
- write: false,
93
- summary: "Start a read-only Kimi challenge of assumptions, design choices, and tradeoffs rather than a defect-only review.",
94
- inputSchema: schema({ ...COMMON_PROPERTIES, base: BASE_PROPERTY, focus: FOCUS_PROPERTY }),
92
+ ...REFERENCE_PROPERTIES,
93
+ });
94
+ const WRITE_SCHEMA = schema({
95
+ mode: {
96
+ type: "string",
97
+ enum: ["rescue", "pursue", "swarm_patch"],
98
+ description: "rescue (default): bounded workspace edit/fix; pursue: autonomous multi-turn goal; swarm_patch: parallel edits in isolated worktree returning a git patch without modifying the real tree.",
95
99
  },
96
- kimi_rescue: {
97
- kind: "rescue",
98
- command: ["task", "rescue"],
99
- write: true,
100
- summary: "Start a bounded write-capable Kimi investigation or fix inside the validated workspace. Review the resulting changes; no commit is made.",
101
- inputSchema: schema({ ...COMMON_PROPERTIES, prompt: PROMPT_PROPERTY, ...RESUME_PROPERTIES }),
100
+ prompt: {
101
+ type: "string",
102
+ description: "Task objective or edit instruction, preserved verbatim. Never mutates Git.",
102
103
  },
103
- kimi_pursue: {
104
- kind: "pursue",
105
- command: ["task", "pursue"],
106
- write: true,
107
- summary: "Start explicitly autonomous Kimi goal mode with a finite hard budget and workspace write limits. Use only for hands-off objectives, not a single bounded fix.",
108
- inputSchema: schema({ ...COMMON_PROPERTIES, objective: OBJECTIVE_PROPERTY, turns: TURNS_PROPERTY }, ["objective"]),
104
+ ...COMMON_PROPERTIES,
105
+ resume: {
106
+ type: "string",
107
+ description: "Resume session for rescue: \"last\" or a job/session ID.",
109
108
  },
110
- kimi_swarm: {
111
- kind: "swarm",
112
- command: ["task", "swarm"],
113
- write: false,
114
- summary: "Start a read-only parallel Kimi fan-out across many independent review targets.",
115
- inputSchema: schema({ ...COMMON_PROPERTIES, objective: OBJECTIVE_PROPERTY, cap: CAP_PROPERTY, max_concurrency: MAX_CONCURRENCY_PROPERTY }, ["objective"]),
109
+ cap: {
110
+ type: "integer",
111
+ minimum: 1,
112
+ maximum: 25,
113
+ description: "Soft hint for total swarm_patch subagent count.",
116
114
  },
117
- kimi_swarm_write: {
118
- kind: "swarm-write",
119
- command: ["task", "swarm"],
120
- write: true,
121
- summary: "Start parallel Kimi implementation in a disposable worktree off HEAD. The real tree is not edited; the result is a patch to review and apply separately.",
122
- inputSchema: schema({ ...COMMON_PROPERTIES, objective: OBJECTIVE_PROPERTY, cap: CAP_PROPERTY, max_concurrency: MAX_CONCURRENCY_PROPERTY }, ["objective"]),
115
+ max_concurrency: {
116
+ type: "integer",
117
+ minimum: 1,
118
+ maximum: 16,
119
+ description: "Maximum simultaneous swarm_patch workers (default 1 runs directly).",
120
+ },
121
+ ...REFERENCE_PROPERTIES,
122
+ });
123
+ const JOB_SCHEMA = schema({
124
+ action: {
125
+ type: "string",
126
+ enum: ["list", "status", "result", "wait", "cancel", "replay", "recover_swarm"],
127
+ description: "Job lifecycle action to run in this workspace.",
128
+ },
129
+ job_id: {
130
+ type: "string",
131
+ description: "Job UUID. Required for replay and recover_swarm; optional for status/result/wait/cancel (defaults to latest repo job).",
123
132
  },
124
- };
125
- const JOB_CONTROL_SCHEMA = schema({
126
133
  workspace: WORKSPACE_PROPERTY,
127
- job_id: { type: "string", description: "The UUID returned by an MCP-launched Kimi operation." },
128
- }, ["job_id"]);
134
+ status_filter: {
135
+ type: "string",
136
+ enum: ["running", "completed", "failed", "cancelled"],
137
+ description: "Filter jobs returned by action=list.",
138
+ },
139
+ limit: {
140
+ type: "integer",
141
+ minimum: 1,
142
+ maximum: 100,
143
+ description: "Maximum jobs to return for action=list (default 20).",
144
+ },
145
+ wait_ms: {
146
+ type: "integer",
147
+ minimum: 100,
148
+ maximum: 600_000,
149
+ description: "Poll duration in ms for action=wait (default 30000).",
150
+ },
151
+ apply: {
152
+ type: "boolean",
153
+ description: "Apply cleanup and patch capture during recover_swarm (default false previews only).",
154
+ },
155
+ }, ["action"]);
156
+ const SETUP_SCHEMA = schema({
157
+ action: {
158
+ type: "string",
159
+ enum: ["check", "models", "install", "install_kimi", "repair_sessions"],
160
+ description: "check (default): verify PreToolUse hook & binary; models: list configured model aliases; install: write/repair hook; install_kimi: install newest certified CLI; repair_sessions: preview/repair Kimi session titles.",
161
+ },
162
+ workspace: WORKSPACE_PROPERTY,
163
+ apply: {
164
+ type: "boolean",
165
+ description: "Write repaired session previews during repair_sessions (default false previews only).",
166
+ },
167
+ all: {
168
+ type: "boolean",
169
+ description: "Scope repair_sessions across all repositories.",
170
+ },
171
+ });
172
+ function schema(properties, required = []) {
173
+ return { type: "object", properties, required, additionalProperties: false };
174
+ }
129
175
  export const MCP_TOOL_DEFINITIONS = [
130
- ...Object.entries(OPERATION_SPECS).map(([name, spec]) => ({
131
- name: name,
132
- description: `${spec.summary} ${START_RESULT_GUIDANCE}`,
133
- inputSchema: spec.inputSchema,
176
+ {
177
+ name: "kimi_read",
178
+ description: "Run a read-only Kimi operation (ask, review, challenge, or parallel read-only swarm). Waits for prose by default on standard tool calls; set wait=false to return job_id immediately.",
179
+ inputSchema: READ_SCHEMA,
134
180
  annotations: {
135
- title: name.replaceAll("_", " "),
136
- readOnlyHint: !spec.write,
137
- destructiveHint: spec.write,
181
+ title: "kimi read",
182
+ readOnlyHint: true,
183
+ destructiveHint: false,
138
184
  idempotentHint: false,
139
185
  openWorldHint: true,
140
186
  },
141
- })),
187
+ },
142
188
  {
143
- name: "kimi_job_status",
144
- description: "Read one MCP-launched job's durable state and phase in the same workspace. This is always an ordinary MCP result, never a task.",
145
- inputSchema: JOB_CONTROL_SCHEMA,
146
- annotations: { title: "kimi job status", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
189
+ name: "kimi_write",
190
+ description: "Run a workspace-confined write operation: rescue (single-turn edit/test), pursue (autonomous multi-turn goal), or swarm_patch (isolated worktree producing a git patch without modifying the working tree).",
191
+ inputSchema: WRITE_SCHEMA,
192
+ annotations: {
193
+ title: "kimi write",
194
+ readOnlyHint: false,
195
+ destructiveHint: true,
196
+ idempotentHint: false,
197
+ openWorldHint: true,
198
+ },
147
199
  },
148
200
  {
149
- name: "kimi_job_result",
150
- description: "Read the terminal artifact for one MCP-launched job in the same workspace. Failed jobs return isError:true with their artifact; running jobs return JOB_NOT_TERMINAL without changing state.",
151
- inputSchema: JOB_CONTROL_SCHEMA,
152
- annotations: { title: "kimi job result", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
201
+ name: "kimi_job",
202
+ description: "Inspect, await, cancel, replay, or recover Kimi jobs in the workspace.",
203
+ inputSchema: JOB_SCHEMA,
204
+ annotations: {
205
+ title: "kimi job",
206
+ readOnlyHint: false,
207
+ destructiveHint: false,
208
+ idempotentHint: false,
209
+ openWorldHint: false,
210
+ },
153
211
  },
154
212
  {
155
- name: "kimi_job_cancel",
156
- description: "Cooperatively cancel one running MCP-launched job in the same workspace. Terminal jobs are a no-op. Cancellation does not roll back edits, and write-swarm still captures its patch before cleanup.",
157
- inputSchema: JOB_CONTROL_SCHEMA,
158
- annotations: { title: "kimi job cancel", readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
213
+ name: "kimi_setup",
214
+ description: "Verify or install the Kimi PreToolUse safety hook, list configured models, install a certified Kimi CLI binary, or repair session titles.",
215
+ inputSchema: SETUP_SCHEMA,
216
+ annotations: {
217
+ title: "kimi setup",
218
+ readOnlyHint: false,
219
+ destructiveHint: false,
220
+ idempotentHint: true,
221
+ openWorldHint: true,
222
+ },
159
223
  },
160
224
  ];
161
225
  export function isMcpModelToolName(name) {
162
- return Object.hasOwn(OPERATION_SPECS, name);
226
+ return name === "kimi_read" || name === "kimi_write";
163
227
  }
164
228
  export function buildMcpOperationInvocation(name, input) {
165
- const spec = OPERATION_SPECS[name];
166
- const properties = spec.inputSchema.properties;
167
- const args = readArguments(input, Object.keys(properties));
229
+ const allowedKeys = Object.keys((name === "kimi_read" ? READ_SCHEMA : WRITE_SCHEMA).properties);
230
+ const args = readArguments(input, allowedKeys);
168
231
  const workspace = optionalString(args, "workspace");
169
- const argv = [...spec.command];
170
- appendCommonOptions(argv, args, spec.kind === "pursue" || spec.kind === "swarm" || spec.kind === "swarm-write" ? "safety" : "response");
171
- switch (spec.kind) {
172
- case "ask":
173
- case "rescue": {
174
- const prompt = args.prompt === undefined ? undefined : requiredNonEmptyString(args, "prompt");
175
- const fresh = optionalBoolean(args, "fresh") ?? false;
176
- const resumeLatest = optionalBoolean(args, "resume_latest") ?? false;
177
- const resume = args.resume === undefined ? undefined : requiredNonEmptyString(args, "resume");
178
- if (fresh && (resumeLatest || resume !== undefined)) {
179
- throw invalidArguments("fresh cannot be combined with resume or resume_latest.");
180
- }
181
- if (resumeLatest && resume !== undefined) {
182
- throw invalidArguments("resume and resume_latest are alternatives; choose one.");
232
+ const wait = optionalBoolean(args, "wait") ?? true;
233
+ const waitTimeoutMs = optionalBoundedInteger(args, "wait_timeout_ms", DEFAULT_WAIT_TIMEOUT_MIN_MS, MAX_WAIT_TIMEOUT_MS);
234
+ if (name === "kimi_read") {
235
+ const mode = readMode(args);
236
+ const kind = mode;
237
+ const argv = mode === "ask" ? ["ask"] : mode === "review" ? ["review"] : ["task", mode];
238
+ appendCommonOptions(argv, args, mode === "swarm" ? "safety" : "response");
239
+ appendScopeOptions(argv, args);
240
+ appendReferenceOptions(argv, args);
241
+ const base = args.base === undefined ? undefined : requiredNonEmptyString(args, "base");
242
+ const uncommitted = optionalBoolean(args, "uncommitted");
243
+ const resume = args.resume === undefined ? undefined : requiredNonEmptyString(args, "resume");
244
+ const cap = optionalBoundedInteger(args, "cap", 1, 25);
245
+ const maxConcurrency = optionalBoundedInteger(args, "max_concurrency", 1, 16);
246
+ const prompt = optionalString(args, "prompt");
247
+ if (mode !== "review" && mode !== "challenge" && (base !== undefined || uncommitted !== undefined)) {
248
+ throw invalidArguments(`base and uncommitted are only valid for mode "review" or "challenge" (got ${mode}).`);
249
+ }
250
+ if (base !== undefined && uncommitted === true) {
251
+ throw invalidArguments("base and uncommitted=true are mutually exclusive.");
252
+ }
253
+ if ((mode === "review" || mode === "challenge") && uncommitted === false && base === undefined) {
254
+ throw invalidArguments('uncommitted=false requires a base ref for mode "review" or "challenge".');
255
+ }
256
+ if (mode !== "ask" && resume !== undefined) {
257
+ throw invalidArguments(`resume is only valid for mode "ask" (got ${mode}).`);
258
+ }
259
+ if (mode !== "swarm" && (cap !== undefined || maxConcurrency !== undefined)) {
260
+ throw invalidArguments(`cap and max_concurrency are only valid for mode "swarm" (got ${mode}).`);
261
+ }
262
+ switch (mode) {
263
+ case "ask": {
264
+ const cleanPrompt = prompt === undefined ? undefined : requiredNonEmptyString(args, "prompt");
265
+ if (resume === "last") {
266
+ argv.push("-r");
267
+ if (cleanPrompt !== undefined)
268
+ argv.push("--", cleanPrompt);
269
+ }
270
+ else if (resume !== undefined) {
271
+ if (cleanPrompt !== undefined) {
272
+ throw invalidArguments('resume with a job/session ID uses the continuation prompt and cannot include prompt; use resume="last" to pair with a new prompt.');
273
+ }
274
+ argv.push("--resume", resume);
275
+ }
276
+ else {
277
+ argv.push("--", requiredNonEmptyString(args, "prompt"));
278
+ }
279
+ break;
183
280
  }
184
- if (resume !== undefined && prompt !== undefined) {
185
- throw invalidArguments("resume uses the standard continuation instruction and cannot include prompt. Use resume_latest with a new prompt instead.");
281
+ case "review":
282
+ case "challenge": {
283
+ if (base !== undefined)
284
+ argv.push("--base", base);
285
+ if (prompt !== undefined && prompt.trim().length > 0)
286
+ argv.push("--", prompt);
287
+ break;
186
288
  }
187
- if (prompt === undefined && !resumeLatest && resume === undefined) {
188
- throw invalidArguments(`${spec.kind} requires prompt unless resume or resume_latest is selected.`);
289
+ case "swarm": {
290
+ if (cap !== undefined)
291
+ argv.push("--cap", String(cap));
292
+ if (maxConcurrency !== undefined)
293
+ argv.push("--max-concurrency", String(maxConcurrency));
294
+ argv.push("--", requiredNonEmptyString(args, "prompt"));
295
+ break;
189
296
  }
190
- if (fresh)
191
- argv.push("--fresh");
192
- if (resumeLatest)
193
- argv.push("-r");
194
- if (resume !== undefined)
195
- argv.push("--resume", resume);
196
- if (prompt !== undefined)
197
- argv.push("--", prompt);
198
- break;
199
297
  }
200
- case "review":
201
- case "challenge": {
202
- const base = args.base === undefined ? undefined : requiredNonEmptyString(args, "base");
203
- const focus = optionalString(args, "focus");
204
- if (base !== undefined)
205
- argv.push("--base", base);
206
- if (focus !== undefined)
207
- argv.push("--", focus);
208
- break;
298
+ return {
299
+ operationKind: kind,
300
+ ...(workspace !== undefined ? { workspace } : {}),
301
+ wait,
302
+ ...(waitTimeoutMs !== undefined ? { waitTimeoutMs } : {}),
303
+ argv,
304
+ };
305
+ }
306
+ // kimi_write
307
+ const mode = writeMode(args);
308
+ const kind = mode === "swarm_patch" ? "swarm-write" : mode;
309
+ const argv = mode === "swarm_patch" ? ["task", "swarm"] : ["task", mode];
310
+ appendCommonOptions(argv, args, mode === "rescue" ? "response" : "safety");
311
+ const resume = args.resume === undefined ? undefined : requiredNonEmptyString(args, "resume");
312
+ const cap = optionalBoundedInteger(args, "cap", 1, 25);
313
+ const maxConcurrency = optionalBoundedInteger(args, "max_concurrency", 1, 16);
314
+ const prompt = optionalString(args, "prompt");
315
+ if (mode === "pursue" && args.referenced_sessions !== undefined) {
316
+ throw invalidArguments('referenced_sessions is not supported for mode "pursue".');
317
+ }
318
+ appendReferenceOptions(argv, args);
319
+ if (mode !== "rescue" && resume !== undefined) {
320
+ throw invalidArguments(`resume is only valid for mode "rescue" (got ${mode}).`);
321
+ }
322
+ if (mode !== "swarm_patch" && (cap !== undefined || maxConcurrency !== undefined)) {
323
+ throw invalidArguments(`cap and max_concurrency are only valid for mode "swarm_patch" (got ${mode}).`);
324
+ }
325
+ if (mode === "rescue") {
326
+ const cleanPrompt = prompt === undefined ? undefined : requiredNonEmptyString(args, "prompt");
327
+ if (resume === "last") {
328
+ argv.push("-r");
329
+ if (cleanPrompt !== undefined)
330
+ argv.push("--", cleanPrompt);
209
331
  }
210
- case "pursue": {
211
- const turns = optionalPositiveInteger(args, "turns");
212
- if (turns !== undefined)
213
- argv.push("--turns", String(turns));
214
- argv.push("--", requiredNonEmptyString(args, "objective"));
215
- break;
332
+ else if (resume !== undefined) {
333
+ if (cleanPrompt !== undefined) {
334
+ throw invalidArguments('resume with a job/session ID cannot include prompt; use resume="last" to pair with a new prompt.');
335
+ }
336
+ argv.push("--resume", resume);
216
337
  }
217
- case "swarm":
218
- case "swarm-write": {
219
- const cap = optionalPositiveInteger(args, "cap");
220
- const maxConcurrency = optionalPositiveInteger(args, "max_concurrency");
221
- if (cap !== undefined)
222
- argv.push("--cap", String(cap));
223
- if (maxConcurrency !== undefined)
224
- argv.push("--max-concurrency", String(maxConcurrency));
225
- if (spec.kind === "swarm-write")
226
- argv.push("--write");
227
- argv.push("--", requiredNonEmptyString(args, "objective"));
228
- break;
338
+ else {
339
+ argv.push("--fresh", "--", requiredNonEmptyString(args, "prompt"));
229
340
  }
230
341
  }
231
- return { operationKind: spec.kind, ...(workspace !== undefined ? { workspace } : {}), argv };
342
+ else if (mode === "pursue") {
343
+ argv.push("--", requiredNonEmptyString(args, "prompt"));
344
+ }
345
+ else {
346
+ if (cap !== undefined)
347
+ argv.push("--cap", String(cap));
348
+ if (maxConcurrency !== undefined)
349
+ argv.push("--max-concurrency", String(maxConcurrency));
350
+ argv.push("--write", "--", requiredNonEmptyString(args, "prompt"));
351
+ }
352
+ return {
353
+ operationKind: kind,
354
+ ...(workspace !== undefined ? { workspace } : {}),
355
+ wait,
356
+ ...(waitTimeoutMs !== undefined ? { waitTimeoutMs } : {}),
357
+ argv,
358
+ };
232
359
  }
233
360
  export function readJobControlArguments(input) {
234
- const args = readArguments(input, ["workspace", "job_id"]);
361
+ const args = readArguments(input, Object.keys(JOB_SCHEMA.properties));
362
+ const action = requiredEnum(args, "action", ["list", "status", "result", "wait", "cancel", "replay", "recover_swarm"]);
363
+ const workspace = optionalString(args, "workspace");
364
+ const jobId = args.job_id === undefined ? undefined : requiredNonEmptyString(args, "job_id");
365
+ const statusFilter = args.status_filter === undefined
366
+ ? undefined
367
+ : requiredEnum(args, "status_filter", ["running", "completed", "failed", "cancelled"]);
368
+ const limit = optionalBoundedInteger(args, "limit", 1, 100);
369
+ const waitMs = optionalBoundedInteger(args, "wait_ms", 100, 600_000);
370
+ const apply = optionalBoolean(args, "apply");
371
+ if (action !== "list" && (statusFilter !== undefined || limit !== undefined)) {
372
+ throw invalidArguments('status_filter and limit are only valid for action "list".');
373
+ }
374
+ if (action !== "wait" && waitMs !== undefined) {
375
+ throw invalidArguments('wait_ms is only valid for action "wait".');
376
+ }
377
+ if (action !== "recover_swarm" && apply !== undefined) {
378
+ throw invalidArguments('apply is only valid for action "recover_swarm".');
379
+ }
380
+ if ((action === "replay" || action === "recover_swarm") && jobId === undefined) {
381
+ throw invalidArguments(`job_id is required for action "${action}".`);
382
+ }
235
383
  return {
236
- ...(optionalString(args, "workspace") !== undefined ? { workspace: optionalString(args, "workspace") } : {}),
237
- jobId: requiredNonEmptyString(args, "job_id"),
384
+ action,
385
+ ...(workspace !== undefined ? { workspace } : {}),
386
+ ...(jobId !== undefined ? { jobId } : {}),
387
+ ...(statusFilter !== undefined ? { statusFilter } : {}),
388
+ ...(limit !== undefined ? { limit } : {}),
389
+ ...(waitMs !== undefined ? { waitMs } : {}),
390
+ ...(apply !== undefined ? { apply } : {}),
238
391
  };
239
392
  }
393
+ export function readSetupArguments(input) {
394
+ const args = readArguments(input, Object.keys(SETUP_SCHEMA.properties));
395
+ const actionRaw = optionalString(args, "action") ?? "check";
396
+ const validActions = ["check", "models", "install", "install_kimi", "repair_sessions"];
397
+ if (!validActions.includes(actionRaw)) {
398
+ throw invalidArguments(`action must be one of ${validActions.join(", ")}.`);
399
+ }
400
+ const action = actionRaw;
401
+ const workspace = optionalString(args, "workspace");
402
+ const apply = optionalBoolean(args, "apply");
403
+ const all = optionalBoolean(args, "all");
404
+ if (action !== "repair_sessions" && (apply !== undefined || all !== undefined)) {
405
+ throw invalidArguments('apply and all are only valid for action "repair_sessions".');
406
+ }
407
+ return {
408
+ action,
409
+ ...(workspace !== undefined ? { workspace } : {}),
410
+ ...(apply !== undefined ? { apply } : {}),
411
+ ...(all !== undefined ? { all } : {}),
412
+ };
413
+ }
414
+ function readMode(args) {
415
+ const raw = optionalString(args, "mode") ?? "ask";
416
+ if (raw !== "ask" && raw !== "review" && raw !== "challenge" && raw !== "swarm") {
417
+ throw invalidArguments('kimi_read mode must be one of "ask", "review", "challenge", "swarm".');
418
+ }
419
+ return raw;
420
+ }
421
+ function writeMode(args) {
422
+ const raw = optionalString(args, "mode") ?? "rescue";
423
+ if (raw !== "rescue" && raw !== "pursue" && raw !== "swarm_patch") {
424
+ throw invalidArguments('kimi_write mode must be one of "rescue", "pursue", "swarm_patch".');
425
+ }
426
+ return raw;
427
+ }
240
428
  function appendCommonOptions(argv, args, budgetKind) {
241
429
  const budget = optionalString(args, "budget");
242
430
  const model = optionalString(args, "model");
@@ -252,6 +440,36 @@ function appendCommonOptions(argv, args, budgetKind) {
252
440
  argv.push("--thinking", thinking);
253
441
  }
254
442
  }
443
+ /** Type checks only: the companion parser and read-scope resolver own every scope rule. */
444
+ function appendScopeOptions(argv, args) {
445
+ const readRoots = args.read_roots;
446
+ if (readRoots !== undefined) {
447
+ if (!Array.isArray(readRoots) || readRoots.some((root) => typeof root !== "string")) {
448
+ throw invalidArguments("read_roots must be an array of strings.");
449
+ }
450
+ for (const root of readRoots)
451
+ argv.push("--read-root", root);
452
+ }
453
+ if (optionalBoolean(args, "network") === true)
454
+ argv.push("--network");
455
+ }
456
+ function appendReferenceOptions(argv, args) {
457
+ const references = args.referenced_sessions;
458
+ if (references === undefined)
459
+ return;
460
+ if (!Array.isArray(references) || references.some((reference) => typeof reference !== "string")) {
461
+ throw invalidArguments("referenced_sessions must be an array of strings.");
462
+ }
463
+ const unique = [...new Set(references)];
464
+ if (unique.length > MAX_SESSION_REFERENCES) {
465
+ throw invalidArguments(`referenced_sessions accepts at most ${MAX_SESSION_REFERENCES} distinct sessions; got ${unique.length}.`);
466
+ }
467
+ if (unique.some((reference) => reference.length > SESSION_REFERENCE_ID_MAX)) {
468
+ throw invalidArguments(`referenced_sessions ids are at most ${SESSION_REFERENCE_ID_MAX} characters.`);
469
+ }
470
+ for (const reference of unique)
471
+ argv.push("--reference-session", reference);
472
+ }
255
473
  function readArguments(input, allowedKeys) {
256
474
  if (input === undefined)
257
475
  return {};
@@ -266,6 +484,13 @@ function readArguments(input, allowedKeys) {
266
484
  }
267
485
  return args;
268
486
  }
487
+ function requiredEnum(args, key, values) {
488
+ const value = args[key];
489
+ if (typeof value !== "string" || !values.includes(value)) {
490
+ throw invalidArguments(`${key} must be one of ${values.join(", ")}.`);
491
+ }
492
+ return value;
493
+ }
269
494
  function optionalString(args, key) {
270
495
  const value = args[key];
271
496
  if (value === undefined)
@@ -288,12 +513,13 @@ function optionalBoolean(args, key) {
288
513
  throw invalidArguments(`${key} must be a boolean.`);
289
514
  return value;
290
515
  }
291
- function optionalPositiveInteger(args, key) {
516
+ function optionalBoundedInteger(args, key, min, max) {
292
517
  const value = args[key];
293
518
  if (value === undefined)
294
519
  return undefined;
295
- if (!Number.isSafeInteger(value) || value <= 0)
296
- throw invalidArguments(`${key} must be a positive safe integer.`);
520
+ if (!Number.isSafeInteger(value) || value < min || value > max) {
521
+ throw invalidArguments(`${key} must be an integer between ${min} and ${max}.`);
522
+ }
297
523
  return value;
298
524
  }
299
525
  function invalidArguments(message) {