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,255 +1,430 @@
1
1
  import { RuntimeError } from "../errors.js";
2
2
  import { kimiVersionsWith } from "../kimi-releases.js";
3
- import { parseDurationMs, validateThinkingEffort } from "../parsing.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;
4
6
  const WORKSPACE_PROPERTY = {
5
7
  type: "string",
6
- 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.",
7
9
  };
8
10
  const MODEL_PROPERTY = {
9
11
  type: "string",
10
- 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.",
11
13
  };
12
14
  const THINKING_PROPERTY = {
13
15
  type: "string",
14
- 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.",
15
17
  };
16
18
  const BUDGET_PROPERTY = {
17
19
  type: "string",
18
- 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
+ },
19
40
  };
20
41
  const COMMON_PROPERTIES = {
21
42
  workspace: WORKSPACE_PROPERTY,
22
43
  model: MODEL_PROPERTY,
23
44
  thinking: THINKING_PROPERTY,
24
45
  budget: BUDGET_PROPERTY,
46
+ ...WAIT_PROPERTIES,
25
47
  };
26
- const RESUME_PROPERTIES = {
27
- fresh: {
28
- type: "boolean",
29
- description: "Start a fresh Kimi session. Incompatible with resume and resume_latest.",
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.",
30
53
  },
31
- resume: {
54
+ prompt: {
32
55
  type: "string",
33
- description: "Resume this job ID or Kimi session ID with the standard continuation instruction. Do not also supply prompt.",
56
+ description: "User question, review focus, or swarm objective, preserved verbatim. Required for ask (unless resume is set) and swarm.",
34
57
  },
35
- resume_latest: {
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: {
36
64
  type: "boolean",
37
- description: "Resume the latest matching session for this repository. May be combined with a new prompt.",
65
+ description: "Review uncommitted/untracked working-tree changes (default for review/challenge; incompatible with base).",
66
+ },
67
+ resume: {
68
+ type: "string",
69
+ description: "Resume session for ask: \"last\" (latest repo session, may pair with prompt) or a job/session ID (no prompt).",
38
70
  },
39
- };
40
- const PROMPT_PROPERTY = {
41
- type: "string",
42
- description: "The complete user request, preserved verbatim. Required except when resume or resume_latest supplies the continuation context.",
43
- };
44
- const OBJECTIVE_PROPERTY = {
45
- type: "string",
46
- description: "The complete objective, preserved verbatim.",
47
- };
48
- const SCOPE_PROPERTIES = {
49
71
  read_roots: {
50
72
  type: "array",
51
73
  items: { type: "string" },
52
- description: "Absolute directories Kimi may also read. Omit for the default read scope.",
74
+ description: "Additional absolute directories Kimi may read outside workspace.",
53
75
  },
54
76
  network: {
55
77
  type: "boolean",
56
- description: "Enable web search and URL fetch; file reads are then confined to the workspace plus read_roots. Default false.",
78
+ description: "Enable web search and URL fetch (file reads remain confined to workspace + read_roots). Default false.",
57
79
  },
58
- };
59
- const REVIEW_MODE_PROPERTY = {
60
- type: "string",
61
- enum: ["defects", "challenge"],
62
- description: "defects (default) reviews for bugs and regressions; challenge questions assumptions, design choices, and tradeoffs instead.",
63
- };
64
- const FOCUS_PROPERTY = {
65
- type: "string",
66
- description: "Optional review focus or adversarial framing, preserved verbatim.",
67
- };
68
- const BASE_PROPERTY = {
69
- type: "string",
70
- description: "Optional Git base ref. The committed branch diff is authoritative; dirty current files are not treated as committed snapshots.",
71
- };
72
- const TURNS_PROPERTY = {
73
- type: "integer",
74
- minimum: 1,
75
- description: "Soft turn-count hint included in the objective. The finite budget is the hard bound.",
76
- };
77
- const CAP_PROPERTY = {
78
- type: "integer",
79
- minimum: 1,
80
- description: "Soft hint for total subagent count, not a hook-enforced limit.",
81
- };
82
- const MAX_CONCURRENCY_PROPERTY = {
83
- type: "integer",
84
- minimum: 1,
85
- description: `Concurrent worker limit on exact Kimi Code ${kimiVersionsWith("bounded-swarm").join("/")}: 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.`,
86
- };
87
- 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.";
88
- function schema(properties, required = []) {
89
- return { type: "object", properties, required, additionalProperties: false };
90
- }
91
- const OPERATION_SPECS = {
92
- kimi_ask: {
93
- kind: "ask",
94
- command: ["ask"],
95
- write: false,
96
- summary: "Start an independent read-only Kimi repository explanation.",
97
- inputSchema: schema({ ...COMMON_PROPERTIES, ...SCOPE_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.",
85
+ },
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).`,
98
91
  },
99
- kimi_review: {
100
- kind: "review",
101
- command: ["review"],
102
- write: false,
103
- summary: "Start an independent read-only Kimi review of working-tree changes, including untracked files, or a committed base diff. Mode challenge questions the approach instead of hunting defects.",
104
- inputSchema: schema({ ...COMMON_PROPERTIES, ...SCOPE_PROPERTIES, mode: REVIEW_MODE_PROPERTY, 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.",
105
99
  },
106
- kimi_rescue: {
107
- kind: "rescue",
108
- command: ["task", "rescue"],
109
- write: true,
110
- summary: "Start a bounded write-capable Kimi investigation or fix inside the validated workspace. Review the resulting changes; no commit is made.",
111
- 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.",
112
103
  },
113
- kimi_pursue: {
114
- kind: "pursue",
115
- command: ["task", "pursue"],
116
- write: true,
117
- 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.",
118
- 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.",
119
108
  },
120
- kimi_swarm: {
121
- kind: "swarm",
122
- command: ["task", "swarm"],
123
- write: false,
124
- summary: "Start a read-only parallel Kimi fan-out across many independent review targets.",
125
- inputSchema: schema({ ...COMMON_PROPERTIES, ...SCOPE_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.",
126
114
  },
127
- kimi_swarm_write: {
128
- kind: "swarm-write",
129
- command: ["task", "swarm"],
130
- write: true,
131
- 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.",
132
- 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).",
132
+ },
133
+ workspace: WORKSPACE_PROPERTY,
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.",
133
161
  },
134
- };
135
- const JOB_CONTROL_SCHEMA = schema({
136
162
  workspace: WORKSPACE_PROPERTY,
137
- job_id: { type: "string", description: "The UUID returned by an MCP-launched Kimi operation." },
138
- }, ["job_id"]);
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
+ }
139
175
  export const MCP_TOOL_DEFINITIONS = [
140
- ...Object.entries(OPERATION_SPECS).map(([name, spec]) => ({
141
- name: name,
142
- description: `${spec.summary} ${START_RESULT_GUIDANCE}`,
143
- 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,
144
180
  annotations: {
145
- title: name.replaceAll("_", " "),
146
- readOnlyHint: !spec.write,
147
- destructiveHint: spec.write,
181
+ title: "kimi read",
182
+ readOnlyHint: true,
183
+ destructiveHint: false,
148
184
  idempotentHint: false,
149
185
  openWorldHint: true,
150
186
  },
151
- })),
187
+ },
152
188
  {
153
- name: "kimi_job_status",
154
- 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.",
155
- inputSchema: JOB_CONTROL_SCHEMA,
156
- 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
+ },
157
199
  },
158
200
  {
159
- name: "kimi_job_result",
160
- 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.",
161
- inputSchema: JOB_CONTROL_SCHEMA,
162
- 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
+ },
163
211
  },
164
212
  {
165
- name: "kimi_job_cancel",
166
- 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.",
167
- inputSchema: JOB_CONTROL_SCHEMA,
168
- 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
+ },
169
223
  },
170
224
  ];
171
225
  export function isMcpModelToolName(name) {
172
- return Object.hasOwn(OPERATION_SPECS, name);
226
+ return name === "kimi_read" || name === "kimi_write";
173
227
  }
174
228
  export function buildMcpOperationInvocation(name, input) {
175
- const spec = OPERATION_SPECS[name];
176
- const properties = spec.inputSchema.properties;
177
- 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);
178
231
  const workspace = optionalString(args, "workspace");
179
- const challenge = name === "kimi_review" && reviewMode(args) === "challenge";
180
- const kind = challenge ? "challenge" : spec.kind;
181
- const argv = challenge ? ["task", "challenge"] : [...spec.command];
182
- appendCommonOptions(argv, args, kind === "pursue" || kind === "swarm" || kind === "swarm-write" ? "safety" : "response");
183
- appendScopeOptions(argv, args);
184
- switch (kind) {
185
- case "ask":
186
- case "rescue": {
187
- const prompt = args.prompt === undefined ? undefined : requiredNonEmptyString(args, "prompt");
188
- const fresh = optionalBoolean(args, "fresh") ?? false;
189
- const resumeLatest = optionalBoolean(args, "resume_latest") ?? false;
190
- const resume = args.resume === undefined ? undefined : requiredNonEmptyString(args, "resume");
191
- if (fresh && (resumeLatest || resume !== undefined)) {
192
- throw invalidArguments("fresh cannot be combined with resume or resume_latest.");
193
- }
194
- if (resumeLatest && resume !== undefined) {
195
- 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;
196
280
  }
197
- if (resume !== undefined && prompt !== undefined) {
198
- 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;
199
288
  }
200
- if (prompt === undefined && !resumeLatest && resume === undefined) {
201
- throw invalidArguments(`${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;
202
296
  }
203
- if (fresh)
204
- argv.push("--fresh");
205
- if (resumeLatest)
206
- argv.push("-r");
207
- if (resume !== undefined)
208
- argv.push("--resume", resume);
209
- if (prompt !== undefined)
210
- argv.push("--", prompt);
211
- break;
212
297
  }
213
- case "review":
214
- case "challenge": {
215
- const base = args.base === undefined ? undefined : requiredNonEmptyString(args, "base");
216
- const focus = optionalString(args, "focus");
217
- if (base !== undefined)
218
- argv.push("--base", base);
219
- if (focus !== undefined)
220
- argv.push("--", focus);
221
- 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);
222
331
  }
223
- case "pursue": {
224
- const turns = optionalPositiveInteger(args, "turns");
225
- if (turns !== undefined)
226
- argv.push("--turns", String(turns));
227
- argv.push("--", requiredNonEmptyString(args, "objective"));
228
- 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);
229
337
  }
230
- case "swarm":
231
- case "swarm-write": {
232
- const cap = optionalPositiveInteger(args, "cap");
233
- const maxConcurrency = optionalPositiveInteger(args, "max_concurrency");
234
- if (cap !== undefined)
235
- argv.push("--cap", String(cap));
236
- if (maxConcurrency !== undefined)
237
- argv.push("--max-concurrency", String(maxConcurrency));
238
- if (kind === "swarm-write")
239
- argv.push("--write");
240
- argv.push("--", requiredNonEmptyString(args, "objective"));
241
- break;
338
+ else {
339
+ argv.push("--fresh", "--", requiredNonEmptyString(args, "prompt"));
242
340
  }
243
341
  }
244
- return { operationKind: 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
+ };
245
359
  }
246
360
  export function readJobControlArguments(input) {
247
- 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
+ }
383
+ return {
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 } : {}),
391
+ };
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
+ }
248
407
  return {
249
- ...(optionalString(args, "workspace") !== undefined ? { workspace: optionalString(args, "workspace") } : {}),
250
- jobId: requiredNonEmptyString(args, "job_id"),
408
+ action,
409
+ ...(workspace !== undefined ? { workspace } : {}),
410
+ ...(apply !== undefined ? { apply } : {}),
411
+ ...(all !== undefined ? { all } : {}),
251
412
  };
252
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
+ }
253
428
  function appendCommonOptions(argv, args, budgetKind) {
254
429
  const budget = optionalString(args, "budget");
255
430
  const model = optionalString(args, "model");
@@ -265,12 +440,6 @@ function appendCommonOptions(argv, args, budgetKind) {
265
440
  argv.push("--thinking", thinking);
266
441
  }
267
442
  }
268
- function reviewMode(args) {
269
- const mode = optionalString(args, "mode") ?? "defects";
270
- if (mode !== "defects" && mode !== "challenge")
271
- throw invalidArguments('mode must be "defects" or "challenge".');
272
- return mode;
273
- }
274
443
  /** Type checks only: the companion parser and read-scope resolver own every scope rule. */
275
444
  function appendScopeOptions(argv, args) {
276
445
  const readRoots = args.read_roots;
@@ -284,6 +453,23 @@ function appendScopeOptions(argv, args) {
284
453
  if (optionalBoolean(args, "network") === true)
285
454
  argv.push("--network");
286
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
+ }
287
473
  function readArguments(input, allowedKeys) {
288
474
  if (input === undefined)
289
475
  return {};
@@ -298,6 +484,13 @@ function readArguments(input, allowedKeys) {
298
484
  }
299
485
  return args;
300
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
+ }
301
494
  function optionalString(args, key) {
302
495
  const value = args[key];
303
496
  if (value === undefined)
@@ -320,12 +513,13 @@ function optionalBoolean(args, key) {
320
513
  throw invalidArguments(`${key} must be a boolean.`);
321
514
  return value;
322
515
  }
323
- function optionalPositiveInteger(args, key) {
516
+ function optionalBoundedInteger(args, key, min, max) {
324
517
  const value = args[key];
325
518
  if (value === undefined)
326
519
  return undefined;
327
- if (!Number.isSafeInteger(value) || value <= 0)
328
- 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
+ }
329
523
  return value;
330
524
  }
331
525
  function invalidArguments(message) {