kimi-plugin-cc 3.0.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +3 -14
  3. package/README.md +428 -572
  4. package/assets/logo.svg +6 -0
  5. package/cordis.patch.yml +18 -0
  6. package/dist/background-spawn.js +4 -2
  7. package/dist/cli-client.js +105 -66
  8. package/dist/commands/ask.js +27 -12
  9. package/dist/commands/cancel.js +4 -13
  10. package/dist/commands/cli-helpers.js +1 -1
  11. package/dist/commands/pursue.js +3 -2
  12. package/dist/commands/registry.js +7 -26
  13. package/dist/commands/repair-sessions.js +7 -4
  14. package/dist/commands/replay.js +4 -3
  15. package/dist/commands/rescue.js +17 -5
  16. package/dist/commands/review.js +18 -5
  17. package/dist/commands/setup.js +283 -265
  18. package/dist/commands/swarm.js +20 -7
  19. package/dist/companion.js +142 -18
  20. package/dist/help.js +11 -7
  21. package/dist/hook-escape.js +7 -16
  22. package/dist/hooks/approval-hook.js +1762 -124
  23. package/dist/hooks/approval-policy.js +15 -10
  24. package/dist/hooks/config-safety.js +15 -24
  25. package/dist/hooks/hook-timing.js +1 -1
  26. package/dist/hooks/install-paths.js +224 -112
  27. package/dist/hooks/install.js +64 -169
  28. package/dist/hooks/managed-block.js +52 -101
  29. package/dist/job-store.js +117 -49
  30. package/dist/jobs.js +53 -1
  31. package/dist/kimi-engine.js +68 -92
  32. package/dist/kimi-errors.js +1 -1
  33. package/dist/kimi-journal.js +3 -2
  34. package/dist/kimi-releases.js +28 -49
  35. package/dist/kimi-timeouts.js +1 -15
  36. package/dist/kimi-version-probe.js +24 -72
  37. package/dist/logging.js +12 -7
  38. package/dist/mcp/binding.js +13 -4
  39. package/dist/mcp/job-control.js +386 -89
  40. package/dist/mcp/launcher.js +1 -1
  41. package/dist/mcp/operations.js +387 -193
  42. package/dist/mcp/protocol.js +116 -27
  43. package/dist/mcp/skills.js +130 -0
  44. package/dist/mcp/stdio.js +15 -2
  45. package/dist/native-v2-preflight.js +127 -35
  46. package/dist/parsing.js +45 -11
  47. package/dist/paths.js +20 -10
  48. package/dist/plugin-data.js +28 -83
  49. package/dist/read-scope.js +2 -2
  50. package/dist/render.js +13 -38
  51. package/dist/session-references.js +216 -0
  52. package/dist/session-title.js +1 -1
  53. package/dist/surface-routing.js +92 -5
  54. package/dist/swarm-activation.js +26 -137
  55. package/dist/version.js +1 -1
  56. package/docs/migration.md +46 -227
  57. package/docs/models.md +24 -66
  58. package/docs/safety.md +195 -400
  59. package/docs/session-visibility.md +24 -14
  60. package/docs/swarm-recovery.md +26 -20
  61. package/dsh/index.json +54 -0
  62. package/mcp_config.json +10 -0
  63. package/package.json +23 -82
  64. package/plugin.json +19 -0
  65. package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
  66. package/plugins/kimi-codex/.mcp.json +2 -3
  67. package/plugins/kimi-codex/dist/background-spawn.js +4 -2
  68. package/plugins/kimi-codex/dist/cli-client.js +105 -66
  69. package/plugins/kimi-codex/dist/commands/ask.js +27 -12
  70. package/plugins/kimi-codex/dist/commands/cancel.js +4 -13
  71. package/plugins/kimi-codex/dist/commands/cli-helpers.js +1 -1
  72. package/plugins/kimi-codex/dist/commands/pursue.js +3 -2
  73. package/plugins/kimi-codex/dist/commands/registry.js +7 -26
  74. package/plugins/kimi-codex/dist/commands/repair-sessions.js +7 -4
  75. package/plugins/kimi-codex/dist/commands/replay.js +4 -3
  76. package/plugins/kimi-codex/dist/commands/rescue.js +17 -5
  77. package/plugins/kimi-codex/dist/commands/review.js +18 -5
  78. package/plugins/kimi-codex/dist/commands/setup.js +283 -265
  79. package/plugins/kimi-codex/dist/commands/swarm.js +20 -7
  80. package/plugins/kimi-codex/dist/companion.js +142 -18
  81. package/plugins/kimi-codex/dist/help.js +11 -7
  82. package/plugins/kimi-codex/dist/hook-escape.js +7 -16
  83. package/plugins/kimi-codex/dist/hooks/approval-hook.js +1762 -124
  84. package/plugins/kimi-codex/dist/hooks/approval-policy.js +15 -10
  85. package/plugins/kimi-codex/dist/hooks/config-safety.js +15 -24
  86. package/plugins/kimi-codex/dist/hooks/hook-timing.js +1 -1
  87. package/plugins/kimi-codex/dist/hooks/install-paths.js +224 -112
  88. package/plugins/kimi-codex/dist/hooks/install.js +64 -169
  89. package/plugins/kimi-codex/dist/hooks/managed-block.js +52 -101
  90. package/plugins/kimi-codex/dist/job-store.js +117 -49
  91. package/plugins/kimi-codex/dist/jobs.js +53 -1
  92. package/plugins/kimi-codex/dist/kimi-engine.js +68 -92
  93. package/plugins/kimi-codex/dist/kimi-errors.js +1 -1
  94. package/plugins/kimi-codex/dist/kimi-journal.js +3 -2
  95. package/plugins/kimi-codex/dist/kimi-releases.js +28 -49
  96. package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -15
  97. package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -72
  98. package/plugins/kimi-codex/dist/logging.js +12 -7
  99. package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
  100. package/plugins/kimi-codex/dist/mcp/job-control.js +386 -89
  101. package/plugins/kimi-codex/dist/mcp/launcher.js +1 -1
  102. package/plugins/kimi-codex/dist/mcp/operations.js +387 -193
  103. package/plugins/kimi-codex/dist/mcp/protocol.js +116 -27
  104. package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
  105. package/plugins/kimi-codex/dist/mcp/stdio.js +15 -2
  106. package/plugins/kimi-codex/dist/native-v2-preflight.js +127 -35
  107. package/plugins/kimi-codex/dist/parsing.js +45 -11
  108. package/plugins/kimi-codex/dist/paths.js +20 -10
  109. package/plugins/kimi-codex/dist/plugin-data.js +28 -83
  110. package/plugins/kimi-codex/dist/read-scope.js +2 -2
  111. package/plugins/kimi-codex/dist/render.js +13 -38
  112. package/plugins/kimi-codex/dist/session-references.js +216 -0
  113. package/plugins/kimi-codex/dist/session-title.js +1 -1
  114. package/plugins/kimi-codex/dist/surface-routing.js +92 -5
  115. package/plugins/kimi-codex/dist/swarm-activation.js +26 -137
  116. package/plugins/kimi-codex/dist/version.js +1 -1
  117. package/plugins/kimi-codex/scripts/companion.sh +4 -15
  118. package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
  119. package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
  120. package/scripts/companion.sh +4 -15
  121. package/skills/kimi/SKILL.md +77 -0
  122. package/skills/kimi/agents/openai.yaml +6 -0
  123. package/CHANGELOG.md +0 -1402
  124. package/agents/kimi-pursue.md +0 -93
  125. package/agents/kimi-review.md +0 -86
  126. package/agents/kimi-swarm.md +0 -88
  127. package/agents/kimi-task.md +0 -93
  128. package/commands/README.md +0 -14
  129. package/commands/cancel.md +0 -17
  130. package/commands/pursue.md +0 -41
  131. package/commands/replay.md +0 -13
  132. package/commands/result.md +0 -13
  133. package/commands/review.md +0 -40
  134. package/commands/setup.md +0 -25
  135. package/commands/status.md +0 -13
  136. package/commands/swarm.md +0 -45
  137. package/commands/task.md +0 -40
  138. package/dist/commands/review-gate.js +0 -391
  139. package/dist/config.js +0 -22
  140. package/dist/dsh/companion.js +0 -177
  141. package/dist/dsh/index.js +0 -167
  142. package/dist/hooks/review-gate-stop.js +0 -19
  143. package/dist/schemas/review-gate-output.js +0 -41
  144. package/docs/registry-releases.md +0 -228
  145. package/docs/upstream-2.4.1-certification.md +0 -54
  146. package/docs/upstream-2.5.0-certification.md +0 -52
  147. package/docs/upstream-2.5.1-certification.md +0 -47
  148. package/docs/upstream-2.5.2-certification.md +0 -40
  149. package/docs/upstream-2.5.3-certification.md +0 -73
  150. package/docs/upstream-2.6.0-certification.md +0 -65
  151. package/docs/upstream-2.6.2-certification.md +0 -144
  152. package/docs/upstream-2.6.3-certification.md +0 -100
  153. package/docs/upstream-2.7.2-certification.md +0 -113
  154. package/docs/upstream-2.7.3-certification.md +0 -95
  155. package/docs/windows-validation.md +0 -39
  156. package/hooks/README.md +0 -9
  157. package/hooks/hooks.json +0 -16
  158. package/plugins/kimi-codex/dist/commands/review-gate.js +0 -391
  159. package/plugins/kimi-codex/dist/config.js +0 -22
  160. package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
  161. package/plugins/kimi-codex/dist/dsh/index.js +0 -167
  162. package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
  163. package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -41
  164. package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
  165. package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
  166. package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
  167. package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
  168. package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
  169. package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
  170. package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
  171. package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
  172. package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
  173. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -35
  174. package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
  175. package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -35
  176. package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
  177. package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
  178. package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
  179. package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -37
  180. package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
  181. package/plugins/kimi-codex/skills/kimi-task/SKILL.md +0 -37
  182. package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +0 -6
  183. package/plugins/kimi-dsh/LICENSE +0 -201
  184. package/plugins/kimi-dsh/README.md +0 -84
  185. package/plugins/kimi-dsh/cordis.patch.yml +0 -45
  186. package/plugins/kimi-dsh/dist/background-spawn.js +0 -209
  187. package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
  188. package/plugins/kimi-dsh/dist/cli-client.js +0 -1097
  189. package/plugins/kimi-dsh/dist/commands/ask.js +0 -269
  190. package/plugins/kimi-dsh/dist/commands/cancel.js +0 -177
  191. package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -302
  192. package/plugins/kimi-dsh/dist/commands/models.js +0 -139
  193. package/plugins/kimi-dsh/dist/commands/pursue.js +0 -293
  194. package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
  195. package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
  196. package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -266
  197. package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
  198. package/plugins/kimi-dsh/dist/commands/rescue.js +0 -277
  199. package/plugins/kimi-dsh/dist/commands/result.js +0 -72
  200. package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -391
  201. package/plugins/kimi-dsh/dist/commands/review.js +0 -217
  202. package/plugins/kimi-dsh/dist/commands/setup.js +0 -1465
  203. package/plugins/kimi-dsh/dist/commands/status.js +0 -27
  204. package/plugins/kimi-dsh/dist/commands/swarm.js +0 -823
  205. package/plugins/kimi-dsh/dist/commands/worker.js +0 -24
  206. package/plugins/kimi-dsh/dist/companion.js +0 -99
  207. package/plugins/kimi-dsh/dist/config.js +0 -22
  208. package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
  209. package/plugins/kimi-dsh/dist/dsh/index.js +0 -167
  210. package/plugins/kimi-dsh/dist/errors.js +0 -40
  211. package/plugins/kimi-dsh/dist/git.js +0 -216
  212. package/plugins/kimi-dsh/dist/help.js +0 -43
  213. package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
  214. package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -145
  215. package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -295
  216. package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -641
  217. package/plugins/kimi-dsh/dist/hooks/hook-timing.js +0 -48
  218. package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
  219. package/plugins/kimi-dsh/dist/hooks/install.js +0 -405
  220. package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -729
  221. package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
  222. package/plugins/kimi-dsh/dist/job-id.js +0 -12
  223. package/plugins/kimi-dsh/dist/job-store.js +0 -631
  224. package/plugins/kimi-dsh/dist/jobs.js +0 -212
  225. package/plugins/kimi-dsh/dist/kimi-command.js +0 -144
  226. package/plugins/kimi-dsh/dist/kimi-engine.js +0 -770
  227. package/plugins/kimi-dsh/dist/kimi-errors.js +0 -205
  228. package/plugins/kimi-dsh/dist/kimi-home.js +0 -15
  229. package/plugins/kimi-dsh/dist/kimi-journal.js +0 -41
  230. package/plugins/kimi-dsh/dist/kimi-releases.js +0 -144
  231. package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
  232. package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -198
  233. package/plugins/kimi-dsh/dist/logging.js +0 -22
  234. package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
  235. package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -343
  236. package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -263
  237. package/plugins/kimi-dsh/dist/mcp/operations.js +0 -333
  238. package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -277
  239. package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
  240. package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -79
  241. package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
  242. package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
  243. package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
  244. package/plugins/kimi-dsh/dist/model-command.js +0 -34
  245. package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -596
  246. package/plugins/kimi-dsh/dist/package.json +0 -1
  247. package/plugins/kimi-dsh/dist/parsing.js +0 -554
  248. package/plugins/kimi-dsh/dist/paths.js +0 -35
  249. package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
  250. package/plugins/kimi-dsh/dist/process-tree.js +0 -597
  251. package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
  252. package/plugins/kimi-dsh/dist/read-scope.js +0 -435
  253. package/plugins/kimi-dsh/dist/render.js +0 -214
  254. package/plugins/kimi-dsh/dist/rescue-approval.js +0 -1242
  255. package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -41
  256. package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
  257. package/plugins/kimi-dsh/dist/session-title.js +0 -313
  258. package/plugins/kimi-dsh/dist/stream-json.js +0 -344
  259. package/plugins/kimi-dsh/dist/surface-routing.js +0 -21
  260. package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1194
  261. package/plugins/kimi-dsh/dist/swarm-policy.js +0 -74
  262. package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -166
  263. package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
  264. package/plugins/kimi-dsh/dist/types.js +0 -1
  265. package/plugins/kimi-dsh/dist/util.js +0 -28
  266. package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
  267. package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
  268. package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
  269. package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
  270. package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
  271. package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
  272. package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
  273. package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
  274. package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
  275. package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
  276. package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
  277. package/plugins/kimi-dsh/dist/version.js +0 -7
  278. package/plugins/kimi-dsh/package.json +0 -78
  279. package/plugins/kimi-dsh/scripts/companion.sh +0 -37
  280. package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
  281. package/scripts/review-gate-hook.sh +0 -32
@@ -21,7 +21,7 @@ import { parseVersionLine } from "./kimi-version-probe.js";
21
21
  import { assertScopeSupported, NETWORK_ENV, READ_ROOTS_ENV, READ_SCOPE_LABELS, readScopeEnvironment, SCOPE_FLAGS_WRITE_MESSAGE, } from "./read-scope.js";
22
22
  import { sleep } from "./util.js";
23
23
  import { BOUNDED_SWARM_POLICY, SWARM_CHILD_TIMEOUT_MS, SWARM_POLICY_ENV, SWARM_WAVE_SIZE_ENV, usesBoundedSwarmPolicy, } from "./swarm-policy.js";
24
- import { StreamJsonParser, extractSessionIdFromStderr, } from "./stream-json.js";
24
+ import { StreamJsonParser, } from "./stream-json.js";
25
25
  import { collectDescendantIdentities, collectDescendantIdentitiesForRoots, raceValueWithTimeout, revalidateProcessIdentities, waitForProcessTreeExit, } from "./process-tree.js";
26
26
  /** Bytes of stderr retained for diagnostics on completion. Rolling buffer. */
27
27
  const STDERR_TAIL_BYTES = 8192;
@@ -59,9 +59,9 @@ export async function runCliPrompt(opts) {
59
59
  if (opts.commandLabel === "rescue" || opts.commandLabel === "swarm-write") {
60
60
  assertWorkspaceSpellable(opts.commandLabel, [opts.cwd, opts.trustedWorkspaceRoot], "cli-client.pre-spawn");
61
61
  }
62
- // The master experimental flag enables v2-only features (tower, subagent
63
- // fork) outside the certified no-plan profile. Legacy-v1 and uncertified
64
- // plans refuse it at the final boundary too; native-v2 children never get it.
62
+ // The master experimental flag enables v2-only features outside the
63
+ // reviewed profile. A legacy-v1 plan refuses it at the final boundary too;
64
+ // native-v2 children never get it.
65
65
  assertNoUnsafeExperimentalSelector(opts.env, "cli-client.pre-spawn", opts.executionPlan);
66
66
  // Validate the ACTUAL prefix argv used for this spawn — not only the
67
67
  // env-resolved value — so a forged/corrupt persisted plan cannot smuggle a
@@ -86,7 +86,7 @@ export async function runCliPrompt(opts) {
86
86
  const env = buildKimiCliEnvironment(opts);
87
87
  const boundedSwarm = usesBoundedSwarmPolicy(opts.executionPlan);
88
88
  if (opts.logPath !== undefined) {
89
- await mkdir(path.dirname(opts.logPath), { recursive: true }).catch(() => {
89
+ await mkdir(path.dirname(opts.logPath), { recursive: true, mode: 0o700 }).catch(() => {
90
90
  // Best-effort; if mkdir fails the appendFile below will error and be
91
91
  // swallowed by the log chain (diagnostics are non-blocking).
92
92
  });
@@ -138,7 +138,7 @@ export async function runCliPrompt(opts) {
138
138
  const hookMonitor = createHookEscapeMonitor({ commandLabel: opts.commandLabel,
139
139
  operationKind: opts.executionPlan.operationKind, trustedWorkspaceRoot: opts.trustedWorkspaceRoot, cwd: opts.cwd,
140
140
  swarmPolicy: env[SWARM_POLICY_ENV], swarmWaveSize: env[SWARM_WAVE_SIZE_ENV],
141
- readRoots: env[READ_ROOTS_ENV], network: env[NETWORK_ENV] });
141
+ readRoots: env[READ_ROOTS_ENV], network: env[NETWORK_ENV], kimiVersion: opts.executionPlan.kimiVersion });
142
142
  const hookEscapes = [];
143
143
  const noteHookEscape = (escape) => {
144
144
  hookEscapes.push(escape);
@@ -156,7 +156,7 @@ export async function runCliPrompt(opts) {
156
156
  if (opts.logPath === undefined)
157
157
  return;
158
158
  const line = `${JSON.stringify({ ts: new Date().toISOString(), ...payload })}\n`;
159
- logChain = logChain.then(() => appendFile(opts.logPath, line, "utf8").catch(() => {
159
+ logChain = logChain.then(() => appendFile(opts.logPath, line, { encoding: "utf8", mode: 0o600 }).catch(() => {
160
160
  // Diagnostics best-effort; never crash on log failure.
161
161
  }));
162
162
  };
@@ -172,7 +172,6 @@ export async function runCliPrompt(opts) {
172
172
  plan_certification: opts.executionPlan.certification,
173
173
  safety_profile: opts.executionPlan.safetyProfile,
174
174
  swarm_max_concurrency: opts.swarmMaxConcurrency ?? null,
175
- legacy_v1_forced: env.KIMI_CODE_LEGACY_FLAG === KIMI_LEGACY_FORCED_VALUE,
176
175
  });
177
176
  const invokeOnRecord = (record) => {
178
177
  if (opts.onRecord === undefined)
@@ -185,9 +184,11 @@ export async function runCliPrompt(opts) {
185
184
  }
186
185
  };
187
186
  // A native-v2 plan must see agent-core-v2's pre-tool system.version marker
188
- // before any consumer-facing output; a legacy plan must never see it.
187
+ // before any consumer-facing output. Generic test-bypass plans without an
188
+ // explicit safety profile let mock scripts omit the marker line.
189
+ const bypassMarkerCheck = opts.executionPlan.certification === "test-bypass" && opts.executionPlan.safetyProfile === null;
189
190
  const requireMarkerBeforeOutput = (what) => {
190
- if (plannedEngine !== "native-v2" || announcedSystemVersion !== undefined)
191
+ if (bypassMarkerCheck || plannedEngine !== "native-v2" || announcedSystemVersion !== undefined)
191
192
  return false;
192
193
  handleEngineMismatch?.({
193
194
  observedEngine: null,
@@ -727,6 +728,55 @@ export async function runCliPrompt(opts) {
727
728
  if (opts.signal?.aborted === true) {
728
729
  onAbort();
729
730
  }
731
+ // Attach stdout/stderr buffering, close capture, and stdin.end() BEFORE
732
+ // awaiting opts.onSpawn so a fast child cannot emit data or close while an
733
+ // async onSpawn (e.g., process-identity lookup) is pending. Buffer chunks
734
+ // until onSpawn succeeds so onSpawn still completes before any onRecord or
735
+ // settlement, and an onSpawn failure tears down without delivering output.
736
+ let streamListenersReady = false;
737
+ const earlyStdout = [];
738
+ let earlyStderrTail = "";
739
+ let earlyClose;
740
+ let earlyStreamSetupError;
741
+ let handleClose;
742
+ child.on("close", (exitCode, signal) => {
743
+ if (streamListenersReady && handleClose) {
744
+ void handleClose(exitCode, signal);
745
+ }
746
+ else {
747
+ earlyClose = { exitCode, signal };
748
+ }
749
+ });
750
+ // Stdin: kimi -p reads from argv, not stdin. End it immediately so the
751
+ // child never blocks. Stream method calls on a failed-spawn child can
752
+ // throw synchronously — capture and surface after early error handling.
753
+ try {
754
+ child.stdout.setEncoding("utf8");
755
+ child.stderr.setEncoding("utf8");
756
+ child.stdout.on("data", (chunk) => {
757
+ if (streamListenersReady) {
758
+ consumeOutcomes(parser.push(chunk));
759
+ }
760
+ else {
761
+ earlyStdout.push(chunk);
762
+ }
763
+ });
764
+ child.stderr.on("data", (chunk) => {
765
+ if (streamListenersReady) {
766
+ stderrTail = appendToTail(stderrTail, chunk, STDERR_TAIL_BYTES);
767
+ }
768
+ else {
769
+ earlyStderrTail = appendToTail(earlyStderrTail, chunk, STDERR_TAIL_BYTES);
770
+ }
771
+ });
772
+ child.stdin.on("error", () => {
773
+ // Ignore EPIPE/ENOENT on stdin; child 'error' or 'close' reports the cause.
774
+ });
775
+ child.stdin.end();
776
+ }
777
+ catch (err) {
778
+ earlyStreamSetupError = err;
779
+ }
730
780
  if (child.pid !== undefined && opts.onSpawn) {
731
781
  try {
732
782
  await opts.onSpawn(child.pid);
@@ -761,8 +811,13 @@ export async function runCliPrompt(opts) {
761
811
  });
762
812
  settle("reject", processError("kimi subprocess error", "cli-client.process", captured));
763
813
  });
814
+ return;
815
+ }
816
+ if (earlyStreamSetupError !== undefined) {
817
+ settle("reject", processError("kimi subprocess stream setup failed", "cli-client.streams", earlyStreamSetupError));
818
+ return;
764
819
  }
765
- child.on("close", async (exitCode, signal) => {
820
+ handleClose = async (exitCode, signal) => {
766
821
  consumeOutcomes(parser.flush());
767
822
  if (!engineMismatchDetected &&
768
823
  exitCode === 0 &&
@@ -770,12 +825,7 @@ export async function runCliPrompt(opts) {
770
825
  requireMarkerBeforeOutput("a clean exit")) {
771
826
  return;
772
827
  }
773
- // The stderr resume-hint channel is the kimi 0.1.x fallback and exists
774
- // only for legacy-v1 plans; a native-v2 plan pins a session id from the
775
- // stdout meta record alone (after the marker), so stderr can never pin
776
- // an id ahead of, or different from, the provenance-checked stream.
777
- const sessionId = announcedSessionId ??
778
- (plannedEngine === "legacy-v1" ? extractSessionIdFromStderr(stderrTail) : undefined);
828
+ const sessionId = announcedSessionId;
779
829
  appendLogLine({
780
830
  event: "exit",
781
831
  exit_code: exitCode,
@@ -795,15 +845,7 @@ export async function runCliPrompt(opts) {
795
845
  goalSummary: announcedGoalSummary,
796
846
  cliError: announcedCliError,
797
847
  systemVersion: announcedSystemVersion,
798
- observedEngine: announcedSystemVersion !== undefined
799
- ? "native-v2"
800
- : plannedEngine === "legacy-v1" &&
801
- (exitCode === 0 ||
802
- records.length > 0 ||
803
- sessionId !== undefined ||
804
- announcedGoalSummary !== undefined)
805
- ? "legacy-v1"
806
- : null,
848
+ observedEngine: announcedSystemVersion !== undefined ? "native-v2" : null,
807
849
  records,
808
850
  malformed,
809
851
  stderrTail,
@@ -811,35 +853,20 @@ export async function runCliPrompt(opts) {
811
853
  signal,
812
854
  aborted,
813
855
  });
814
- });
815
- // Stdin: kimi -p reads from argv, not stdin. End it immediately so the
816
- // child never blocks. Stream method calls on a failed-spawn child can
817
- // throw synchronously — guard so the 'error' event still wins.
818
- try {
819
- child.stdout.setEncoding("utf8");
820
- child.stderr.setEncoding("utf8");
821
- child.stdout.on("data", (chunk) => {
856
+ };
857
+ streamListenersReady = true;
858
+ if (earlyStderrTail.length > 0) {
859
+ stderrTail = appendToTail(stderrTail, earlyStderrTail, STDERR_TAIL_BYTES);
860
+ earlyStderrTail = "";
861
+ }
862
+ if (earlyStdout.length > 0) {
863
+ for (const chunk of earlyStdout) {
822
864
  consumeOutcomes(parser.push(chunk));
823
- });
824
- child.stderr.on("data", (chunk) => {
825
- // First-announce-wins across both channels: once a session id is
826
- // pinned (from the stdout meta record or an earlier stderr line),
827
- // never let a later stderr line overwrite it. The stderr channel is
828
- // the 0.1.x fallback and is consulted ONLY for legacy-v1 plans — on a
829
- // native-v2 plan a stderr line could otherwise pin a session id before
830
- // (or different from) the provenance-checked stdout stream.
831
- if (plannedEngine === "legacy-v1" && announcedSessionId === undefined) {
832
- const nextSessionId = extractSessionIdFromStderr(stderrTail + chunk);
833
- if (nextSessionId !== undefined) {
834
- announcedSessionId = nextSessionId;
835
- }
836
- }
837
- stderrTail = appendToTail(stderrTail, chunk, STDERR_TAIL_BYTES);
838
- });
839
- child.stdin.end();
865
+ }
866
+ earlyStdout.length = 0;
840
867
  }
841
- catch (err) {
842
- settle("reject", processError("kimi subprocess stream setup failed", "cli-client.streams", err));
868
+ if (earlyClose !== undefined && !settlementStarted) {
869
+ void handleClose(earlyClose.exitCode, earlyClose.signal);
843
870
  }
844
871
  });
845
872
  }
@@ -972,8 +999,6 @@ function parseExactVersionToken(value) {
972
999
  return undefined;
973
1000
  return parseVersionLine(value)?.raw;
974
1001
  }
975
- const KIMI_LEGACY_ENV = "KIMI_CODE_LEGACY_FLAG";
976
- const KIMI_LEGACY_FORCED_VALUE = "1";
977
1002
  function buildArgs(opts) {
978
1003
  const args = [...(opts.prefixArgs ?? [])];
979
1004
  args.push("--output-format", "stream-json");
@@ -1001,8 +1026,28 @@ function buildArgs(opts) {
1001
1026
  args.push("-p", opts.prompt);
1002
1027
  return args;
1003
1028
  }
1029
+ /**
1030
+ * Windows environment names are case-insensitive, so `kimi_code_experimental_flag`
1031
+ * reaches a child exactly like the upper-case name. Re-key every KIMI_* name to
1032
+ * upper case, so the exact-name deletes and overrides below decide it. Where
1033
+ * both spellings exist the upper-case one wins, as it does in Windows itself.
1034
+ */
1035
+ export function copyChildEnvironment(source, platform = process.platform) {
1036
+ const env = { ...source };
1037
+ if (platform !== "win32")
1038
+ return env;
1039
+ for (const key of Object.keys(env)) {
1040
+ const upper = key.toUpperCase();
1041
+ if (upper === key || !upper.startsWith("KIMI_"))
1042
+ continue;
1043
+ if (env[upper] === undefined)
1044
+ env[upper] = env[key];
1045
+ delete env[key];
1046
+ }
1047
+ return env;
1048
+ }
1004
1049
  export function buildKimiCliEnvironment(opts) {
1005
- const env = { ...opts.env };
1050
+ const env = copyChildEnvironment(opts.env);
1006
1051
  // A previous host/job cannot opt another operation into a swarm policy or
1007
1052
  // choose its bound. Only this immutable execution plan grants the policy.
1008
1053
  delete env[SWARM_POLICY_ENV];
@@ -1020,22 +1065,16 @@ export function buildKimiCliEnvironment(opts) {
1020
1065
  env.KIMI_MODEL_THINKING_EFFORT = opts.thinkingEffort;
1021
1066
  // Ambient workspace trust starts project MCP stdio servers outside PreToolUse.
1022
1067
  delete env.KIMI_CODE_TRUST_WORKSPACE;
1023
- // Legacy-v1 plans use this flag on releases whose unflagged -p default can
1024
- // route to native-v2. Always overwrite ambient false values; older releases
1025
- // ignore it. The engine choice stays plugin-owned, while certified native-v2
1026
- // plans use the no-plan construction rather than a legacy pin.
1027
- if (opts.executionPlan.intendedEngine === "legacy-v1") {
1028
- env[KIMI_LEGACY_ENV] = KIMI_LEGACY_FORCED_VALUE;
1029
- }
1030
1068
  // Suppress passive update checks on the `-p` path. Manually staged native
1031
1069
  // swaps remain an upstream exception, so the exact probe and first-line
1032
1070
  // version marker must still prove the spawned artifact's identity.
1033
1071
  env.KIMI_CODE_NO_AUTO_UPDATE = "1";
1034
1072
  // Plugin-owned web lifecycles must not inherit ambient idle-session reclamation.
1035
1073
  env.KIMI_CODE_SESSION_IDLE_RECLAIM_MS = "0";
1036
- // Tower and subagent fork are uncertified. A per-flag env value outranks
1037
- // [experimental] config and the master flag upstream (0.42.0-2.7.3), and
1038
- // "0" parses as false there, so these force both off for print and web.
1074
+ // Plugin tasks run without tower and subagent fork. A per-flag env value
1075
+ // outranks [experimental] config and the master flag upstream
1076
+ // (0.42.0-2.8.0), and "0" parses as false there, so these force both off
1077
+ // for print and web. 2.8.0 removed subagent fork and ignores its variable.
1039
1078
  env.KIMI_CODE_EXPERIMENTAL_TOWER = "0";
1040
1079
  env.KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK = "0";
1041
1080
  // The master flag is read only from the child's own environment, so a
@@ -7,7 +7,7 @@ import { assertPersistedResumeLineage, executionPlanFromPersisted, observedExecu
7
7
  import { getManagedCommandConfig } from "./registry.js";
8
8
  import { RuntimeError } from "../errors.js";
9
9
  import { resolveRepoIdentity } from "../git.js";
10
- import { digestPrompt, markJobCancelled, markJobFailed, sweepStaleJobs } from "../jobs.js";
10
+ import { digestPrompt, markJobCancelled, markJobFailed, recordKimiSpawnIdentity, serializedProcessIdentity, sweepStaleJobs, } from "../jobs.js";
11
11
  import { JobStore } from "../job-store.js";
12
12
  import { KIMI_ASK_PROMPT_TIMEOUT_MS } from "../kimi-timeouts.js";
13
13
  import { writeInvocationLogHeader } from "../logging.js";
@@ -19,6 +19,7 @@ import { classifyManagedCommandFailure } from "../kimi-errors.js";
19
19
  import { startBackgroundJob } from "../background-spawn.js";
20
20
  import { warnInheritedBudget, captureTimeoutPartialOutput, assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes, resolveResumeSession, assertNetworkResumeConfined, resumeBudget, hookRefusal } from "./cli-helpers.js";
21
21
  import { buildKimiSessionTitle, syncKimiSessionTitle } from "../session-title.js";
22
+ import { appendSessionReferences, resolveSessionReferences, stripSessionReferences, withReferenceReadRoots } from "../session-references.js";
22
23
  import { shorten } from "../util.js";
23
24
  const ASK_SUMMARY_MAX = 120;
24
25
  const ASK_AGENT_PROFILE_PLACEHOLDER = "<cli-client>";
@@ -47,7 +48,7 @@ export async function runAsk(argv, context) {
47
48
  if (parsed.help)
48
49
  return companionHelp(["ask", ...argv]);
49
50
  // Scope always comes from this invocation, never from a resumed job.
50
- const readScope = parsed.readRoots === undefined && parsed.network === undefined ? undefined
51
+ const callerScope = parsed.readRoots === undefined && parsed.network === undefined ? undefined
51
52
  : await resolveReadScope(parsed.readRoots, parsed.network, "ask.parse");
52
53
  if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
53
54
  await requireAskHookInstalled(context);
@@ -61,10 +62,7 @@ export async function runAsk(argv, context) {
61
62
  await sweepStaleJobs(store, paths);
62
63
  const jobId = allocateJobId(context);
63
64
  const sessionResolution = await resolveResumeSession(store, "ask", repoIdentity.repoId, parsed);
64
- if (readScope?.network === true) {
65
- assertNetworkResumeConfined(store, "ask", sessionResolution, effectiveReadRoots(readScope, context.cwd));
66
- }
67
- const askPrompt = buildAskPrompt(parsed.prompt, sessionResolution.reusedSession);
65
+ const basePrompt = buildAskPrompt(parsed.prompt, sessionResolution.reusedSession);
68
66
  const executionPlan = await prepareKimiExecutionPlan({
69
67
  operationKind: "ask",
70
68
  cwd: context.cwd,
@@ -74,7 +72,17 @@ export async function runAsk(argv, context) {
74
72
  resumeSessionId: sessionResolution.kimiSessionId ?? undefined,
75
73
  resumeSource: sessionResolution.sourceJob,
76
74
  });
77
- assertScopeSupported(readScope, executionPlan.certification, "INVALID_ARGS", "ask.parse");
75
+ assertScopeSupported(callerScope, executionPlan.certification, "INVALID_ARGS", "ask.parse");
76
+ const references = await resolveSessionReferences(parsed.referenceSessions, {
77
+ store, env: context.env, spawnCwd: context.cwd, plan: executionPlan,
78
+ resumeSessionId: sessionResolution.kimiSessionId, stage: "ask.reference-session",
79
+ });
80
+ // A named session is a root this call grants, so the resume rule judges the widened roots.
81
+ const readScope = withReferenceReadRoots(callerScope, references);
82
+ if (readScope?.network === true) {
83
+ assertNetworkResumeConfined(store, "ask", sessionResolution, effectiveReadRoots(readScope, context.cwd));
84
+ }
85
+ const askPrompt = appendSessionReferences(basePrompt, references);
78
86
  const logPath = path.join(paths.logsDir, `ask-${jobId}.jsonl`);
79
87
  const job = store.createJob({
80
88
  job_id: jobId,
@@ -89,6 +97,7 @@ export async function runAsk(argv, context) {
89
97
  ...resumeBudget("ask", parsed.budgetMs, sessionResolution.sourceJob),
90
98
  pid: parsed.background ? null : process.pid,
91
99
  kimi_pid: null,
100
+ companion_identity: parsed.background ? null : await serializedProcessIdentity(process.pid),
92
101
  status: "running",
93
102
  kimi_session_id: sessionResolution.kimiSessionId,
94
103
  kimi_session_id_source: sessionResolution.sourceJob?.kimi_session_id_source ?? null,
@@ -161,7 +170,12 @@ export async function executeAskJob(jobId, prompt, context, options) {
161
170
  await assertPersistedResumeLineage(store, executionPlan, job.kimi_session_id, "ask");
162
171
  }
163
172
  if (options?.workerPid) {
164
- store.updateRunningJob(job.job_id, { pid: options.workerPid, phase: "worker-running" });
173
+ const workerIdentity = await serializedProcessIdentity(options.workerPid);
174
+ store.updateRunningJob(job.job_id, {
175
+ pid: options.workerPid,
176
+ ...(workerIdentity ? { companion_identity: workerIdentity } : {}),
177
+ phase: "worker-running",
178
+ });
165
179
  }
166
180
  const result = await runCliPromptWithBudget({
167
181
  cwd: job.cwd,
@@ -176,7 +190,7 @@ export async function executeAskJob(jobId, prompt, context, options) {
176
190
  readScope,
177
191
  resumeSessionId: job.kimi_session_id ?? undefined,
178
192
  logPath: job.stream_log_path,
179
- onSpawn: (pid) => { store.updateRunningJob(job.job_id, { kimi_pid: pid }); },
193
+ onSpawn: async (pid) => { await recordKimiSpawnIdentity(store, job.job_id, pid); },
180
194
  signal: handlers.signal,
181
195
  }, job.budget_ms ?? KIMI_ASK_PROMPT_TIMEOUT_MS, "ask.prompt");
182
196
  store.updateRunningJob(job.job_id, observedExecutionFields(result));
@@ -263,7 +277,8 @@ function buildAskPrompt(question, reusedSession) {
263
277
  throw new RuntimeError("INVALID_ARGS", "ask requires a question after the flags.", "ask.parse");
264
278
  }
265
279
  export function askPromptSubject(prompt) {
266
- if (prompt.startsWith(ASK_PROMPT_PREFIX))
267
- return prompt.slice(ASK_PROMPT_PREFIX.length);
268
- return prompt === ASK_RESUME_PROMPT ? ASK_CONTINUE_TASK : prompt;
280
+ const body = stripSessionReferences(prompt);
281
+ if (body.startsWith(ASK_PROMPT_PREFIX))
282
+ return body.slice(ASK_PROMPT_PREFIX.length);
283
+ return body === ASK_RESUME_PROMPT ? ASK_CONTINUE_TASK : body;
269
284
  }
@@ -5,7 +5,6 @@ import { JobStore, withJobStore } from "../job-store.js";
5
5
  import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
6
6
  import { parseJobLookupArgs } from "../parsing.js";
7
7
  import { revalidateProcessIdentities } from "../process-tree.js";
8
- import { getManagedCommandConfig } from "./registry.js";
9
8
  import { sleep } from "../util.js";
10
9
  export async function runCancel(argv, context) {
11
10
  const parsed = parseJobLookupArgs(argv);
@@ -14,7 +13,8 @@ export async function runCancel(argv, context) {
14
13
  const repoIdentity = await resolveRepoIdentity(context.cwd);
15
14
  const store = new JobStore(paths);
16
15
  try {
17
- await sweepStaleJobs(store, paths);
16
+ const isMcpCancel = context.mcpCompanionIdentity !== undefined || context.mcpKimiIdentity !== undefined;
17
+ await sweepStaleJobs(store, paths, isMcpCancel ? { repoId: repoIdentity.repoId, workspaceCwd: context.cwd } : undefined);
18
18
  const job = parsed.jobId
19
19
  ? store.getJob(parsed.jobId)
20
20
  : store.findLatestJob({
@@ -34,7 +34,7 @@ export async function runCancel(argv, context) {
34
34
  }
35
35
  if (store.getMcpTask(job.job_id) &&
36
36
  (context.mcpCompanionIdentity === undefined || context.mcpKimiIdentity === undefined)) {
37
- throw new RuntimeError("MCP_CANCEL_REQUIRES_BINDING", `MCP job ${job.job_id} requires MCP job-control cancellation with recorded identities; use tasks/cancel or kimi_job_cancel.`, "mcp.cancel");
37
+ throw new RuntimeError("MCP_CANCEL_REQUIRES_BINDING", `MCP job ${job.job_id} requires MCP job-control cancellation with recorded identities; use tasks/cancel or kimi_job (action: "cancel").`, "mcp.cancel");
38
38
  }
39
39
  const recovery = store.getSwarmRecovery(job.job_id)?.record;
40
40
  if (recovery) {
@@ -47,20 +47,11 @@ export async function runCancel(argv, context) {
47
47
  if (job.pid === null && job.kimi_pid === null) {
48
48
  throw new RuntimeError("CANCEL_NOT_SUPPORTED", `Job ${job.job_id} does not have a recorded process id to cancel.`, "cancel.runtime");
49
49
  }
50
- // review_gate runs in a Stop hook. Pre-mark the row as cancelled before
51
- // signaling so the subprocess close/result path cannot persist a failure
52
- // over the user's intent; later updates are no-ops on a terminal row.
53
- //
54
- // The terminal row also makes waitForCancellation return before its own
55
- // escalation, so this path always attempts SIGTERM after the pre-mark
56
- // attempt, waits 1s, and sends SIGKILL only if a recorded process remains
57
- // live. A pre-mark failure is rethrown only after termination is attempted.
58
50
  if (job.command_type === "review_gate") {
59
51
  let preMarkError;
60
52
  try {
61
53
  await withJobStore(paths, async (preMarkStore) => {
62
- const reviewGateCancel = getManagedCommandConfig("review_gate").cancellation;
63
- await markJobCancelled(preMarkStore, paths, job, reviewGateCancel.cancelledSummary, new RuntimeError(reviewGateCancel.errorCodes.cancelled, reviewGateCancel.cancelMessages.default, "cancel.runtime"));
54
+ await markJobCancelled(preMarkStore, paths, job, "review_gate cancelled by user request.", new RuntimeError("REVIEW_GATE_CANCELLED", "review_gate cancelled by user request.", "cancel.runtime"));
64
55
  });
65
56
  }
66
57
  catch (error) {
@@ -277,7 +277,7 @@ export function assertNetworkResumeConfined(store, kind, resolution, currentRoot
277
277
  jobId = job?.resumed_from_job_id;
278
278
  }
279
279
  if (!confined) {
280
- throw new RuntimeError("INVALID_ARGS", `${kind} --network cannot resume session ${sessionId ?? "<unknown>"}: an earlier turn in it ran without confined reads, or could read outside this call's workspace and --read-root directories (or its history is not recorded), so those reads could be sent out. ` +
280
+ throw new RuntimeError("INVALID_ARGS", `${kind} --network cannot resume session ${sessionId ?? "<unknown>"}: an earlier turn in it ran without confined reads, or could read outside this call's workspace, --read-root directories and referenced sessions (or its history is not recorded), so those reads could be sent out. ` +
281
281
  `Start a fresh session instead: ${kind} --fresh --network [--read-root <dir>] <prompt>.`, `${kind}.resume`);
282
282
  }
283
283
  }
@@ -5,7 +5,7 @@ import { runCliPromptWithBudget } from "../cli-client.js";
5
5
  import { executionPlanFromPersisted, observedExecutionFields, persistedExecutionPlanFields, prepareKimiExecutionPlan, } from "../kimi-engine.js";
6
6
  import { RuntimeError } from "../errors.js";
7
7
  import { resolveRepoIdentity } from "../git.js";
8
- import { digestPrompt, markJobCancelled, markJobFailed, sweepStaleJobs } from "../jobs.js";
8
+ import { digestPrompt, markJobCancelled, markJobFailed, recordKimiSpawnIdentity, serializedProcessIdentity, sweepStaleJobs, } from "../jobs.js";
9
9
  import { JobStore } from "../job-store.js";
10
10
  import { classifyManagedCommandFailure } from "../kimi-errors.js";
11
11
  import { KIMI_PURSUE_DEFAULT_BUDGET_MS } from "../kimi-timeouts.js";
@@ -139,6 +139,7 @@ export async function runPursue(argv, context) {
139
139
  budget_source: parsed.budgetMs !== undefined ? "explicit" : "default",
140
140
  pid: process.pid,
141
141
  kimi_pid: null,
142
+ companion_identity: await serializedProcessIdentity(process.pid),
142
143
  status: "running",
143
144
  kimi_session_id: null,
144
145
  ...persistedExecutionPlanFields(executionPlan),
@@ -219,7 +220,7 @@ async function executePursueJob(jobId, prompt, objective, budgetMs, context) {
219
220
  model: job.model ?? undefined,
220
221
  thinkingEffort: job.thinking_effort ?? undefined,
221
222
  logPath: job.stream_log_path,
222
- onSpawn: (pid) => { store.updateRunningJob(job.job_id, { kimi_pid: pid }); },
223
+ onSpawn: async (pid) => { await recordKimiSpawnIdentity(store, job.job_id, pid); },
223
224
  signal: handlers.signal,
224
225
  }, budgetMs, "pursue.prompt");
225
226
  store.updateRunningJob(job.job_id, observedExecutionFields(result));
@@ -1,11 +1,6 @@
1
1
  import { RuntimeError } from "../errors.js";
2
2
  const passthroughOutput = "passthrough";
3
- const parsedOutput = "parsed";
4
3
  const DEFAULT_ESCALATION_MS = 1_500;
5
- /**
6
- * Build cancellation config from the display name used verbatim in messages
7
- * and the uppercase stem used in error codes.
8
- */
9
4
  function makeCancellationConfig(prefix) {
10
5
  const { displayName, errorCodeStem } = prefix;
11
6
  return {
@@ -24,13 +19,6 @@ function makeCancellationConfig(prefix) {
24
19
  failedSummary: `${displayName} failed.`,
25
20
  };
26
21
  }
27
- /**
28
- * Single source of truth for per-command behavior. Only commands using the
29
- * managed-cancellation flow participate; `setup` and `task` do not.
30
- *
31
- * Display-name casing is part of the user-visible contract: `Ask` and `Rescue`
32
- * are title-cased, while `review`, `challenge`, and `review_gate` are lowercase.
33
- */
34
22
  export const COMMAND_REGISTRY = {
35
23
  ask: {
36
24
  outputMode: passthroughOutput,
@@ -48,22 +36,15 @@ export const COMMAND_REGISTRY = {
48
36
  outputMode: passthroughOutput,
49
37
  cancellation: makeCancellationConfig({ displayName: "Rescue", errorCodeStem: "RESCUE" }),
50
38
  },
51
- review_gate: {
52
- outputMode: parsedOutput,
53
- cancellation: makeCancellationConfig({ displayName: "review_gate", errorCodeStem: "REVIEW_GATE" }),
54
- },
55
39
  };
56
40
  /**
57
- * Convenience accessor for managed commands (review/challenge/rescue/
58
- * review_gate/ask). Identical to direct lookup, with a defensive
59
- * runtime guard: TypeScript narrows `commandType` to `ManagedCommandType`,
60
- * but a stale SQLite row, corrupted job artifact, or future command
61
- * type added without a registry entry could still reach here at
62
- * runtime. A bare `COMMAND_REGISTRY[commandType]` would return
63
- * `undefined` and surface as an unclassified `TypeError` at the
64
- * destructure call site. Throwing a classified `RuntimeError` here
65
- * keeps the failure path within the command-layer error model so
66
- * /kimi:status and /kimi:result render it correctly.
41
+ * Convenience accessor for managed commands (ask/review/challenge/rescue).
42
+ * Identical to direct lookup, with a defensive runtime guard: TypeScript
43
+ * narrows `commandType` to `ManagedCommandType`, but a stale SQLite row,
44
+ * corrupted job artifact, or future command type added without a registry
45
+ * entry could still reach here at runtime. Throwing a classified `RuntimeError`
46
+ * keeps the failure path within the command-layer error model so `job status`
47
+ * and `job result` render it correctly.
67
48
  */
68
49
  export function getManagedCommandConfig(commandType) {
69
50
  const config = COMMAND_REGISTRY[commandType];
@@ -8,6 +8,7 @@ import { resolveRepoIdentity } from "../git.js";
8
8
  import { digestPrompt } from "../jobs.js";
9
9
  import { resolvePluginPaths } from "../paths.js";
10
10
  import { syncKimiSessionTitle } from "../session-title.js";
11
+ import { stripSessionReferences } from "../session-references.js";
11
12
  import { askPromptSubject } from "./ask.js";
12
13
  import { buildGoalPrompt } from "./pursue.js";
13
14
  import { stripRescuePromptPrefix } from "./rescue.js";
@@ -185,7 +186,8 @@ const TASK_SLOT = "\u0000kimi-plugin-cc-task\u0000";
185
186
  /**
186
187
  * Recover the raw task text a live run previews from its verified submitted
187
188
  * prompt. Derivations are exact or absent: prompts from other plugin releases,
188
- * ambiguous parameter choices and unknown operations return undefined.
189
+ * ambiguous parameter choices and unknown operations return undefined. A
190
+ * trailing referenced-sessions block is not task text; pursue never carries one.
189
191
  */
190
192
  export function rawTaskTextFromSubmittedPrompt(operationKind, prompt) {
191
193
  switch (operationKind) {
@@ -201,17 +203,18 @@ export function rawTaskTextFromSubmittedPrompt(operationKind, prompt) {
201
203
  const build = operationKind === "swarm" ? buildSwarmPrompt : buildSwarmWritePrompt;
202
204
  const caps = [undefined, ...numbersAfter(prompt, /at most (\d+) subagents/g)];
203
205
  const waves = [undefined, 1, ...numbersAfter(prompt, /at most (\d+) entries/g)];
204
- return uniqueInversion(prompt, caps.flatMap((cap) => waves.map((wave) => (task) => build(task, cap, wave))));
206
+ return uniqueInversion(stripSessionReferences(prompt), caps.flatMap((cap) => waves.map((wave) => (task) => build(task, cap, wave))));
205
207
  }
206
208
  case "review":
207
209
  case "challenge":
208
- return reviewTaskText(prompt);
210
+ return reviewTaskText(stripSessionReferences(prompt));
209
211
  default:
210
212
  return undefined;
211
213
  }
212
214
  }
215
+ /** The plugin prefix must have been removed, not merely a referenced-sessions block. */
213
216
  function strippedOrUndefined(prompt, stripped) {
214
- return stripped !== prompt && stripped.trim() ? stripped : undefined;
217
+ return stripped !== stripSessionReferences(prompt) && stripped.trim() ? stripped : undefined;
215
218
  }
216
219
  function numbersAfter(prompt, pattern) {
217
220
  return [...new Set([...prompt.matchAll(pattern)].map((match) => Number(match[1])))];
@@ -40,12 +40,13 @@ export async function replayJob(job) {
40
40
  if (stats.size > MAX_REPLAY_LOG_BYTES) {
41
41
  throw new RuntimeError("REPLAY_LOG_TOO_LARGE", `Job ${job.job_id} stream log is ${stats.size} bytes, which exceeds the ${MAX_REPLAY_LOG_BYTES}-byte replay ceiling.`, "replay.lookup");
42
42
  }
43
- const finalText = await replayFinalText(job.stream_log_path);
44
- const rendered = renderManagedJobOutput(job, finalText);
43
+ const replayed = await replayFinalText(job.stream_log_path);
44
+ const rendered = renderManagedJobOutput(job, replayed.text);
45
45
  return {
46
46
  rendered: rendered.rendered,
47
47
  output: rendered.output,
48
48
  summary: rendered.summary,
49
+ partial: replayed.partial,
49
50
  };
50
51
  }
51
52
  async function replayFinalText(logPath) {
@@ -120,5 +121,5 @@ async function replayFinalText(logPath) {
120
121
  if (!sawExit && assistantContent.length === 0) {
121
122
  throw new RuntimeError("REPLAY_LOG_INVALID", `Stream log ${logPath} did not capture any assistant content before truncation.`, "replay.log", { details: { logPath } });
122
123
  }
123
- return assistantContent;
124
+ return { text: assistantContent, partial: !sawExit };
124
125
  }