kimi-plugin-cc 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +3 -14
  3. package/README.md +428 -572
  4. package/assets/logo.svg +6 -0
  5. package/cordis.patch.yml +18 -0
  6. package/dist/background-spawn.js +4 -2
  7. package/dist/cli-client.js +105 -66
  8. package/dist/commands/ask.js +27 -12
  9. package/dist/commands/cancel.js +4 -13
  10. package/dist/commands/cli-helpers.js +1 -1
  11. package/dist/commands/pursue.js +3 -2
  12. package/dist/commands/registry.js +7 -26
  13. package/dist/commands/repair-sessions.js +7 -4
  14. package/dist/commands/replay.js +4 -3
  15. package/dist/commands/rescue.js +17 -5
  16. package/dist/commands/review.js +18 -5
  17. package/dist/commands/setup.js +277 -262
  18. package/dist/commands/swarm.js +20 -7
  19. package/dist/companion.js +142 -18
  20. package/dist/help.js +11 -7
  21. package/dist/hook-escape.js +7 -16
  22. package/dist/hooks/approval-hook.js +1762 -124
  23. package/dist/hooks/approval-policy.js +15 -10
  24. package/dist/hooks/config-safety.js +15 -24
  25. package/dist/hooks/hook-timing.js +1 -1
  26. package/dist/hooks/install-paths.js +179 -107
  27. package/dist/hooks/install.js +44 -166
  28. package/dist/hooks/managed-block.js +44 -95
  29. package/dist/job-store.js +117 -49
  30. package/dist/jobs.js +53 -1
  31. package/dist/kimi-engine.js +68 -92
  32. package/dist/kimi-errors.js +1 -1
  33. package/dist/kimi-journal.js +3 -2
  34. package/dist/kimi-releases.js +28 -49
  35. package/dist/kimi-timeouts.js +1 -15
  36. package/dist/kimi-version-probe.js +24 -72
  37. package/dist/logging.js +12 -7
  38. package/dist/mcp/binding.js +13 -4
  39. package/dist/mcp/job-control.js +386 -89
  40. package/dist/mcp/launcher.js +1 -1
  41. package/dist/mcp/operations.js +387 -193
  42. package/dist/mcp/protocol.js +116 -27
  43. package/dist/mcp/skills.js +130 -0
  44. package/dist/mcp/stdio.js +15 -2
  45. package/dist/native-v2-preflight.js +127 -35
  46. package/dist/parsing.js +45 -11
  47. package/dist/paths.js +20 -10
  48. package/dist/plugin-data.js +28 -83
  49. package/dist/read-scope.js +2 -2
  50. package/dist/render.js +13 -38
  51. package/dist/session-references.js +216 -0
  52. package/dist/session-title.js +1 -1
  53. package/dist/surface-routing.js +92 -5
  54. package/dist/swarm-activation.js +26 -137
  55. package/dist/version.js +1 -1
  56. package/docs/migration.md +45 -227
  57. package/docs/models.md +24 -66
  58. package/docs/safety.md +195 -400
  59. package/docs/session-visibility.md +24 -14
  60. package/docs/swarm-recovery.md +26 -20
  61. package/dsh/index.json +54 -0
  62. package/mcp_config.json +10 -0
  63. package/package.json +23 -82
  64. package/plugin.json +19 -0
  65. package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
  66. package/plugins/kimi-codex/.mcp.json +2 -3
  67. package/plugins/kimi-codex/dist/background-spawn.js +4 -2
  68. package/plugins/kimi-codex/dist/cli-client.js +105 -66
  69. package/plugins/kimi-codex/dist/commands/ask.js +27 -12
  70. package/plugins/kimi-codex/dist/commands/cancel.js +4 -13
  71. package/plugins/kimi-codex/dist/commands/cli-helpers.js +1 -1
  72. package/plugins/kimi-codex/dist/commands/pursue.js +3 -2
  73. package/plugins/kimi-codex/dist/commands/registry.js +7 -26
  74. package/plugins/kimi-codex/dist/commands/repair-sessions.js +7 -4
  75. package/plugins/kimi-codex/dist/commands/replay.js +4 -3
  76. package/plugins/kimi-codex/dist/commands/rescue.js +17 -5
  77. package/plugins/kimi-codex/dist/commands/review.js +18 -5
  78. package/plugins/kimi-codex/dist/commands/setup.js +277 -262
  79. package/plugins/kimi-codex/dist/commands/swarm.js +20 -7
  80. package/plugins/kimi-codex/dist/companion.js +142 -18
  81. package/plugins/kimi-codex/dist/help.js +11 -7
  82. package/plugins/kimi-codex/dist/hook-escape.js +7 -16
  83. package/plugins/kimi-codex/dist/hooks/approval-hook.js +1762 -124
  84. package/plugins/kimi-codex/dist/hooks/approval-policy.js +15 -10
  85. package/plugins/kimi-codex/dist/hooks/config-safety.js +15 -24
  86. package/plugins/kimi-codex/dist/hooks/hook-timing.js +1 -1
  87. package/plugins/kimi-codex/dist/hooks/install-paths.js +179 -107
  88. package/plugins/kimi-codex/dist/hooks/install.js +44 -166
  89. package/plugins/kimi-codex/dist/hooks/managed-block.js +44 -95
  90. package/plugins/kimi-codex/dist/job-store.js +117 -49
  91. package/plugins/kimi-codex/dist/jobs.js +53 -1
  92. package/plugins/kimi-codex/dist/kimi-engine.js +68 -92
  93. package/plugins/kimi-codex/dist/kimi-errors.js +1 -1
  94. package/plugins/kimi-codex/dist/kimi-journal.js +3 -2
  95. package/plugins/kimi-codex/dist/kimi-releases.js +28 -49
  96. package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -15
  97. package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -72
  98. package/plugins/kimi-codex/dist/logging.js +12 -7
  99. package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
  100. package/plugins/kimi-codex/dist/mcp/job-control.js +386 -89
  101. package/plugins/kimi-codex/dist/mcp/launcher.js +1 -1
  102. package/plugins/kimi-codex/dist/mcp/operations.js +387 -193
  103. package/plugins/kimi-codex/dist/mcp/protocol.js +116 -27
  104. package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
  105. package/plugins/kimi-codex/dist/mcp/stdio.js +15 -2
  106. package/plugins/kimi-codex/dist/native-v2-preflight.js +127 -35
  107. package/plugins/kimi-codex/dist/parsing.js +45 -11
  108. package/plugins/kimi-codex/dist/paths.js +20 -10
  109. package/plugins/kimi-codex/dist/plugin-data.js +28 -83
  110. package/plugins/kimi-codex/dist/read-scope.js +2 -2
  111. package/plugins/kimi-codex/dist/render.js +13 -38
  112. package/plugins/kimi-codex/dist/session-references.js +216 -0
  113. package/plugins/kimi-codex/dist/session-title.js +1 -1
  114. package/plugins/kimi-codex/dist/surface-routing.js +92 -5
  115. package/plugins/kimi-codex/dist/swarm-activation.js +26 -137
  116. package/plugins/kimi-codex/dist/version.js +1 -1
  117. package/plugins/kimi-codex/scripts/companion.sh +4 -15
  118. package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
  119. package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
  120. package/scripts/companion.sh +4 -15
  121. package/skills/kimi/SKILL.md +77 -0
  122. package/skills/kimi/agents/openai.yaml +6 -0
  123. package/CHANGELOG.md +0 -1402
  124. package/agents/kimi-pursue.md +0 -93
  125. package/agents/kimi-review.md +0 -86
  126. package/agents/kimi-swarm.md +0 -88
  127. package/agents/kimi-task.md +0 -93
  128. package/commands/README.md +0 -14
  129. package/commands/cancel.md +0 -17
  130. package/commands/pursue.md +0 -41
  131. package/commands/replay.md +0 -13
  132. package/commands/result.md +0 -13
  133. package/commands/review.md +0 -40
  134. package/commands/setup.md +0 -25
  135. package/commands/status.md +0 -13
  136. package/commands/swarm.md +0 -45
  137. package/commands/task.md +0 -40
  138. package/dist/commands/review-gate.js +0 -391
  139. package/dist/config.js +0 -22
  140. package/dist/dsh/companion.js +0 -177
  141. package/dist/dsh/index.js +0 -167
  142. package/dist/hooks/review-gate-stop.js +0 -19
  143. package/dist/schemas/review-gate-output.js +0 -41
  144. package/docs/registry-releases.md +0 -228
  145. package/docs/upstream-2.4.1-certification.md +0 -54
  146. package/docs/upstream-2.5.0-certification.md +0 -52
  147. package/docs/upstream-2.5.1-certification.md +0 -47
  148. package/docs/upstream-2.5.2-certification.md +0 -40
  149. package/docs/upstream-2.5.3-certification.md +0 -73
  150. package/docs/upstream-2.6.0-certification.md +0 -65
  151. package/docs/upstream-2.6.2-certification.md +0 -144
  152. package/docs/upstream-2.6.3-certification.md +0 -100
  153. package/docs/upstream-2.7.2-certification.md +0 -113
  154. package/docs/upstream-2.7.3-certification.md +0 -95
  155. package/docs/windows-validation.md +0 -39
  156. package/hooks/README.md +0 -9
  157. package/hooks/hooks.json +0 -16
  158. package/plugins/kimi-codex/dist/commands/review-gate.js +0 -391
  159. package/plugins/kimi-codex/dist/config.js +0 -22
  160. package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
  161. package/plugins/kimi-codex/dist/dsh/index.js +0 -167
  162. package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
  163. package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -41
  164. package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
  165. package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
  166. package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
  167. package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
  168. package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
  169. package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
  170. package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
  171. package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
  172. package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
  173. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -35
  174. package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
  175. package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -35
  176. package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
  177. package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
  178. package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
  179. package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -37
  180. package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
  181. package/plugins/kimi-codex/skills/kimi-task/SKILL.md +0 -37
  182. package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +0 -6
  183. package/plugins/kimi-dsh/LICENSE +0 -201
  184. package/plugins/kimi-dsh/README.md +0 -84
  185. package/plugins/kimi-dsh/cordis.patch.yml +0 -45
  186. package/plugins/kimi-dsh/dist/background-spawn.js +0 -209
  187. package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
  188. package/plugins/kimi-dsh/dist/cli-client.js +0 -1097
  189. package/plugins/kimi-dsh/dist/commands/ask.js +0 -269
  190. package/plugins/kimi-dsh/dist/commands/cancel.js +0 -177
  191. package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -302
  192. package/plugins/kimi-dsh/dist/commands/models.js +0 -139
  193. package/plugins/kimi-dsh/dist/commands/pursue.js +0 -293
  194. package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
  195. package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
  196. package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -266
  197. package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
  198. package/plugins/kimi-dsh/dist/commands/rescue.js +0 -277
  199. package/plugins/kimi-dsh/dist/commands/result.js +0 -72
  200. package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -391
  201. package/plugins/kimi-dsh/dist/commands/review.js +0 -217
  202. package/plugins/kimi-dsh/dist/commands/setup.js +0 -1465
  203. package/plugins/kimi-dsh/dist/commands/status.js +0 -27
  204. package/plugins/kimi-dsh/dist/commands/swarm.js +0 -823
  205. package/plugins/kimi-dsh/dist/commands/worker.js +0 -24
  206. package/plugins/kimi-dsh/dist/companion.js +0 -99
  207. package/plugins/kimi-dsh/dist/config.js +0 -22
  208. package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
  209. package/plugins/kimi-dsh/dist/dsh/index.js +0 -167
  210. package/plugins/kimi-dsh/dist/errors.js +0 -40
  211. package/plugins/kimi-dsh/dist/git.js +0 -216
  212. package/plugins/kimi-dsh/dist/help.js +0 -43
  213. package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
  214. package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -145
  215. package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -295
  216. package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -641
  217. package/plugins/kimi-dsh/dist/hooks/hook-timing.js +0 -48
  218. package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
  219. package/plugins/kimi-dsh/dist/hooks/install.js +0 -405
  220. package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -729
  221. package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
  222. package/plugins/kimi-dsh/dist/job-id.js +0 -12
  223. package/plugins/kimi-dsh/dist/job-store.js +0 -631
  224. package/plugins/kimi-dsh/dist/jobs.js +0 -212
  225. package/plugins/kimi-dsh/dist/kimi-command.js +0 -144
  226. package/plugins/kimi-dsh/dist/kimi-engine.js +0 -770
  227. package/plugins/kimi-dsh/dist/kimi-errors.js +0 -205
  228. package/plugins/kimi-dsh/dist/kimi-home.js +0 -15
  229. package/plugins/kimi-dsh/dist/kimi-journal.js +0 -41
  230. package/plugins/kimi-dsh/dist/kimi-releases.js +0 -144
  231. package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
  232. package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -198
  233. package/plugins/kimi-dsh/dist/logging.js +0 -22
  234. package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
  235. package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -343
  236. package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -263
  237. package/plugins/kimi-dsh/dist/mcp/operations.js +0 -333
  238. package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -277
  239. package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
  240. package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -79
  241. package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
  242. package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
  243. package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
  244. package/plugins/kimi-dsh/dist/model-command.js +0 -34
  245. package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -596
  246. package/plugins/kimi-dsh/dist/package.json +0 -1
  247. package/plugins/kimi-dsh/dist/parsing.js +0 -554
  248. package/plugins/kimi-dsh/dist/paths.js +0 -35
  249. package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
  250. package/plugins/kimi-dsh/dist/process-tree.js +0 -597
  251. package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
  252. package/plugins/kimi-dsh/dist/read-scope.js +0 -435
  253. package/plugins/kimi-dsh/dist/render.js +0 -214
  254. package/plugins/kimi-dsh/dist/rescue-approval.js +0 -1242
  255. package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -41
  256. package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
  257. package/plugins/kimi-dsh/dist/session-title.js +0 -313
  258. package/plugins/kimi-dsh/dist/stream-json.js +0 -344
  259. package/plugins/kimi-dsh/dist/surface-routing.js +0 -21
  260. package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1194
  261. package/plugins/kimi-dsh/dist/swarm-policy.js +0 -74
  262. package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -166
  263. package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
  264. package/plugins/kimi-dsh/dist/types.js +0 -1
  265. package/plugins/kimi-dsh/dist/util.js +0 -28
  266. package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
  267. package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
  268. package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
  269. package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
  270. package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
  271. package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
  272. package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
  273. package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
  274. package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
  275. package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
  276. package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
  277. package/plugins/kimi-dsh/dist/version.js +0 -7
  278. package/plugins/kimi-dsh/package.json +0 -78
  279. package/plugins/kimi-dsh/scripts/companion.sh +0 -37
  280. package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
  281. package/scripts/review-gate-hook.sh +0 -32
@@ -1,596 +0,0 @@
1
- // Native-v2 pre-spawn safety preflight.
2
- //
3
- // Why this module exists:
4
- //
5
- // kimi-code 0.42.0 removed the legacy-v1 engine. agent-core-v2's ONLY
6
- // chain-breaking `event.allow()` is the plan-file guard
7
- // (features/plan/planService.ts:110), and it fires only while plan mode is
8
- // ACTIVE. Plan mode can arm in a plugin-spawned `kimi -p` session in exactly
9
- // three ways:
10
- // A. `default_plan_mode = true` in <KIMI_CODE_HOME>/config.toml, read ONCE
11
- // inside sessions.create() (single user file; no env, argv or project
12
- // overlay; invalid values fall back to false upstream);
13
- // B. the EnterPlanMode tool (already hook-denied for every label);
14
- // C. resuming a session whose agent wire journal holds a durable
15
- // `plan_mode.enter` record (restore() folds ONLY agents/*/wire.jsonl).
16
- // This module closes A and C before any process is spawned and requires
17
- // local execution for configured and resumed sessions. The v2-only
18
- // experimental features (tower, subagent fork) are forced off for every
19
- // child by per-flag env in cli-client.ts; only an uncertified release, whose
20
- // flag names are unreviewed, still refuses an enabled selector here.
21
- // B stays in runtime/hooks/approval-policy.ts.
22
- //
23
- // Contract:
24
- // - Pure inspection: never writes, never rewrites operator config, never
25
- // clears saved plan state. Refusals name the setting, never dump config.
26
- // - Fail-closed: unparseable/unreadable/oversized inputs refuse.
27
- // - Strictly more conservative than upstream (a non-boolean value that
28
- // upstream would ignore still refuses here).
29
- // - Refusals here are NOT /kimi:setup-recoverable and must never be
30
- // described as hook drift.
31
- import { constants as fsConstants } from "node:fs";
32
- import { open, readdir } from "node:fs/promises";
33
- import path from "node:path";
34
- import { RuntimeError } from "./errors.js";
35
- import { kimiCodeConfigPath } from "./kimi-home.js";
36
- import { kimiJournalRecords, UNPARSEABLE_JOURNAL_LINE } from "./kimi-journal.js";
37
- import { kimiCertifiedReleaseHas } from "./kimi-releases.js";
38
- import { tomlErrorLocation } from "./util.js";
39
- import { parse as parseToml } from "./vendor/smol-toml/parse.js";
40
- /** `<kimiHome>/config.toml` is small hand-edited config, never a data file. */
41
- const CONFIG_MAX_BYTES = 1 * 1024 * 1024;
42
- /** A single agent's wire journal; generous but bounded so a runaway session
43
- * log can't turn a preflight check into an unbounded read. */
44
- const JOURNAL_MAX_BYTES = 64 * 1024 * 1024;
45
- /** Bounded directory enumeration so a pathological sessions/ tree refuses
46
- * instead of scanning forever. */
47
- const DIR_ENUM_CAP = 4096;
48
- const TRUTHY_STRINGS = new Set(["1", "true", "yes", "on"]);
49
- function isTruthySelectorValue(value) {
50
- if (value === true)
51
- return true;
52
- if (typeof value === "string")
53
- return TRUTHY_STRINGS.has(value.trim().toLowerCase());
54
- return false;
55
- }
56
- /**
57
- * Read a small file with the same no-follow, size-capped posture as the
58
- * config lock reader in runtime/hooks/config-safety.ts. Never partial-reads:
59
- * an oversized file refuses rather than being silently truncated.
60
- */
61
- async function readSmallFileSafe(filePath, maxBytes) {
62
- let handle;
63
- try {
64
- handle = await open(filePath, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0) | (fsConstants.O_NONBLOCK ?? 0));
65
- }
66
- catch (error) {
67
- const code = error.code;
68
- if (code === "ENOENT")
69
- return { kind: "absent" };
70
- if (code === "ELOOP")
71
- return { kind: "unreadable", reason: "path is a symbolic link" };
72
- return { kind: "unreadable", reason: error.message };
73
- }
74
- try {
75
- const stats = await handle.stat({ bigint: true });
76
- if (!stats.isFile())
77
- return { kind: "unreadable", reason: "not a regular file" };
78
- if (stats.size > BigInt(maxBytes)) {
79
- return { kind: "unreadable", reason: `exceeds ${maxBytes} byte cap` };
80
- }
81
- const size = Number(stats.size);
82
- const buffer = Buffer.alloc(size);
83
- let offset = 0;
84
- while (offset < size) {
85
- const { bytesRead } = await handle.read(buffer, offset, size - offset, offset);
86
- if (bytesRead === 0)
87
- break;
88
- offset += bytesRead;
89
- }
90
- return { kind: "ok", contents: buffer.subarray(0, offset).toString("utf8") };
91
- }
92
- finally {
93
- await handle.close().catch(() => undefined);
94
- }
95
- }
96
- /** Read+parse `<kimiHome>/config.toml`. `config: null` means the file is
97
- * absent (upstream default applies); any read/parse failure fails closed. */
98
- async function readParsedConfig(kimiHome) {
99
- const configPath = kimiCodeConfigPath(kimiHome);
100
- const read = await readSmallFileSafe(configPath, CONFIG_MAX_BYTES);
101
- if (read.kind === "absent")
102
- return { kind: "ok", config: null };
103
- if (read.kind === "unreadable") {
104
- return { kind: "unreadable", reason: `${configPath} could not be read safely: ${read.reason}` };
105
- }
106
- try {
107
- return { kind: "ok", config: parseToml(read.contents) };
108
- }
109
- catch (error) {
110
- return {
111
- kind: "unreadable",
112
- reason: `${configPath} could not be parsed as TOML: ${tomlErrorLocation(error)}`,
113
- };
114
- }
115
- }
116
- /**
117
- * Upstream's EXACT top-level key normalization
118
- * (`packages/agent-core-v2/src/app/config/toml.ts::snakeToCamel`, applied to
119
- * every top-level key by `transformTomlData` before the config registry sees
120
- * it). The plan section is registered under the camelCase domain
121
- * `defaultPlanMode`, so the operator can spell it `default_plan_mode`,
122
- * `defaultPlanMode`, `default_planMode`, … and upstream reads the same
123
- * setting. The plugin MUST inspect the same normalized view — a literal
124
- * `default_plan_mode` check lets `defaultPlanMode = true` arm plan mode.
125
- * Pinned by tests/audit/v2-tag-scan.test.ts (toml.ts hash + regex text).
126
- * NOTE: the `[experimental]` section registers its own `fromToml` that keeps
127
- * raw keys, and its flag ids are snake_case (`subagent_fork`), so that table
128
- * is deliberately NOT normalized here.
129
- */
130
- export function upstreamSnakeToCamel(key) {
131
- return key.replace(/_([a-z])/g, (_match, ch) => ch.toUpperCase());
132
- }
133
- const DEFAULT_PLAN_MODE_DOMAIN = "defaultPlanMode";
134
- /**
135
- * Inspect `<kimiHome>/config.toml` for the upstream default-plan-mode setting
136
- * under EVERY spelling upstream normalizes to the `defaultPlanMode` domain.
137
- * ENOENT → ok:"absent" (upstream default is false; the missing hook is caught
138
- * separately). Any other read error, a symlinked file (open with O_NOFOLLOW),
139
- * an oversized file, or a TOML parse failure → refuse "v2-config-unreadable".
140
- * Every matching key holding literal boolean `false` → ok:"false". ANY matching
141
- * key with any other value (true, string, number, table, array) → refuse
142
- * "v2-plan-mode-configured", naming the raw key(s) found.
143
- */
144
- export async function inspectPlanModeConfig(kimiHome) {
145
- const parsed = await readParsedConfig(kimiHome);
146
- if (parsed.kind === "unreadable") {
147
- return { kind: "refuse", refusalKind: "v2-config-unreadable", reason: parsed.reason };
148
- }
149
- if (parsed.config === null)
150
- return { kind: "ok", setting: "absent" };
151
- const matching = Object.entries(parsed.config).filter(([rawKey]) => upstreamSnakeToCamel(rawKey) === DEFAULT_PLAN_MODE_DOMAIN);
152
- if (matching.length === 0)
153
- return { kind: "ok", setting: "absent" };
154
- const offending = matching.filter(([, value]) => value !== false).map(([rawKey]) => rawKey);
155
- if (offending.length === 0)
156
- return { kind: "ok", setting: "false" };
157
- const configPath = kimiCodeConfigPath(kimiHome);
158
- return {
159
- kind: "refuse",
160
- refusalKind: "v2-plan-mode-configured",
161
- reason: `\`${offending.join("`, `")}\` (upstream setting \`default_plan_mode\`) is set in ${configPath} and is not \`false\`.`,
162
- };
163
- }
164
- /**
165
- * `allowDefaultEnvironment`: upstream reads `environments.default` only in
166
- * sessionManagerService.openCreation, i.e. when a session is created. A fresh
167
- * print on a certified row passes `--environment local`, which skips the
168
- * declarations; a resume goes through doResume, which applies the session's
169
- * stored binding (state.json) and never consults the default (2.5.0-2.7.3).
170
- * The stored binding is checked separately by scanSessionJournalsForPlan, so
171
- * that one key stops refusing. A non-table section still refuses.
172
- */
173
- export async function inspectEnvironmentConfig(kimiHome, options = {}) {
174
- const parsed = await readParsedConfig(kimiHome);
175
- if (parsed.kind === "unreadable") {
176
- return { kind: "refuse", refusalKind: "v2-config-unreadable", reason: parsed.reason };
177
- }
178
- const section = parsed.config?.["environments"];
179
- if (section !== undefined) {
180
- if (section === null || typeof section !== "object" || Array.isArray(section)) {
181
- return {
182
- kind: "refuse",
183
- refusalKind: "v2-environment-configured",
184
- reason: "The [environments] section is not a table, so the execution environment cannot be verified as local.",
185
- };
186
- }
187
- if (options.allowDefaultEnvironment !== true && section["default"] !== undefined) {
188
- return {
189
- kind: "refuse",
190
- refusalKind: "v2-environment-configured",
191
- reason: "A default remote execution environment is configured in [environments]; plugin-managed jobs require the local environment.",
192
- };
193
- }
194
- }
195
- const workspace = parsed.config?.["workspace"];
196
- if (workspace !== undefined) {
197
- if (workspace === null || typeof workspace !== "object" || Array.isArray(workspace)) {
198
- return {
199
- kind: "refuse",
200
- refusalKind: "v2-workspace-trust-disabled",
201
- reason: "The [workspace] section is not a table, so project trust requirements cannot be verified.",
202
- };
203
- }
204
- const trustValues = Object.entries(workspace)
205
- .filter(([key]) => upstreamSnakeToCamel(key) === "requireTrust")
206
- .map(([, value]) => value);
207
- // Literal false is the user's own choice and becomes a warning; any other
208
- // non-true value is malformed and still refuses.
209
- if (trustValues.some((value) => value !== true && value !== false)) {
210
- return {
211
- kind: "refuse",
212
- refusalKind: "v2-workspace-trust-disabled",
213
- reason: "[workspace] require_trust is not a boolean, so project trust requirements cannot be verified.",
214
- };
215
- }
216
- if (trustValues.includes(false))
217
- return { kind: "ok", trustDisabled: true };
218
- }
219
- return { kind: "ok" };
220
- }
221
- export const WORKSPACE_TRUST_DISABLED_WARNING = "Workspace trust is disabled in kimi-code's config: MCP servers configured by this repository can start outside the plugin's hook.";
222
- /**
223
- * Refuse v2-only experimental features this plugin does not certify.
224
- * Sources (per-flag precedence upstream is env → [experimental] config →
225
- * master flag → default): the `[experimental]` table keys `tower` and
226
- * `subagent_fork` in `<kimiHome>/config.toml`, and the per-flag env vars
227
- * `KIMI_CODE_EXPERIMENTAL_TOWER` / `KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK`.
228
- * Truthy = boolean true, or a string in {"1","true","yes","on"} (trimmed,
229
- * case-insensitive). The master `KIMI_CODE_EXPERIMENTAL_FLAG` is handled by
230
- * kimi-engine.ts::assertNoUnsafeExperimentalSelector, not here.
231
- * Config read errors follow inspectPlanModeConfig's fail-closed rules.
232
- */
233
- export async function inspectExperimentalSelectors(kimiHome, env) {
234
- const parsed = await readParsedConfig(kimiHome);
235
- if (parsed.kind === "unreadable") {
236
- return { kind: "refuse", selectors: [], reason: parsed.reason };
237
- }
238
- const selectors = [];
239
- const experimental = parsed.config?.["experimental"];
240
- if (experimental !== null && typeof experimental === "object" && !Array.isArray(experimental)) {
241
- const table = experimental;
242
- if (isTruthySelectorValue(table["tower"]))
243
- selectors.push("config:[experimental].tower");
244
- if (isTruthySelectorValue(table["subagent_fork"])) {
245
- selectors.push("config:[experimental].subagent_fork");
246
- }
247
- }
248
- if (isTruthySelectorValue(env.KIMI_CODE_EXPERIMENTAL_TOWER)) {
249
- selectors.push("env:KIMI_CODE_EXPERIMENTAL_TOWER");
250
- }
251
- if (isTruthySelectorValue(env.KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK)) {
252
- selectors.push("env:KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK");
253
- }
254
- if (selectors.length === 0)
255
- return { kind: "ok" };
256
- return {
257
- kind: "refuse",
258
- selectors,
259
- reason: `Refusing v2-only experimental feature(s) not certified by kimi-plugin-cc: ${selectors.join(", ")}.`,
260
- };
261
- }
262
- async function boundedReaddir(dirPath, cap) {
263
- let entries;
264
- try {
265
- entries = await readdir(dirPath, { withFileTypes: true });
266
- }
267
- catch (error) {
268
- const code = error.code;
269
- if (code === "ENOENT" || code === "ENOTDIR")
270
- return { kind: "absent" };
271
- // Any other enumeration failure (EACCES, EIO, ELOOP, …) must land in the
272
- // classified `unavailable` refusal, not escape as an untyped fs error.
273
- return { kind: "unreadable", reason: `${dirPath}: ${error.message}` };
274
- }
275
- if (entries.length > cap)
276
- return { kind: "cap-exceeded" };
277
- return { kind: "ok", entries };
278
- }
279
- async function openJournalSafely(journalPath, maxBytes) {
280
- let handle;
281
- try {
282
- // O_NONBLOCK so a FIFO planted at the journal path (no writer) does not
283
- // block the open() indefinitely — the regular-file check below then
284
- // refuses it. O_NOFOLLOW refuses a symlinked final component.
285
- handle = await open(journalPath, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0) | (fsConstants.O_NONBLOCK ?? 0));
286
- }
287
- catch (error) {
288
- const code = error.code;
289
- if (code === "ENOENT")
290
- return { kind: "unavailable", reason: "journal not found" };
291
- if (code === "ELOOP")
292
- return { kind: "unavailable", reason: "journal path is a symbolic link" };
293
- return { kind: "unavailable", reason: error.message };
294
- }
295
- const stats = await handle.stat({ bigint: true });
296
- if (!stats.isFile()) {
297
- await handle.close().catch(() => undefined);
298
- return { kind: "unavailable", reason: "journal is not a regular file" };
299
- }
300
- if (stats.size > BigInt(maxBytes)) {
301
- await handle.close().catch(() => undefined);
302
- return { kind: "unavailable", reason: `journal exceeds ${maxBytes} byte cap` };
303
- }
304
- return { kind: "ok", handle };
305
- }
306
- /** Records that mean the session already did work: a turn, prompt, tool, model or delegated task. */
307
- const ACTIVITY_RECORD = /^(turn\.|prompt\.|tool\.|llm\.|shell\.|subagent\.|task\.|assistant\.|context\.append_message$|context\.append_loop_event$)/;
308
- /** Records that make replay non-linear (branch switch or undo), so a fold could differ. */
309
- const REWIND_RECORD = /^(agent\.switched$|context\.undo$|context\.undone$)/;
310
- async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelledDefaultEnter = false) {
311
- // G2: a print-created session's main journal holds the create-time
312
- // `default_plan_mode` enter immediately followed by print's id-less cancel,
313
- // before any work. On a linear journal that pair folds to inactive, so it
314
- // alone is tolerated; every other plan record, or that pair anywhere else,
315
- // still taints.
316
- // Replay stops at the first corrupt line, so records after it may add
317
- // taints (seeing more is conservative) but never start or complete a fold.
318
- let sawActivity = false;
319
- let sawRewind = false;
320
- let sawCorrupt = false;
321
- let pendingEnter = null;
322
- let toleratedPair = false;
323
- const taintEnter = { kind: "tainted", recordType: "plan_mode.enter" };
324
- for await (const framed of kimiJournalRecords(handle.createReadStream())) {
325
- const { line, parsed } = framed;
326
- if (parsed === UNPARSEABLE_JOURNAL_LINE) {
327
- if (framed.terminated)
328
- sawCorrupt = true;
329
- if (pendingEnter !== null)
330
- return taintEnter;
331
- if (line.includes('"plan_mode.') || line.includes('"plan.')) {
332
- return { kind: "tainted", recordType: "<unparseable>" };
333
- }
334
- if (line.includes('"environment.set_binding')) {
335
- return { kind: "environment", recordType: "<unparseable-environment-binding>" };
336
- }
337
- continue;
338
- }
339
- const record = parsed;
340
- const type = record?.["type"];
341
- if (pendingEnter !== null) {
342
- const cancelId = record?.["id"];
343
- const cancels = type === "plan_mode.cancel" && record?.["agentId"] === "main" &&
344
- (cancelId === undefined || cancelId === pendingEnter.id);
345
- if (!cancels)
346
- return taintEnter;
347
- pendingEnter = null;
348
- toleratedPair = true;
349
- continue;
350
- }
351
- if (typeof type === "string" && REWIND_RECORD.test(type)) {
352
- if (toleratedPair)
353
- return taintEnter;
354
- sawRewind = true;
355
- }
356
- if (typeof type === "string" && ACTIVITY_RECORD.test(type))
357
- sawActivity = true;
358
- if (typeof type === "string" && (type.startsWith("plan_mode.") || type.startsWith("plan."))) {
359
- if (tolerateCancelledDefaultEnter && type === "plan_mode.enter" && !toleratedPair &&
360
- !sawActivity && !sawRewind && !sawCorrupt && record?.["agentId"] === "main" && typeof record?.["id"] === "string") {
361
- pendingEnter = { id: record["id"] };
362
- continue;
363
- }
364
- return { kind: "tainted", recordType: type };
365
- }
366
- if (type === "environment.set_binding") {
367
- if (record?.["environmentId"] !== "local") {
368
- return { kind: "environment", recordType: type };
369
- }
370
- const cwd = record?.["cwd"];
371
- if (expectedExecutionRoot !== undefined && cwd !== undefined && cwd !== expectedExecutionRoot) {
372
- return { kind: "environment", recordType: "environment.set_binding.cwd" };
373
- }
374
- }
375
- }
376
- // An enter as the last record was never cancelled.
377
- if (pendingEnter !== null)
378
- return taintEnter;
379
- return null;
380
- }
381
- async function inspectSessionMetadataEnvironment(statePath, expectedExecutionRoot) {
382
- const read = await readSmallFileSafe(statePath, CONFIG_MAX_BYTES);
383
- if (read.kind === "absent")
384
- return null;
385
- if (read.kind === "unreadable") {
386
- return { kind: "unavailable", reason: `${statePath}: ${read.reason}` };
387
- }
388
- let metadata;
389
- try {
390
- metadata = JSON.parse(read.contents);
391
- }
392
- catch {
393
- return { kind: "unavailable", reason: `${statePath}: malformed session metadata` };
394
- }
395
- if (metadata === null || typeof metadata !== "object" || Array.isArray(metadata)) {
396
- return { kind: "unavailable", reason: `${statePath}: invalid session metadata` };
397
- }
398
- const record = metadata;
399
- const environmentId = record["environmentId"];
400
- if (environmentId !== undefined && environmentId !== "local") {
401
- return { kind: "environment", journal: statePath, recordType: "session.metadata.environmentId" };
402
- }
403
- const environmentCwd = record["environmentCwd"];
404
- if ((environmentId === undefined || environmentId === "local") &&
405
- expectedExecutionRoot !== undefined &&
406
- environmentCwd !== undefined &&
407
- environmentCwd !== expectedExecutionRoot) {
408
- return { kind: "environment", journal: statePath, recordType: "session.metadata.environmentCwd" };
409
- }
410
- return null;
411
- }
412
- /**
413
- * Scan saved session metadata and every agent wire journal for plan-mode records
414
- * and nonlocal environment bindings. Layout at 0.42.0:
415
- * `<kimiHome>/sessions/<workspaceId>/<sessionId>/agents/<agentId>/wire.jsonl`
416
- * (workspaceId is unknown to the plugin → enumerate `sessions/*` with bounded
417
- * readdir). Raw-line scan of EVERY agent journal: a JSON line whose `type`
418
- * starts with `plan_mode.` or `plan.` → tainted; `environment.set_binding` must
419
- * name `environmentId:"local"`. No session dir, no journal, unreadable metadata,
420
- * or any single journal above the size cap → unavailable. Never modifies files.
421
- */
422
- export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedExecutionRoot, options = {}) {
423
- const sessionsDir = path.join(kimiHome, "sessions");
424
- const workspaceEntries = await boundedReaddir(sessionsDir, DIR_ENUM_CAP);
425
- if (workspaceEntries.kind === "absent") {
426
- return { kind: "unavailable", reason: `no sessions directory at ${sessionsDir}` };
427
- }
428
- if (workspaceEntries.kind === "cap-exceeded") {
429
- return { kind: "unavailable", reason: `too many entries under ${sessionsDir} to scan safely` };
430
- }
431
- if (workspaceEntries.kind === "unreadable") {
432
- return { kind: "unavailable", reason: `could not enumerate the session tree: ${workspaceEntries.reason}` };
433
- }
434
- const journalPaths = [];
435
- for (const workspaceEntry of workspaceEntries.entries) {
436
- // A symlinked entry in the session tree is refused, not skipped: a
437
- // symlinked agent (or workspace) directory has isDirectory() === false, so
438
- // skipping it would drop its journal from the scan and let an active-plan
439
- // journal hide behind the symlink while a sibling reads clean. Fail closed.
440
- if (workspaceEntry.isSymbolicLink()) {
441
- return {
442
- kind: "unavailable",
443
- reason: `symlinked entry in the session tree: ${path.join(sessionsDir, workspaceEntry.name)}`,
444
- };
445
- }
446
- if (!workspaceEntry.isDirectory())
447
- continue;
448
- const sessionDir = path.join(sessionsDir, workspaceEntry.name, sessionId);
449
- const metadataFinding = await inspectSessionMetadataEnvironment(path.join(sessionDir, "state.json"), expectedExecutionRoot);
450
- if (metadataFinding !== null)
451
- return metadataFinding;
452
- const agentsDir = path.join(sessionDir, "agents");
453
- const agentEntries = await boundedReaddir(agentsDir, DIR_ENUM_CAP);
454
- if (agentEntries.kind === "absent")
455
- continue;
456
- if (agentEntries.kind === "cap-exceeded") {
457
- return { kind: "unavailable", reason: `too many agent entries under ${agentsDir} to scan safely` };
458
- }
459
- if (agentEntries.kind === "unreadable") {
460
- return { kind: "unavailable", reason: `could not enumerate agent journals: ${agentEntries.reason}` };
461
- }
462
- for (const agentEntry of agentEntries.entries) {
463
- if (agentEntry.isSymbolicLink()) {
464
- return {
465
- kind: "unavailable",
466
- reason: `symlinked agent entry in the session tree: ${path.join(agentsDir, agentEntry.name)}`,
467
- };
468
- }
469
- if (!agentEntry.isDirectory())
470
- continue;
471
- journalPaths.push({ path: path.join(agentsDir, agentEntry.name, "wire.jsonl"), main: agentEntry.name === "main" });
472
- }
473
- }
474
- if (journalPaths.length === 0) {
475
- return { kind: "unavailable", reason: `no agent wire journals found for session ${sessionId}` };
476
- }
477
- for (const { path: journalPath, main } of journalPaths) {
478
- const opened = await openJournalSafely(journalPath, JOURNAL_MAX_BYTES);
479
- if (opened.kind === "unavailable") {
480
- return { kind: "unavailable", reason: `${journalPath}: ${opened.reason}` };
481
- }
482
- try {
483
- const finding = await scanJournalLines(opened.handle, expectedExecutionRoot, main && options.tolerateCancelledDefaultEnter === true);
484
- if (finding?.kind === "tainted") {
485
- return { kind: "tainted", journal: journalPath, recordType: finding.recordType };
486
- }
487
- if (finding?.kind === "environment") {
488
- return { kind: "environment", journal: journalPath, recordType: finding.recordType };
489
- }
490
- }
491
- finally {
492
- await opened.handle.close().catch(() => undefined);
493
- }
494
- }
495
- return { kind: "clean", journals: journalPaths.map((journal) => journal.path) };
496
- }
497
- /** A non-swarm launch of an exactly certified row that has the capability. */
498
- function certifiedPrintLaunchHas(options, capability) {
499
- const release = options.release;
500
- return release !== undefined &&
501
- release.certification === "certified" &&
502
- release.operationKind !== "swarm" &&
503
- release.operationKind !== "swarm-write" &&
504
- kimiCertifiedReleaseHas(release.kimiVersion, capability);
505
- }
506
- export async function assertNativeV2Preflight(options) {
507
- const warnings = [];
508
- const stage = options.stage ?? "native-v2.preflight";
509
- const configPath = kimiCodeConfigPath(options.kimiHome);
510
- // On a print-cancels-plan row the setting is read only inside
511
- // sessionLifecycleService.create(): a fresh print cancels that enter before
512
- // any turn (run-v2-print.ts), and `-r` on an existing session goes through
513
- // doResume, which never consults it (a missing id fails, never creates).
514
- // So the setting no longer refuses there; for a resume the journal scan
515
- // below remains the gate. An unreadable config still refuses.
516
- const planMode = await inspectPlanModeConfig(options.kimiHome);
517
- const printCancelsPlan = planMode.kind === "refuse" &&
518
- planMode.refusalKind === "v2-plan-mode-configured" &&
519
- certifiedPrintLaunchHas(options, "print-cancels-plan");
520
- if (planMode.kind === "refuse" && !printCancelsPlan) {
521
- const code = planMode.refusalKind === "v2-plan-mode-configured"
522
- ? "CLI_V2_PLAN_MODE_CONFIGURED"
523
- : "CLI_V2_CONFIG_UNREADABLE";
524
- const remedy = planMode.refusalKind === "v2-plan-mode-configured"
525
- ? `Set \`default_plan_mode = false\` (or remove it) in ${configPath}.`
526
- : `Fix or remove the unreadable file at ${configPath} so plan mode can be verified off.`;
527
- throw new RuntimeError(code, `${planMode.reason} ${remedy}`, stage, {
528
- details: { refusal_kind: planMode.refusalKind, retryable_after_setup: false },
529
- });
530
- }
531
- const environment = await inspectEnvironmentConfig(options.kimiHome, {
532
- allowDefaultEnvironment: certifiedPrintLaunchHas(options, "local-environment"),
533
- });
534
- if (environment.kind === "refuse") {
535
- const code = environment.refusalKind === "v2-environment-configured"
536
- ? "CLI_V2_ENVIRONMENT_UNSAFE"
537
- : environment.refusalKind === "v2-workspace-trust-disabled"
538
- ? "CLI_V2_WORKSPACE_TRUST_UNSAFE"
539
- : "CLI_V2_CONFIG_UNREADABLE";
540
- const remedy = environment.refusalKind === "v2-environment-configured"
541
- ? `Remove \`environments.default\` in ${configPath} so plugin-managed sessions stay local.`
542
- : environment.refusalKind === "v2-workspace-trust-disabled"
543
- ? `Set \`workspace.require_trust = true\` (or remove it) in ${configPath}.`
544
- : `Fix or remove the unreadable file at ${configPath} so the execution environment can be verified as local.`;
545
- throw new RuntimeError(code, `${environment.reason} ${remedy}`, stage, {
546
- details: { refusal_kind: environment.refusalKind, retryable_after_setup: false },
547
- });
548
- }
549
- if (environment.trustDisabled === true)
550
- warnings.push(WORKSPACE_TRUST_DISABLED_WARNING);
551
- // Certified and test-bypass children run with tower and subagent fork forced
552
- // off by per-flag env, which outranks config and the master flag on every
553
- // reviewed release. An uncertified release's flag names are unreviewed.
554
- const experimental = options.release === undefined || options.release.certification === "uncertified"
555
- ? await inspectExperimentalSelectors(options.kimiHome, options.env)
556
- : { kind: "ok" };
557
- if (experimental.kind === "refuse") {
558
- throw new RuntimeError("CLI_V2_EXPERIMENTAL_UNSAFE", `${experimental.reason} Unset the listed selector(s) before retrying.`, stage, {
559
- details: {
560
- refusal_kind: "v2-experimental-unsafe",
561
- selectors: experimental.selectors,
562
- retryable_after_setup: false,
563
- },
564
- });
565
- }
566
- if (options.resumeSessionId !== undefined) {
567
- const journalScan = await scanSessionJournalsForPlan(options.kimiHome, options.resumeSessionId, options.expectedExecutionRoot, { tolerateCancelledDefaultEnter: certifiedPrintLaunchHas(options, "print-cancels-plan") });
568
- if (journalScan.kind === "environment") {
569
- throw new RuntimeError("KIMI_SESSION_ENVIRONMENT_UNSAFE", `Saved session ${options.resumeSessionId} has an unsafe execution environment binding (${journalScan.recordType} in ${journalScan.journal}). Start a fresh local session; saved session state was not modified.`, stage, {
570
- details: {
571
- refusal_kind: "session-environment-unsafe",
572
- record_type: journalScan.recordType,
573
- retryable_after_setup: false,
574
- },
575
- });
576
- }
577
- if (journalScan.kind === "tainted") {
578
- throw new RuntimeError("KIMI_SESSION_PLAN_TAINTED", `Saved session ${options.resumeSessionId} previously entered plan mode (record type "${journalScan.recordType}" in ${journalScan.journal}). Start a fresh session; saved session state was not modified.`, stage, {
579
- details: {
580
- refusal_kind: "session-plan-tainted",
581
- record_type: journalScan.recordType,
582
- retryable_after_setup: false,
583
- },
584
- });
585
- }
586
- if (journalScan.kind === "unavailable") {
587
- throw new RuntimeError("KIMI_SESSION_JOURNAL_UNAVAILABLE", `Could not verify saved session ${options.resumeSessionId} is free of plan-mode state (${journalScan.reason}). Start a fresh session; saved session state was not modified.`, stage, {
588
- details: {
589
- refusal_kind: "session-journal-unavailable",
590
- retryable_after_setup: false,
591
- },
592
- });
593
- }
594
- }
595
- return { warnings };
596
- }
@@ -1 +0,0 @@
1
- {"type":"module"}