kimi-plugin-cc 2.7.2 → 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 (224) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +3 -5
  3. package/CHANGELOG.md +78 -1
  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 +6 -5
  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 -42
  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 -74
  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 +74 -77
  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 +27 -6
  74. package/docs/models.md +2 -2
  75. package/docs/registry-releases.md +3 -1
  76. package/docs/safety.md +131 -81
  77. package/docs/session-visibility.md +5 -3
  78. package/docs/swarm-recovery.md +4 -4
  79. package/docs/upstream-2.7.2-certification.md +16 -2
  80. package/docs/upstream-2.7.3-certification.md +95 -0
  81. package/package.json +2 -1
  82. package/plugins/kimi-codex/.codex-plugin/plugin.json +3 -3
  83. package/plugins/kimi-codex/.mcp.json +1 -0
  84. package/plugins/kimi-codex/dist/background-spawn.js +10 -17
  85. package/plugins/kimi-codex/dist/cli-client.js +65 -46
  86. package/plugins/kimi-codex/dist/commands/ask.js +22 -89
  87. package/plugins/kimi-codex/dist/commands/cancel.js +7 -46
  88. package/plugins/kimi-codex/dist/commands/cli-helpers.js +102 -1
  89. package/plugins/kimi-codex/dist/commands/models.js +2 -3
  90. package/plugins/kimi-codex/dist/commands/pursue.js +5 -19
  91. package/plugins/kimi-codex/dist/commands/repair-sessions.js +118 -12
  92. package/plugins/kimi-codex/dist/commands/rescue.js +12 -82
  93. package/plugins/kimi-codex/dist/commands/result.js +7 -1
  94. package/plugins/kimi-codex/dist/commands/review-gate.js +1 -0
  95. package/plugins/kimi-codex/dist/commands/review.js +12 -15
  96. package/plugins/kimi-codex/dist/commands/setup.js +606 -270
  97. package/plugins/kimi-codex/dist/commands/status.js +2 -2
  98. package/plugins/kimi-codex/dist/commands/swarm.js +93 -119
  99. package/plugins/kimi-codex/dist/commands/worker.js +1 -2
  100. package/plugins/kimi-codex/dist/companion.js +3 -1
  101. package/plugins/kimi-codex/dist/dsh/index.js +15 -17
  102. package/plugins/kimi-codex/dist/git.js +1 -9
  103. package/plugins/kimi-codex/dist/help.js +3 -3
  104. package/plugins/kimi-codex/dist/hooks/approval-hook.js +41 -0
  105. package/plugins/kimi-codex/dist/hooks/approval-policy.js +72 -10
  106. package/plugins/kimi-codex/dist/hooks/config-safety.js +19 -42
  107. package/plugins/kimi-codex/dist/hooks/hook-timing.js +48 -0
  108. package/plugins/kimi-codex/dist/hooks/install.js +206 -11
  109. package/plugins/kimi-codex/dist/hooks/managed-block.js +78 -33
  110. package/plugins/kimi-codex/dist/job-store.js +100 -128
  111. package/plugins/kimi-codex/dist/jobs.js +14 -19
  112. package/plugins/kimi-codex/dist/kimi-command.js +74 -1
  113. package/plugins/kimi-codex/dist/kimi-engine.js +170 -74
  114. package/plugins/kimi-codex/dist/kimi-errors.js +14 -69
  115. package/plugins/kimi-codex/dist/kimi-home.js +6 -0
  116. package/plugins/kimi-codex/dist/kimi-journal.js +41 -0
  117. package/plugins/kimi-codex/dist/kimi-releases.js +144 -0
  118. package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -1
  119. package/plugins/kimi-codex/dist/kimi-version-probe.js +12 -48
  120. package/plugins/kimi-codex/dist/mcp/job-control.js +4 -6
  121. package/plugins/kimi-codex/dist/mcp/launcher.js +12 -6
  122. package/plugins/kimi-codex/dist/mcp/operations.js +50 -18
  123. package/plugins/kimi-codex/dist/mcp/protocol.js +16 -14
  124. package/plugins/kimi-codex/dist/mcp/stdio.js +3 -2
  125. package/plugins/kimi-codex/dist/model-command.js +5 -3
  126. package/plugins/kimi-codex/dist/native-v2-preflight.js +139 -68
  127. package/plugins/kimi-codex/dist/parsing.js +171 -237
  128. package/plugins/kimi-codex/dist/paths.js +8 -0
  129. package/plugins/kimi-codex/dist/process-tree.js +35 -24
  130. package/plugins/kimi-codex/dist/read-scope.js +435 -0
  131. package/plugins/kimi-codex/dist/render.js +46 -9
  132. package/plugins/kimi-codex/dist/rescue-approval.js +461 -84
  133. package/plugins/kimi-codex/dist/schemas/review-gate-output.js +3 -5
  134. package/plugins/kimi-codex/dist/session-title.js +25 -5
  135. package/plugins/kimi-codex/dist/stream-json.js +1 -3
  136. package/plugins/kimi-codex/dist/surface-routing.js +21 -0
  137. package/plugins/kimi-codex/dist/swarm-activation.js +74 -77
  138. package/plugins/kimi-codex/dist/swarm-policy.js +2 -1
  139. package/plugins/kimi-codex/dist/swarm-recovery.js +2 -1
  140. package/plugins/kimi-codex/dist/util.js +28 -0
  141. package/plugins/kimi-codex/dist/version.js +1 -1
  142. package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +1 -1
  143. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +8 -7
  144. package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +1 -1
  145. package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +2 -1
  146. package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +8 -6
  147. package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +1 -1
  148. package/plugins/kimi-codex/skills/{kimi-ask → kimi-task}/SKILL.md +11 -9
  149. package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +6 -0
  150. package/plugins/kimi-dsh/README.md +3 -2
  151. package/plugins/kimi-dsh/dist/background-spawn.js +10 -17
  152. package/plugins/kimi-dsh/dist/cli-client.js +65 -46
  153. package/plugins/kimi-dsh/dist/commands/ask.js +22 -89
  154. package/plugins/kimi-dsh/dist/commands/cancel.js +7 -46
  155. package/plugins/kimi-dsh/dist/commands/cli-helpers.js +102 -1
  156. package/plugins/kimi-dsh/dist/commands/models.js +2 -3
  157. package/plugins/kimi-dsh/dist/commands/pursue.js +5 -19
  158. package/plugins/kimi-dsh/dist/commands/repair-sessions.js +118 -12
  159. package/plugins/kimi-dsh/dist/commands/rescue.js +12 -82
  160. package/plugins/kimi-dsh/dist/commands/result.js +7 -1
  161. package/plugins/kimi-dsh/dist/commands/review-gate.js +1 -0
  162. package/plugins/kimi-dsh/dist/commands/review.js +12 -15
  163. package/plugins/kimi-dsh/dist/commands/setup.js +606 -270
  164. package/plugins/kimi-dsh/dist/commands/status.js +2 -2
  165. package/plugins/kimi-dsh/dist/commands/swarm.js +93 -119
  166. package/plugins/kimi-dsh/dist/commands/worker.js +1 -2
  167. package/plugins/kimi-dsh/dist/companion.js +3 -1
  168. package/plugins/kimi-dsh/dist/dsh/index.js +15 -17
  169. package/plugins/kimi-dsh/dist/git.js +1 -9
  170. package/plugins/kimi-dsh/dist/help.js +3 -3
  171. package/plugins/kimi-dsh/dist/hooks/approval-hook.js +41 -0
  172. package/plugins/kimi-dsh/dist/hooks/approval-policy.js +72 -10
  173. package/plugins/kimi-dsh/dist/hooks/config-safety.js +19 -42
  174. package/plugins/kimi-dsh/dist/hooks/hook-timing.js +48 -0
  175. package/plugins/kimi-dsh/dist/hooks/install.js +206 -11
  176. package/plugins/kimi-dsh/dist/hooks/managed-block.js +78 -33
  177. package/plugins/kimi-dsh/dist/job-store.js +100 -128
  178. package/plugins/kimi-dsh/dist/jobs.js +14 -19
  179. package/plugins/kimi-dsh/dist/kimi-command.js +74 -1
  180. package/plugins/kimi-dsh/dist/kimi-engine.js +170 -74
  181. package/plugins/kimi-dsh/dist/kimi-errors.js +14 -69
  182. package/plugins/kimi-dsh/dist/kimi-home.js +6 -0
  183. package/plugins/kimi-dsh/dist/kimi-journal.js +41 -0
  184. package/plugins/kimi-dsh/dist/kimi-releases.js +144 -0
  185. package/plugins/kimi-dsh/dist/kimi-timeouts.js +1 -1
  186. package/plugins/kimi-dsh/dist/kimi-version-probe.js +12 -48
  187. package/plugins/kimi-dsh/dist/mcp/job-control.js +4 -6
  188. package/plugins/kimi-dsh/dist/mcp/launcher.js +12 -6
  189. package/plugins/kimi-dsh/dist/mcp/operations.js +50 -18
  190. package/plugins/kimi-dsh/dist/mcp/protocol.js +16 -14
  191. package/plugins/kimi-dsh/dist/mcp/stdio.js +3 -2
  192. package/plugins/kimi-dsh/dist/model-command.js +5 -3
  193. package/plugins/kimi-dsh/dist/native-v2-preflight.js +139 -68
  194. package/plugins/kimi-dsh/dist/parsing.js +171 -237
  195. package/plugins/kimi-dsh/dist/paths.js +8 -0
  196. package/plugins/kimi-dsh/dist/process-tree.js +35 -24
  197. package/plugins/kimi-dsh/dist/read-scope.js +435 -0
  198. package/plugins/kimi-dsh/dist/render.js +46 -9
  199. package/plugins/kimi-dsh/dist/rescue-approval.js +461 -84
  200. package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +3 -5
  201. package/plugins/kimi-dsh/dist/session-title.js +25 -5
  202. package/plugins/kimi-dsh/dist/stream-json.js +1 -3
  203. package/plugins/kimi-dsh/dist/surface-routing.js +21 -0
  204. package/plugins/kimi-dsh/dist/swarm-activation.js +74 -77
  205. package/plugins/kimi-dsh/dist/swarm-policy.js +2 -1
  206. package/plugins/kimi-dsh/dist/swarm-recovery.js +2 -1
  207. package/plugins/kimi-dsh/dist/util.js +28 -0
  208. package/plugins/kimi-dsh/dist/version.js +1 -1
  209. package/plugins/kimi-dsh/package.json +1 -1
  210. package/agents/kimi-challenge.md +0 -86
  211. package/agents/kimi-rescue.md +0 -92
  212. package/agents/kimi-swarm-write.md +0 -96
  213. package/commands/ask.md +0 -38
  214. package/commands/challenge.md +0 -35
  215. package/dist/commands/not-implemented.js +0 -4
  216. package/plugins/kimi-codex/dist/commands/not-implemented.js +0 -4
  217. package/plugins/kimi-codex/skills/kimi-ask/agents/openai.yaml +0 -6
  218. package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +0 -34
  219. package/plugins/kimi-codex/skills/kimi-challenge/agents/openai.yaml +0 -6
  220. package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +0 -34
  221. package/plugins/kimi-codex/skills/kimi-rescue/agents/openai.yaml +0 -6
  222. package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +0 -36
  223. package/plugins/kimi-codex/skills/kimi-swarm-write/agents/openai.yaml +0 -6
  224. package/plugins/kimi-dsh/dist/commands/not-implemented.js +0 -4
@@ -1,4 +1,5 @@
1
1
  import { RuntimeError } from "../errors.js";
2
+ import { isRecord } from "../util.js";
2
3
  const ALLOWED_DECISIONS = new Set(["ALLOW", "BLOCK"]);
3
4
  const ALLOWED_SEVERITIES = new Set(["low", "medium", "high"]);
4
5
  const ALLOWED_CONFIDENCE = new Set(["low", "medium", "high"]);
@@ -10,7 +11,7 @@ export function parseReviewGateOutput(text) {
10
11
  catch (error) {
11
12
  throw new RuntimeError("REVIEW_GATE_PARSE_FAILED", `Review gate output is not valid JSON: ${error.message}`, "review_gate.parse", { cause: error });
12
13
  }
13
- if (!isObject(parsed)) {
14
+ if (!isRecord(parsed)) {
14
15
  throw new RuntimeError("REVIEW_GATE_PARSE_FAILED", "Review gate output must be a JSON object.", "review_gate.parse");
15
16
  }
16
17
  const { decision, confidence, summary, issues } = parsed;
@@ -28,7 +29,7 @@ export function parseReviewGateOutput(text) {
28
29
  };
29
30
  }
30
31
  function normalizeIssue(issue, index) {
31
- if (!isObject(issue)) {
32
+ if (!isRecord(issue)) {
32
33
  throw new RuntimeError("REVIEW_GATE_PARSE_FAILED", `Review gate issue ${index + 1} must be an object.`, "review_gate.parse");
33
34
  }
34
35
  if (typeof issue.title !== "string" ||
@@ -38,6 +39,3 @@ function normalizeIssue(issue, index) {
38
39
  }
39
40
  return issue;
40
41
  }
41
- function isObject(value) {
42
- return typeof value === "object" && value !== null && !Array.isArray(value);
43
- }
@@ -30,7 +30,11 @@ export function normalizeTitleFragment(text) {
30
30
  }
31
31
  /** Mirrors kimi-code 2.0.0 promptMetadataTextFromText: redact BEFORE truncating. */
32
32
  export function promptMetadataText(text) {
33
- const sanitized = text
33
+ const sanitized = sanitizePromptMetadata(text);
34
+ return sanitized ? sanitized.slice(0, 4000) : undefined;
35
+ }
36
+ function sanitizePromptMetadata(text) {
37
+ return text
34
38
  .replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?-----END [^-]*PRIVATE KEY-----/gi, "[redacted]")
35
39
  .replace(/\b(authorization)\s*:\s*bearer\s+\S+/gi, "$1: Bearer [redacted]")
36
40
  .replace(/\b(api[_-]?key|token|secret|password|passwd|pwd)\b\s*[:=]\s*(?:"[^"]*"|'[^']*'|\S+)/gi, "$1=[redacted]")
@@ -39,7 +43,19 @@ export function promptMetadataText(text) {
39
43
  .replace(/\p{Cc}+/gu, " ")
40
44
  .replace(/\s+/g, " ")
41
45
  .trim();
42
- return sanitized ? sanitized.slice(0, 4000) : undefined;
46
+ }
47
+ const OWN_PROMPT_MIN_PREFIX = 40;
48
+ /**
49
+ * Earlier plugin releases stored the submitted prompt redacted, whitespace-
50
+ * collapsed and capped, so compare normalized forms. A prefix relation counts
51
+ * only when the shorter side is long enough that short native text never does.
52
+ */
53
+ function isOwnPrompt(existing, ownPrompts) {
54
+ const current = normalizeTitleFragment(existing);
55
+ if (!current)
56
+ return false;
57
+ return ownPrompts.some((prompt) => [normalizeTitleFragment(prompt), sanitizePromptMetadata(prompt)].some((own) => own.length > 0 && (current === own ||
58
+ (Math.min(own.length, current.length) >= OWN_PROMPT_MIN_PREFIX && (own.startsWith(current) || current.startsWith(own))))));
43
59
  }
44
60
  export function shortenForTitle(text, maxLength) {
45
61
  const normalized = normalizeTitleFragment(text);
@@ -122,9 +138,11 @@ export async function syncKimiSessionTitle(options) {
122
138
  const generatedTitle = state.titleKind === "generated";
123
139
  const next = { ...state };
124
140
  const preview = options.promptText === undefined ? undefined : promptMetadataText(options.promptText);
125
- if (nativeV2 && preview && (typeof state.lastPrompt !== "string" || !state.lastPrompt.trim())) {
141
+ const blankPreview = typeof state.lastPrompt !== "string" || !state.lastPrompt.trim();
142
+ if (nativeV2 && preview && (blankPreview || !options.ownPrompts || isOwnPrompt(state.lastPrompt, options.ownPrompts))) {
126
143
  next.lastPrompt = preview;
127
144
  }
145
+ const replacedPreview = !blankPreview && next.lastPrompt !== state.lastPrompt;
128
146
  if (!options.preserveTitle && !customTitle && !generatedTitle) {
129
147
  next.title = promptMetadataText(options.title)?.slice(0, KIMI_SESSION_TITLE_MAX_LENGTH) ?? "Kimi Session";
130
148
  // Native UI generation must remain eligible; a deterministic fallback is not
@@ -135,7 +153,7 @@ export async function syncKimiSessionTitle(options) {
135
153
  }
136
154
  const changed = JSON.stringify(next) !== JSON.stringify(state);
137
155
  if (options.dryRun)
138
- return changed ? "would-update" : "unchanged";
156
+ return !changed ? "unchanged" : replacedPreview ? "would-replace-preview" : "would-update";
139
157
  try {
140
158
  if (changed && !(await writeStateFileAtomic(statePath, `${JSON.stringify(next, null, 2)}\n`, stateFileMode, stateRead.text))) {
141
159
  warn(options.stderr, "session metadata sync skipped: state changed concurrently; retry after the session is idle");
@@ -157,7 +175,9 @@ export async function syncKimiSessionTitle(options) {
157
175
  return "index-failed";
158
176
  }
159
177
  }
160
- return changed ? "updated" : customTitle && !options.preserveTitle ? "custom-title" : "unchanged";
178
+ if (changed)
179
+ return replacedPreview ? "preview-replaced" : "updated";
180
+ return customTitle && !options.preserveTitle ? "custom-title" : "unchanged";
161
181
  }
162
182
  function findSessionIndexEntry(indexText, sessionId, stderr) {
163
183
  for (const line of indexText.split(/\r?\n/)) {
@@ -27,6 +27,7 @@
27
27
  // entering stream-json.
28
28
  // - assistant messages are only emitted when content OR tool_calls are
29
29
  // non-empty; we still defend against the empty case for resilience.
30
+ import { isRecord } from "./util.js";
30
31
  export const MAX_STREAM_JSON_LINE_BYTES = 1_048_576;
31
32
  /**
32
33
  * Stateful line-buffer parser. Hold partial-line bytes across chunk boundaries.
@@ -314,9 +315,6 @@ function validateToolResult(parsed, line) {
314
315
  };
315
316
  return { record };
316
317
  }
317
- function isRecord(value) {
318
- return typeof value === "object" && value !== null && !Array.isArray(value);
319
- }
320
318
  /**
321
319
  * Match kimi-code's stderr session announce line. In stream-json mode this
322
320
  * is a 0.1.x compatibility fallback only — kimi 0.2.0+ emits the resume
@@ -0,0 +1,21 @@
1
+ import { withoutLeadingFlag } from "./parsing.js";
2
+ /**
3
+ * Host wrappers pass user arguments through to `ask` and `review`; a leading
4
+ * `--write` or `--challenge` selects the existing operation. Only the CLI entry
5
+ * point applies this: MCP children run canonical spellings whose operation is
6
+ * already recorded from the tool name.
7
+ */
8
+ export function routeSurfaceAliases(argv) {
9
+ const [command, ...rest] = argv;
10
+ if (command === "ask") {
11
+ const remaining = withoutLeadingFlag(rest, "--write");
12
+ if (remaining !== undefined)
13
+ return ["task", "rescue", ...remaining];
14
+ }
15
+ if (command === "review") {
16
+ const remaining = withoutLeadingFlag(rest, "--challenge");
17
+ if (remaining !== undefined)
18
+ return ["task", "challenge", ...remaining];
19
+ }
20
+ return [...argv];
21
+ }
@@ -3,18 +3,21 @@ import { randomUUID } from "node:crypto";
3
3
  import { constants as fsConstants } from "node:fs";
4
4
  import { open } from "node:fs/promises";
5
5
  import path from "node:path";
6
- import { buildKimiCliEnvironment, } from "./cli-client.js";
6
+ import { assertWorkspaceSpellable, buildKimiCliEnvironment, } from "./cli-client.js";
7
7
  import { RuntimeError } from "./errors.js";
8
8
  import { assertPrefixArgsSafe } from "./kimi-command.js";
9
9
  import { assertExecutionPlanMatchesSpawn, assertNoUnsafeExperimentalSelector, } from "./kimi-engine.js";
10
10
  import { resolveKimiHome } from "./kimi-home.js";
11
+ import { kimiJournalRecords, UNPARSEABLE_JOURNAL_LINE } from "./kimi-journal.js";
12
+ import { kimiReleaseHas, kimiVersionsWith } from "./kimi-releases.js";
11
13
  import { assertNativeV2Preflight } from "./native-v2-preflight.js";
12
14
  import { usesBoundedSwarmPolicy } from "./swarm-policy.js";
13
15
  import { installBoundedSwarmToolPolicy } from "./swarm-tool-policy.js";
14
- import { collectDescendantIdentities, collectProcessGroupsIdentities, probeProcessIdentity, revalidateProcessIdentities, waitForProcessTreeExit, } from "./process-tree.js";
16
+ import { sleep } from "./util.js";
17
+ import { collectDescendantIdentities, collectProcessGroupsIdentities, probeProcessIdentity, retryIncompleteCapture, revalidateProcessIdentities, waitForProcessTreeExit, } from "./process-tree.js";
15
18
  // These exact activation entries support candidate integration; production scope is per operation.
16
- const PREACTIVATION_VERSIONS = ["2.3.2", "2.3.3", "2.4.0", "2.4.1", "2.5.0", "2.5.1", "2.5.2", "2.5.3", "2.6.0", "2.6.2", "2.6.3", "2.7.2"];
17
- const JSON_READY_VERSION = "2.7.2";
19
+ const PREACTIVATION_VERSIONS = kimiVersionsWith("web-preactivation");
20
+ const JSON_READY_VERSIONS = kimiVersionsWith("web-json-ready");
18
21
  const KIMI_AGENT_PROTOCOL_VERSION = "1.0.0";
19
22
  const READY_TIMEOUT_MS = 10_000;
20
23
  const REST_TIMEOUT_MS = 5_000;
@@ -51,10 +54,7 @@ export async function preactivateSwarmSession(options) {
51
54
  await verifyLocalEnvironment(web, identity, options.cwd, prepared.expectedVersion, options.signal, failureCode);
52
55
  options.onRecoveryEvent?.({ kind: "session", ...identity });
53
56
  profileMutationAttempted = true;
54
- await postSwarmProfile(web, identity, true, model, options.signal, failureCode);
55
- await verifySwarmStatus(web, identity, true, model, prepared.expectedVersion, options.signal, failureCode);
56
- await shutdownWeb(web, options.signal, failureCode);
57
- await requireSwarmJournal(prepared.kimiHome, identity, "enter", options.signal, failureCode);
57
+ await setSwarmMode(web, prepared, identity, true, model, options.signal, failureCode);
58
58
  if (usesBoundedSwarmPolicy(options.executionPlan) && options.swarmMaxConcurrency > 1) {
59
59
  await installBoundedSwarmToolPolicy(prepared.kimiHome, identity, options.signal);
60
60
  }
@@ -99,10 +99,7 @@ export async function deactivateSwarmSession(options) {
99
99
  web = await startWebChild(options, prepared.env, prepared.expectedVersion, failureCode);
100
100
  await verifyMeta(web, prepared.expectedVersion, options.signal, failureCode);
101
101
  await verifyLocalEnvironment(web, options, options.cwd, prepared.expectedVersion, options.signal, failureCode);
102
- await postSwarmProfile(web, options, false, undefined, options.signal, failureCode);
103
- await verifySwarmStatus(web, options, false, undefined, prepared.expectedVersion, options.signal, failureCode);
104
- await shutdownWeb(web, options.signal, failureCode);
105
- await requireSwarmJournal(prepared.kimiHome, options, "exit", options.signal, failureCode);
102
+ await setSwarmMode(web, prepared, options, false, undefined, options.signal, failureCode);
106
103
  options.onRecoveryEvent?.({ kind: "disabled" });
107
104
  throwIfAborted(options.signal, failureCode, "swarm-deactivation.complete");
108
105
  }
@@ -114,6 +111,13 @@ export async function deactivateSwarmSession(options) {
114
111
  throw primary;
115
112
  }
116
113
  }
114
+ /** Set swarm mode, prove the resulting state, stop the web child, then require the journal record. */
115
+ async function setSwarmMode(web, prepared, identity, active, model, signal, failureCode) {
116
+ await postSwarmProfile(web, identity, active, model, signal, failureCode);
117
+ await verifySwarmStatus(web, identity, active, model, prepared.expectedVersion, signal, failureCode);
118
+ await shutdownWeb(web, signal, failureCode);
119
+ await requireSwarmJournal(prepared.kimiHome, identity, active ? "enter" : "exit", signal, failureCode);
120
+ }
117
121
  async function prepareWebSpawn(options, failureCode) {
118
122
  throwIfAborted(options.signal, failureCode, "swarm-activation.pre-spawn");
119
123
  const prefixArgs = options.prefixArgs ?? [];
@@ -121,7 +125,10 @@ async function prepareWebSpawn(options, failureCode) {
121
125
  if (options.commandLabel === "swarm-write" && !options.trustedWorkspaceRoot) {
122
126
  throw new RuntimeError("CLI_TRUSTED_WORKSPACE_ROOT_MISSING", "Refusing swarm-write: write-capable plugin launches require a plugin-owned trusted workspace root.", "swarm-activation.pre-spawn", { details: { command_label: options.commandLabel } });
123
127
  }
124
- assertNoUnsafeExperimentalSelector(options.env, "swarm-activation.pre-spawn");
128
+ if (options.commandLabel === "swarm-write") {
129
+ assertWorkspaceSpellable(options.commandLabel, [options.cwd, options.trustedWorkspaceRoot], "swarm-activation.pre-spawn");
130
+ }
131
+ assertNoUnsafeExperimentalSelector(options.env, "swarm-activation.pre-spawn", options.executionPlan);
125
132
  assertPrefixArgsSafe(prefixArgs);
126
133
  if (options.expectedVersion !== undefined &&
127
134
  options.executionPlan.kimiVersion !== null &&
@@ -139,6 +146,7 @@ async function prepareWebSpawn(options, failureCode) {
139
146
  env: options.env,
140
147
  expectedExecutionRoot: options.cwd,
141
148
  stage: "swarm-activation.pre-spawn",
149
+ release: options.executionPlan,
142
150
  });
143
151
  }
144
152
  throwIfAborted(options.signal, failureCode, "swarm-activation.pre-spawn");
@@ -152,7 +160,7 @@ async function startWebChild(options, env, expectedVersion, failureCode) {
152
160
  const args = [
153
161
  ...(options.prefixArgs ?? []),
154
162
  "web",
155
- expectedVersion === JSON_READY_VERSION ? "--json" : "--no-open",
163
+ JSON_READY_VERSIONS.includes(expectedVersion) ? "--json" : "--no-open",
156
164
  "--host",
157
165
  "127.0.0.1",
158
166
  "--port",
@@ -232,6 +240,17 @@ async function startWebChild(options, env, expectedVersion, failureCode) {
232
240
  }
233
241
  async function waitForReadyLine(owned, expectedVersion, signal, failureCode) {
234
242
  throwIfAborted(signal, failureCode, "swarm-activation.ready");
243
+ const ready = JSON_READY_VERSIONS.includes(expectedVersion)
244
+ ? {
245
+ skip: (line) => line.trim().length === 0,
246
+ parse: parseJsonReadyLine,
247
+ invalid: "The Kimi web JSON ready line did not confirm the authenticated KAP loopback contract.",
248
+ }
249
+ : {
250
+ skip: (line) => !line.startsWith("Kimi server: "),
251
+ parse: parseReadyLine,
252
+ invalid: "The Kimi web ready line was not an authenticated loopback URL in the expected format.",
253
+ };
235
254
  return await new Promise((resolve, reject) => {
236
255
  let buffered = "";
237
256
  let settled = false;
@@ -274,24 +293,13 @@ async function waitForReadyLine(owned, expectedVersion, signal, failureCode) {
274
293
  const newline = buffered.indexOf("\n");
275
294
  const line = buffered.slice(0, newline).replace(/\r$/, "");
276
295
  buffered = buffered.slice(newline + 1);
277
- if (expectedVersion === JSON_READY_VERSION) {
278
- if (line.trim().length === 0)
279
- continue;
280
- try {
281
- settle(parseJsonReadyLine(line));
282
- }
283
- catch {
284
- settle(failure(failureCode, "swarm-activation.ready", "The Kimi web JSON ready line did not confirm the authenticated KAP loopback contract."));
285
- }
286
- return;
287
- }
288
- if (!line.startsWith("Kimi server: "))
296
+ if (ready.skip(line))
289
297
  continue;
290
298
  try {
291
- settle(parseReadyLine(line));
299
+ settle(ready.parse(line));
292
300
  }
293
301
  catch {
294
- settle(failure(failureCode, "swarm-activation.ready", "The Kimi web ready line was not an authenticated loopback URL in the expected format."));
302
+ settle(failure(failureCode, "swarm-activation.ready", ready.invalid));
295
303
  }
296
304
  return;
297
305
  }
@@ -307,15 +315,8 @@ async function waitForReadyLine(owned, expectedVersion, signal, failureCode) {
307
315
  function parseReadyLine(line) {
308
316
  const candidate = line.slice("Kimi server: ".length);
309
317
  const parsed = new URL(candidate);
310
- if (parsed.protocol !== "http:" ||
311
- parsed.hostname !== "127.0.0.1" ||
312
- parsed.port.length === 0 ||
313
- parsed.pathname !== "/" ||
314
- parsed.search.length > 0 ||
315
- parsed.username.length > 0 ||
316
- parsed.password.length > 0) {
318
+ if (!isLoopbackRootUrl(parsed))
317
319
  throw new Error("invalid ready URL");
318
- }
319
320
  if (!parsed.hash.startsWith("#token=") || parsed.hash.length === "#token=".length) {
320
321
  throw new Error("invalid ready token");
321
322
  }
@@ -324,6 +325,16 @@ function parseReadyLine(line) {
324
325
  token: parsed.hash.slice("#token=".length),
325
326
  };
326
327
  }
328
+ /** An http://127.0.0.1:<port>/ URL with no query or credentials; callers check the hash. */
329
+ function isLoopbackRootUrl(url) {
330
+ return (url.protocol === "http:" &&
331
+ url.hostname === "127.0.0.1" &&
332
+ url.port.length > 0 &&
333
+ url.pathname === "/" &&
334
+ url.search.length === 0 &&
335
+ url.username.length === 0 &&
336
+ url.password.length === 0);
337
+ }
327
338
  function parseJsonReadyLine(line) {
328
339
  const data = JSON.parse(line);
329
340
  if (!isRecord(data) ||
@@ -335,14 +346,8 @@ function parseJsonReadyLine(line) {
335
346
  throw new Error("invalid JSON ready payload");
336
347
  }
337
348
  const origin = new URL(data.origin);
338
- if (origin.protocol !== "http:" ||
339
- origin.hostname !== "127.0.0.1" ||
340
- origin.port.length === 0 ||
341
- origin.pathname !== "/" ||
342
- origin.search.length > 0 ||
349
+ if (!isLoopbackRootUrl(origin) ||
343
350
  origin.hash.length > 0 ||
344
- origin.username.length > 0 ||
345
- origin.password.length > 0 ||
346
351
  (data.origin !== origin.origin && data.origin !== `${origin.origin}/`)) {
347
352
  throw new Error("invalid JSON ready origin");
348
353
  }
@@ -364,7 +369,7 @@ async function verifyMeta(web, expectedVersion, signal, failureCode) {
364
369
  if (!isRecord(data)) {
365
370
  throw failure(failureCode, "swarm-activation.meta", "Kimi web /meta returned an invalid payload.");
366
371
  }
367
- if (expectedVersion === JSON_READY_VERSION) {
372
+ if (JSON_READY_VERSIONS.includes(expectedVersion)) {
368
373
  if (data.kimi_agent_protocol_version !== KIMI_AGENT_PROTOCOL_VERSION ||
369
374
  !isRecord(data.capabilities) ||
370
375
  data.capabilities.websocket !== true ||
@@ -399,7 +404,7 @@ async function resolveProfileModel(web, options, failureCode) {
399
404
  }
400
405
  async function createSession(web, options, expectedVersion, failureCode) {
401
406
  const request = { metadata: { cwd: options.cwd } };
402
- if (["2.5.0", "2.5.1", "2.5.2", "2.5.3", "2.6.0", "2.6.2", "2.6.3", "2.7.2"].includes(expectedVersion)) {
407
+ if (kimiReleaseHas(expectedVersion, "local-environment")) {
403
408
  request.environment_id = "local";
404
409
  request.environment_cwd = options.cwd;
405
410
  }
@@ -410,7 +415,7 @@ async function createSession(web, options, expectedVersion, failureCode) {
410
415
  return { sessionId: data.id, workspaceId: data.workspace_id };
411
416
  }
412
417
  async function verifyLocalEnvironment(web, identity, expectedCwd, expectedVersion, signal, failureCode) {
413
- if (!["2.5.0", "2.5.1", "2.5.2", "2.5.3", "2.6.0", "2.6.2", "2.6.3", "2.7.2"].includes(expectedVersion))
418
+ if (!kimiReleaseHas(expectedVersion, "local-environment"))
414
419
  return;
415
420
  const data = await restData(web, "GET", `/api/v1/sessions/${encodeURIComponent(identity.sessionId)}/environment`, undefined, signal, failureCode);
416
421
  if (!isRecord(data)) {
@@ -430,10 +435,11 @@ async function postSwarmProfile(web, identity, active, model, signal, failureCod
430
435
  await restData(web, "POST", `/api/v1/sessions/${encodeURIComponent(identity.sessionId)}/profile`, { agent_config: agentConfig }, signal, failureCode);
431
436
  }
432
437
  async function verifySwarmStatus(web, identity, active, model, expectedVersion, signal, failureCode) {
433
- const data = ["2.5.0", "2.5.1", "2.5.2", "2.5.3", "2.6.0", "2.6.2", "2.6.3", "2.7.2"].includes(expectedVersion)
438
+ const agentState = kimiReleaseHas(expectedVersion, "agent-state");
439
+ const data = agentState
434
440
  ? await readWebSocketAgentState(web, identity.sessionId, expectedVersion, signal, failureCode)
435
441
  : await restData(web, "GET", `/api/v1/sessions/${encodeURIComponent(identity.sessionId)}/status`, undefined, signal, failureCode);
436
- const source = ["2.5.0", "2.5.1", "2.5.2", "2.5.3", "2.6.0", "2.6.2", "2.6.3", "2.7.2"].includes(expectedVersion) ? "agent state" : "/status";
442
+ const source = agentState ? "agent state" : "/status";
437
443
  if (!isRecord(data)) {
438
444
  throw failure(failureCode, "swarm-activation.status", `Kimi web ${source} returned an invalid payload.`);
439
445
  }
@@ -443,10 +449,10 @@ async function verifySwarmStatus(web, identity, active, model, expectedVersion,
443
449
  if (data.plan_mode !== false) {
444
450
  throw failure(failureCode, "swarm-activation.status", `Kimi web ${source} did not confirm plan mode is off.`);
445
451
  }
446
- if (["2.5.0", "2.5.1", "2.5.2", "2.5.3", "2.6.0", "2.6.2", "2.6.3", "2.7.2"].includes(expectedVersion) && data.tower_mode !== false) {
452
+ if (agentState && data.tower_mode !== false) {
447
453
  throw failure(failureCode, "swarm-activation.status", "Kimi web agent state did not confirm tower mode is off.");
448
454
  }
449
- const permission = ["2.5.0", "2.5.1", "2.5.2", "2.5.3", "2.6.0", "2.6.2", "2.6.3", "2.7.2"].includes(expectedVersion) ? data.permission_mode : data.permission;
455
+ const permission = agentState ? data.permission_mode : data.permission;
450
456
  if (permission !== "auto") {
451
457
  throw failure(failureCode, "swarm-activation.status", `Kimi web ${source} did not confirm auto permission mode.`);
452
458
  }
@@ -462,7 +468,7 @@ async function readWebSocketAgentState(web, sessionId, expectedVersion, signal,
462
468
  return await new Promise((resolve, reject) => {
463
469
  let socket;
464
470
  const bearerProtocol = `kimi-code.bearer.${web.token}`;
465
- const legacyControl = !["2.6.0", "2.6.2", "2.6.3", "2.7.2"].includes(expectedVersion);
471
+ const legacyControl = !kimiReleaseHas(expectedVersion, "modern-ws-control");
466
472
  const helloId = `swarm-activation-hello-${randomUUID()}`;
467
473
  const subscribeId = `swarm-activation-subscribe-${randomUUID()}`;
468
474
  try {
@@ -730,7 +736,7 @@ async function shutdownWeb(web, signal, failureCode) {
730
736
  await restData(web, "POST", "/api/v1/shutdown", undefined, signal, failureCode);
731
737
  const settlement = await waitForChildClose(web, signal, failureCode);
732
738
  if (!(await teardownOwnedChild(web))) {
733
- throw failure(failureCode, "swarm-activation.shutdown", "The Kimi web process tree did not become quiescent after shutdown.", { exit_code: settlement.exitCode, signal: settlement.signal });
739
+ throw failure(failureCode, "swarm-activation.shutdown", "The Kimi web process tree did not become quiescent after shutdown.", { exit_code: settlement.exitCode, signal: settlement.signal, cleanup_summary: web.cleanupSummary ?? null });
734
740
  }
735
741
  if (web.processError || settlement.exitCode !== 0) {
736
742
  throw failure(failureCode, "swarm-activation.shutdown", "The Kimi web process did not exit cleanly after shutdown.", { exit_code: settlement.exitCode, signal: settlement.signal });
@@ -775,9 +781,7 @@ async function restData(web, method, route, body, signal, failureCode) {
775
781
  if (signal?.aborted === true)
776
782
  onAbort();
777
783
  try {
778
- const headers = { accept: "application/json" };
779
- if (web.token !== undefined)
780
- headers.authorization = `Bearer ${web.token}`;
784
+ const headers = { accept: "application/json", authorization: `Bearer ${web.token}` };
781
785
  if (body !== undefined)
782
786
  headers["content-type"] = "application/json";
783
787
  const response = await fetch(`${web.origin}${route}`, {
@@ -893,17 +897,13 @@ async function readSwarmJournalState(journalPath) {
893
897
  break;
894
898
  offset += bytesRead;
895
899
  }
900
+ // Framed as kimi-code replays it. Replay stops at the first corrupt
901
+ // terminated line, so no later record may confirm a state: fail closed.
902
+ // An unparseable unterminated tail is truncation, which replay drops.
896
903
  let state = "missing";
897
- for (const rawLine of buffer.subarray(0, offset).toString("utf8").split("\n")) {
898
- const line = rawLine.trim();
899
- if (line.length === 0)
900
- continue;
901
- let record;
902
- try {
903
- record = JSON.parse(line);
904
- }
905
- catch {
906
- if (line.includes("swarm_mode."))
904
+ for await (const { line, parsed: record, terminated } of kimiJournalRecords([buffer.subarray(0, offset)])) {
905
+ if (record === UNPARSEABLE_JOURNAL_LINE) {
906
+ if (terminated || line.includes("swarm_mode."))
907
907
  return "unreadable";
908
908
  continue;
909
909
  }
@@ -933,7 +933,7 @@ function startDescendantTracking(owned) {
933
933
  await refreshOwnedDescendants(owned);
934
934
  if (owned.trackingStopped || owned.exited)
935
935
  break;
936
- await new Promise((resolve) => setTimeout(resolve, DESCENDANT_TRACK_INTERVAL_MS));
936
+ await sleep(DESCENDANT_TRACK_INTERVAL_MS);
937
937
  }
938
938
  })();
939
939
  }
@@ -953,7 +953,7 @@ async function refreshOwnedDescendants(owned) {
953
953
  return;
954
954
  }
955
955
  owned.refreshPromise = (async () => {
956
- const snapshot = await captureDescendantIdentities(childPid);
956
+ const snapshot = await retryIncompleteCapture(() => captureDescendantIdentities(childPid));
957
957
  const previousRoot = owned.rootIdentity;
958
958
  if (snapshot.root !== undefined) {
959
959
  if (previousRoot === undefined) {
@@ -1072,8 +1072,11 @@ async function processGroupsQuiescent(owned, childPid) {
1072
1072
  const groupIds = new Set([childPid]);
1073
1073
  for (const identity of owned.descendants)
1074
1074
  groupIds.add(identity.processGroupId);
1075
- const members = await collectProcessGroupsIdentities([...groupIds]);
1076
- return members !== undefined && members.every((identity) => /^[ZX]/i.test(identity.state.trim()));
1075
+ const scan = await retryIncompleteCapture(async () => {
1076
+ const members = await collectProcessGroupsIdentities([...groupIds]);
1077
+ return { members, complete: members !== undefined };
1078
+ });
1079
+ return scan.members !== undefined && scan.members.every((identity) => /^[ZX]/i.test(identity.state.trim()));
1077
1080
  }
1078
1081
  async function captureDescendantIdentities(childPid) {
1079
1082
  let timer;
@@ -1088,7 +1091,7 @@ async function captureDescendantIdentities(childPid) {
1088
1091
  }),
1089
1092
  ]);
1090
1093
  if (snapshot === null)
1091
- return { identities: [], complete: false };
1094
+ return { identities: [], complete: false, timedOut: true };
1092
1095
  const [collected, rootProbe] = snapshot;
1093
1096
  const identities = [];
1094
1097
  const seen = new Set();
@@ -1133,14 +1136,8 @@ async function signalCapturedTree(owned, childPid, identities, signal) {
1133
1136
  for (const identity of pidValidation.identities)
1134
1137
  trySignalPid(identity.pid, signal);
1135
1138
  const activeGroupIds = new Set(pidValidation.identities.map((identity) => identity.processGroupId));
1136
- if (owned.exited) {
1137
- if (!pidValidation.identities.some((identity) => identity.processGroupId === childPid)) {
1138
- activeGroupIds.delete(childPid);
1139
- }
1140
- }
1141
- else {
1139
+ if (!owned.exited)
1142
1140
  activeGroupIds.delete(childPid);
1143
- }
1144
1141
  for (const processGroupId of activeGroupIds)
1145
1142
  trySignalPid(-processGroupId, signal);
1146
1143
  }
@@ -1,3 +1,4 @@
1
+ import { kimiReleaseHas } from "./kimi-releases.js";
1
2
  export const SWARM_POLICY_ENV = "KIMI_PLUGIN_CC_SWARM_POLICY";
2
3
  export const SWARM_WAVE_SIZE_ENV = "KIMI_PLUGIN_CC_SWARM_WAVE_SIZE";
3
4
  export const BOUNDED_SWARM_POLICY = "bounded-waves/1";
@@ -7,7 +8,7 @@ export const BOUNDED_SWARM_POLICY = "bounded-waves/1";
7
8
  export const SWARM_CHILD_TIMEOUT_MS = 2_147_483_647;
8
9
  export function usesBoundedSwarmPolicy(plan) {
9
10
  return plan.intendedEngine === "native-v2" &&
10
- (plan.kimiVersion === "2.6.2" || plan.kimiVersion === "2.6.3" || plan.kimiVersion === "2.7.2") &&
11
+ kimiReleaseHas(plan.kimiVersion, "bounded-swarm") &&
11
12
  (plan.operationKind === "swarm" || plan.operationKind === "swarm-write");
12
13
  }
13
14
  function plainObject(value) {
@@ -1,4 +1,5 @@
1
1
  import { RuntimeError } from "./errors.js";
2
+ import { sleep } from "./util.js";
2
3
  import { collectDescendantIdentities, collectProcessGroupsIdentities, probeProcessIdentity, revalidateProcessIdentities } from "./process-tree.js";
3
4
  export function recordRecoveryEvent(store, record, event) {
4
5
  record.complete = false;
@@ -158,7 +159,7 @@ export async function recoverLaunch(launch, persist, signal) {
158
159
  persist();
159
160
  return;
160
161
  }
161
- await new Promise((resolve) => setTimeout(resolve, 25));
162
+ await sleep(25);
162
163
  } while (Date.now() < deadline);
163
164
  }
164
165
  throw recoveryError("Recorded processes did not become quiescent; recovery remains pending.");
package/dist/util.js ADDED
@@ -0,0 +1,28 @@
1
+ /** Small helpers shared across the runtime. Imports nothing. */
2
+ // Uses the global timer on purpose: tests observe globalThis.setTimeout.
3
+ export function sleep(ms) {
4
+ return new Promise((resolve) => setTimeout(resolve, ms));
5
+ }
6
+ /** Collapse whitespace and cut to `max` characters, ending in an ellipsis when cut. */
7
+ export function shorten(text, max) {
8
+ const normalized = text.replace(/\s+/g, " ").trim();
9
+ if (normalized.length <= max) {
10
+ return normalized;
11
+ }
12
+ return `${normalized.slice(0, Math.max(0, max - 1)).trimEnd()}…`;
13
+ }
14
+ /**
15
+ * Where a smol-toml parse failed. Its own message quotes the neighbouring
16
+ * source lines, and lines of kimi-code's config can hold credentials, so that
17
+ * message must never reach an error, log or artifact.
18
+ */
19
+ export function tomlErrorLocation(error) {
20
+ // `codeblock` marks a smol-toml TomlError; plain Errors also carry line/column under Bun.
21
+ const { line, column, codeblock } = (typeof error === "object" && error !== null ? error : {});
22
+ return typeof codeblock === "string" && typeof line === "number" && typeof column === "number"
23
+ ? `syntax error at line ${line}, column ${column}`
24
+ : "syntax error";
25
+ }
26
+ export function isRecord(value) {
27
+ return typeof value === "object" && value !== null && !Array.isArray(value);
28
+ }
package/dist/version.js CHANGED
@@ -4,4 +4,4 @@
4
4
  // and AGENTS.md on every release. A future improvement would read this from
5
5
  // package.json at build time, but that adds a build-step dependency we
6
6
  // don't want yet.
7
- export const KIMI_PLUGIN_CC_VERSION = "2.7.2";
7
+ export const KIMI_PLUGIN_CC_VERSION = "3.0.0";
package/docs/migration.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Compatibility and upgrades
2
2
 
3
- The runtime certifies exact CLI releases per operation. Plugin 2.6.2 adds bounded swarm on exact stock CLI 2.6.2; see the [certification receipt](upstream-2.6.2-certification.md) for validation status. Plugin 2.6.3 additionally certifies exact CLI 2.6.3 with a separate [release receipt](upstream-2.6.3-certification.md); the immutable GitHub/npm release and fresh registry verification are complete. Plugin 2.7.2 certifies exact CLI 2.7.2 with separate [certification evidence](upstream-2.7.2-certification.md); publication does not change the compatibility matrix. Exact 2.6.0 remains non-swarm-only. Older full-operation rows through 2.5.3 keep their inherited recovery limitation. `NATIVE_V2_CERTIFIED_VERSIONS` is the all-operation export, and `NATIVE_V2_ANY_OPERATION_VERSIONS` is the scoped union. Other versions, including 2.6.1, 2.6.4, 2.7.0, 2.7.1 and 2.7.3, are not accepted automatically. The npm channel does not change the compatibility matrix.
3
+ The runtime certifies exact CLI releases per operation. Plugin 2.6.2 adds bounded swarm on exact stock CLI 2.6.2; see the [certification receipt](upstream-2.6.2-certification.md) for validation status. Plugin 2.6.3 additionally certifies exact CLI 2.6.3 with a separate [release receipt](upstream-2.6.3-certification.md); the immutable GitHub/npm release and fresh registry verification are complete. Plugin 2.7.2 certifies exact CLI 2.7.2 with separate [certification evidence](upstream-2.7.2-certification.md). Plugin 2.7.3 adds exact CLI 2.7.3 under the same construction with a separate [certification record](upstream-2.7.3-certification.md); publication does not change the compatibility matrix. Exact 2.6.0 remains non-swarm-only. Older full-operation rows through 2.5.3 keep their inherited recovery limitation. `NATIVE_V2_CERTIFIED_VERSIONS` is the all-operation export, and `NATIVE_V2_ANY_OPERATION_VERSIONS` is the scoped union. Since plugin 3.0.0, another plain 2.x release above 2.0.0, including 2.6.1, 2.7.0 and 2.7.4, runs only the read-only operations (ask, review, challenge and the review gate) with a warning; rescue, pursue and both swarm modes refuse, and `KIMI_PLUGIN_CC_STRICT_VERSIONS=1` refuses every operation. The npm channel does not change the compatibility matrix.
4
4
 
5
5
  Plugin 2.5.1 also adds DeepSeek Harness as a third host with all seven operations and a DSH-specific bundle, data root, and managed hook id. Existing Claude Code and Codex certification, job stores, and host-scoped hooks are unchanged; no migration is required for those hosts. New DSH installations follow the [README DSH section](../README.md#install-in-deepseek-harness), including `/kimi-setup` on that host.
6
6
 
7
- Explicitly pinned legacy-v1 binaries remain supported within `KIMI_TESTED_MINORS`, through 0.41.x, subject to each operation's minimum version. The [runtime table](../runtime/kimi-engine.ts) is the authority.
7
+ Explicitly pinned legacy-v1 binaries remain supported within `KIMI_TESTED_MINORS` (`runtime/kimi-version-probe.ts`), through 0.41.x, subject to each operation's minimum version. The [native-v2 release table](../runtime/kimi-releases.ts) is the authority for native-v2 versions.
8
8
 
9
9
  Use the [README installation and update steps](../README.md) for Claude Code or Codex. Model and provider choices are covered in the [model setup guide](./models.md). Do not change your host application's authentication to configure Kimi.
10
10
 
@@ -12,6 +12,27 @@ Use the [README installation and update steps](../README.md) for Claude Code or
12
12
 
13
13
  Plugin versions advance independently using ordinary SemVer and may deliberately align with a certified CLI release. Nearby version numbers do not imply compatibility or operation scope; the exact per-operation matrix is authoritative. Published versions and tags are never reused. Every upstream patch requires its own certification. The native-v2 no-plan profile, plugin/marketplace IDs and existing job store are preserved.
14
14
 
15
+ ## Upgrading to 3.0
16
+
17
+ Plugin 3.0.0 replaces seven model commands with four. The operations behind them do not change, so existing jobs, sessions, hook labels and session-title prefixes carry over. Run setup on each host after updating, as for every release.
18
+
19
+ | Before 3.0.0 | From 3.0.0 |
20
+ |---|---|
21
+ | `/kimi:ask`, agent `kimi-ask`, Codex `$kimi-ask` | `/kimi:task`, agent `kimi-task`, Codex `$kimi-task` |
22
+ | `/kimi:rescue`, agent `kimi-rescue`, Codex `$kimi-rescue` | `/kimi:task --write`, agent `kimi-task` with `--write`, Codex `$kimi-task` with `--write` |
23
+ | `/kimi:challenge`, agent `kimi-challenge`, Codex `$kimi-challenge` | `/kimi:review --challenge`, agent `kimi-review` with `--challenge`, Codex `$kimi-review` with `--challenge` |
24
+ | agent `kimi-swarm-write`, Codex `$kimi-swarm-write` | agent `kimi-swarm` with `--write`, Codex `$kimi-swarm` with `--write`; `/kimi:swarm --write` is unchanged |
25
+ | MCP tool `kimi_challenge` | MCP tool `kimi_review` with `mode: "challenge"` |
26
+
27
+ - `--write` and `--challenge` select the operation only as leading flags, before the first word of the prompt. The same text inside the prompt, or after `--`, keeps the read-only operation.
28
+ - Scripts that call `companion.sh` directly keep working: `ask`, `task rescue`, `review`, `task challenge`, `task pursue`, `task swarm` and `task swarm --write` are unchanged.
29
+ - Codex lists nine skills instead of twelve. `$kimi-task` is not implicitly invocable, so Codex no longer starts the read-only question skill on its own; name it when you want it. `$kimi-review` stays implicitly invocable.
30
+ - Update the plugin on every host you use. Every installed hook checks every plugin job, so another host's older hook still applies its own rules and can deny what 3.0 allows; each job launch and each setup warns about it.
31
+ - The MCP server lists six model tools and the three job tools. A client that called `kimi_challenge` must call `kimi_review` with `mode: "challenge"`. `kimi_ask`, `kimi_review` and `kimi_swarm` also accept `read_roots` and `network`.
32
+ - DeepSeek Harness keeps all seven providers, including `kimi_challenge` and `kimi_swarm_write`.
33
+
34
+ The same release stops refusing several Kimi settings it can neutralize, runs read-only operations on uncertified 2.x releases, adds `setup --install-kimi` and per-call read scope, and reports non-fatal conditions as warnings. See the [changelog](../CHANGELOG.md) and [safety guide](./safety.md).
35
+
15
36
  ## Plugin 2.6.2 swarm behavior on exact CLI 2.6.2
16
37
 
17
38
  Concurrency 1 uses one direct worker without native swarm activation or delegation. The default for write mode remains 1; its edits still produce an unapplied patch from a temporary worktree. Read mode defaults to 4 and uses guarded waves. At concurrency 2 or more, new and resumed entries share the wave limit; a model must divide larger tasks into successive waves. Fresh-only waves require at least two entries, so group odd target counts into disjoint entries or resume an own-session child for remaining work. `--cap` remains an advisory lifetime-total count.
@@ -22,17 +43,17 @@ Parallel Bash commands use the native 60-second default foreground timeout, with
22
43
 
23
44
  ## Native parallel swarm activation
24
45
 
25
- Upstream 2.3.2 removes model self-activation of `AgentSwarm` in fresh print sessions. On exact 2.3.2, 2.3.3, 2.4.0, 2.4.1 and 2.5.0/2.5.1/2.5.2/2.5.3, plus the exact-2.6.2/2.6.3/2.7.2 parallel paths, swarm commands and MCP calls use the same `runSwarm` lifecycle. The direct single-worker path skips it:
46
+ Upstream 2.3.2 removes model self-activation of `AgentSwarm` in fresh print sessions. On exact 2.3.2, 2.3.3, 2.4.0, 2.4.1 and 2.5.0/2.5.1/2.5.2/2.5.3, plus the exact-2.6.2/2.6.3/2.7.2/2.7.3 parallel paths, swarm commands and MCP calls use the same `runSwarm` lifecycle. The direct single-worker path skips it:
26
47
 
27
- 1. A short-lived `web --no-open --host 127.0.0.1 --port 0 --log-level error` process uses authenticated loopback routes to verify the exact v2 server, choose the explicit or configured default model, create a session, bind the model and auto permission, enable and verify `swarm_mode`, and shut down. Exact 2.7.2 instead uses `web --json` with an in-memory ephemeral token, a validated loopback origin and `/api/v1/ws`, and KAP 1.0.0/WebSocket meta proof without a legacy backend field. On exact 2.5.0/2.5.1/2.5.2/2.5.3 and the bounded 2.6.2/2.6.3/2.7.2 paths, creation explicitly selects the local environment and an authenticated `/environment` read proves its cwd before profile mutation; state verification uses protocol-v2 or direct-subscription WebSocket main-agent frames because `/status` was removed. The child environment sets `KIMI_CODE_SESSION_IDLE_RECLAIM_MS=0` to disable ambient idle-session reclamation.
48
+ 1. A short-lived `web --no-open --host 127.0.0.1 --port 0 --log-level error` process uses authenticated loopback routes to verify the exact v2 server, choose the explicit or configured default model, create a session, bind the model and auto permission, enable and verify `swarm_mode`, and shut down. Exact 2.7.2/2.7.3 instead uses `web --json` with an in-memory ephemeral token, a validated loopback origin and `/api/v1/ws`, and KAP 1.0.0/WebSocket meta proof without a legacy backend field. On exact 2.5.0/2.5.1/2.5.2/2.5.3 and the bounded 2.6.2/2.6.3/2.7.2/2.7.3 paths, creation explicitly selects the local environment and an authenticated `/environment` read proves its cwd before profile mutation; state verification uses protocol-v2 or direct-subscription WebSocket main-agent frames because `/status` was removed. The child environment sets `KIMI_CODE_SESSION_IDLE_RECLAIM_MS=0` to disable ambient idle-session reclamation.
28
49
  2. One ordinary `kimi -p -r` prompt runner resumes that session. Its recorded session-id source is `preactivated`, and the returned print session must match it.
29
- 3. A second short-lived web lifecycle rechecks the local binding on 2.5.0/2.5.1/2.5.2/2.5.3/2.6.2/2.6.3/2.7.2, disables swarm mode, verifies the version-appropriate state proof and the `swarm_mode.exit` journal record, and shuts down.
50
+ 3. A second short-lived web lifecycle rechecks the local binding on 2.5.0/2.5.1/2.5.2/2.5.3/2.6.2/2.6.3/2.7.2/2.7.3, disables swarm mode, verifies the version-appropriate state proof and the `swarm_mode.exit` journal record, and shuts down.
30
51
 
31
52
  Activation is inside the job's finite budget. Graceful process close has a bounded 15-second allowance. `runSwarm` solely owns deactivation: normal cleanup uses the remaining budget, while failure recovery has a separate two-second cancellation-aware bound and is never retried. Print/session failures stay primary. The ready token stays in memory and out of logs, and success cannot complete if cleanup fails. Post-mutation identity or process/group uncertainty preserves diagnostics and, for write-swarm, the recovery worktree. Process groups are rechecked after teardown; unknown survivors are unverified and unproven groups are not signalled. Older certified versions still launch swarm directly with `kimi -p`. This narrow lifecycle is not a full RPC transport or a model-driven activation workaround; the managed hook and workspace boundaries still govern every tool call.
32
53
 
33
54
  After updating the plugin, run Claude Code `/kimi:setup` or Codex `$kimi-setup`
34
55
  from that host's active install to re-pin its version-stamped hook path, then
35
- run setup with `--check`. This fixes path drift, not policy omissions in an older installed plugin. Older coexisting hooks still veto pursue goal-status tools; update each host only when authorized. Keep `default_plan_mode` absent or false. Upgrades
56
+ run setup with `--check`. This fixes path drift, not policy omissions in an older installed plugin. Older coexisting hooks still veto pursue goal-status tools; update each host only when authorized. Keep `default_plan_mode` absent or false if you use swarm or a CLI older than 2.4.0. Upgrades
36
57
  from pre-1.10 releases must also follow the historical native-v2 migration section below.
37
58
 
38
59
  ## Historical migration instructions