kimi-plugin-cc 2.5.8 → 2.6.2
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 +1 -1
- package/CHANGELOG.md +19 -0
- package/README.md +29 -13
- package/agents/kimi-swarm-write.md +6 -4
- package/agents/kimi-swarm.md +5 -4
- package/commands/swarm.md +5 -3
- package/dist/cli-client.js +224 -31
- package/dist/commands/recover-swarm.js +4 -0
- package/dist/commands/setup.js +5 -1
- package/dist/commands/swarm.js +131 -43
- package/dist/hooks/approval-hook.js +3 -0
- package/dist/hooks/approval-policy.js +34 -12
- package/dist/hooks/config-safety.js +5 -4
- package/dist/kimi-engine.js +5 -3
- package/dist/kimi-timeouts.js +4 -4
- package/dist/mcp/operations.js +1 -1
- package/dist/process-tree.js +150 -43
- package/dist/swarm-activation.js +14 -9
- package/dist/swarm-policy.js +72 -0
- package/dist/swarm-recovery.js +41 -10
- package/dist/swarm-tool-policy.js +146 -0
- package/dist/version.js +1 -1
- package/docs/migration.md +13 -5
- package/docs/registry-releases.md +6 -0
- package/docs/safety.md +41 -16
- package/docs/swarm-recovery.md +4 -2
- package/docs/upstream-2.6.0-certification.md +13 -0
- package/docs/upstream-2.6.2-certification.md +132 -0
- package/package.json +3 -2
- package/plugins/kimi-codex/.codex-plugin/plugin.json +1 -1
- package/plugins/kimi-codex/dist/cli-client.js +224 -31
- package/plugins/kimi-codex/dist/commands/recover-swarm.js +4 -0
- package/plugins/kimi-codex/dist/commands/setup.js +5 -1
- package/plugins/kimi-codex/dist/commands/swarm.js +131 -43
- package/plugins/kimi-codex/dist/hooks/approval-hook.js +3 -0
- package/plugins/kimi-codex/dist/hooks/approval-policy.js +34 -12
- package/plugins/kimi-codex/dist/hooks/config-safety.js +5 -4
- package/plugins/kimi-codex/dist/kimi-engine.js +5 -3
- package/plugins/kimi-codex/dist/kimi-timeouts.js +4 -4
- package/plugins/kimi-codex/dist/mcp/operations.js +1 -1
- package/plugins/kimi-codex/dist/process-tree.js +150 -43
- package/plugins/kimi-codex/dist/swarm-activation.js +14 -9
- package/plugins/kimi-codex/dist/swarm-policy.js +72 -0
- package/plugins/kimi-codex/dist/swarm-recovery.js +41 -10
- package/plugins/kimi-codex/dist/swarm-tool-policy.js +146 -0
- package/plugins/kimi-codex/dist/version.js +1 -1
- package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +2 -0
- package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +2 -0
- package/plugins/kimi-dsh/dist/cli-client.js +224 -31
- package/plugins/kimi-dsh/dist/commands/recover-swarm.js +4 -0
- package/plugins/kimi-dsh/dist/commands/setup.js +5 -1
- package/plugins/kimi-dsh/dist/commands/swarm.js +131 -43
- package/plugins/kimi-dsh/dist/hooks/approval-hook.js +3 -0
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +34 -12
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +5 -4
- package/plugins/kimi-dsh/dist/kimi-engine.js +5 -3
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +4 -4
- package/plugins/kimi-dsh/dist/mcp/operations.js +1 -1
- package/plugins/kimi-dsh/dist/process-tree.js +150 -43
- package/plugins/kimi-dsh/dist/swarm-activation.js +14 -9
- package/plugins/kimi-dsh/dist/swarm-policy.js +72 -0
- package/plugins/kimi-dsh/dist/swarm-recovery.js +41 -10
- package/plugins/kimi-dsh/dist/swarm-tool-policy.js +146 -0
- package/plugins/kimi-dsh/dist/version.js +1 -1
- package/plugins/kimi-dsh/package.json +1 -1
|
@@ -21,29 +21,30 @@ import { readArtifact, renderManagedJobOutput, writeArtifact } from "../render.j
|
|
|
21
21
|
import { hookRefusalDetails, hookRefusalRetryProtocol, maybeWarnHookMissing, verifyHookInstalled, } from "../hooks/install.js";
|
|
22
22
|
import { assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes } from "./cli-helpers.js";
|
|
23
23
|
import { buildKimiSessionTitle, syncKimiSessionTitle } from "../session-title.js";
|
|
24
|
+
import { usesBoundedSwarmPolicy } from "../swarm-policy.js";
|
|
24
25
|
// /kimi:swarm — parallel fan-out, read-only by default and runtime-foreground-only.
|
|
25
26
|
// A finite wall-clock budget bounds the whole run. --cap is a SOFT total-count
|
|
26
|
-
// prompt hint
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
27
|
+
// prompt hint. Exact native-v2 2.6.2 bounds admitted waves and prevents native
|
|
28
|
+
// child timeouts from returning a continuing coordinator before children stop.
|
|
29
|
+
// Concurrency 1 uses a direct worker without native fan-out. Older versions keep
|
|
30
|
+
// their normal-launch setting and inherited recovery limitation. Read/write
|
|
31
|
+
// modes reuse review/rescue lineage, and the
|
|
30
32
|
// mandatory PreToolUse hook enforces read-only policy or trusted-worktree write
|
|
31
33
|
// confinement on the coordinator and every subagent. Write mode requires
|
|
32
34
|
// kimi-code 0.18.0+. Exact 2.3.2, 2.3.3, 2.4.0, 2.4.1, 2.5.0, 2.5.1, 2.5.2,
|
|
33
35
|
// and certified 2.5.3 activate a same-job session through a bounded loopback
|
|
34
|
-
// web lifecycle, then resume it through the normal print path.
|
|
35
|
-
// 2.6.0
|
|
36
|
-
//
|
|
37
|
-
// controls whether each exact version is reachable.
|
|
36
|
+
// web lifecycle, then resume it through the normal print path. 2.6.2 parallel
|
|
37
|
+
// waves and candidate-only 2.6.0 use that lifecycle too. The per-operation certification
|
|
38
|
+
// table controls whether each exact version is reachable in production.
|
|
38
39
|
const SWARM_SUMMARY_MAX = 120;
|
|
39
40
|
const SWARM_AGENT_PROFILE = "<swarm>";
|
|
40
41
|
const SWARM_WRITE_AGENT_PROFILE = "<swarm-write>";
|
|
41
42
|
/**
|
|
42
|
-
* Default
|
|
43
|
-
*
|
|
43
|
+
* Default concurrency setting when the user passes no `--max-concurrency`.
|
|
44
|
+
* Exact native-v2 2.6.2 also enforces this as the admitted wave size. The plugin exports
|
|
44
45
|
* KIMI_CODE_AGENT_SWARM_MAX_CONCURRENCY; older read-only swarms ignore it and
|
|
45
46
|
* retain only the wall-clock hard bound. Rate-limit recovery can exceed it on
|
|
46
|
-
* reviewed
|
|
47
|
+
* older reviewed sources; their setting is not an unconditional peak guarantee.
|
|
47
48
|
*/
|
|
48
49
|
export const SWARM_DEFAULT_MAX_CONCURRENCY = 4;
|
|
49
50
|
/**
|
|
@@ -56,10 +57,10 @@ export function resolveSwarmMaxConcurrency(requested) {
|
|
|
56
57
|
return requested ?? SWARM_DEFAULT_MAX_CONCURRENCY;
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
59
|
-
* Default
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
60
|
+
* Default concurrency for WRITE mode — 1 vs read's 4. Exact native-v2 2.6.2
|
|
61
|
+
* runs one direct worker; older versions serialize normal child launches but
|
|
62
|
+
* retain the rate-limit recovery overrun. Disjoint-target partitioning remains
|
|
63
|
+
* prompt-only when parallel workers are explicitly requested.
|
|
63
64
|
* Override with an explicit `--max-concurrency N`.
|
|
64
65
|
*/
|
|
65
66
|
export const SWARM_WRITE_DEFAULT_MAX_CONCURRENCY = 1;
|
|
@@ -77,14 +78,28 @@ export function resolveSwarmWriteMaxConcurrency(requested) {
|
|
|
77
78
|
* Read-only is NOT enforced by this prose — the PreToolUse hook (swarm label) at
|
|
78
79
|
* policy index 0 denies every write/edit/shell for the coordinator AND every
|
|
79
80
|
* subagent, so slimming this text does not move the safety boundary. The optional
|
|
80
|
-
* `cap` is a SOFT subagent-count hint
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* The --budget wall-clock ceiling is the always-on hard bound on the whole run.
|
|
81
|
+
* `cap` is a SOFT total subagent-count hint. `waveSize` is supplied only for
|
|
82
|
+
* the exact bounded policy: 1 runs directly; larger values guide the model to
|
|
83
|
+
* satisfy the separately enforced admission rule. Older versions keep their
|
|
84
|
+
* existing prompt and normal-launch concurrency semantics.
|
|
85
85
|
*/
|
|
86
|
-
export function buildSwarmPrompt(objective, cap) {
|
|
86
|
+
export function buildSwarmPrompt(objective, cap, waveSize) {
|
|
87
87
|
const trimmed = objective.trim();
|
|
88
|
+
if (waveSize === 1) {
|
|
89
|
+
return [
|
|
90
|
+
"Review the following read-only as the single worker: inspect and report; do not modify anything.",
|
|
91
|
+
"",
|
|
92
|
+
`Objective: ${trimmed}`,
|
|
93
|
+
"",
|
|
94
|
+
"Complete every target yourself, one at a time. Do not delegate: Agent and AgentSwarm are denied.",
|
|
95
|
+
"Use the allowed read-only tools, primarily Read/Grep/Glob and ReadMediaFile where relevant;",
|
|
96
|
+
"shell/Bash and every write/edit tool are denied.",
|
|
97
|
+
"",
|
|
98
|
+
"Return a single markdown report: deduplicate findings, preserve coverage across every target,",
|
|
99
|
+
"and explicitly mention targets with no findings. Include a short verdict line, a brief summary,",
|
|
100
|
+
"then findings as `file:line — issue — severity`. No JSON wrapper or outer code fences.",
|
|
101
|
+
].join("\n");
|
|
102
|
+
}
|
|
88
103
|
const capClause = cap !== undefined
|
|
89
104
|
? `Use at most ${cap} subagents in total across the whole run (soft cap); split or group targets to stay within it.`
|
|
90
105
|
: undefined;
|
|
@@ -99,6 +114,7 @@ export function buildSwarmPrompt(objective, cap) {
|
|
|
99
114
|
"workspace directly with the allowed read-only tools).",
|
|
100
115
|
"Fan the work out across the relevant targets in parallel using your own subagent capability,",
|
|
101
116
|
"as you judge best — split or group the work however fits the objective.",
|
|
117
|
+
...boundedWaveInstructions(waveSize),
|
|
102
118
|
...(capClause ? [capClause] : []),
|
|
103
119
|
"",
|
|
104
120
|
"Consolidate into a single markdown report: deduplicate findings, preserve coverage across",
|
|
@@ -109,17 +125,38 @@ export function buildSwarmPrompt(objective, cap) {
|
|
|
109
125
|
}
|
|
110
126
|
/**
|
|
111
127
|
* Build the WRITE-mode coordination prompt. Unlike the read-only prompt, this
|
|
112
|
-
* sets subagent_type="coder" (write-capable) and instructs DISJOINT
|
|
113
|
-
*
|
|
128
|
+
* sets subagent_type="coder" (write-capable) and instructs DISJOINT target
|
|
129
|
+
* assignments with NO git and NO nested swarm. The coordinator and all
|
|
114
130
|
* subagents run in an ephemeral throwaway worktree; the PreToolUse hook
|
|
115
131
|
* (swarm-write label) confines writes there and the plugin captures a patch the
|
|
116
132
|
* user reviews. The `cap` is the same SOFT total-count hint as read mode.
|
|
117
133
|
*/
|
|
118
|
-
export function buildSwarmWritePrompt(objective, cap) {
|
|
134
|
+
export function buildSwarmWritePrompt(objective, cap, waveSize) {
|
|
119
135
|
const trimmed = objective.trim();
|
|
136
|
+
if (waveSize === 1) {
|
|
137
|
+
return [
|
|
138
|
+
"Perform the following CODE-EDITING task as the single worker.",
|
|
139
|
+
"",
|
|
140
|
+
`Objective: ${trimmed}`,
|
|
141
|
+
"",
|
|
142
|
+
"You are running inside a throwaway git worktree dedicated to this task.",
|
|
143
|
+
"Complete every target yourself, one at a time. Do not delegate: Agent and AgentSwarm are denied.",
|
|
144
|
+
"Your changes will be captured as a patch for the human to review and apply.",
|
|
145
|
+
"",
|
|
146
|
+
"Safety rules enforced by the PreToolUse hook:",
|
|
147
|
+
"- Writes are confined to this worktree; an out-of-worktree write is denied.",
|
|
148
|
+
"- Git mutation is denied: do not add, commit, checkout, or change repository state.",
|
|
149
|
+
"",
|
|
150
|
+
"Report what changed and why, with a short verdict and a section for each target listing edited files.",
|
|
151
|
+
"Do not paste full diffs; the patch is captured separately. Return plain markdown,",
|
|
152
|
+
"without a JSON wrapper or outer code fences.",
|
|
153
|
+
].join("\n");
|
|
154
|
+
}
|
|
120
155
|
const capClause = cap !== undefined
|
|
121
156
|
? `Launch at most ${cap} subagents in total across the whole run (soft cap — split or group targets to stay within it).`
|
|
122
|
-
:
|
|
157
|
+
: waveSize === undefined
|
|
158
|
+
? "Launch one subagent per distinct target; group related targets if there are many."
|
|
159
|
+
: "Assign disjoint targets or target groups to subagents; group related targets when needed.";
|
|
123
160
|
return [
|
|
124
161
|
"Coordinate a parallel CODE-EDITING task using the AgentSwarm tool.",
|
|
125
162
|
"",
|
|
@@ -128,8 +165,16 @@ export function buildSwarmWritePrompt(objective, cap) {
|
|
|
128
165
|
"You are running inside a throwaway git worktree dedicated to this task — edit freely;",
|
|
129
166
|
"your changes will be captured as a patch for the human to review and apply. Use the",
|
|
130
167
|
'AgentSwarm tool to fan the work out across subagents. Set subagent_type to "coder" (the',
|
|
131
|
-
|
|
132
|
-
|
|
168
|
+
...(waveSize === undefined
|
|
169
|
+
? [
|
|
170
|
+
"write-capable profile). Give each subagent ONE target via prompt_template + items: a single",
|
|
171
|
+
"file or module per subagent.",
|
|
172
|
+
]
|
|
173
|
+
: [
|
|
174
|
+
"write-capable profile). Give each subagent a DISJOINT target or target group via prompt_template + items.",
|
|
175
|
+
"Each file must belong to only one subagent's assignment.",
|
|
176
|
+
]),
|
|
177
|
+
...boundedWaveInstructions(waveSize),
|
|
133
178
|
capClause,
|
|
134
179
|
"",
|
|
135
180
|
"Safety rules enforced by the PreToolUse hook (violations are denied):",
|
|
@@ -149,6 +194,15 @@ export function buildSwarmWritePrompt(objective, cap) {
|
|
|
149
194
|
"no JSON wrapper, no outer code fences.",
|
|
150
195
|
].join("\n");
|
|
151
196
|
}
|
|
197
|
+
function boundedWaveInstructions(waveSize) {
|
|
198
|
+
return waveSize === undefined ? [] : [
|
|
199
|
+
`Each AgentSwarm call must contain at most ${waveSize} entries in total, counting both new items and resumed agents.`,
|
|
200
|
+
"A wave with no resumed agents must contain at least two new entries; a single resumed agent is allowed.",
|
|
201
|
+
"For odd target counts, group multiple targets into disjoint worker entries so the final wave is not a lone fresh entry.",
|
|
202
|
+
"Split larger work into sequential waves and wait for each wave to finish before starting the next.",
|
|
203
|
+
"Oversized calls and forks are denied; if a call is denied, group or split its targets into smaller waves.",
|
|
204
|
+
];
|
|
205
|
+
}
|
|
152
206
|
export async function runSwarm(argv, context) {
|
|
153
207
|
const parsed = parseSwarmArgs(argv);
|
|
154
208
|
const objective = parsed.objective?.trim();
|
|
@@ -172,7 +226,8 @@ async function runReadSwarm(parsed, objective, context) {
|
|
|
172
226
|
cwd: context.cwd,
|
|
173
227
|
env: context.env,
|
|
174
228
|
});
|
|
175
|
-
const
|
|
229
|
+
const maxConcurrency = resolveSwarmMaxConcurrency(parsed.maxConcurrency);
|
|
230
|
+
const prompt = buildSwarmPrompt(objective, parsed.cap, usesBoundedSwarmPolicy(executionPlan) ? maxConcurrency : undefined);
|
|
176
231
|
const jobId = allocateJobId(context);
|
|
177
232
|
const logPath = path.join(paths.logsDir, `swarm-${jobId}.jsonl`);
|
|
178
233
|
const job = store.createJob({
|
|
@@ -213,7 +268,7 @@ async function runReadSwarm(parsed, objective, context) {
|
|
|
213
268
|
await markJobFailed(store, paths, job, classified, "Swarm failed.", { phase: "failed" });
|
|
214
269
|
throw classified;
|
|
215
270
|
}
|
|
216
|
-
const completed = await executeSwarmJob(job.job_id, prompt, objective, job.budget_ms,
|
|
271
|
+
const completed = await executeSwarmJob(job.job_id, prompt, objective, job.budget_ms, maxConcurrency, context, undefined, await realpath(context.cwd));
|
|
217
272
|
if (!completed.final_output_path) {
|
|
218
273
|
throw new RuntimeError("SWARM_RESULT_MISSING", "Swarm finished without a rendered result.", "swarm.result");
|
|
219
274
|
}
|
|
@@ -249,7 +304,7 @@ async function runWriteSwarm(parsed, objective, context) {
|
|
|
249
304
|
if (await isWorkingTreeDirty(context.cwd)) {
|
|
250
305
|
context.stderr.write("[kimi-plugin-cc] /kimi:swarm --write bases its worktree on HEAD — your uncommitted changes are NOT visible to the swarm. Commit or stash them first if the swarm needs them.\n");
|
|
251
306
|
}
|
|
252
|
-
const
|
|
307
|
+
const maxConcurrency = resolveSwarmWriteMaxConcurrency(parsed.maxConcurrency);
|
|
253
308
|
const jobId = allocateJobId(context);
|
|
254
309
|
const logPath = path.join(paths.logsDir, `swarm-write-${jobId}.jsonl`);
|
|
255
310
|
// Namespace worktrees per repo so the cross-repo sweep below only ever
|
|
@@ -275,6 +330,7 @@ async function runWriteSwarm(parsed, objective, context) {
|
|
|
275
330
|
cwd: worktreePath,
|
|
276
331
|
env: context.env,
|
|
277
332
|
});
|
|
333
|
+
const prompt = buildSwarmWritePrompt(objective, parsed.cap, usesBoundedSwarmPolicy(executionPlan) ? maxConcurrency : undefined);
|
|
278
334
|
const job = store.createJob({
|
|
279
335
|
job_id: jobId,
|
|
280
336
|
repo_id: repoIdentity.repoId,
|
|
@@ -317,7 +373,7 @@ async function runWriteSwarm(parsed, objective, context) {
|
|
|
317
373
|
});
|
|
318
374
|
throw classified;
|
|
319
375
|
}
|
|
320
|
-
const completed = await executeSwarmJob(job.job_id, prompt, objective, job.budget_ms,
|
|
376
|
+
const completed = await executeSwarmJob(job.job_id, prompt, objective, job.budget_ms, maxConcurrency, context, {
|
|
321
377
|
spawnCwd: worktreePath,
|
|
322
378
|
workspaceRoot: worktreePath,
|
|
323
379
|
onPatchCaptureFailure: () => {
|
|
@@ -406,8 +462,8 @@ writeMode, executionCwd) {
|
|
|
406
462
|
store.close();
|
|
407
463
|
throw new RuntimeError("JOB_NOT_FOUND", `Swarm job ${jobId} was not found.`, "swarm.worker");
|
|
408
464
|
}
|
|
409
|
-
// Both modes
|
|
410
|
-
// enforces read-only policy
|
|
465
|
+
// Both modes require the PreToolUse hook, including a direct single worker:
|
|
466
|
+
// read mode enforces read-only policy; write mode confines writes to its
|
|
411
467
|
// worktree. Fail closed before spawning.
|
|
412
468
|
if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
|
|
413
469
|
const installStatus = await verifyHookInstalled(context.env);
|
|
@@ -415,8 +471,7 @@ writeMode, executionCwd) {
|
|
|
415
471
|
maybeWarnHookMissing(installStatus, "swarm", context.stderr);
|
|
416
472
|
const classified = new RuntimeError("SWARM_HOOK_NOT_INSTALLED", [
|
|
417
473
|
"/kimi:swarm refuses to run without the kimi-plugin-cc PreToolUse hook.",
|
|
418
|
-
"
|
|
419
|
-
"one of them read-only, so a missing hook means no enforcement across the fan-out.",
|
|
474
|
+
"The hook enforces each worker's tool permissions, write confinement, and delegation limits.",
|
|
420
475
|
`Hook check failed: ${installStatus.reason ?? "unknown"}.`,
|
|
421
476
|
"Repair by running Claude Code /kimi:setup or Codex $kimi-setup, then retry.",
|
|
422
477
|
hookRefusalRetryProtocol(context.env),
|
|
@@ -463,6 +518,11 @@ writeMode, executionCwd) {
|
|
|
463
518
|
};
|
|
464
519
|
try {
|
|
465
520
|
const executionPlan = executionPlanFromPersisted(job);
|
|
521
|
+
const boundedSwarm = usesBoundedSwarmPolicy(executionPlan);
|
|
522
|
+
const singleWorker = boundedSwarm && maxConcurrency === 1;
|
|
523
|
+
const needsPreactivation = !singleWorker && requiresSwarmPreactivation(executionPlan.kimiVersion);
|
|
524
|
+
// A direct worker still needs durable print ownership and patch recovery.
|
|
525
|
+
// Its record has no activated session and never requires web cleanup.
|
|
466
526
|
if (requiresSwarmPreactivation(executionPlan.kimiVersion)) {
|
|
467
527
|
const owner = await probeProcessIdentity(process.pid);
|
|
468
528
|
recovery = { schema: 1, jobId: job.job_id, ownerPid: process.pid, owner: owner.identity ?? null,
|
|
@@ -485,7 +545,7 @@ writeMode, executionCwd) {
|
|
|
485
545
|
expectedVersion: executionPlan.kimiVersion ?? undefined,
|
|
486
546
|
onRecoveryEvent: recovery ? (event) => recordRecoveryEvent(store, recovery, event) : undefined,
|
|
487
547
|
};
|
|
488
|
-
if (
|
|
548
|
+
if (needsPreactivation) {
|
|
489
549
|
store.updateRunningJob(job.job_id, { phase: "turn-running" });
|
|
490
550
|
const activationController = new AbortController();
|
|
491
551
|
const onParentAbort = () => activationController.abort();
|
|
@@ -573,6 +633,12 @@ writeMode, executionCwd) {
|
|
|
573
633
|
recordRecoveryEvent(store, recovery, { kind: "print-processes", identities: probe.identity ? [probe.identity] : [], complete: probe.complete });
|
|
574
634
|
}
|
|
575
635
|
},
|
|
636
|
+
onProcessIdentities: recovery
|
|
637
|
+
? (identities, complete) => recordRecoveryEvent(store, recovery, {
|
|
638
|
+
kind: boundedSwarm ? "print-processes-snapshot" : "print-processes",
|
|
639
|
+
identities: [...identities], complete,
|
|
640
|
+
})
|
|
641
|
+
: undefined,
|
|
576
642
|
signal: handlers.signal,
|
|
577
643
|
}, promptBudgetMs, "swarm.prompt");
|
|
578
644
|
if (recovery)
|
|
@@ -672,8 +738,14 @@ writeMode, executionCwd) {
|
|
|
672
738
|
writeMode?.onPatchCaptureFailure?.();
|
|
673
739
|
context.stderr.write(`[kimi-plugin-cc] swarm session cleanup also failed: ${cleanupFailure.message}\n`);
|
|
674
740
|
}
|
|
741
|
+
const processCleanupUnverified = hasUnverifiedProcessCleanup(error) || hasUnverifiedProcessCleanup(cleanupFailure);
|
|
742
|
+
const patchCaptureSkipped = writeMode !== undefined && processCleanupUnverified;
|
|
743
|
+
if (patchCaptureSkipped) {
|
|
744
|
+
writeMode.onPatchCaptureFailure?.();
|
|
745
|
+
context.stderr.write(`[kimi-plugin-cc] swarm-write process cleanup is unverified; no patch was captured. Worktree retained at ${writeMode.workspaceRoot}.\n`);
|
|
746
|
+
}
|
|
675
747
|
let captureFailed = writeMode !== undefined && error instanceof RuntimeError && error.code === "SWARM_PATCH_CAPTURE_FAILED";
|
|
676
|
-
if (writeMode && !(error instanceof RuntimeError && error.code === "SWARM_PATCH_CAPTURE_FAILED")) {
|
|
748
|
+
if (writeMode && !patchCaptureSkipped && !(error instanceof RuntimeError && error.code === "SWARM_PATCH_CAPTURE_FAILED")) {
|
|
677
749
|
const captured = await capturePatchArtifact(paths, job.job_id, writeMode.workspaceRoot, context.stderr, writeMode.onPatchCaptureFailure);
|
|
678
750
|
captureFailed = captured === null;
|
|
679
751
|
if (recovery && captured)
|
|
@@ -686,7 +758,9 @@ writeMode, executionCwd) {
|
|
|
686
758
|
...(error instanceof RuntimeError && typeof error.details.exit_code === "number"
|
|
687
759
|
? { exit_code: error.details.exit_code }
|
|
688
760
|
: {}),
|
|
689
|
-
...((captureFailed || cleanupFailure) && writeMode ? { worktreePath: writeMode.workspaceRoot } : {}),
|
|
761
|
+
...((captureFailed || cleanupFailure || patchCaptureSkipped) && writeMode ? { worktreePath: writeMode.workspaceRoot } : {}),
|
|
762
|
+
...(processCleanupUnverified ? { process_cleanup_unverified: true } : {}),
|
|
763
|
+
...(patchCaptureSkipped ? { patch_capture_skipped: true } : {}),
|
|
690
764
|
...(cleanupFailure
|
|
691
765
|
? {
|
|
692
766
|
cleanup_error: {
|
|
@@ -703,9 +777,11 @@ writeMode, executionCwd) {
|
|
|
703
777
|
const cancellationCause = classifyManagedCommandFailure(error, writeMode ? "rescue" : "review", job.job_id, {
|
|
704
778
|
preserveStage: true,
|
|
705
779
|
});
|
|
706
|
-
const cancelledError = new RuntimeError("SWARM_CANCELLED",
|
|
707
|
-
? `Swarm cancelled; patch
|
|
708
|
-
:
|
|
780
|
+
const cancelledError = new RuntimeError("SWARM_CANCELLED", patchCaptureSkipped && writeMode
|
|
781
|
+
? `Swarm cancelled; process cleanup is unverified. No patch was captured; worktree retained at ${writeMode.workspaceRoot}.`
|
|
782
|
+
: captureFailed && writeMode
|
|
783
|
+
? `Swarm cancelled; patch capture failed and worktree retained at ${writeMode.workspaceRoot}.`
|
|
784
|
+
: "Swarm cancelled by user request.", "swarm.runtime", {
|
|
709
785
|
...(error instanceof Error ? { cause: error } : {}),
|
|
710
786
|
details: {
|
|
711
787
|
...(cancellationCause instanceof RuntimeError ? cancellationCause.details : {}),
|
|
@@ -722,13 +798,13 @@ writeMode, executionCwd) {
|
|
|
722
798
|
const classified = classifyManagedCommandFailure(error, writeMode ? "rescue" : "review", job.job_id, {
|
|
723
799
|
preserveStage: true,
|
|
724
800
|
});
|
|
725
|
-
const withRecovery = captureFailed || cleanupFailure
|
|
801
|
+
const withRecovery = captureFailed || cleanupFailure || processCleanupUnverified
|
|
726
802
|
? classified instanceof RuntimeError
|
|
727
803
|
? new RuntimeError(classified.code, classified.message, classified.stage, {
|
|
728
804
|
cause: classified,
|
|
729
805
|
details: { ...classified.details, ...recoveryDetails },
|
|
730
806
|
})
|
|
731
|
-
: new RuntimeError(cleanupFailure?.code ?? "SWARM_PATCH_CAPTURE_FAILED", classified.message, cleanupFailure?.stage ?? "swarm.patch-capture", { cause: classified, details: recoveryDetails })
|
|
807
|
+
: new RuntimeError(cleanupFailure?.code ?? (processCleanupUnverified ? "CLI_PROCESS_SETTLEMENT_FAILED" : "SWARM_PATCH_CAPTURE_FAILED"), classified.message, cleanupFailure?.stage ?? (processCleanupUnverified ? "cli-client.settlement" : "swarm.patch-capture"), { cause: classified, details: recoveryDetails })
|
|
732
808
|
: classified;
|
|
733
809
|
return await markJobFailed(store, paths, job, withRecovery, "Swarm failed.", { phase: "failed" });
|
|
734
810
|
}
|
|
@@ -752,6 +828,18 @@ writeMode, executionCwd) {
|
|
|
752
828
|
}
|
|
753
829
|
}
|
|
754
830
|
}
|
|
831
|
+
function hasUnverifiedProcessCleanup(error) {
|
|
832
|
+
// Budget expiry wraps teardown failures. Preserve the unsafe-settlement
|
|
833
|
+
// signal through that cause chain before considering any patch capture.
|
|
834
|
+
const seen = new Set();
|
|
835
|
+
while (error instanceof Error && !seen.has(error)) {
|
|
836
|
+
seen.add(error);
|
|
837
|
+
if (error instanceof RuntimeError && (error.code === "CLI_PROCESS_SETTLEMENT_FAILED" || error.details.process_cleanup_unverified === true))
|
|
838
|
+
return true;
|
|
839
|
+
error = error.cause;
|
|
840
|
+
}
|
|
841
|
+
return false;
|
|
842
|
+
}
|
|
755
843
|
function shorten(text, max) {
|
|
756
844
|
const normalized = text.replace(/\s+/g, " ").trim();
|
|
757
845
|
if (normalized.length <= max) {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
// `/bin/sh -c` does not depend on its working directory or PATH.
|
|
28
28
|
import { decideHookOutcome } from "./approval-policy.js";
|
|
29
29
|
import { evaluateRescueHookRequest } from "../rescue-approval.js";
|
|
30
|
+
import { SWARM_POLICY_ENV, SWARM_WAVE_SIZE_ENV } from "../swarm-policy.js";
|
|
30
31
|
const STDIN_TIMEOUT_MS = 5_000;
|
|
31
32
|
async function main() {
|
|
32
33
|
const stdinText = await readStdinWithTimeout(STDIN_TIMEOUT_MS);
|
|
@@ -45,6 +46,8 @@ async function main() {
|
|
|
45
46
|
const decision = await decideHookOutcome(input, {
|
|
46
47
|
commandLabel: process.env.KIMI_PLUGIN_CC_CMD,
|
|
47
48
|
operationKind: process.env.KIMI_PLUGIN_CC_OPERATION,
|
|
49
|
+
swarmPolicy: process.env[SWARM_POLICY_ENV],
|
|
50
|
+
swarmWaveSize: process.env[SWARM_WAVE_SIZE_ENV],
|
|
48
51
|
rescueEvaluator: evaluateRescueHookRequest,
|
|
49
52
|
// Trusted root for rescue/pursue/swarm-write. Set by the plugin spawn; the
|
|
50
53
|
// model inside kimi cannot forge it and hook payload cwd is not trusted.
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// stdin/stdout/exit semantics so callers can test this policy without mocking
|
|
3
|
-
// process IO.
|
|
4
|
-
//
|
|
5
|
-
// `kimi -p` hard-codes `permission: 'auto'`, and PreToolUse fires before
|
|
6
|
-
// permission rules, so this hook is load-bearing for read-only commands.
|
|
7
|
-
// Unknown command labels fail closed to READ_ONLY_TOOLS. An absent
|
|
8
|
-
// KIMI_PLUGIN_CC_CMD means out-of-plugin use and remains unrestricted.
|
|
1
|
+
import { BOUNDED_SWARM_POLICY, evaluateSwarmWaveInput } from "../swarm-policy.js";
|
|
9
2
|
/**
|
|
10
3
|
* Tools considered read-only across review/challenge/review_gate/rescue.
|
|
11
4
|
*
|
|
@@ -80,6 +73,26 @@ export function decideHookOutcomePure(input, ctx) {
|
|
|
80
73
|
return { decision: "allow" };
|
|
81
74
|
}
|
|
82
75
|
const toolName = typeof input.tool_name === "string" ? input.tool_name : "";
|
|
76
|
+
if ((label === "swarm" || label === "swarm-write") &&
|
|
77
|
+
(ctx.swarmPolicy !== undefined || ctx.swarmWaveSize !== undefined)) {
|
|
78
|
+
if (toolName === AGENT_SWARM_TOOL) {
|
|
79
|
+
return evaluateSwarmWaveInput(input.tool_input, ctx.swarmPolicy, ctx.swarmWaveSize);
|
|
80
|
+
}
|
|
81
|
+
if (toolName === "Agent") {
|
|
82
|
+
return {
|
|
83
|
+
decision: "deny",
|
|
84
|
+
reason: "kimi-plugin-cc safety hook: singular Agent delegation is denied for bounded swarm jobs.",
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const args = input.tool_input;
|
|
88
|
+
if (toolName === "Bash" && typeof args === "object" && args !== null &&
|
|
89
|
+
args.run_in_background === true) {
|
|
90
|
+
return {
|
|
91
|
+
decision: "deny",
|
|
92
|
+
reason: "kimi-plugin-cc safety hook: run commands in the foreground; explicit background commands are disabled for bounded swarm execution.",
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
83
96
|
if (PLAN_MODE_TOOLS.has(toolName)) {
|
|
84
97
|
return {
|
|
85
98
|
decision: "deny",
|
|
@@ -133,14 +146,15 @@ export function decideHookOutcomePure(input, ctx) {
|
|
|
133
146
|
// AgentSwarm are allowed and the singular Agent stays denied. This adds
|
|
134
147
|
// no direct tool-write permission within the repository/Git trust
|
|
135
148
|
// boundary: read-only Git context commands still trust repository Git
|
|
136
|
-
// configuration and can execute configured helpers.
|
|
137
|
-
//
|
|
149
|
+
// configuration and can execute configured helpers. Exact 2.6.2 waves
|
|
150
|
+
// pass the admission guard above; fresh children cannot activate swarm
|
|
151
|
+
// mode. Older paths retain their inherited scheduler limitations.
|
|
138
152
|
if (READ_ONLY_TOOLS.has(toolName) || toolName === AGENT_SWARM_TOOL) {
|
|
139
153
|
return { decision: "allow" };
|
|
140
154
|
}
|
|
141
155
|
return {
|
|
142
156
|
decision: "deny",
|
|
143
|
-
reason: denySwarmMessage(toolName),
|
|
157
|
+
reason: denySwarmMessage(toolName, ctx.swarmPolicy === BOUNDED_SWARM_POLICY && ctx.swarmWaveSize === "1"),
|
|
144
158
|
};
|
|
145
159
|
case "swarm-write": {
|
|
146
160
|
// Write-capable fan-out runs in an ephemeral worktree. AgentSwarm and the
|
|
@@ -200,8 +214,16 @@ function denyReadOnlyMessage(label, toolName) {
|
|
|
200
214
|
"If you need to mutate state, the user must invoke /kimi:rescue (write-capable) rather than this command.",
|
|
201
215
|
].join(" ");
|
|
202
216
|
}
|
|
203
|
-
function denySwarmMessage(toolName) {
|
|
217
|
+
function denySwarmMessage(toolName, singleWorker) {
|
|
204
218
|
const tool = toolName.length > 0 ? toolName : "<unspecified>";
|
|
219
|
+
if (singleWorker) {
|
|
220
|
+
return [
|
|
221
|
+
"kimi-plugin-cc safety hook: swarm with concurrency 1 is a read-only review.",
|
|
222
|
+
`Tool "${tool}" is denied — use Read, Grep, or Glob to inspect the workspace.`,
|
|
223
|
+
"Complete the review yourself; delegation is denied.",
|
|
224
|
+
"Return your findings in a markdown report.",
|
|
225
|
+
].join(" ");
|
|
226
|
+
}
|
|
205
227
|
return [
|
|
206
228
|
"kimi-plugin-cc safety hook: swarm is a read-only parallel review.",
|
|
207
229
|
`Tool "${tool}" is denied — every subagent may use Read, Grep, or Glob to inspect the workspace,`,
|
|
@@ -596,9 +596,9 @@ function validateVersionSensitiveEvents(events, version) {
|
|
|
596
596
|
// 2.0.2 (9d07f634), 2.1.0 (52437299), 2.1.1 (f67e6398), 2.2.0 (472192c3),
|
|
597
597
|
// 2.3.0 (b5e28fd6), 2.3.1 (684bae9e), 2.3.2 (b8dd3a13), 2.3.3 (ec495f0c),
|
|
598
598
|
// 2.4.0 (f26e4d91), 2.4.1 (2c73f3f5), 2.5.0 (41c34143), 2.5.1 (1b02030d),
|
|
599
|
-
// 2.5.2 (1c142a00), 2.5.3 (5af9942e),
|
|
600
|
-
// the additive events and HookDefSchema are unchanged. Exact 2.6.
|
|
601
|
-
//
|
|
599
|
+
// 2.5.2 (1c142a00), 2.5.3 (5af9942e), 2.6.0 (740d6c0b), and 2.6.2
|
|
600
|
+
// (6a8493df): the additive events and HookDefSchema are unchanged. Exact 2.6.x
|
|
601
|
+
// schema acceptance does not certify swarm operations.
|
|
602
602
|
// Require the full version string AND matching components; no inferred 2.x compatibility.
|
|
603
603
|
if (version.major === 2 && ((version.minor === 0 && ((version.version === "2.0.0" && version.patch === 0) ||
|
|
604
604
|
(version.version === "2.0.1" && version.patch === 1) ||
|
|
@@ -616,7 +616,8 @@ function validateVersionSensitiveEvents(events, version) {
|
|
|
616
616
|
(version.version === "2.5.1" && version.patch === 1) ||
|
|
617
617
|
(version.version === "2.5.2" && version.patch === 2) ||
|
|
618
618
|
(version.version === "2.5.3" && version.patch === 3))) ||
|
|
619
|
-
(version.minor === 6 && ((version.version === "2.6.0" && version.patch === 0)
|
|
619
|
+
(version.minor === 6 && ((version.version === "2.6.0" && version.patch === 0) ||
|
|
620
|
+
(version.version === "2.6.2" && version.patch === 2))))) {
|
|
620
621
|
return { valid: true };
|
|
621
622
|
}
|
|
622
623
|
if (version.major !== 0) {
|
|
@@ -49,11 +49,13 @@ export const NATIVE_V2_CERTIFIED_VERSIONS = Object.freeze([
|
|
|
49
49
|
"2.5.1",
|
|
50
50
|
"2.5.2",
|
|
51
51
|
"2.5.3",
|
|
52
|
+
"2.6.2",
|
|
52
53
|
]);
|
|
53
54
|
/**
|
|
54
55
|
* Exact releases certified only for review, challenge, ask, rescue, review_gate
|
|
55
56
|
* and pursue. Their upstream rate-limit recovery can exceed AgentSwarm's
|
|
56
|
-
* configured maximum,
|
|
57
|
+
* configured maximum, and these releases lack a certified plugin admission
|
|
58
|
+
* construction, so both swarm operations refuse before model spawn.
|
|
57
59
|
*/
|
|
58
60
|
export const NATIVE_V2_NON_SWARM_VERSIONS = Object.freeze(["2.6.0"]);
|
|
59
61
|
/**
|
|
@@ -64,7 +66,7 @@ export const NATIVE_V2_NON_SWARM_VERSIONS = Object.freeze(["2.6.0"]);
|
|
|
64
66
|
export const NATIVE_V2_ANY_OPERATION_VERSIONS = Object.freeze([
|
|
65
67
|
...NATIVE_V2_CERTIFIED_VERSIONS,
|
|
66
68
|
...NATIVE_V2_NON_SWARM_VERSIONS,
|
|
67
|
-
]);
|
|
69
|
+
].sort((left, right) => left.localeCompare(right, "en", { numeric: true })));
|
|
68
70
|
/** Per-operation native-v2 certification. One green operation never certifies another. */
|
|
69
71
|
export const NATIVE_V2_CERTIFIED = new Map([
|
|
70
72
|
["review", NATIVE_V2_ANY_OPERATION_VERSIONS],
|
|
@@ -567,7 +569,7 @@ function nativeV2NotCertified(operationKind, version) {
|
|
|
567
569
|
if (normalized !== undefined &&
|
|
568
570
|
NATIVE_V2_NON_SWARM_VERSIONS.includes(normalized) &&
|
|
569
571
|
(operationKind === "swarm" || operationKind === "swarm-write")) {
|
|
570
|
-
return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind}: kimi-code ${normalized} is certified only for non-swarm operations (review, challenge, ask, rescue, review_gate, pursue). Its
|
|
572
|
+
return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind}: kimi-code ${normalized} is certified only for non-swarm operations (review, challenge, ask, rescue, review_gate, pursue). Its native rate-limit recovery can exceed AgentSwarm's configured maximum, so this exact release refuses swarm before model spawn. Select exact kimi-code 2.6.2 for this plugin's certified bounded waves and single-worker path, or use a non-swarm operation on ${normalized}.`, "kimi-engine.capability", {
|
|
571
573
|
details: {
|
|
572
574
|
refusal_kind: "v2-swarm-not-certified",
|
|
573
575
|
certification_scope: "non-swarm",
|
|
@@ -22,10 +22,10 @@ export const KIMI_PURSUE_DEFAULT_BUDGET_MS = 2_700_000; // 45 minutes
|
|
|
22
22
|
/**
|
|
23
23
|
* Swarm (read-only parallel fan-out) DEFAULT wall-clock ceiling when the user
|
|
24
24
|
* passes no `--budget`. Read-only swarm opens no write surface, so the only new
|
|
25
|
-
* risk is
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
25
|
+
* risk is cost/runaway from repeated model work. This AbortController bounds
|
|
26
|
+
* the whole job; `--cap` remains a soft lifetime-count hint. Exact 2.6.2 also
|
|
27
|
+
* bounds wave cardinality and prevents child timeouts from overlapping waves;
|
|
28
|
+
* a requested concurrency of one runs a direct worker. Sized like the single-turn
|
|
29
29
|
* review budget — a swarm fans review work out in parallel within one process,
|
|
30
30
|
* so 30m of wall-clock is generous headroom. Overridable per-job via `--budget`
|
|
31
31
|
* (parsed to ms in parseSwarmArgs). See runtime/commands/swarm.ts and
|
|
@@ -65,7 +65,7 @@ const CAP_PROPERTY = {
|
|
|
65
65
|
const MAX_CONCURRENCY_PROPERTY = {
|
|
66
66
|
type: "integer",
|
|
67
67
|
minimum: 1,
|
|
68
|
-
description: "
|
|
68
|
+
description: "Concurrent worker limit on exact Kimi Code 2.6.2: 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
69
|
};
|
|
70
70
|
const START_RESULT_GUIDANCE = "Task-capable clients receive an MCP task. Other clients receive a job ID immediately after launch; use kimi_job_status and kimi_job_result until terminal, and kimi_job_cancel to stop. Do not present a launch handle as the finished answer.";
|
|
71
71
|
function schema(properties, required = []) {
|