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,347 +0,0 @@
1
- import { companionHelp } from "../help.js";
2
- import { allocateJobId } from "../job-id.js";
3
- import path from "node:path";
4
- import { createCliCancellationHandlers } from "../cli-cancellation.js";
5
- import { runCliPromptWithBudget } from "../cli-client.js";
6
- import { assertPersistedResumeLineage, executionPlanFromPersisted, observedExecutionFields, persistedExecutionPlanFields, prepareKimiExecutionPlan, reconcileHistoricalJobProvenance, } from "../kimi-engine.js";
7
- import { getManagedCommandConfig } from "./registry.js";
8
- import { RuntimeError } from "../errors.js";
9
- import { resolveRepoIdentity } from "../git.js";
10
- import { digestPrompt, markJobCancelled, markJobFailed, sweepStaleJobs } from "../jobs.js";
11
- import { JobStore } from "../job-store.js";
12
- import { classifyManagedCommandFailure } from "../kimi-errors.js";
13
- import { KIMI_RESCUE_PROMPT_TIMEOUT_MS } from "../kimi-timeouts.js";
14
- import { writeInvocationLogHeader } from "../logging.js";
15
- import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
16
- import { parseRescueArgs } from "../parsing.js";
17
- import { readArtifact, renderManagedJobOutput, writeArtifact } from "../render.js";
18
- import { startBackgroundJob } from "../background-spawn.js";
19
- import { hookRefusalDetails, hookRefusalRetryProtocol, maybeWarnHookMissing, verifyHookInstalled, } from "../hooks/install.js";
20
- import { warnInheritedBudget, captureTimeoutPartialOutput, assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes } from "./cli-helpers.js";
21
- import { buildKimiSessionTitle, syncKimiSessionTitle } from "../session-title.js";
22
- export { describeMissingResult } from "../background-spawn.js";
23
- // "Continue working on the bug" verbs that auto-attach to the latest
24
- // rescue session. Documented UX trap: a prompt matching this pattern
25
- // will resume the most recent rescue session regardless of whether
26
- // that session was about the same bug. Users should pass an explicit
27
- // `--resume <job-id>` or `--fresh` when the topic switches.
28
- const AUTO_RESUME_PATTERN = /\b(continue|resume|keep going|keep working|apply the top fix|dig deeper)\b/i;
29
- const RESCUE_SUMMARY_MAX = 120;
30
- const RESCUE_AGENT_PROFILE_PLACEHOLDER = "<cli-client>";
31
- const RESCUE_CONTINUE_TASK = "Continue the previous rescue task using the latest repository state.";
32
- const RESCUE_PROMPT_PREFIX = [
33
- "Follow repository instructions and inspect the current state before editing.",
34
- "Implement the smallest complete change that satisfies the task instead of stopping at a plan.",
35
- "Do not mutate git state.",
36
- "Run proportionate relevant checks, and never claim unrun checks passed.",
37
- "Do not narrate progress.",
38
- "Finish with a self-contained report of changed files, verification commands and results, and unfinished work or blockers.",
39
- "",
40
- "Rescue task:",
41
- "",
42
- ].join("\n");
43
- export async function runRescue(argv, context) {
44
- const parsed = parseRescueArgs(argv);
45
- if (parsed.help)
46
- return companionHelp(["task", "rescue", ...argv]);
47
- const paths = resolvePluginPaths(context.env);
48
- await ensurePluginPaths(paths);
49
- const repoIdentity = await resolveRepoIdentity(context.cwd);
50
- const rescueConfig = getManagedCommandConfig("rescue");
51
- const store = new JobStore(paths);
52
- try {
53
- await sweepStaleJobs(store, paths);
54
- const sessionResolution = await resolveRescueSession(store, repoIdentity.repoId, parsed.prompt, parsed.fresh, parsed.resume, parsed.resumeTarget);
55
- const prompt = buildRescuePrompt(parsed.prompt, sessionResolution.reusedSession);
56
- const executionPlan = await prepareKimiExecutionPlan({
57
- operationKind: "rescue",
58
- cwd: context.cwd,
59
- env: context.env,
60
- resumedFromJobId: sessionResolution.resumedFromJobId,
61
- resumeSessionId: sessionResolution.kimiSessionId ?? undefined,
62
- resumeSource: sessionResolution.sourceJob,
63
- });
64
- const jobId = allocateJobId(context);
65
- const logPath = path.join(paths.logsDir, `rescue-${jobId}.jsonl`);
66
- const job = store.createJob({
67
- job_id: jobId,
68
- repo_id: repoIdentity.repoId,
69
- command_type: "rescue",
70
- cwd: context.cwd,
71
- model: parsed.model ?? null,
72
- thinking: null,
73
- thinking_effort: parsed.thinkingEffort ?? null,
74
- background: parsed.background,
75
- budget_ms: parsed.budgetMs ?? (sessionResolution.sourceJob?.operation_kind === "rescue" ? sessionResolution.sourceJob.budget_ms : null) ?? null,
76
- budget_source: parsed.budgetMs !== undefined ? "explicit"
77
- : sessionResolution.sourceJob?.operation_kind === "rescue" && sessionResolution.sourceJob.budget_ms !== null ? "inherited" : "default",
78
- pid: parsed.background ? null : process.pid,
79
- kimi_pid: null,
80
- status: "running",
81
- kimi_session_id: sessionResolution.kimiSessionId,
82
- kimi_session_id_source: sessionResolution.sourceJob?.kimi_session_id_source ?? null,
83
- ...persistedExecutionPlanFields(executionPlan),
84
- agent_profile: RESCUE_AGENT_PROFILE_PLACEHOLDER,
85
- prompt_digest: digestPrompt(prompt),
86
- summary: shorten(stripRescuePromptPrefix(prompt), RESCUE_SUMMARY_MAX),
87
- phase: parsed.background ? "queued" : "starting",
88
- final_output_path: null,
89
- stream_log_path: logPath,
90
- error: null,
91
- });
92
- try {
93
- await writeInvocationLogHeader(logPath, {
94
- commandType: "rescue",
95
- kimiSessionId: sessionResolution.kimiSessionId ?? "(pending)",
96
- cwd: context.cwd,
97
- });
98
- }
99
- catch (error) {
100
- const classified = new RuntimeError("RESCUE_LOG_HEADER_FAILED", `Failed to write rescue invocation log header: ${error.message ?? String(error)}`, "rescue.log-header", error instanceof Error ? { cause: error } : undefined);
101
- await markJobFailed(store, paths, job, classified, rescueConfig.cancellation.failedSummary, { phase: "failed" });
102
- throw classified;
103
- }
104
- warnInheritedBudget(job, context.stderr);
105
- if (parsed.background) {
106
- return startBackgroundJob(job, prompt, context, paths, {
107
- workerKind: "rescue",
108
- wait: parsed.wait,
109
- promptEnvVar: "KIMI_PLUGIN_CC_RESCUE_PROMPT_B64",
110
- reusedSessionEnvVar: "KIMI_PLUGIN_CC_RESCUE_REUSED_SESSION",
111
- reusedSession: sessionResolution.reusedSession,
112
- failedSummary: rescueConfig.cancellation.failedSummary,
113
- missingResultErrorCode: "RESCUE_RESULT_MISSING",
114
- spawnFailedErrorCode: "RESCUE_WORKER_SPAWN_FAILED",
115
- earlyExitErrorCode: "RESCUE_WORKER_EXITED_EARLY",
116
- nodeBinInvalidErrorCode: "RESCUE_NODE_BIN_INVALID",
117
- waitStage: "rescue.wait",
118
- spawnStage: "rescue.worker.spawn",
119
- });
120
- }
121
- const completed = await executeRescueJob(job.job_id, prompt, context);
122
- if (!completed.final_output_path) {
123
- throw new RuntimeError("RESCUE_RESULT_MISSING", "Rescue finished without a rendered result.", "rescue.result");
124
- }
125
- return readArtifact(completed.final_output_path);
126
- }
127
- finally {
128
- store.close();
129
- }
130
- }
131
- export async function executeRescueJob(jobId, prompt, context, options) {
132
- const paths = resolvePluginPaths(context.env);
133
- await ensurePluginPaths(paths);
134
- const store = new JobStore(paths);
135
- const job = store.getJob(jobId);
136
- if (!job) {
137
- store.close();
138
- throw new RuntimeError("JOB_NOT_FOUND", `Rescue job ${jobId} was not found.`, "rescue.worker");
139
- }
140
- const rescueConfig = getManagedCommandConfig("rescue");
141
- const cancel = rescueConfig.cancellation;
142
- // Rescue writes directly to the workspace. Without the PreToolUse hook,
143
- // kimi-code's `-p` mode auto-approves every Bash/Write/Edit, including
144
- // destructive ones. Refuse before the worker can spawn Kimi.
145
- //
146
- // The hook check happens BEFORE `createCliCancellationHandlers()` so
147
- // an early return doesn't leak SIGTERM/SIGINT listeners. Tests /
148
- // setup probes / intentional bypass: KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1.
149
- if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
150
- const installStatus = await verifyHookInstalled(context.env);
151
- if (!installStatus.installed) {
152
- maybeWarnHookMissing(installStatus, "rescue", context.stderr);
153
- const classified = new RuntimeError("RESCUE_HOOK_NOT_INSTALLED", [
154
- "rescue refuses to run without the kimi-plugin-cc PreToolUse hook.",
155
- `Hook check failed: ${installStatus.reason ?? "unknown"}.`,
156
- "Repair by running Claude Code /kimi:setup or Codex $kimi-setup, then retry.",
157
- "KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 is only for deliberate tests or diagnostics.",
158
- hookRefusalRetryProtocol(context.env),
159
- ].join(" "), "rescue.hook-check", { details: hookRefusalDetails(installStatus) });
160
- try {
161
- return await markJobFailed(store, paths, job, classified, cancel.failedSummary, { phase: "failed" });
162
- }
163
- finally {
164
- store.close();
165
- }
166
- }
167
- }
168
- const handlers = createCliCancellationHandlers();
169
- try {
170
- const executionPlan = executionPlanFromPersisted(job);
171
- // Re-validate resume lineage from the store before spawning: a detached
172
- // worker (or a forged queued row) reloads the persisted plan and would
173
- // otherwise hand kimi_session_id to the spawn without the dispatch-time
174
- // lineage check. Fresh sessions (no resumedFromJobId) are exempt.
175
- if (job.kimi_session_id !== null) {
176
- await assertPersistedResumeLineage(store, executionPlan, job.kimi_session_id, "rescue");
177
- }
178
- if (options?.workerPid) {
179
- store.updateRunningJob(job.job_id, { pid: options.workerPid, phase: "worker-running" });
180
- }
181
- store.updateRunningJob(job.job_id, { phase: "turn-running" });
182
- const result = await runCliPromptWithBudget({
183
- cwd: job.cwd,
184
- env: context.env,
185
- command: executionPlan.command,
186
- prefixArgs: [...executionPlan.prefixArgs],
187
- executionPlan,
188
- prompt,
189
- commandLabel: "rescue",
190
- trustedWorkspaceRoot: job.cwd,
191
- model: job.model ?? undefined,
192
- thinkingEffort: job.thinking_effort ?? undefined,
193
- resumeSessionId: job.kimi_session_id ?? undefined,
194
- logPath: job.stream_log_path,
195
- onSpawn: (pid) => { store.updateRunningJob(job.job_id, { kimi_pid: pid }); },
196
- signal: handlers.signal,
197
- }, job.budget_ms ?? KIMI_RESCUE_PROMPT_TIMEOUT_MS, "rescue.prompt");
198
- store.updateRunningJob(job.job_id, observedExecutionFields(result));
199
- if (handlers.cancelling) {
200
- throw new RuntimeError(cancel.errorCodes.cancelled, cancel.cancelMessages.afterPrompt, "rescue.runtime");
201
- }
202
- assertCliResultSuccess(result, "rescue.runtime");
203
- warnHookEscapes(result, "rescue", context.stderr);
204
- if (result.sessionId !== undefined &&
205
- result.sessionId.length > 0) {
206
- // Never persist an empty ID because NULL represents a missing session ID.
207
- store.updateRunningJob(job.job_id, { kimi_session_id_source: "announced", kimi_session_id: result.sessionId });
208
- }
209
- await syncKimiSessionTitle({
210
- promptText: prompt,
211
- env: context.env,
212
- cwd: job.cwd,
213
- sessionId: result.sessionId ?? job.kimi_session_id,
214
- title: buildKimiSessionTitle("rescue", stripRescuePromptPrefix(prompt)),
215
- stderr: context.stderr,
216
- });
217
- if (job.kimi_session_id === null) {
218
- warnIfSessionIdMissing(result, "rescue", job.job_id, context.stderr);
219
- }
220
- const finalText = reassembleProseFromRecords(result.records);
221
- const rendered = renderManagedJobOutput(job, finalText);
222
- let artifactPath;
223
- try {
224
- if (context.env.KIMI_PLUGIN_CC_TEST_FAIL_WRITE_ARTIFACT === "1") {
225
- throw new Error("Simulated artifact write failure (test seam).");
226
- }
227
- artifactPath = await writeArtifact(paths, job, rendered.rendered);
228
- }
229
- catch (writeError) {
230
- // LLM-caller discipline: writing the raw model output to stderr
231
- // for a wrapper LLM-caller would corrupt its prose stream. Keep
232
- // the raw text in the RuntimeError details — surfaces via
233
- // /kimi:status / /kimi:result --json — and emit only a short
234
- // human-facing line on stderr.
235
- context.stderr.write(`[kimi-plugin-cc] rescue artifact write failed for job ${job.job_id}; raw output preserved in error details.\n`);
236
- const classified = new RuntimeError("RESCUE_ARTIFACT_WRITE_FAILED", `Failed to write rescue artifact: ${writeError.message ?? String(writeError)}`, "rescue.artifact", {
237
- ...(writeError instanceof Error ? { cause: writeError } : {}),
238
- details: { rawOutput: finalText },
239
- });
240
- return await markJobFailed(store, paths, job, classified, cancel.failedSummary, { phase: "failed" });
241
- }
242
- if (handlers.cancelling) {
243
- throw new RuntimeError(cancel.errorCodes.cancelled, cancel.cancelMessages.afterArtifact, "rescue.runtime");
244
- }
245
- return (store.markCompleted(job.job_id, {
246
- summary: rendered.summary,
247
- phase: "done",
248
- final_output_path: artifactPath,
249
- error: null,
250
- }) ?? job);
251
- }
252
- catch (error) {
253
- const classified = classifyManagedCommandFailure(error, "rescue", job.job_id, {
254
- preserveStage: true,
255
- background: job.background,
256
- budgetMs: job.budget_ms ?? KIMI_RESCUE_PROMPT_TIMEOUT_MS,
257
- });
258
- const partialOutput = await captureTimeoutPartialOutput(classified, store, job, context.env, handlers.signal);
259
- if (handlers.cancelling) {
260
- const cancelledError = new RuntimeError(cancel.errorCodes.cancelled, cancel.cancelMessages.default, "rescue.runtime", error instanceof Error ? { cause: error } : undefined);
261
- return await markJobCancelled(store, paths, job, cancel.cancelledSummary, cancelledError, { phase: "cancelled" });
262
- }
263
- return await markJobFailed(store, paths, job, classified, cancel.failedSummary, { phase: "failed", partialOutput });
264
- }
265
- finally {
266
- handlers.dispose();
267
- store.close();
268
- }
269
- }
270
- function buildRescuePrompt(prompt, reusedSession) {
271
- if (prompt?.trim()) {
272
- return RESCUE_PROMPT_PREFIX + prompt.trim();
273
- }
274
- if (reusedSession) {
275
- return RESCUE_PROMPT_PREFIX + RESCUE_CONTINUE_TASK;
276
- }
277
- throw new RuntimeError("INVALID_ARGS", "rescue requires a task description.", "rescue.parse");
278
- }
279
- function stripRescuePromptPrefix(prompt) {
280
- return prompt.startsWith(RESCUE_PROMPT_PREFIX) ? prompt.slice(RESCUE_PROMPT_PREFIX.length) : prompt;
281
- }
282
- async function resolveRescueSession(store, repoId, prompt, fresh, resume, resumeTarget) {
283
- if (fresh) {
284
- return { kimiSessionId: null, reusedSession: false, resumedFromJobId: null, sourceJob: null };
285
- }
286
- if (resumeTarget) {
287
- const byJob = store.getJob(resumeTarget);
288
- const scoped = byJob?.repo_id === repoId && byJob.command_type === "rescue" ? byJob : null;
289
- const exact = scoped ?? store.findRescueJobBySession(repoId, resumeTarget);
290
- if (!exact) {
291
- throw new RuntimeError("RESCUE_RESUME_NOT_FOUND", `No rescue job or session matched ${resumeTarget}.`, "rescue.resume");
292
- }
293
- const source = await reconcileHistoricalJobProvenance(store, exact);
294
- ensureSessionIsNotRunning(source);
295
- if (!source.kimi_session_id) {
296
- throw new RuntimeError("RESCUE_RESUME_NOT_FOUND", `No rescue job or session matched ${resumeTarget}.`, "rescue.resume");
297
- }
298
- return {
299
- kimiSessionId: source.kimi_session_id,
300
- reusedSession: true,
301
- resumedFromJobId: source.job_id,
302
- sourceJob: source,
303
- };
304
- }
305
- if (resume) {
306
- const latest = store.findLatestJob({ repoId, commandType: "rescue" });
307
- if (!latest) {
308
- throw new RuntimeError("RESCUE_RESUME_NOT_FOUND", "No prior rescue session exists for this repository.", "rescue.resume");
309
- }
310
- const source = await reconcileHistoricalJobProvenance(store, latest);
311
- ensureSessionIsNotRunning(source);
312
- if (!source.kimi_session_id) {
313
- throw new RuntimeError("RESCUE_RESUME_NOT_FOUND", "No prior rescue session exists for this repository.", "rescue.resume");
314
- }
315
- return {
316
- kimiSessionId: source.kimi_session_id,
317
- reusedSession: true,
318
- resumedFromJobId: source.job_id,
319
- sourceJob: source,
320
- };
321
- }
322
- if (prompt && AUTO_RESUME_PATTERN.test(prompt)) {
323
- const latest = store.findLatestJob({ repoId, commandType: "rescue" });
324
- if (latest?.kimi_session_id && latest.status !== "running") {
325
- const source = await reconcileHistoricalJobProvenance(store, latest);
326
- return {
327
- kimiSessionId: source.kimi_session_id,
328
- reusedSession: true,
329
- resumedFromJobId: source.job_id,
330
- sourceJob: source,
331
- };
332
- }
333
- }
334
- return { kimiSessionId: null, reusedSession: false, resumedFromJobId: null, sourceJob: null };
335
- }
336
- function ensureSessionIsNotRunning(job) {
337
- if (job.status === "running") {
338
- throw new RuntimeError("RESCUE_ALREADY_RUNNING", `Rescue session ${job.kimi_session_id ?? "<unknown>"} is already active under job ${job.job_id}.`, "rescue.resume");
339
- }
340
- }
341
- function shorten(text, max) {
342
- const normalized = text.replace(/\s+/g, " ").trim();
343
- if (normalized.length <= max) {
344
- return normalized;
345
- }
346
- return `${normalized.slice(0, Math.max(0, max - 1)).trimEnd()}…`;
347
- }
@@ -1,66 +0,0 @@
1
- import { RuntimeError } from "../errors.js";
2
- import { resolveRepoIdentity } from "../git.js";
3
- import { sweepStaleJobs } from "../jobs.js";
4
- import { reconcileHistoricalJobProvenance } from "../kimi-engine.js";
5
- import { renderBudgetSource, withJobStore, parseHookEscapes } from "../job-store.js";
6
- import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
7
- import { parseJobLookupArgs } from "../parsing.js";
8
- import { readArtifact, renderTerminalJobArtifact } from "../render.js";
9
- export async function runResult(argv, context) {
10
- const parsed = parseJobLookupArgs(argv);
11
- const paths = resolvePluginPaths(context.env);
12
- await ensurePluginPaths(paths);
13
- const repoIdentity = await resolveRepoIdentity(context.cwd);
14
- return withJobStore(paths, async (store) => {
15
- await sweepStaleJobs(store, paths);
16
- const found = parsed.jobId
17
- ? store.getJob(parsed.jobId)
18
- : store.findLatestJob({
19
- repoId: repoIdentity.repoId,
20
- commandType: parsed.type,
21
- terminalOnly: true,
22
- });
23
- if (!found) {
24
- throw new RuntimeError("JOB_NOT_FOUND", "No matching terminal job was found for result.", "result.lookup");
25
- }
26
- const job = await reconcileHistoricalJobProvenance(store, found);
27
- if (job.status === "running") {
28
- // `result --json` preserves the existing result contract: callers only
29
- // receive terminal artifacts, never a partial/running envelope.
30
- throw new RuntimeError("JOB_NOT_TERMINAL", `Job ${job.job_id} is still running.`, "result.lookup");
31
- }
32
- if (!job.final_output_path) {
33
- const fallbackBody = `${renderTerminalJobArtifact(job)}\n`;
34
- return parsed.json ? renderResultEnvelope(job, null, fallbackBody) : fallbackBody;
35
- }
36
- const body = await readArtifact(job.final_output_path);
37
- return parsed.json ? renderResultEnvelope(job, job.final_output_path, body) : body;
38
- });
39
- }
40
- function renderResultEnvelope(job, artifactPath, body) {
41
- return `${JSON.stringify({
42
- job_id: job.job_id,
43
- kind: job.command_type,
44
- status: job.status,
45
- budget_ms: job.budget_ms,
46
- budget_source: renderBudgetSource(job),
47
- thinking_effort_requested: job.thinking_effort ?? null,
48
- hook_escapes: parseHookEscapes(job.hook_escapes),
49
- kimi_session_id_source: job.kimi_session_id_source,
50
- kimi_session_id: job.kimi_session_id,
51
- // True when a budget timeout preserved assistant prose in the artifact.
52
- partial_output: job.status === "failed" && Number(job.error?.details?.partial_output_chars ?? 0) > 0,
53
- summary: job.summary,
54
- error: job.error,
55
- artifact_path: artifactPath,
56
- body,
57
- created_at: job.created_at,
58
- completed_at: job.updated_at,
59
- operation_kind: job.operation_kind,
60
- intended_engine: job.intended_engine,
61
- observed_engine: job.observed_engine,
62
- kimi_version: job.kimi_version,
63
- system_version: job.system_version,
64
- resumed_from_job_id: job.resumed_from_job_id,
65
- }, null, 2)}\n`;
66
- }