kimi-plugin-cc 2.7.3 → 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.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +3 -16
- package/README.md +428 -515
- package/assets/logo.svg +6 -0
- package/cordis.patch.yml +18 -0
- package/dist/background-spawn.js +14 -19
- package/dist/cli-client.js +163 -105
- package/dist/commands/ask.js +44 -96
- package/dist/commands/cancel.js +11 -59
- package/dist/commands/cli-helpers.js +102 -1
- package/dist/commands/models.js +2 -3
- package/dist/commands/pursue.js +8 -21
- package/dist/commands/registry.js +7 -26
- package/dist/commands/repair-sessions.js +121 -12
- package/dist/commands/replay.js +4 -3
- package/dist/commands/rescue.js +29 -87
- package/dist/commands/result.js +7 -1
- package/dist/commands/review.js +28 -18
- package/dist/commands/setup.js +813 -462
- package/dist/commands/status.js +2 -2
- package/dist/commands/swarm.js +112 -125
- package/dist/commands/worker.js +1 -2
- package/dist/companion.js +145 -19
- package/dist/git.js +1 -9
- package/dist/help.js +13 -9
- package/dist/hook-escape.js +7 -16
- package/dist/hooks/approval-hook.js +1766 -87
- package/dist/hooks/approval-policy.js +86 -19
- package/dist/hooks/config-safety.js +31 -64
- package/dist/hooks/hook-timing.js +48 -0
- package/dist/hooks/install-paths.js +179 -107
- package/dist/hooks/install.js +126 -53
- package/dist/hooks/managed-block.js +121 -127
- package/dist/job-store.js +206 -166
- package/dist/jobs.js +66 -19
- package/dist/kimi-command.js +74 -1
- package/dist/kimi-engine.js +198 -127
- package/dist/kimi-errors.js +15 -70
- package/dist/kimi-home.js +6 -0
- package/dist/kimi-journal.js +42 -0
- package/dist/kimi-releases.js +123 -0
- package/dist/kimi-timeouts.js +2 -16
- package/dist/kimi-version-probe.js +24 -108
- package/dist/logging.js +12 -7
- package/dist/mcp/binding.js +13 -4
- package/dist/mcp/job-control.js +390 -95
- package/dist/mcp/launcher.js +13 -7
- package/dist/mcp/operations.js +405 -179
- package/dist/mcp/protocol.js +124 -33
- package/dist/mcp/skills.js +130 -0
- package/dist/mcp/stdio.js +18 -4
- package/dist/model-command.js +5 -3
- package/dist/native-v2-preflight.js +243 -80
- package/dist/parsing.js +211 -243
- package/dist/paths.js +28 -10
- package/dist/plugin-data.js +28 -83
- package/dist/process-tree.js +35 -24
- package/dist/read-scope.js +435 -0
- package/dist/render.js +58 -46
- package/dist/rescue-approval.js +461 -84
- package/dist/session-references.js +216 -0
- package/dist/session-title.js +26 -6
- package/dist/stream-json.js +1 -3
- package/dist/surface-routing.js +108 -0
- package/dist/swarm-activation.js +74 -188
- package/dist/swarm-policy.js +2 -1
- package/dist/swarm-recovery.js +2 -1
- package/dist/util.js +28 -0
- package/dist/version.js +1 -1
- package/docs/migration.md +45 -206
- package/docs/models.md +24 -66
- package/docs/safety.md +198 -353
- package/docs/session-visibility.md +25 -13
- package/docs/swarm-recovery.md +26 -20
- package/dsh/index.json +54 -0
- package/mcp_config.json +10 -0
- package/package.json +23 -82
- package/plugin.json +19 -0
- package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
- package/plugins/kimi-codex/.mcp.json +3 -3
- package/plugins/kimi-codex/dist/background-spawn.js +14 -19
- package/plugins/kimi-codex/dist/cli-client.js +163 -105
- package/plugins/kimi-codex/dist/commands/ask.js +44 -96
- package/plugins/kimi-codex/dist/commands/cancel.js +11 -59
- package/plugins/kimi-codex/dist/commands/cli-helpers.js +102 -1
- package/plugins/kimi-codex/dist/commands/models.js +2 -3
- package/plugins/kimi-codex/dist/commands/pursue.js +8 -21
- package/plugins/kimi-codex/dist/commands/registry.js +7 -26
- package/plugins/kimi-codex/dist/commands/repair-sessions.js +121 -12
- package/plugins/kimi-codex/dist/commands/replay.js +4 -3
- package/plugins/kimi-codex/dist/commands/rescue.js +29 -87
- package/plugins/kimi-codex/dist/commands/result.js +7 -1
- package/plugins/kimi-codex/dist/commands/review.js +28 -18
- package/plugins/kimi-codex/dist/commands/setup.js +813 -462
- package/plugins/kimi-codex/dist/commands/status.js +2 -2
- package/plugins/kimi-codex/dist/commands/swarm.js +112 -125
- package/plugins/kimi-codex/dist/commands/worker.js +1 -2
- package/plugins/kimi-codex/dist/companion.js +145 -19
- package/plugins/kimi-codex/dist/git.js +1 -9
- package/plugins/kimi-codex/dist/help.js +13 -9
- package/plugins/kimi-codex/dist/hook-escape.js +7 -16
- package/plugins/kimi-codex/dist/hooks/approval-hook.js +1766 -87
- package/plugins/kimi-codex/dist/hooks/approval-policy.js +86 -19
- package/plugins/kimi-codex/dist/hooks/config-safety.js +31 -64
- package/plugins/kimi-codex/dist/hooks/hook-timing.js +48 -0
- package/plugins/kimi-codex/dist/hooks/install-paths.js +179 -107
- package/plugins/kimi-codex/dist/hooks/install.js +126 -53
- package/plugins/kimi-codex/dist/hooks/managed-block.js +121 -127
- package/plugins/kimi-codex/dist/job-store.js +206 -166
- package/plugins/kimi-codex/dist/jobs.js +66 -19
- package/plugins/kimi-codex/dist/kimi-command.js +74 -1
- package/plugins/kimi-codex/dist/kimi-engine.js +198 -127
- package/plugins/kimi-codex/dist/kimi-errors.js +15 -70
- package/plugins/kimi-codex/dist/kimi-home.js +6 -0
- package/plugins/kimi-codex/dist/kimi-journal.js +42 -0
- package/plugins/kimi-codex/dist/kimi-releases.js +123 -0
- package/plugins/kimi-codex/dist/kimi-timeouts.js +2 -16
- package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -108
- package/plugins/kimi-codex/dist/logging.js +12 -7
- package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
- package/plugins/kimi-codex/dist/mcp/job-control.js +390 -95
- package/plugins/kimi-codex/dist/mcp/launcher.js +13 -7
- package/plugins/kimi-codex/dist/mcp/operations.js +405 -179
- package/plugins/kimi-codex/dist/mcp/protocol.js +124 -33
- package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
- package/plugins/kimi-codex/dist/mcp/stdio.js +18 -4
- package/plugins/kimi-codex/dist/model-command.js +5 -3
- package/plugins/kimi-codex/dist/native-v2-preflight.js +243 -80
- package/plugins/kimi-codex/dist/parsing.js +211 -243
- package/plugins/kimi-codex/dist/paths.js +28 -10
- package/plugins/kimi-codex/dist/plugin-data.js +28 -83
- package/plugins/kimi-codex/dist/process-tree.js +35 -24
- package/plugins/kimi-codex/dist/read-scope.js +435 -0
- package/plugins/kimi-codex/dist/render.js +58 -46
- package/plugins/kimi-codex/dist/rescue-approval.js +461 -84
- package/plugins/kimi-codex/dist/session-references.js +216 -0
- package/plugins/kimi-codex/dist/session-title.js +26 -6
- package/plugins/kimi-codex/dist/stream-json.js +1 -3
- package/plugins/kimi-codex/dist/surface-routing.js +108 -0
- package/plugins/kimi-codex/dist/swarm-activation.js +74 -188
- package/plugins/kimi-codex/dist/swarm-policy.js +2 -1
- package/plugins/kimi-codex/dist/swarm-recovery.js +2 -1
- package/plugins/kimi-codex/dist/util.js +28 -0
- package/plugins/kimi-codex/dist/version.js +1 -1
- package/plugins/kimi-codex/scripts/companion.sh +4 -15
- package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
- package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
- package/scripts/companion.sh +4 -15
- package/skills/kimi/SKILL.md +77 -0
- package/skills/kimi/agents/openai.yaml +6 -0
- package/CHANGELOG.md +0 -1333
- package/agents/kimi-ask.md +0 -89
- package/agents/kimi-challenge.md +0 -86
- package/agents/kimi-pursue.md +0 -93
- package/agents/kimi-rescue.md +0 -92
- package/agents/kimi-review.md +0 -86
- package/agents/kimi-swarm-write.md +0 -96
- package/agents/kimi-swarm.md +0 -86
- package/commands/README.md +0 -16
- package/commands/ask.md +0 -38
- package/commands/cancel.md +0 -17
- package/commands/challenge.md +0 -35
- package/commands/pursue.md +0 -41
- package/commands/replay.md +0 -13
- package/commands/rescue.md +0 -38
- package/commands/result.md +0 -13
- package/commands/review.md +0 -35
- package/commands/setup.md +0 -23
- package/commands/status.md +0 -13
- package/commands/swarm.md +0 -44
- package/dist/commands/not-implemented.js +0 -4
- package/dist/commands/review-gate.js +0 -390
- package/dist/config.js +0 -22
- package/dist/dsh/companion.js +0 -177
- package/dist/dsh/index.js +0 -169
- package/dist/hooks/review-gate-stop.js +0 -19
- package/dist/schemas/review-gate-output.js +0 -43
- package/docs/registry-releases.md +0 -228
- package/docs/upstream-2.4.1-certification.md +0 -54
- package/docs/upstream-2.5.0-certification.md +0 -52
- package/docs/upstream-2.5.1-certification.md +0 -47
- package/docs/upstream-2.5.2-certification.md +0 -40
- package/docs/upstream-2.5.3-certification.md +0 -73
- package/docs/upstream-2.6.0-certification.md +0 -65
- package/docs/upstream-2.6.2-certification.md +0 -144
- package/docs/upstream-2.6.3-certification.md +0 -100
- package/docs/upstream-2.7.2-certification.md +0 -113
- package/docs/upstream-2.7.3-certification.md +0 -83
- package/docs/windows-validation.md +0 -39
- package/hooks/README.md +0 -9
- package/hooks/hooks.json +0 -16
- package/plugins/kimi-codex/dist/commands/not-implemented.js +0 -4
- package/plugins/kimi-codex/dist/commands/review-gate.js +0 -390
- package/plugins/kimi-codex/dist/config.js +0 -22
- package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
- package/plugins/kimi-codex/dist/dsh/index.js +0 -169
- package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -43
- package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
- package/plugins/kimi-codex/skills/kimi-ask/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-ask/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-challenge/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
- package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-rescue/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +0 -36
- package/plugins/kimi-codex/skills/kimi-swarm-write/agents/openai.yaml +0 -6
- package/plugins/kimi-dsh/LICENSE +0 -201
- package/plugins/kimi-dsh/README.md +0 -83
- package/plugins/kimi-dsh/cordis.patch.yml +0 -45
- package/plugins/kimi-dsh/dist/background-spawn.js +0 -216
- package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
- package/plugins/kimi-dsh/dist/cli-client.js +0 -1078
- package/plugins/kimi-dsh/dist/commands/ask.js +0 -336
- package/plugins/kimi-dsh/dist/commands/cancel.js +0 -216
- package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -201
- package/plugins/kimi-dsh/dist/commands/models.js +0 -140
- package/plugins/kimi-dsh/dist/commands/not-implemented.js +0 -4
- package/plugins/kimi-dsh/dist/commands/pursue.js +0 -307
- package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
- package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
- package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -160
- package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
- package/plugins/kimi-dsh/dist/commands/rescue.js +0 -347
- package/plugins/kimi-dsh/dist/commands/result.js +0 -66
- package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -390
- package/plugins/kimi-dsh/dist/commands/review.js +0 -220
- package/plugins/kimi-dsh/dist/commands/setup.js +0 -1129
- package/plugins/kimi-dsh/dist/commands/status.js +0 -27
- package/plugins/kimi-dsh/dist/commands/swarm.js +0 -849
- package/plugins/kimi-dsh/dist/commands/worker.js +0 -25
- package/plugins/kimi-dsh/dist/companion.js +0 -97
- package/plugins/kimi-dsh/dist/config.js +0 -22
- package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
- package/plugins/kimi-dsh/dist/dsh/index.js +0 -169
- package/plugins/kimi-dsh/dist/errors.js +0 -40
- package/plugins/kimi-dsh/dist/git.js +0 -224
- package/plugins/kimi-dsh/dist/help.js +0 -43
- package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
- package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -104
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -233
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -665
- package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
- package/plugins/kimi-dsh/dist/hooks/install.js +0 -210
- package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -684
- package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-dsh/dist/job-id.js +0 -12
- package/plugins/kimi-dsh/dist/job-store.js +0 -659
- package/plugins/kimi-dsh/dist/jobs.js +0 -217
- package/plugins/kimi-dsh/dist/kimi-command.js +0 -71
- package/plugins/kimi-dsh/dist/kimi-engine.js +0 -675
- package/plugins/kimi-dsh/dist/kimi-errors.js +0 -260
- package/plugins/kimi-dsh/dist/kimi-home.js +0 -9
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
- package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -234
- package/plugins/kimi-dsh/dist/logging.js +0 -22
- package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
- package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -345
- package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -257
- package/plugins/kimi-dsh/dist/mcp/operations.js +0 -301
- package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -275
- package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
- package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -78
- package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
- package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
- package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
- package/plugins/kimi-dsh/dist/model-command.js +0 -32
- package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -525
- package/plugins/kimi-dsh/dist/package.json +0 -1
- package/plugins/kimi-dsh/dist/parsing.js +0 -620
- package/plugins/kimi-dsh/dist/paths.js +0 -27
- package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
- package/plugins/kimi-dsh/dist/process-tree.js +0 -586
- package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
- package/plugins/kimi-dsh/dist/render.js +0 -177
- package/plugins/kimi-dsh/dist/rescue-approval.js +0 -865
- package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -43
- package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
- package/plugins/kimi-dsh/dist/session-title.js +0 -293
- package/plugins/kimi-dsh/dist/stream-json.js +0 -346
- package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1197
- package/plugins/kimi-dsh/dist/swarm-policy.js +0 -73
- package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -165
- package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
- package/plugins/kimi-dsh/dist/types.js +0 -1
- package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
- package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
- package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
- package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
- package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
- package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
- package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
- package/plugins/kimi-dsh/dist/version.js +0 -7
- package/plugins/kimi-dsh/package.json +0 -78
- package/plugins/kimi-dsh/scripts/companion.sh +0 -37
- package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
- package/scripts/review-gate-hook.sh +0 -32
|
@@ -1,242 +1,430 @@
|
|
|
1
1
|
import { RuntimeError } from "../errors.js";
|
|
2
|
-
import {
|
|
2
|
+
import { kimiVersionsWith } from "../kimi-releases.js";
|
|
3
|
+
import { MAX_SESSION_REFERENCES, parseDurationMs, SESSION_REFERENCE_ID_MAX, validateThinkingEffort } from "../parsing.js";
|
|
4
|
+
const DEFAULT_WAIT_TIMEOUT_MIN_MS = 1_000;
|
|
5
|
+
const MAX_WAIT_TIMEOUT_MS = 86_400_000;
|
|
3
6
|
const WORKSPACE_PROPERTY = {
|
|
4
7
|
type: "string",
|
|
5
|
-
description: "Absolute workspace directory. Required when the host does not configure a default
|
|
8
|
+
description: "Absolute workspace directory. Required when the host does not configure a default.",
|
|
6
9
|
};
|
|
7
10
|
const MODEL_PROPERTY = {
|
|
8
11
|
type: "string",
|
|
9
|
-
description: "
|
|
12
|
+
description: "Configured Kimi model alias. Omit to use the default model; never guess an alias.",
|
|
10
13
|
};
|
|
11
14
|
const THINKING_PROPERTY = {
|
|
12
15
|
type: "string",
|
|
13
|
-
description: "Per-run thinking-effort request
|
|
16
|
+
description: "Per-run thinking-effort request (off, low, medium, high). Not observable on the wire.",
|
|
14
17
|
};
|
|
15
18
|
const BUDGET_PROPERTY = {
|
|
16
19
|
type: "string",
|
|
17
|
-
description: "Finite duration such as 30m, 1h, or 90s; bare numbers mean minutes. Maximum 24h.
|
|
20
|
+
description: "Finite duration such as 30m, 1h, or 90s; bare numbers mean minutes. Maximum 24h.",
|
|
21
|
+
};
|
|
22
|
+
const WAIT_PROPERTIES = {
|
|
23
|
+
wait: {
|
|
24
|
+
type: "boolean",
|
|
25
|
+
description: "Wait for completion and return the result directly (default true on standard calls; set false to get job_id immediately for parallel fan-out).",
|
|
26
|
+
},
|
|
27
|
+
wait_timeout_ms: {
|
|
28
|
+
type: "integer",
|
|
29
|
+
minimum: DEFAULT_WAIT_TIMEOUT_MIN_MS,
|
|
30
|
+
maximum: MAX_WAIT_TIMEOUT_MS,
|
|
31
|
+
description: "Maximum milliseconds this call waits before returning a running handle (job keeps running in background; poll with kimi_job).",
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const REFERENCE_PROPERTIES = {
|
|
35
|
+
referenced_sessions: {
|
|
36
|
+
type: "array",
|
|
37
|
+
items: { type: "string" },
|
|
38
|
+
description: "Up to 8 earlier job IDs or Kimi session IDs whose main logs Kimi may consult.",
|
|
39
|
+
},
|
|
18
40
|
};
|
|
19
41
|
const COMMON_PROPERTIES = {
|
|
20
42
|
workspace: WORKSPACE_PROPERTY,
|
|
21
43
|
model: MODEL_PROPERTY,
|
|
22
44
|
thinking: THINKING_PROPERTY,
|
|
23
45
|
budget: BUDGET_PROPERTY,
|
|
46
|
+
...WAIT_PROPERTIES,
|
|
24
47
|
};
|
|
25
|
-
const
|
|
26
|
-
|
|
48
|
+
const READ_SCHEMA = schema({
|
|
49
|
+
mode: {
|
|
50
|
+
type: "string",
|
|
51
|
+
enum: ["ask", "review", "challenge", "swarm"],
|
|
52
|
+
description: "ask (default): explain/investigate; review: defect review of diff; challenge: adversarial design critique; swarm: read-only parallel fan-out.",
|
|
53
|
+
},
|
|
54
|
+
prompt: {
|
|
55
|
+
type: "string",
|
|
56
|
+
description: "User question, review focus, or swarm objective, preserved verbatim. Required for ask (unless resume is set) and swarm.",
|
|
57
|
+
},
|
|
58
|
+
...COMMON_PROPERTIES,
|
|
59
|
+
base: {
|
|
60
|
+
type: "string",
|
|
61
|
+
description: "Git base ref for review/challenge (committed branch diff; incompatible with uncommitted=true).",
|
|
62
|
+
},
|
|
63
|
+
uncommitted: {
|
|
27
64
|
type: "boolean",
|
|
28
|
-
description: "
|
|
65
|
+
description: "Review uncommitted/untracked working-tree changes (default for review/challenge; incompatible with base).",
|
|
29
66
|
},
|
|
30
67
|
resume: {
|
|
31
68
|
type: "string",
|
|
32
|
-
description: "Resume
|
|
69
|
+
description: "Resume session for ask: \"last\" (latest repo session, may pair with prompt) or a job/session ID (no prompt).",
|
|
70
|
+
},
|
|
71
|
+
read_roots: {
|
|
72
|
+
type: "array",
|
|
73
|
+
items: { type: "string" },
|
|
74
|
+
description: "Additional absolute directories Kimi may read outside workspace.",
|
|
33
75
|
},
|
|
34
|
-
|
|
76
|
+
network: {
|
|
35
77
|
type: "boolean",
|
|
36
|
-
description: "
|
|
78
|
+
description: "Enable web search and URL fetch (file reads remain confined to workspace + read_roots). Default false.",
|
|
37
79
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const OBJECTIVE_PROPERTY = {
|
|
44
|
-
type: "string",
|
|
45
|
-
description: "The complete objective, preserved verbatim.",
|
|
46
|
-
};
|
|
47
|
-
const FOCUS_PROPERTY = {
|
|
48
|
-
type: "string",
|
|
49
|
-
description: "Optional review focus or adversarial framing, preserved verbatim.",
|
|
50
|
-
};
|
|
51
|
-
const BASE_PROPERTY = {
|
|
52
|
-
type: "string",
|
|
53
|
-
description: "Optional Git base ref. The committed branch diff is authoritative; dirty current files are not treated as committed snapshots.",
|
|
54
|
-
};
|
|
55
|
-
const TURNS_PROPERTY = {
|
|
56
|
-
type: "integer",
|
|
57
|
-
minimum: 1,
|
|
58
|
-
description: "Soft turn-count hint included in the objective. The finite budget is the hard bound.",
|
|
59
|
-
};
|
|
60
|
-
const CAP_PROPERTY = {
|
|
61
|
-
type: "integer",
|
|
62
|
-
minimum: 1,
|
|
63
|
-
description: "Soft hint for total subagent count, not a hook-enforced limit.",
|
|
64
|
-
};
|
|
65
|
-
const MAX_CONCURRENCY_PROPERTY = {
|
|
66
|
-
type: "integer",
|
|
67
|
-
minimum: 1,
|
|
68
|
-
description: "Concurrent worker limit on exact Kimi Code 2.6.2/2.6.3/2.7.2/2.7.3: one runs directly; larger values bound each native swarm wave. Older certified versions limit normal launches only and recovery can exceed it. Distinct from the soft total cap.",
|
|
69
|
-
};
|
|
70
|
-
const START_RESULT_GUIDANCE = "Task-capable clients receive an MCP task. Other clients receive a job ID immediately after launch; use kimi_job_status and kimi_job_result until terminal, and kimi_job_cancel to stop. Do not present a launch handle as the finished answer.";
|
|
71
|
-
function schema(properties, required = []) {
|
|
72
|
-
return { type: "object", properties, required, additionalProperties: false };
|
|
73
|
-
}
|
|
74
|
-
const OPERATION_SPECS = {
|
|
75
|
-
kimi_ask: {
|
|
76
|
-
kind: "ask",
|
|
77
|
-
command: ["ask"],
|
|
78
|
-
write: false,
|
|
79
|
-
summary: "Start an independent read-only Kimi repository explanation.",
|
|
80
|
-
inputSchema: schema({ ...COMMON_PROPERTIES, prompt: PROMPT_PROPERTY, ...RESUME_PROPERTIES }),
|
|
80
|
+
cap: {
|
|
81
|
+
type: "integer",
|
|
82
|
+
minimum: 1,
|
|
83
|
+
maximum: 25,
|
|
84
|
+
description: "Soft hint for total swarm subagent count.",
|
|
81
85
|
},
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
inputSchema: schema({ ...COMMON_PROPERTIES, base: BASE_PROPERTY, focus: FOCUS_PROPERTY }),
|
|
86
|
+
max_concurrency: {
|
|
87
|
+
type: "integer",
|
|
88
|
+
minimum: 1,
|
|
89
|
+
maximum: 16,
|
|
90
|
+
description: `Maximum simultaneous swarm workers on Kimi Code ${kimiVersionsWith("bounded-swarm").join("/")}+ (1 runs directly).`,
|
|
88
91
|
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
...REFERENCE_PROPERTIES,
|
|
93
|
+
});
|
|
94
|
+
const WRITE_SCHEMA = schema({
|
|
95
|
+
mode: {
|
|
96
|
+
type: "string",
|
|
97
|
+
enum: ["rescue", "pursue", "swarm_patch"],
|
|
98
|
+
description: "rescue (default): bounded workspace edit/fix; pursue: autonomous multi-turn goal; swarm_patch: parallel edits in isolated worktree returning a git patch without modifying the real tree.",
|
|
95
99
|
},
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
write: true,
|
|
100
|
-
summary: "Start a bounded write-capable Kimi investigation or fix inside the validated workspace. Review the resulting changes; no commit is made.",
|
|
101
|
-
inputSchema: schema({ ...COMMON_PROPERTIES, prompt: PROMPT_PROPERTY, ...RESUME_PROPERTIES }),
|
|
100
|
+
prompt: {
|
|
101
|
+
type: "string",
|
|
102
|
+
description: "Task objective or edit instruction, preserved verbatim. Never mutates Git.",
|
|
102
103
|
},
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
summary: "Start explicitly autonomous Kimi goal mode with a finite hard budget and workspace write limits. Use only for hands-off objectives, not a single bounded fix.",
|
|
108
|
-
inputSchema: schema({ ...COMMON_PROPERTIES, objective: OBJECTIVE_PROPERTY, turns: TURNS_PROPERTY }, ["objective"]),
|
|
104
|
+
...COMMON_PROPERTIES,
|
|
105
|
+
resume: {
|
|
106
|
+
type: "string",
|
|
107
|
+
description: "Resume session for rescue: \"last\" or a job/session ID.",
|
|
109
108
|
},
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
inputSchema: schema({ ...COMMON_PROPERTIES, objective: OBJECTIVE_PROPERTY, cap: CAP_PROPERTY, max_concurrency: MAX_CONCURRENCY_PROPERTY }, ["objective"]),
|
|
109
|
+
cap: {
|
|
110
|
+
type: "integer",
|
|
111
|
+
minimum: 1,
|
|
112
|
+
maximum: 25,
|
|
113
|
+
description: "Soft hint for total swarm_patch subagent count.",
|
|
116
114
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
max_concurrency: {
|
|
116
|
+
type: "integer",
|
|
117
|
+
minimum: 1,
|
|
118
|
+
maximum: 16,
|
|
119
|
+
description: "Maximum simultaneous swarm_patch workers (default 1 runs directly).",
|
|
120
|
+
},
|
|
121
|
+
...REFERENCE_PROPERTIES,
|
|
122
|
+
});
|
|
123
|
+
const JOB_SCHEMA = schema({
|
|
124
|
+
action: {
|
|
125
|
+
type: "string",
|
|
126
|
+
enum: ["list", "status", "result", "wait", "cancel", "replay", "recover_swarm"],
|
|
127
|
+
description: "Job lifecycle action to run in this workspace.",
|
|
128
|
+
},
|
|
129
|
+
job_id: {
|
|
130
|
+
type: "string",
|
|
131
|
+
description: "Job UUID. Required for replay and recover_swarm; optional for status/result/wait/cancel (defaults to latest repo job).",
|
|
123
132
|
},
|
|
124
|
-
};
|
|
125
|
-
const JOB_CONTROL_SCHEMA = schema({
|
|
126
133
|
workspace: WORKSPACE_PROPERTY,
|
|
127
|
-
|
|
128
|
-
|
|
134
|
+
status_filter: {
|
|
135
|
+
type: "string",
|
|
136
|
+
enum: ["running", "completed", "failed", "cancelled"],
|
|
137
|
+
description: "Filter jobs returned by action=list.",
|
|
138
|
+
},
|
|
139
|
+
limit: {
|
|
140
|
+
type: "integer",
|
|
141
|
+
minimum: 1,
|
|
142
|
+
maximum: 100,
|
|
143
|
+
description: "Maximum jobs to return for action=list (default 20).",
|
|
144
|
+
},
|
|
145
|
+
wait_ms: {
|
|
146
|
+
type: "integer",
|
|
147
|
+
minimum: 100,
|
|
148
|
+
maximum: 600_000,
|
|
149
|
+
description: "Poll duration in ms for action=wait (default 30000).",
|
|
150
|
+
},
|
|
151
|
+
apply: {
|
|
152
|
+
type: "boolean",
|
|
153
|
+
description: "Apply cleanup and patch capture during recover_swarm (default false previews only).",
|
|
154
|
+
},
|
|
155
|
+
}, ["action"]);
|
|
156
|
+
const SETUP_SCHEMA = schema({
|
|
157
|
+
action: {
|
|
158
|
+
type: "string",
|
|
159
|
+
enum: ["check", "models", "install", "install_kimi", "repair_sessions"],
|
|
160
|
+
description: "check (default): verify PreToolUse hook & binary; models: list configured model aliases; install: write/repair hook; install_kimi: install newest certified CLI; repair_sessions: preview/repair Kimi session titles.",
|
|
161
|
+
},
|
|
162
|
+
workspace: WORKSPACE_PROPERTY,
|
|
163
|
+
apply: {
|
|
164
|
+
type: "boolean",
|
|
165
|
+
description: "Write repaired session previews during repair_sessions (default false previews only).",
|
|
166
|
+
},
|
|
167
|
+
all: {
|
|
168
|
+
type: "boolean",
|
|
169
|
+
description: "Scope repair_sessions across all repositories.",
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
function schema(properties, required = []) {
|
|
173
|
+
return { type: "object", properties, required, additionalProperties: false };
|
|
174
|
+
}
|
|
129
175
|
export const MCP_TOOL_DEFINITIONS = [
|
|
130
|
-
|
|
131
|
-
name:
|
|
132
|
-
description:
|
|
133
|
-
inputSchema:
|
|
176
|
+
{
|
|
177
|
+
name: "kimi_read",
|
|
178
|
+
description: "Run a read-only Kimi operation (ask, review, challenge, or parallel read-only swarm). Waits for prose by default on standard tool calls; set wait=false to return job_id immediately.",
|
|
179
|
+
inputSchema: READ_SCHEMA,
|
|
134
180
|
annotations: {
|
|
135
|
-
title:
|
|
136
|
-
readOnlyHint:
|
|
137
|
-
destructiveHint:
|
|
181
|
+
title: "kimi read",
|
|
182
|
+
readOnlyHint: true,
|
|
183
|
+
destructiveHint: false,
|
|
138
184
|
idempotentHint: false,
|
|
139
185
|
openWorldHint: true,
|
|
140
186
|
},
|
|
141
|
-
}
|
|
187
|
+
},
|
|
142
188
|
{
|
|
143
|
-
name: "
|
|
144
|
-
description: "
|
|
145
|
-
inputSchema:
|
|
146
|
-
annotations: {
|
|
189
|
+
name: "kimi_write",
|
|
190
|
+
description: "Run a workspace-confined write operation: rescue (single-turn edit/test), pursue (autonomous multi-turn goal), or swarm_patch (isolated worktree producing a git patch without modifying the working tree).",
|
|
191
|
+
inputSchema: WRITE_SCHEMA,
|
|
192
|
+
annotations: {
|
|
193
|
+
title: "kimi write",
|
|
194
|
+
readOnlyHint: false,
|
|
195
|
+
destructiveHint: true,
|
|
196
|
+
idempotentHint: false,
|
|
197
|
+
openWorldHint: true,
|
|
198
|
+
},
|
|
147
199
|
},
|
|
148
200
|
{
|
|
149
|
-
name: "
|
|
150
|
-
description: "
|
|
151
|
-
inputSchema:
|
|
152
|
-
annotations: {
|
|
201
|
+
name: "kimi_job",
|
|
202
|
+
description: "Inspect, await, cancel, replay, or recover Kimi jobs in the workspace.",
|
|
203
|
+
inputSchema: JOB_SCHEMA,
|
|
204
|
+
annotations: {
|
|
205
|
+
title: "kimi job",
|
|
206
|
+
readOnlyHint: false,
|
|
207
|
+
destructiveHint: false,
|
|
208
|
+
idempotentHint: false,
|
|
209
|
+
openWorldHint: false,
|
|
210
|
+
},
|
|
153
211
|
},
|
|
154
212
|
{
|
|
155
|
-
name: "
|
|
156
|
-
description: "
|
|
157
|
-
inputSchema:
|
|
158
|
-
annotations: {
|
|
213
|
+
name: "kimi_setup",
|
|
214
|
+
description: "Verify or install the Kimi PreToolUse safety hook, list configured models, install a certified Kimi CLI binary, or repair session titles.",
|
|
215
|
+
inputSchema: SETUP_SCHEMA,
|
|
216
|
+
annotations: {
|
|
217
|
+
title: "kimi setup",
|
|
218
|
+
readOnlyHint: false,
|
|
219
|
+
destructiveHint: false,
|
|
220
|
+
idempotentHint: true,
|
|
221
|
+
openWorldHint: true,
|
|
222
|
+
},
|
|
159
223
|
},
|
|
160
224
|
];
|
|
161
225
|
export function isMcpModelToolName(name) {
|
|
162
|
-
return
|
|
226
|
+
return name === "kimi_read" || name === "kimi_write";
|
|
163
227
|
}
|
|
164
228
|
export function buildMcpOperationInvocation(name, input) {
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
const args = readArguments(input, Object.keys(properties));
|
|
229
|
+
const allowedKeys = Object.keys((name === "kimi_read" ? READ_SCHEMA : WRITE_SCHEMA).properties);
|
|
230
|
+
const args = readArguments(input, allowedKeys);
|
|
168
231
|
const workspace = optionalString(args, "workspace");
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
232
|
+
const wait = optionalBoolean(args, "wait") ?? true;
|
|
233
|
+
const waitTimeoutMs = optionalBoundedInteger(args, "wait_timeout_ms", DEFAULT_WAIT_TIMEOUT_MIN_MS, MAX_WAIT_TIMEOUT_MS);
|
|
234
|
+
if (name === "kimi_read") {
|
|
235
|
+
const mode = readMode(args);
|
|
236
|
+
const kind = mode;
|
|
237
|
+
const argv = mode === "ask" ? ["ask"] : mode === "review" ? ["review"] : ["task", mode];
|
|
238
|
+
appendCommonOptions(argv, args, mode === "swarm" ? "safety" : "response");
|
|
239
|
+
appendScopeOptions(argv, args);
|
|
240
|
+
appendReferenceOptions(argv, args);
|
|
241
|
+
const base = args.base === undefined ? undefined : requiredNonEmptyString(args, "base");
|
|
242
|
+
const uncommitted = optionalBoolean(args, "uncommitted");
|
|
243
|
+
const resume = args.resume === undefined ? undefined : requiredNonEmptyString(args, "resume");
|
|
244
|
+
const cap = optionalBoundedInteger(args, "cap", 1, 25);
|
|
245
|
+
const maxConcurrency = optionalBoundedInteger(args, "max_concurrency", 1, 16);
|
|
246
|
+
const prompt = optionalString(args, "prompt");
|
|
247
|
+
if (mode !== "review" && mode !== "challenge" && (base !== undefined || uncommitted !== undefined)) {
|
|
248
|
+
throw invalidArguments(`base and uncommitted are only valid for mode "review" or "challenge" (got ${mode}).`);
|
|
249
|
+
}
|
|
250
|
+
if (base !== undefined && uncommitted === true) {
|
|
251
|
+
throw invalidArguments("base and uncommitted=true are mutually exclusive.");
|
|
252
|
+
}
|
|
253
|
+
if ((mode === "review" || mode === "challenge") && uncommitted === false && base === undefined) {
|
|
254
|
+
throw invalidArguments('uncommitted=false requires a base ref for mode "review" or "challenge".');
|
|
255
|
+
}
|
|
256
|
+
if (mode !== "ask" && resume !== undefined) {
|
|
257
|
+
throw invalidArguments(`resume is only valid for mode "ask" (got ${mode}).`);
|
|
258
|
+
}
|
|
259
|
+
if (mode !== "swarm" && (cap !== undefined || maxConcurrency !== undefined)) {
|
|
260
|
+
throw invalidArguments(`cap and max_concurrency are only valid for mode "swarm" (got ${mode}).`);
|
|
261
|
+
}
|
|
262
|
+
switch (mode) {
|
|
263
|
+
case "ask": {
|
|
264
|
+
const cleanPrompt = prompt === undefined ? undefined : requiredNonEmptyString(args, "prompt");
|
|
265
|
+
if (resume === "last") {
|
|
266
|
+
argv.push("-r");
|
|
267
|
+
if (cleanPrompt !== undefined)
|
|
268
|
+
argv.push("--", cleanPrompt);
|
|
269
|
+
}
|
|
270
|
+
else if (resume !== undefined) {
|
|
271
|
+
if (cleanPrompt !== undefined) {
|
|
272
|
+
throw invalidArguments('resume with a job/session ID uses the continuation prompt and cannot include prompt; use resume="last" to pair with a new prompt.');
|
|
273
|
+
}
|
|
274
|
+
argv.push("--resume", resume);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
argv.push("--", requiredNonEmptyString(args, "prompt"));
|
|
278
|
+
}
|
|
279
|
+
break;
|
|
183
280
|
}
|
|
184
|
-
|
|
185
|
-
|
|
281
|
+
case "review":
|
|
282
|
+
case "challenge": {
|
|
283
|
+
if (base !== undefined)
|
|
284
|
+
argv.push("--base", base);
|
|
285
|
+
if (prompt !== undefined && prompt.trim().length > 0)
|
|
286
|
+
argv.push("--", prompt);
|
|
287
|
+
break;
|
|
186
288
|
}
|
|
187
|
-
|
|
188
|
-
|
|
289
|
+
case "swarm": {
|
|
290
|
+
if (cap !== undefined)
|
|
291
|
+
argv.push("--cap", String(cap));
|
|
292
|
+
if (maxConcurrency !== undefined)
|
|
293
|
+
argv.push("--max-concurrency", String(maxConcurrency));
|
|
294
|
+
argv.push("--", requiredNonEmptyString(args, "prompt"));
|
|
295
|
+
break;
|
|
189
296
|
}
|
|
190
|
-
if (fresh)
|
|
191
|
-
argv.push("--fresh");
|
|
192
|
-
if (resumeLatest)
|
|
193
|
-
argv.push("-r");
|
|
194
|
-
if (resume !== undefined)
|
|
195
|
-
argv.push("--resume", resume);
|
|
196
|
-
if (prompt !== undefined)
|
|
197
|
-
argv.push("--", prompt);
|
|
198
|
-
break;
|
|
199
297
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
298
|
+
return {
|
|
299
|
+
operationKind: kind,
|
|
300
|
+
...(workspace !== undefined ? { workspace } : {}),
|
|
301
|
+
wait,
|
|
302
|
+
...(waitTimeoutMs !== undefined ? { waitTimeoutMs } : {}),
|
|
303
|
+
argv,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
// kimi_write
|
|
307
|
+
const mode = writeMode(args);
|
|
308
|
+
const kind = mode === "swarm_patch" ? "swarm-write" : mode;
|
|
309
|
+
const argv = mode === "swarm_patch" ? ["task", "swarm"] : ["task", mode];
|
|
310
|
+
appendCommonOptions(argv, args, mode === "rescue" ? "response" : "safety");
|
|
311
|
+
const resume = args.resume === undefined ? undefined : requiredNonEmptyString(args, "resume");
|
|
312
|
+
const cap = optionalBoundedInteger(args, "cap", 1, 25);
|
|
313
|
+
const maxConcurrency = optionalBoundedInteger(args, "max_concurrency", 1, 16);
|
|
314
|
+
const prompt = optionalString(args, "prompt");
|
|
315
|
+
if (mode === "pursue" && args.referenced_sessions !== undefined) {
|
|
316
|
+
throw invalidArguments('referenced_sessions is not supported for mode "pursue".');
|
|
317
|
+
}
|
|
318
|
+
appendReferenceOptions(argv, args);
|
|
319
|
+
if (mode !== "rescue" && resume !== undefined) {
|
|
320
|
+
throw invalidArguments(`resume is only valid for mode "rescue" (got ${mode}).`);
|
|
321
|
+
}
|
|
322
|
+
if (mode !== "swarm_patch" && (cap !== undefined || maxConcurrency !== undefined)) {
|
|
323
|
+
throw invalidArguments(`cap and max_concurrency are only valid for mode "swarm_patch" (got ${mode}).`);
|
|
324
|
+
}
|
|
325
|
+
if (mode === "rescue") {
|
|
326
|
+
const cleanPrompt = prompt === undefined ? undefined : requiredNonEmptyString(args, "prompt");
|
|
327
|
+
if (resume === "last") {
|
|
328
|
+
argv.push("-r");
|
|
329
|
+
if (cleanPrompt !== undefined)
|
|
330
|
+
argv.push("--", cleanPrompt);
|
|
209
331
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
argv.push("--",
|
|
215
|
-
break;
|
|
332
|
+
else if (resume !== undefined) {
|
|
333
|
+
if (cleanPrompt !== undefined) {
|
|
334
|
+
throw invalidArguments('resume with a job/session ID cannot include prompt; use resume="last" to pair with a new prompt.');
|
|
335
|
+
}
|
|
336
|
+
argv.push("--resume", resume);
|
|
216
337
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const cap = optionalPositiveInteger(args, "cap");
|
|
220
|
-
const maxConcurrency = optionalPositiveInteger(args, "max_concurrency");
|
|
221
|
-
if (cap !== undefined)
|
|
222
|
-
argv.push("--cap", String(cap));
|
|
223
|
-
if (maxConcurrency !== undefined)
|
|
224
|
-
argv.push("--max-concurrency", String(maxConcurrency));
|
|
225
|
-
if (spec.kind === "swarm-write")
|
|
226
|
-
argv.push("--write");
|
|
227
|
-
argv.push("--", requiredNonEmptyString(args, "objective"));
|
|
228
|
-
break;
|
|
338
|
+
else {
|
|
339
|
+
argv.push("--fresh", "--", requiredNonEmptyString(args, "prompt"));
|
|
229
340
|
}
|
|
230
341
|
}
|
|
231
|
-
|
|
342
|
+
else if (mode === "pursue") {
|
|
343
|
+
argv.push("--", requiredNonEmptyString(args, "prompt"));
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
if (cap !== undefined)
|
|
347
|
+
argv.push("--cap", String(cap));
|
|
348
|
+
if (maxConcurrency !== undefined)
|
|
349
|
+
argv.push("--max-concurrency", String(maxConcurrency));
|
|
350
|
+
argv.push("--write", "--", requiredNonEmptyString(args, "prompt"));
|
|
351
|
+
}
|
|
352
|
+
return {
|
|
353
|
+
operationKind: kind,
|
|
354
|
+
...(workspace !== undefined ? { workspace } : {}),
|
|
355
|
+
wait,
|
|
356
|
+
...(waitTimeoutMs !== undefined ? { waitTimeoutMs } : {}),
|
|
357
|
+
argv,
|
|
358
|
+
};
|
|
232
359
|
}
|
|
233
360
|
export function readJobControlArguments(input) {
|
|
234
|
-
const args = readArguments(input,
|
|
361
|
+
const args = readArguments(input, Object.keys(JOB_SCHEMA.properties));
|
|
362
|
+
const action = requiredEnum(args, "action", ["list", "status", "result", "wait", "cancel", "replay", "recover_swarm"]);
|
|
363
|
+
const workspace = optionalString(args, "workspace");
|
|
364
|
+
const jobId = args.job_id === undefined ? undefined : requiredNonEmptyString(args, "job_id");
|
|
365
|
+
const statusFilter = args.status_filter === undefined
|
|
366
|
+
? undefined
|
|
367
|
+
: requiredEnum(args, "status_filter", ["running", "completed", "failed", "cancelled"]);
|
|
368
|
+
const limit = optionalBoundedInteger(args, "limit", 1, 100);
|
|
369
|
+
const waitMs = optionalBoundedInteger(args, "wait_ms", 100, 600_000);
|
|
370
|
+
const apply = optionalBoolean(args, "apply");
|
|
371
|
+
if (action !== "list" && (statusFilter !== undefined || limit !== undefined)) {
|
|
372
|
+
throw invalidArguments('status_filter and limit are only valid for action "list".');
|
|
373
|
+
}
|
|
374
|
+
if (action !== "wait" && waitMs !== undefined) {
|
|
375
|
+
throw invalidArguments('wait_ms is only valid for action "wait".');
|
|
376
|
+
}
|
|
377
|
+
if (action !== "recover_swarm" && apply !== undefined) {
|
|
378
|
+
throw invalidArguments('apply is only valid for action "recover_swarm".');
|
|
379
|
+
}
|
|
380
|
+
if ((action === "replay" || action === "recover_swarm") && jobId === undefined) {
|
|
381
|
+
throw invalidArguments(`job_id is required for action "${action}".`);
|
|
382
|
+
}
|
|
235
383
|
return {
|
|
236
|
-
|
|
237
|
-
|
|
384
|
+
action,
|
|
385
|
+
...(workspace !== undefined ? { workspace } : {}),
|
|
386
|
+
...(jobId !== undefined ? { jobId } : {}),
|
|
387
|
+
...(statusFilter !== undefined ? { statusFilter } : {}),
|
|
388
|
+
...(limit !== undefined ? { limit } : {}),
|
|
389
|
+
...(waitMs !== undefined ? { waitMs } : {}),
|
|
390
|
+
...(apply !== undefined ? { apply } : {}),
|
|
238
391
|
};
|
|
239
392
|
}
|
|
393
|
+
export function readSetupArguments(input) {
|
|
394
|
+
const args = readArguments(input, Object.keys(SETUP_SCHEMA.properties));
|
|
395
|
+
const actionRaw = optionalString(args, "action") ?? "check";
|
|
396
|
+
const validActions = ["check", "models", "install", "install_kimi", "repair_sessions"];
|
|
397
|
+
if (!validActions.includes(actionRaw)) {
|
|
398
|
+
throw invalidArguments(`action must be one of ${validActions.join(", ")}.`);
|
|
399
|
+
}
|
|
400
|
+
const action = actionRaw;
|
|
401
|
+
const workspace = optionalString(args, "workspace");
|
|
402
|
+
const apply = optionalBoolean(args, "apply");
|
|
403
|
+
const all = optionalBoolean(args, "all");
|
|
404
|
+
if (action !== "repair_sessions" && (apply !== undefined || all !== undefined)) {
|
|
405
|
+
throw invalidArguments('apply and all are only valid for action "repair_sessions".');
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
action,
|
|
409
|
+
...(workspace !== undefined ? { workspace } : {}),
|
|
410
|
+
...(apply !== undefined ? { apply } : {}),
|
|
411
|
+
...(all !== undefined ? { all } : {}),
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function readMode(args) {
|
|
415
|
+
const raw = optionalString(args, "mode") ?? "ask";
|
|
416
|
+
if (raw !== "ask" && raw !== "review" && raw !== "challenge" && raw !== "swarm") {
|
|
417
|
+
throw invalidArguments('kimi_read mode must be one of "ask", "review", "challenge", "swarm".');
|
|
418
|
+
}
|
|
419
|
+
return raw;
|
|
420
|
+
}
|
|
421
|
+
function writeMode(args) {
|
|
422
|
+
const raw = optionalString(args, "mode") ?? "rescue";
|
|
423
|
+
if (raw !== "rescue" && raw !== "pursue" && raw !== "swarm_patch") {
|
|
424
|
+
throw invalidArguments('kimi_write mode must be one of "rescue", "pursue", "swarm_patch".');
|
|
425
|
+
}
|
|
426
|
+
return raw;
|
|
427
|
+
}
|
|
240
428
|
function appendCommonOptions(argv, args, budgetKind) {
|
|
241
429
|
const budget = optionalString(args, "budget");
|
|
242
430
|
const model = optionalString(args, "model");
|
|
@@ -252,6 +440,36 @@ function appendCommonOptions(argv, args, budgetKind) {
|
|
|
252
440
|
argv.push("--thinking", thinking);
|
|
253
441
|
}
|
|
254
442
|
}
|
|
443
|
+
/** Type checks only: the companion parser and read-scope resolver own every scope rule. */
|
|
444
|
+
function appendScopeOptions(argv, args) {
|
|
445
|
+
const readRoots = args.read_roots;
|
|
446
|
+
if (readRoots !== undefined) {
|
|
447
|
+
if (!Array.isArray(readRoots) || readRoots.some((root) => typeof root !== "string")) {
|
|
448
|
+
throw invalidArguments("read_roots must be an array of strings.");
|
|
449
|
+
}
|
|
450
|
+
for (const root of readRoots)
|
|
451
|
+
argv.push("--read-root", root);
|
|
452
|
+
}
|
|
453
|
+
if (optionalBoolean(args, "network") === true)
|
|
454
|
+
argv.push("--network");
|
|
455
|
+
}
|
|
456
|
+
function appendReferenceOptions(argv, args) {
|
|
457
|
+
const references = args.referenced_sessions;
|
|
458
|
+
if (references === undefined)
|
|
459
|
+
return;
|
|
460
|
+
if (!Array.isArray(references) || references.some((reference) => typeof reference !== "string")) {
|
|
461
|
+
throw invalidArguments("referenced_sessions must be an array of strings.");
|
|
462
|
+
}
|
|
463
|
+
const unique = [...new Set(references)];
|
|
464
|
+
if (unique.length > MAX_SESSION_REFERENCES) {
|
|
465
|
+
throw invalidArguments(`referenced_sessions accepts at most ${MAX_SESSION_REFERENCES} distinct sessions; got ${unique.length}.`);
|
|
466
|
+
}
|
|
467
|
+
if (unique.some((reference) => reference.length > SESSION_REFERENCE_ID_MAX)) {
|
|
468
|
+
throw invalidArguments(`referenced_sessions ids are at most ${SESSION_REFERENCE_ID_MAX} characters.`);
|
|
469
|
+
}
|
|
470
|
+
for (const reference of unique)
|
|
471
|
+
argv.push("--reference-session", reference);
|
|
472
|
+
}
|
|
255
473
|
function readArguments(input, allowedKeys) {
|
|
256
474
|
if (input === undefined)
|
|
257
475
|
return {};
|
|
@@ -266,6 +484,13 @@ function readArguments(input, allowedKeys) {
|
|
|
266
484
|
}
|
|
267
485
|
return args;
|
|
268
486
|
}
|
|
487
|
+
function requiredEnum(args, key, values) {
|
|
488
|
+
const value = args[key];
|
|
489
|
+
if (typeof value !== "string" || !values.includes(value)) {
|
|
490
|
+
throw invalidArguments(`${key} must be one of ${values.join(", ")}.`);
|
|
491
|
+
}
|
|
492
|
+
return value;
|
|
493
|
+
}
|
|
269
494
|
function optionalString(args, key) {
|
|
270
495
|
const value = args[key];
|
|
271
496
|
if (value === undefined)
|
|
@@ -288,12 +513,13 @@ function optionalBoolean(args, key) {
|
|
|
288
513
|
throw invalidArguments(`${key} must be a boolean.`);
|
|
289
514
|
return value;
|
|
290
515
|
}
|
|
291
|
-
function
|
|
516
|
+
function optionalBoundedInteger(args, key, min, max) {
|
|
292
517
|
const value = args[key];
|
|
293
518
|
if (value === undefined)
|
|
294
519
|
return undefined;
|
|
295
|
-
if (!Number.isSafeInteger(value) || value
|
|
296
|
-
throw invalidArguments(`${key} must be
|
|
520
|
+
if (!Number.isSafeInteger(value) || value < min || value > max) {
|
|
521
|
+
throw invalidArguments(`${key} must be an integer between ${min} and ${max}.`);
|
|
522
|
+
}
|
|
297
523
|
return value;
|
|
298
524
|
}
|
|
299
525
|
function invalidArguments(message) {
|