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,554 +0,0 @@
1
- import { RuntimeError } from "./errors.js";
2
- import { SCOPE_FLAGS_WRITE_MESSAGE } from "./read-scope.js";
3
- /**
4
- * Unknown flag-shaped tokens hard-fail instead of being absorbed into prose.
5
- * Parsing still switches to prose at the first non-flag token or after `--`.
6
- */
7
- function looksLikeFlag(token) {
8
- if (!token.startsWith("-")) {
9
- return false;
10
- }
11
- if (token.startsWith("--") && token.length > 2) {
12
- return true;
13
- }
14
- // Short flag: a single dash followed by exactly one letter (`-r`, `-m`).
15
- return /^-[a-zA-Z]$/.test(token);
16
- }
17
- const SCOPE_SUPPORTED_FLAGS = "--read-root <absolute-dir> (repeatable), --network";
18
- export const RESCUE_SUPPORTED_FLAGS = "-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --background, --wait, --fresh, -r, --resume <job-id|session-id>";
19
- export const ASK_SUPPORTED_FLAGS = `${RESCUE_SUPPORTED_FLAGS}, ${SCOPE_SUPPORTED_FLAGS}`;
20
- export const REVIEW_SUPPORTED_FLAGS = `--base <ref>, -m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, ${SCOPE_SUPPORTED_FLAGS}`;
21
- export const JOB_LOOKUP_SUPPORTED_FLAGS = "--type <review|challenge|rescue|review_gate|ask>, --json";
22
- export const SETUP_SUPPORTED_FLAGS = "--check, --uninstall, --all (with --uninstall), --enable-review-gate, --disable-review-gate, --models [--json] (without other setup flags), --install-kimi [--json] (without other setup flags)";
23
- export const RECOVER_SWARM_SUPPORTED_FLAGS = "--apply";
24
- export const REPAIR_SESSIONS_SUPPORTED_FLAGS = "--apply, --all";
25
- export const REPLAY_SUPPORTED_FLAGS = "none (one job-id required)";
26
- /** Validate syntax only; upstream per-model supportEfforts remains authoritative. */
27
- export function validateThinkingEffort(value, stage = "args.parse", lowercase = true) {
28
- const effort = lowercase ? value?.toLowerCase() : value;
29
- if (!effort || !/^[a-z][a-z0-9-]{0,31}$/.test(effort)) {
30
- throw new RuntimeError("INVALID_ARGS", "--thinking requires an effort matching [a-z][a-z0-9-]{0,31} (e.g. off, low, medium, high).", stage);
31
- }
32
- return effort;
33
- }
34
- export const PURSUE_SUPPORTED_FLAGS = "-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --turns <N>";
35
- export const SWARM_SUPPORTED_FLAGS = `-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --cap <N>, --max-concurrency <N>, --write, ${SCOPE_SUPPORTED_FLAGS} (read-only swarm only)`;
36
- /**
37
- * Parser for /kimi:swarm. Foreground-only: no --background/--fresh/--resume.
38
- * Trailing tokens are the objective.
39
- */
40
- export function parseSwarmArgs(argv) {
41
- let model;
42
- let thinkingEffort;
43
- let budgetMs;
44
- let cap;
45
- let maxConcurrency;
46
- let write = false;
47
- const readRoots = [];
48
- let network = false;
49
- let trailingTokens;
50
- for (let index = 0; index < argv.length; index += 1) {
51
- const token = argv[index];
52
- const thinking = readThinkingFlag(argv, index);
53
- if (thinking) {
54
- [thinkingEffort, index] = thinking;
55
- continue;
56
- }
57
- if (token === "--") {
58
- trailingTokens = argv.slice(index + 1);
59
- break;
60
- }
61
- if (!token.startsWith("-")) {
62
- trailingTokens = argv.slice(index);
63
- break;
64
- }
65
- switch (token) {
66
- case "-m":
67
- case "--model":
68
- model = readModel(token, argv[++index], "swarm.parse");
69
- break;
70
- case "--write":
71
- write = true;
72
- break;
73
- case "--read-root":
74
- readRoots.push(readRootValue(argv[++index], "swarm.parse"));
75
- break;
76
- case "--network":
77
- network = true;
78
- break;
79
- case "--budget":
80
- budgetMs = readBudget(argv[++index], "swarm.parse", "safety");
81
- break;
82
- case "--cap":
83
- cap = parsePositiveIntFlag("--cap", argv[++index], "swarm.parse");
84
- break;
85
- case "--max-concurrency":
86
- maxConcurrency = parsePositiveIntFlag("--max-concurrency", argv[++index], "swarm.parse");
87
- break;
88
- default:
89
- if (looksLikeFlag(token)) {
90
- throw new RuntimeError("INVALID_ARGS", `Unknown flag ${token} for swarm. Supported flags: ${SWARM_SUPPORTED_FLAGS}. Use \`--\` before flag-shaped objective text to pass it through.`, "swarm.parse");
91
- }
92
- trailingTokens = argv.slice(index);
93
- index = argv.length;
94
- break;
95
- }
96
- }
97
- if (write && (readRoots.length > 0 || network)) {
98
- throw new RuntimeError("INVALID_ARGS", `swarm --write rejects scope flags. ${SCOPE_FLAGS_WRITE_MESSAGE}`, "swarm.parse");
99
- }
100
- return {
101
- budgetMs,
102
- cap,
103
- maxConcurrency,
104
- write,
105
- model,
106
- thinkingEffort,
107
- ...scopeFields(readRoots, network),
108
- objective: trailingTokens?.join(" "),
109
- };
110
- }
111
- /** Omit default-scope fields so parsed shapes stay unchanged without the flags. */
112
- function scopeFields(readRoots, network) {
113
- return {
114
- ...(readRoots.length > 0 ? { readRoots } : {}),
115
- ...(network ? { network } : {}),
116
- };
117
- }
118
- function readRootValue(value, stage) {
119
- if (!value || value.startsWith("-")) {
120
- throw new RuntimeError("INVALID_ARGS", "--read-root requires an absolute directory path.", stage);
121
- }
122
- return value;
123
- }
124
- function rejectScopeFlag(token, command, stage) {
125
- throw new RuntimeError("INVALID_ARGS", `${command} rejects ${token}. ${SCOPE_FLAGS_WRITE_MESSAGE}`, stage);
126
- }
127
- /**
128
- * Shared positive-integer flag parser for swarm's `--cap` / `--max-concurrency`
129
- * and pursue's `--turns`. Each must be a strict positive integer;
130
- * `--max-concurrency` in particular maps to kimi-code's
131
- * `KIMI_CODE_AGENT_SWARM_MAX_CONCURRENCY`, whose upstream resolver THROWS on a
132
- * non-positive-integer — so the same `Number.isInteger && > 0` predicate
133
- * guarantees every accepted value round-trips through `String()`.
134
- */
135
- function parsePositiveIntFlag(flag, value, stage) {
136
- if (!value || value.startsWith("-")) {
137
- throw new RuntimeError("INVALID_ARGS", `${flag} requires a positive integer.`, stage);
138
- }
139
- const parsed = Number(value);
140
- if (!Number.isInteger(parsed) || parsed <= 0) {
141
- throw new RuntimeError("INVALID_ARGS", `${flag} must be a positive integer.`, stage);
142
- }
143
- return parsed;
144
- }
145
- /** `--thinking <effort>` / `--thinking=<effort>`: [effort, last consumed index]; undefined for other tokens. */
146
- function readThinkingFlag(argv, index) {
147
- const token = argv[index];
148
- if (token === "--thinking" || token.startsWith("--thinking=")) {
149
- const value = token === "--thinking" ? argv[++index] : token.slice("--thinking=".length);
150
- return [validateThinkingEffort(value), index];
151
- }
152
- if (token === "--no-thinking" || token.startsWith("--no-thinking=")) {
153
- throw new RuntimeError("INVALID_ARGS", "--no-thinking is unsupported; use --thinking off", "args.parse");
154
- }
155
- return undefined;
156
- }
157
- function readModel(flag, value, stage) {
158
- if (!value) {
159
- throw new RuntimeError("INVALID_ARGS", `${flag} requires a model value.`, stage);
160
- }
161
- if (value.startsWith("-")) {
162
- throw new RuntimeError("INVALID_ARGS", `${flag} value cannot start with '-'; pass a model name`, stage);
163
- }
164
- return value;
165
- }
166
- function readBudget(value, stage, budgetKind) {
167
- if (!value || value.startsWith("-")) {
168
- throw new RuntimeError("INVALID_ARGS", "--budget requires a duration (e.g. 30m, 1h, 90s).", stage);
169
- }
170
- return parseDurationMs(value, "--budget", stage, budgetKind);
171
- }
172
- /**
173
- * Upper bound for any `--budget` duration. The budget is the SOLE hard
174
- * wall-clock bound on the plugin's autonomous/fan-out surfaces (pursue, swarm),
175
- * so a typo'd or absurd value (`999999h`, a pasted nanosecond count) would
176
- * effectively disable that bound — defeating the one guarantee these modes rest
177
- * on. 24h is far above any legitimate budget (pursue defaults to 45m, swarm to
178
- * 30m) yet still finite, so the AbortController always fires. Above it we
179
- * hard-fail INVALID_ARGS rather than silently clamp — a wrapper LLM passing a
180
- * runaway budget should see the rejection, not a quietly-different value.
181
- */
182
- export const MAX_DURATION_MS = 24 * 60 * 60 * 1_000;
183
- /**
184
- * Parse a duration token (`30m`, `1h`, `90s`, or a bare integer = minutes)
185
- * into milliseconds. Throws INVALID_ARGS on a malformed, non-positive, or
186
- * absurdly large value (> {@link MAX_DURATION_MS}).
187
- */
188
- export function parseDurationMs(token, flag, stage, budgetKind) {
189
- const limitReason = budgetKind === "safety"
190
- ? "the budget is a safety ceiling, not a scheduler"
191
- : "the budget is a response-time limit; a timed-out job is still a safe failure";
192
- const match = /^(\d+)(s|m|h)?$/.exec(token.trim());
193
- if (!match) {
194
- throw new RuntimeError("INVALID_ARGS", `${flag} expects a duration like 30m, 1h, or 90s (bare number = minutes); got "${token}".`, stage);
195
- }
196
- const value = Number(match[1]);
197
- const unit = match[2] ?? "m";
198
- if (!Number.isFinite(value) || value <= 0) {
199
- throw new RuntimeError("INVALID_ARGS", `${flag} must be a positive duration.`, stage);
200
- }
201
- const unitMs = unit === "s" ? 1_000 : unit === "h" ? 3_600_000 : 60_000;
202
- const ms = value * unitMs;
203
- if (ms > MAX_DURATION_MS) {
204
- throw new RuntimeError("INVALID_ARGS", `${flag} must be at most 24h (got "${token}"); ${limitReason}.`, stage);
205
- }
206
- return ms;
207
- }
208
- /**
209
- * Parser for /kimi:pursue (autonomous goal mode). Foreground-only in the
210
- * prototype: no --background/--fresh/--resume (the goalId/sessionId split makes
211
- * session resume unreliable — see pursue.ts). Trailing tokens are the objective.
212
- */
213
- export function parsePursueArgs(argv) {
214
- let model;
215
- let thinkingEffort;
216
- let budgetMs;
217
- let turns;
218
- let trailingTokens;
219
- for (let index = 0; index < argv.length; index += 1) {
220
- const token = argv[index];
221
- const thinking = readThinkingFlag(argv, index);
222
- if (thinking) {
223
- [thinkingEffort, index] = thinking;
224
- continue;
225
- }
226
- if (token === "--") {
227
- trailingTokens = argv.slice(index + 1);
228
- break;
229
- }
230
- if (!token.startsWith("-")) {
231
- trailingTokens = argv.slice(index);
232
- break;
233
- }
234
- switch (token) {
235
- case "-m":
236
- case "--model":
237
- model = readModel(token, argv[++index], "pursue.parse");
238
- break;
239
- case "--budget":
240
- budgetMs = readBudget(argv[++index], "pursue.parse", "safety");
241
- break;
242
- case "--turns":
243
- turns = parsePositiveIntFlag("--turns", argv[++index], "pursue.parse");
244
- break;
245
- case "--read-root":
246
- case "--network":
247
- rejectScopeFlag(token, "pursue", "pursue.parse");
248
- default:
249
- if (looksLikeFlag(token)) {
250
- throw new RuntimeError("INVALID_ARGS", `Unknown flag ${token} for pursue. Supported flags: ${PURSUE_SUPPORTED_FLAGS}. Use \`--\` before flag-shaped objective text to pass it through.`, "pursue.parse");
251
- }
252
- trailingTokens = argv.slice(index);
253
- index = argv.length;
254
- break;
255
- }
256
- }
257
- return {
258
- budgetMs,
259
- turns,
260
- model,
261
- thinkingEffort,
262
- objective: trailingTokens?.join(" "),
263
- };
264
- }
265
- const VALUE_TAKING_FLAGS = new Set(["--thinking", "-m", "--model", "--budget", "--resume", "--base", "--cap", "--max-concurrency", "--turns", "--type", "--read-root"]);
266
- /**
267
- * `--help` / `-h` counts only inside the leading flag region: before `--`
268
- * and before the first prose token. The value of a value-taking flag is
269
- * skipped, so `-m kimi -h` is still a help request (`kimi` is a value, not
270
- * prose) and `--budget --help` asks for help rather than failing on a bad
271
- * duration. Once prose starts (`ask what does du -h print`), nothing after it
272
- * is a flag — the whole remainder is the prompt.
273
- */
274
- export function hasHelpFlag(argv) {
275
- for (let index = 0; index < argv.length; index += 1) {
276
- const token = argv[index];
277
- if (token === "--")
278
- return false;
279
- if (token === "--help" || token === "-h")
280
- return true;
281
- if (!token.startsWith("-"))
282
- return false;
283
- if (VALUE_TAKING_FLAGS.has(token)) {
284
- const value = argv[index + 1];
285
- if (value === "--help" || value === "-h")
286
- return true;
287
- index += 1;
288
- }
289
- }
290
- return false;
291
- }
292
- /**
293
- * Remove every occurrence of a boolean selector flag from the leading flag
294
- * region the prompt parsers use (prose starts at `--` or the first token that
295
- * is not flag-shaped, such as `-5`); undefined when the region lacks it, so a
296
- * selector inside prose never changes the operation.
297
- */
298
- export function withoutLeadingFlag(argv, flag) {
299
- const kept = [];
300
- let found = false;
301
- for (let index = 0; index < argv.length; index += 1) {
302
- const token = argv[index];
303
- if (token === "--" || !looksLikeFlag(token)) {
304
- kept.push(...argv.slice(index));
305
- break;
306
- }
307
- if (token === flag) {
308
- found = true;
309
- continue;
310
- }
311
- kept.push(token);
312
- if (VALUE_TAKING_FLAGS.has(token) && index + 1 < argv.length) {
313
- kept.push(argv[index + 1]);
314
- index += 1;
315
- }
316
- }
317
- return found ? kept : undefined;
318
- }
319
- export function parseAskArgs(argv) {
320
- return parsePromptArgs(argv, "ask");
321
- }
322
- export function parseRescueArgs(argv) {
323
- return parsePromptArgs(argv, "rescue");
324
- }
325
- /** ask and rescue accept the same flags; only the command word in messages and stages differs. */
326
- function parsePromptArgs(argv, kind) {
327
- if (hasHelpFlag(argv))
328
- return { help: true, background: false, wait: false, fresh: false, resume: false };
329
- let budgetMs;
330
- let model;
331
- let thinkingEffort;
332
- let background = false;
333
- let wait = false;
334
- let fresh = false;
335
- let resume = false;
336
- let resumeTarget;
337
- let explicitResumeTarget = false;
338
- const readRoots = [];
339
- let network = false;
340
- let trailingTokens;
341
- for (let index = 0; index < argv.length; index += 1) {
342
- const token = argv[index];
343
- const thinking = readThinkingFlag(argv, index);
344
- if (thinking) {
345
- [thinkingEffort, index] = thinking;
346
- continue;
347
- }
348
- if (token === "--") {
349
- trailingTokens = argv.slice(index + 1);
350
- break;
351
- }
352
- if (!token.startsWith("-")) {
353
- trailingTokens = argv.slice(index);
354
- break;
355
- }
356
- switch (token) {
357
- case "--budget":
358
- budgetMs = readBudget(argv[++index], `${kind}.parse`, "response");
359
- break;
360
- case "-m":
361
- case "--model":
362
- model = readModel(token, argv[++index], "args.parse");
363
- break;
364
- case "--background":
365
- background = true;
366
- break;
367
- case "--wait":
368
- wait = true;
369
- break;
370
- case "--fresh":
371
- fresh = true;
372
- break;
373
- case "--read-root":
374
- if (kind === "rescue")
375
- rejectScopeFlag(token, kind, `${kind}.parse`);
376
- readRoots.push(readRootValue(argv[++index], `${kind}.parse`));
377
- break;
378
- case "--network":
379
- if (kind === "rescue")
380
- rejectScopeFlag(token, kind, `${kind}.parse`);
381
- network = true;
382
- break;
383
- case "-r":
384
- resume = true;
385
- break;
386
- case "--resume": {
387
- const value = argv[index + 1];
388
- if (!value || value.startsWith("-")) {
389
- throw new RuntimeError("INVALID_ARGS", `--resume requires a job-id or session-id. Use -r to resume the latest ${kind} session for this repo.`, `${kind}.parse`);
390
- }
391
- resume = true;
392
- resumeTarget = value;
393
- explicitResumeTarget = true;
394
- index += 1;
395
- break;
396
- }
397
- default:
398
- if (looksLikeFlag(token)) {
399
- throw new RuntimeError("INVALID_ARGS", `Unknown flag ${token} for ${kind}. Supported flags: ${kind === "rescue" ? RESCUE_SUPPORTED_FLAGS : ASK_SUPPORTED_FLAGS}. Use \`--\` before flag-shaped prompt text to pass it through.`, "args.parse");
400
- }
401
- trailingTokens = argv.slice(index);
402
- index = argv.length;
403
- break;
404
- }
405
- }
406
- if (fresh && resume) {
407
- throw new RuntimeError("INVALID_ARGS", `${kind} does not allow --fresh and --resume together.`, `${kind}.parse`);
408
- }
409
- if (explicitResumeTarget && trailingTokens?.length) {
410
- throw new RuntimeError("INVALID_ARGS", `--resume only accepts a job-id or session-id. Use -r to resume the latest ${kind} session with a prompt.`, `${kind}.parse`);
411
- }
412
- return {
413
- budgetMs,
414
- background,
415
- wait,
416
- fresh,
417
- resume,
418
- resumeTarget,
419
- model,
420
- thinkingEffort,
421
- ...scopeFields(readRoots, network),
422
- prompt: trailingTokens?.join(" "),
423
- };
424
- }
425
- export function parseReviewArgs(argv, commandName = "review") {
426
- const parsed = parseKnownFlags(argv, new Set(["--budget", "--base", "--background", "--wait", "-m", "--model", "--read-root", "--network"]), commandName);
427
- return {
428
- budgetMs: parsed.budgetMs,
429
- base: parsed.base,
430
- background: parsed.background,
431
- wait: parsed.wait,
432
- model: parsed.model,
433
- thinkingEffort: parsed.thinkingEffort,
434
- ...scopeFields(parsed.readRoots, parsed.network),
435
- focus: parsed.trailingText,
436
- };
437
- }
438
- export function parseJobLookupArgs(argv) {
439
- let type;
440
- let jobId;
441
- let json = false;
442
- for (let index = 0; index < argv.length; index += 1) {
443
- const token = argv[index];
444
- if (token === "--type") {
445
- const value = argv[index + 1];
446
- if (!value || !isManagedCommandType(value)) {
447
- throw new RuntimeError("INVALID_ARGS", "--type requires one of review, challenge, rescue, review_gate, ask.", "args.parse");
448
- }
449
- type = value;
450
- index += 1;
451
- continue;
452
- }
453
- if (token === "--json") {
454
- json = true;
455
- continue;
456
- }
457
- if (token.startsWith("-")) {
458
- throw new RuntimeError("INVALID_ARGS", `Unknown flag ${token}. Supported flags: ${JOB_LOOKUP_SUPPORTED_FLAGS}.`, "args.parse");
459
- }
460
- if (jobId) {
461
- throw new RuntimeError("INVALID_ARGS", "Only one optional job id may be supplied.", "args.parse");
462
- }
463
- jobId = token;
464
- }
465
- return {
466
- jobId,
467
- type,
468
- json,
469
- };
470
- }
471
- function isManagedCommandType(value) {
472
- return (value === "review" ||
473
- value === "challenge" ||
474
- value === "rescue" ||
475
- value === "review_gate" ||
476
- value === "ask");
477
- }
478
- function parseKnownFlags(argv, knownFlags, commandName) {
479
- let budgetMs;
480
- let model;
481
- let thinkingEffort;
482
- let base;
483
- let background = false;
484
- let wait = false;
485
- const readRoots = [];
486
- let network = false;
487
- let trailingTokens;
488
- for (let index = 0; index < argv.length; index += 1) {
489
- const token = argv[index];
490
- const thinking = readThinkingFlag(argv, index);
491
- if (thinking) {
492
- [thinkingEffort, index] = thinking;
493
- continue;
494
- }
495
- if (token === "--") {
496
- trailingTokens = argv.slice(index + 1);
497
- break;
498
- }
499
- if (!knownFlags.has(token)) {
500
- if (looksLikeFlag(token)) {
501
- throw new RuntimeError("INVALID_ARGS", `Unknown flag ${token} for ${commandName}. Supported flags: ${REVIEW_SUPPORTED_FLAGS}. Use \`--\` before flag-shaped focus text to pass it through.`, "args.parse");
502
- }
503
- trailingTokens = argv.slice(index);
504
- break;
505
- }
506
- switch (token) {
507
- case "--budget":
508
- budgetMs = readBudget(argv[++index], `${commandName}.parse`, "response");
509
- break;
510
- case "-m":
511
- case "--model":
512
- model = readModel(token, argv[++index], "args.parse");
513
- break;
514
- case "--base": {
515
- const value = argv[index + 1];
516
- if (!value) {
517
- throw new RuntimeError("INVALID_ARGS", "--base requires a ref value.", "args.parse");
518
- }
519
- if (value.startsWith("-")) {
520
- throw new RuntimeError("INVALID_ARGS", "--base value cannot start with '-'; pass a branch, tag, or commit ref.", "args.parse");
521
- }
522
- base = value;
523
- index += 1;
524
- break;
525
- }
526
- case "--background":
527
- background = true;
528
- break;
529
- case "--wait":
530
- wait = true;
531
- break;
532
- case "--read-root":
533
- readRoots.push(readRootValue(argv[++index], `${commandName}.parse`));
534
- break;
535
- case "--network":
536
- network = true;
537
- break;
538
- // The early `if (!knownFlags.has(token))` gate above means we only
539
- // reach this switch with tokens that ARE in knownFlags, and every
540
- // member is handled above. A `default` arm would be unreachable.
541
- }
542
- }
543
- return {
544
- budgetMs,
545
- base,
546
- background,
547
- wait,
548
- readRoots,
549
- network,
550
- model,
551
- thinkingEffort,
552
- trailingText: trailingTokens?.join(" "),
553
- };
554
- }
@@ -1,35 +0,0 @@
1
- import { constants } from "node:fs";
2
- import { access, mkdir } from "node:fs/promises";
3
- import path from "node:path";
4
- import { resolvePluginDataRoot } from "./plugin-data.js";
5
- export function resolvePluginPaths(env) {
6
- const claudePluginData = resolvePluginDataRoot(env);
7
- const pluginRoot = path.join(claudePluginData, "kimi-plugin-cc");
8
- return {
9
- claudePluginData,
10
- pluginRoot,
11
- stateDbPath: path.join(pluginRoot, "state.db"),
12
- logsDir: path.join(pluginRoot, "logs"),
13
- artifactsDir: path.join(pluginRoot, "artifacts"),
14
- worktreesDir: path.join(pluginRoot, "worktrees"),
15
- configPath: path.join(pluginRoot, "config.json"),
16
- };
17
- }
18
- /**
19
- * Plugin-owned kimi-code installs (`setup --install-kimi`): one directory per
20
- * exact version plus a `current` symlink. Binary resolution and the installer
21
- * both use this helper so they cannot disagree about the location.
22
- */
23
- export function resolveKimiBinDir(env) {
24
- return path.join(resolvePluginPaths(env).pluginRoot, "kimi-bin");
25
- }
26
- export async function ensurePluginPaths(paths) {
27
- await mkdir(paths.pluginRoot, { recursive: true });
28
- await mkdir(paths.logsDir, { recursive: true });
29
- await mkdir(paths.artifactsDir, { recursive: true });
30
- await access(paths.pluginRoot, constants.R_OK | constants.W_OK);
31
- await access(paths.logsDir, constants.R_OK | constants.W_OK);
32
- await access(paths.artifactsDir, constants.R_OK | constants.W_OK);
33
- // worktreesDir is created lazily by the write-swarm path (not every command
34
- // needs it), so it is intentionally NOT required here.
35
- }
@@ -1,98 +0,0 @@
1
- import { existsSync, lstatSync, realpathSync, statSync } from "node:fs";
2
- import path from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import { RuntimeError } from "./errors.js";
5
- // Use the loaded module, not the shared PLUGIN_ROOT/CLAUDE_PLUGIN_ROOT variables.
6
- // Both source and compiled modules live one directory below the package root.
7
- const loadedPackageRoot = fileURLToPath(new URL("../", import.meta.url));
8
- /** Resolve state without silently trusting a different plugin's shared env. */
9
- export function resolvePluginDataRoot(env, packageRoot = loadedPackageRoot) {
10
- const explicit = env.KIMI_PLUGIN_CC_DATA;
11
- if (explicit !== undefined) {
12
- if (!path.isAbsolute(explicit)) {
13
- throw new RuntimeError("INVALID_PLUGIN_DATA", "KIMI_PLUGIN_CC_DATA must be an absolute directory path, not an empty or relative value.", "paths");
14
- }
15
- return path.normalize(explicit);
16
- }
17
- const expected = installedDataRoot(packageRoot);
18
- const shared = [env.CLAUDE_PLUGIN_DATA, env.PLUGIN_DATA].filter((value) => Boolean(value));
19
- if (expected) {
20
- if (shared.some((value) => !path.isAbsolute(value) || !sameDataRoot(value, expected))) {
21
- throw new RuntimeError("PLUGIN_DATA_CONFLICT", "Shared plugin data variables do not match this installation. Remove the conflicting variables or set KIMI_PLUGIN_CC_DATA to the intended Kimi data directory. No data was moved.", "paths", { details: { expected_data_root: expected, override_variable: "KIMI_PLUGIN_CC_DATA" } });
22
- }
23
- return expected;
24
- }
25
- // Checkout/custom launch compatibility: we cannot infer ownership from an
26
- // arbitrary directory or from a marker that may not exist on first setup.
27
- // Preserve the old location when unambiguous; require an explicit choice otherwise.
28
- if (shared.length === 2 && !sameDataRoot(shared[0], shared[1])) {
29
- throw new RuntimeError("PLUGIN_DATA_CONFLICT", "CLAUDE_PLUGIN_DATA and PLUGIN_DATA disagree. Set KIMI_PLUGIN_CC_DATA to the intended Kimi data directory before retrying. No data was moved.", "paths");
30
- }
31
- if (shared[0])
32
- return shared[0];
33
- if (env.KIMI_PLUGIN_CC_SHELL_LAUNCH === "1" && (env.CODEX_HOME || env.HOME)) {
34
- const dataRoot = env.CODEX_HOME
35
- ? path.join(env.CODEX_HOME, "plugins", "data")
36
- : path.join(env.HOME, ".codex", "plugins", "data");
37
- return path.join(dataRoot, "kimi-marketplace-kimi");
38
- }
39
- throw new RuntimeError("MISSING_PLUGIN_DATA", "Set KIMI_PLUGIN_CC_DATA to an absolute writable data directory. Custom launches may also use an unambiguous CLAUDE_PLUGIN_DATA or PLUGIN_DATA value.", "paths");
40
- }
41
- function installedDataRoot(packageRoot) {
42
- const root = path.resolve(packageRoot);
43
- const pluginDir = path.dirname(root);
44
- const marketplaceDir = path.dirname(pluginDir);
45
- const cacheDir = path.dirname(marketplaceDir);
46
- const pluginsDir = path.dirname(cacheDir);
47
- if (path.basename(pluginDir) !== "kimi" || path.basename(cacheDir) !== "cache" || path.basename(pluginsDir) !== "plugins") {
48
- return undefined;
49
- }
50
- const marketplace = path.basename(marketplaceDir);
51
- if (existsSync(path.join(root, ".codex-plugin", "plugin.json"))) {
52
- return path.join(pluginsDir, "data", `${marketplace}-kimi`);
53
- }
54
- if (existsSync(path.join(root, ".claude-plugin", "plugin.json"))) {
55
- // Claude documents plugin-id sanitization for persistent data directories.
56
- const id = `kimi@${marketplace}`.replace(/[^a-zA-Z0-9_-]/g, "-");
57
- return path.join(pluginsDir, "data", id);
58
- }
59
- return undefined;
60
- }
61
- function sameDataRoot(left, right) {
62
- if (path.resolve(left) === path.resolve(right))
63
- return true;
64
- const canonicalLeft = canonicalDataRoot(left);
65
- return canonicalLeft !== undefined && canonicalLeft === canonicalDataRoot(right);
66
- }
67
- /** Resolve existing ancestors without creating a first-run data directory. */
68
- function canonicalDataRoot(value) {
69
- let cursor = path.resolve(value);
70
- const missing = [];
71
- for (;;) {
72
- try {
73
- const resolved = realpathSync(cursor);
74
- if (missing.length > 0 && !statSync(cursor).isDirectory())
75
- return undefined;
76
- return path.join(resolved, ...missing);
77
- }
78
- catch (error) {
79
- if (error.code !== "ENOENT")
80
- return undefined;
81
- // ENOENT can also mean a dangling symlink. Do not treat an existing
82
- // link as a missing directory and accidentally bypass its destination.
83
- try {
84
- lstatSync(cursor);
85
- return undefined;
86
- }
87
- catch (statError) {
88
- if (statError.code !== "ENOENT")
89
- return undefined;
90
- }
91
- const parent = path.dirname(cursor);
92
- if (parent === cursor)
93
- return undefined;
94
- missing.unshift(path.basename(cursor));
95
- cursor = parent;
96
- }
97
- }
98
- }