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
@@ -8,6 +8,11 @@ import { resolveRepoIdentity } from "../git.js";
8
8
  import { digestPrompt } from "../jobs.js";
9
9
  import { resolvePluginPaths } from "../paths.js";
10
10
  import { syncKimiSessionTitle } from "../session-title.js";
11
+ import { stripSessionReferences } from "../session-references.js";
12
+ import { askPromptSubject } from "./ask.js";
13
+ import { buildGoalPrompt } from "./pursue.js";
14
+ import { stripRescuePromptPrefix } from "./rescue.js";
15
+ import { buildSwarmPrompt, buildSwarmWritePrompt } from "./swarm.js";
11
16
  // Repair is deliberately finite and local. Stream logs may be very large, but
12
17
  // the spawn record follows the invocation header: read only a bounded prefix.
13
18
  const MAX_JOBS = 1000;
@@ -25,27 +30,46 @@ export async function runRepairSessions(argv, context) {
25
30
  const paths = resolvePluginPaths(context.env);
26
31
  const repoId = all ? undefined : (await resolveRepoIdentity(context.cwd)).repoId;
27
32
  const jobs = await readRepairJobs(paths.stateDbPath, repoId);
28
- const sessions = new Set();
29
- const results = [];
33
+ // Newest job first per session: it supplies the preview, while every
34
+ // verified prompt of the session counts as the plugin's own.
35
+ const sessions = new Map();
30
36
  for (const job of jobs) {
31
- if (sessions.has(job.kimi_session_id))
32
- continue;
33
- sessions.add(job.kimi_session_id);
34
- const promptText = await readVerifiedPrompt(job, paths.logsDir, paths.worktreesDir);
35
- const status = promptText === undefined
36
- ? "unavailable-verified-prompt"
37
- : await syncKimiSessionTitle({
37
+ const sessionJobs = sessions.get(job.kimi_session_id);
38
+ if (sessionJobs)
39
+ sessionJobs.push(job);
40
+ else
41
+ sessions.set(job.kimi_session_id, [job]);
42
+ }
43
+ const results = [];
44
+ for (const [sessionId, [job, ...earlier]] of sessions) {
45
+ const prompt = await readVerifiedPrompt(job, paths.logsDir, paths.worktreesDir);
46
+ let status = "unavailable-verified-prompt";
47
+ if (prompt !== undefined) {
48
+ const raw = rawTaskTextFromSubmittedPrompt(job.operation_kind, prompt);
49
+ const own = [prompt];
50
+ if (raw !== undefined) {
51
+ for (const other of earlier) {
52
+ const otherPrompt = await readVerifiedPrompt(other, paths.logsDir, paths.worktreesDir);
53
+ if (otherPrompt !== undefined)
54
+ own.push(otherPrompt);
55
+ }
56
+ }
57
+ status = await syncKimiSessionTitle({
38
58
  env: context.env,
39
59
  cwd: job.cwd,
40
- sessionId: job.kimi_session_id,
60
+ sessionId,
41
61
  title: "",
42
- promptText,
62
+ // Without an exact raw-text derivation, only a missing preview is
63
+ // filled, with the verified prompt itself.
64
+ promptText: raw ?? prompt,
65
+ ownPrompts: raw === undefined ? [] : own,
43
66
  dryRun: !apply,
44
67
  preserveTitle: true,
45
68
  requireNativeV2: true,
46
69
  stderr: context.stderr,
47
70
  });
48
- results.push({ job_id: job.job_id, session_id: job.kimi_session_id, status });
71
+ }
72
+ results.push({ job_id: job.job_id, session_id: sessionId, status });
49
73
  }
50
74
  const counts = {};
51
75
  for (const { status } of results)
@@ -158,3 +182,88 @@ async function readVerifiedPrompt(job, logsDir, worktreesDir) {
158
182
  return undefined;
159
183
  }
160
184
  }
185
+ const TASK_SLOT = "\u0000kimi-plugin-cc-task\u0000";
186
+ /**
187
+ * Recover the raw task text a live run previews from its verified submitted
188
+ * prompt. Derivations are exact or absent: prompts from other plugin releases,
189
+ * ambiguous parameter choices and unknown operations return undefined. A
190
+ * trailing referenced-sessions block is not task text; pursue never carries one.
191
+ */
192
+ export function rawTaskTextFromSubmittedPrompt(operationKind, prompt) {
193
+ switch (operationKind) {
194
+ case "ask":
195
+ return strippedOrUndefined(prompt, askPromptSubject(prompt));
196
+ case "rescue":
197
+ return strippedOrUndefined(prompt, stripRescuePromptPrefix(prompt));
198
+ case "pursue":
199
+ return uniqueInversion(prompt, [undefined, ...numbersAfter(prompt, /at most (\d+) turns/g)]
200
+ .map((turns) => (task) => buildGoalPrompt(task, turns)));
201
+ case "swarm":
202
+ case "swarm-write": {
203
+ const build = operationKind === "swarm" ? buildSwarmPrompt : buildSwarmWritePrompt;
204
+ const caps = [undefined, ...numbersAfter(prompt, /at most (\d+) subagents/g)];
205
+ const waves = [undefined, 1, ...numbersAfter(prompt, /at most (\d+) entries/g)];
206
+ return uniqueInversion(stripSessionReferences(prompt), caps.flatMap((cap) => waves.map((wave) => (task) => build(task, cap, wave))));
207
+ }
208
+ case "review":
209
+ case "challenge":
210
+ return reviewTaskText(stripSessionReferences(prompt));
211
+ default:
212
+ return undefined;
213
+ }
214
+ }
215
+ /** The plugin prefix must have been removed, not merely a referenced-sessions block. */
216
+ function strippedOrUndefined(prompt, stripped) {
217
+ return stripped !== stripSessionReferences(prompt) && stripped.trim() ? stripped : undefined;
218
+ }
219
+ function numbersAfter(prompt, pattern) {
220
+ return [...new Set([...prompt.matchAll(pattern)].map((match) => Number(match[1])))];
221
+ }
222
+ /**
223
+ * Split each candidate template around the task slot and require an exact
224
+ * rebuild. The template explaining the most prompt text wins (without --turns
225
+ * the turn guidance would otherwise read as objective); a tie is ambiguous.
226
+ */
227
+ function uniqueInversion(prompt, builders) {
228
+ let found = new Set();
229
+ let bestTemplate = -1;
230
+ for (const build of builders) {
231
+ try {
232
+ const template = build(TASK_SLOT);
233
+ const at = template.indexOf(TASK_SLOT);
234
+ if (at < 0)
235
+ continue;
236
+ const head = template.slice(0, at);
237
+ const tail = template.slice(at + TASK_SLOT.length);
238
+ if (prompt.length < head.length + tail.length || !prompt.startsWith(head) || !prompt.endsWith(tail))
239
+ continue;
240
+ const task = prompt.slice(head.length, prompt.length - tail.length);
241
+ if (!task.trim() || build(task) !== prompt || head.length + tail.length < bestTemplate)
242
+ continue;
243
+ if (head.length + tail.length > bestTemplate)
244
+ found = new Set();
245
+ bestTemplate = head.length + tail.length;
246
+ found.add(task);
247
+ }
248
+ catch {
249
+ continue;
250
+ }
251
+ }
252
+ return found.size === 1 ? [...found][0] : undefined;
253
+ }
254
+ // Mirrors the review/challenge preview built at the review.ts sync call; the
255
+ // review command tests pin the two against real submitted prompts.
256
+ const REVIEW_PROMPT_START = "Perform a read-only code review of the supplied repository changes.\n";
257
+ const REVIEW_TARGET_LINES = /\n\nTarget: (current working tree changes|branch diff against [^\n]+)\nScope: (?:branch diff only; all working-tree changes are out of scope|current working tree, including tracked and untracked changes)\nRepository root: /;
258
+ const REVIEW_FOCUS_LINE = "\nReview focus: ";
259
+ function reviewTaskText(prompt) {
260
+ if (!prompt.startsWith(REVIEW_PROMPT_START))
261
+ return undefined;
262
+ const target = REVIEW_TARGET_LINES.exec(prompt);
263
+ if (!target)
264
+ return undefined;
265
+ const header = prompt.slice(0, target.index);
266
+ const focusAt = header.indexOf(REVIEW_FOCUS_LINE);
267
+ const focus = focusAt < 0 ? undefined : header.slice(focusAt + REVIEW_FOCUS_LINE.length);
268
+ return `Review target: ${target[1]}${focus ? `. Focus: ${focus}` : ""}`;
269
+ }
@@ -40,12 +40,13 @@ export async function replayJob(job) {
40
40
  if (stats.size > MAX_REPLAY_LOG_BYTES) {
41
41
  throw new RuntimeError("REPLAY_LOG_TOO_LARGE", `Job ${job.job_id} stream log is ${stats.size} bytes, which exceeds the ${MAX_REPLAY_LOG_BYTES}-byte replay ceiling.`, "replay.lookup");
42
42
  }
43
- const finalText = await replayFinalText(job.stream_log_path);
44
- const rendered = renderManagedJobOutput(job, finalText);
43
+ const replayed = await replayFinalText(job.stream_log_path);
44
+ const rendered = renderManagedJobOutput(job, replayed.text);
45
45
  return {
46
46
  rendered: rendered.rendered,
47
47
  output: rendered.output,
48
48
  summary: rendered.summary,
49
+ partial: replayed.partial,
49
50
  };
50
51
  }
51
52
  async function replayFinalText(logPath) {
@@ -120,5 +121,5 @@ async function replayFinalText(logPath) {
120
121
  if (!sawExit && assistantContent.length === 0) {
121
122
  throw new RuntimeError("REPLAY_LOG_INVALID", `Stream log ${logPath} did not capture any assistant content before truncation.`, "replay.log", { details: { logPath } });
122
123
  }
123
- return assistantContent;
124
+ return { text: assistantContent, partial: !sawExit };
124
125
  }
@@ -7,7 +7,7 @@ import { assertPersistedResumeLineage, executionPlanFromPersisted, observedExecu
7
7
  import { getManagedCommandConfig } from "./registry.js";
8
8
  import { RuntimeError } from "../errors.js";
9
9
  import { resolveRepoIdentity } from "../git.js";
10
- import { digestPrompt, markJobCancelled, markJobFailed, sweepStaleJobs } from "../jobs.js";
10
+ import { digestPrompt, markJobCancelled, markJobFailed, recordKimiSpawnIdentity, serializedProcessIdentity, sweepStaleJobs, } from "../jobs.js";
11
11
  import { JobStore } from "../job-store.js";
12
12
  import { classifyManagedCommandFailure } from "../kimi-errors.js";
13
13
  import { KIMI_RESCUE_PROMPT_TIMEOUT_MS } from "../kimi-timeouts.js";
@@ -16,10 +16,10 @@ import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
16
16
  import { parseRescueArgs } from "../parsing.js";
17
17
  import { readArtifact, renderManagedJobOutput, writeArtifact } from "../render.js";
18
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";
19
+ import { warnInheritedBudget, captureTimeoutPartialOutput, assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes, resolveResumeSession, resumeBudget, hookRefusal } from "./cli-helpers.js";
21
20
  import { buildKimiSessionTitle, syncKimiSessionTitle } from "../session-title.js";
22
- export { describeMissingResult } from "../background-spawn.js";
21
+ import { appendSessionReferences, resolveSessionReferences, stripSessionReferences } from "../session-references.js";
22
+ import { shorten } from "../util.js";
23
23
  // "Continue working on the bug" verbs that auto-attach to the latest
24
24
  // rescue session. Documented UX trap: a prompt matching this pattern
25
25
  // will resume the most recent rescue session regardless of whether
@@ -51,16 +51,21 @@ export async function runRescue(argv, context) {
51
51
  const store = new JobStore(paths);
52
52
  try {
53
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);
54
+ const sessionResolution = await resolveRescueSession(store, repoIdentity.repoId, parsed);
55
+ const basePrompt = buildRescuePrompt(parsed.prompt, sessionResolution.reusedSession);
56
56
  const executionPlan = await prepareKimiExecutionPlan({
57
57
  operationKind: "rescue",
58
58
  cwd: context.cwd,
59
59
  env: context.env,
60
+ stderr: context.stderr,
60
61
  resumedFromJobId: sessionResolution.resumedFromJobId,
61
62
  resumeSessionId: sessionResolution.kimiSessionId ?? undefined,
62
63
  resumeSource: sessionResolution.sourceJob,
63
64
  });
65
+ const prompt = appendSessionReferences(basePrompt, await resolveSessionReferences(parsed.referenceSessions, {
66
+ store, env: context.env, spawnCwd: context.cwd, plan: executionPlan,
67
+ resumeSessionId: sessionResolution.kimiSessionId, stage: "rescue.reference-session",
68
+ }));
64
69
  const jobId = allocateJobId(context);
65
70
  const logPath = path.join(paths.logsDir, `rescue-${jobId}.jsonl`);
66
71
  const job = store.createJob({
@@ -72,11 +77,10 @@ export async function runRescue(argv, context) {
72
77
  thinking: null,
73
78
  thinking_effort: parsed.thinkingEffort ?? null,
74
79
  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",
80
+ ...resumeBudget("rescue", parsed.budgetMs, sessionResolution.sourceJob),
78
81
  pid: parsed.background ? null : process.pid,
79
82
  kimi_pid: null,
83
+ companion_identity: parsed.background ? null : await serializedProcessIdentity(process.pid),
80
84
  status: "running",
81
85
  kimi_session_id: sessionResolution.kimiSessionId,
82
86
  kimi_session_id_source: sessionResolution.sourceJob?.kimi_session_id_source ?? null,
@@ -106,16 +110,7 @@ export async function runRescue(argv, context) {
106
110
  return startBackgroundJob(job, prompt, context, paths, {
107
111
  workerKind: "rescue",
108
112
  wait: parsed.wait,
109
- promptEnvVar: "KIMI_PLUGIN_CC_RESCUE_PROMPT_B64",
110
- reusedSessionEnvVar: "KIMI_PLUGIN_CC_RESCUE_REUSED_SESSION",
111
- reusedSession: sessionResolution.reusedSession,
112
113
  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
114
  });
120
115
  }
121
116
  const completed = await executeRescueJob(job.job_id, prompt, context);
@@ -147,16 +142,8 @@ export async function executeRescueJob(jobId, prompt, context, options) {
147
142
  // an early return doesn't leak SIGTERM/SIGINT listeners. Tests /
148
143
  // setup probes / intentional bypass: KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1.
149
144
  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) });
145
+ const classified = await hookRefusal(context, "rescue");
146
+ if (classified) {
160
147
  try {
161
148
  return await markJobFailed(store, paths, job, classified, cancel.failedSummary, { phase: "failed" });
162
149
  }
@@ -176,7 +163,12 @@ export async function executeRescueJob(jobId, prompt, context, options) {
176
163
  await assertPersistedResumeLineage(store, executionPlan, job.kimi_session_id, "rescue");
177
164
  }
178
165
  if (options?.workerPid) {
179
- store.updateRunningJob(job.job_id, { pid: options.workerPid, phase: "worker-running" });
166
+ const workerIdentity = await serializedProcessIdentity(options.workerPid);
167
+ store.updateRunningJob(job.job_id, {
168
+ pid: options.workerPid,
169
+ ...(workerIdentity ? { companion_identity: workerIdentity } : {}),
170
+ phase: "worker-running",
171
+ });
180
172
  }
181
173
  store.updateRunningJob(job.job_id, { phase: "turn-running" });
182
174
  const result = await runCliPromptWithBudget({
@@ -192,7 +184,7 @@ export async function executeRescueJob(jobId, prompt, context, options) {
192
184
  thinkingEffort: job.thinking_effort ?? undefined,
193
185
  resumeSessionId: job.kimi_session_id ?? undefined,
194
186
  logPath: job.stream_log_path,
195
- onSpawn: (pid) => { store.updateRunningJob(job.job_id, { kimi_pid: pid }); },
187
+ onSpawn: async (pid) => { await recordKimiSpawnIdentity(store, job.job_id, pid); },
196
188
  signal: handlers.signal,
197
189
  }, job.budget_ms ?? KIMI_RESCUE_PROMPT_TIMEOUT_MS, "rescue.prompt");
198
190
  store.updateRunningJob(job.job_id, observedExecutionFields(result));
@@ -207,7 +199,7 @@ export async function executeRescueJob(jobId, prompt, context, options) {
207
199
  store.updateRunningJob(job.job_id, { kimi_session_id_source: "announced", kimi_session_id: result.sessionId });
208
200
  }
209
201
  await syncKimiSessionTitle({
210
- promptText: prompt,
202
+ promptText: stripRescuePromptPrefix(prompt),
211
203
  env: context.env,
212
204
  cwd: job.cwd,
213
205
  sessionId: result.sessionId ?? job.kimi_session_id,
@@ -276,50 +268,12 @@ function buildRescuePrompt(prompt, reusedSession) {
276
268
  }
277
269
  throw new RuntimeError("INVALID_ARGS", "rescue requires a task description.", "rescue.parse");
278
270
  }
279
- function stripRescuePromptPrefix(prompt) {
280
- return prompt.startsWith(RESCUE_PROMPT_PREFIX) ? prompt.slice(RESCUE_PROMPT_PREFIX.length) : prompt;
271
+ export function stripRescuePromptPrefix(prompt) {
272
+ const body = stripSessionReferences(prompt);
273
+ return body.startsWith(RESCUE_PROMPT_PREFIX) ? body.slice(RESCUE_PROMPT_PREFIX.length) : body;
281
274
  }
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)) {
275
+ async function resolveRescueSession(store, repoId, parsed) {
276
+ if (!parsed.fresh && !parsed.resumeTarget && !parsed.resume && parsed.prompt && AUTO_RESUME_PATTERN.test(parsed.prompt)) {
323
277
  const latest = store.findLatestJob({ repoId, commandType: "rescue" });
324
278
  if (latest?.kimi_session_id && latest.status !== "running") {
325
279
  const source = await reconcileHistoricalJobProvenance(store, latest);
@@ -331,17 +285,5 @@ async function resolveRescueSession(store, repoId, prompt, fresh, resume, resume
331
285
  };
332
286
  }
333
287
  }
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()}…`;
288
+ return resolveResumeSession(store, "rescue", repoId, parsed);
347
289
  }
@@ -2,7 +2,7 @@ import { RuntimeError } from "../errors.js";
2
2
  import { resolveRepoIdentity } from "../git.js";
3
3
  import { sweepStaleJobs } from "../jobs.js";
4
4
  import { reconcileHistoricalJobProvenance } from "../kimi-engine.js";
5
- import { renderBudgetSource, withJobStore, parseHookEscapes } from "../job-store.js";
5
+ import { parseJobWarnings, renderBudgetSource, withJobStore, parseHookEscapes } from "../job-store.js";
6
6
  import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
7
7
  import { parseJobLookupArgs } from "../parsing.js";
8
8
  import { readArtifact, renderTerminalJobArtifact } from "../render.js";
@@ -62,5 +62,11 @@ function renderResultEnvelope(job, artifactPath, body) {
62
62
  kimi_version: job.kimi_version,
63
63
  system_version: job.system_version,
64
64
  resumed_from_job_id: job.resumed_from_job_id,
65
+ ...warningsField(job),
65
66
  }, null, 2)}\n`;
66
67
  }
68
+ /** Present only when the job carries warnings, so warning-free envelopes are unchanged. */
69
+ function warningsField(job) {
70
+ const warnings = parseJobWarnings(job.warnings);
71
+ return warnings.length > 0 ? { warnings } : {};
72
+ }
@@ -6,25 +6,28 @@ import { runCliPromptWithBudget } from "../cli-client.js";
6
6
  import { observedExecutionFields, persistedExecutionPlanFields, prepareKimiExecutionPlan, } from "../kimi-engine.js";
7
7
  import { getManagedCommandConfig } from "./registry.js";
8
8
  import { collectReviewContext } from "../git.js";
9
- import { digestPrompt, markJobCancelled, markJobFailed } from "../jobs.js";
9
+ import { digestPrompt, markJobCancelled, markJobFailed, recordKimiSpawnIdentity, serializedProcessIdentity, } from "../jobs.js";
10
10
  import { JobStore } from "../job-store.js";
11
11
  import { classifyManagedCommandFailure } from "../kimi-errors.js";
12
12
  import { KIMI_REVIEW_PROMPT_TIMEOUT_MS } from "../kimi-timeouts.js";
13
13
  import { writeInvocationLogHeader } from "../logging.js";
14
14
  import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
15
15
  import { parseReviewArgs } from "../parsing.js";
16
+ import { assertScopeSupported, resolveReadScope, serializeReadScope } from "../read-scope.js";
16
17
  import { renderManagedJobOutput, writeArtifact } from "../render.js";
17
18
  import { RuntimeError } from "../errors.js";
18
19
  import { resolveRepoIdentity } from "../git.js";
19
- import { hookRefusalDetails, hookRefusalRetryProtocol, maybeWarnHookMissing, verifyHookInstalled, } from "../hooks/install.js";
20
- import { captureTimeoutPartialOutput, assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes } from "./cli-helpers.js";
20
+ import { captureTimeoutPartialOutput, assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes, hookRefusal } from "./cli-helpers.js";
21
21
  import { buildKimiSessionTitle, syncKimiSessionTitle } from "../session-title.js";
22
+ import { appendSessionReferences, resolveSessionReferences, withReferenceReadRoots } from "../session-references.js";
22
23
  const REVIEW_AGENT_PROFILE_PLACEHOLDER = "<cli-client>";
23
24
  export async function runReview(argv, context, commandType) {
24
25
  const parsed = parseReviewArgs(argv, commandType);
25
26
  if (parsed.background || parsed.wait) {
26
27
  throw new RuntimeError("INVALID_FLAGS", `${commandType} does not support --background or --wait in v1; review runs foreground-synchronously.`, `${commandType}.parse`);
27
28
  }
29
+ const callerScope = parsed.readRoots === undefined && parsed.network === undefined ? undefined
30
+ : await resolveReadScope(parsed.readRoots, parsed.network, `${commandType}.parse`);
28
31
  if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
29
32
  await requireReadOnlyHookInstalled(context, commandType);
30
33
  }
@@ -36,14 +39,27 @@ export async function runReview(argv, context, commandType) {
36
39
  operationKind: commandType,
37
40
  cwd: context.cwd,
38
41
  env: context.env,
42
+ stderr: context.stderr,
39
43
  });
44
+ assertScopeSupported(callerScope, executionPlan.certification, "INVALID_ARGS", `${commandType}.parse`);
40
45
  const store = new JobStore(paths);
46
+ let references;
47
+ try {
48
+ references = await resolveSessionReferences(parsed.referenceSessions, {
49
+ store, env: context.env, spawnCwd: context.cwd, plan: executionPlan, stage: `${commandType}.reference-session`,
50
+ });
51
+ }
52
+ catch (error) {
53
+ store.close();
54
+ throw error;
55
+ }
56
+ const readScope = withReferenceReadRoots(callerScope, references);
41
57
  const jobId = allocateJobId(context);
42
58
  // Leave kimi_session_id NULL until kimi announces an actual ID; never invent
43
59
  // one that no on-disk session matches.
44
60
  const reviewSessionId = null;
45
61
  const logPath = path.join(paths.logsDir, `${commandType}-${jobId}.jsonl`);
46
- const previewPrompt = buildReviewPrompt(commandType, reviewContext, parsed.focus);
62
+ const previewPrompt = appendSessionReferences(buildReviewPrompt(commandType, reviewContext, parsed.focus), references);
47
63
  const job = store.createJob({
48
64
  job_id: jobId,
49
65
  repo_id: repoIdentity.repoId,
@@ -52,11 +68,13 @@ export async function runReview(argv, context, commandType) {
52
68
  model: parsed.model ?? null,
53
69
  thinking: null,
54
70
  thinking_effort: parsed.thinkingEffort ?? null,
71
+ read_scope: serializeReadScope(readScope),
55
72
  background: false,
56
73
  budget_ms: parsed.budgetMs ?? null,
57
74
  budget_source: parsed.budgetMs !== undefined ? "explicit" : "default",
58
75
  pid: process.pid,
59
76
  kimi_pid: null,
77
+ companion_identity: await serializedProcessIdentity(process.pid),
60
78
  status: "running",
61
79
  kimi_session_id: reviewSessionId,
62
80
  ...persistedExecutionPlanFields(executionPlan),
@@ -87,8 +105,9 @@ export async function runReview(argv, context, commandType) {
87
105
  commandLabel: commandType,
88
106
  model: parsed.model,
89
107
  thinkingEffort: parsed.thinkingEffort,
108
+ readScope,
90
109
  logPath,
91
- onSpawn: (pid) => { store.updateRunningJob(job.job_id, { kimi_pid: pid }); },
110
+ onSpawn: async (pid) => { await recordKimiSpawnIdentity(store, job.job_id, pid); },
92
111
  signal: handlers.signal,
93
112
  }, job.budget_ms ?? KIMI_REVIEW_PROMPT_TIMEOUT_MS, `${commandType}.prompt`);
94
113
  store.updateRunningJob(job.job_id, observedExecutionFields(result));
@@ -105,7 +124,7 @@ export async function runReview(argv, context, commandType) {
105
124
  store.updateRunningJob(job.job_id, { kimi_session_id_source: "announced", kimi_session_id: result.sessionId });
106
125
  }
107
126
  await syncKimiSessionTitle({
108
- promptText: previewPrompt,
127
+ promptText: `Review target: ${reviewContext.targetDescription}${parsed.focus ? `. Focus: ${parsed.focus}` : ""}`,
109
128
  env: context.env,
110
129
  cwd: job.cwd,
111
130
  sessionId: result.sessionId ?? job.kimi_session_id,
@@ -152,18 +171,9 @@ async function requireReadOnlyHookInstalled(context, commandType) {
152
171
  if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK === "1") {
153
172
  return;
154
173
  }
155
- const installStatus = await verifyHookInstalled(context.env);
156
- if (installStatus.installed) {
157
- return;
158
- }
159
- maybeWarnHookMissing(installStatus, commandType, context.stderr);
160
- throw new RuntimeError(`${commandType.toUpperCase()}_HOOK_NOT_INSTALLED`, [
161
- `${commandType} refuses to run without the canonical kimi-plugin-cc PreToolUse hook.`,
162
- `Hook check failed: ${installStatus.reason ?? "unknown"}.`,
163
- "Run /kimi:setup or $kimi-setup to install or repair this host's managed block.",
164
- "Set KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 only if you intentionally accept un-enforced execution.",
165
- hookRefusalRetryProtocol(context.env),
166
- ].join(" "), `${commandType}.hook-check`, { details: hookRefusalDetails(installStatus) });
174
+ const refusal = await hookRefusal(context, commandType);
175
+ if (refusal)
176
+ throw refusal;
167
177
  }
168
178
  function buildReviewPrompt(commandType, reviewContext, focus) {
169
179
  const modeInstructions = commandType === "challenge"