kimi-plugin-cc 3.0.0 → 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 (281) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +3 -14
  3. package/README.md +428 -572
  4. package/assets/logo.svg +6 -0
  5. package/cordis.patch.yml +18 -0
  6. package/dist/background-spawn.js +4 -2
  7. package/dist/cli-client.js +105 -66
  8. package/dist/commands/ask.js +27 -12
  9. package/dist/commands/cancel.js +4 -13
  10. package/dist/commands/cli-helpers.js +1 -1
  11. package/dist/commands/pursue.js +3 -2
  12. package/dist/commands/registry.js +7 -26
  13. package/dist/commands/repair-sessions.js +7 -4
  14. package/dist/commands/replay.js +4 -3
  15. package/dist/commands/rescue.js +17 -5
  16. package/dist/commands/review.js +18 -5
  17. package/dist/commands/setup.js +277 -262
  18. package/dist/commands/swarm.js +20 -7
  19. package/dist/companion.js +142 -18
  20. package/dist/help.js +11 -7
  21. package/dist/hook-escape.js +7 -16
  22. package/dist/hooks/approval-hook.js +1762 -124
  23. package/dist/hooks/approval-policy.js +15 -10
  24. package/dist/hooks/config-safety.js +15 -24
  25. package/dist/hooks/hook-timing.js +1 -1
  26. package/dist/hooks/install-paths.js +179 -107
  27. package/dist/hooks/install.js +44 -166
  28. package/dist/hooks/managed-block.js +44 -95
  29. package/dist/job-store.js +117 -49
  30. package/dist/jobs.js +53 -1
  31. package/dist/kimi-engine.js +68 -92
  32. package/dist/kimi-errors.js +1 -1
  33. package/dist/kimi-journal.js +3 -2
  34. package/dist/kimi-releases.js +28 -49
  35. package/dist/kimi-timeouts.js +1 -15
  36. package/dist/kimi-version-probe.js +24 -72
  37. package/dist/logging.js +12 -7
  38. package/dist/mcp/binding.js +13 -4
  39. package/dist/mcp/job-control.js +386 -89
  40. package/dist/mcp/launcher.js +1 -1
  41. package/dist/mcp/operations.js +387 -193
  42. package/dist/mcp/protocol.js +116 -27
  43. package/dist/mcp/skills.js +130 -0
  44. package/dist/mcp/stdio.js +15 -2
  45. package/dist/native-v2-preflight.js +127 -35
  46. package/dist/parsing.js +45 -11
  47. package/dist/paths.js +20 -10
  48. package/dist/plugin-data.js +28 -83
  49. package/dist/read-scope.js +2 -2
  50. package/dist/render.js +13 -38
  51. package/dist/session-references.js +216 -0
  52. package/dist/session-title.js +1 -1
  53. package/dist/surface-routing.js +92 -5
  54. package/dist/swarm-activation.js +26 -137
  55. package/dist/version.js +1 -1
  56. package/docs/migration.md +45 -227
  57. package/docs/models.md +24 -66
  58. package/docs/safety.md +195 -400
  59. package/docs/session-visibility.md +24 -14
  60. package/docs/swarm-recovery.md +26 -20
  61. package/dsh/index.json +54 -0
  62. package/mcp_config.json +10 -0
  63. package/package.json +23 -82
  64. package/plugin.json +19 -0
  65. package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
  66. package/plugins/kimi-codex/.mcp.json +2 -3
  67. package/plugins/kimi-codex/dist/background-spawn.js +4 -2
  68. package/plugins/kimi-codex/dist/cli-client.js +105 -66
  69. package/plugins/kimi-codex/dist/commands/ask.js +27 -12
  70. package/plugins/kimi-codex/dist/commands/cancel.js +4 -13
  71. package/plugins/kimi-codex/dist/commands/cli-helpers.js +1 -1
  72. package/plugins/kimi-codex/dist/commands/pursue.js +3 -2
  73. package/plugins/kimi-codex/dist/commands/registry.js +7 -26
  74. package/plugins/kimi-codex/dist/commands/repair-sessions.js +7 -4
  75. package/plugins/kimi-codex/dist/commands/replay.js +4 -3
  76. package/plugins/kimi-codex/dist/commands/rescue.js +17 -5
  77. package/plugins/kimi-codex/dist/commands/review.js +18 -5
  78. package/plugins/kimi-codex/dist/commands/setup.js +277 -262
  79. package/plugins/kimi-codex/dist/commands/swarm.js +20 -7
  80. package/plugins/kimi-codex/dist/companion.js +142 -18
  81. package/plugins/kimi-codex/dist/help.js +11 -7
  82. package/plugins/kimi-codex/dist/hook-escape.js +7 -16
  83. package/plugins/kimi-codex/dist/hooks/approval-hook.js +1762 -124
  84. package/plugins/kimi-codex/dist/hooks/approval-policy.js +15 -10
  85. package/plugins/kimi-codex/dist/hooks/config-safety.js +15 -24
  86. package/plugins/kimi-codex/dist/hooks/hook-timing.js +1 -1
  87. package/plugins/kimi-codex/dist/hooks/install-paths.js +179 -107
  88. package/plugins/kimi-codex/dist/hooks/install.js +44 -166
  89. package/plugins/kimi-codex/dist/hooks/managed-block.js +44 -95
  90. package/plugins/kimi-codex/dist/job-store.js +117 -49
  91. package/plugins/kimi-codex/dist/jobs.js +53 -1
  92. package/plugins/kimi-codex/dist/kimi-engine.js +68 -92
  93. package/plugins/kimi-codex/dist/kimi-errors.js +1 -1
  94. package/plugins/kimi-codex/dist/kimi-journal.js +3 -2
  95. package/plugins/kimi-codex/dist/kimi-releases.js +28 -49
  96. package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -15
  97. package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -72
  98. package/plugins/kimi-codex/dist/logging.js +12 -7
  99. package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
  100. package/plugins/kimi-codex/dist/mcp/job-control.js +386 -89
  101. package/plugins/kimi-codex/dist/mcp/launcher.js +1 -1
  102. package/plugins/kimi-codex/dist/mcp/operations.js +387 -193
  103. package/plugins/kimi-codex/dist/mcp/protocol.js +116 -27
  104. package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
  105. package/plugins/kimi-codex/dist/mcp/stdio.js +15 -2
  106. package/plugins/kimi-codex/dist/native-v2-preflight.js +127 -35
  107. package/plugins/kimi-codex/dist/parsing.js +45 -11
  108. package/plugins/kimi-codex/dist/paths.js +20 -10
  109. package/plugins/kimi-codex/dist/plugin-data.js +28 -83
  110. package/plugins/kimi-codex/dist/read-scope.js +2 -2
  111. package/plugins/kimi-codex/dist/render.js +13 -38
  112. package/plugins/kimi-codex/dist/session-references.js +216 -0
  113. package/plugins/kimi-codex/dist/session-title.js +1 -1
  114. package/plugins/kimi-codex/dist/surface-routing.js +92 -5
  115. package/plugins/kimi-codex/dist/swarm-activation.js +26 -137
  116. package/plugins/kimi-codex/dist/version.js +1 -1
  117. package/plugins/kimi-codex/scripts/companion.sh +4 -15
  118. package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
  119. package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
  120. package/scripts/companion.sh +4 -15
  121. package/skills/kimi/SKILL.md +77 -0
  122. package/skills/kimi/agents/openai.yaml +6 -0
  123. package/CHANGELOG.md +0 -1402
  124. package/agents/kimi-pursue.md +0 -93
  125. package/agents/kimi-review.md +0 -86
  126. package/agents/kimi-swarm.md +0 -88
  127. package/agents/kimi-task.md +0 -93
  128. package/commands/README.md +0 -14
  129. package/commands/cancel.md +0 -17
  130. package/commands/pursue.md +0 -41
  131. package/commands/replay.md +0 -13
  132. package/commands/result.md +0 -13
  133. package/commands/review.md +0 -40
  134. package/commands/setup.md +0 -25
  135. package/commands/status.md +0 -13
  136. package/commands/swarm.md +0 -45
  137. package/commands/task.md +0 -40
  138. package/dist/commands/review-gate.js +0 -391
  139. package/dist/config.js +0 -22
  140. package/dist/dsh/companion.js +0 -177
  141. package/dist/dsh/index.js +0 -167
  142. package/dist/hooks/review-gate-stop.js +0 -19
  143. package/dist/schemas/review-gate-output.js +0 -41
  144. package/docs/registry-releases.md +0 -228
  145. package/docs/upstream-2.4.1-certification.md +0 -54
  146. package/docs/upstream-2.5.0-certification.md +0 -52
  147. package/docs/upstream-2.5.1-certification.md +0 -47
  148. package/docs/upstream-2.5.2-certification.md +0 -40
  149. package/docs/upstream-2.5.3-certification.md +0 -73
  150. package/docs/upstream-2.6.0-certification.md +0 -65
  151. package/docs/upstream-2.6.2-certification.md +0 -144
  152. package/docs/upstream-2.6.3-certification.md +0 -100
  153. package/docs/upstream-2.7.2-certification.md +0 -113
  154. package/docs/upstream-2.7.3-certification.md +0 -95
  155. package/docs/windows-validation.md +0 -39
  156. package/hooks/README.md +0 -9
  157. package/hooks/hooks.json +0 -16
  158. package/plugins/kimi-codex/dist/commands/review-gate.js +0 -391
  159. package/plugins/kimi-codex/dist/config.js +0 -22
  160. package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
  161. package/plugins/kimi-codex/dist/dsh/index.js +0 -167
  162. package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
  163. package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -41
  164. package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
  165. package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
  166. package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
  167. package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
  168. package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
  169. package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
  170. package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
  171. package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
  172. package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
  173. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -35
  174. package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
  175. package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -35
  176. package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
  177. package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
  178. package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
  179. package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -37
  180. package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
  181. package/plugins/kimi-codex/skills/kimi-task/SKILL.md +0 -37
  182. package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +0 -6
  183. package/plugins/kimi-dsh/LICENSE +0 -201
  184. package/plugins/kimi-dsh/README.md +0 -84
  185. package/plugins/kimi-dsh/cordis.patch.yml +0 -45
  186. package/plugins/kimi-dsh/dist/background-spawn.js +0 -209
  187. package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
  188. package/plugins/kimi-dsh/dist/cli-client.js +0 -1097
  189. package/plugins/kimi-dsh/dist/commands/ask.js +0 -269
  190. package/plugins/kimi-dsh/dist/commands/cancel.js +0 -177
  191. package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -302
  192. package/plugins/kimi-dsh/dist/commands/models.js +0 -139
  193. package/plugins/kimi-dsh/dist/commands/pursue.js +0 -293
  194. package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
  195. package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
  196. package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -266
  197. package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
  198. package/plugins/kimi-dsh/dist/commands/rescue.js +0 -277
  199. package/plugins/kimi-dsh/dist/commands/result.js +0 -72
  200. package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -391
  201. package/plugins/kimi-dsh/dist/commands/review.js +0 -217
  202. package/plugins/kimi-dsh/dist/commands/setup.js +0 -1465
  203. package/plugins/kimi-dsh/dist/commands/status.js +0 -27
  204. package/plugins/kimi-dsh/dist/commands/swarm.js +0 -823
  205. package/plugins/kimi-dsh/dist/commands/worker.js +0 -24
  206. package/plugins/kimi-dsh/dist/companion.js +0 -99
  207. package/plugins/kimi-dsh/dist/config.js +0 -22
  208. package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
  209. package/plugins/kimi-dsh/dist/dsh/index.js +0 -167
  210. package/plugins/kimi-dsh/dist/errors.js +0 -40
  211. package/plugins/kimi-dsh/dist/git.js +0 -216
  212. package/plugins/kimi-dsh/dist/help.js +0 -43
  213. package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
  214. package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -145
  215. package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -295
  216. package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -641
  217. package/plugins/kimi-dsh/dist/hooks/hook-timing.js +0 -48
  218. package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
  219. package/plugins/kimi-dsh/dist/hooks/install.js +0 -405
  220. package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -729
  221. package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
  222. package/plugins/kimi-dsh/dist/job-id.js +0 -12
  223. package/plugins/kimi-dsh/dist/job-store.js +0 -631
  224. package/plugins/kimi-dsh/dist/jobs.js +0 -212
  225. package/plugins/kimi-dsh/dist/kimi-command.js +0 -144
  226. package/plugins/kimi-dsh/dist/kimi-engine.js +0 -770
  227. package/plugins/kimi-dsh/dist/kimi-errors.js +0 -205
  228. package/plugins/kimi-dsh/dist/kimi-home.js +0 -15
  229. package/plugins/kimi-dsh/dist/kimi-journal.js +0 -41
  230. package/plugins/kimi-dsh/dist/kimi-releases.js +0 -144
  231. package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
  232. package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -198
  233. package/plugins/kimi-dsh/dist/logging.js +0 -22
  234. package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
  235. package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -343
  236. package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -263
  237. package/plugins/kimi-dsh/dist/mcp/operations.js +0 -333
  238. package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -277
  239. package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
  240. package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -79
  241. package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
  242. package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
  243. package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
  244. package/plugins/kimi-dsh/dist/model-command.js +0 -34
  245. package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -596
  246. package/plugins/kimi-dsh/dist/package.json +0 -1
  247. package/plugins/kimi-dsh/dist/parsing.js +0 -554
  248. package/plugins/kimi-dsh/dist/paths.js +0 -35
  249. package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
  250. package/plugins/kimi-dsh/dist/process-tree.js +0 -597
  251. package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
  252. package/plugins/kimi-dsh/dist/read-scope.js +0 -435
  253. package/plugins/kimi-dsh/dist/render.js +0 -214
  254. package/plugins/kimi-dsh/dist/rescue-approval.js +0 -1242
  255. package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -41
  256. package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
  257. package/plugins/kimi-dsh/dist/session-title.js +0 -313
  258. package/plugins/kimi-dsh/dist/stream-json.js +0 -344
  259. package/plugins/kimi-dsh/dist/surface-routing.js +0 -21
  260. package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1194
  261. package/plugins/kimi-dsh/dist/swarm-policy.js +0 -74
  262. package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -166
  263. package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
  264. package/plugins/kimi-dsh/dist/types.js +0 -1
  265. package/plugins/kimi-dsh/dist/util.js +0 -28
  266. package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
  267. package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
  268. package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
  269. package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
  270. package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
  271. package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
  272. package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
  273. package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
  274. package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
  275. package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
  276. package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
  277. package/plugins/kimi-dsh/dist/version.js +0 -7
  278. package/plugins/kimi-dsh/package.json +0 -78
  279. package/plugins/kimi-dsh/scripts/companion.sh +0 -37
  280. package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
  281. package/scripts/review-gate-hook.sh +0 -32
@@ -29,7 +29,7 @@
29
29
  // - Refusals here are NOT /kimi:setup-recoverable and must never be
30
30
  // described as hook drift.
31
31
  import { constants as fsConstants } from "node:fs";
32
- import { open, readdir } from "node:fs/promises";
32
+ import { lstat, open, readdir } from "node:fs/promises";
33
33
  import path from "node:path";
34
34
  import { RuntimeError } from "./errors.js";
35
35
  import { kimiCodeConfigPath } from "./kimi-home.js";
@@ -44,7 +44,7 @@ const CONFIG_MAX_BYTES = 1 * 1024 * 1024;
44
44
  const JOURNAL_MAX_BYTES = 64 * 1024 * 1024;
45
45
  /** Bounded directory enumeration so a pathological sessions/ tree refuses
46
46
  * instead of scanning forever. */
47
- const DIR_ENUM_CAP = 4096;
47
+ export const DIR_ENUM_CAP = 4096;
48
48
  const TRUTHY_STRINGS = new Set(["1", "true", "yes", "on"]);
49
49
  function isTruthySelectorValue(value) {
50
50
  if (value === true)
@@ -58,7 +58,7 @@ function isTruthySelectorValue(value) {
58
58
  * config lock reader in runtime/hooks/config-safety.ts. Never partial-reads:
59
59
  * an oversized file refuses rather than being silently truncated.
60
60
  */
61
- async function readSmallFileSafe(filePath, maxBytes) {
61
+ export async function readSmallFileSafe(filePath, maxBytes) {
62
62
  let handle;
63
63
  try {
64
64
  handle = await open(filePath, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0) | (fsConstants.O_NONBLOCK ?? 0));
@@ -166,7 +166,7 @@ export async function inspectPlanModeConfig(kimiHome) {
166
166
  * sessionManagerService.openCreation, i.e. when a session is created. A fresh
167
167
  * print on a certified row passes `--environment local`, which skips the
168
168
  * declarations; a resume goes through doResume, which applies the session's
169
- * stored binding (state.json) and never consults the default (2.5.0-2.7.3).
169
+ * stored binding (state.json) and never consults the default (2.5.0-2.8.0).
170
170
  * The stored binding is checked separately by scanSessionJournalsForPlan, so
171
171
  * that one key stops refusing. A non-table section still refuses.
172
172
  */
@@ -219,8 +219,13 @@ export async function inspectEnvironmentConfig(kimiHome, options = {}) {
219
219
  return { kind: "ok" };
220
220
  }
221
221
  export const WORKSPACE_TRUST_DISABLED_WARNING = "Workspace trust is disabled in kimi-code's config: MCP servers configured by this repository can start outside the plugin's hook.";
222
+ /** Launch warning for an uncertified release with experimental selectors switched on. */
223
+ export function experimentalSelectorsWarning(selectors) {
224
+ return `kimi-code experimental features are switched on (${selectors.join(", ")}) and this kimi-code release is not certified by the plugin. The plugin starts Kimi with KIMI_CODE_EXPERIMENTAL_TOWER=0 and without KIMI_CODE_EXPERIMENTAL_FLAG; how this release reads them has not been reviewed.`;
225
+ }
222
226
  /**
223
- * Refuse v2-only experimental features this plugin does not certify.
227
+ * Find v2-only experimental features this plugin runs its tasks without.
228
+ * A plan-less launch refuses on them; an uncertified release only warns.
224
229
  * Sources (per-flag precedence upstream is env → [experimental] config →
225
230
  * master flag → default): the `[experimental]` table keys `tower` and
226
231
  * `subagent_fork` in `<kimiHome>/config.toml`, and the per-flag env vars
@@ -231,11 +236,22 @@ export const WORKSPACE_TRUST_DISABLED_WARNING = "Workspace trust is disabled in
231
236
  * Config read errors follow inspectPlanModeConfig's fail-closed rules.
232
237
  */
233
238
  export async function inspectExperimentalSelectors(kimiHome, env) {
239
+ return (await inspectExperimentalConfig(kimiHome, env)).inspection;
240
+ }
241
+ /**
242
+ * One read of the config for both answers: the two selectors a plan-less
243
+ * launch refuses on, and every selector the user switched on (truthy
244
+ * `[experimental]` keys and truthy `KIMI_CODE_EXPERIMENTAL_*` variables, the
245
+ * master flag included). An uncertified release's flag set is unreviewed, so
246
+ * its warning names them all, not only the two the plugin forces off.
247
+ */
248
+ async function inspectExperimentalConfig(kimiHome, env) {
234
249
  const parsed = await readParsedConfig(kimiHome);
235
250
  if (parsed.kind === "unreadable") {
236
- return { kind: "refuse", selectors: [], reason: parsed.reason };
251
+ return { inspection: { kind: "refuse", selectors: [], reason: parsed.reason }, switchedOn: [] };
237
252
  }
238
253
  const selectors = [];
254
+ const switchedOn = [];
239
255
  const experimental = parsed.config?.["experimental"];
240
256
  if (experimental !== null && typeof experimental === "object" && !Array.isArray(experimental)) {
241
257
  const table = experimental;
@@ -244,6 +260,10 @@ export async function inspectExperimentalSelectors(kimiHome, env) {
244
260
  if (isTruthySelectorValue(table["subagent_fork"])) {
245
261
  selectors.push("config:[experimental].subagent_fork");
246
262
  }
263
+ for (const [key, value] of Object.entries(table)) {
264
+ if (isTruthySelectorValue(value))
265
+ switchedOn.push(`config:[experimental].${key}`);
266
+ }
247
267
  }
248
268
  if (isTruthySelectorValue(env.KIMI_CODE_EXPERIMENTAL_TOWER)) {
249
269
  selectors.push("env:KIMI_CODE_EXPERIMENTAL_TOWER");
@@ -251,15 +271,34 @@ export async function inspectExperimentalSelectors(kimiHome, env) {
251
271
  if (isTruthySelectorValue(env.KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK)) {
252
272
  selectors.push("env:KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK");
253
273
  }
274
+ // Environment names are case-sensitive except on Windows, where Kimi reads any spelling.
275
+ const selectorName = (name) => (process.platform === "win32" ? name.toUpperCase() : name);
276
+ for (const [name, value] of Object.entries(env)) {
277
+ if (selectorName(name).startsWith("KIMI_CODE_EXPERIMENTAL_") && isTruthySelectorValue(value))
278
+ switchedOn.push(`env:${name}`);
279
+ }
254
280
  if (selectors.length === 0)
255
- return { kind: "ok" };
281
+ return { inspection: { kind: "ok" }, switchedOn };
256
282
  return {
257
- kind: "refuse",
258
- selectors,
259
- reason: `Refusing v2-only experimental feature(s) not certified by kimi-plugin-cc: ${selectors.join(", ")}.`,
283
+ inspection: {
284
+ kind: "refuse",
285
+ selectors,
286
+ reason: `Refusing v2-only experimental feature(s) not certified by kimi-plugin-cc: ${selectors.join(", ")}.`,
287
+ },
288
+ switchedOn,
260
289
  };
261
290
  }
262
- async function boundedReaddir(dirPath, cap) {
291
+ /** Device and inode of a directory, without following a final link; undefined when it cannot be read. */
292
+ async function directoryIdentity(directory) {
293
+ try {
294
+ const info = await lstat(directory, { bigint: true });
295
+ return info.isDirectory() ? `${info.dev}:${info.ino}` : undefined;
296
+ }
297
+ catch {
298
+ return undefined;
299
+ }
300
+ }
301
+ export async function boundedReaddir(dirPath, cap) {
263
302
  let entries;
264
303
  try {
265
304
  entries = await readdir(dirPath, { withFileTypes: true });
@@ -276,7 +315,8 @@ async function boundedReaddir(dirPath, cap) {
276
315
  return { kind: "cap-exceeded" };
277
316
  return { kind: "ok", entries };
278
317
  }
279
- async function openJournalSafely(journalPath, maxBytes) {
318
+ /** `maxBytes` omitted: no size cap (the caller never reads the content). */
319
+ export async function openJournalSafely(journalPath, maxBytes) {
280
320
  let handle;
281
321
  try {
282
322
  // O_NONBLOCK so a FIFO planted at the journal path (no writer) does not
@@ -297,7 +337,7 @@ async function openJournalSafely(journalPath, maxBytes) {
297
337
  await handle.close().catch(() => undefined);
298
338
  return { kind: "unavailable", reason: "journal is not a regular file" };
299
339
  }
300
- if (stats.size > BigInt(maxBytes)) {
340
+ if (maxBytes !== undefined && stats.size > BigInt(maxBytes)) {
301
341
  await handle.close().catch(() => undefined);
302
342
  return { kind: "unavailable", reason: `journal exceeds ${maxBytes} byte cap` };
303
343
  }
@@ -305,14 +345,25 @@ async function openJournalSafely(journalPath, maxBytes) {
305
345
  }
306
346
  /** Records that mean the session already did work: a turn, prompt, tool, model or delegated task. */
307
347
  const ACTIVITY_RECORD = /^(turn\.|prompt\.|tool\.|llm\.|shell\.|subagent\.|task\.|assistant\.|context\.append_message$|context\.append_loop_event$)/;
348
+ /**
349
+ * Records kimi may write between the create-time `plan_mode.enter` and print's
350
+ * `plan_mode.cancel` without doing work. These are kimi's three durable MCP
351
+ * events (2.8.0): its MCP service writes them on its own clock while servers
352
+ * connect, and each folds only into MCP discovery or failure state. Discovery
353
+ * was observed there on 2.8.0. Anything else between the two taints.
354
+ */
355
+ export const PLAN_PAIR_BOOKKEEPING = new Set([
356
+ "mcp.tools_discovered", "mcp.server_failed", "mcp.server_failure_resolved",
357
+ ]);
308
358
  /** Records that make replay non-linear (branch switch or undo), so a fold could differ. */
309
359
  const REWIND_RECORD = /^(agent\.switched$|context\.undo$|context\.undone$)/;
310
- async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelledDefaultEnter = false) {
360
+ async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelledDefaultEnter = false, main = false) {
311
361
  // G2: a print-created session's main journal holds the create-time
312
- // `default_plan_mode` enter immediately followed by print's id-less cancel,
313
- // before any work. On a linear journal that pair folds to inactive, so it
314
- // alone is tolerated; every other plan record, or that pair anywhere else,
315
- // still taints.
362
+ // `default_plan_mode` enter followed by print's id-less cancel, before any
363
+ // work. On a linear journal that pair folds to inactive, so it alone is
364
+ // tolerated; every other plan record, or that pair anywhere else, still
365
+ // taints. Bookkeeping records may sit between the two (2.8.0 journals MCP
366
+ // discovery there); work, a rewind or another plan record may not.
316
367
  // Replay stops at the first corrupt line, so records after it may add
317
368
  // taints (seeing more is conservative) but never start or complete a fold.
318
369
  let sawActivity = false;
@@ -320,10 +371,17 @@ async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelled
320
371
  let sawCorrupt = false;
321
372
  let pendingEnter = null;
322
373
  let toleratedPair = false;
374
+ // Restoring a session left in tower mode lets kimi adopt the workspace's
375
+ // `.tower` state without a tool call, whatever the tower flag says. Kimi
376
+ // folds tower state from the main journal only, takes a record with no
377
+ // agentId as the journal's own, ignores another agent's, and stops at the
378
+ // first corrupt line: an exit it will not replay must not clear the state.
379
+ let towerActive = false;
323
380
  const taintEnter = { kind: "tainted", recordType: "plan_mode.enter" };
324
381
  for await (const framed of kimiJournalRecords(handle.createReadStream())) {
325
382
  const { line, parsed } = framed;
326
383
  if (parsed === UNPARSEABLE_JOURNAL_LINE) {
384
+ const firstCorrupt = framed.terminated && !sawCorrupt;
327
385
  if (framed.terminated)
328
386
  sawCorrupt = true;
329
387
  if (pendingEnter !== null)
@@ -334,28 +392,44 @@ async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelled
334
392
  if (line.includes('"environment.set_binding')) {
335
393
  return { kind: "environment", recordType: "<unparseable-environment-binding>" };
336
394
  }
395
+ // Kimi drops a torn final line and stops replaying at the first complete
396
+ // corrupt one; that one line is read conservatively as an enter.
397
+ if (main && firstCorrupt && line.includes('"tower_mode.'))
398
+ towerActive = true;
337
399
  continue;
338
400
  }
339
401
  const record = parsed;
340
402
  const type = record?.["type"];
403
+ // Kimi stops replaying at the first complete corrupt line, so nothing after it changes tower state.
404
+ if (main && !sawCorrupt && (record?.["agentId"] === undefined || record["agentId"] === "main")) {
405
+ if (type === "tower_mode.enter")
406
+ towerActive = true;
407
+ else if (type === "tower_mode.exit")
408
+ towerActive = false;
409
+ }
410
+ const isPlanRecord = typeof type === "string" && (type.startsWith("plan_mode.") || type.startsWith("plan."));
411
+ const isRewind = typeof type === "string" && REWIND_RECORD.test(type);
412
+ const isActivity = typeof type === "string" && ACTIVITY_RECORD.test(type);
341
413
  if (pendingEnter !== null) {
342
414
  const cancelId = record?.["id"];
343
415
  const cancels = type === "plan_mode.cancel" && record?.["agentId"] === "main" &&
344
416
  (cancelId === undefined || cancelId === pendingEnter.id);
345
- if (!cancels)
417
+ if (cancels) {
418
+ pendingEnter = null;
419
+ toleratedPair = true;
420
+ continue;
421
+ }
422
+ if (typeof type !== "string" || !PLAN_PAIR_BOOKKEEPING.has(type))
346
423
  return taintEnter;
347
- pendingEnter = null;
348
- toleratedPair = true;
349
- continue;
350
424
  }
351
- if (typeof type === "string" && REWIND_RECORD.test(type)) {
425
+ if (isRewind) {
352
426
  if (toleratedPair)
353
427
  return taintEnter;
354
428
  sawRewind = true;
355
429
  }
356
- if (typeof type === "string" && ACTIVITY_RECORD.test(type))
430
+ if (isActivity)
357
431
  sawActivity = true;
358
- if (typeof type === "string" && (type.startsWith("plan_mode.") || type.startsWith("plan."))) {
432
+ if (isPlanRecord) {
359
433
  if (tolerateCancelledDefaultEnter && type === "plan_mode.enter" && !toleratedPair &&
360
434
  !sawActivity && !sawRewind && !sawCorrupt && record?.["agentId"] === "main" && typeof record?.["id"] === "string") {
361
435
  pendingEnter = { id: record["id"] };
@@ -376,7 +450,7 @@ async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelled
376
450
  // An enter as the last record was never cancelled.
377
451
  if (pendingEnter !== null)
378
452
  return taintEnter;
379
- return null;
453
+ return towerActive ? { kind: "tower" } : null;
380
454
  }
381
455
  async function inspectSessionMetadataEnvironment(statePath, expectedExecutionRoot) {
382
456
  const read = await readSmallFileSafe(statePath, CONFIG_MAX_BYTES);
@@ -459,6 +533,10 @@ export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedEx
459
533
  if (agentEntries.kind === "unreadable") {
460
534
  return { kind: "unavailable", reason: `could not enumerate agent journals: ${agentEntries.reason}` };
461
535
  }
536
+ // Kimi opens `agents/main` by that spelling. On a case-insensitive volume
537
+ // a directory stored as `Main` answers to it, so the main journal is
538
+ // identified by what that lookup reaches, not by the stored name.
539
+ const mainIdentity = await directoryIdentity(path.join(agentsDir, "main"));
462
540
  for (const agentEntry of agentEntries.entries) {
463
541
  if (agentEntry.isSymbolicLink()) {
464
542
  return {
@@ -468,7 +546,10 @@ export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedEx
468
546
  }
469
547
  if (!agentEntry.isDirectory())
470
548
  continue;
471
- journalPaths.push({ path: path.join(agentsDir, agentEntry.name, "wire.jsonl"), main: agentEntry.name === "main" });
549
+ const agentDir = path.join(agentsDir, agentEntry.name);
550
+ const main = agentEntry.name === "main" ||
551
+ (mainIdentity !== undefined && (await directoryIdentity(agentDir)) === mainIdentity);
552
+ journalPaths.push({ path: path.join(agentDir, "wire.jsonl"), main });
472
553
  }
473
554
  }
474
555
  if (journalPaths.length === 0) {
@@ -480,13 +561,15 @@ export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedEx
480
561
  return { kind: "unavailable", reason: `${journalPath}: ${opened.reason}` };
481
562
  }
482
563
  try {
483
- const finding = await scanJournalLines(opened.handle, expectedExecutionRoot, main && options.tolerateCancelledDefaultEnter === true);
564
+ const finding = await scanJournalLines(opened.handle, expectedExecutionRoot, main && options.tolerateCancelledDefaultEnter === true, main);
484
565
  if (finding?.kind === "tainted") {
485
566
  return { kind: "tainted", journal: journalPath, recordType: finding.recordType };
486
567
  }
487
568
  if (finding?.kind === "environment") {
488
569
  return { kind: "environment", journal: journalPath, recordType: finding.recordType };
489
570
  }
571
+ if (finding?.kind === "tower")
572
+ return { kind: "tower", journal: journalPath };
490
573
  }
491
574
  finally {
492
575
  await opened.handle.close().catch(() => undefined);
@@ -548,13 +631,16 @@ export async function assertNativeV2Preflight(options) {
548
631
  }
549
632
  if (environment.trustDisabled === true)
550
633
  warnings.push(WORKSPACE_TRUST_DISABLED_WARNING);
551
- // Certified and test-bypass children run with tower and subagent fork forced
552
- // off by per-flag env, which outranks config and the master flag on every
553
- // reviewed release. An uncertified release's flag names are unreviewed.
554
- const experimental = options.release === undefined || options.release.certification === "uncertified"
555
- ? await inspectExperimentalSelectors(options.kimiHome, options.env)
556
- : { kind: "ok" };
557
- if (experimental.kind === "refuse") {
634
+ // Every native-v2 child runs with tower and subagent fork forced off by
635
+ // per-flag env and without the master flag. On a reviewed release that is
636
+ // proven to win; an uncertified release's flag handling is unreviewed, so
637
+ // the caller is told what is switched on. Only a launch with no plan refuses.
638
+ const uncertified = options.release?.certification === "uncertified";
639
+ const experimentalConfig = options.release === undefined || uncertified
640
+ ? await inspectExperimentalConfig(options.kimiHome, options.env)
641
+ : { inspection: { kind: "ok" }, switchedOn: [] };
642
+ const experimental = experimentalConfig.inspection;
643
+ if (experimental.kind === "refuse" && !(uncertified && experimental.selectors.length > 0)) {
558
644
  throw new RuntimeError("CLI_V2_EXPERIMENTAL_UNSAFE", `${experimental.reason} Unset the listed selector(s) before retrying.`, stage, {
559
645
  details: {
560
646
  refusal_kind: "v2-experimental-unsafe",
@@ -563,6 +649,9 @@ export async function assertNativeV2Preflight(options) {
563
649
  },
564
650
  });
565
651
  }
652
+ if (uncertified && experimentalConfig.switchedOn.length > 0) {
653
+ warnings.push(experimentalSelectorsWarning(experimentalConfig.switchedOn));
654
+ }
566
655
  if (options.resumeSessionId !== undefined) {
567
656
  const journalScan = await scanSessionJournalsForPlan(options.kimiHome, options.resumeSessionId, options.expectedExecutionRoot, { tolerateCancelledDefaultEnter: certifiedPrintLaunchHas(options, "print-cancels-plan") });
568
657
  if (journalScan.kind === "environment") {
@@ -583,6 +672,9 @@ export async function assertNativeV2Preflight(options) {
583
672
  },
584
673
  });
585
674
  }
675
+ if (journalScan.kind === "tower") {
676
+ throw new RuntimeError("KIMI_SESSION_TOWER_ACTIVE", `Saved session ${options.resumeSessionId} is in tower mode (${journalScan.journal}). Resuming it lets Kimi update this workspace's .tower state outside the plugin's hook. Turn tower mode off in that session with /tower, or start a fresh session; saved session state was not modified.`, stage, { details: { refusal_kind: "session-tower-active", retryable_after_setup: false } });
677
+ }
586
678
  if (journalScan.kind === "unavailable") {
587
679
  throw new RuntimeError("KIMI_SESSION_JOURNAL_UNAVAILABLE", `Could not verify saved session ${options.resumeSessionId} is free of plan-mode state (${journalScan.reason}). Start a fresh session; saved session state was not modified.`, stage, {
588
680
  details: {
@@ -4,7 +4,7 @@ import { SCOPE_FLAGS_WRITE_MESSAGE } from "./read-scope.js";
4
4
  * Unknown flag-shaped tokens hard-fail instead of being absorbed into prose.
5
5
  * Parsing still switches to prose at the first non-flag token or after `--`.
6
6
  */
7
- function looksLikeFlag(token) {
7
+ export function looksLikeFlag(token) {
8
8
  if (!token.startsWith("-")) {
9
9
  return false;
10
10
  }
@@ -15,11 +15,14 @@ function looksLikeFlag(token) {
15
15
  return /^-[a-zA-Z]$/.test(token);
16
16
  }
17
17
  const SCOPE_SUPPORTED_FLAGS = "--read-root <absolute-dir> (repeatable), --network";
18
- export const RESCUE_SUPPORTED_FLAGS = "-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --background, --wait, --fresh, -r, --resume <job-id|session-id>";
18
+ export const MAX_SESSION_REFERENCES = 8;
19
+ export const SESSION_REFERENCE_ID_MAX = 128;
20
+ const REFERENCE_SUPPORTED_FLAG = `--reference-session <job-id|session-id> (repeatable, at most ${MAX_SESSION_REFERENCES})`;
21
+ export const RESCUE_SUPPORTED_FLAGS = `-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --background, --wait, --fresh, -r, --resume <job-id|session-id>, ${REFERENCE_SUPPORTED_FLAG}`;
19
22
  export const ASK_SUPPORTED_FLAGS = `${RESCUE_SUPPORTED_FLAGS}, ${SCOPE_SUPPORTED_FLAGS}`;
20
- export const REVIEW_SUPPORTED_FLAGS = `--base <ref>, -m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, ${SCOPE_SUPPORTED_FLAGS}`;
21
- export const JOB_LOOKUP_SUPPORTED_FLAGS = "--type <review|challenge|rescue|review_gate|ask>, --json";
22
- export const SETUP_SUPPORTED_FLAGS = "--check, --uninstall, --all (with --uninstall), --enable-review-gate, --disable-review-gate, --models [--json] (without other setup flags), --install-kimi [--json] (without other setup flags)";
23
+ export const REVIEW_SUPPORTED_FLAGS = `--base <ref>, -m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, ${SCOPE_SUPPORTED_FLAGS}, ${REFERENCE_SUPPORTED_FLAG}`;
24
+ export const JOB_LOOKUP_SUPPORTED_FLAGS = "--type <review|challenge|rescue|ask>, --json";
25
+ export const SETUP_SUPPORTED_FLAGS = "--check, --uninstall, --models [--json] (without other setup flags), --install-kimi [--json] (without other setup flags), --repair-sessions [--apply] [--all] (without other setup flags)";
23
26
  export const RECOVER_SWARM_SUPPORTED_FLAGS = "--apply";
24
27
  export const REPAIR_SESSIONS_SUPPORTED_FLAGS = "--apply, --all";
25
28
  export const REPLAY_SUPPORTED_FLAGS = "none (one job-id required)";
@@ -32,7 +35,7 @@ export function validateThinkingEffort(value, stage = "args.parse", lowercase =
32
35
  return effort;
33
36
  }
34
37
  export const PURSUE_SUPPORTED_FLAGS = "-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --turns <N>";
35
- export const SWARM_SUPPORTED_FLAGS = `-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --cap <N>, --max-concurrency <N>, --write, ${SCOPE_SUPPORTED_FLAGS} (read-only swarm only)`;
38
+ export const SWARM_SUPPORTED_FLAGS = `-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --cap <N>, --max-concurrency <N>, --write, ${SCOPE_SUPPORTED_FLAGS} (read-only swarm only), ${REFERENCE_SUPPORTED_FLAG}`;
36
39
  /**
37
40
  * Parser for /kimi:swarm. Foreground-only: no --background/--fresh/--resume.
38
41
  * Trailing tokens are the objective.
@@ -46,6 +49,7 @@ export function parseSwarmArgs(argv) {
46
49
  let write = false;
47
50
  const readRoots = [];
48
51
  let network = false;
52
+ const references = [];
49
53
  let trailingTokens;
50
54
  for (let index = 0; index < argv.length; index += 1) {
51
55
  const token = argv[index];
@@ -67,6 +71,9 @@ export function parseSwarmArgs(argv) {
67
71
  case "--model":
68
72
  model = readModel(token, argv[++index], "swarm.parse");
69
73
  break;
74
+ case "--reference-session":
75
+ references.push(referenceSessionValue(argv[++index], "swarm.parse"));
76
+ break;
70
77
  case "--write":
71
78
  write = true;
72
79
  break;
@@ -105,9 +112,26 @@ export function parseSwarmArgs(argv) {
105
112
  model,
106
113
  thinkingEffort,
107
114
  ...scopeFields(readRoots, network),
115
+ ...referenceSessionsField(references, "swarm.parse"),
108
116
  objective: trailingTokens?.join(" "),
109
117
  };
110
118
  }
119
+ function referenceSessionValue(value, stage) {
120
+ if (!value || value.startsWith("-")) {
121
+ throw new RuntimeError("INVALID_ARGS", "--reference-session requires a job id or Kimi session id.", stage);
122
+ }
123
+ return value;
124
+ }
125
+ /** Omitted when absent so parsed shapes stay unchanged; refuses more than the cap. */
126
+ function referenceSessionsField(values, stage) {
127
+ if (values.length === 0)
128
+ return {};
129
+ const unique = [...new Set(values)];
130
+ if (unique.length > MAX_SESSION_REFERENCES) {
131
+ throw new RuntimeError("INVALID_ARGS", `--reference-session accepts at most ${MAX_SESSION_REFERENCES} distinct sessions; got ${unique.length}.`, stage);
132
+ }
133
+ return { referenceSessions: unique };
134
+ }
111
135
  /** Omit default-scope fields so parsed shapes stay unchanged without the flags. */
112
136
  function scopeFields(readRoots, network) {
113
137
  return {
@@ -262,7 +286,7 @@ export function parsePursueArgs(argv) {
262
286
  objective: trailingTokens?.join(" "),
263
287
  };
264
288
  }
265
- const VALUE_TAKING_FLAGS = new Set(["--thinking", "-m", "--model", "--budget", "--resume", "--base", "--cap", "--max-concurrency", "--turns", "--type", "--read-root"]);
289
+ const VALUE_TAKING_FLAGS = new Set(["--mode", "--thinking", "-m", "--model", "--budget", "--resume", "--base", "--cap", "--max-concurrency", "--turns", "--type", "--read-root", "--reference-session"]);
266
290
  /**
267
291
  * `--help` / `-h` counts only inside the leading flag region: before `--`
268
292
  * and before the first prose token. The value of a value-taking flag is
@@ -278,7 +302,7 @@ export function hasHelpFlag(argv) {
278
302
  return false;
279
303
  if (token === "--help" || token === "-h")
280
304
  return true;
281
- if (!token.startsWith("-"))
305
+ if (!looksLikeFlag(token))
282
306
  return false;
283
307
  if (VALUE_TAKING_FLAGS.has(token)) {
284
308
  const value = argv[index + 1];
@@ -337,6 +361,7 @@ function parsePromptArgs(argv, kind) {
337
361
  let explicitResumeTarget = false;
338
362
  const readRoots = [];
339
363
  let network = false;
364
+ const references = [];
340
365
  let trailingTokens;
341
366
  for (let index = 0; index < argv.length; index += 1) {
342
367
  const token = argv[index];
@@ -357,6 +382,9 @@ function parsePromptArgs(argv, kind) {
357
382
  case "--budget":
358
383
  budgetMs = readBudget(argv[++index], `${kind}.parse`, "response");
359
384
  break;
385
+ case "--reference-session":
386
+ references.push(referenceSessionValue(argv[++index], `${kind}.parse`));
387
+ break;
360
388
  case "-m":
361
389
  case "--model":
362
390
  model = readModel(token, argv[++index], "args.parse");
@@ -419,11 +447,12 @@ function parsePromptArgs(argv, kind) {
419
447
  model,
420
448
  thinkingEffort,
421
449
  ...scopeFields(readRoots, network),
450
+ ...referenceSessionsField(references, `${kind}.parse`),
422
451
  prompt: trailingTokens?.join(" "),
423
452
  };
424
453
  }
425
454
  export function parseReviewArgs(argv, commandName = "review") {
426
- const parsed = parseKnownFlags(argv, new Set(["--budget", "--base", "--background", "--wait", "-m", "--model", "--read-root", "--network"]), commandName);
455
+ const parsed = parseKnownFlags(argv, new Set(["--budget", "--base", "--background", "--wait", "-m", "--model", "--read-root", "--network", "--reference-session"]), commandName);
427
456
  return {
428
457
  budgetMs: parsed.budgetMs,
429
458
  base: parsed.base,
@@ -432,6 +461,7 @@ export function parseReviewArgs(argv, commandName = "review") {
432
461
  model: parsed.model,
433
462
  thinkingEffort: parsed.thinkingEffort,
434
463
  ...scopeFields(parsed.readRoots, parsed.network),
464
+ ...referenceSessionsField(parsed.references, `${commandName}.parse`),
435
465
  focus: parsed.trailingText,
436
466
  };
437
467
  }
@@ -444,7 +474,7 @@ export function parseJobLookupArgs(argv) {
444
474
  if (token === "--type") {
445
475
  const value = argv[index + 1];
446
476
  if (!value || !isManagedCommandType(value)) {
447
- throw new RuntimeError("INVALID_ARGS", "--type requires one of review, challenge, rescue, review_gate, ask.", "args.parse");
477
+ throw new RuntimeError("INVALID_ARGS", "--type requires one of review, challenge, rescue, ask.", "args.parse");
448
478
  }
449
479
  type = value;
450
480
  index += 1;
@@ -472,7 +502,6 @@ function isManagedCommandType(value) {
472
502
  return (value === "review" ||
473
503
  value === "challenge" ||
474
504
  value === "rescue" ||
475
- value === "review_gate" ||
476
505
  value === "ask");
477
506
  }
478
507
  function parseKnownFlags(argv, knownFlags, commandName) {
@@ -484,6 +513,7 @@ function parseKnownFlags(argv, knownFlags, commandName) {
484
513
  let wait = false;
485
514
  const readRoots = [];
486
515
  let network = false;
516
+ const references = [];
487
517
  let trailingTokens;
488
518
  for (let index = 0; index < argv.length; index += 1) {
489
519
  const token = argv[index];
@@ -535,6 +565,9 @@ function parseKnownFlags(argv, knownFlags, commandName) {
535
565
  case "--network":
536
566
  network = true;
537
567
  break;
568
+ case "--reference-session":
569
+ references.push(referenceSessionValue(argv[++index], `${commandName}.parse`));
570
+ break;
538
571
  // The early `if (!knownFlags.has(token))` gate above means we only
539
572
  // reach this switch with tokens that ARE in knownFlags, and every
540
573
  // member is handled above. A `default` arm would be unreachable.
@@ -547,6 +580,7 @@ function parseKnownFlags(argv, knownFlags, commandName) {
547
580
  wait,
548
581
  readRoots,
549
582
  network,
583
+ references,
550
584
  model,
551
585
  thinkingEffort,
552
586
  trailingText: trailingTokens?.join(" "),
@@ -1,16 +1,20 @@
1
1
  import { constants } from "node:fs";
2
- import { access, mkdir } from "node:fs/promises";
2
+ import { access, chmod, lstat, mkdir } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { resolvePluginDataRoot } from "./plugin-data.js";
5
5
  export function resolvePluginPaths(env) {
6
- const claudePluginData = resolvePluginDataRoot(env);
7
- const pluginRoot = path.join(claudePluginData, "kimi-plugin-cc");
6
+ const dataRoot = resolvePluginDataRoot(env);
7
+ const pluginRoot = path.join(dataRoot, "kimi-plugin-cc");
8
+ const hookDir = path.join(pluginRoot, "hook");
8
9
  return {
9
- claudePluginData,
10
+ dataRoot,
11
+ claudePluginData: dataRoot,
10
12
  pluginRoot,
11
13
  stateDbPath: path.join(pluginRoot, "state.db"),
12
14
  logsDir: path.join(pluginRoot, "logs"),
13
15
  artifactsDir: path.join(pluginRoot, "artifacts"),
16
+ hookDir,
17
+ hookScriptPath: path.join(hookDir, "approval-hook.js"),
14
18
  worktreesDir: path.join(pluginRoot, "worktrees"),
15
19
  configPath: path.join(pluginRoot, "config.json"),
16
20
  };
@@ -24,12 +28,18 @@ export function resolveKimiBinDir(env) {
24
28
  return path.join(resolvePluginPaths(env).pluginRoot, "kimi-bin");
25
29
  }
26
30
  export async function ensurePluginPaths(paths) {
27
- await mkdir(paths.pluginRoot, { recursive: true });
28
- await mkdir(paths.logsDir, { recursive: true });
29
- await mkdir(paths.artifactsDir, { recursive: true });
30
- await access(paths.pluginRoot, constants.R_OK | constants.W_OK);
31
- await access(paths.logsDir, constants.R_OK | constants.W_OK);
32
- await access(paths.artifactsDir, constants.R_OK | constants.W_OK);
31
+ // Never chmod paths.dataRoot (often shared ~/.local/share or a user directory),
32
+ // and never follow a symlink when tightening permissions on plugin directories.
33
+ for (const dir of [paths.pluginRoot, paths.logsDir, paths.artifactsDir]) {
34
+ await mkdir(dir, { recursive: true, mode: 0o700 });
35
+ if (process.platform !== "win32") {
36
+ const info = await lstat(dir);
37
+ if (!info.isSymbolicLink()) {
38
+ await chmod(dir, 0o700);
39
+ }
40
+ }
41
+ await access(dir, constants.R_OK | constants.W_OK);
42
+ }
33
43
  // worktreesDir is created lazily by the write-swarm path (not every command
34
44
  // needs it), so it is intentionally NOT required here.
35
45
  }