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 { isRecord } from "../util.js";
|
|
2
3
|
const ALLOWED_DECISIONS = new Set(["ALLOW", "BLOCK"]);
|
|
3
4
|
const ALLOWED_SEVERITIES = new Set(["low", "medium", "high"]);
|
|
4
5
|
const ALLOWED_CONFIDENCE = new Set(["low", "medium", "high"]);
|
|
@@ -10,7 +11,7 @@ export function parseReviewGateOutput(text) {
|
|
|
10
11
|
catch (error) {
|
|
11
12
|
throw new RuntimeError("REVIEW_GATE_PARSE_FAILED", `Review gate output is not valid JSON: ${error.message}`, "review_gate.parse", { cause: error });
|
|
12
13
|
}
|
|
13
|
-
if (!
|
|
14
|
+
if (!isRecord(parsed)) {
|
|
14
15
|
throw new RuntimeError("REVIEW_GATE_PARSE_FAILED", "Review gate output must be a JSON object.", "review_gate.parse");
|
|
15
16
|
}
|
|
16
17
|
const { decision, confidence, summary, issues } = parsed;
|
|
@@ -28,7 +29,7 @@ export function parseReviewGateOutput(text) {
|
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
function normalizeIssue(issue, index) {
|
|
31
|
-
if (!
|
|
32
|
+
if (!isRecord(issue)) {
|
|
32
33
|
throw new RuntimeError("REVIEW_GATE_PARSE_FAILED", `Review gate issue ${index + 1} must be an object.`, "review_gate.parse");
|
|
33
34
|
}
|
|
34
35
|
if (typeof issue.title !== "string" ||
|
|
@@ -38,6 +39,3 @@ function normalizeIssue(issue, index) {
|
|
|
38
39
|
}
|
|
39
40
|
return issue;
|
|
40
41
|
}
|
|
41
|
-
function isObject(value) {
|
|
42
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43
|
-
}
|
package/dist/session-title.js
CHANGED
|
@@ -30,7 +30,11 @@ export function normalizeTitleFragment(text) {
|
|
|
30
30
|
}
|
|
31
31
|
/** Mirrors kimi-code 2.0.0 promptMetadataTextFromText: redact BEFORE truncating. */
|
|
32
32
|
export function promptMetadataText(text) {
|
|
33
|
-
const sanitized = text
|
|
33
|
+
const sanitized = sanitizePromptMetadata(text);
|
|
34
|
+
return sanitized ? sanitized.slice(0, 4000) : undefined;
|
|
35
|
+
}
|
|
36
|
+
function sanitizePromptMetadata(text) {
|
|
37
|
+
return text
|
|
34
38
|
.replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?-----END [^-]*PRIVATE KEY-----/gi, "[redacted]")
|
|
35
39
|
.replace(/\b(authorization)\s*:\s*bearer\s+\S+/gi, "$1: Bearer [redacted]")
|
|
36
40
|
.replace(/\b(api[_-]?key|token|secret|password|passwd|pwd)\b\s*[:=]\s*(?:"[^"]*"|'[^']*'|\S+)/gi, "$1=[redacted]")
|
|
@@ -39,7 +43,19 @@ export function promptMetadataText(text) {
|
|
|
39
43
|
.replace(/\p{Cc}+/gu, " ")
|
|
40
44
|
.replace(/\s+/g, " ")
|
|
41
45
|
.trim();
|
|
42
|
-
|
|
46
|
+
}
|
|
47
|
+
const OWN_PROMPT_MIN_PREFIX = 40;
|
|
48
|
+
/**
|
|
49
|
+
* Earlier plugin releases stored the submitted prompt redacted, whitespace-
|
|
50
|
+
* collapsed and capped, so compare normalized forms. A prefix relation counts
|
|
51
|
+
* only when the shorter side is long enough that short native text never does.
|
|
52
|
+
*/
|
|
53
|
+
function isOwnPrompt(existing, ownPrompts) {
|
|
54
|
+
const current = normalizeTitleFragment(existing);
|
|
55
|
+
if (!current)
|
|
56
|
+
return false;
|
|
57
|
+
return ownPrompts.some((prompt) => [normalizeTitleFragment(prompt), sanitizePromptMetadata(prompt)].some((own) => own.length > 0 && (current === own ||
|
|
58
|
+
(Math.min(own.length, current.length) >= OWN_PROMPT_MIN_PREFIX && (own.startsWith(current) || current.startsWith(own))))));
|
|
43
59
|
}
|
|
44
60
|
export function shortenForTitle(text, maxLength) {
|
|
45
61
|
const normalized = normalizeTitleFragment(text);
|
|
@@ -122,9 +138,11 @@ export async function syncKimiSessionTitle(options) {
|
|
|
122
138
|
const generatedTitle = state.titleKind === "generated";
|
|
123
139
|
const next = { ...state };
|
|
124
140
|
const preview = options.promptText === undefined ? undefined : promptMetadataText(options.promptText);
|
|
125
|
-
|
|
141
|
+
const blankPreview = typeof state.lastPrompt !== "string" || !state.lastPrompt.trim();
|
|
142
|
+
if (nativeV2 && preview && (blankPreview || !options.ownPrompts || isOwnPrompt(state.lastPrompt, options.ownPrompts))) {
|
|
126
143
|
next.lastPrompt = preview;
|
|
127
144
|
}
|
|
145
|
+
const replacedPreview = !blankPreview && next.lastPrompt !== state.lastPrompt;
|
|
128
146
|
if (!options.preserveTitle && !customTitle && !generatedTitle) {
|
|
129
147
|
next.title = promptMetadataText(options.title)?.slice(0, KIMI_SESSION_TITLE_MAX_LENGTH) ?? "Kimi Session";
|
|
130
148
|
// Native UI generation must remain eligible; a deterministic fallback is not
|
|
@@ -135,7 +153,7 @@ export async function syncKimiSessionTitle(options) {
|
|
|
135
153
|
}
|
|
136
154
|
const changed = JSON.stringify(next) !== JSON.stringify(state);
|
|
137
155
|
if (options.dryRun)
|
|
138
|
-
return changed ? "would-
|
|
156
|
+
return !changed ? "unchanged" : replacedPreview ? "would-replace-preview" : "would-update";
|
|
139
157
|
try {
|
|
140
158
|
if (changed && !(await writeStateFileAtomic(statePath, `${JSON.stringify(next, null, 2)}\n`, stateFileMode, stateRead.text))) {
|
|
141
159
|
warn(options.stderr, "session metadata sync skipped: state changed concurrently; retry after the session is idle");
|
|
@@ -157,7 +175,9 @@ export async function syncKimiSessionTitle(options) {
|
|
|
157
175
|
return "index-failed";
|
|
158
176
|
}
|
|
159
177
|
}
|
|
160
|
-
|
|
178
|
+
if (changed)
|
|
179
|
+
return replacedPreview ? "preview-replaced" : "updated";
|
|
180
|
+
return customTitle && !options.preserveTitle ? "custom-title" : "unchanged";
|
|
161
181
|
}
|
|
162
182
|
function findSessionIndexEntry(indexText, sessionId, stderr) {
|
|
163
183
|
for (const line of indexText.split(/\r?\n/)) {
|
package/dist/stream-json.js
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
// entering stream-json.
|
|
28
28
|
// - assistant messages are only emitted when content OR tool_calls are
|
|
29
29
|
// non-empty; we still defend against the empty case for resilience.
|
|
30
|
+
import { isRecord } from "./util.js";
|
|
30
31
|
export const MAX_STREAM_JSON_LINE_BYTES = 1_048_576;
|
|
31
32
|
/**
|
|
32
33
|
* Stateful line-buffer parser. Hold partial-line bytes across chunk boundaries.
|
|
@@ -314,9 +315,6 @@ function validateToolResult(parsed, line) {
|
|
|
314
315
|
};
|
|
315
316
|
return { record };
|
|
316
317
|
}
|
|
317
|
-
function isRecord(value) {
|
|
318
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
319
|
-
}
|
|
320
318
|
/**
|
|
321
319
|
* Match kimi-code's stderr session announce line. In stream-json mode this
|
|
322
320
|
* is a 0.1.x compatibility fallback only — kimi 0.2.0+ emits the resume
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { withoutLeadingFlag } from "./parsing.js";
|
|
2
|
+
/**
|
|
3
|
+
* Host wrappers pass user arguments through to `ask` and `review`; a leading
|
|
4
|
+
* `--write` or `--challenge` selects the existing operation. Only the CLI entry
|
|
5
|
+
* point applies this: MCP children run canonical spellings whose operation is
|
|
6
|
+
* already recorded from the tool name.
|
|
7
|
+
*/
|
|
8
|
+
export function routeSurfaceAliases(argv) {
|
|
9
|
+
const [command, ...rest] = argv;
|
|
10
|
+
if (command === "ask") {
|
|
11
|
+
const remaining = withoutLeadingFlag(rest, "--write");
|
|
12
|
+
if (remaining !== undefined)
|
|
13
|
+
return ["task", "rescue", ...remaining];
|
|
14
|
+
}
|
|
15
|
+
if (command === "review") {
|
|
16
|
+
const remaining = withoutLeadingFlag(rest, "--challenge");
|
|
17
|
+
if (remaining !== undefined)
|
|
18
|
+
return ["task", "challenge", ...remaining];
|
|
19
|
+
}
|
|
20
|
+
return [...argv];
|
|
21
|
+
}
|
package/dist/swarm-activation.js
CHANGED
|
@@ -3,18 +3,21 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { constants as fsConstants } from "node:fs";
|
|
4
4
|
import { open } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { buildKimiCliEnvironment, } from "./cli-client.js";
|
|
6
|
+
import { assertWorkspaceSpellable, buildKimiCliEnvironment, } from "./cli-client.js";
|
|
7
7
|
import { RuntimeError } from "./errors.js";
|
|
8
8
|
import { assertPrefixArgsSafe } from "./kimi-command.js";
|
|
9
9
|
import { assertExecutionPlanMatchesSpawn, assertNoUnsafeExperimentalSelector, } from "./kimi-engine.js";
|
|
10
10
|
import { resolveKimiHome } from "./kimi-home.js";
|
|
11
|
+
import { kimiJournalRecords, UNPARSEABLE_JOURNAL_LINE } from "./kimi-journal.js";
|
|
12
|
+
import { kimiReleaseHas, kimiVersionsWith } from "./kimi-releases.js";
|
|
11
13
|
import { assertNativeV2Preflight } from "./native-v2-preflight.js";
|
|
12
14
|
import { usesBoundedSwarmPolicy } from "./swarm-policy.js";
|
|
13
15
|
import { installBoundedSwarmToolPolicy } from "./swarm-tool-policy.js";
|
|
14
|
-
import {
|
|
16
|
+
import { sleep } from "./util.js";
|
|
17
|
+
import { collectDescendantIdentities, collectProcessGroupsIdentities, probeProcessIdentity, retryIncompleteCapture, revalidateProcessIdentities, waitForProcessTreeExit, } from "./process-tree.js";
|
|
15
18
|
// These exact activation entries support candidate integration; production scope is per operation.
|
|
16
|
-
const PREACTIVATION_VERSIONS =
|
|
17
|
-
const JSON_READY_VERSIONS =
|
|
19
|
+
const PREACTIVATION_VERSIONS = kimiVersionsWith("web-preactivation");
|
|
20
|
+
const JSON_READY_VERSIONS = kimiVersionsWith("web-json-ready");
|
|
18
21
|
const KIMI_AGENT_PROTOCOL_VERSION = "1.0.0";
|
|
19
22
|
const READY_TIMEOUT_MS = 10_000;
|
|
20
23
|
const REST_TIMEOUT_MS = 5_000;
|
|
@@ -51,10 +54,7 @@ export async function preactivateSwarmSession(options) {
|
|
|
51
54
|
await verifyLocalEnvironment(web, identity, options.cwd, prepared.expectedVersion, options.signal, failureCode);
|
|
52
55
|
options.onRecoveryEvent?.({ kind: "session", ...identity });
|
|
53
56
|
profileMutationAttempted = true;
|
|
54
|
-
await
|
|
55
|
-
await verifySwarmStatus(web, identity, true, model, prepared.expectedVersion, options.signal, failureCode);
|
|
56
|
-
await shutdownWeb(web, options.signal, failureCode);
|
|
57
|
-
await requireSwarmJournal(prepared.kimiHome, identity, "enter", options.signal, failureCode);
|
|
57
|
+
await setSwarmMode(web, prepared, identity, true, model, options.signal, failureCode);
|
|
58
58
|
if (usesBoundedSwarmPolicy(options.executionPlan) && options.swarmMaxConcurrency > 1) {
|
|
59
59
|
await installBoundedSwarmToolPolicy(prepared.kimiHome, identity, options.signal);
|
|
60
60
|
}
|
|
@@ -99,10 +99,7 @@ export async function deactivateSwarmSession(options) {
|
|
|
99
99
|
web = await startWebChild(options, prepared.env, prepared.expectedVersion, failureCode);
|
|
100
100
|
await verifyMeta(web, prepared.expectedVersion, options.signal, failureCode);
|
|
101
101
|
await verifyLocalEnvironment(web, options, options.cwd, prepared.expectedVersion, options.signal, failureCode);
|
|
102
|
-
await
|
|
103
|
-
await verifySwarmStatus(web, options, false, undefined, prepared.expectedVersion, options.signal, failureCode);
|
|
104
|
-
await shutdownWeb(web, options.signal, failureCode);
|
|
105
|
-
await requireSwarmJournal(prepared.kimiHome, options, "exit", options.signal, failureCode);
|
|
102
|
+
await setSwarmMode(web, prepared, options, false, undefined, options.signal, failureCode);
|
|
106
103
|
options.onRecoveryEvent?.({ kind: "disabled" });
|
|
107
104
|
throwIfAborted(options.signal, failureCode, "swarm-deactivation.complete");
|
|
108
105
|
}
|
|
@@ -114,6 +111,13 @@ export async function deactivateSwarmSession(options) {
|
|
|
114
111
|
throw primary;
|
|
115
112
|
}
|
|
116
113
|
}
|
|
114
|
+
/** Set swarm mode, prove the resulting state, stop the web child, then require the journal record. */
|
|
115
|
+
async function setSwarmMode(web, prepared, identity, active, model, signal, failureCode) {
|
|
116
|
+
await postSwarmProfile(web, identity, active, model, signal, failureCode);
|
|
117
|
+
await verifySwarmStatus(web, identity, active, model, prepared.expectedVersion, signal, failureCode);
|
|
118
|
+
await shutdownWeb(web, signal, failureCode);
|
|
119
|
+
await requireSwarmJournal(prepared.kimiHome, identity, active ? "enter" : "exit", signal, failureCode);
|
|
120
|
+
}
|
|
117
121
|
async function prepareWebSpawn(options, failureCode) {
|
|
118
122
|
throwIfAborted(options.signal, failureCode, "swarm-activation.pre-spawn");
|
|
119
123
|
const prefixArgs = options.prefixArgs ?? [];
|
|
@@ -121,7 +125,10 @@ async function prepareWebSpawn(options, failureCode) {
|
|
|
121
125
|
if (options.commandLabel === "swarm-write" && !options.trustedWorkspaceRoot) {
|
|
122
126
|
throw new RuntimeError("CLI_TRUSTED_WORKSPACE_ROOT_MISSING", "Refusing swarm-write: write-capable plugin launches require a plugin-owned trusted workspace root.", "swarm-activation.pre-spawn", { details: { command_label: options.commandLabel } });
|
|
123
127
|
}
|
|
124
|
-
|
|
128
|
+
if (options.commandLabel === "swarm-write") {
|
|
129
|
+
assertWorkspaceSpellable(options.commandLabel, [options.cwd, options.trustedWorkspaceRoot], "swarm-activation.pre-spawn");
|
|
130
|
+
}
|
|
131
|
+
assertNoUnsafeExperimentalSelector(options.env, "swarm-activation.pre-spawn", options.executionPlan);
|
|
125
132
|
assertPrefixArgsSafe(prefixArgs);
|
|
126
133
|
if (options.expectedVersion !== undefined &&
|
|
127
134
|
options.executionPlan.kimiVersion !== null &&
|
|
@@ -139,6 +146,7 @@ async function prepareWebSpawn(options, failureCode) {
|
|
|
139
146
|
env: options.env,
|
|
140
147
|
expectedExecutionRoot: options.cwd,
|
|
141
148
|
stage: "swarm-activation.pre-spawn",
|
|
149
|
+
release: options.executionPlan,
|
|
142
150
|
});
|
|
143
151
|
}
|
|
144
152
|
throwIfAborted(options.signal, failureCode, "swarm-activation.pre-spawn");
|
|
@@ -232,6 +240,17 @@ async function startWebChild(options, env, expectedVersion, failureCode) {
|
|
|
232
240
|
}
|
|
233
241
|
async function waitForReadyLine(owned, expectedVersion, signal, failureCode) {
|
|
234
242
|
throwIfAborted(signal, failureCode, "swarm-activation.ready");
|
|
243
|
+
const ready = JSON_READY_VERSIONS.includes(expectedVersion)
|
|
244
|
+
? {
|
|
245
|
+
skip: (line) => line.trim().length === 0,
|
|
246
|
+
parse: parseJsonReadyLine,
|
|
247
|
+
invalid: "The Kimi web JSON ready line did not confirm the authenticated KAP loopback contract.",
|
|
248
|
+
}
|
|
249
|
+
: {
|
|
250
|
+
skip: (line) => !line.startsWith("Kimi server: "),
|
|
251
|
+
parse: parseReadyLine,
|
|
252
|
+
invalid: "The Kimi web ready line was not an authenticated loopback URL in the expected format.",
|
|
253
|
+
};
|
|
235
254
|
return await new Promise((resolve, reject) => {
|
|
236
255
|
let buffered = "";
|
|
237
256
|
let settled = false;
|
|
@@ -274,24 +293,13 @@ async function waitForReadyLine(owned, expectedVersion, signal, failureCode) {
|
|
|
274
293
|
const newline = buffered.indexOf("\n");
|
|
275
294
|
const line = buffered.slice(0, newline).replace(/\r$/, "");
|
|
276
295
|
buffered = buffered.slice(newline + 1);
|
|
277
|
-
if (
|
|
278
|
-
if (line.trim().length === 0)
|
|
279
|
-
continue;
|
|
280
|
-
try {
|
|
281
|
-
settle(parseJsonReadyLine(line));
|
|
282
|
-
}
|
|
283
|
-
catch {
|
|
284
|
-
settle(failure(failureCode, "swarm-activation.ready", "The Kimi web JSON ready line did not confirm the authenticated KAP loopback contract."));
|
|
285
|
-
}
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
if (!line.startsWith("Kimi server: "))
|
|
296
|
+
if (ready.skip(line))
|
|
289
297
|
continue;
|
|
290
298
|
try {
|
|
291
|
-
settle(
|
|
299
|
+
settle(ready.parse(line));
|
|
292
300
|
}
|
|
293
301
|
catch {
|
|
294
|
-
settle(failure(failureCode, "swarm-activation.ready",
|
|
302
|
+
settle(failure(failureCode, "swarm-activation.ready", ready.invalid));
|
|
295
303
|
}
|
|
296
304
|
return;
|
|
297
305
|
}
|
|
@@ -307,15 +315,8 @@ async function waitForReadyLine(owned, expectedVersion, signal, failureCode) {
|
|
|
307
315
|
function parseReadyLine(line) {
|
|
308
316
|
const candidate = line.slice("Kimi server: ".length);
|
|
309
317
|
const parsed = new URL(candidate);
|
|
310
|
-
if (parsed
|
|
311
|
-
parsed.hostname !== "127.0.0.1" ||
|
|
312
|
-
parsed.port.length === 0 ||
|
|
313
|
-
parsed.pathname !== "/" ||
|
|
314
|
-
parsed.search.length > 0 ||
|
|
315
|
-
parsed.username.length > 0 ||
|
|
316
|
-
parsed.password.length > 0) {
|
|
318
|
+
if (!isLoopbackRootUrl(parsed))
|
|
317
319
|
throw new Error("invalid ready URL");
|
|
318
|
-
}
|
|
319
320
|
if (!parsed.hash.startsWith("#token=") || parsed.hash.length === "#token=".length) {
|
|
320
321
|
throw new Error("invalid ready token");
|
|
321
322
|
}
|
|
@@ -324,6 +325,16 @@ function parseReadyLine(line) {
|
|
|
324
325
|
token: parsed.hash.slice("#token=".length),
|
|
325
326
|
};
|
|
326
327
|
}
|
|
328
|
+
/** An http://127.0.0.1:<port>/ URL with no query or credentials; callers check the hash. */
|
|
329
|
+
function isLoopbackRootUrl(url) {
|
|
330
|
+
return (url.protocol === "http:" &&
|
|
331
|
+
url.hostname === "127.0.0.1" &&
|
|
332
|
+
url.port.length > 0 &&
|
|
333
|
+
url.pathname === "/" &&
|
|
334
|
+
url.search.length === 0 &&
|
|
335
|
+
url.username.length === 0 &&
|
|
336
|
+
url.password.length === 0);
|
|
337
|
+
}
|
|
327
338
|
function parseJsonReadyLine(line) {
|
|
328
339
|
const data = JSON.parse(line);
|
|
329
340
|
if (!isRecord(data) ||
|
|
@@ -335,14 +346,8 @@ function parseJsonReadyLine(line) {
|
|
|
335
346
|
throw new Error("invalid JSON ready payload");
|
|
336
347
|
}
|
|
337
348
|
const origin = new URL(data.origin);
|
|
338
|
-
if (origin
|
|
339
|
-
origin.hostname !== "127.0.0.1" ||
|
|
340
|
-
origin.port.length === 0 ||
|
|
341
|
-
origin.pathname !== "/" ||
|
|
342
|
-
origin.search.length > 0 ||
|
|
349
|
+
if (!isLoopbackRootUrl(origin) ||
|
|
343
350
|
origin.hash.length > 0 ||
|
|
344
|
-
origin.username.length > 0 ||
|
|
345
|
-
origin.password.length > 0 ||
|
|
346
351
|
(data.origin !== origin.origin && data.origin !== `${origin.origin}/`)) {
|
|
347
352
|
throw new Error("invalid JSON ready origin");
|
|
348
353
|
}
|
|
@@ -399,7 +404,7 @@ async function resolveProfileModel(web, options, failureCode) {
|
|
|
399
404
|
}
|
|
400
405
|
async function createSession(web, options, expectedVersion, failureCode) {
|
|
401
406
|
const request = { metadata: { cwd: options.cwd } };
|
|
402
|
-
if (
|
|
407
|
+
if (kimiReleaseHas(expectedVersion, "local-environment")) {
|
|
403
408
|
request.environment_id = "local";
|
|
404
409
|
request.environment_cwd = options.cwd;
|
|
405
410
|
}
|
|
@@ -410,7 +415,7 @@ async function createSession(web, options, expectedVersion, failureCode) {
|
|
|
410
415
|
return { sessionId: data.id, workspaceId: data.workspace_id };
|
|
411
416
|
}
|
|
412
417
|
async function verifyLocalEnvironment(web, identity, expectedCwd, expectedVersion, signal, failureCode) {
|
|
413
|
-
if (!
|
|
418
|
+
if (!kimiReleaseHas(expectedVersion, "local-environment"))
|
|
414
419
|
return;
|
|
415
420
|
const data = await restData(web, "GET", `/api/v1/sessions/${encodeURIComponent(identity.sessionId)}/environment`, undefined, signal, failureCode);
|
|
416
421
|
if (!isRecord(data)) {
|
|
@@ -430,10 +435,11 @@ async function postSwarmProfile(web, identity, active, model, signal, failureCod
|
|
|
430
435
|
await restData(web, "POST", `/api/v1/sessions/${encodeURIComponent(identity.sessionId)}/profile`, { agent_config: agentConfig }, signal, failureCode);
|
|
431
436
|
}
|
|
432
437
|
async function verifySwarmStatus(web, identity, active, model, expectedVersion, signal, failureCode) {
|
|
433
|
-
const
|
|
438
|
+
const agentState = kimiReleaseHas(expectedVersion, "agent-state");
|
|
439
|
+
const data = agentState
|
|
434
440
|
? await readWebSocketAgentState(web, identity.sessionId, expectedVersion, signal, failureCode)
|
|
435
441
|
: await restData(web, "GET", `/api/v1/sessions/${encodeURIComponent(identity.sessionId)}/status`, undefined, signal, failureCode);
|
|
436
|
-
const source =
|
|
442
|
+
const source = agentState ? "agent state" : "/status";
|
|
437
443
|
if (!isRecord(data)) {
|
|
438
444
|
throw failure(failureCode, "swarm-activation.status", `Kimi web ${source} returned an invalid payload.`);
|
|
439
445
|
}
|
|
@@ -443,10 +449,10 @@ async function verifySwarmStatus(web, identity, active, model, expectedVersion,
|
|
|
443
449
|
if (data.plan_mode !== false) {
|
|
444
450
|
throw failure(failureCode, "swarm-activation.status", `Kimi web ${source} did not confirm plan mode is off.`);
|
|
445
451
|
}
|
|
446
|
-
if (
|
|
452
|
+
if (agentState && data.tower_mode !== false) {
|
|
447
453
|
throw failure(failureCode, "swarm-activation.status", "Kimi web agent state did not confirm tower mode is off.");
|
|
448
454
|
}
|
|
449
|
-
const permission =
|
|
455
|
+
const permission = agentState ? data.permission_mode : data.permission;
|
|
450
456
|
if (permission !== "auto") {
|
|
451
457
|
throw failure(failureCode, "swarm-activation.status", `Kimi web ${source} did not confirm auto permission mode.`);
|
|
452
458
|
}
|
|
@@ -462,7 +468,7 @@ async function readWebSocketAgentState(web, sessionId, expectedVersion, signal,
|
|
|
462
468
|
return await new Promise((resolve, reject) => {
|
|
463
469
|
let socket;
|
|
464
470
|
const bearerProtocol = `kimi-code.bearer.${web.token}`;
|
|
465
|
-
const legacyControl = !
|
|
471
|
+
const legacyControl = !kimiReleaseHas(expectedVersion, "modern-ws-control");
|
|
466
472
|
const helloId = `swarm-activation-hello-${randomUUID()}`;
|
|
467
473
|
const subscribeId = `swarm-activation-subscribe-${randomUUID()}`;
|
|
468
474
|
try {
|
|
@@ -730,7 +736,7 @@ async function shutdownWeb(web, signal, failureCode) {
|
|
|
730
736
|
await restData(web, "POST", "/api/v1/shutdown", undefined, signal, failureCode);
|
|
731
737
|
const settlement = await waitForChildClose(web, signal, failureCode);
|
|
732
738
|
if (!(await teardownOwnedChild(web))) {
|
|
733
|
-
throw failure(failureCode, "swarm-activation.shutdown", "The Kimi web process tree did not become quiescent after shutdown.", { exit_code: settlement.exitCode, signal: settlement.signal });
|
|
739
|
+
throw failure(failureCode, "swarm-activation.shutdown", "The Kimi web process tree did not become quiescent after shutdown.", { exit_code: settlement.exitCode, signal: settlement.signal, cleanup_summary: web.cleanupSummary ?? null });
|
|
734
740
|
}
|
|
735
741
|
if (web.processError || settlement.exitCode !== 0) {
|
|
736
742
|
throw failure(failureCode, "swarm-activation.shutdown", "The Kimi web process did not exit cleanly after shutdown.", { exit_code: settlement.exitCode, signal: settlement.signal });
|
|
@@ -775,9 +781,7 @@ async function restData(web, method, route, body, signal, failureCode) {
|
|
|
775
781
|
if (signal?.aborted === true)
|
|
776
782
|
onAbort();
|
|
777
783
|
try {
|
|
778
|
-
const headers = { accept: "application/json" };
|
|
779
|
-
if (web.token !== undefined)
|
|
780
|
-
headers.authorization = `Bearer ${web.token}`;
|
|
784
|
+
const headers = { accept: "application/json", authorization: `Bearer ${web.token}` };
|
|
781
785
|
if (body !== undefined)
|
|
782
786
|
headers["content-type"] = "application/json";
|
|
783
787
|
const response = await fetch(`${web.origin}${route}`, {
|
|
@@ -893,17 +897,13 @@ async function readSwarmJournalState(journalPath) {
|
|
|
893
897
|
break;
|
|
894
898
|
offset += bytesRead;
|
|
895
899
|
}
|
|
900
|
+
// Framed as kimi-code replays it. Replay stops at the first corrupt
|
|
901
|
+
// terminated line, so no later record may confirm a state: fail closed.
|
|
902
|
+
// An unparseable unterminated tail is truncation, which replay drops.
|
|
896
903
|
let state = "missing";
|
|
897
|
-
for (const
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
continue;
|
|
901
|
-
let record;
|
|
902
|
-
try {
|
|
903
|
-
record = JSON.parse(line);
|
|
904
|
-
}
|
|
905
|
-
catch {
|
|
906
|
-
if (line.includes("swarm_mode."))
|
|
904
|
+
for await (const { line, parsed: record, terminated } of kimiJournalRecords([buffer.subarray(0, offset)])) {
|
|
905
|
+
if (record === UNPARSEABLE_JOURNAL_LINE) {
|
|
906
|
+
if (terminated || line.includes("swarm_mode."))
|
|
907
907
|
return "unreadable";
|
|
908
908
|
continue;
|
|
909
909
|
}
|
|
@@ -933,7 +933,7 @@ function startDescendantTracking(owned) {
|
|
|
933
933
|
await refreshOwnedDescendants(owned);
|
|
934
934
|
if (owned.trackingStopped || owned.exited)
|
|
935
935
|
break;
|
|
936
|
-
await
|
|
936
|
+
await sleep(DESCENDANT_TRACK_INTERVAL_MS);
|
|
937
937
|
}
|
|
938
938
|
})();
|
|
939
939
|
}
|
|
@@ -953,7 +953,7 @@ async function refreshOwnedDescendants(owned) {
|
|
|
953
953
|
return;
|
|
954
954
|
}
|
|
955
955
|
owned.refreshPromise = (async () => {
|
|
956
|
-
const snapshot = await captureDescendantIdentities(childPid);
|
|
956
|
+
const snapshot = await retryIncompleteCapture(() => captureDescendantIdentities(childPid));
|
|
957
957
|
const previousRoot = owned.rootIdentity;
|
|
958
958
|
if (snapshot.root !== undefined) {
|
|
959
959
|
if (previousRoot === undefined) {
|
|
@@ -1072,8 +1072,11 @@ async function processGroupsQuiescent(owned, childPid) {
|
|
|
1072
1072
|
const groupIds = new Set([childPid]);
|
|
1073
1073
|
for (const identity of owned.descendants)
|
|
1074
1074
|
groupIds.add(identity.processGroupId);
|
|
1075
|
-
const
|
|
1076
|
-
|
|
1075
|
+
const scan = await retryIncompleteCapture(async () => {
|
|
1076
|
+
const members = await collectProcessGroupsIdentities([...groupIds]);
|
|
1077
|
+
return { members, complete: members !== undefined };
|
|
1078
|
+
});
|
|
1079
|
+
return scan.members !== undefined && scan.members.every((identity) => /^[ZX]/i.test(identity.state.trim()));
|
|
1077
1080
|
}
|
|
1078
1081
|
async function captureDescendantIdentities(childPid) {
|
|
1079
1082
|
let timer;
|
|
@@ -1088,7 +1091,7 @@ async function captureDescendantIdentities(childPid) {
|
|
|
1088
1091
|
}),
|
|
1089
1092
|
]);
|
|
1090
1093
|
if (snapshot === null)
|
|
1091
|
-
return { identities: [], complete: false };
|
|
1094
|
+
return { identities: [], complete: false, timedOut: true };
|
|
1092
1095
|
const [collected, rootProbe] = snapshot;
|
|
1093
1096
|
const identities = [];
|
|
1094
1097
|
const seen = new Set();
|
|
@@ -1133,14 +1136,8 @@ async function signalCapturedTree(owned, childPid, identities, signal) {
|
|
|
1133
1136
|
for (const identity of pidValidation.identities)
|
|
1134
1137
|
trySignalPid(identity.pid, signal);
|
|
1135
1138
|
const activeGroupIds = new Set(pidValidation.identities.map((identity) => identity.processGroupId));
|
|
1136
|
-
if (owned.exited)
|
|
1137
|
-
if (!pidValidation.identities.some((identity) => identity.processGroupId === childPid)) {
|
|
1138
|
-
activeGroupIds.delete(childPid);
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
else {
|
|
1139
|
+
if (!owned.exited)
|
|
1142
1140
|
activeGroupIds.delete(childPid);
|
|
1143
|
-
}
|
|
1144
1141
|
for (const processGroupId of activeGroupIds)
|
|
1145
1142
|
trySignalPid(-processGroupId, signal);
|
|
1146
1143
|
}
|
package/dist/swarm-policy.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { kimiReleaseHas } from "./kimi-releases.js";
|
|
1
2
|
export const SWARM_POLICY_ENV = "KIMI_PLUGIN_CC_SWARM_POLICY";
|
|
2
3
|
export const SWARM_WAVE_SIZE_ENV = "KIMI_PLUGIN_CC_SWARM_WAVE_SIZE";
|
|
3
4
|
export const BOUNDED_SWARM_POLICY = "bounded-waves/1";
|
|
@@ -7,7 +8,7 @@ export const BOUNDED_SWARM_POLICY = "bounded-waves/1";
|
|
|
7
8
|
export const SWARM_CHILD_TIMEOUT_MS = 2_147_483_647;
|
|
8
9
|
export function usesBoundedSwarmPolicy(plan) {
|
|
9
10
|
return plan.intendedEngine === "native-v2" &&
|
|
10
|
-
(plan.kimiVersion
|
|
11
|
+
kimiReleaseHas(plan.kimiVersion, "bounded-swarm") &&
|
|
11
12
|
(plan.operationKind === "swarm" || plan.operationKind === "swarm-write");
|
|
12
13
|
}
|
|
13
14
|
function plainObject(value) {
|
package/dist/swarm-recovery.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RuntimeError } from "./errors.js";
|
|
2
|
+
import { sleep } from "./util.js";
|
|
2
3
|
import { collectDescendantIdentities, collectProcessGroupsIdentities, probeProcessIdentity, revalidateProcessIdentities } from "./process-tree.js";
|
|
3
4
|
export function recordRecoveryEvent(store, record, event) {
|
|
4
5
|
record.complete = false;
|
|
@@ -158,7 +159,7 @@ export async function recoverLaunch(launch, persist, signal) {
|
|
|
158
159
|
persist();
|
|
159
160
|
return;
|
|
160
161
|
}
|
|
161
|
-
await
|
|
162
|
+
await sleep(25);
|
|
162
163
|
} while (Date.now() < deadline);
|
|
163
164
|
}
|
|
164
165
|
throw recoveryError("Recorded processes did not become quiescent; recovery remains pending.");
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Small helpers shared across the runtime. Imports nothing. */
|
|
2
|
+
// Uses the global timer on purpose: tests observe globalThis.setTimeout.
|
|
3
|
+
export function sleep(ms) {
|
|
4
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
+
}
|
|
6
|
+
/** Collapse whitespace and cut to `max` characters, ending in an ellipsis when cut. */
|
|
7
|
+
export function shorten(text, max) {
|
|
8
|
+
const normalized = text.replace(/\s+/g, " ").trim();
|
|
9
|
+
if (normalized.length <= max) {
|
|
10
|
+
return normalized;
|
|
11
|
+
}
|
|
12
|
+
return `${normalized.slice(0, Math.max(0, max - 1)).trimEnd()}…`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Where a smol-toml parse failed. Its own message quotes the neighbouring
|
|
16
|
+
* source lines, and lines of kimi-code's config can hold credentials, so that
|
|
17
|
+
* message must never reach an error, log or artifact.
|
|
18
|
+
*/
|
|
19
|
+
export function tomlErrorLocation(error) {
|
|
20
|
+
// `codeblock` marks a smol-toml TomlError; plain Errors also carry line/column under Bun.
|
|
21
|
+
const { line, column, codeblock } = (typeof error === "object" && error !== null ? error : {});
|
|
22
|
+
return typeof codeblock === "string" && typeof line === "number" && typeof column === "number"
|
|
23
|
+
? `syntax error at line ${line}, column ${column}`
|
|
24
|
+
: "syntax error";
|
|
25
|
+
}
|
|
26
|
+
export function isRecord(value) {
|
|
27
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28
|
+
}
|
package/dist/version.js
CHANGED
package/docs/migration.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Compatibility and upgrades
|
|
2
2
|
|
|
3
|
-
The runtime certifies exact CLI releases per operation. Plugin 2.6.2 adds bounded swarm on exact stock CLI 2.6.2; see the [certification receipt](upstream-2.6.2-certification.md) for validation status. Plugin 2.6.3 additionally certifies exact CLI 2.6.3 with a separate [release receipt](upstream-2.6.3-certification.md); the immutable GitHub/npm release and fresh registry verification are complete. Plugin 2.7.2 certifies exact CLI 2.7.2 with separate [certification evidence](upstream-2.7.2-certification.md). Plugin 2.7.3 adds exact CLI 2.7.3 under the same construction with a separate [certification record](upstream-2.7.3-certification.md); publication does not change the compatibility matrix. Exact 2.6.0 remains non-swarm-only. Older full-operation rows through 2.5.3 keep their inherited recovery limitation. `NATIVE_V2_CERTIFIED_VERSIONS` is the all-operation export, and `NATIVE_V2_ANY_OPERATION_VERSIONS` is the scoped union.
|
|
3
|
+
The runtime certifies exact CLI releases per operation. Plugin 2.6.2 adds bounded swarm on exact stock CLI 2.6.2; see the [certification receipt](upstream-2.6.2-certification.md) for validation status. Plugin 2.6.3 additionally certifies exact CLI 2.6.3 with a separate [release receipt](upstream-2.6.3-certification.md); the immutable GitHub/npm release and fresh registry verification are complete. Plugin 2.7.2 certifies exact CLI 2.7.2 with separate [certification evidence](upstream-2.7.2-certification.md). Plugin 2.7.3 adds exact CLI 2.7.3 under the same construction with a separate [certification record](upstream-2.7.3-certification.md); publication does not change the compatibility matrix. Exact 2.6.0 remains non-swarm-only. Older full-operation rows through 2.5.3 keep their inherited recovery limitation. `NATIVE_V2_CERTIFIED_VERSIONS` is the all-operation export, and `NATIVE_V2_ANY_OPERATION_VERSIONS` is the scoped union. Since plugin 3.0.0, another plain 2.x release above 2.0.0, including 2.6.1, 2.7.0 and 2.7.4, runs only the read-only operations (ask, review, challenge and the review gate) with a warning; rescue, pursue and both swarm modes refuse, and `KIMI_PLUGIN_CC_STRICT_VERSIONS=1` refuses every operation. The npm channel does not change the compatibility matrix.
|
|
4
4
|
|
|
5
5
|
Plugin 2.5.1 also adds DeepSeek Harness as a third host with all seven operations and a DSH-specific bundle, data root, and managed hook id. Existing Claude Code and Codex certification, job stores, and host-scoped hooks are unchanged; no migration is required for those hosts. New DSH installations follow the [README DSH section](../README.md#install-in-deepseek-harness), including `/kimi-setup` on that host.
|
|
6
6
|
|
|
7
|
-
Explicitly pinned legacy-v1 binaries remain supported within `KIMI_TESTED_MINORS
|
|
7
|
+
Explicitly pinned legacy-v1 binaries remain supported within `KIMI_TESTED_MINORS` (`runtime/kimi-version-probe.ts`), through 0.41.x, subject to each operation's minimum version. The [native-v2 release table](../runtime/kimi-releases.ts) is the authority for native-v2 versions.
|
|
8
8
|
|
|
9
9
|
Use the [README installation and update steps](../README.md) for Claude Code or Codex. Model and provider choices are covered in the [model setup guide](./models.md). Do not change your host application's authentication to configure Kimi.
|
|
10
10
|
|
|
@@ -12,6 +12,27 @@ Use the [README installation and update steps](../README.md) for Claude Code or
|
|
|
12
12
|
|
|
13
13
|
Plugin versions advance independently using ordinary SemVer and may deliberately align with a certified CLI release. Nearby version numbers do not imply compatibility or operation scope; the exact per-operation matrix is authoritative. Published versions and tags are never reused. Every upstream patch requires its own certification. The native-v2 no-plan profile, plugin/marketplace IDs and existing job store are preserved.
|
|
14
14
|
|
|
15
|
+
## Upgrading to 3.0
|
|
16
|
+
|
|
17
|
+
Plugin 3.0.0 replaces seven model commands with four. The operations behind them do not change, so existing jobs, sessions, hook labels and session-title prefixes carry over. Run setup on each host after updating, as for every release.
|
|
18
|
+
|
|
19
|
+
| Before 3.0.0 | From 3.0.0 |
|
|
20
|
+
|---|---|
|
|
21
|
+
| `/kimi:ask`, agent `kimi-ask`, Codex `$kimi-ask` | `/kimi:task`, agent `kimi-task`, Codex `$kimi-task` |
|
|
22
|
+
| `/kimi:rescue`, agent `kimi-rescue`, Codex `$kimi-rescue` | `/kimi:task --write`, agent `kimi-task` with `--write`, Codex `$kimi-task` with `--write` |
|
|
23
|
+
| `/kimi:challenge`, agent `kimi-challenge`, Codex `$kimi-challenge` | `/kimi:review --challenge`, agent `kimi-review` with `--challenge`, Codex `$kimi-review` with `--challenge` |
|
|
24
|
+
| agent `kimi-swarm-write`, Codex `$kimi-swarm-write` | agent `kimi-swarm` with `--write`, Codex `$kimi-swarm` with `--write`; `/kimi:swarm --write` is unchanged |
|
|
25
|
+
| MCP tool `kimi_challenge` | MCP tool `kimi_review` with `mode: "challenge"` |
|
|
26
|
+
|
|
27
|
+
- `--write` and `--challenge` select the operation only as leading flags, before the first word of the prompt. The same text inside the prompt, or after `--`, keeps the read-only operation.
|
|
28
|
+
- Scripts that call `companion.sh` directly keep working: `ask`, `task rescue`, `review`, `task challenge`, `task pursue`, `task swarm` and `task swarm --write` are unchanged.
|
|
29
|
+
- Codex lists nine skills instead of twelve. `$kimi-task` is not implicitly invocable, so Codex no longer starts the read-only question skill on its own; name it when you want it. `$kimi-review` stays implicitly invocable.
|
|
30
|
+
- Update the plugin on every host you use. Every installed hook checks every plugin job, so another host's older hook still applies its own rules and can deny what 3.0 allows; each job launch and each setup warns about it.
|
|
31
|
+
- The MCP server lists six model tools and the three job tools. A client that called `kimi_challenge` must call `kimi_review` with `mode: "challenge"`. `kimi_ask`, `kimi_review` and `kimi_swarm` also accept `read_roots` and `network`.
|
|
32
|
+
- DeepSeek Harness keeps all seven providers, including `kimi_challenge` and `kimi_swarm_write`.
|
|
33
|
+
|
|
34
|
+
The same release stops refusing several Kimi settings it can neutralize, runs read-only operations on uncertified 2.x releases, adds `setup --install-kimi` and per-call read scope, and reports non-fatal conditions as warnings. See the [changelog](../CHANGELOG.md) and [safety guide](./safety.md).
|
|
35
|
+
|
|
15
36
|
## Plugin 2.6.2 swarm behavior on exact CLI 2.6.2
|
|
16
37
|
|
|
17
38
|
Concurrency 1 uses one direct worker without native swarm activation or delegation. The default for write mode remains 1; its edits still produce an unapplied patch from a temporary worktree. Read mode defaults to 4 and uses guarded waves. At concurrency 2 or more, new and resumed entries share the wave limit; a model must divide larger tasks into successive waves. Fresh-only waves require at least two entries, so group odd target counts into disjoint entries or resume an own-session child for remaining work. `--cap` remains an advisory lifetime-total count.
|
|
@@ -32,7 +53,7 @@ Activation is inside the job's finite budget. Graceful process close has a bound
|
|
|
32
53
|
|
|
33
54
|
After updating the plugin, run Claude Code `/kimi:setup` or Codex `$kimi-setup`
|
|
34
55
|
from that host's active install to re-pin its version-stamped hook path, then
|
|
35
|
-
run setup with `--check`. This fixes path drift, not policy omissions in an older installed plugin. Older coexisting hooks still veto pursue goal-status tools; update each host only when authorized. Keep `default_plan_mode` absent or false. Upgrades
|
|
56
|
+
run setup with `--check`. This fixes path drift, not policy omissions in an older installed plugin. Older coexisting hooks still veto pursue goal-status tools; update each host only when authorized. Keep `default_plan_mode` absent or false if you use swarm or a CLI older than 2.4.0. Upgrades
|
|
36
57
|
from pre-1.10 releases must also follow the historical native-v2 migration section below.
|
|
37
58
|
|
|
38
59
|
## Historical migration instructions
|
package/docs/models.md
CHANGED
|
@@ -26,7 +26,7 @@ Say “review this with my configured fast model” or pass its exact alias:
|
|
|
26
26
|
|
|
27
27
|
```text
|
|
28
28
|
/kimi:review -m 'my-provider/my-model' review this diff
|
|
29
|
-
/kimi:
|
|
29
|
+
/kimi:task -m 'my-provider/my-model' explain the cache
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
The Claude agents and Codex skills list models when you request a model in
|
|
@@ -78,7 +78,7 @@ Names in the inventory are untrusted configuration data and must be passed as
|
|
|
78
78
|
one correctly shell-quoted argument, never evaluated as shell instructions.
|
|
79
79
|
|
|
80
80
|
The model list is a routing aid, not a second implementation of Kimi's config
|
|
81
|
-
validator. Every task still uses the existing
|
|
81
|
+
validator. Every task still uses the existing version-certification, hook, workspace,
|
|
82
82
|
and no-plan checks. Source review is against kimi-code 2.0.0 (`1b89e4b0`),
|
|
83
83
|
including `kosongConfig/configSection.ts`, `envOverlay.ts`, and
|
|
84
84
|
`cli/v2/run-v2-print.ts`.
|
|
@@ -8,7 +8,7 @@ no separate CLI.
|
|
|
8
8
|
|
|
9
9
|
## Publishing status
|
|
10
10
|
|
|
11
|
-
Plugin **2.7.3**
|
|
11
|
+
Plugin **2.7.3** certifies exact Kimi Code **2.7.3** for all eight operations with separate [certification evidence](upstream-2.7.3-certification.md). Release commit `8e2187d1826952440e18f870eaae52bb765f385b` passed [release CI 45418692870](https://github.com/linxule/kimi-plugin-cc/actions/runs/45418692870), and the immutable [v2.7.3 release](https://github.com/linxule/kimi-plugin-cc/releases/tag/v2.7.3) is published with annotated tag object `bb019411da1deb73c8a17ba8eba314004a610377`. [OIDC run 45420498664](https://github.com/linxule/kimi-plugin-cc/actions/runs/45420498664) validated the same tag and published npm `latest` 2.7.3 at `2026-11-24T15:13:17.012Z`. The **343-file** registry tarball matches the successful Actions artifact and every tag file, with SHA-1 `bbb42f48fe2f620be6a89b588561905c235a715f`, SHA-256 `d23e4742d6c5c5337e5ae98c1d8435c3c3409b6cf4f7b36bd61054327c41836f` and SHA-512 `21b30f741417c117c95f7afdef0fe11368d30fbe21ec3489509d9a4bb543851b35cc83f24ae6db1dfe90ad6cd58a4b4bb1af1ee7ab83d804a9271c7e52e497a3`. SLSA provenance log index `4080883768` and publish attestation log index `4080953677` match the package subject, SHA-512, release commit, run and tag. Fresh isolated Claude Code, Codex and DSH setup/checks and all three capability maps pass, with zero production advisories and no invalid or missing signatures. The post-publication Discover timestamp is `1795533197`, recording actual npm publication. Publication does not update installed hosts or operator pins.
|
|
12
12
|
|
|
13
13
|
Plugin **2.7.2** certifies exact Kimi Code **2.7.2** for all eight operations with separate [certification evidence](upstream-2.7.2-certification.md). Release commit `e2bba0e2d4e1745e4155eb5c6ddf3f4dabaffb66` passed the frozen-install full gate (**1,848 passes / 24,260 assertions**), **342-file** package/DSH and consumer-security gates, plus [release CI 44799772434](https://github.com/linxule/kimi-plugin-cc/actions/runs/44799772434). The immutable [v2.7.2 release](https://github.com/linxule/kimi-plugin-cc/releases/tag/v2.7.2) is published. Initial OIDC run `44801159950` passed build but npm rejected publication with `TLOG_CREATE_ENTRY_ERROR`; it published nothing. The documented manual-dispatch recovery [run 44803040496](https://github.com/linxule/kimi-plugin-cc/actions/runs/44803040496) validated the same tag and published npm `latest` 2.7.2 at `2026-11-20T19:44:23.172Z`. The 342-file registry tarball matches the successful Actions artifact and every release-tag file, with SHA-1 `c78a89fa5ea199c6605c7453ca50b2c23ee3cb3f`, SHA-256 `0a0bcba76513adac3448776d4f8df9ec73b60987edac0ca5e6535db428b91f33` and SHA-512 `2e7dfe8043c2c05447a28dbfc17c6124c6b08444efb864c5b5f5f3f586f338ff4b77d35e3b769168b570a32c08bec48e8f78aa6e11b958e9f22257cda29616f1`. SLSA provenance log index `4028226284` and publish attestation log index `4028244850` match the package subject, SHA-512, recovery run and release commit; their workflow ref is `refs/heads/main` because recovery used manual dispatch, while the package bytes independently match the immutable tag. A fresh registry installation has zero production advisories and no invalid or missing signatures; isolated Claude Code, Codex and DSH setup/checks and all three capability maps pass. The post-publication Discover timestamp is `1795203863`, recording actual npm publication. Publication does not update installed hosts or operator pins.
|
|
14
14
|
|