kimi-plugin-cc 2.7.3 → 3.0.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 (223) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +3 -5
  3. package/CHANGELOG.md +69 -0
  4. package/README.md +505 -448
  5. package/agents/kimi-pursue.md +6 -6
  6. package/agents/kimi-review.md +22 -22
  7. package/agents/kimi-swarm.md +25 -23
  8. package/agents/{kimi-ask.md → kimi-task.md} +34 -30
  9. package/commands/README.md +4 -6
  10. package/commands/pursue.md +1 -1
  11. package/commands/review.md +8 -3
  12. package/commands/setup.md +4 -2
  13. package/commands/swarm.md +3 -2
  14. package/commands/{rescue.md → task.md} +13 -11
  15. package/dist/background-spawn.js +10 -17
  16. package/dist/cli-client.js +65 -46
  17. package/dist/commands/ask.js +22 -89
  18. package/dist/commands/cancel.js +7 -46
  19. package/dist/commands/cli-helpers.js +102 -1
  20. package/dist/commands/models.js +2 -3
  21. package/dist/commands/pursue.js +5 -19
  22. package/dist/commands/repair-sessions.js +118 -12
  23. package/dist/commands/rescue.js +12 -82
  24. package/dist/commands/result.js +7 -1
  25. package/dist/commands/review-gate.js +1 -0
  26. package/dist/commands/review.js +12 -15
  27. package/dist/commands/setup.js +606 -270
  28. package/dist/commands/status.js +2 -2
  29. package/dist/commands/swarm.js +93 -119
  30. package/dist/commands/worker.js +1 -2
  31. package/dist/companion.js +3 -1
  32. package/dist/dsh/index.js +15 -17
  33. package/dist/git.js +1 -9
  34. package/dist/help.js +3 -3
  35. package/dist/hooks/approval-hook.js +41 -0
  36. package/dist/hooks/approval-policy.js +72 -10
  37. package/dist/hooks/config-safety.js +19 -43
  38. package/dist/hooks/hook-timing.js +48 -0
  39. package/dist/hooks/install.js +206 -11
  40. package/dist/hooks/managed-block.js +78 -33
  41. package/dist/job-store.js +100 -128
  42. package/dist/jobs.js +14 -19
  43. package/dist/kimi-command.js +74 -1
  44. package/dist/kimi-engine.js +170 -75
  45. package/dist/kimi-errors.js +14 -69
  46. package/dist/kimi-home.js +6 -0
  47. package/dist/kimi-journal.js +41 -0
  48. package/dist/kimi-releases.js +144 -0
  49. package/dist/kimi-timeouts.js +1 -1
  50. package/dist/kimi-version-probe.js +12 -48
  51. package/dist/mcp/job-control.js +4 -6
  52. package/dist/mcp/launcher.js +12 -6
  53. package/dist/mcp/operations.js +50 -18
  54. package/dist/mcp/protocol.js +16 -14
  55. package/dist/mcp/stdio.js +3 -2
  56. package/dist/model-command.js +5 -3
  57. package/dist/native-v2-preflight.js +139 -68
  58. package/dist/parsing.js +171 -237
  59. package/dist/paths.js +8 -0
  60. package/dist/process-tree.js +35 -24
  61. package/dist/read-scope.js +435 -0
  62. package/dist/render.js +46 -9
  63. package/dist/rescue-approval.js +461 -84
  64. package/dist/schemas/review-gate-output.js +3 -5
  65. package/dist/session-title.js +25 -5
  66. package/dist/stream-json.js +1 -3
  67. package/dist/surface-routing.js +21 -0
  68. package/dist/swarm-activation.js +72 -75
  69. package/dist/swarm-policy.js +2 -1
  70. package/dist/swarm-recovery.js +2 -1
  71. package/dist/util.js +28 -0
  72. package/dist/version.js +1 -1
  73. package/docs/migration.md +24 -3
  74. package/docs/models.md +2 -2
  75. package/docs/registry-releases.md +1 -1
  76. package/docs/safety.md +120 -70
  77. package/docs/session-visibility.md +5 -3
  78. package/docs/swarm-recovery.md +1 -1
  79. package/docs/upstream-2.7.3-certification.md +14 -2
  80. package/package.json +1 -1
  81. package/plugins/kimi-codex/.codex-plugin/plugin.json +3 -3
  82. package/plugins/kimi-codex/.mcp.json +1 -0
  83. package/plugins/kimi-codex/dist/background-spawn.js +10 -17
  84. package/plugins/kimi-codex/dist/cli-client.js +65 -46
  85. package/plugins/kimi-codex/dist/commands/ask.js +22 -89
  86. package/plugins/kimi-codex/dist/commands/cancel.js +7 -46
  87. package/plugins/kimi-codex/dist/commands/cli-helpers.js +102 -1
  88. package/plugins/kimi-codex/dist/commands/models.js +2 -3
  89. package/plugins/kimi-codex/dist/commands/pursue.js +5 -19
  90. package/plugins/kimi-codex/dist/commands/repair-sessions.js +118 -12
  91. package/plugins/kimi-codex/dist/commands/rescue.js +12 -82
  92. package/plugins/kimi-codex/dist/commands/result.js +7 -1
  93. package/plugins/kimi-codex/dist/commands/review-gate.js +1 -0
  94. package/plugins/kimi-codex/dist/commands/review.js +12 -15
  95. package/plugins/kimi-codex/dist/commands/setup.js +606 -270
  96. package/plugins/kimi-codex/dist/commands/status.js +2 -2
  97. package/plugins/kimi-codex/dist/commands/swarm.js +93 -119
  98. package/plugins/kimi-codex/dist/commands/worker.js +1 -2
  99. package/plugins/kimi-codex/dist/companion.js +3 -1
  100. package/plugins/kimi-codex/dist/dsh/index.js +15 -17
  101. package/plugins/kimi-codex/dist/git.js +1 -9
  102. package/plugins/kimi-codex/dist/help.js +3 -3
  103. package/plugins/kimi-codex/dist/hooks/approval-hook.js +41 -0
  104. package/plugins/kimi-codex/dist/hooks/approval-policy.js +72 -10
  105. package/plugins/kimi-codex/dist/hooks/config-safety.js +19 -43
  106. package/plugins/kimi-codex/dist/hooks/hook-timing.js +48 -0
  107. package/plugins/kimi-codex/dist/hooks/install.js +206 -11
  108. package/plugins/kimi-codex/dist/hooks/managed-block.js +78 -33
  109. package/plugins/kimi-codex/dist/job-store.js +100 -128
  110. package/plugins/kimi-codex/dist/jobs.js +14 -19
  111. package/plugins/kimi-codex/dist/kimi-command.js +74 -1
  112. package/plugins/kimi-codex/dist/kimi-engine.js +170 -75
  113. package/plugins/kimi-codex/dist/kimi-errors.js +14 -69
  114. package/plugins/kimi-codex/dist/kimi-home.js +6 -0
  115. package/plugins/kimi-codex/dist/kimi-journal.js +41 -0
  116. package/plugins/kimi-codex/dist/kimi-releases.js +144 -0
  117. package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -1
  118. package/plugins/kimi-codex/dist/kimi-version-probe.js +12 -48
  119. package/plugins/kimi-codex/dist/mcp/job-control.js +4 -6
  120. package/plugins/kimi-codex/dist/mcp/launcher.js +12 -6
  121. package/plugins/kimi-codex/dist/mcp/operations.js +50 -18
  122. package/plugins/kimi-codex/dist/mcp/protocol.js +16 -14
  123. package/plugins/kimi-codex/dist/mcp/stdio.js +3 -2
  124. package/plugins/kimi-codex/dist/model-command.js +5 -3
  125. package/plugins/kimi-codex/dist/native-v2-preflight.js +139 -68
  126. package/plugins/kimi-codex/dist/parsing.js +171 -237
  127. package/plugins/kimi-codex/dist/paths.js +8 -0
  128. package/plugins/kimi-codex/dist/process-tree.js +35 -24
  129. package/plugins/kimi-codex/dist/read-scope.js +435 -0
  130. package/plugins/kimi-codex/dist/render.js +46 -9
  131. package/plugins/kimi-codex/dist/rescue-approval.js +461 -84
  132. package/plugins/kimi-codex/dist/schemas/review-gate-output.js +3 -5
  133. package/plugins/kimi-codex/dist/session-title.js +25 -5
  134. package/plugins/kimi-codex/dist/stream-json.js +1 -3
  135. package/plugins/kimi-codex/dist/surface-routing.js +21 -0
  136. package/plugins/kimi-codex/dist/swarm-activation.js +72 -75
  137. package/plugins/kimi-codex/dist/swarm-policy.js +2 -1
  138. package/plugins/kimi-codex/dist/swarm-recovery.js +2 -1
  139. package/plugins/kimi-codex/dist/util.js +28 -0
  140. package/plugins/kimi-codex/dist/version.js +1 -1
  141. package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +1 -1
  142. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +8 -7
  143. package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +1 -1
  144. package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +2 -1
  145. package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +8 -6
  146. package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +1 -1
  147. package/plugins/kimi-codex/skills/{kimi-ask → kimi-task}/SKILL.md +11 -9
  148. package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +6 -0
  149. package/plugins/kimi-dsh/README.md +3 -2
  150. package/plugins/kimi-dsh/dist/background-spawn.js +10 -17
  151. package/plugins/kimi-dsh/dist/cli-client.js +65 -46
  152. package/plugins/kimi-dsh/dist/commands/ask.js +22 -89
  153. package/plugins/kimi-dsh/dist/commands/cancel.js +7 -46
  154. package/plugins/kimi-dsh/dist/commands/cli-helpers.js +102 -1
  155. package/plugins/kimi-dsh/dist/commands/models.js +2 -3
  156. package/plugins/kimi-dsh/dist/commands/pursue.js +5 -19
  157. package/plugins/kimi-dsh/dist/commands/repair-sessions.js +118 -12
  158. package/plugins/kimi-dsh/dist/commands/rescue.js +12 -82
  159. package/plugins/kimi-dsh/dist/commands/result.js +7 -1
  160. package/plugins/kimi-dsh/dist/commands/review-gate.js +1 -0
  161. package/plugins/kimi-dsh/dist/commands/review.js +12 -15
  162. package/plugins/kimi-dsh/dist/commands/setup.js +606 -270
  163. package/plugins/kimi-dsh/dist/commands/status.js +2 -2
  164. package/plugins/kimi-dsh/dist/commands/swarm.js +93 -119
  165. package/plugins/kimi-dsh/dist/commands/worker.js +1 -2
  166. package/plugins/kimi-dsh/dist/companion.js +3 -1
  167. package/plugins/kimi-dsh/dist/dsh/index.js +15 -17
  168. package/plugins/kimi-dsh/dist/git.js +1 -9
  169. package/plugins/kimi-dsh/dist/help.js +3 -3
  170. package/plugins/kimi-dsh/dist/hooks/approval-hook.js +41 -0
  171. package/plugins/kimi-dsh/dist/hooks/approval-policy.js +72 -10
  172. package/plugins/kimi-dsh/dist/hooks/config-safety.js +19 -43
  173. package/plugins/kimi-dsh/dist/hooks/hook-timing.js +48 -0
  174. package/plugins/kimi-dsh/dist/hooks/install.js +206 -11
  175. package/plugins/kimi-dsh/dist/hooks/managed-block.js +78 -33
  176. package/plugins/kimi-dsh/dist/job-store.js +100 -128
  177. package/plugins/kimi-dsh/dist/jobs.js +14 -19
  178. package/plugins/kimi-dsh/dist/kimi-command.js +74 -1
  179. package/plugins/kimi-dsh/dist/kimi-engine.js +170 -75
  180. package/plugins/kimi-dsh/dist/kimi-errors.js +14 -69
  181. package/plugins/kimi-dsh/dist/kimi-home.js +6 -0
  182. package/plugins/kimi-dsh/dist/kimi-journal.js +41 -0
  183. package/plugins/kimi-dsh/dist/kimi-releases.js +144 -0
  184. package/plugins/kimi-dsh/dist/kimi-timeouts.js +1 -1
  185. package/plugins/kimi-dsh/dist/kimi-version-probe.js +12 -48
  186. package/plugins/kimi-dsh/dist/mcp/job-control.js +4 -6
  187. package/plugins/kimi-dsh/dist/mcp/launcher.js +12 -6
  188. package/plugins/kimi-dsh/dist/mcp/operations.js +50 -18
  189. package/plugins/kimi-dsh/dist/mcp/protocol.js +16 -14
  190. package/plugins/kimi-dsh/dist/mcp/stdio.js +3 -2
  191. package/plugins/kimi-dsh/dist/model-command.js +5 -3
  192. package/plugins/kimi-dsh/dist/native-v2-preflight.js +139 -68
  193. package/plugins/kimi-dsh/dist/parsing.js +171 -237
  194. package/plugins/kimi-dsh/dist/paths.js +8 -0
  195. package/plugins/kimi-dsh/dist/process-tree.js +35 -24
  196. package/plugins/kimi-dsh/dist/read-scope.js +435 -0
  197. package/plugins/kimi-dsh/dist/render.js +46 -9
  198. package/plugins/kimi-dsh/dist/rescue-approval.js +461 -84
  199. package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +3 -5
  200. package/plugins/kimi-dsh/dist/session-title.js +25 -5
  201. package/plugins/kimi-dsh/dist/stream-json.js +1 -3
  202. package/plugins/kimi-dsh/dist/surface-routing.js +21 -0
  203. package/plugins/kimi-dsh/dist/swarm-activation.js +72 -75
  204. package/plugins/kimi-dsh/dist/swarm-policy.js +2 -1
  205. package/plugins/kimi-dsh/dist/swarm-recovery.js +2 -1
  206. package/plugins/kimi-dsh/dist/util.js +28 -0
  207. package/plugins/kimi-dsh/dist/version.js +1 -1
  208. package/plugins/kimi-dsh/package.json +1 -1
  209. package/agents/kimi-challenge.md +0 -86
  210. package/agents/kimi-rescue.md +0 -92
  211. package/agents/kimi-swarm-write.md +0 -96
  212. package/commands/ask.md +0 -38
  213. package/commands/challenge.md +0 -35
  214. package/dist/commands/not-implemented.js +0 -4
  215. package/plugins/kimi-codex/dist/commands/not-implemented.js +0 -4
  216. package/plugins/kimi-codex/skills/kimi-ask/agents/openai.yaml +0 -6
  217. package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +0 -34
  218. package/plugins/kimi-codex/skills/kimi-challenge/agents/openai.yaml +0 -6
  219. package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +0 -34
  220. package/plugins/kimi-codex/skills/kimi-rescue/agents/openai.yaml +0 -6
  221. package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +0 -36
  222. package/plugins/kimi-codex/skills/kimi-swarm-write/agents/openai.yaml +0 -6
  223. package/plugins/kimi-dsh/dist/commands/not-implemented.js +0 -4
@@ -1,8 +1,11 @@
1
1
  import { RuntimeError } from "../errors.js";
2
2
  import { ResponseTimeoutError } from "../cli-client.js";
3
- import { observedExecutionFields } from "../kimi-engine.js";
3
+ import { observedExecutionFields, reconcileHistoricalJobProvenance } from "../kimi-engine.js";
4
+ import { capitalize } from "../render.js";
4
5
  import { resolveKimiHome } from "../kimi-home.js";
5
6
  import { recoverSessionIdFromStore } from "../session-recovery.js";
7
+ import { effectiveReadRoots, parseJobReadScope, rootsWithin } from "../read-scope.js";
8
+ import { hookGateRefusal, verifyHookInstalled } from "../hooks/install.js";
6
9
  import { formatBudgetDuration } from "../render.js";
7
10
  /**
8
11
  * Reassemble prose final text from cli-client records.
@@ -199,3 +202,101 @@ export function warnInheritedBudget(job, stderr) {
199
202
  stderr.write(`[${job.command_type}] budget ${formatBudgetDuration(job.budget_ms)} inherited from job ${job.resumed_from_job_id}; pass --budget to override\n`);
200
203
  }
201
204
  }
205
+ /** Resolve `--resume <job-or-session>` or `-r` for ask and rescue; fresh otherwise. */
206
+ export async function resolveResumeSession(store, kind, repoId, options) {
207
+ if (options.fresh || (!options.resumeTarget && !options.resume)) {
208
+ return { kimiSessionId: null, reusedSession: false, resumedFromJobId: null, sourceJob: null };
209
+ }
210
+ const stem = kind.toUpperCase();
211
+ let candidate;
212
+ let notFoundMessage;
213
+ if (options.resumeTarget) {
214
+ const byJob = store.getJob(options.resumeTarget);
215
+ const scoped = byJob?.repo_id === repoId && byJob.command_type === kind ? byJob : null;
216
+ candidate = scoped ?? (kind === "ask"
217
+ ? store.findAskJobBySession(repoId, options.resumeTarget)
218
+ : store.findRescueJobBySession(repoId, options.resumeTarget));
219
+ notFoundMessage = `No ${kind} job or session matched ${options.resumeTarget}.`;
220
+ }
221
+ else {
222
+ candidate = store.findLatestJob({ repoId, commandType: kind });
223
+ notFoundMessage = `No prior ${kind} session exists for this repository.`;
224
+ }
225
+ if (!candidate) {
226
+ throw new RuntimeError(`${stem}_RESUME_NOT_FOUND`, notFoundMessage, `${kind}.resume`);
227
+ }
228
+ // Report ALREADY_RUNNING before a missing session id: a running row can
229
+ // still have kimi_session_id = NULL because kimi-code assigns it later.
230
+ const source = await reconcileHistoricalJobProvenance(store, candidate);
231
+ if (source.status === "running") {
232
+ throw new RuntimeError(`${stem}_ALREADY_RUNNING`, `${capitalize(kind)} session ${source.kimi_session_id ?? "<unknown>"} is already active under job ${source.job_id}.`, `${kind}.resume`);
233
+ }
234
+ if (!source.kimi_session_id) {
235
+ throw new RuntimeError(`${stem}_RESUME_NOT_FOUND`, notFoundMessage, `${kind}.resume`);
236
+ }
237
+ return {
238
+ kimiSessionId: source.kimi_session_id,
239
+ reusedSession: true,
240
+ resumedFromJobId: source.job_id,
241
+ sourceJob: source,
242
+ };
243
+ }
244
+ /**
245
+ * --network on a resumed session must not send out what an earlier turn
246
+ * read. Every job recorded for the session, and every job on the source's
247
+ * resume chain, must have run confined to roots inside `currentRoots`.
248
+ * No recorded history, a broken chain or an unreadable scope counts as
249
+ * unconfined.
250
+ */
251
+ export function assertNetworkResumeConfined(store, kind, resolution, currentRoots) {
252
+ if (!resolution.reusedSession)
253
+ return;
254
+ const sessionId = resolution.kimiSessionId;
255
+ // Each earlier turn's reads stay in the conversation, so each earlier
256
+ // turn's roots must lie inside this call's roots.
257
+ const confinedWithin = (job) => {
258
+ if (job === null || job.read_scope == null)
259
+ return false;
260
+ try {
261
+ const scope = parseJobReadScope(job.read_scope);
262
+ return scope !== undefined && rootsWithin(effectiveReadRoots(scope, job.cwd), currentRoots);
263
+ }
264
+ catch {
265
+ return false;
266
+ }
267
+ };
268
+ const history = sessionId ? store.listJobsBySessionId(sessionId) : [];
269
+ let confined = history.length > 0 && history.every(confinedWithin);
270
+ const seen = new Set();
271
+ for (let jobId = resolution.sourceJob?.job_id; confined && jobId;) {
272
+ if (seen.has(jobId))
273
+ break;
274
+ seen.add(jobId);
275
+ const job = store.getJob(jobId);
276
+ confined = confinedWithin(job);
277
+ jobId = job?.resumed_from_job_id;
278
+ }
279
+ if (!confined) {
280
+ throw new RuntimeError("INVALID_ARGS", `${kind} --network cannot resume session ${sessionId ?? "<unknown>"}: an earlier turn in it ran without confined reads, or could read outside this call's workspace and --read-root directories (or its history is not recorded), so those reads could be sent out. ` +
281
+ `Start a fresh session instead: ${kind} --fresh --network [--read-root <dir>] <prompt>.`, `${kind}.resume`);
282
+ }
283
+ }
284
+ /** An explicit budget wins; otherwise a resume inherits its same-operation source's budget. */
285
+ export function resumeBudget(kind, explicitMs, source) {
286
+ const inherited = source?.operation_kind === kind ? source.budget_ms : null;
287
+ return {
288
+ budget_ms: explicitMs ?? inherited ?? null,
289
+ budget_source: explicitMs !== undefined ? "explicit" : inherited !== null ? "inherited" : "default",
290
+ };
291
+ }
292
+ export { READ_ONLY_HOOK_REPAIR, WRITE_HOOK_REPAIR } from "../hooks/install.js";
293
+ /**
294
+ * Verify the managed PreToolUse hook. Returns null when it is installed;
295
+ * otherwise warns once on stderr and returns `operation`'s gate refusal.
296
+ */
297
+ export async function hookRefusal(context, operation) {
298
+ const installStatus = await verifyHookInstalled(context.env);
299
+ if (installStatus.installed)
300
+ return null;
301
+ return hookGateRefusal(operation, installStatus, context.env, context.stderr);
302
+ }
@@ -1,15 +1,14 @@
1
1
  import { constants } from "node:fs";
2
2
  import { open } from "node:fs/promises";
3
- import path from "node:path";
4
3
  import { RuntimeError } from "../errors.js";
5
- import { resolveKimiHome } from "../kimi-home.js";
4
+ import { resolveKimiCodeConfigPath } from "../kimi-home.js";
6
5
  import { upstreamSnakeToCamel } from "../native-v2-preflight.js";
7
6
  import { parse as parseToml } from "../vendor/smol-toml/parse.js";
8
7
  export async function runModelInventory(argv, context) {
9
8
  if (argv.length > 1 || (argv.length === 1 && argv[0] !== "--json")) {
10
9
  throw new RuntimeError("INVALID_ARGS", "Use setup --models [--json] without other setup flags.", "setup.models");
11
10
  }
12
- const configPath = path.join(resolveKimiHome(context.env, context.cwd), "config.toml");
11
+ const configPath = resolveKimiCodeConfigPath(context.env, context.cwd);
13
12
  let config = {};
14
13
  let configPresent = true;
15
14
  try {
@@ -13,9 +13,9 @@ import { writeInvocationLogHeader } from "../logging.js";
13
13
  import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
14
14
  import { parsePursueArgs } from "../parsing.js";
15
15
  import { readArtifact, renderManagedJobOutput, writeArtifact } from "../render.js";
16
- import { hookRefusalDetails, hookRefusalRetryProtocol, maybeWarnHookMissing, verifyHookInstalled, } from "../hooks/install.js";
17
- import { assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes } from "./cli-helpers.js";
16
+ import { assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes, hookRefusal } from "./cli-helpers.js";
18
17
  import { buildKimiSessionTitle, syncKimiSessionTitle } from "../session-title.js";
18
+ import { shorten } from "../util.js";
19
19
  // /kimi:pursue — experimental autonomous goal mode (kimi-code 0.8.0+).
20
20
  // Runtime-foreground-only, with a mandatory finite wall-clock budget. No resume:
21
21
  // goalId is distinct from sessionId. Rescue lineage and the "rescue" hook label
@@ -120,6 +120,7 @@ export async function runPursue(argv, context) {
120
120
  operationKind: "pursue",
121
121
  cwd: context.cwd,
122
122
  env: context.env,
123
+ stderr: context.stderr,
123
124
  });
124
125
  const prompt = buildGoalPrompt(objective, parsed.turns);
125
126
  const jobId = allocateJobId(context);
@@ -184,16 +185,8 @@ async function executePursueJob(jobId, prompt, objective, budgetMs, context) {
184
185
  // exactly like rescue. The hook gates every tool call in every goal
185
186
  // continuation turn; without it, kimi -p auto-approves destructive ops.
186
187
  if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
187
- const installStatus = await verifyHookInstalled(context.env);
188
- if (!installStatus.installed) {
189
- maybeWarnHookMissing(installStatus, "rescue", context.stderr);
190
- const classified = new RuntimeError("PURSUE_HOOK_NOT_INSTALLED", [
191
- "/kimi:pursue refuses to run without the kimi-plugin-cc PreToolUse hook.",
192
- `Hook check failed: ${installStatus.reason ?? "unknown"}.`,
193
- "Repair by running Claude Code /kimi:setup or Codex $kimi-setup, then retry.",
194
- "KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 is only for deliberate tests or diagnostics.",
195
- hookRefusalRetryProtocol(context.env),
196
- ].join(" "), "pursue.hook-check", { details: hookRefusalDetails(installStatus) });
188
+ const classified = await hookRefusal(context, "pursue");
189
+ if (classified) {
197
190
  try {
198
191
  return await markJobFailed(store, paths, job, classified, "Pursue failed.", { phase: "failed" });
199
192
  }
@@ -298,10 +291,3 @@ async function executePursueJob(jobId, prompt, objective, budgetMs, context) {
298
291
  store.close();
299
292
  }
300
293
  }
301
- function shorten(text, max) {
302
- const normalized = text.replace(/\s+/g, " ").trim();
303
- if (normalized.length <= max) {
304
- return normalized;
305
- }
306
- return `${normalized.slice(0, Math.max(0, max - 1)).trimEnd()}…`;
307
- }
@@ -8,6 +8,10 @@ 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 { askPromptSubject } from "./ask.js";
12
+ import { buildGoalPrompt } from "./pursue.js";
13
+ import { stripRescuePromptPrefix } from "./rescue.js";
14
+ import { buildSwarmPrompt, buildSwarmWritePrompt } from "./swarm.js";
11
15
  // Repair is deliberately finite and local. Stream logs may be very large, but
12
16
  // the spawn record follows the invocation header: read only a bounded prefix.
13
17
  const MAX_JOBS = 1000;
@@ -25,27 +29,46 @@ export async function runRepairSessions(argv, context) {
25
29
  const paths = resolvePluginPaths(context.env);
26
30
  const repoId = all ? undefined : (await resolveRepoIdentity(context.cwd)).repoId;
27
31
  const jobs = await readRepairJobs(paths.stateDbPath, repoId);
28
- const sessions = new Set();
29
- const results = [];
32
+ // Newest job first per session: it supplies the preview, while every
33
+ // verified prompt of the session counts as the plugin's own.
34
+ const sessions = new Map();
30
35
  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({
36
+ const sessionJobs = sessions.get(job.kimi_session_id);
37
+ if (sessionJobs)
38
+ sessionJobs.push(job);
39
+ else
40
+ sessions.set(job.kimi_session_id, [job]);
41
+ }
42
+ const results = [];
43
+ for (const [sessionId, [job, ...earlier]] of sessions) {
44
+ const prompt = await readVerifiedPrompt(job, paths.logsDir, paths.worktreesDir);
45
+ let status = "unavailable-verified-prompt";
46
+ if (prompt !== undefined) {
47
+ const raw = rawTaskTextFromSubmittedPrompt(job.operation_kind, prompt);
48
+ const own = [prompt];
49
+ if (raw !== undefined) {
50
+ for (const other of earlier) {
51
+ const otherPrompt = await readVerifiedPrompt(other, paths.logsDir, paths.worktreesDir);
52
+ if (otherPrompt !== undefined)
53
+ own.push(otherPrompt);
54
+ }
55
+ }
56
+ status = await syncKimiSessionTitle({
38
57
  env: context.env,
39
58
  cwd: job.cwd,
40
- sessionId: job.kimi_session_id,
59
+ sessionId,
41
60
  title: "",
42
- promptText,
61
+ // Without an exact raw-text derivation, only a missing preview is
62
+ // filled, with the verified prompt itself.
63
+ promptText: raw ?? prompt,
64
+ ownPrompts: raw === undefined ? [] : own,
43
65
  dryRun: !apply,
44
66
  preserveTitle: true,
45
67
  requireNativeV2: true,
46
68
  stderr: context.stderr,
47
69
  });
48
- results.push({ job_id: job.job_id, session_id: job.kimi_session_id, status });
70
+ }
71
+ results.push({ job_id: job.job_id, session_id: sessionId, status });
49
72
  }
50
73
  const counts = {};
51
74
  for (const { status } of results)
@@ -158,3 +181,86 @@ async function readVerifiedPrompt(job, logsDir, worktreesDir) {
158
181
  return undefined;
159
182
  }
160
183
  }
184
+ const TASK_SLOT = "\u0000kimi-plugin-cc-task\u0000";
185
+ /**
186
+ * Recover the raw task text a live run previews from its verified submitted
187
+ * prompt. Derivations are exact or absent: prompts from other plugin releases,
188
+ * ambiguous parameter choices and unknown operations return undefined.
189
+ */
190
+ export function rawTaskTextFromSubmittedPrompt(operationKind, prompt) {
191
+ switch (operationKind) {
192
+ case "ask":
193
+ return strippedOrUndefined(prompt, askPromptSubject(prompt));
194
+ case "rescue":
195
+ return strippedOrUndefined(prompt, stripRescuePromptPrefix(prompt));
196
+ case "pursue":
197
+ return uniqueInversion(prompt, [undefined, ...numbersAfter(prompt, /at most (\d+) turns/g)]
198
+ .map((turns) => (task) => buildGoalPrompt(task, turns)));
199
+ case "swarm":
200
+ case "swarm-write": {
201
+ const build = operationKind === "swarm" ? buildSwarmPrompt : buildSwarmWritePrompt;
202
+ const caps = [undefined, ...numbersAfter(prompt, /at most (\d+) subagents/g)];
203
+ const waves = [undefined, 1, ...numbersAfter(prompt, /at most (\d+) entries/g)];
204
+ return uniqueInversion(prompt, caps.flatMap((cap) => waves.map((wave) => (task) => build(task, cap, wave))));
205
+ }
206
+ case "review":
207
+ case "challenge":
208
+ return reviewTaskText(prompt);
209
+ default:
210
+ return undefined;
211
+ }
212
+ }
213
+ function strippedOrUndefined(prompt, stripped) {
214
+ return stripped !== prompt && stripped.trim() ? stripped : undefined;
215
+ }
216
+ function numbersAfter(prompt, pattern) {
217
+ return [...new Set([...prompt.matchAll(pattern)].map((match) => Number(match[1])))];
218
+ }
219
+ /**
220
+ * Split each candidate template around the task slot and require an exact
221
+ * rebuild. The template explaining the most prompt text wins (without --turns
222
+ * the turn guidance would otherwise read as objective); a tie is ambiguous.
223
+ */
224
+ function uniqueInversion(prompt, builders) {
225
+ let found = new Set();
226
+ let bestTemplate = -1;
227
+ for (const build of builders) {
228
+ try {
229
+ const template = build(TASK_SLOT);
230
+ const at = template.indexOf(TASK_SLOT);
231
+ if (at < 0)
232
+ continue;
233
+ const head = template.slice(0, at);
234
+ const tail = template.slice(at + TASK_SLOT.length);
235
+ if (prompt.length < head.length + tail.length || !prompt.startsWith(head) || !prompt.endsWith(tail))
236
+ continue;
237
+ const task = prompt.slice(head.length, prompt.length - tail.length);
238
+ if (!task.trim() || build(task) !== prompt || head.length + tail.length < bestTemplate)
239
+ continue;
240
+ if (head.length + tail.length > bestTemplate)
241
+ found = new Set();
242
+ bestTemplate = head.length + tail.length;
243
+ found.add(task);
244
+ }
245
+ catch {
246
+ continue;
247
+ }
248
+ }
249
+ return found.size === 1 ? [...found][0] : undefined;
250
+ }
251
+ // Mirrors the review/challenge preview built at the review.ts sync call; the
252
+ // review command tests pin the two against real submitted prompts.
253
+ const REVIEW_PROMPT_START = "Perform a read-only code review of the supplied repository changes.\n";
254
+ 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: /;
255
+ const REVIEW_FOCUS_LINE = "\nReview focus: ";
256
+ function reviewTaskText(prompt) {
257
+ if (!prompt.startsWith(REVIEW_PROMPT_START))
258
+ return undefined;
259
+ const target = REVIEW_TARGET_LINES.exec(prompt);
260
+ if (!target)
261
+ return undefined;
262
+ const header = prompt.slice(0, target.index);
263
+ const focusAt = header.indexOf(REVIEW_FOCUS_LINE);
264
+ const focus = focusAt < 0 ? undefined : header.slice(focusAt + REVIEW_FOCUS_LINE.length);
265
+ return `Review target: ${target[1]}${focus ? `. Focus: ${focus}` : ""}`;
266
+ }
@@ -16,10 +16,9 @@ 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 { shorten } from "../util.js";
23
22
  // "Continue working on the bug" verbs that auto-attach to the latest
24
23
  // rescue session. Documented UX trap: a prompt matching this pattern
25
24
  // will resume the most recent rescue session regardless of whether
@@ -51,12 +50,13 @@ export async function runRescue(argv, context) {
51
50
  const store = new JobStore(paths);
52
51
  try {
53
52
  await sweepStaleJobs(store, paths);
54
- const sessionResolution = await resolveRescueSession(store, repoIdentity.repoId, parsed.prompt, parsed.fresh, parsed.resume, parsed.resumeTarget);
53
+ const sessionResolution = await resolveRescueSession(store, repoIdentity.repoId, parsed);
55
54
  const prompt = buildRescuePrompt(parsed.prompt, sessionResolution.reusedSession);
56
55
  const executionPlan = await prepareKimiExecutionPlan({
57
56
  operationKind: "rescue",
58
57
  cwd: context.cwd,
59
58
  env: context.env,
59
+ stderr: context.stderr,
60
60
  resumedFromJobId: sessionResolution.resumedFromJobId,
61
61
  resumeSessionId: sessionResolution.kimiSessionId ?? undefined,
62
62
  resumeSource: sessionResolution.sourceJob,
@@ -72,9 +72,7 @@ export async function runRescue(argv, context) {
72
72
  thinking: null,
73
73
  thinking_effort: parsed.thinkingEffort ?? null,
74
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",
75
+ ...resumeBudget("rescue", parsed.budgetMs, sessionResolution.sourceJob),
78
76
  pid: parsed.background ? null : process.pid,
79
77
  kimi_pid: null,
80
78
  status: "running",
@@ -106,16 +104,7 @@ export async function runRescue(argv, context) {
106
104
  return startBackgroundJob(job, prompt, context, paths, {
107
105
  workerKind: "rescue",
108
106
  wait: parsed.wait,
109
- promptEnvVar: "KIMI_PLUGIN_CC_RESCUE_PROMPT_B64",
110
- reusedSessionEnvVar: "KIMI_PLUGIN_CC_RESCUE_REUSED_SESSION",
111
- reusedSession: sessionResolution.reusedSession,
112
107
  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
108
  });
120
109
  }
121
110
  const completed = await executeRescueJob(job.job_id, prompt, context);
@@ -147,16 +136,8 @@ export async function executeRescueJob(jobId, prompt, context, options) {
147
136
  // an early return doesn't leak SIGTERM/SIGINT listeners. Tests /
148
137
  // setup probes / intentional bypass: KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1.
149
138
  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) });
139
+ const classified = await hookRefusal(context, "rescue");
140
+ if (classified) {
160
141
  try {
161
142
  return await markJobFailed(store, paths, job, classified, cancel.failedSummary, { phase: "failed" });
162
143
  }
@@ -207,7 +188,7 @@ export async function executeRescueJob(jobId, prompt, context, options) {
207
188
  store.updateRunningJob(job.job_id, { kimi_session_id_source: "announced", kimi_session_id: result.sessionId });
208
189
  }
209
190
  await syncKimiSessionTitle({
210
- promptText: prompt,
191
+ promptText: stripRescuePromptPrefix(prompt),
211
192
  env: context.env,
212
193
  cwd: job.cwd,
213
194
  sessionId: result.sessionId ?? job.kimi_session_id,
@@ -276,50 +257,11 @@ function buildRescuePrompt(prompt, reusedSession) {
276
257
  }
277
258
  throw new RuntimeError("INVALID_ARGS", "rescue requires a task description.", "rescue.parse");
278
259
  }
279
- function stripRescuePromptPrefix(prompt) {
260
+ export function stripRescuePromptPrefix(prompt) {
280
261
  return prompt.startsWith(RESCUE_PROMPT_PREFIX) ? prompt.slice(RESCUE_PROMPT_PREFIX.length) : prompt;
281
262
  }
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)) {
263
+ async function resolveRescueSession(store, repoId, parsed) {
264
+ if (!parsed.fresh && !parsed.resumeTarget && !parsed.resume && parsed.prompt && AUTO_RESUME_PATTERN.test(parsed.prompt)) {
323
265
  const latest = store.findLatestJob({ repoId, commandType: "rescue" });
324
266
  if (latest?.kimi_session_id && latest.status !== "running") {
325
267
  const source = await reconcileHistoricalJobProvenance(store, latest);
@@ -331,17 +273,5 @@ async function resolveRescueSession(store, repoId, prompt, fresh, resume, resume
331
273
  };
332
274
  }
333
275
  }
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()}…`;
276
+ return resolveResumeSession(store, "rescue", repoId, parsed);
347
277
  }
@@ -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
+ }
@@ -127,6 +127,7 @@ async function executeReviewGate(payload, assistantMessage, context) {
127
127
  operationKind: "review_gate",
128
128
  cwd: payload.cwd,
129
129
  env: context.env,
130
+ stderr: context.stderr,
130
131
  });
131
132
  // Header-before-job-row mirrors v0.4's reordering (the comment
132
133
  // chain there explains why). If the disk-bound writeInvocationLogHeader
@@ -13,11 +13,11 @@ 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
22
  const REVIEW_AGENT_PROFILE_PLACEHOLDER = "<cli-client>";
23
23
  export async function runReview(argv, context, commandType) {
@@ -25,6 +25,8 @@ export async function runReview(argv, context, commandType) {
25
25
  if (parsed.background || parsed.wait) {
26
26
  throw new RuntimeError("INVALID_FLAGS", `${commandType} does not support --background or --wait in v1; review runs foreground-synchronously.`, `${commandType}.parse`);
27
27
  }
28
+ const readScope = parsed.readRoots === undefined && parsed.network === undefined ? undefined
29
+ : await resolveReadScope(parsed.readRoots, parsed.network, `${commandType}.parse`);
28
30
  if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
29
31
  await requireReadOnlyHookInstalled(context, commandType);
30
32
  }
@@ -36,7 +38,9 @@ export async function runReview(argv, context, commandType) {
36
38
  operationKind: commandType,
37
39
  cwd: context.cwd,
38
40
  env: context.env,
41
+ stderr: context.stderr,
39
42
  });
43
+ assertScopeSupported(readScope, executionPlan.certification, "INVALID_ARGS", `${commandType}.parse`);
40
44
  const store = new JobStore(paths);
41
45
  const jobId = allocateJobId(context);
42
46
  // Leave kimi_session_id NULL until kimi announces an actual ID; never invent
@@ -52,6 +56,7 @@ export async function runReview(argv, context, commandType) {
52
56
  model: parsed.model ?? null,
53
57
  thinking: null,
54
58
  thinking_effort: parsed.thinkingEffort ?? null,
59
+ read_scope: serializeReadScope(readScope),
55
60
  background: false,
56
61
  budget_ms: parsed.budgetMs ?? null,
57
62
  budget_source: parsed.budgetMs !== undefined ? "explicit" : "default",
@@ -87,6 +92,7 @@ export async function runReview(argv, context, commandType) {
87
92
  commandLabel: commandType,
88
93
  model: parsed.model,
89
94
  thinkingEffort: parsed.thinkingEffort,
95
+ readScope,
90
96
  logPath,
91
97
  onSpawn: (pid) => { store.updateRunningJob(job.job_id, { kimi_pid: pid }); },
92
98
  signal: handlers.signal,
@@ -105,7 +111,7 @@ export async function runReview(argv, context, commandType) {
105
111
  store.updateRunningJob(job.job_id, { kimi_session_id_source: "announced", kimi_session_id: result.sessionId });
106
112
  }
107
113
  await syncKimiSessionTitle({
108
- promptText: previewPrompt,
114
+ promptText: `Review target: ${reviewContext.targetDescription}${parsed.focus ? `. Focus: ${parsed.focus}` : ""}`,
109
115
  env: context.env,
110
116
  cwd: job.cwd,
111
117
  sessionId: result.sessionId ?? job.kimi_session_id,
@@ -152,18 +158,9 @@ async function requireReadOnlyHookInstalled(context, commandType) {
152
158
  if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK === "1") {
153
159
  return;
154
160
  }
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) });
161
+ const refusal = await hookRefusal(context, commandType);
162
+ if (refusal)
163
+ throw refusal;
167
164
  }
168
165
  function buildReviewPrompt(commandType, reviewContext, focus) {
169
166
  const modeInstructions = commandType === "challenge"