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,6 +1,79 @@
1
+ import { accessSync, constants as fsConstants, lstatSync, realpathSync, statSync } from "node:fs";
2
+ import path from "node:path";
1
3
  import { RuntimeError } from "./errors.js";
4
+ import { resolveKimiBinDir } from "./paths.js";
5
+ const EXACT_VERSION_DIR_RE = /^\d+\.\d+\.\d+$/;
6
+ /** Which binary jobs will use and why; setup reports this. */
7
+ export function selectKimiBinary(env) {
8
+ const pluginOwned = inspectPluginOwnedKimi(env);
9
+ if (env.KIMI_PLUGIN_CC_KIMI_BIN) {
10
+ return { command: env.KIMI_PLUGIN_CC_KIMI_BIN, source: "override", pluginOwned };
11
+ }
12
+ if (pluginOwned.status === "active") {
13
+ return { command: pluginOwned.target, source: "plugin-owned", pluginOwned };
14
+ }
15
+ return { command: "kimi", source: "path", pluginOwned };
16
+ }
17
+ /**
18
+ * The plugin-owned binary is used only when `current` resolves to an
19
+ * executable regular file inside `<data root>/kimi-plugin-cc/kimi-bin/<x.y.z>/`. The resolved
20
+ * realpath is returned so the checked file is the one the plan records.
21
+ * Anything else falls back to PATH, as before this install existed.
22
+ */
23
+ export function inspectPluginOwnedKimi(env) {
24
+ let binDir;
25
+ try {
26
+ binDir = resolveKimiBinDir(env);
27
+ }
28
+ catch {
29
+ return { binDir: null, status: "unavailable", reason: "plugin data root is not resolved" };
30
+ }
31
+ if (process.platform === "win32") {
32
+ return { binDir, status: "unavailable", reason: "plugin-owned kimi-code is not supported on Windows" };
33
+ }
34
+ const currentPath = path.join(binDir, "current");
35
+ try {
36
+ lstatSync(currentPath);
37
+ }
38
+ catch {
39
+ return { binDir, status: "absent" };
40
+ }
41
+ let realBinDir;
42
+ let target;
43
+ try {
44
+ realBinDir = realpathSync(binDir);
45
+ target = realpathSync(currentPath);
46
+ }
47
+ catch {
48
+ return { binDir, status: "rejected", reason: `${currentPath} does not resolve to an existing file` };
49
+ }
50
+ const relative = path.relative(realBinDir, target);
51
+ const versionDir = relative.split(path.sep)[0] ?? "";
52
+ if (relative === "" ||
53
+ path.isAbsolute(relative) ||
54
+ relative.startsWith(`..${path.sep}`) ||
55
+ relative === ".." ||
56
+ !EXACT_VERSION_DIR_RE.test(versionDir) ||
57
+ relative === versionDir) {
58
+ return {
59
+ binDir,
60
+ status: "rejected",
61
+ reason: `${currentPath} resolves to ${target}, outside ${path.join(realBinDir, "<version>")}${path.sep}`,
62
+ };
63
+ }
64
+ try {
65
+ if (!statSync(target).isFile()) {
66
+ return { binDir, status: "rejected", reason: `${target} is not a regular file` };
67
+ }
68
+ accessSync(target, fsConstants.X_OK);
69
+ }
70
+ catch {
71
+ return { binDir, status: "rejected", reason: `${target} is not executable` };
72
+ }
73
+ return { binDir, status: "active", target, version: versionDir };
74
+ }
2
75
  export function resolveKimiCliCommand(env) {
3
- const command = env.KIMI_PLUGIN_CC_KIMI_BIN || "kimi";
76
+ const command = env.KIMI_PLUGIN_CC_KIMI_BIN || selectKimiBinary(env).command;
4
77
  const raw = env.KIMI_PLUGIN_CC_KIMI_PREFIX_ARGS;
5
78
  if (!raw) {
6
79
  return { command, prefixArgs: [] };
@@ -4,8 +4,46 @@ import path from "node:path";
4
4
  import { RuntimeError } from "./errors.js";
5
5
  import { resolveKimiCliCommand } from "./kimi-command.js";
6
6
  import { resolveKimiHome } from "./kimi-home.js";
7
+ import { formatVersionChoice, kimiVersionsInScope, kimiVersionsWith, resolveKimiRelease } from "./kimi-releases.js";
8
+ import { hookGateRefusal, verifyHookInstalled } from "./hooks/install.js";
7
9
  import { assertNativeV2Preflight } from "./native-v2-preflight.js";
8
10
  import { isInTestedRange, parseVersionLine, probeKimiVersion, } from "./kimi-version-probe.js";
11
+ import { isRecord } from "./util.js";
12
+ /**
13
+ * The user-visible operation actually being performed. This is deliberately
14
+ * separate from JobRecord.command_type: pursue and swarm-write reuse the
15
+ * rescue job lineage, while read-only swarm reuses review.
16
+ */
17
+ const NON_SWARM_OPERATION_KINDS = ["review", "challenge", "ask", "rescue", "review_gate", "pursue"];
18
+ const OPERATION_KINDS = [...NON_SWARM_OPERATION_KINDS, "swarm", "swarm-write"];
19
+ /** Operations that may run on an uncertified release. Every write or swarm operation stays exact. */
20
+ const UNCERTIFIED_READ_ONLY_OPERATIONS = new Set([
21
+ "ask",
22
+ "review",
23
+ "challenge",
24
+ "review_gate",
25
+ ]);
26
+ /** Restores exact-version refusal for every operation. */
27
+ export const STRICT_VERSIONS_ENV = "KIMI_PLUGIN_CC_STRICT_VERSIONS";
28
+ function strictVersions(env) {
29
+ return env[STRICT_VERSIONS_ENV] === "1";
30
+ }
31
+ /**
32
+ * Native-v2 certification of an exact version for one operation: "certified"
33
+ * from the per-operation table, "uncertified" for a read-only operation on an
34
+ * unlisted plain 2.x that borrows a row's mechanics, otherwise null (refuse).
35
+ */
36
+ export function resolveNativeV2Certification(operationKind, version, env) {
37
+ if (isNativeV2Certified(operationKind, version))
38
+ return "certified";
39
+ if (!UNCERTIFIED_READ_ONLY_OPERATIONS.has(operationKind) || strictVersions(env))
40
+ return null;
41
+ const normalized = parseVersionLine(version)?.raw;
42
+ if (normalized === undefined || isNativeV2CertifiedVersion(normalized))
43
+ return null;
44
+ const resolved = resolveKimiRelease(normalized);
45
+ return resolved !== null && !resolved.certified ? "uncertified" : null;
46
+ }
9
47
  export const NATIVE_V2_SAFETY_PROFILE = "native-v2-no-plan/1";
10
48
  /**
11
49
  * Minimum legacy-v1 version that actually contains each operation. The upper
@@ -25,42 +63,19 @@ const LEGACY_V1_MINIMUMS = {
25
63
  * Exact kimi-code releases certified for native v2 under
26
64
  * NATIVE_V2_SAFETY_PROFILE. Exact, not minor-ranged: upstream ships
27
65
  * behavioural changes in patch releases, and the no-plan construction must be
28
- * re-proven (mechanized tag scan + real-binary smoke) per tag before a version
29
- * is appended. Each entry has its own row in tests/audit/v2-tag-scan.test.ts
30
- * and a dated entry in ROADMAP-TO-GA.md § Post-GA audit log.
66
+ * re-proven (mechanized tag scan + real-binary smoke) per tag before a row is
67
+ * added to KIMI_V2_RELEASES in kimi-releases.ts with scope "all". Each entry
68
+ * has its own row in tests/audit/v2-tag-scan.test.ts and a dated entry in
69
+ * ROADMAP-TO-GA.md § Post-GA audit log.
31
70
  */
32
- export const NATIVE_V2_CERTIFIED_VERSIONS = Object.freeze([
33
- "0.42.0",
34
- "0.43.0",
35
- "0.43.1",
36
- "2.0.0",
37
- "2.0.1",
38
- "2.0.2",
39
- "2.1.0",
40
- "2.1.1",
41
- "2.2.0",
42
- "2.3.0",
43
- "2.3.1",
44
- "2.3.2",
45
- "2.3.3",
46
- "2.4.0",
47
- "2.4.1",
48
- "2.5.0",
49
- "2.5.1",
50
- "2.5.2",
51
- "2.5.3",
52
- "2.6.2",
53
- "2.6.3",
54
- "2.7.2",
55
- "2.7.3",
56
- ]);
71
+ export const NATIVE_V2_CERTIFIED_VERSIONS = Object.freeze([...kimiVersionsInScope("all")]);
57
72
  /**
58
73
  * Exact releases certified only for review, challenge, ask, rescue, review_gate
59
74
  * and pursue. Their upstream rate-limit recovery can exceed AgentSwarm's
60
75
  * configured maximum, and these releases lack a certified plugin admission
61
76
  * construction, so both swarm operations refuse before model spawn.
62
77
  */
63
- export const NATIVE_V2_NON_SWARM_VERSIONS = Object.freeze(["2.6.0"]);
78
+ export const NATIVE_V2_NON_SWARM_VERSIONS = Object.freeze([...kimiVersionsInScope("non-swarm")]);
64
79
  /**
65
80
  * Any-operation union used by setup and engine selection. The older
66
81
  * NATIVE_V2_CERTIFIED_VERSIONS export stays all-operation-only for consumers
@@ -100,25 +115,34 @@ export function isNativeV2CertifiedVersion(version) {
100
115
  return NATIVE_V2_ANY_OPERATION_VERSIONS.includes(normalized);
101
116
  }
102
117
  /**
103
- * Select native v2 for an exactly certified version or a test-only operation
104
- * admission, then enforce scope in assertCertifiedCapability. A narrowed
105
- * release must not fall back to legacy-v1 for an excluded operation.
118
+ * Select native v2 for a certified version, a test-only operation admission,
119
+ * or any major-2 release, then enforce scope in assertCertifiedCapability. A
120
+ * narrowed or uncertified 2.x never falls back to legacy-v1 (deleted upstream
121
+ * at 0.42.0), so its refusal names the native-v2 set.
106
122
  */
107
123
  export function selectIntendedEngine(operationKind, probe) {
108
- return isNativeV2CertifiedVersion(probe.version) || isNativeV2Certified(operationKind, probe.version)
109
- ? "native-v2"
110
- : "legacy-v1";
124
+ if (isNativeV2CertifiedVersion(probe.version) || isNativeV2Certified(operationKind, probe.version)) {
125
+ return "native-v2";
126
+ }
127
+ const parsed = parseVersionLine(probe.version);
128
+ return parsed !== undefined && parsed.major >= 2 ? "native-v2" : "legacy-v1";
111
129
  }
112
130
  const UNSAFE_EXPERIMENTAL_VALUES = new Set(["1", "true", "yes", "on"]);
113
131
  /**
114
- * Refuse the ambient experimental-feature selector before any model or version
115
- * subprocess. cli-client repeats this at the final spawn boundary in case the
116
- * environment changes after plan creation.
132
+ * Refuse the ambient experimental-feature selector for legacy-v1, uncertified
133
+ * and plan-less launches. A certified or test-bypass native-v2 plan is exempt:
134
+ * upstream reads the master flag only from the child's own environment
135
+ * (flagService via bootstrap.getEnv, 0.42.0-2.7.3), and buildKimiCliEnvironment
136
+ * deletes it from every native-v2 child. cli-client and swarm activation repeat
137
+ * this at the final spawn boundary in case the environment changed after plan
138
+ * creation.
117
139
  */
118
- export function assertNoUnsafeExperimentalSelector(env, stage = "kimi-engine.plan") {
140
+ export function assertNoUnsafeExperimentalSelector(env, stage = "kimi-engine.plan", plan) {
119
141
  const enabled = UNSAFE_EXPERIMENTAL_VALUES.has((env.KIMI_CODE_EXPERIMENTAL_FLAG ?? "").trim().toLowerCase());
120
142
  if (!enabled)
121
143
  return;
144
+ if (plan?.intendedEngine === "native-v2" && plan.certification !== "uncertified")
145
+ return;
122
146
  throw new RuntimeError("CLI_V2_HOOK_ORDER_UNSAFE", "Refusing kimi-code experimental features: the master KIMI_CODE_EXPERIMENTAL_FLAG enables unreviewed agent-core-v2 features (tower, subagent fork) that kimi-plugin-cc has not certified under its no-plan safety profile. Unset KIMI_CODE_EXPERIMENTAL_FLAG and retry.", stage, {
123
147
  details: {
124
148
  refusal_kind: "v2-hook-order-unsafe",
@@ -134,33 +158,41 @@ export function assertNoUnsafeExperimentalSelector(env, stage = "kimi-engine.pla
134
158
  * alternate route between dispatch and execution.
135
159
  */
136
160
  export async function prepareKimiExecutionPlan(options) {
137
- assertNoUnsafeExperimentalSelector(options.env);
161
+ // An explicit legacy-v1 plan refuses before any subprocess; otherwise the
162
+ // engine and certification decide below, after the master-flag-free probe.
163
+ if (options.intendedEngine === "legacy-v1")
164
+ assertNoUnsafeExperimentalSelector(options.env);
138
165
  if (options.intendedEngine === "native-v2" &&
139
166
  !NATIVE_V2_CERTIFIED.has(options.operationKind)) {
140
167
  throw nativeV2NotCertified(options.operationKind, null);
141
168
  }
142
169
  const kimi = resolveKimiCliCommand(options.env);
143
170
  const exactCommand = await resolveExactExecutable(kimi.command, options.cwd, options.env);
144
- const runPreflight = async (intendedEngine) => {
171
+ const warnings = [];
172
+ const runPreflight = async (intendedEngine, release) => {
145
173
  if (options.resumeSource) {
146
174
  assertResumeEngineCompatible(options.resumeSource, intendedEngine, options.operationKind);
147
175
  }
148
176
  if (intendedEngine !== "native-v2")
149
177
  return;
150
178
  // Safety, not certification: runs for test-bypass plans too.
151
- await assertNativeV2Preflight({
179
+ const preflight = await assertNativeV2Preflight({
152
180
  kimiHome: resolveKimiHome(options.env, options.cwd),
153
181
  env: options.env,
154
182
  resumeSessionId: options.resumeSessionId,
155
183
  expectedExecutionRoot: options.cwd,
156
184
  stage: "kimi-engine.plan",
185
+ release: { operationKind: options.operationKind, ...release },
157
186
  });
187
+ warnings.push(...preflight.warnings);
158
188
  };
159
189
  if (options.env.KIMI_PLUGIN_CC_SKIP_VERSION_PROBE === "1") {
160
190
  const intendedEngine = options.intendedEngine ?? "legacy-v1";
161
191
  const safetyProfile = intendedEngine === "native-v2" ? NATIVE_V2_SAFETY_PROFILE : null;
162
- await runPreflight(intendedEngine);
163
- return Object.freeze({
192
+ assertNoUnsafeExperimentalSelector(options.env, "kimi-engine.plan", { intendedEngine, certification: "test-bypass" });
193
+ await runPreflight(intendedEngine, { kimiVersion: null, certification: "test-bypass" });
194
+ warnings.push(...await planHookCheck(options.operationKind, options.env, options.stderr));
195
+ return finishPlan({
164
196
  schemaVersion: 1,
165
197
  operationKind: options.operationKind,
166
198
  intendedEngine,
@@ -170,13 +202,13 @@ export async function prepareKimiExecutionPlan(options) {
170
202
  certification: "test-bypass",
171
203
  resumedFromJobId: options.resumedFromJobId ?? null,
172
204
  safetyProfile,
173
- });
205
+ }, warnings, options.stderr);
174
206
  }
175
207
  const probe = await probeKimiVersion({
176
208
  kimiBin: exactCommand,
177
209
  prefixArgs: kimi.prefixArgs,
178
210
  cwd: options.cwd,
179
- env: options.env,
211
+ env: withoutExperimentalMasterFlag(options.env),
180
212
  });
181
213
  if (probe.kind !== "ok") {
182
214
  throw new RuntimeError("KIMI_EXECUTION_PLAN_UNRESOLVED", `Refusing to spawn kimi because the exact command/version plan could not be established: ${probe.reason}. Run Claude Code \`/kimi:setup\` or Codex \`$kimi-setup\` to verify the active binary, or correct KIMI_PLUGIN_CC_KIMI_BIN / KIMI_PLUGIN_CC_KIMI_PREFIX_ARGS and retry.`, "kimi-engine.plan", {
@@ -190,19 +222,71 @@ export async function prepareKimiExecutionPlan(options) {
190
222
  }
191
223
  const intendedEngine = options.intendedEngine ?? selectIntendedEngine(options.operationKind, probe);
192
224
  const safetyProfile = intendedEngine === "native-v2" ? NATIVE_V2_SAFETY_PROFILE : null;
193
- assertCertifiedCapability(intendedEngine, options.operationKind, probe);
194
- await runPreflight(intendedEngine);
195
- return Object.freeze({
225
+ const certification = assertCertifiedCapability(intendedEngine, options.operationKind, probe, options.env);
226
+ assertNoUnsafeExperimentalSelector(options.env, "kimi-engine.plan", { intendedEngine, certification });
227
+ if (certification === "uncertified") {
228
+ const borrowed = resolveKimiRelease(probe.version).release.version;
229
+ warnings.push(`kimi-code ${probe.version} is not certified by this plugin release; running ${options.operationKind} read-only with ${borrowed} mechanics.`);
230
+ }
231
+ await runPreflight(intendedEngine, { kimiVersion: probe.version, certification });
232
+ warnings.push(...await planHookCheck(options.operationKind, options.env, options.stderr, probe));
233
+ return finishPlan({
196
234
  schemaVersion: 1,
197
235
  operationKind: options.operationKind,
198
236
  intendedEngine,
199
237
  command: exactCommand,
200
238
  prefixArgs: Object.freeze([...kimi.prefixArgs]),
201
239
  kimiVersion: probe.version,
202
- certification: "certified",
240
+ certification,
203
241
  resumedFromJobId: options.resumedFromJobId ?? null,
204
242
  safetyProfile,
205
- });
243
+ }, warnings, options.stderr);
244
+ }
245
+ function withoutExperimentalMasterFlag(env) {
246
+ const copy = { ...env };
247
+ delete copy.KIMI_CODE_EXPERIMENTAL_FLAG;
248
+ return copy;
249
+ }
250
+ /**
251
+ * Job-time hook check against the release this plan probed (`probe`, absent
252
+ * only on the test-bypass path). It refuses when the configured hooks array is
253
+ * invalid for that release, because kimi-code would then load no hook at all;
254
+ * the command gate's earlier check may have probed a different release.
255
+ * Any other definite negative (`installed === false`) refuses with the
256
+ * operation's command-gate error: the hook may have gone between that gate and
257
+ * this plan. KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 makes verifyHookInstalled report
258
+ * installed, exactly as at the gates. Otherwise it returns warnings: marker
259
+ * repair (G6) and other hosts' older hooks that still apply their own rules to
260
+ * this job (H2). A thrown, unverifiable result adds nothing and never refuses.
261
+ */
262
+ async function planHookCheck(operation, env, stderr, probe) {
263
+ let status;
264
+ try {
265
+ status = await verifyHookInstalled(env, { kimiVersion: probe });
266
+ }
267
+ catch {
268
+ return [];
269
+ }
270
+ if (status.hookSetInvalid) {
271
+ throw new RuntimeError("KIMI_HOOK_SET_INVALID", `Refusing to spawn kimi: the configured kimi-code hooks are invalid for the release this job runs (${probe?.version ?? "version not probed"}): ${status.reason}. kimi-code drops the whole hooks array, so the managed PreToolUse hook would not run. Repair or remove that [[hooks]] entry in ${status.configPath} and retry.`, "kimi-engine.plan", {
272
+ details: {
273
+ config_path: status.configPath,
274
+ kimi_version: probe?.version ?? null,
275
+ retryable_after_setup: false,
276
+ },
277
+ });
278
+ }
279
+ if (status.installed)
280
+ return status.warnings ?? [];
281
+ throw hookGateRefusal(operation, status, env, stderr);
282
+ }
283
+ /** Freeze the plan; a nonempty warning list is attached and announced once on stderr. */
284
+ function finishPlan(plan, warnings, stderr = process.stderr) {
285
+ if (warnings.length === 0)
286
+ return Object.freeze(plan);
287
+ for (const warning of warnings)
288
+ stderr.write(`[kimi-plugin-cc] warning: ${warning}\n`);
289
+ return Object.freeze({ ...plan, warnings: Object.freeze([...warnings]) });
206
290
  }
207
291
  export function assertExecutionPlanMatchesSpawn(plan, command, prefixArgs, env = {}) {
208
292
  assertExecutionPlanShape(plan);
@@ -232,6 +316,7 @@ export function persistedExecutionPlanFields(plan) {
232
316
  plan_certification: plan.certification,
233
317
  resumed_from_job_id: plan.resumedFromJobId,
234
318
  safety_profile: plan.safetyProfile,
319
+ warnings: plan.warnings !== undefined && plan.warnings.length > 0 ? JSON.stringify(plan.warnings) : null,
235
320
  };
236
321
  }
237
322
  export function observedExecutionFields(result) {
@@ -467,12 +552,12 @@ export function classifyHistoricalEngineProvenance(contents) {
467
552
  conflict,
468
553
  };
469
554
  }
470
- function assertCertifiedCapability(engine, operationKind, probe) {
555
+ function assertCertifiedCapability(engine, operationKind, probe, env) {
471
556
  if (engine === "native-v2") {
472
- if (!isNativeV2Certified(operationKind, probe.version)) {
473
- throw nativeV2NotCertified(operationKind, probe.version);
474
- }
475
- return;
557
+ const certification = resolveNativeV2Certification(operationKind, probe.version, env);
558
+ if (certification === null)
559
+ throw nativeV2NotCertified(operationKind, probe.version, env);
560
+ return certification;
476
561
  }
477
562
  const minimum = LEGACY_V1_MINIMUMS[operationKind];
478
563
  const meetsMinimum = probe.major > minimum.major ||
@@ -493,6 +578,7 @@ function assertCertifiedCapability(engine, operationKind, probe) {
493
578
  },
494
579
  });
495
580
  }
581
+ return "certified";
496
582
  }
497
583
  /**
498
584
  * Revalidate the persisted certification at the final subprocess boundary.
@@ -518,20 +604,33 @@ function assertPlanCertification(plan, env) {
518
604
  return;
519
605
  }
520
606
  if (plan.kimiVersion === null) {
521
- throw invalidPersistedPlan("certified plans require kimi_version");
607
+ throw invalidPersistedPlan(`${plan.certification} plans require kimi_version`);
522
608
  }
523
609
  const parsed = parseVersionLine(plan.kimiVersion);
524
610
  if (parsed === undefined) {
525
611
  throw invalidPersistedPlan("kimi_version is not a parseable semantic version");
526
612
  }
527
- assertCertifiedCapability(plan.intendedEngine, plan.operationKind, {
613
+ if (plan.certification === "uncertified" && plan.intendedEngine !== "native-v2") {
614
+ throw invalidPersistedPlan("uncertified plans must use native-v2");
615
+ }
616
+ // Recompute from the release table and the current environment: a strict
617
+ // environment, a write operation, or a row that has since been added all
618
+ // refuse a plan whose recorded certification no longer matches.
619
+ const certification = assertCertifiedCapability(plan.intendedEngine, plan.operationKind, {
528
620
  kind: "ok",
529
621
  version: parsed.raw,
530
622
  major: parsed.major,
531
623
  minor: parsed.minor,
532
624
  patch: parsed.patch,
533
625
  inTestedRange: isInTestedRange(parsed.major, parsed.minor),
534
- });
626
+ }, env);
627
+ if (certification !== plan.certification) {
628
+ // A plan claiming exact certification for an uncertified release keeps the
629
+ // historical capability refusal; any other mismatch is a stale/forged row.
630
+ if (plan.certification === "certified")
631
+ throw nativeV2NotCertified(plan.operationKind, parsed.raw, env);
632
+ throw invalidPersistedPlan(`plan_certification ${JSON.stringify(plan.certification)} does not match ${JSON.stringify(certification)} for kimi-code ${parsed.raw}`);
633
+ }
535
634
  }
536
635
  function assertExecutionPlanShape(plan) {
537
636
  const candidate = plan;
@@ -566,13 +665,13 @@ function assertExecutionPlanShape(plan) {
566
665
  throw invalidPersistedPlan("safetyProfile is invalid");
567
666
  }
568
667
  }
569
- function nativeV2NotCertified(operationKind, version) {
668
+ function nativeV2NotCertified(operationKind, version, env = {}) {
570
669
  const certified = NATIVE_V2_CERTIFIED.get(operationKind) ?? [];
571
670
  const normalized = version === null ? undefined : parseVersionLine(version)?.raw;
572
671
  if (normalized !== undefined &&
573
672
  NATIVE_V2_NON_SWARM_VERSIONS.includes(normalized) &&
574
673
  (operationKind === "swarm" || operationKind === "swarm-write")) {
575
- return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind}: kimi-code ${normalized} is certified only for non-swarm operations (review, challenge, ask, rescue, review_gate, pursue). Its native rate-limit recovery can exceed AgentSwarm's configured maximum, so this exact release refuses swarm before model spawn. Select exact kimi-code 2.6.2, 2.6.3, 2.7.2 or 2.7.3 for this plugin's certified bounded waves and single-worker path, or use a non-swarm operation on ${normalized}.`, "kimi-engine.capability", {
674
+ return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind}: kimi-code ${normalized} is certified only for non-swarm operations (review, challenge, ask, rescue, review_gate, pursue). Its native rate-limit recovery can exceed AgentSwarm's configured maximum, so this exact release refuses swarm before model spawn. Select exact kimi-code ${formatVersionChoice(kimiVersionsWith("bounded-swarm"))} for this plugin's certified bounded waves and single-worker path, or use a non-swarm operation on ${normalized}.`, "kimi-engine.capability", {
576
675
  details: {
577
676
  refusal_kind: "v2-swarm-not-certified",
578
677
  certification_scope: "non-swarm",
@@ -581,12 +680,18 @@ function nativeV2NotCertified(operationKind, version) {
581
680
  intended_engine: "native-v2",
582
681
  kimi_version: normalized,
583
682
  certified_versions: [...certified],
584
- certified_operations: ["review", "challenge", "ask", "rescue", "review_gate", "pursue"],
683
+ certified_operations: [...NON_SWARM_OPERATION_KINDS],
585
684
  },
586
685
  });
587
686
  }
588
687
  const observed = version === null ? "an unprobed version" : `kimi-code ${version}`;
589
- return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind} on native v2: ${observed} is not in this operation's exactly certified set [${certified.join(", ")}]. Update kimi-plugin-cc to a release that certifies this kimi-code version, or point KIMI_PLUGIN_CC_KIMI_BIN at a certified binary. KIMI_PLUGIN_CC_SKIP_VERSION_PROBE is a test/smoke seam, not a production repair path.`, "kimi-engine.capability", {
688
+ const borrowable = normalized !== undefined && resolveKimiRelease(normalized)?.certified === false;
689
+ const readOnlyNote = !borrowable
690
+ ? ""
691
+ : strictVersions(env)
692
+ ? ` ${STRICT_VERSIONS_ENV}=1 is set, so read-only operations on this uncertified release also refuse.`
693
+ : " Read-only operations (ask, review, challenge, review gate) still run on this uncertified release with a warning; write and swarm operations need an exact certified release.";
694
+ return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind} on native v2: ${observed} is not in this operation's exactly certified set [${certified.join(", ")}].${readOnlyNote} Run setup --install-kimi to give the plugin its own copy of the newest certified kimi-code, update kimi-plugin-cc to a release that certifies this version, or point KIMI_PLUGIN_CC_KIMI_BIN at a certified binary. KIMI_PLUGIN_CC_SKIP_VERSION_PROBE is a test/smoke seam, not a production repair path.`, "kimi-engine.capability", {
590
695
  details: {
591
696
  refusal_kind: "v2-version-not-certified",
592
697
  retryable_after_setup: false,
@@ -630,9 +735,6 @@ async function resolveExactExecutable(command, cwd, env) {
630
735
  }
631
736
  throw new RuntimeError("KIMI_EXECUTION_PLAN_UNRESOLVED", `Refusing to spawn kimi because executable ${JSON.stringify(command)} could not be resolved to an exact runnable path. Run Claude Code \`/kimi:setup\` or Codex \`$kimi-setup\` to verify the active binary, or correct KIMI_PLUGIN_CC_KIMI_BIN and retry.`, "kimi-engine.plan", { details: { command, cwd } });
632
737
  }
633
- function isRecord(value) {
634
- return typeof value === "object" && value !== null && !Array.isArray(value);
635
- }
636
738
  function parseProtocolVersion(value) {
637
739
  const match = value.match(/^(\d+)\.(\d+)(?:\.\d+)?$/);
638
740
  if (match === null)
@@ -658,18 +760,11 @@ function operationKindFromLogEntry(entry) {
658
760
  return isOperationKind(candidate) ? candidate : null;
659
761
  }
660
762
  function isOperationKind(value) {
661
- return (value === "review" ||
662
- value === "challenge" ||
663
- value === "ask" ||
664
- value === "rescue" ||
665
- value === "review_gate" ||
666
- value === "pursue" ||
667
- value === "swarm" ||
668
- value === "swarm-write");
763
+ return OPERATION_KINDS.includes(value);
669
764
  }
670
765
  function isKimiEngine(value) {
671
766
  return value === "legacy-v1" || value === "native-v2";
672
767
  }
673
768
  function isPlanCertification(value) {
674
- return value === "certified" || value === "test-bypass";
769
+ return value === "certified" || value === "uncertified" || value === "test-bypass";
675
770
  }