kimi-plugin-cc 2.7.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +3 -5
- package/CHANGELOG.md +69 -0
- package/README.md +505 -448
- package/agents/kimi-pursue.md +6 -6
- package/agents/kimi-review.md +22 -22
- package/agents/kimi-swarm.md +25 -23
- package/agents/{kimi-ask.md → kimi-task.md} +34 -30
- package/commands/README.md +4 -6
- package/commands/pursue.md +1 -1
- package/commands/review.md +8 -3
- package/commands/setup.md +4 -2
- package/commands/swarm.md +3 -2
- package/commands/{rescue.md → task.md} +13 -11
- package/dist/background-spawn.js +10 -17
- package/dist/cli-client.js +65 -46
- package/dist/commands/ask.js +22 -89
- package/dist/commands/cancel.js +7 -46
- package/dist/commands/cli-helpers.js +102 -1
- package/dist/commands/models.js +2 -3
- package/dist/commands/pursue.js +5 -19
- package/dist/commands/repair-sessions.js +118 -12
- package/dist/commands/rescue.js +12 -82
- package/dist/commands/result.js +7 -1
- package/dist/commands/review-gate.js +1 -0
- package/dist/commands/review.js +12 -15
- package/dist/commands/setup.js +606 -270
- package/dist/commands/status.js +2 -2
- package/dist/commands/swarm.js +93 -119
- package/dist/commands/worker.js +1 -2
- package/dist/companion.js +3 -1
- package/dist/dsh/index.js +15 -17
- package/dist/git.js +1 -9
- package/dist/help.js +3 -3
- package/dist/hooks/approval-hook.js +41 -0
- package/dist/hooks/approval-policy.js +72 -10
- package/dist/hooks/config-safety.js +19 -43
- package/dist/hooks/hook-timing.js +48 -0
- package/dist/hooks/install.js +206 -11
- package/dist/hooks/managed-block.js +78 -33
- package/dist/job-store.js +100 -128
- package/dist/jobs.js +14 -19
- package/dist/kimi-command.js +74 -1
- package/dist/kimi-engine.js +170 -75
- package/dist/kimi-errors.js +14 -69
- package/dist/kimi-home.js +6 -0
- package/dist/kimi-journal.js +41 -0
- package/dist/kimi-releases.js +144 -0
- package/dist/kimi-timeouts.js +1 -1
- package/dist/kimi-version-probe.js +12 -48
- package/dist/mcp/job-control.js +4 -6
- package/dist/mcp/launcher.js +12 -6
- package/dist/mcp/operations.js +50 -18
- package/dist/mcp/protocol.js +16 -14
- package/dist/mcp/stdio.js +3 -2
- package/dist/model-command.js +5 -3
- package/dist/native-v2-preflight.js +139 -68
- package/dist/parsing.js +171 -237
- package/dist/paths.js +8 -0
- package/dist/process-tree.js +35 -24
- package/dist/read-scope.js +435 -0
- package/dist/render.js +46 -9
- package/dist/rescue-approval.js +461 -84
- package/dist/schemas/review-gate-output.js +3 -5
- package/dist/session-title.js +25 -5
- package/dist/stream-json.js +1 -3
- package/dist/surface-routing.js +21 -0
- package/dist/swarm-activation.js +72 -75
- 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 +24 -3
- package/docs/models.md +2 -2
- package/docs/registry-releases.md +1 -1
- package/docs/safety.md +120 -70
- package/docs/session-visibility.md +5 -3
- package/docs/swarm-recovery.md +1 -1
- package/docs/upstream-2.7.3-certification.md +14 -2
- package/package.json +1 -1
- package/plugins/kimi-codex/.codex-plugin/plugin.json +3 -3
- package/plugins/kimi-codex/.mcp.json +1 -0
- package/plugins/kimi-codex/dist/background-spawn.js +10 -17
- package/plugins/kimi-codex/dist/cli-client.js +65 -46
- package/plugins/kimi-codex/dist/commands/ask.js +22 -89
- package/plugins/kimi-codex/dist/commands/cancel.js +7 -46
- 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 +5 -19
- package/plugins/kimi-codex/dist/commands/repair-sessions.js +118 -12
- package/plugins/kimi-codex/dist/commands/rescue.js +12 -82
- package/plugins/kimi-codex/dist/commands/result.js +7 -1
- package/plugins/kimi-codex/dist/commands/review-gate.js +1 -0
- package/plugins/kimi-codex/dist/commands/review.js +12 -15
- package/plugins/kimi-codex/dist/commands/setup.js +606 -270
- package/plugins/kimi-codex/dist/commands/status.js +2 -2
- package/plugins/kimi-codex/dist/commands/swarm.js +93 -119
- package/plugins/kimi-codex/dist/commands/worker.js +1 -2
- package/plugins/kimi-codex/dist/companion.js +3 -1
- package/plugins/kimi-codex/dist/dsh/index.js +15 -17
- package/plugins/kimi-codex/dist/git.js +1 -9
- package/plugins/kimi-codex/dist/help.js +3 -3
- package/plugins/kimi-codex/dist/hooks/approval-hook.js +41 -0
- package/plugins/kimi-codex/dist/hooks/approval-policy.js +72 -10
- package/plugins/kimi-codex/dist/hooks/config-safety.js +19 -43
- package/plugins/kimi-codex/dist/hooks/hook-timing.js +48 -0
- package/plugins/kimi-codex/dist/hooks/install.js +206 -11
- package/plugins/kimi-codex/dist/hooks/managed-block.js +78 -33
- package/plugins/kimi-codex/dist/job-store.js +100 -128
- package/plugins/kimi-codex/dist/jobs.js +14 -19
- package/plugins/kimi-codex/dist/kimi-command.js +74 -1
- package/plugins/kimi-codex/dist/kimi-engine.js +170 -75
- package/plugins/kimi-codex/dist/kimi-errors.js +14 -69
- package/plugins/kimi-codex/dist/kimi-home.js +6 -0
- package/plugins/kimi-codex/dist/kimi-journal.js +41 -0
- package/plugins/kimi-codex/dist/kimi-releases.js +144 -0
- package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -1
- package/plugins/kimi-codex/dist/kimi-version-probe.js +12 -48
- package/plugins/kimi-codex/dist/mcp/job-control.js +4 -6
- package/plugins/kimi-codex/dist/mcp/launcher.js +12 -6
- package/plugins/kimi-codex/dist/mcp/operations.js +50 -18
- package/plugins/kimi-codex/dist/mcp/protocol.js +16 -14
- package/plugins/kimi-codex/dist/mcp/stdio.js +3 -2
- package/plugins/kimi-codex/dist/model-command.js +5 -3
- package/plugins/kimi-codex/dist/native-v2-preflight.js +139 -68
- package/plugins/kimi-codex/dist/parsing.js +171 -237
- package/plugins/kimi-codex/dist/paths.js +8 -0
- 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 +46 -9
- package/plugins/kimi-codex/dist/rescue-approval.js +461 -84
- package/plugins/kimi-codex/dist/schemas/review-gate-output.js +3 -5
- package/plugins/kimi-codex/dist/session-title.js +25 -5
- package/plugins/kimi-codex/dist/stream-json.js +1 -3
- package/plugins/kimi-codex/dist/surface-routing.js +21 -0
- package/plugins/kimi-codex/dist/swarm-activation.js +72 -75
- 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/skills/kimi-pursue/SKILL.md +1 -1
- package/plugins/kimi-codex/skills/kimi-review/SKILL.md +8 -7
- package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +1 -1
- package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +2 -1
- package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +8 -6
- package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +1 -1
- package/plugins/kimi-codex/skills/{kimi-ask → kimi-task}/SKILL.md +11 -9
- package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +6 -0
- package/plugins/kimi-dsh/README.md +3 -2
- package/plugins/kimi-dsh/dist/background-spawn.js +10 -17
- package/plugins/kimi-dsh/dist/cli-client.js +65 -46
- package/plugins/kimi-dsh/dist/commands/ask.js +22 -89
- package/plugins/kimi-dsh/dist/commands/cancel.js +7 -46
- package/plugins/kimi-dsh/dist/commands/cli-helpers.js +102 -1
- package/plugins/kimi-dsh/dist/commands/models.js +2 -3
- package/plugins/kimi-dsh/dist/commands/pursue.js +5 -19
- package/plugins/kimi-dsh/dist/commands/repair-sessions.js +118 -12
- package/plugins/kimi-dsh/dist/commands/rescue.js +12 -82
- package/plugins/kimi-dsh/dist/commands/result.js +7 -1
- package/plugins/kimi-dsh/dist/commands/review-gate.js +1 -0
- package/plugins/kimi-dsh/dist/commands/review.js +12 -15
- package/plugins/kimi-dsh/dist/commands/setup.js +606 -270
- package/plugins/kimi-dsh/dist/commands/status.js +2 -2
- package/plugins/kimi-dsh/dist/commands/swarm.js +93 -119
- package/plugins/kimi-dsh/dist/commands/worker.js +1 -2
- package/plugins/kimi-dsh/dist/companion.js +3 -1
- package/plugins/kimi-dsh/dist/dsh/index.js +15 -17
- package/plugins/kimi-dsh/dist/git.js +1 -9
- package/plugins/kimi-dsh/dist/help.js +3 -3
- package/plugins/kimi-dsh/dist/hooks/approval-hook.js +41 -0
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +72 -10
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +19 -43
- package/plugins/kimi-dsh/dist/hooks/hook-timing.js +48 -0
- package/plugins/kimi-dsh/dist/hooks/install.js +206 -11
- package/plugins/kimi-dsh/dist/hooks/managed-block.js +78 -33
- package/plugins/kimi-dsh/dist/job-store.js +100 -128
- package/plugins/kimi-dsh/dist/jobs.js +14 -19
- package/plugins/kimi-dsh/dist/kimi-command.js +74 -1
- package/plugins/kimi-dsh/dist/kimi-engine.js +170 -75
- package/plugins/kimi-dsh/dist/kimi-errors.js +14 -69
- package/plugins/kimi-dsh/dist/kimi-home.js +6 -0
- package/plugins/kimi-dsh/dist/kimi-journal.js +41 -0
- package/plugins/kimi-dsh/dist/kimi-releases.js +144 -0
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +1 -1
- package/plugins/kimi-dsh/dist/kimi-version-probe.js +12 -48
- package/plugins/kimi-dsh/dist/mcp/job-control.js +4 -6
- package/plugins/kimi-dsh/dist/mcp/launcher.js +12 -6
- package/plugins/kimi-dsh/dist/mcp/operations.js +50 -18
- package/plugins/kimi-dsh/dist/mcp/protocol.js +16 -14
- package/plugins/kimi-dsh/dist/mcp/stdio.js +3 -2
- package/plugins/kimi-dsh/dist/model-command.js +5 -3
- package/plugins/kimi-dsh/dist/native-v2-preflight.js +139 -68
- package/plugins/kimi-dsh/dist/parsing.js +171 -237
- package/plugins/kimi-dsh/dist/paths.js +8 -0
- package/plugins/kimi-dsh/dist/process-tree.js +35 -24
- package/plugins/kimi-dsh/dist/read-scope.js +435 -0
- package/plugins/kimi-dsh/dist/render.js +46 -9
- package/plugins/kimi-dsh/dist/rescue-approval.js +461 -84
- package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +3 -5
- package/plugins/kimi-dsh/dist/session-title.js +25 -5
- package/plugins/kimi-dsh/dist/stream-json.js +1 -3
- package/plugins/kimi-dsh/dist/surface-routing.js +21 -0
- package/plugins/kimi-dsh/dist/swarm-activation.js +72 -75
- package/plugins/kimi-dsh/dist/swarm-policy.js +2 -1
- package/plugins/kimi-dsh/dist/swarm-recovery.js +2 -1
- package/plugins/kimi-dsh/dist/util.js +28 -0
- package/plugins/kimi-dsh/dist/version.js +1 -1
- package/plugins/kimi-dsh/package.json +1 -1
- package/agents/kimi-challenge.md +0 -86
- package/agents/kimi-rescue.md +0 -92
- package/agents/kimi-swarm-write.md +0 -96
- package/commands/ask.md +0 -38
- package/commands/challenge.md +0 -35
- package/dist/commands/not-implemented.js +0 -4
- package/plugins/kimi-codex/dist/commands/not-implemented.js +0 -4
- package/plugins/kimi-codex/skills/kimi-ask/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-rescue/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-rescue/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/dist/commands/not-implemented.js +0 -4
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RuntimeError } from "../errors.js";
|
|
2
|
+
import { kimiVersionsWith } from "../kimi-releases.js";
|
|
2
3
|
import { parseDurationMs, validateThinkingEffort } from "../parsing.js";
|
|
3
4
|
const WORKSPACE_PROPERTY = {
|
|
4
5
|
type: "string",
|
|
@@ -44,6 +45,22 @@ const OBJECTIVE_PROPERTY = {
|
|
|
44
45
|
type: "string",
|
|
45
46
|
description: "The complete objective, preserved verbatim.",
|
|
46
47
|
};
|
|
48
|
+
const SCOPE_PROPERTIES = {
|
|
49
|
+
read_roots: {
|
|
50
|
+
type: "array",
|
|
51
|
+
items: { type: "string" },
|
|
52
|
+
description: "Absolute directories Kimi may also read. Omit for the default read scope.",
|
|
53
|
+
},
|
|
54
|
+
network: {
|
|
55
|
+
type: "boolean",
|
|
56
|
+
description: "Enable web search and URL fetch; file reads are then confined to the workspace plus read_roots. Default false.",
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const REVIEW_MODE_PROPERTY = {
|
|
60
|
+
type: "string",
|
|
61
|
+
enum: ["defects", "challenge"],
|
|
62
|
+
description: "defects (default) reviews for bugs and regressions; challenge questions assumptions, design choices, and tradeoffs instead.",
|
|
63
|
+
};
|
|
47
64
|
const FOCUS_PROPERTY = {
|
|
48
65
|
type: "string",
|
|
49
66
|
description: "Optional review focus or adversarial framing, preserved verbatim.",
|
|
@@ -65,7 +82,7 @@ const CAP_PROPERTY = {
|
|
|
65
82
|
const MAX_CONCURRENCY_PROPERTY = {
|
|
66
83
|
type: "integer",
|
|
67
84
|
minimum: 1,
|
|
68
|
-
description:
|
|
85
|
+
description: `Concurrent worker limit on exact Kimi Code ${kimiVersionsWith("bounded-swarm").join("/")}: 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
86
|
};
|
|
70
87
|
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
88
|
function schema(properties, required = []) {
|
|
@@ -77,21 +94,14 @@ const OPERATION_SPECS = {
|
|
|
77
94
|
command: ["ask"],
|
|
78
95
|
write: false,
|
|
79
96
|
summary: "Start an independent read-only Kimi repository explanation.",
|
|
80
|
-
inputSchema: schema({ ...COMMON_PROPERTIES, prompt: PROMPT_PROPERTY, ...RESUME_PROPERTIES }),
|
|
97
|
+
inputSchema: schema({ ...COMMON_PROPERTIES, ...SCOPE_PROPERTIES, prompt: PROMPT_PROPERTY, ...RESUME_PROPERTIES }),
|
|
81
98
|
},
|
|
82
99
|
kimi_review: {
|
|
83
100
|
kind: "review",
|
|
84
101
|
command: ["review"],
|
|
85
102
|
write: false,
|
|
86
|
-
summary: "Start an independent read-only Kimi review of working-tree changes, including untracked files, or a committed base diff.",
|
|
87
|
-
inputSchema: schema({ ...COMMON_PROPERTIES, base: BASE_PROPERTY, focus: FOCUS_PROPERTY }),
|
|
88
|
-
},
|
|
89
|
-
kimi_challenge: {
|
|
90
|
-
kind: "challenge",
|
|
91
|
-
command: ["task", "challenge"],
|
|
92
|
-
write: false,
|
|
93
|
-
summary: "Start a read-only Kimi challenge of assumptions, design choices, and tradeoffs rather than a defect-only review.",
|
|
94
|
-
inputSchema: schema({ ...COMMON_PROPERTIES, base: BASE_PROPERTY, focus: FOCUS_PROPERTY }),
|
|
103
|
+
summary: "Start an independent read-only Kimi review of working-tree changes, including untracked files, or a committed base diff. Mode challenge questions the approach instead of hunting defects.",
|
|
104
|
+
inputSchema: schema({ ...COMMON_PROPERTIES, ...SCOPE_PROPERTIES, mode: REVIEW_MODE_PROPERTY, base: BASE_PROPERTY, focus: FOCUS_PROPERTY }),
|
|
95
105
|
},
|
|
96
106
|
kimi_rescue: {
|
|
97
107
|
kind: "rescue",
|
|
@@ -112,7 +122,7 @@ const OPERATION_SPECS = {
|
|
|
112
122
|
command: ["task", "swarm"],
|
|
113
123
|
write: false,
|
|
114
124
|
summary: "Start a read-only parallel Kimi fan-out across many independent review targets.",
|
|
115
|
-
inputSchema: schema({ ...COMMON_PROPERTIES, objective: OBJECTIVE_PROPERTY, cap: CAP_PROPERTY, max_concurrency: MAX_CONCURRENCY_PROPERTY }, ["objective"]),
|
|
125
|
+
inputSchema: schema({ ...COMMON_PROPERTIES, ...SCOPE_PROPERTIES, objective: OBJECTIVE_PROPERTY, cap: CAP_PROPERTY, max_concurrency: MAX_CONCURRENCY_PROPERTY }, ["objective"]),
|
|
116
126
|
},
|
|
117
127
|
kimi_swarm_write: {
|
|
118
128
|
kind: "swarm-write",
|
|
@@ -166,9 +176,12 @@ export function buildMcpOperationInvocation(name, input) {
|
|
|
166
176
|
const properties = spec.inputSchema.properties;
|
|
167
177
|
const args = readArguments(input, Object.keys(properties));
|
|
168
178
|
const workspace = optionalString(args, "workspace");
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
179
|
+
const challenge = name === "kimi_review" && reviewMode(args) === "challenge";
|
|
180
|
+
const kind = challenge ? "challenge" : spec.kind;
|
|
181
|
+
const argv = challenge ? ["task", "challenge"] : [...spec.command];
|
|
182
|
+
appendCommonOptions(argv, args, kind === "pursue" || kind === "swarm" || kind === "swarm-write" ? "safety" : "response");
|
|
183
|
+
appendScopeOptions(argv, args);
|
|
184
|
+
switch (kind) {
|
|
172
185
|
case "ask":
|
|
173
186
|
case "rescue": {
|
|
174
187
|
const prompt = args.prompt === undefined ? undefined : requiredNonEmptyString(args, "prompt");
|
|
@@ -185,7 +198,7 @@ export function buildMcpOperationInvocation(name, input) {
|
|
|
185
198
|
throw invalidArguments("resume uses the standard continuation instruction and cannot include prompt. Use resume_latest with a new prompt instead.");
|
|
186
199
|
}
|
|
187
200
|
if (prompt === undefined && !resumeLatest && resume === undefined) {
|
|
188
|
-
throw invalidArguments(`${
|
|
201
|
+
throw invalidArguments(`${kind} requires prompt unless resume or resume_latest is selected.`);
|
|
189
202
|
}
|
|
190
203
|
if (fresh)
|
|
191
204
|
argv.push("--fresh");
|
|
@@ -222,13 +235,13 @@ export function buildMcpOperationInvocation(name, input) {
|
|
|
222
235
|
argv.push("--cap", String(cap));
|
|
223
236
|
if (maxConcurrency !== undefined)
|
|
224
237
|
argv.push("--max-concurrency", String(maxConcurrency));
|
|
225
|
-
if (
|
|
238
|
+
if (kind === "swarm-write")
|
|
226
239
|
argv.push("--write");
|
|
227
240
|
argv.push("--", requiredNonEmptyString(args, "objective"));
|
|
228
241
|
break;
|
|
229
242
|
}
|
|
230
243
|
}
|
|
231
|
-
return { operationKind:
|
|
244
|
+
return { operationKind: kind, ...(workspace !== undefined ? { workspace } : {}), argv };
|
|
232
245
|
}
|
|
233
246
|
export function readJobControlArguments(input) {
|
|
234
247
|
const args = readArguments(input, ["workspace", "job_id"]);
|
|
@@ -252,6 +265,25 @@ function appendCommonOptions(argv, args, budgetKind) {
|
|
|
252
265
|
argv.push("--thinking", thinking);
|
|
253
266
|
}
|
|
254
267
|
}
|
|
268
|
+
function reviewMode(args) {
|
|
269
|
+
const mode = optionalString(args, "mode") ?? "defects";
|
|
270
|
+
if (mode !== "defects" && mode !== "challenge")
|
|
271
|
+
throw invalidArguments('mode must be "defects" or "challenge".');
|
|
272
|
+
return mode;
|
|
273
|
+
}
|
|
274
|
+
/** Type checks only: the companion parser and read-scope resolver own every scope rule. */
|
|
275
|
+
function appendScopeOptions(argv, args) {
|
|
276
|
+
const readRoots = args.read_roots;
|
|
277
|
+
if (readRoots !== undefined) {
|
|
278
|
+
if (!Array.isArray(readRoots) || readRoots.some((root) => typeof root !== "string")) {
|
|
279
|
+
throw invalidArguments("read_roots must be an array of strings.");
|
|
280
|
+
}
|
|
281
|
+
for (const root of readRoots)
|
|
282
|
+
argv.push("--read-root", root);
|
|
283
|
+
}
|
|
284
|
+
if (optionalBoolean(args, "network") === true)
|
|
285
|
+
argv.push("--network");
|
|
286
|
+
}
|
|
255
287
|
function readArguments(input, allowedKeys) {
|
|
256
288
|
if (input === undefined)
|
|
257
289
|
return {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { formatError, RuntimeError } from "../errors.js";
|
|
2
|
+
import { isRecord } from "../util.js";
|
|
2
3
|
import { KIMI_PLUGIN_CC_VERSION } from "../version.js";
|
|
3
|
-
import { cancelMcpJob, getMcpJobResult, getMcpJobStatus, getMcpTaskView } from "./job-control.js";
|
|
4
|
+
import { cancelMcpJob, getMcpJobResult, getMcpJobStatus, getMcpTaskView, taskView } from "./job-control.js";
|
|
4
5
|
import { launchMcpOperation } from "./launcher.js";
|
|
5
6
|
import { buildMcpOperationInvocation, isMcpModelToolName, MCP_TOOL_DEFINITIONS, } from "./operations.js";
|
|
6
7
|
import { textResult } from "./tool-result.js";
|
|
@@ -11,6 +12,15 @@ const CLIENT_INFO_META = "io.modelcontextprotocol/clientInfo";
|
|
|
11
12
|
const CLIENT_CAPABILITIES_META = "io.modelcontextprotocol/clientCapabilities";
|
|
12
13
|
const TASKS_EXTENSION = "io.modelcontextprotocol/tasks";
|
|
13
14
|
const SERVER_INFO_META = "io.modelcontextprotocol/serverInfo";
|
|
15
|
+
// Every supported version permits `instructions`: InitializeResult since 2024-11-05, DiscoverResult in 2026-07-28.
|
|
16
|
+
export const MCP_SERVER_INSTRUCTIONS = [
|
|
17
|
+
"Prefer these tools for detached or long-running Kimi work.",
|
|
18
|
+
"Each model tool starts a durable job that keeps running if this connection drops; reconnect and look it up by job_id.",
|
|
19
|
+
"Where the host supports MCP tasks, completion arrives as a task notification; otherwise poll kimi_job_status and kimi_job_result with the returned job_id, and stop a job with kimi_job_cancel.",
|
|
20
|
+
"kimi_ask, kimi_review and kimi_swarm are read-only. kimi_rescue and kimi_pursue edit the workspace, never git; kimi_swarm_write edits a disposable worktree and returns a patch it never applies.",
|
|
21
|
+
"Use a write tool only when the user asked for edits, and kimi_pursue only for an explicitly autonomous objective.",
|
|
22
|
+
"A result may carry warnings, such as an uncertified Kimi release or workspace trust being off; relay them to the user.",
|
|
23
|
+
].join(" ");
|
|
14
24
|
export function createMcpMessageHandler(env) {
|
|
15
25
|
let mode;
|
|
16
26
|
return async (message) => {
|
|
@@ -31,6 +41,7 @@ export function createMcpMessageHandler(env) {
|
|
|
31
41
|
resultType: "complete",
|
|
32
42
|
supportedVersions: [MODERN_VERSION],
|
|
33
43
|
capabilities: { tools: {}, extensions: { [TASKS_EXTENSION]: {} } },
|
|
44
|
+
instructions: MCP_SERVER_INSTRUCTIONS,
|
|
34
45
|
_meta: { [SERVER_INFO_META]: { name: "kimi-plugin-cc", version: KIMI_PLUGIN_CC_VERSION } },
|
|
35
46
|
ttlMs: 0,
|
|
36
47
|
cacheScope: "private",
|
|
@@ -46,6 +57,7 @@ export function createMcpMessageHandler(env) {
|
|
|
46
57
|
protocolVersion: requested,
|
|
47
58
|
capabilities: { tools: {} },
|
|
48
59
|
serverInfo: { name: "kimi-plugin-cc", version: KIMI_PLUGIN_CC_VERSION },
|
|
60
|
+
instructions: MCP_SERVER_INSTRUCTIONS,
|
|
49
61
|
});
|
|
50
62
|
}
|
|
51
63
|
if (method === "notifications/initialized")
|
|
@@ -167,16 +179,9 @@ function launchResult(launched) {
|
|
|
167
179
|
return textResult(`Started ${task.operation_kind} job ${task.task_id}. This is a launch handle, not the finished answer. Use kimi_job_status and kimi_job_result with this job_id until the job is terminal; use kimi_job_cancel to stop it.`, metadata);
|
|
168
180
|
}
|
|
169
181
|
function taskHandle({ task, job }) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
status: job.status === "running" ? "working" : job.status === "cancelled" ? "cancelled" : "completed",
|
|
174
|
-
...(job.status === "running" ? { statusMessage: `${task.operation_kind}: ${job.phase ?? "running"}` } : job.summary ? { statusMessage: job.summary } : {}),
|
|
175
|
-
createdAt: task.created_at,
|
|
176
|
-
lastUpdatedAt: job.updated_at,
|
|
177
|
-
ttlMs: null,
|
|
178
|
-
pollIntervalMs: 2_000,
|
|
179
|
-
};
|
|
182
|
+
const status = job.status === "running" ? "working" : job.status === "cancelled" ? "cancelled" : "completed";
|
|
183
|
+
const statusMessage = job.status === "running" ? `${task.operation_kind}: ${job.phase ?? "running"}` : job.summary;
|
|
184
|
+
return { resultType: "task", ...taskView(task, job, status, undefined, statusMessage) };
|
|
180
185
|
}
|
|
181
186
|
function parseRequest(message) {
|
|
182
187
|
if (!isRecord(message))
|
|
@@ -270,6 +275,3 @@ class McpJsonRpcError extends Error {
|
|
|
270
275
|
function isRpcError(error) {
|
|
271
276
|
return error instanceof McpJsonRpcError || (error instanceof Error && "code" in error && typeof error.code === "number");
|
|
272
277
|
}
|
|
273
|
-
function isRecord(value) {
|
|
274
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
275
|
-
}
|
|
@@ -37,11 +37,12 @@ export async function serveMcpStdio(input, output, handle) {
|
|
|
37
37
|
buffer = buffer.subarray(newline + 1);
|
|
38
38
|
if (line.length > MAX_MESSAGE_BYTES)
|
|
39
39
|
throw new Error("MCP frame exceeds 8 MiB");
|
|
40
|
-
|
|
40
|
+
const text = line.toString("utf8");
|
|
41
|
+
if (text.trim().length === 0)
|
|
41
42
|
continue;
|
|
42
43
|
let parsed;
|
|
43
44
|
try {
|
|
44
|
-
parsed = JSON.parse(
|
|
45
|
+
parsed = JSON.parse(text);
|
|
45
46
|
}
|
|
46
47
|
catch {
|
|
47
48
|
track(write({ jsonrpc: "2.0", id: null, error: { code: -32_700, message: "Parse error" } }));
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { runAsk } from "./commands/ask.js";
|
|
2
|
-
import { notImplementedCompanionCommand } from "./commands/not-implemented.js";
|
|
3
2
|
import { runPursue } from "./commands/pursue.js";
|
|
4
3
|
import { runRescue } from "./commands/rescue.js";
|
|
5
4
|
import { runReview } from "./commands/review.js";
|
|
6
5
|
import { runSwarm } from "./commands/swarm.js";
|
|
6
|
+
import { RuntimeError } from "./errors.js";
|
|
7
7
|
export async function runModelCommand(argv, context) {
|
|
8
8
|
const [command, ...rest] = argv;
|
|
9
9
|
switch (command) {
|
|
@@ -22,8 +22,10 @@ export async function runModelCommand(argv, context) {
|
|
|
22
22
|
return runPursue(taskArgs, context);
|
|
23
23
|
case "swarm":
|
|
24
24
|
return runSwarm(taskArgs, context);
|
|
25
|
-
default:
|
|
26
|
-
|
|
25
|
+
default: {
|
|
26
|
+
const label = taskType ? `task ${taskType}` : "task";
|
|
27
|
+
throw new RuntimeError("NOT_IMPLEMENTED", `Companion subcommand ${label} is not implemented.`, label);
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
default:
|
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
// B. the EnterPlanMode tool (already hook-denied for every label);
|
|
14
14
|
// C. resuming a session whose agent wire journal holds a durable
|
|
15
15
|
// `plan_mode.enter` record (restore() folds ONLY agents/*/wire.jsonl).
|
|
16
|
-
// This module closes A and C before any process is spawned
|
|
17
|
-
//
|
|
18
|
-
//
|
|
16
|
+
// This module closes A and C before any process is spawned and requires
|
|
17
|
+
// local execution for configured and resumed sessions. The v2-only
|
|
18
|
+
// experimental features (tower, subagent fork) are forced off for every
|
|
19
|
+
// child by per-flag env in cli-client.ts; only an uncertified release, whose
|
|
20
|
+
// flag names are unreviewed, still refuses an enabled selector here.
|
|
19
21
|
// B stays in runtime/hooks/approval-policy.ts.
|
|
20
22
|
//
|
|
21
23
|
// Contract:
|
|
@@ -29,8 +31,11 @@
|
|
|
29
31
|
import { constants as fsConstants } from "node:fs";
|
|
30
32
|
import { open, readdir } from "node:fs/promises";
|
|
31
33
|
import path from "node:path";
|
|
32
|
-
import { createInterface } from "node:readline";
|
|
33
34
|
import { RuntimeError } from "./errors.js";
|
|
35
|
+
import { kimiCodeConfigPath } from "./kimi-home.js";
|
|
36
|
+
import { kimiJournalRecords, UNPARSEABLE_JOURNAL_LINE } from "./kimi-journal.js";
|
|
37
|
+
import { kimiCertifiedReleaseHas } from "./kimi-releases.js";
|
|
38
|
+
import { tomlErrorLocation } from "./util.js";
|
|
34
39
|
import { parse as parseToml } from "./vendor/smol-toml/parse.js";
|
|
35
40
|
/** `<kimiHome>/config.toml` is small hand-edited config, never a data file. */
|
|
36
41
|
const CONFIG_MAX_BYTES = 1 * 1024 * 1024;
|
|
@@ -91,7 +96,7 @@ async function readSmallFileSafe(filePath, maxBytes) {
|
|
|
91
96
|
/** Read+parse `<kimiHome>/config.toml`. `config: null` means the file is
|
|
92
97
|
* absent (upstream default applies); any read/parse failure fails closed. */
|
|
93
98
|
async function readParsedConfig(kimiHome) {
|
|
94
|
-
const configPath =
|
|
99
|
+
const configPath = kimiCodeConfigPath(kimiHome);
|
|
95
100
|
const read = await readSmallFileSafe(configPath, CONFIG_MAX_BYTES);
|
|
96
101
|
if (read.kind === "absent")
|
|
97
102
|
return { kind: "ok", config: null };
|
|
@@ -104,7 +109,7 @@ async function readParsedConfig(kimiHome) {
|
|
|
104
109
|
catch (error) {
|
|
105
110
|
return {
|
|
106
111
|
kind: "unreadable",
|
|
107
|
-
reason: `${configPath} could not be parsed as TOML: ${error
|
|
112
|
+
reason: `${configPath} could not be parsed as TOML: ${tomlErrorLocation(error)}`,
|
|
108
113
|
};
|
|
109
114
|
}
|
|
110
115
|
}
|
|
@@ -149,14 +154,23 @@ export async function inspectPlanModeConfig(kimiHome) {
|
|
|
149
154
|
const offending = matching.filter(([, value]) => value !== false).map(([rawKey]) => rawKey);
|
|
150
155
|
if (offending.length === 0)
|
|
151
156
|
return { kind: "ok", setting: "false" };
|
|
152
|
-
const configPath =
|
|
157
|
+
const configPath = kimiCodeConfigPath(kimiHome);
|
|
153
158
|
return {
|
|
154
159
|
kind: "refuse",
|
|
155
160
|
refusalKind: "v2-plan-mode-configured",
|
|
156
161
|
reason: `\`${offending.join("`, `")}\` (upstream setting \`default_plan_mode\`) is set in ${configPath} and is not \`false\`.`,
|
|
157
162
|
};
|
|
158
163
|
}
|
|
159
|
-
|
|
164
|
+
/**
|
|
165
|
+
* `allowDefaultEnvironment`: upstream reads `environments.default` only in
|
|
166
|
+
* sessionManagerService.openCreation, i.e. when a session is created. A fresh
|
|
167
|
+
* print on a certified row passes `--environment local`, which skips the
|
|
168
|
+
* declarations; a resume goes through doResume, which applies the session's
|
|
169
|
+
* stored binding (state.json) and never consults the default (2.5.0-2.7.3).
|
|
170
|
+
* The stored binding is checked separately by scanSessionJournalsForPlan, so
|
|
171
|
+
* that one key stops refusing. A non-table section still refuses.
|
|
172
|
+
*/
|
|
173
|
+
export async function inspectEnvironmentConfig(kimiHome, options = {}) {
|
|
160
174
|
const parsed = await readParsedConfig(kimiHome);
|
|
161
175
|
if (parsed.kind === "unreadable") {
|
|
162
176
|
return { kind: "refuse", refusalKind: "v2-config-unreadable", reason: parsed.reason };
|
|
@@ -170,7 +184,7 @@ export async function inspectEnvironmentConfig(kimiHome) {
|
|
|
170
184
|
reason: "The [environments] section is not a table, so the execution environment cannot be verified as local.",
|
|
171
185
|
};
|
|
172
186
|
}
|
|
173
|
-
if (section["default"] !== undefined) {
|
|
187
|
+
if (options.allowDefaultEnvironment !== true && section["default"] !== undefined) {
|
|
174
188
|
return {
|
|
175
189
|
kind: "refuse",
|
|
176
190
|
refusalKind: "v2-environment-configured",
|
|
@@ -187,17 +201,24 @@ export async function inspectEnvironmentConfig(kimiHome) {
|
|
|
187
201
|
reason: "The [workspace] section is not a table, so project trust requirements cannot be verified.",
|
|
188
202
|
};
|
|
189
203
|
}
|
|
190
|
-
const
|
|
191
|
-
|
|
204
|
+
const trustValues = Object.entries(workspace)
|
|
205
|
+
.filter(([key]) => upstreamSnakeToCamel(key) === "requireTrust")
|
|
206
|
+
.map(([, value]) => value);
|
|
207
|
+
// Literal false is the user's own choice and becomes a warning; any other
|
|
208
|
+
// non-true value is malformed and still refuses.
|
|
209
|
+
if (trustValues.some((value) => value !== true && value !== false)) {
|
|
192
210
|
return {
|
|
193
211
|
kind: "refuse",
|
|
194
212
|
refusalKind: "v2-workspace-trust-disabled",
|
|
195
|
-
reason: "
|
|
213
|
+
reason: "[workspace] require_trust is not a boolean, so project trust requirements cannot be verified.",
|
|
196
214
|
};
|
|
197
215
|
}
|
|
216
|
+
if (trustValues.includes(false))
|
|
217
|
+
return { kind: "ok", trustDisabled: true };
|
|
198
218
|
}
|
|
199
219
|
return { kind: "ok" };
|
|
200
220
|
}
|
|
221
|
+
export const WORKSPACE_TRUST_DISABLED_WARNING = "Workspace trust is disabled in kimi-code's config: MCP servers configured by this repository can start outside the plugin's hook.";
|
|
201
222
|
/**
|
|
202
223
|
* Refuse v2-only experimental features this plugin does not certify.
|
|
203
224
|
* Sources (per-flag precedence upstream is env → [experimental] config →
|
|
@@ -282,46 +303,80 @@ async function openJournalSafely(journalPath, maxBytes) {
|
|
|
282
303
|
}
|
|
283
304
|
return { kind: "ok", handle };
|
|
284
305
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
306
|
+
/** Records that mean the session already did work: a turn, prompt, tool, model or delegated task. */
|
|
307
|
+
const ACTIVITY_RECORD = /^(turn\.|prompt\.|tool\.|llm\.|shell\.|subagent\.|task\.|assistant\.|context\.append_message$|context\.append_loop_event$)/;
|
|
308
|
+
/** Records that make replay non-linear (branch switch or undo), so a fold could differ. */
|
|
309
|
+
const REWIND_RECORD = /^(agent\.switched$|context\.undo$|context\.undone$)/;
|
|
310
|
+
async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelledDefaultEnter = false) {
|
|
311
|
+
// G2: a print-created session's main journal holds the create-time
|
|
312
|
+
// `default_plan_mode` enter immediately followed by print's id-less cancel,
|
|
313
|
+
// before any work. On a linear journal that pair folds to inactive, so it
|
|
314
|
+
// alone is tolerated; every other plan record, or that pair anywhere else,
|
|
315
|
+
// still taints.
|
|
316
|
+
// Replay stops at the first corrupt line, so records after it may add
|
|
317
|
+
// taints (seeing more is conservative) but never start or complete a fold.
|
|
318
|
+
let sawActivity = false;
|
|
319
|
+
let sawRewind = false;
|
|
320
|
+
let sawCorrupt = false;
|
|
321
|
+
let pendingEnter = null;
|
|
322
|
+
let toleratedPair = false;
|
|
323
|
+
const taintEnter = { kind: "tainted", recordType: "plan_mode.enter" };
|
|
324
|
+
for await (const framed of kimiJournalRecords(handle.createReadStream())) {
|
|
325
|
+
const { line, parsed } = framed;
|
|
326
|
+
if (parsed === UNPARSEABLE_JOURNAL_LINE) {
|
|
327
|
+
if (framed.terminated)
|
|
328
|
+
sawCorrupt = true;
|
|
329
|
+
if (pendingEnter !== null)
|
|
330
|
+
return taintEnter;
|
|
331
|
+
if (line.includes('"plan_mode.') || line.includes('"plan.')) {
|
|
332
|
+
return { kind: "tainted", recordType: "<unparseable>" };
|
|
333
|
+
}
|
|
334
|
+
if (line.includes('"environment.set_binding')) {
|
|
335
|
+
return { kind: "environment", recordType: "<unparseable-environment-binding>" };
|
|
295
336
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const record = parsed;
|
|
340
|
+
const type = record?.["type"];
|
|
341
|
+
if (pendingEnter !== null) {
|
|
342
|
+
const cancelId = record?.["id"];
|
|
343
|
+
const cancels = type === "plan_mode.cancel" && record?.["agentId"] === "main" &&
|
|
344
|
+
(cancelId === undefined || cancelId === pendingEnter.id);
|
|
345
|
+
if (!cancels)
|
|
346
|
+
return taintEnter;
|
|
347
|
+
pendingEnter = null;
|
|
348
|
+
toleratedPair = true;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (typeof type === "string" && REWIND_RECORD.test(type)) {
|
|
352
|
+
if (toleratedPair)
|
|
353
|
+
return taintEnter;
|
|
354
|
+
sawRewind = true;
|
|
355
|
+
}
|
|
356
|
+
if (typeof type === "string" && ACTIVITY_RECORD.test(type))
|
|
357
|
+
sawActivity = true;
|
|
358
|
+
if (typeof type === "string" && (type.startsWith("plan_mode.") || type.startsWith("plan."))) {
|
|
359
|
+
if (tolerateCancelledDefaultEnter && type === "plan_mode.enter" && !toleratedPair &&
|
|
360
|
+
!sawActivity && !sawRewind && !sawCorrupt && record?.["agentId"] === "main" && typeof record?.["id"] === "string") {
|
|
361
|
+
pendingEnter = { id: record["id"] };
|
|
303
362
|
continue;
|
|
304
363
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
364
|
+
return { kind: "tainted", recordType: type };
|
|
365
|
+
}
|
|
366
|
+
if (type === "environment.set_binding") {
|
|
367
|
+
if (record?.["environmentId"] !== "local") {
|
|
368
|
+
return { kind: "environment", recordType: type };
|
|
309
369
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
const cwd = record?.["cwd"];
|
|
315
|
-
if (expectedExecutionRoot !== undefined && cwd !== undefined && cwd !== expectedExecutionRoot) {
|
|
316
|
-
return { kind: "environment", recordType: "environment.set_binding.cwd" };
|
|
317
|
-
}
|
|
370
|
+
const cwd = record?.["cwd"];
|
|
371
|
+
if (expectedExecutionRoot !== undefined && cwd !== undefined && cwd !== expectedExecutionRoot) {
|
|
372
|
+
return { kind: "environment", recordType: "environment.set_binding.cwd" };
|
|
318
373
|
}
|
|
319
374
|
}
|
|
320
|
-
return null;
|
|
321
|
-
}
|
|
322
|
-
finally {
|
|
323
|
-
rl.close();
|
|
324
375
|
}
|
|
376
|
+
// An enter as the last record was never cancelled.
|
|
377
|
+
if (pendingEnter !== null)
|
|
378
|
+
return taintEnter;
|
|
379
|
+
return null;
|
|
325
380
|
}
|
|
326
381
|
async function inspectSessionMetadataEnvironment(statePath, expectedExecutionRoot) {
|
|
327
382
|
const read = await readSmallFileSafe(statePath, CONFIG_MAX_BYTES);
|
|
@@ -364,7 +419,7 @@ async function inspectSessionMetadataEnvironment(statePath, expectedExecutionRoo
|
|
|
364
419
|
* name `environmentId:"local"`. No session dir, no journal, unreadable metadata,
|
|
365
420
|
* or any single journal above the size cap → unavailable. Never modifies files.
|
|
366
421
|
*/
|
|
367
|
-
export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedExecutionRoot) {
|
|
422
|
+
export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedExecutionRoot, options = {}) {
|
|
368
423
|
const sessionsDir = path.join(kimiHome, "sessions");
|
|
369
424
|
const workspaceEntries = await boundedReaddir(sessionsDir, DIR_ENUM_CAP);
|
|
370
425
|
if (workspaceEntries.kind === "absent") {
|
|
@@ -413,19 +468,19 @@ export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedEx
|
|
|
413
468
|
}
|
|
414
469
|
if (!agentEntry.isDirectory())
|
|
415
470
|
continue;
|
|
416
|
-
journalPaths.push(path.join(agentsDir, agentEntry.name, "wire.jsonl"));
|
|
471
|
+
journalPaths.push({ path: path.join(agentsDir, agentEntry.name, "wire.jsonl"), main: agentEntry.name === "main" });
|
|
417
472
|
}
|
|
418
473
|
}
|
|
419
474
|
if (journalPaths.length === 0) {
|
|
420
475
|
return { kind: "unavailable", reason: `no agent wire journals found for session ${sessionId}` };
|
|
421
476
|
}
|
|
422
|
-
for (const journalPath of journalPaths) {
|
|
477
|
+
for (const { path: journalPath, main } of journalPaths) {
|
|
423
478
|
const opened = await openJournalSafely(journalPath, JOURNAL_MAX_BYTES);
|
|
424
479
|
if (opened.kind === "unavailable") {
|
|
425
480
|
return { kind: "unavailable", reason: `${journalPath}: ${opened.reason}` };
|
|
426
481
|
}
|
|
427
482
|
try {
|
|
428
|
-
const finding = await scanJournalLines(opened.handle, expectedExecutionRoot);
|
|
483
|
+
const finding = await scanJournalLines(opened.handle, expectedExecutionRoot, main && options.tolerateCancelledDefaultEnter === true);
|
|
429
484
|
if (finding?.kind === "tainted") {
|
|
430
485
|
return { kind: "tainted", journal: journalPath, recordType: finding.recordType };
|
|
431
486
|
}
|
|
@@ -437,26 +492,32 @@ export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedEx
|
|
|
437
492
|
await opened.handle.close().catch(() => undefined);
|
|
438
493
|
}
|
|
439
494
|
}
|
|
440
|
-
return { kind: "clean", journals: journalPaths };
|
|
495
|
+
return { kind: "clean", journals: journalPaths.map((journal) => journal.path) };
|
|
496
|
+
}
|
|
497
|
+
/** A non-swarm launch of an exactly certified row that has the capability. */
|
|
498
|
+
function certifiedPrintLaunchHas(options, capability) {
|
|
499
|
+
const release = options.release;
|
|
500
|
+
return release !== undefined &&
|
|
501
|
+
release.certification === "certified" &&
|
|
502
|
+
release.operationKind !== "swarm" &&
|
|
503
|
+
release.operationKind !== "swarm-write" &&
|
|
504
|
+
kimiCertifiedReleaseHas(release.kimiVersion, capability);
|
|
441
505
|
}
|
|
442
|
-
/**
|
|
443
|
-
* Run every inspection and throw a RuntimeError on the first refusal:
|
|
444
|
-
* CLI_V2_PLAN_MODE_CONFIGURED details.refusal_kind = "v2-plan-mode-configured"
|
|
445
|
-
* CLI_V2_CONFIG_UNREADABLE details.refusal_kind = "v2-config-unreadable"
|
|
446
|
-
* CLI_V2_EXPERIMENTAL_UNSAFE details.refusal_kind = "v2-experimental-unsafe", details.selectors
|
|
447
|
-
* CLI_V2_ENVIRONMENT_UNSAFE / CLI_V2_WORKSPACE_TRUST_UNSAFE for unsafe config
|
|
448
|
-
* KIMI_SESSION_ENVIRONMENT_UNSAFE details.refusal_kind = "session-environment-unsafe"
|
|
449
|
-
* KIMI_SESSION_PLAN_TAINTED details.refusal_kind = "session-plan-tainted", details.record_type
|
|
450
|
-
* KIMI_SESSION_JOURNAL_UNAVAILABLE details.refusal_kind = "session-journal-unavailable"
|
|
451
|
-
* Every message carries a truthful remedy (edit the named setting / start a
|
|
452
|
-
* fresh session) and MUST NOT mention /kimi:setup or hook drift.
|
|
453
|
-
* Every details object also carries `retryable_after_setup: false`.
|
|
454
|
-
*/
|
|
455
506
|
export async function assertNativeV2Preflight(options) {
|
|
507
|
+
const warnings = [];
|
|
456
508
|
const stage = options.stage ?? "native-v2.preflight";
|
|
457
|
-
const configPath =
|
|
509
|
+
const configPath = kimiCodeConfigPath(options.kimiHome);
|
|
510
|
+
// On a print-cancels-plan row the setting is read only inside
|
|
511
|
+
// sessionLifecycleService.create(): a fresh print cancels that enter before
|
|
512
|
+
// any turn (run-v2-print.ts), and `-r` on an existing session goes through
|
|
513
|
+
// doResume, which never consults it (a missing id fails, never creates).
|
|
514
|
+
// So the setting no longer refuses there; for a resume the journal scan
|
|
515
|
+
// below remains the gate. An unreadable config still refuses.
|
|
458
516
|
const planMode = await inspectPlanModeConfig(options.kimiHome);
|
|
459
|
-
|
|
517
|
+
const printCancelsPlan = planMode.kind === "refuse" &&
|
|
518
|
+
planMode.refusalKind === "v2-plan-mode-configured" &&
|
|
519
|
+
certifiedPrintLaunchHas(options, "print-cancels-plan");
|
|
520
|
+
if (planMode.kind === "refuse" && !printCancelsPlan) {
|
|
460
521
|
const code = planMode.refusalKind === "v2-plan-mode-configured"
|
|
461
522
|
? "CLI_V2_PLAN_MODE_CONFIGURED"
|
|
462
523
|
: "CLI_V2_CONFIG_UNREADABLE";
|
|
@@ -467,7 +528,9 @@ export async function assertNativeV2Preflight(options) {
|
|
|
467
528
|
details: { refusal_kind: planMode.refusalKind, retryable_after_setup: false },
|
|
468
529
|
});
|
|
469
530
|
}
|
|
470
|
-
const environment = await inspectEnvironmentConfig(options.kimiHome
|
|
531
|
+
const environment = await inspectEnvironmentConfig(options.kimiHome, {
|
|
532
|
+
allowDefaultEnvironment: certifiedPrintLaunchHas(options, "local-environment"),
|
|
533
|
+
});
|
|
471
534
|
if (environment.kind === "refuse") {
|
|
472
535
|
const code = environment.refusalKind === "v2-environment-configured"
|
|
473
536
|
? "CLI_V2_ENVIRONMENT_UNSAFE"
|
|
@@ -483,7 +546,14 @@ export async function assertNativeV2Preflight(options) {
|
|
|
483
546
|
details: { refusal_kind: environment.refusalKind, retryable_after_setup: false },
|
|
484
547
|
});
|
|
485
548
|
}
|
|
486
|
-
|
|
549
|
+
if (environment.trustDisabled === true)
|
|
550
|
+
warnings.push(WORKSPACE_TRUST_DISABLED_WARNING);
|
|
551
|
+
// Certified and test-bypass children run with tower and subagent fork forced
|
|
552
|
+
// off by per-flag env, which outranks config and the master flag on every
|
|
553
|
+
// reviewed release. An uncertified release's flag names are unreviewed.
|
|
554
|
+
const experimental = options.release === undefined || options.release.certification === "uncertified"
|
|
555
|
+
? await inspectExperimentalSelectors(options.kimiHome, options.env)
|
|
556
|
+
: { kind: "ok" };
|
|
487
557
|
if (experimental.kind === "refuse") {
|
|
488
558
|
throw new RuntimeError("CLI_V2_EXPERIMENTAL_UNSAFE", `${experimental.reason} Unset the listed selector(s) before retrying.`, stage, {
|
|
489
559
|
details: {
|
|
@@ -494,7 +564,7 @@ export async function assertNativeV2Preflight(options) {
|
|
|
494
564
|
});
|
|
495
565
|
}
|
|
496
566
|
if (options.resumeSessionId !== undefined) {
|
|
497
|
-
const journalScan = await scanSessionJournalsForPlan(options.kimiHome, options.resumeSessionId, options.expectedExecutionRoot);
|
|
567
|
+
const journalScan = await scanSessionJournalsForPlan(options.kimiHome, options.resumeSessionId, options.expectedExecutionRoot, { tolerateCancelledDefaultEnter: certifiedPrintLaunchHas(options, "print-cancels-plan") });
|
|
498
568
|
if (journalScan.kind === "environment") {
|
|
499
569
|
throw new RuntimeError("KIMI_SESSION_ENVIRONMENT_UNSAFE", `Saved session ${options.resumeSessionId} has an unsafe execution environment binding (${journalScan.recordType} in ${journalScan.journal}). Start a fresh local session; saved session state was not modified.`, stage, {
|
|
500
570
|
details: {
|
|
@@ -522,4 +592,5 @@ export async function assertNativeV2Preflight(options) {
|
|
|
522
592
|
});
|
|
523
593
|
}
|
|
524
594
|
}
|
|
595
|
+
return { warnings };
|
|
525
596
|
}
|