kimi-plugin-cc 2.7.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +3 -5
  3. package/CHANGELOG.md +78 -1
  4. package/README.md +505 -448
  5. package/agents/kimi-pursue.md +6 -6
  6. package/agents/kimi-review.md +22 -22
  7. package/agents/kimi-swarm.md +25 -23
  8. package/agents/{kimi-ask.md → kimi-task.md} +34 -30
  9. package/commands/README.md +4 -6
  10. package/commands/pursue.md +1 -1
  11. package/commands/review.md +8 -3
  12. package/commands/setup.md +4 -2
  13. package/commands/swarm.md +6 -5
  14. package/commands/{rescue.md → task.md} +13 -11
  15. package/dist/background-spawn.js +10 -17
  16. package/dist/cli-client.js +65 -46
  17. package/dist/commands/ask.js +22 -89
  18. package/dist/commands/cancel.js +7 -46
  19. package/dist/commands/cli-helpers.js +102 -1
  20. package/dist/commands/models.js +2 -3
  21. package/dist/commands/pursue.js +5 -19
  22. package/dist/commands/repair-sessions.js +118 -12
  23. package/dist/commands/rescue.js +12 -82
  24. package/dist/commands/result.js +7 -1
  25. package/dist/commands/review-gate.js +1 -0
  26. package/dist/commands/review.js +12 -15
  27. package/dist/commands/setup.js +606 -270
  28. package/dist/commands/status.js +2 -2
  29. package/dist/commands/swarm.js +93 -119
  30. package/dist/commands/worker.js +1 -2
  31. package/dist/companion.js +3 -1
  32. package/dist/dsh/index.js +15 -17
  33. package/dist/git.js +1 -9
  34. package/dist/help.js +3 -3
  35. package/dist/hooks/approval-hook.js +41 -0
  36. package/dist/hooks/approval-policy.js +72 -10
  37. package/dist/hooks/config-safety.js +19 -42
  38. package/dist/hooks/hook-timing.js +48 -0
  39. package/dist/hooks/install.js +206 -11
  40. package/dist/hooks/managed-block.js +78 -33
  41. package/dist/job-store.js +100 -128
  42. package/dist/jobs.js +14 -19
  43. package/dist/kimi-command.js +74 -1
  44. package/dist/kimi-engine.js +170 -74
  45. package/dist/kimi-errors.js +14 -69
  46. package/dist/kimi-home.js +6 -0
  47. package/dist/kimi-journal.js +41 -0
  48. package/dist/kimi-releases.js +144 -0
  49. package/dist/kimi-timeouts.js +1 -1
  50. package/dist/kimi-version-probe.js +12 -48
  51. package/dist/mcp/job-control.js +4 -6
  52. package/dist/mcp/launcher.js +12 -6
  53. package/dist/mcp/operations.js +50 -18
  54. package/dist/mcp/protocol.js +16 -14
  55. package/dist/mcp/stdio.js +3 -2
  56. package/dist/model-command.js +5 -3
  57. package/dist/native-v2-preflight.js +139 -68
  58. package/dist/parsing.js +171 -237
  59. package/dist/paths.js +8 -0
  60. package/dist/process-tree.js +35 -24
  61. package/dist/read-scope.js +435 -0
  62. package/dist/render.js +46 -9
  63. package/dist/rescue-approval.js +461 -84
  64. package/dist/schemas/review-gate-output.js +3 -5
  65. package/dist/session-title.js +25 -5
  66. package/dist/stream-json.js +1 -3
  67. package/dist/surface-routing.js +21 -0
  68. package/dist/swarm-activation.js +74 -77
  69. package/dist/swarm-policy.js +2 -1
  70. package/dist/swarm-recovery.js +2 -1
  71. package/dist/util.js +28 -0
  72. package/dist/version.js +1 -1
  73. package/docs/migration.md +27 -6
  74. package/docs/models.md +2 -2
  75. package/docs/registry-releases.md +3 -1
  76. package/docs/safety.md +131 -81
  77. package/docs/session-visibility.md +5 -3
  78. package/docs/swarm-recovery.md +4 -4
  79. package/docs/upstream-2.7.2-certification.md +16 -2
  80. package/docs/upstream-2.7.3-certification.md +95 -0
  81. package/package.json +2 -1
  82. package/plugins/kimi-codex/.codex-plugin/plugin.json +3 -3
  83. package/plugins/kimi-codex/.mcp.json +1 -0
  84. package/plugins/kimi-codex/dist/background-spawn.js +10 -17
  85. package/plugins/kimi-codex/dist/cli-client.js +65 -46
  86. package/plugins/kimi-codex/dist/commands/ask.js +22 -89
  87. package/plugins/kimi-codex/dist/commands/cancel.js +7 -46
  88. package/plugins/kimi-codex/dist/commands/cli-helpers.js +102 -1
  89. package/plugins/kimi-codex/dist/commands/models.js +2 -3
  90. package/plugins/kimi-codex/dist/commands/pursue.js +5 -19
  91. package/plugins/kimi-codex/dist/commands/repair-sessions.js +118 -12
  92. package/plugins/kimi-codex/dist/commands/rescue.js +12 -82
  93. package/plugins/kimi-codex/dist/commands/result.js +7 -1
  94. package/plugins/kimi-codex/dist/commands/review-gate.js +1 -0
  95. package/plugins/kimi-codex/dist/commands/review.js +12 -15
  96. package/plugins/kimi-codex/dist/commands/setup.js +606 -270
  97. package/plugins/kimi-codex/dist/commands/status.js +2 -2
  98. package/plugins/kimi-codex/dist/commands/swarm.js +93 -119
  99. package/plugins/kimi-codex/dist/commands/worker.js +1 -2
  100. package/plugins/kimi-codex/dist/companion.js +3 -1
  101. package/plugins/kimi-codex/dist/dsh/index.js +15 -17
  102. package/plugins/kimi-codex/dist/git.js +1 -9
  103. package/plugins/kimi-codex/dist/help.js +3 -3
  104. package/plugins/kimi-codex/dist/hooks/approval-hook.js +41 -0
  105. package/plugins/kimi-codex/dist/hooks/approval-policy.js +72 -10
  106. package/plugins/kimi-codex/dist/hooks/config-safety.js +19 -42
  107. package/plugins/kimi-codex/dist/hooks/hook-timing.js +48 -0
  108. package/plugins/kimi-codex/dist/hooks/install.js +206 -11
  109. package/plugins/kimi-codex/dist/hooks/managed-block.js +78 -33
  110. package/plugins/kimi-codex/dist/job-store.js +100 -128
  111. package/plugins/kimi-codex/dist/jobs.js +14 -19
  112. package/plugins/kimi-codex/dist/kimi-command.js +74 -1
  113. package/plugins/kimi-codex/dist/kimi-engine.js +170 -74
  114. package/plugins/kimi-codex/dist/kimi-errors.js +14 -69
  115. package/plugins/kimi-codex/dist/kimi-home.js +6 -0
  116. package/plugins/kimi-codex/dist/kimi-journal.js +41 -0
  117. package/plugins/kimi-codex/dist/kimi-releases.js +144 -0
  118. package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -1
  119. package/plugins/kimi-codex/dist/kimi-version-probe.js +12 -48
  120. package/plugins/kimi-codex/dist/mcp/job-control.js +4 -6
  121. package/plugins/kimi-codex/dist/mcp/launcher.js +12 -6
  122. package/plugins/kimi-codex/dist/mcp/operations.js +50 -18
  123. package/plugins/kimi-codex/dist/mcp/protocol.js +16 -14
  124. package/plugins/kimi-codex/dist/mcp/stdio.js +3 -2
  125. package/plugins/kimi-codex/dist/model-command.js +5 -3
  126. package/plugins/kimi-codex/dist/native-v2-preflight.js +139 -68
  127. package/plugins/kimi-codex/dist/parsing.js +171 -237
  128. package/plugins/kimi-codex/dist/paths.js +8 -0
  129. package/plugins/kimi-codex/dist/process-tree.js +35 -24
  130. package/plugins/kimi-codex/dist/read-scope.js +435 -0
  131. package/plugins/kimi-codex/dist/render.js +46 -9
  132. package/plugins/kimi-codex/dist/rescue-approval.js +461 -84
  133. package/plugins/kimi-codex/dist/schemas/review-gate-output.js +3 -5
  134. package/plugins/kimi-codex/dist/session-title.js +25 -5
  135. package/plugins/kimi-codex/dist/stream-json.js +1 -3
  136. package/plugins/kimi-codex/dist/surface-routing.js +21 -0
  137. package/plugins/kimi-codex/dist/swarm-activation.js +74 -77
  138. package/plugins/kimi-codex/dist/swarm-policy.js +2 -1
  139. package/plugins/kimi-codex/dist/swarm-recovery.js +2 -1
  140. package/plugins/kimi-codex/dist/util.js +28 -0
  141. package/plugins/kimi-codex/dist/version.js +1 -1
  142. package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +1 -1
  143. package/plugins/kimi-codex/skills/kimi-review/SKILL.md +8 -7
  144. package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +1 -1
  145. package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +2 -1
  146. package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +8 -6
  147. package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +1 -1
  148. package/plugins/kimi-codex/skills/{kimi-ask → kimi-task}/SKILL.md +11 -9
  149. package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +6 -0
  150. package/plugins/kimi-dsh/README.md +3 -2
  151. package/plugins/kimi-dsh/dist/background-spawn.js +10 -17
  152. package/plugins/kimi-dsh/dist/cli-client.js +65 -46
  153. package/plugins/kimi-dsh/dist/commands/ask.js +22 -89
  154. package/plugins/kimi-dsh/dist/commands/cancel.js +7 -46
  155. package/plugins/kimi-dsh/dist/commands/cli-helpers.js +102 -1
  156. package/plugins/kimi-dsh/dist/commands/models.js +2 -3
  157. package/plugins/kimi-dsh/dist/commands/pursue.js +5 -19
  158. package/plugins/kimi-dsh/dist/commands/repair-sessions.js +118 -12
  159. package/plugins/kimi-dsh/dist/commands/rescue.js +12 -82
  160. package/plugins/kimi-dsh/dist/commands/result.js +7 -1
  161. package/plugins/kimi-dsh/dist/commands/review-gate.js +1 -0
  162. package/plugins/kimi-dsh/dist/commands/review.js +12 -15
  163. package/plugins/kimi-dsh/dist/commands/setup.js +606 -270
  164. package/plugins/kimi-dsh/dist/commands/status.js +2 -2
  165. package/plugins/kimi-dsh/dist/commands/swarm.js +93 -119
  166. package/plugins/kimi-dsh/dist/commands/worker.js +1 -2
  167. package/plugins/kimi-dsh/dist/companion.js +3 -1
  168. package/plugins/kimi-dsh/dist/dsh/index.js +15 -17
  169. package/plugins/kimi-dsh/dist/git.js +1 -9
  170. package/plugins/kimi-dsh/dist/help.js +3 -3
  171. package/plugins/kimi-dsh/dist/hooks/approval-hook.js +41 -0
  172. package/plugins/kimi-dsh/dist/hooks/approval-policy.js +72 -10
  173. package/plugins/kimi-dsh/dist/hooks/config-safety.js +19 -42
  174. package/plugins/kimi-dsh/dist/hooks/hook-timing.js +48 -0
  175. package/plugins/kimi-dsh/dist/hooks/install.js +206 -11
  176. package/plugins/kimi-dsh/dist/hooks/managed-block.js +78 -33
  177. package/plugins/kimi-dsh/dist/job-store.js +100 -128
  178. package/plugins/kimi-dsh/dist/jobs.js +14 -19
  179. package/plugins/kimi-dsh/dist/kimi-command.js +74 -1
  180. package/plugins/kimi-dsh/dist/kimi-engine.js +170 -74
  181. package/plugins/kimi-dsh/dist/kimi-errors.js +14 -69
  182. package/plugins/kimi-dsh/dist/kimi-home.js +6 -0
  183. package/plugins/kimi-dsh/dist/kimi-journal.js +41 -0
  184. package/plugins/kimi-dsh/dist/kimi-releases.js +144 -0
  185. package/plugins/kimi-dsh/dist/kimi-timeouts.js +1 -1
  186. package/plugins/kimi-dsh/dist/kimi-version-probe.js +12 -48
  187. package/plugins/kimi-dsh/dist/mcp/job-control.js +4 -6
  188. package/plugins/kimi-dsh/dist/mcp/launcher.js +12 -6
  189. package/plugins/kimi-dsh/dist/mcp/operations.js +50 -18
  190. package/plugins/kimi-dsh/dist/mcp/protocol.js +16 -14
  191. package/plugins/kimi-dsh/dist/mcp/stdio.js +3 -2
  192. package/plugins/kimi-dsh/dist/model-command.js +5 -3
  193. package/plugins/kimi-dsh/dist/native-v2-preflight.js +139 -68
  194. package/plugins/kimi-dsh/dist/parsing.js +171 -237
  195. package/plugins/kimi-dsh/dist/paths.js +8 -0
  196. package/plugins/kimi-dsh/dist/process-tree.js +35 -24
  197. package/plugins/kimi-dsh/dist/read-scope.js +435 -0
  198. package/plugins/kimi-dsh/dist/render.js +46 -9
  199. package/plugins/kimi-dsh/dist/rescue-approval.js +461 -84
  200. package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +3 -5
  201. package/plugins/kimi-dsh/dist/session-title.js +25 -5
  202. package/plugins/kimi-dsh/dist/stream-json.js +1 -3
  203. package/plugins/kimi-dsh/dist/surface-routing.js +21 -0
  204. package/plugins/kimi-dsh/dist/swarm-activation.js +74 -77
  205. package/plugins/kimi-dsh/dist/swarm-policy.js +2 -1
  206. package/plugins/kimi-dsh/dist/swarm-recovery.js +2 -1
  207. package/plugins/kimi-dsh/dist/util.js +28 -0
  208. package/plugins/kimi-dsh/dist/version.js +1 -1
  209. package/plugins/kimi-dsh/package.json +1 -1
  210. package/agents/kimi-challenge.md +0 -86
  211. package/agents/kimi-rescue.md +0 -92
  212. package/agents/kimi-swarm-write.md +0 -96
  213. package/commands/ask.md +0 -38
  214. package/commands/challenge.md +0 -35
  215. package/dist/commands/not-implemented.js +0 -4
  216. package/plugins/kimi-codex/dist/commands/not-implemented.js +0 -4
  217. package/plugins/kimi-codex/skills/kimi-ask/agents/openai.yaml +0 -6
  218. package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +0 -34
  219. package/plugins/kimi-codex/skills/kimi-challenge/agents/openai.yaml +0 -6
  220. package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +0 -34
  221. package/plugins/kimi-codex/skills/kimi-rescue/agents/openai.yaml +0 -6
  222. package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +0 -36
  223. package/plugins/kimi-codex/skills/kimi-swarm-write/agents/openai.yaml +0 -6
  224. package/plugins/kimi-dsh/dist/commands/not-implemented.js +0 -4
package/dist/parsing.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { RuntimeError } from "./errors.js";
2
+ import { SCOPE_FLAGS_WRITE_MESSAGE } from "./read-scope.js";
2
3
  /**
3
4
  * Unknown flag-shaped tokens hard-fail instead of being absorbed into prose.
4
5
  * Parsing still switches to prose at the first non-flag token or after `--`.
@@ -13,11 +14,12 @@ function looksLikeFlag(token) {
13
14
  // Short flag: a single dash followed by exactly one letter (`-r`, `-m`).
14
15
  return /^-[a-zA-Z]$/.test(token);
15
16
  }
16
- export const ASK_SUPPORTED_FLAGS = "-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --background, --wait, --fresh, -r, --resume <job-id|session-id>";
17
+ const SCOPE_SUPPORTED_FLAGS = "--read-root <absolute-dir> (repeatable), --network";
17
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>";
18
- export const REVIEW_SUPPORTED_FLAGS = "--base <ref>, -m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>";
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}`;
19
21
  export const JOB_LOOKUP_SUPPORTED_FLAGS = "--type <review|challenge|rescue|review_gate|ask>, --json";
20
- export const SETUP_SUPPORTED_FLAGS = "--check, --uninstall, --all (with --uninstall), --enable-review-gate, --disable-review-gate, --models [--json] (without other setup flags)";
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)";
21
23
  export const RECOVER_SWARM_SUPPORTED_FLAGS = "--apply";
22
24
  export const REPAIR_SESSIONS_SUPPORTED_FLAGS = "--apply, --all";
23
25
  export const REPLAY_SUPPORTED_FLAGS = "none (one job-id required)";
@@ -30,7 +32,7 @@ export function validateThinkingEffort(value, stage = "args.parse", lowercase =
30
32
  return effort;
31
33
  }
32
34
  export const PURSUE_SUPPORTED_FLAGS = "-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --turns <N>";
33
- export const SWARM_SUPPORTED_FLAGS = "-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --cap <N>, --max-concurrency <N>, --write";
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)`;
34
36
  /**
35
37
  * Parser for /kimi:swarm. Foreground-only: no --background/--fresh/--resume.
36
38
  * Trailing tokens are the objective.
@@ -42,16 +44,16 @@ export function parseSwarmArgs(argv) {
42
44
  let cap;
43
45
  let maxConcurrency;
44
46
  let write = false;
47
+ const readRoots = [];
48
+ let network = false;
45
49
  let trailingTokens;
46
50
  for (let index = 0; index < argv.length; index += 1) {
47
51
  const token = argv[index];
48
- if (token === "--thinking" || token.startsWith("--thinking=")) {
49
- thinkingEffort = validateThinkingEffort(token === "--thinking" ? argv[++index] : token.slice("--thinking=".length));
52
+ const thinking = readThinkingFlag(argv, index);
53
+ if (thinking) {
54
+ [thinkingEffort, index] = thinking;
50
55
  continue;
51
56
  }
52
- if (token === "--no-thinking" || token.startsWith("--no-thinking=")) {
53
- throw new RuntimeError("INVALID_ARGS", "--no-thinking is unsupported; use --thinking off", "args.parse");
54
- }
55
57
  if (token === "--") {
56
58
  trailingTokens = argv.slice(index + 1);
57
59
  break;
@@ -62,40 +64,27 @@ export function parseSwarmArgs(argv) {
62
64
  }
63
65
  switch (token) {
64
66
  case "-m":
65
- case "--model": {
66
- const value = argv[index + 1];
67
- if (!value) {
68
- throw new RuntimeError("INVALID_ARGS", `${token} requires a model value.`, "swarm.parse");
69
- }
70
- if (value.startsWith("-")) {
71
- throw new RuntimeError("INVALID_ARGS", `${token} value cannot start with '-'; pass a model name`, "swarm.parse");
72
- }
73
- model = value;
74
- index += 1;
67
+ case "--model":
68
+ model = readModel(token, argv[++index], "swarm.parse");
75
69
  break;
76
- }
77
70
  case "--write":
78
71
  write = true;
79
72
  break;
80
- case "--budget": {
81
- const value = argv[index + 1];
82
- if (!value || value.startsWith("-")) {
83
- throw new RuntimeError("INVALID_ARGS", "--budget requires a duration (e.g. 30m, 1h, 90s).", "swarm.parse");
84
- }
85
- budgetMs = parseDurationMs(value, "--budget", "swarm.parse", "safety");
86
- index += 1;
73
+ case "--read-root":
74
+ readRoots.push(readRootValue(argv[++index], "swarm.parse"));
87
75
  break;
88
- }
89
- case "--cap": {
90
- cap = parsePositiveIntFlag("--cap", argv[index + 1]);
91
- index += 1;
76
+ case "--network":
77
+ network = true;
92
78
  break;
93
- }
94
- case "--max-concurrency": {
95
- maxConcurrency = parsePositiveIntFlag("--max-concurrency", argv[index + 1]);
96
- index += 1;
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");
97
87
  break;
98
- }
99
88
  default:
100
89
  if (looksLikeFlag(token)) {
101
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");
@@ -105,6 +94,9 @@ export function parseSwarmArgs(argv) {
105
94
  break;
106
95
  }
107
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
+ }
108
100
  return {
109
101
  budgetMs,
110
102
  cap,
@@ -112,26 +104,71 @@ export function parseSwarmArgs(argv) {
112
104
  write,
113
105
  model,
114
106
  thinkingEffort,
107
+ ...scopeFields(readRoots, network),
115
108
  objective: trailingTokens?.join(" "),
116
109
  };
117
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
+ }
118
127
  /**
119
- * Shared positive-integer flag parser for swarm's `--cap` / `--max-concurrency`.
120
- * Both must be a strict positive integer; `--max-concurrency` in particular maps
121
- * to kimi-code's `KIMI_CODE_AGENT_SWARM_MAX_CONCURRENCY`, whose upstream resolver
122
- * THROWS on a non-positive-integer — so the same `Number.isInteger && > 0`
123
- * predicate guarantees every accepted value round-trips through `String()`.
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()`.
124
134
  */
125
- function parsePositiveIntFlag(flag, value) {
135
+ function parsePositiveIntFlag(flag, value, stage) {
126
136
  if (!value || value.startsWith("-")) {
127
- throw new RuntimeError("INVALID_ARGS", `${flag} requires a positive integer.`, "swarm.parse");
137
+ throw new RuntimeError("INVALID_ARGS", `${flag} requires a positive integer.`, stage);
128
138
  }
129
139
  const parsed = Number(value);
130
140
  if (!Number.isInteger(parsed) || parsed <= 0) {
131
- throw new RuntimeError("INVALID_ARGS", `${flag} must be a positive integer.`, "swarm.parse");
141
+ throw new RuntimeError("INVALID_ARGS", `${flag} must be a positive integer.`, stage);
132
142
  }
133
143
  return parsed;
134
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
+ }
135
172
  /**
136
173
  * Upper bound for any `--budget` duration. The budget is the SOLE hard
137
174
  * wall-clock bound on the plugin's autonomous/fan-out surfaces (pursue, swarm),
@@ -181,13 +218,11 @@ export function parsePursueArgs(argv) {
181
218
  let trailingTokens;
182
219
  for (let index = 0; index < argv.length; index += 1) {
183
220
  const token = argv[index];
184
- if (token === "--thinking" || token.startsWith("--thinking=")) {
185
- thinkingEffort = validateThinkingEffort(token === "--thinking" ? argv[++index] : token.slice("--thinking=".length));
221
+ const thinking = readThinkingFlag(argv, index);
222
+ if (thinking) {
223
+ [thinkingEffort, index] = thinking;
186
224
  continue;
187
225
  }
188
- if (token === "--no-thinking" || token.startsWith("--no-thinking=")) {
189
- throw new RuntimeError("INVALID_ARGS", "--no-thinking is unsupported; use --thinking off", "args.parse");
190
- }
191
226
  if (token === "--") {
192
227
  trailingTokens = argv.slice(index + 1);
193
228
  break;
@@ -198,40 +233,18 @@ export function parsePursueArgs(argv) {
198
233
  }
199
234
  switch (token) {
200
235
  case "-m":
201
- case "--model": {
202
- const value = argv[index + 1];
203
- if (!value) {
204
- throw new RuntimeError("INVALID_ARGS", `${token} requires a model value.`, "pursue.parse");
205
- }
206
- if (value.startsWith("-")) {
207
- throw new RuntimeError("INVALID_ARGS", `${token} value cannot start with '-'; pass a model name`, "pursue.parse");
208
- }
209
- model = value;
210
- index += 1;
236
+ case "--model":
237
+ model = readModel(token, argv[++index], "pursue.parse");
211
238
  break;
212
- }
213
- case "--budget": {
214
- const value = argv[index + 1];
215
- if (!value || value.startsWith("-")) {
216
- throw new RuntimeError("INVALID_ARGS", "--budget requires a duration (e.g. 30m, 1h, 90s).", "pursue.parse");
217
- }
218
- budgetMs = parseDurationMs(value, "--budget", "pursue.parse", "safety");
219
- index += 1;
239
+ case "--budget":
240
+ budgetMs = readBudget(argv[++index], "pursue.parse", "safety");
220
241
  break;
221
- }
222
- case "--turns": {
223
- const value = argv[index + 1];
224
- if (!value || value.startsWith("-")) {
225
- throw new RuntimeError("INVALID_ARGS", "--turns requires a positive integer.", "pursue.parse");
226
- }
227
- const parsedTurns = Number(value);
228
- if (!Number.isInteger(parsedTurns) || parsedTurns <= 0) {
229
- throw new RuntimeError("INVALID_ARGS", "--turns must be a positive integer.", "pursue.parse");
230
- }
231
- turns = parsedTurns;
232
- index += 1;
242
+ case "--turns":
243
+ turns = parsePositiveIntFlag("--turns", argv[++index], "pursue.parse");
233
244
  break;
234
- }
245
+ case "--read-root":
246
+ case "--network":
247
+ rejectScopeFlag(token, "pursue", "pursue.parse");
235
248
  default:
236
249
  if (looksLikeFlag(token)) {
237
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");
@@ -249,7 +262,7 @@ export function parsePursueArgs(argv) {
249
262
  objective: trailingTokens?.join(" "),
250
263
  };
251
264
  }
252
- const VALUE_TAKING_FLAGS = new Set(["--thinking", "-m", "--model", "--budget", "--resume", "--base", "--cap", "--max-concurrency", "--turns", "--type"]);
265
+ const VALUE_TAKING_FLAGS = new Set(["--thinking", "-m", "--model", "--budget", "--resume", "--base", "--cap", "--max-concurrency", "--turns", "--type", "--read-root"]);
253
266
  /**
254
267
  * `--help` / `-h` counts only inside the leading flag region: before `--`
255
268
  * and before the first prose token. The value of a value-taking flag is
@@ -276,7 +289,41 @@ export function hasHelpFlag(argv) {
276
289
  }
277
290
  return false;
278
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
+ }
279
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) {
280
327
  if (hasHelpFlag(argv))
281
328
  return { help: true, background: false, wait: false, fresh: false, resume: false };
282
329
  let budgetMs;
@@ -288,16 +335,16 @@ export function parseAskArgs(argv) {
288
335
  let resume = false;
289
336
  let resumeTarget;
290
337
  let explicitResumeTarget = false;
338
+ const readRoots = [];
339
+ let network = false;
291
340
  let trailingTokens;
292
341
  for (let index = 0; index < argv.length; index += 1) {
293
342
  const token = argv[index];
294
- if (token === "--thinking" || token.startsWith("--thinking=")) {
295
- thinkingEffort = validateThinkingEffort(token === "--thinking" ? argv[++index] : token.slice("--thinking=".length));
343
+ const thinking = readThinkingFlag(argv, index);
344
+ if (thinking) {
345
+ [thinkingEffort, index] = thinking;
296
346
  continue;
297
347
  }
298
- if (token === "--no-thinking" || token.startsWith("--no-thinking=")) {
299
- throw new RuntimeError("INVALID_ARGS", "--no-thinking is unsupported; use --thinking off", "args.parse");
300
- }
301
348
  if (token === "--") {
302
349
  trailingTokens = argv.slice(index + 1);
303
350
  break;
@@ -307,28 +354,13 @@ export function parseAskArgs(argv) {
307
354
  break;
308
355
  }
309
356
  switch (token) {
310
- case "--budget": {
311
- const value = argv[index + 1];
312
- if (!value || value.startsWith("-")) {
313
- throw new RuntimeError("INVALID_ARGS", "--budget requires a duration (e.g. 30m, 1h, 90s).", "ask.parse");
314
- }
315
- budgetMs = parseDurationMs(value, "--budget", "ask.parse", "response");
316
- index += 1;
357
+ case "--budget":
358
+ budgetMs = readBudget(argv[++index], `${kind}.parse`, "response");
317
359
  break;
318
- }
319
360
  case "-m":
320
- case "--model": {
321
- const value = argv[index + 1];
322
- if (!value) {
323
- throw new RuntimeError("INVALID_ARGS", `${token} requires a model value.`, "args.parse");
324
- }
325
- if (value.startsWith("-")) {
326
- throw new RuntimeError("INVALID_ARGS", `${token} value cannot start with '-'; pass a model name`, "args.parse");
327
- }
328
- model = value;
329
- index += 1;
361
+ case "--model":
362
+ model = readModel(token, argv[++index], "args.parse");
330
363
  break;
331
- }
332
364
  case "--background":
333
365
  background = true;
334
366
  break;
@@ -338,13 +370,23 @@ export function parseAskArgs(argv) {
338
370
  case "--fresh":
339
371
  fresh = true;
340
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;
341
383
  case "-r":
342
384
  resume = true;
343
385
  break;
344
386
  case "--resume": {
345
387
  const value = argv[index + 1];
346
388
  if (!value || value.startsWith("-")) {
347
- throw new RuntimeError("INVALID_ARGS", "--resume requires a job-id or session-id. Use -r to resume the latest ask session for this repo.", "ask.parse");
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`);
348
390
  }
349
391
  resume = true;
350
392
  resumeTarget = value;
@@ -354,7 +396,7 @@ export function parseAskArgs(argv) {
354
396
  }
355
397
  default:
356
398
  if (looksLikeFlag(token)) {
357
- throw new RuntimeError("INVALID_ARGS", `Unknown flag ${token} for ask. Supported flags: ${ASK_SUPPORTED_FLAGS}. Use \`--\` before flag-shaped prompt text to pass it through.`, "args.parse");
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");
358
400
  }
359
401
  trailingTokens = argv.slice(index);
360
402
  index = argv.length;
@@ -362,10 +404,10 @@ export function parseAskArgs(argv) {
362
404
  }
363
405
  }
364
406
  if (fresh && resume) {
365
- throw new RuntimeError("INVALID_ARGS", "ask does not allow --fresh and --resume together.", "ask.parse");
407
+ throw new RuntimeError("INVALID_ARGS", `${kind} does not allow --fresh and --resume together.`, `${kind}.parse`);
366
408
  }
367
409
  if (explicitResumeTarget && trailingTokens?.length) {
368
- throw new RuntimeError("INVALID_ARGS", "--resume only accepts a job-id or session-id. Use -r to resume the latest ask session with a prompt.", "ask.parse");
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`);
369
411
  }
370
412
  return {
371
413
  budgetMs,
@@ -376,11 +418,12 @@ export function parseAskArgs(argv) {
376
418
  resumeTarget,
377
419
  model,
378
420
  thinkingEffort,
421
+ ...scopeFields(readRoots, network),
379
422
  prompt: trailingTokens?.join(" "),
380
423
  };
381
424
  }
382
425
  export function parseReviewArgs(argv, commandName = "review") {
383
- const parsed = parseKnownFlags(argv, new Set(["--budget", "--base", "--background", "--wait", "-m", "--model"]), commandName);
426
+ const parsed = parseKnownFlags(argv, new Set(["--budget", "--base", "--background", "--wait", "-m", "--model", "--read-root", "--network"]), commandName);
384
427
  return {
385
428
  budgetMs: parsed.budgetMs,
386
429
  base: parsed.base,
@@ -388,112 +431,10 @@ export function parseReviewArgs(argv, commandName = "review") {
388
431
  wait: parsed.wait,
389
432
  model: parsed.model,
390
433
  thinkingEffort: parsed.thinkingEffort,
434
+ ...scopeFields(parsed.readRoots, parsed.network),
391
435
  focus: parsed.trailingText,
392
436
  };
393
437
  }
394
- export function parseRescueArgs(argv) {
395
- if (hasHelpFlag(argv))
396
- return { help: true, background: false, wait: false, fresh: false, resume: false };
397
- let budgetMs;
398
- let model;
399
- let thinkingEffort;
400
- let background = false;
401
- let wait = false;
402
- let fresh = false;
403
- let resume = false;
404
- let resumeTarget;
405
- let explicitResumeTarget = false;
406
- let trailingTokens;
407
- for (let index = 0; index < argv.length; index += 1) {
408
- const token = argv[index];
409
- if (token === "--thinking" || token.startsWith("--thinking=")) {
410
- thinkingEffort = validateThinkingEffort(token === "--thinking" ? argv[++index] : token.slice("--thinking=".length));
411
- continue;
412
- }
413
- if (token === "--no-thinking" || token.startsWith("--no-thinking=")) {
414
- throw new RuntimeError("INVALID_ARGS", "--no-thinking is unsupported; use --thinking off", "args.parse");
415
- }
416
- if (token === "--") {
417
- trailingTokens = argv.slice(index + 1);
418
- break;
419
- }
420
- if (!token.startsWith("-")) {
421
- trailingTokens = argv.slice(index);
422
- break;
423
- }
424
- switch (token) {
425
- case "--budget": {
426
- const value = argv[index + 1];
427
- if (!value || value.startsWith("-")) {
428
- throw new RuntimeError("INVALID_ARGS", "--budget requires a duration (e.g. 30m, 1h, 90s).", "rescue.parse");
429
- }
430
- budgetMs = parseDurationMs(value, "--budget", "rescue.parse", "response");
431
- index += 1;
432
- break;
433
- }
434
- case "-m":
435
- case "--model": {
436
- const value = argv[index + 1];
437
- if (!value) {
438
- throw new RuntimeError("INVALID_ARGS", `${token} requires a model value.`, "args.parse");
439
- }
440
- if (value.startsWith("-")) {
441
- throw new RuntimeError("INVALID_ARGS", `${token} value cannot start with '-'; pass a model name`, "args.parse");
442
- }
443
- model = value;
444
- index += 1;
445
- break;
446
- }
447
- case "--background":
448
- background = true;
449
- break;
450
- case "--wait":
451
- wait = true;
452
- break;
453
- case "--fresh":
454
- fresh = true;
455
- break;
456
- case "-r":
457
- resume = true;
458
- break;
459
- case "--resume": {
460
- const value = argv[index + 1];
461
- if (!value || value.startsWith("-")) {
462
- throw new RuntimeError("INVALID_ARGS", "--resume requires a job-id or session-id. Use -r to resume the latest rescue session for this repo.", "rescue.parse");
463
- }
464
- resume = true;
465
- resumeTarget = value;
466
- explicitResumeTarget = true;
467
- index += 1;
468
- break;
469
- }
470
- default:
471
- if (looksLikeFlag(token)) {
472
- throw new RuntimeError("INVALID_ARGS", `Unknown flag ${token} for rescue. Supported flags: ${RESCUE_SUPPORTED_FLAGS}. Use \`--\` before flag-shaped prompt text to pass it through.`, "args.parse");
473
- }
474
- trailingTokens = argv.slice(index);
475
- index = argv.length;
476
- break;
477
- }
478
- }
479
- if (fresh && resume) {
480
- throw new RuntimeError("INVALID_ARGS", "rescue does not allow --fresh and --resume together.", "rescue.parse");
481
- }
482
- if (explicitResumeTarget && trailingTokens?.length) {
483
- throw new RuntimeError("INVALID_ARGS", "--resume only accepts a job-id or session-id. Use -r to resume the latest rescue session with a prompt.", "rescue.parse");
484
- }
485
- return {
486
- budgetMs,
487
- background,
488
- wait,
489
- fresh,
490
- resume,
491
- resumeTarget,
492
- model,
493
- thinkingEffort,
494
- prompt: trailingTokens?.join(" "),
495
- };
496
- }
497
438
  export function parseJobLookupArgs(argv) {
498
439
  let type;
499
440
  let jobId;
@@ -541,16 +482,16 @@ function parseKnownFlags(argv, knownFlags, commandName) {
541
482
  let base;
542
483
  let background = false;
543
484
  let wait = false;
485
+ const readRoots = [];
486
+ let network = false;
544
487
  let trailingTokens;
545
488
  for (let index = 0; index < argv.length; index += 1) {
546
489
  const token = argv[index];
547
- if (token === "--thinking" || token.startsWith("--thinking=")) {
548
- thinkingEffort = validateThinkingEffort(token === "--thinking" ? argv[++index] : token.slice("--thinking=".length));
490
+ const thinking = readThinkingFlag(argv, index);
491
+ if (thinking) {
492
+ [thinkingEffort, index] = thinking;
549
493
  continue;
550
494
  }
551
- if (token === "--no-thinking" || token.startsWith("--no-thinking=")) {
552
- throw new RuntimeError("INVALID_ARGS", "--no-thinking is unsupported; use --thinking off", "args.parse");
553
- }
554
495
  if (token === "--") {
555
496
  trailingTokens = argv.slice(index + 1);
556
497
  break;
@@ -563,28 +504,13 @@ function parseKnownFlags(argv, knownFlags, commandName) {
563
504
  break;
564
505
  }
565
506
  switch (token) {
566
- case "--budget": {
567
- const value = argv[index + 1];
568
- if (!value || value.startsWith("-")) {
569
- throw new RuntimeError("INVALID_ARGS", "--budget requires a duration (e.g. 30m, 1h, 90s).", `${commandName}.parse`);
570
- }
571
- budgetMs = parseDurationMs(value, "--budget", `${commandName}.parse`, "response");
572
- index += 1;
507
+ case "--budget":
508
+ budgetMs = readBudget(argv[++index], `${commandName}.parse`, "response");
573
509
  break;
574
- }
575
510
  case "-m":
576
- case "--model": {
577
- const value = argv[index + 1];
578
- if (!value) {
579
- throw new RuntimeError("INVALID_ARGS", `${token} requires a model value.`, "args.parse");
580
- }
581
- if (value.startsWith("-")) {
582
- throw new RuntimeError("INVALID_ARGS", `${token} value cannot start with '-'; pass a model name`, "args.parse");
583
- }
584
- model = value;
585
- index += 1;
511
+ case "--model":
512
+ model = readModel(token, argv[++index], "args.parse");
586
513
  break;
587
- }
588
514
  case "--base": {
589
515
  const value = argv[index + 1];
590
516
  if (!value) {
@@ -603,6 +529,12 @@ function parseKnownFlags(argv, knownFlags, commandName) {
603
529
  case "--wait":
604
530
  wait = true;
605
531
  break;
532
+ case "--read-root":
533
+ readRoots.push(readRootValue(argv[++index], `${commandName}.parse`));
534
+ break;
535
+ case "--network":
536
+ network = true;
537
+ break;
606
538
  // The early `if (!knownFlags.has(token))` gate above means we only
607
539
  // reach this switch with tokens that ARE in knownFlags, and every
608
540
  // member is handled above. A `default` arm would be unreachable.
@@ -613,6 +545,8 @@ function parseKnownFlags(argv, knownFlags, commandName) {
613
545
  base,
614
546
  background,
615
547
  wait,
548
+ readRoots,
549
+ network,
616
550
  model,
617
551
  thinkingEffort,
618
552
  trailingText: trailingTokens?.join(" "),
package/dist/paths.js CHANGED
@@ -15,6 +15,14 @@ export function resolvePluginPaths(env) {
15
15
  configPath: path.join(pluginRoot, "config.json"),
16
16
  };
17
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
+ }
18
26
  export async function ensurePluginPaths(paths) {
19
27
  await mkdir(paths.pluginRoot, { recursive: true });
20
28
  await mkdir(paths.logsDir, { recursive: true });