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
package/dist/kimi-command.js
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
|
+
import { accessSync, constants as fsConstants, lstatSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
1
3
|
import { RuntimeError } from "./errors.js";
|
|
4
|
+
import { resolveKimiBinDir } from "./paths.js";
|
|
5
|
+
const EXACT_VERSION_DIR_RE = /^\d+\.\d+\.\d+$/;
|
|
6
|
+
/** Which binary jobs will use and why; setup reports this. */
|
|
7
|
+
export function selectKimiBinary(env) {
|
|
8
|
+
const pluginOwned = inspectPluginOwnedKimi(env);
|
|
9
|
+
if (env.KIMI_PLUGIN_CC_KIMI_BIN) {
|
|
10
|
+
return { command: env.KIMI_PLUGIN_CC_KIMI_BIN, source: "override", pluginOwned };
|
|
11
|
+
}
|
|
12
|
+
if (pluginOwned.status === "active") {
|
|
13
|
+
return { command: pluginOwned.target, source: "plugin-owned", pluginOwned };
|
|
14
|
+
}
|
|
15
|
+
return { command: "kimi", source: "path", pluginOwned };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The plugin-owned binary is used only when `current` resolves to an
|
|
19
|
+
* executable regular file inside `<data root>/kimi-plugin-cc/kimi-bin/<x.y.z>/`. The resolved
|
|
20
|
+
* realpath is returned so the checked file is the one the plan records.
|
|
21
|
+
* Anything else falls back to PATH, as before this install existed.
|
|
22
|
+
*/
|
|
23
|
+
export function inspectPluginOwnedKimi(env) {
|
|
24
|
+
let binDir;
|
|
25
|
+
try {
|
|
26
|
+
binDir = resolveKimiBinDir(env);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return { binDir: null, status: "unavailable", reason: "plugin data root is not resolved" };
|
|
30
|
+
}
|
|
31
|
+
if (process.platform === "win32") {
|
|
32
|
+
return { binDir, status: "unavailable", reason: "plugin-owned kimi-code is not supported on Windows" };
|
|
33
|
+
}
|
|
34
|
+
const currentPath = path.join(binDir, "current");
|
|
35
|
+
try {
|
|
36
|
+
lstatSync(currentPath);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return { binDir, status: "absent" };
|
|
40
|
+
}
|
|
41
|
+
let realBinDir;
|
|
42
|
+
let target;
|
|
43
|
+
try {
|
|
44
|
+
realBinDir = realpathSync(binDir);
|
|
45
|
+
target = realpathSync(currentPath);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return { binDir, status: "rejected", reason: `${currentPath} does not resolve to an existing file` };
|
|
49
|
+
}
|
|
50
|
+
const relative = path.relative(realBinDir, target);
|
|
51
|
+
const versionDir = relative.split(path.sep)[0] ?? "";
|
|
52
|
+
if (relative === "" ||
|
|
53
|
+
path.isAbsolute(relative) ||
|
|
54
|
+
relative.startsWith(`..${path.sep}`) ||
|
|
55
|
+
relative === ".." ||
|
|
56
|
+
!EXACT_VERSION_DIR_RE.test(versionDir) ||
|
|
57
|
+
relative === versionDir) {
|
|
58
|
+
return {
|
|
59
|
+
binDir,
|
|
60
|
+
status: "rejected",
|
|
61
|
+
reason: `${currentPath} resolves to ${target}, outside ${path.join(realBinDir, "<version>")}${path.sep}`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
if (!statSync(target).isFile()) {
|
|
66
|
+
return { binDir, status: "rejected", reason: `${target} is not a regular file` };
|
|
67
|
+
}
|
|
68
|
+
accessSync(target, fsConstants.X_OK);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return { binDir, status: "rejected", reason: `${target} is not executable` };
|
|
72
|
+
}
|
|
73
|
+
return { binDir, status: "active", target, version: versionDir };
|
|
74
|
+
}
|
|
2
75
|
export function resolveKimiCliCommand(env) {
|
|
3
|
-
const command = env.KIMI_PLUGIN_CC_KIMI_BIN ||
|
|
76
|
+
const command = env.KIMI_PLUGIN_CC_KIMI_BIN || selectKimiBinary(env).command;
|
|
4
77
|
const raw = env.KIMI_PLUGIN_CC_KIMI_PREFIX_ARGS;
|
|
5
78
|
if (!raw) {
|
|
6
79
|
return { command, prefixArgs: [] };
|
package/dist/kimi-engine.js
CHANGED
|
@@ -4,63 +4,61 @@ import path from "node:path";
|
|
|
4
4
|
import { RuntimeError } from "./errors.js";
|
|
5
5
|
import { resolveKimiCliCommand } from "./kimi-command.js";
|
|
6
6
|
import { resolveKimiHome } from "./kimi-home.js";
|
|
7
|
+
import { formatVersionChoice, kimiVersionsInScope, kimiVersionsWith, resolveKimiRelease } from "./kimi-releases.js";
|
|
8
|
+
import { hookGateRefusal, verifyHookInstalled } from "./hooks/install.js";
|
|
7
9
|
import { assertNativeV2Preflight } from "./native-v2-preflight.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
+
import { KIMI_MINIMUM_CERTIFIED_VERSION, parseVersionLine, probeKimiVersion, } from "./kimi-version-probe.js";
|
|
11
|
+
import { isRecord } from "./util.js";
|
|
10
12
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
+
* The user-visible operation actually being performed. This is deliberately
|
|
14
|
+
* separate from JobRecord.command_type: pursue and swarm-write reuse the
|
|
15
|
+
* rescue job lineage, while read-only swarm reuses review.
|
|
13
16
|
*/
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
const NON_SWARM_OPERATION_KINDS = ["review", "challenge", "ask", "rescue", "pursue"];
|
|
18
|
+
const OPERATION_KINDS = [...NON_SWARM_OPERATION_KINDS, "swarm", "swarm-write"];
|
|
19
|
+
/** Operations that may run on an uncertified release (> 2.8.0). Every write or swarm operation stays exact. */
|
|
20
|
+
const UNCERTIFIED_READ_ONLY_OPERATIONS = new Set([
|
|
21
|
+
"ask",
|
|
22
|
+
"review",
|
|
23
|
+
"challenge",
|
|
24
|
+
]);
|
|
25
|
+
/** Restores exact-version refusal for every operation. */
|
|
26
|
+
export const STRICT_VERSIONS_ENV = "KIMI_PLUGIN_CC_STRICT_VERSIONS";
|
|
27
|
+
function strictVersions(env) {
|
|
28
|
+
return env[STRICT_VERSIONS_ENV] === "1";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Native-v2 certification of an exact version for one operation: "certified"
|
|
32
|
+
* from the per-operation table, "uncertified" for a read-only operation on an
|
|
33
|
+
* unlisted plain 2.x that borrows a row's mechanics, otherwise null (refuse).
|
|
34
|
+
*/
|
|
35
|
+
export function resolveNativeV2Certification(operationKind, version, env) {
|
|
36
|
+
if (isNativeV2Certified(operationKind, version))
|
|
37
|
+
return "certified";
|
|
38
|
+
if (!UNCERTIFIED_READ_ONLY_OPERATIONS.has(operationKind) || strictVersions(env))
|
|
39
|
+
return null;
|
|
40
|
+
const normalized = parseVersionLine(version)?.raw;
|
|
41
|
+
if (normalized === undefined || isNativeV2CertifiedVersion(normalized))
|
|
42
|
+
return null;
|
|
43
|
+
const resolved = resolveKimiRelease(normalized);
|
|
44
|
+
return resolved !== null && !resolved.certified ? "uncertified" : null;
|
|
45
|
+
}
|
|
46
|
+
export const NATIVE_V2_SAFETY_PROFILE = "native-v2-no-plan/1";
|
|
24
47
|
/**
|
|
25
48
|
* Exact kimi-code releases certified for native v2 under
|
|
26
49
|
* NATIVE_V2_SAFETY_PROFILE. Exact, not minor-ranged: upstream ships
|
|
27
50
|
* behavioural changes in patch releases, and the no-plan construction must be
|
|
28
|
-
* re-proven (mechanized tag scan + real-binary smoke) per tag before a
|
|
29
|
-
*
|
|
30
|
-
*
|
|
51
|
+
* re-proven (mechanized tag scan + real-binary smoke) per tag before a row is
|
|
52
|
+
* added to KIMI_V2_RELEASES in kimi-releases.ts with scope "all". Each entry
|
|
53
|
+
* has its own row in tests/audit/v2-tag-scan.test.ts and an active
|
|
54
|
+
* certification record in docs/upstream-<version>-certification.md.
|
|
31
55
|
*/
|
|
32
|
-
export const NATIVE_V2_CERTIFIED_VERSIONS = Object.freeze([
|
|
33
|
-
"0.42.0",
|
|
34
|
-
"0.43.0",
|
|
35
|
-
"0.43.1",
|
|
36
|
-
"2.0.0",
|
|
37
|
-
"2.0.1",
|
|
38
|
-
"2.0.2",
|
|
39
|
-
"2.1.0",
|
|
40
|
-
"2.1.1",
|
|
41
|
-
"2.2.0",
|
|
42
|
-
"2.3.0",
|
|
43
|
-
"2.3.1",
|
|
44
|
-
"2.3.2",
|
|
45
|
-
"2.3.3",
|
|
46
|
-
"2.4.0",
|
|
47
|
-
"2.4.1",
|
|
48
|
-
"2.5.0",
|
|
49
|
-
"2.5.1",
|
|
50
|
-
"2.5.2",
|
|
51
|
-
"2.5.3",
|
|
52
|
-
"2.6.2",
|
|
53
|
-
"2.6.3",
|
|
54
|
-
"2.7.2",
|
|
55
|
-
"2.7.3",
|
|
56
|
-
]);
|
|
56
|
+
export const NATIVE_V2_CERTIFIED_VERSIONS = Object.freeze([...kimiVersionsInScope("all")]);
|
|
57
57
|
/**
|
|
58
|
-
* Exact releases certified only for
|
|
59
|
-
*
|
|
60
|
-
* configured maximum, and these releases lack a certified plugin admission
|
|
61
|
-
* construction, so both swarm operations refuse before model spawn.
|
|
58
|
+
* Exact releases certified only for non-swarm operations. Empty in the 2.8.0+
|
|
59
|
+
* rolling window, kept exported so callers/diagnostics checking scope compile cleanly.
|
|
62
60
|
*/
|
|
63
|
-
export const NATIVE_V2_NON_SWARM_VERSIONS = Object.freeze(["
|
|
61
|
+
export const NATIVE_V2_NON_SWARM_VERSIONS = Object.freeze([...kimiVersionsInScope("non-swarm")]);
|
|
64
62
|
/**
|
|
65
63
|
* Any-operation union used by setup and engine selection. The older
|
|
66
64
|
* NATIVE_V2_CERTIFIED_VERSIONS export stays all-operation-only for consumers
|
|
@@ -76,7 +74,6 @@ export const NATIVE_V2_CERTIFIED = new Map([
|
|
|
76
74
|
["challenge", NATIVE_V2_ANY_OPERATION_VERSIONS],
|
|
77
75
|
["ask", NATIVE_V2_ANY_OPERATION_VERSIONS],
|
|
78
76
|
["rescue", NATIVE_V2_ANY_OPERATION_VERSIONS],
|
|
79
|
-
["review_gate", NATIVE_V2_ANY_OPERATION_VERSIONS],
|
|
80
77
|
["pursue", NATIVE_V2_ANY_OPERATION_VERSIONS],
|
|
81
78
|
["swarm", NATIVE_V2_CERTIFIED_VERSIONS],
|
|
82
79
|
["swarm-write", NATIVE_V2_CERTIFIED_VERSIONS],
|
|
@@ -89,9 +86,6 @@ export function isNativeV2Certified(operationKind, version) {
|
|
|
89
86
|
}
|
|
90
87
|
/**
|
|
91
88
|
* True when this exact version is certified for native v2 for ANY operation.
|
|
92
|
-
* Used by setup to phrase its version notice: a v2-certified version is NOT an
|
|
93
|
-
* "out of tested range, will refuse" case even though it is outside the legacy
|
|
94
|
-
* `KIMI_TESTED_MINORS` table (that table intentionally never gains 0.42).
|
|
95
89
|
*/
|
|
96
90
|
export function isNativeV2CertifiedVersion(version) {
|
|
97
91
|
const normalized = parseVersionLine(version)?.raw;
|
|
@@ -100,26 +94,30 @@ export function isNativeV2CertifiedVersion(version) {
|
|
|
100
94
|
return NATIVE_V2_ANY_OPERATION_VERSIONS.includes(normalized);
|
|
101
95
|
}
|
|
102
96
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
97
|
+
* All kimi-code releases >= 2.8.0 use native agent-core-v2. Legacy-v1
|
|
98
|
+
* (0.1–0.41) and < 2.8.0 shims are no longer supported; assertCertifiedCapability
|
|
99
|
+
* enforces the exact 2.8.0+ window.
|
|
106
100
|
*/
|
|
107
|
-
export function selectIntendedEngine(
|
|
108
|
-
return
|
|
109
|
-
? "native-v2"
|
|
110
|
-
: "legacy-v1";
|
|
101
|
+
export function selectIntendedEngine(_operationKind, _probe) {
|
|
102
|
+
return "native-v2";
|
|
111
103
|
}
|
|
112
104
|
const UNSAFE_EXPERIMENTAL_VALUES = new Set(["1", "true", "yes", "on"]);
|
|
113
105
|
/**
|
|
114
|
-
* Refuse the
|
|
115
|
-
*
|
|
116
|
-
* environment
|
|
106
|
+
* Refuse the master experimental flag for legacy-v1 and plan-less launches.
|
|
107
|
+
* A native-v2 plan is exempt, certified or not: upstream reads the master flag
|
|
108
|
+
* only from the child's own environment (flagService via bootstrap.getEnv,
|
|
109
|
+
* 0.42.0-2.8.0), and buildKimiCliEnvironment deletes it from every native-v2
|
|
110
|
+
* child. An uncertified plan gets a launch warning from the preflight instead.
|
|
111
|
+
* cli-client and swarm activation repeat this at the final spawn boundary in
|
|
112
|
+
* case the environment changed after plan creation.
|
|
117
113
|
*/
|
|
118
|
-
export function assertNoUnsafeExperimentalSelector(env, stage = "kimi-engine.plan") {
|
|
114
|
+
export function assertNoUnsafeExperimentalSelector(env, stage = "kimi-engine.plan", plan) {
|
|
119
115
|
const enabled = UNSAFE_EXPERIMENTAL_VALUES.has((env.KIMI_CODE_EXPERIMENTAL_FLAG ?? "").trim().toLowerCase());
|
|
120
116
|
if (!enabled)
|
|
121
117
|
return;
|
|
122
|
-
|
|
118
|
+
if (plan?.intendedEngine === "native-v2")
|
|
119
|
+
return;
|
|
120
|
+
throw new RuntimeError("CLI_V2_HOOK_ORDER_UNSAFE", "Refusing kimi-code experimental features: the master KIMI_CODE_EXPERIMENTAL_FLAG is set and this launch is not a native-v2 plan, so kimi-plugin-cc cannot keep it from the Kimi process. Unset KIMI_CODE_EXPERIMENTAL_FLAG and retry.", stage, {
|
|
123
121
|
details: {
|
|
124
122
|
refusal_kind: "v2-hook-order-unsafe",
|
|
125
123
|
retryable_after_setup: false,
|
|
@@ -134,33 +132,47 @@ export function assertNoUnsafeExperimentalSelector(env, stage = "kimi-engine.pla
|
|
|
134
132
|
* alternate route between dispatch and execution.
|
|
135
133
|
*/
|
|
136
134
|
export async function prepareKimiExecutionPlan(options) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
if (options.intendedEngine === "legacy-v1") {
|
|
136
|
+
throw new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${options.operationKind}: legacy-v1 is unsupported in 3.1.0+; use kimi-code >= ${KIMI_MINIMUM_CERTIFIED_VERSION}.`, "kimi-engine.plan", {
|
|
137
|
+
details: {
|
|
138
|
+
refusal_kind: "legacy-v1-unsupported",
|
|
139
|
+
retryable_after_setup: false,
|
|
140
|
+
operation_kind: options.operationKind,
|
|
141
|
+
intended_engine: "legacy-v1",
|
|
142
|
+
minimum_version: KIMI_MINIMUM_CERTIFIED_VERSION,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (!NATIVE_V2_CERTIFIED.has(options.operationKind)) {
|
|
140
147
|
throw nativeV2NotCertified(options.operationKind, null);
|
|
141
148
|
}
|
|
142
149
|
const kimi = resolveKimiCliCommand(options.env);
|
|
143
150
|
const exactCommand = await resolveExactExecutable(kimi.command, options.cwd, options.env);
|
|
144
|
-
const
|
|
151
|
+
const warnings = [];
|
|
152
|
+
const runPreflight = async (intendedEngine, release) => {
|
|
145
153
|
if (options.resumeSource) {
|
|
146
154
|
assertResumeEngineCompatible(options.resumeSource, intendedEngine, options.operationKind);
|
|
147
155
|
}
|
|
148
156
|
if (intendedEngine !== "native-v2")
|
|
149
157
|
return;
|
|
150
158
|
// Safety, not certification: runs for test-bypass plans too.
|
|
151
|
-
await assertNativeV2Preflight({
|
|
159
|
+
const preflight = await assertNativeV2Preflight({
|
|
152
160
|
kimiHome: resolveKimiHome(options.env, options.cwd),
|
|
153
161
|
env: options.env,
|
|
154
162
|
resumeSessionId: options.resumeSessionId,
|
|
155
163
|
expectedExecutionRoot: options.cwd,
|
|
156
164
|
stage: "kimi-engine.plan",
|
|
165
|
+
release: { operationKind: options.operationKind, ...release },
|
|
157
166
|
});
|
|
167
|
+
warnings.push(...preflight.warnings);
|
|
158
168
|
};
|
|
159
169
|
if (options.env.KIMI_PLUGIN_CC_SKIP_VERSION_PROBE === "1") {
|
|
160
|
-
const intendedEngine =
|
|
161
|
-
const safetyProfile = intendedEngine === "native-v2" ? NATIVE_V2_SAFETY_PROFILE : null;
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
const intendedEngine = "native-v2";
|
|
171
|
+
const safetyProfile = options.intendedEngine === "native-v2" ? NATIVE_V2_SAFETY_PROFILE : null;
|
|
172
|
+
assertNoUnsafeExperimentalSelector(options.env, "kimi-engine.plan", { intendedEngine });
|
|
173
|
+
await runPreflight(intendedEngine, { kimiVersion: null, certification: "test-bypass" });
|
|
174
|
+
warnings.push(...await planHookCheck(options.operationKind, options.env, options.stderr));
|
|
175
|
+
return finishPlan({
|
|
164
176
|
schemaVersion: 1,
|
|
165
177
|
operationKind: options.operationKind,
|
|
166
178
|
intendedEngine,
|
|
@@ -170,16 +182,16 @@ export async function prepareKimiExecutionPlan(options) {
|
|
|
170
182
|
certification: "test-bypass",
|
|
171
183
|
resumedFromJobId: options.resumedFromJobId ?? null,
|
|
172
184
|
safetyProfile,
|
|
173
|
-
});
|
|
185
|
+
}, warnings, options.stderr);
|
|
174
186
|
}
|
|
175
187
|
const probe = await probeKimiVersion({
|
|
176
188
|
kimiBin: exactCommand,
|
|
177
189
|
prefixArgs: kimi.prefixArgs,
|
|
178
190
|
cwd: options.cwd,
|
|
179
|
-
env: options.env,
|
|
191
|
+
env: withoutExperimentalMasterFlag(options.env),
|
|
180
192
|
});
|
|
181
193
|
if (probe.kind !== "ok") {
|
|
182
|
-
throw new RuntimeError("KIMI_EXECUTION_PLAN_UNRESOLVED", `Refusing to spawn kimi because the exact command/version plan could not be established: ${probe.reason}. Run
|
|
194
|
+
throw new RuntimeError("KIMI_EXECUTION_PLAN_UNRESOLVED", `Refusing to spawn kimi because the exact command/version plan could not be established: ${probe.reason}. Run \`kimi_setup\` (or \`scripts/companion.sh setup\`) to verify the active binary, or correct KIMI_PLUGIN_CC_KIMI_BIN / KIMI_PLUGIN_CC_KIMI_PREFIX_ARGS and retry.`, "kimi-engine.plan", {
|
|
183
195
|
details: {
|
|
184
196
|
operation_kind: options.operationKind,
|
|
185
197
|
intended_engine: options.intendedEngine ?? null,
|
|
@@ -190,19 +202,71 @@ export async function prepareKimiExecutionPlan(options) {
|
|
|
190
202
|
}
|
|
191
203
|
const intendedEngine = options.intendedEngine ?? selectIntendedEngine(options.operationKind, probe);
|
|
192
204
|
const safetyProfile = intendedEngine === "native-v2" ? NATIVE_V2_SAFETY_PROFILE : null;
|
|
193
|
-
assertCertifiedCapability(intendedEngine, options.operationKind, probe);
|
|
194
|
-
|
|
195
|
-
|
|
205
|
+
const certification = assertCertifiedCapability(intendedEngine, options.operationKind, probe, options.env);
|
|
206
|
+
assertNoUnsafeExperimentalSelector(options.env, "kimi-engine.plan", { intendedEngine });
|
|
207
|
+
if (certification === "uncertified") {
|
|
208
|
+
const borrowed = resolveKimiRelease(probe.version).release.version;
|
|
209
|
+
warnings.push(`kimi-code ${probe.version} is not certified by this plugin release; running ${options.operationKind} read-only with ${borrowed} mechanics.`);
|
|
210
|
+
}
|
|
211
|
+
await runPreflight(intendedEngine, { kimiVersion: probe.version, certification });
|
|
212
|
+
warnings.push(...await planHookCheck(options.operationKind, options.env, options.stderr, probe));
|
|
213
|
+
return finishPlan({
|
|
196
214
|
schemaVersion: 1,
|
|
197
215
|
operationKind: options.operationKind,
|
|
198
216
|
intendedEngine,
|
|
199
217
|
command: exactCommand,
|
|
200
218
|
prefixArgs: Object.freeze([...kimi.prefixArgs]),
|
|
201
219
|
kimiVersion: probe.version,
|
|
202
|
-
certification
|
|
220
|
+
certification,
|
|
203
221
|
resumedFromJobId: options.resumedFromJobId ?? null,
|
|
204
222
|
safetyProfile,
|
|
205
|
-
});
|
|
223
|
+
}, warnings, options.stderr);
|
|
224
|
+
}
|
|
225
|
+
function withoutExperimentalMasterFlag(env) {
|
|
226
|
+
const copy = { ...env };
|
|
227
|
+
delete copy.KIMI_CODE_EXPERIMENTAL_FLAG;
|
|
228
|
+
return copy;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Job-time hook check against the release this plan probed (`probe`, absent
|
|
232
|
+
* only on the test-bypass path). It refuses when the configured hooks array is
|
|
233
|
+
* invalid for that release, because kimi-code would then load no hook at all;
|
|
234
|
+
* the command gate's earlier check may have probed a different release.
|
|
235
|
+
* Any other definite negative (`installed === false`) refuses with the
|
|
236
|
+
* operation's command-gate error: the hook may have gone between that gate and
|
|
237
|
+
* this plan. KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 makes verifyHookInstalled report
|
|
238
|
+
* installed, exactly as at the gates. Otherwise it returns warnings: marker
|
|
239
|
+
* repair (G6) and other hosts' older hooks that still apply their own rules to
|
|
240
|
+
* this job (H2). A thrown, unverifiable result adds nothing and never refuses.
|
|
241
|
+
*/
|
|
242
|
+
async function planHookCheck(operation, env, stderr, probe) {
|
|
243
|
+
let status;
|
|
244
|
+
try {
|
|
245
|
+
status = await verifyHookInstalled(env, { kimiVersion: probe });
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
return [];
|
|
249
|
+
}
|
|
250
|
+
if (status.hookSetInvalid) {
|
|
251
|
+
throw new RuntimeError("KIMI_HOOK_SET_INVALID", `Refusing to spawn kimi: the configured kimi-code hooks are invalid for the release this job runs (${probe?.version ?? "version not probed"}): ${status.reason}. kimi-code drops the whole hooks array, so the managed PreToolUse hook would not run. Repair or remove that [[hooks]] entry in ${status.configPath} and retry.`, "kimi-engine.plan", {
|
|
252
|
+
details: {
|
|
253
|
+
config_path: status.configPath,
|
|
254
|
+
kimi_version: probe?.version ?? null,
|
|
255
|
+
retryable_after_setup: false,
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
if (status.installed)
|
|
260
|
+
return status.warnings ?? [];
|
|
261
|
+
throw hookGateRefusal(operation, status, env, stderr);
|
|
262
|
+
}
|
|
263
|
+
/** Freeze the plan; a nonempty warning list is attached and announced once on stderr. */
|
|
264
|
+
function finishPlan(plan, warnings, stderr = process.stderr) {
|
|
265
|
+
if (warnings.length === 0)
|
|
266
|
+
return Object.freeze(plan);
|
|
267
|
+
for (const warning of warnings)
|
|
268
|
+
stderr.write(`[kimi-plugin-cc] warning: ${warning}\n`);
|
|
269
|
+
return Object.freeze({ ...plan, warnings: Object.freeze([...warnings]) });
|
|
206
270
|
}
|
|
207
271
|
export function assertExecutionPlanMatchesSpawn(plan, command, prefixArgs, env = {}) {
|
|
208
272
|
assertExecutionPlanShape(plan);
|
|
@@ -232,6 +296,7 @@ export function persistedExecutionPlanFields(plan) {
|
|
|
232
296
|
plan_certification: plan.certification,
|
|
233
297
|
resumed_from_job_id: plan.resumedFromJobId,
|
|
234
298
|
safety_profile: plan.safetyProfile,
|
|
299
|
+
warnings: plan.warnings !== undefined && plan.warnings.length > 0 ? JSON.stringify(plan.warnings) : null,
|
|
235
300
|
};
|
|
236
301
|
}
|
|
237
302
|
export function observedExecutionFields(result) {
|
|
@@ -467,46 +532,42 @@ export function classifyHistoricalEngineProvenance(contents) {
|
|
|
467
532
|
conflict,
|
|
468
533
|
};
|
|
469
534
|
}
|
|
470
|
-
function
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
return;
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
: `Upgrade kimi-code to at least ${minimum.major}.${minimum.minor}.0 within a certified minor.`;
|
|
484
|
-
throw new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind}: kimi-code ${probe.version} is not in this operation's certified legacy-v1 range. ${remedy} KIMI_PLUGIN_CC_SKIP_VERSION_PROBE is a test/smoke seam, not a production repair path.`, "kimi-engine.capability", {
|
|
535
|
+
function isBelowMinimumVersion(probe) {
|
|
536
|
+
const min = parseVersionLine(KIMI_MINIMUM_CERTIFIED_VERSION);
|
|
537
|
+
if (min === undefined)
|
|
538
|
+
return false;
|
|
539
|
+
if (probe.major !== min.major)
|
|
540
|
+
return probe.major < min.major;
|
|
541
|
+
if (probe.minor !== min.minor)
|
|
542
|
+
return probe.minor < min.minor;
|
|
543
|
+
return probe.patch < min.patch;
|
|
544
|
+
}
|
|
545
|
+
function assertCertifiedCapability(engine, operationKind, probe, env) {
|
|
546
|
+
if (engine !== "native-v2" || isBelowMinimumVersion(probe)) {
|
|
547
|
+
throw new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind}: kimi-code ${probe.version} is below the >= ${KIMI_MINIMUM_CERTIFIED_VERSION} rolling window supported by 3.1.0+. Run \`kimi_setup\` with action "install_kimi" (or \`setup --install-kimi\`) or point KIMI_PLUGIN_CC_KIMI_BIN at kimi-code >= ${KIMI_MINIMUM_CERTIFIED_VERSION}.`, "kimi-engine.capability", {
|
|
485
548
|
details: {
|
|
486
|
-
refusal_kind: "v1-
|
|
549
|
+
refusal_kind: "legacy-v1-unsupported",
|
|
487
550
|
retryable_after_setup: false,
|
|
488
551
|
operation_kind: operationKind,
|
|
489
552
|
intended_engine: engine,
|
|
490
553
|
kimi_version: probe.version,
|
|
491
|
-
minimum_version:
|
|
492
|
-
tested_minor: probe.inTestedRange,
|
|
554
|
+
minimum_version: KIMI_MINIMUM_CERTIFIED_VERSION,
|
|
493
555
|
},
|
|
494
556
|
});
|
|
495
557
|
}
|
|
558
|
+
const certification = resolveNativeV2Certification(operationKind, probe.version, env);
|
|
559
|
+
if (certification === null)
|
|
560
|
+
throw nativeV2NotCertified(operationKind, probe.version, env);
|
|
561
|
+
return certification;
|
|
496
562
|
}
|
|
497
563
|
/**
|
|
498
564
|
* Revalidate the persisted certification at the final subprocess boundary.
|
|
499
565
|
* This keeps a corrupt/forged SQLite row from converting a once-certified plan
|
|
500
|
-
* into an untested-version or
|
|
566
|
+
* into an untested-version or legacy spawn.
|
|
501
567
|
*/
|
|
502
568
|
function assertPlanCertification(plan, env) {
|
|
503
|
-
if (plan.intendedEngine
|
|
504
|
-
|
|
505
|
-
// was certified under.
|
|
506
|
-
throw invalidPersistedPlan("native-v2 plans require the native-v2-no-plan safety profile");
|
|
507
|
-
}
|
|
508
|
-
if (plan.intendedEngine === "legacy-v1" && plan.safetyProfile !== null) {
|
|
509
|
-
throw invalidPersistedPlan("legacy-v1 plans must not carry a safety profile");
|
|
569
|
+
if (plan.intendedEngine !== "native-v2") {
|
|
570
|
+
throw invalidPersistedPlan("only native-v2 plans are supported at the spawn boundary");
|
|
510
571
|
}
|
|
511
572
|
if (plan.certification === "test-bypass") {
|
|
512
573
|
if (plan.kimiVersion !== null) {
|
|
@@ -517,21 +578,35 @@ function assertPlanCertification(plan, env) {
|
|
|
517
578
|
}
|
|
518
579
|
return;
|
|
519
580
|
}
|
|
581
|
+
if (plan.safetyProfile !== NATIVE_V2_SAFETY_PROFILE) {
|
|
582
|
+
// A forged/deserialized v2 row cannot reach spawn without the profile it
|
|
583
|
+
// was certified under.
|
|
584
|
+
throw invalidPersistedPlan("native-v2 plans require the native-v2-no-plan safety profile");
|
|
585
|
+
}
|
|
520
586
|
if (plan.kimiVersion === null) {
|
|
521
|
-
throw invalidPersistedPlan(
|
|
587
|
+
throw invalidPersistedPlan(`${plan.certification} plans require kimi_version`);
|
|
522
588
|
}
|
|
523
589
|
const parsed = parseVersionLine(plan.kimiVersion);
|
|
524
590
|
if (parsed === undefined) {
|
|
525
591
|
throw invalidPersistedPlan("kimi_version is not a parseable semantic version");
|
|
526
592
|
}
|
|
527
|
-
|
|
593
|
+
// Recompute from the release table and the current environment: a strict
|
|
594
|
+
// environment, a write operation, or a row that has since been added all
|
|
595
|
+
// refuse a plan whose recorded certification no longer matches.
|
|
596
|
+
const certification = assertCertifiedCapability(plan.intendedEngine, plan.operationKind, {
|
|
528
597
|
kind: "ok",
|
|
529
598
|
version: parsed.raw,
|
|
530
599
|
major: parsed.major,
|
|
531
600
|
minor: parsed.minor,
|
|
532
601
|
patch: parsed.patch,
|
|
533
|
-
|
|
534
|
-
|
|
602
|
+
}, env);
|
|
603
|
+
if (certification !== plan.certification) {
|
|
604
|
+
// A plan claiming exact certification for an uncertified release keeps the
|
|
605
|
+
// historical capability refusal; any other mismatch is a stale/forged row.
|
|
606
|
+
if (plan.certification === "certified")
|
|
607
|
+
throw nativeV2NotCertified(plan.operationKind, parsed.raw, env);
|
|
608
|
+
throw invalidPersistedPlan(`plan_certification ${JSON.stringify(plan.certification)} does not match ${JSON.stringify(certification)} for kimi-code ${parsed.raw}`);
|
|
609
|
+
}
|
|
535
610
|
}
|
|
536
611
|
function assertExecutionPlanShape(plan) {
|
|
537
612
|
const candidate = plan;
|
|
@@ -566,13 +641,13 @@ function assertExecutionPlanShape(plan) {
|
|
|
566
641
|
throw invalidPersistedPlan("safetyProfile is invalid");
|
|
567
642
|
}
|
|
568
643
|
}
|
|
569
|
-
function nativeV2NotCertified(operationKind, version) {
|
|
644
|
+
function nativeV2NotCertified(operationKind, version, env = {}) {
|
|
570
645
|
const certified = NATIVE_V2_CERTIFIED.get(operationKind) ?? [];
|
|
571
646
|
const normalized = version === null ? undefined : parseVersionLine(version)?.raw;
|
|
572
647
|
if (normalized !== undefined &&
|
|
573
648
|
NATIVE_V2_NON_SWARM_VERSIONS.includes(normalized) &&
|
|
574
649
|
(operationKind === "swarm" || operationKind === "swarm-write")) {
|
|
575
|
-
return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind}: kimi-code ${normalized} is certified only for non-swarm operations (review, challenge, ask, rescue,
|
|
650
|
+
return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind}: kimi-code ${normalized} is certified only for non-swarm operations (review, challenge, ask, rescue, pursue). Its native rate-limit recovery can exceed AgentSwarm's configured maximum, so this exact release refuses swarm before model spawn. Select exact kimi-code ${formatVersionChoice(kimiVersionsWith("bounded-swarm"))} for this plugin's certified bounded waves and single-worker path, or use a non-swarm operation on ${normalized}.`, "kimi-engine.capability", {
|
|
576
651
|
details: {
|
|
577
652
|
refusal_kind: "v2-swarm-not-certified",
|
|
578
653
|
certification_scope: "non-swarm",
|
|
@@ -581,12 +656,18 @@ function nativeV2NotCertified(operationKind, version) {
|
|
|
581
656
|
intended_engine: "native-v2",
|
|
582
657
|
kimi_version: normalized,
|
|
583
658
|
certified_versions: [...certified],
|
|
584
|
-
certified_operations: [
|
|
659
|
+
certified_operations: [...NON_SWARM_OPERATION_KINDS],
|
|
585
660
|
},
|
|
586
661
|
});
|
|
587
662
|
}
|
|
588
663
|
const observed = version === null ? "an unprobed version" : `kimi-code ${version}`;
|
|
589
|
-
|
|
664
|
+
const borrowable = normalized !== undefined && resolveKimiRelease(normalized)?.certified === false;
|
|
665
|
+
const readOnlyNote = !borrowable
|
|
666
|
+
? ""
|
|
667
|
+
: strictVersions(env)
|
|
668
|
+
? ` ${STRICT_VERSIONS_ENV}=1 is set, so read-only operations on this uncertified release also refuse.`
|
|
669
|
+
: " Read-only operations (ask, review, challenge) still run on this uncertified release with a warning; write and swarm operations need an exact certified release.";
|
|
670
|
+
return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind} on native v2: ${observed} is not in this operation's exactly certified set [${certified.join(", ")}] (rolling window >= ${KIMI_MINIMUM_CERTIFIED_VERSION}).${readOnlyNote} Run \`kimi_setup\` with action "install_kimi" (or \`setup --install-kimi\`) to install the newest certified kimi-code, update kimi-plugin-cc, or point KIMI_PLUGIN_CC_KIMI_BIN at a certified binary.`, "kimi-engine.capability", {
|
|
590
671
|
details: {
|
|
591
672
|
refusal_kind: "v2-version-not-certified",
|
|
592
673
|
retryable_after_setup: false,
|
|
@@ -628,10 +709,7 @@ async function resolveExactExecutable(command, cwd, env) {
|
|
|
628
709
|
catch {
|
|
629
710
|
}
|
|
630
711
|
}
|
|
631
|
-
throw new RuntimeError("KIMI_EXECUTION_PLAN_UNRESOLVED", `Refusing to spawn kimi because executable ${JSON.stringify(command)} could not be resolved to an exact runnable path. Run
|
|
632
|
-
}
|
|
633
|
-
function isRecord(value) {
|
|
634
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
712
|
+
throw new RuntimeError("KIMI_EXECUTION_PLAN_UNRESOLVED", `Refusing to spawn kimi because executable ${JSON.stringify(command)} could not be resolved to an exact runnable path. Run \`kimi_setup\` (or \`scripts/companion.sh setup\`) to verify the active binary, or correct KIMI_PLUGIN_CC_KIMI_BIN and retry.`, "kimi-engine.plan", { details: { command, cwd } });
|
|
635
713
|
}
|
|
636
714
|
function parseProtocolVersion(value) {
|
|
637
715
|
const match = value.match(/^(\d+)\.(\d+)(?:\.\d+)?$/);
|
|
@@ -658,18 +736,11 @@ function operationKindFromLogEntry(entry) {
|
|
|
658
736
|
return isOperationKind(candidate) ? candidate : null;
|
|
659
737
|
}
|
|
660
738
|
function isOperationKind(value) {
|
|
661
|
-
return (value
|
|
662
|
-
value === "challenge" ||
|
|
663
|
-
value === "ask" ||
|
|
664
|
-
value === "rescue" ||
|
|
665
|
-
value === "review_gate" ||
|
|
666
|
-
value === "pursue" ||
|
|
667
|
-
value === "swarm" ||
|
|
668
|
-
value === "swarm-write");
|
|
739
|
+
return OPERATION_KINDS.includes(value);
|
|
669
740
|
}
|
|
670
741
|
function isKimiEngine(value) {
|
|
671
742
|
return value === "legacy-v1" || value === "native-v2";
|
|
672
743
|
}
|
|
673
744
|
function isPlanCertification(value) {
|
|
674
|
-
return value === "certified" || value === "test-bypass";
|
|
745
|
+
return value === "certified" || value === "uncertified" || value === "test-bypass";
|
|
675
746
|
}
|