kimi-plugin-cc 2.5.9 → 2.6.3
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 +130 -41
- 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 +7 -4
- 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 +13 -8
- package/dist/swarm-policy.js +73 -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 +42 -17
- package/docs/swarm-recovery.md +4 -2
- package/docs/upstream-2.6.2-certification.md +93 -3
- package/docs/upstream-2.6.3-certification.md +88 -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 +130 -41
- 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 +7 -4
- 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 +13 -8
- package/plugins/kimi-codex/dist/swarm-policy.js +73 -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 +130 -41
- 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 +7 -4
- 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 +13 -8
- package/plugins/kimi-dsh/dist/swarm-policy.js +73 -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,28 +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/2.6.3 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
|
+
// web lifecycle, then resume it through the normal print path. 2.6.2/2.6.3 parallel
|
|
37
|
+
// waves and candidate-only 2.6.0 use that lifecycle too. The per-operation certification
|
|
36
38
|
// table controls whether each exact version is reachable in production.
|
|
37
39
|
const SWARM_SUMMARY_MAX = 120;
|
|
38
40
|
const SWARM_AGENT_PROFILE = "<swarm>";
|
|
39
41
|
const SWARM_WRITE_AGENT_PROFILE = "<swarm-write>";
|
|
40
42
|
/**
|
|
41
|
-
* Default
|
|
42
|
-
*
|
|
43
|
+
* Default concurrency setting when the user passes no `--max-concurrency`.
|
|
44
|
+
* Exact native-v2 2.6.2/2.6.3 also enforces this as the admitted wave size. The plugin exports
|
|
43
45
|
* KIMI_CODE_AGENT_SWARM_MAX_CONCURRENCY; older read-only swarms ignore it and
|
|
44
46
|
* retain only the wall-clock hard bound. Rate-limit recovery can exceed it on
|
|
45
|
-
* reviewed
|
|
47
|
+
* older reviewed sources; their setting is not an unconditional peak guarantee.
|
|
46
48
|
*/
|
|
47
49
|
export const SWARM_DEFAULT_MAX_CONCURRENCY = 4;
|
|
48
50
|
/**
|
|
@@ -55,10 +57,10 @@ export function resolveSwarmMaxConcurrency(requested) {
|
|
|
55
57
|
return requested ?? SWARM_DEFAULT_MAX_CONCURRENCY;
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
58
|
-
* Default
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
60
|
+
* Default concurrency for WRITE mode — 1 vs read's 4. Exact native-v2 2.6.2/2.6.3
|
|
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.
|
|
62
64
|
* Override with an explicit `--max-concurrency N`.
|
|
63
65
|
*/
|
|
64
66
|
export const SWARM_WRITE_DEFAULT_MAX_CONCURRENCY = 1;
|
|
@@ -76,14 +78,28 @@ export function resolveSwarmWriteMaxConcurrency(requested) {
|
|
|
76
78
|
* Read-only is NOT enforced by this prose — the PreToolUse hook (swarm label) at
|
|
77
79
|
* policy index 0 denies every write/edit/shell for the coordinator AND every
|
|
78
80
|
* subagent, so slimming this text does not move the safety boundary. The optional
|
|
79
|
-
* `cap` is a SOFT subagent-count hint
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* 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.
|
|
84
85
|
*/
|
|
85
|
-
export function buildSwarmPrompt(objective, cap) {
|
|
86
|
+
export function buildSwarmPrompt(objective, cap, waveSize) {
|
|
86
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
|
+
}
|
|
87
103
|
const capClause = cap !== undefined
|
|
88
104
|
? `Use at most ${cap} subagents in total across the whole run (soft cap); split or group targets to stay within it.`
|
|
89
105
|
: undefined;
|
|
@@ -98,6 +114,7 @@ export function buildSwarmPrompt(objective, cap) {
|
|
|
98
114
|
"workspace directly with the allowed read-only tools).",
|
|
99
115
|
"Fan the work out across the relevant targets in parallel using your own subagent capability,",
|
|
100
116
|
"as you judge best — split or group the work however fits the objective.",
|
|
117
|
+
...boundedWaveInstructions(waveSize),
|
|
101
118
|
...(capClause ? [capClause] : []),
|
|
102
119
|
"",
|
|
103
120
|
"Consolidate into a single markdown report: deduplicate findings, preserve coverage across",
|
|
@@ -108,17 +125,38 @@ export function buildSwarmPrompt(objective, cap) {
|
|
|
108
125
|
}
|
|
109
126
|
/**
|
|
110
127
|
* Build the WRITE-mode coordination prompt. Unlike the read-only prompt, this
|
|
111
|
-
* sets subagent_type="coder" (write-capable) and instructs DISJOINT
|
|
112
|
-
*
|
|
128
|
+
* sets subagent_type="coder" (write-capable) and instructs DISJOINT target
|
|
129
|
+
* assignments with NO git and NO nested swarm. The coordinator and all
|
|
113
130
|
* subagents run in an ephemeral throwaway worktree; the PreToolUse hook
|
|
114
131
|
* (swarm-write label) confines writes there and the plugin captures a patch the
|
|
115
132
|
* user reviews. The `cap` is the same SOFT total-count hint as read mode.
|
|
116
133
|
*/
|
|
117
|
-
export function buildSwarmWritePrompt(objective, cap) {
|
|
134
|
+
export function buildSwarmWritePrompt(objective, cap, waveSize) {
|
|
118
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
|
+
}
|
|
119
155
|
const capClause = cap !== undefined
|
|
120
156
|
? `Launch at most ${cap} subagents in total across the whole run (soft cap — split or group targets to stay within it).`
|
|
121
|
-
:
|
|
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.";
|
|
122
160
|
return [
|
|
123
161
|
"Coordinate a parallel CODE-EDITING task using the AgentSwarm tool.",
|
|
124
162
|
"",
|
|
@@ -127,8 +165,16 @@ export function buildSwarmWritePrompt(objective, cap) {
|
|
|
127
165
|
"You are running inside a throwaway git worktree dedicated to this task — edit freely;",
|
|
128
166
|
"your changes will be captured as a patch for the human to review and apply. Use the",
|
|
129
167
|
'AgentSwarm tool to fan the work out across subagents. Set subagent_type to "coder" (the',
|
|
130
|
-
|
|
131
|
-
|
|
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),
|
|
132
178
|
capClause,
|
|
133
179
|
"",
|
|
134
180
|
"Safety rules enforced by the PreToolUse hook (violations are denied):",
|
|
@@ -148,6 +194,15 @@ export function buildSwarmWritePrompt(objective, cap) {
|
|
|
148
194
|
"no JSON wrapper, no outer code fences.",
|
|
149
195
|
].join("\n");
|
|
150
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
|
+
}
|
|
151
206
|
export async function runSwarm(argv, context) {
|
|
152
207
|
const parsed = parseSwarmArgs(argv);
|
|
153
208
|
const objective = parsed.objective?.trim();
|
|
@@ -171,7 +226,8 @@ async function runReadSwarm(parsed, objective, context) {
|
|
|
171
226
|
cwd: context.cwd,
|
|
172
227
|
env: context.env,
|
|
173
228
|
});
|
|
174
|
-
const
|
|
229
|
+
const maxConcurrency = resolveSwarmMaxConcurrency(parsed.maxConcurrency);
|
|
230
|
+
const prompt = buildSwarmPrompt(objective, parsed.cap, usesBoundedSwarmPolicy(executionPlan) ? maxConcurrency : undefined);
|
|
175
231
|
const jobId = allocateJobId(context);
|
|
176
232
|
const logPath = path.join(paths.logsDir, `swarm-${jobId}.jsonl`);
|
|
177
233
|
const job = store.createJob({
|
|
@@ -212,7 +268,7 @@ async function runReadSwarm(parsed, objective, context) {
|
|
|
212
268
|
await markJobFailed(store, paths, job, classified, "Swarm failed.", { phase: "failed" });
|
|
213
269
|
throw classified;
|
|
214
270
|
}
|
|
215
|
-
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));
|
|
216
272
|
if (!completed.final_output_path) {
|
|
217
273
|
throw new RuntimeError("SWARM_RESULT_MISSING", "Swarm finished without a rendered result.", "swarm.result");
|
|
218
274
|
}
|
|
@@ -248,7 +304,7 @@ async function runWriteSwarm(parsed, objective, context) {
|
|
|
248
304
|
if (await isWorkingTreeDirty(context.cwd)) {
|
|
249
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");
|
|
250
306
|
}
|
|
251
|
-
const
|
|
307
|
+
const maxConcurrency = resolveSwarmWriteMaxConcurrency(parsed.maxConcurrency);
|
|
252
308
|
const jobId = allocateJobId(context);
|
|
253
309
|
const logPath = path.join(paths.logsDir, `swarm-write-${jobId}.jsonl`);
|
|
254
310
|
// Namespace worktrees per repo so the cross-repo sweep below only ever
|
|
@@ -274,6 +330,7 @@ async function runWriteSwarm(parsed, objective, context) {
|
|
|
274
330
|
cwd: worktreePath,
|
|
275
331
|
env: context.env,
|
|
276
332
|
});
|
|
333
|
+
const prompt = buildSwarmWritePrompt(objective, parsed.cap, usesBoundedSwarmPolicy(executionPlan) ? maxConcurrency : undefined);
|
|
277
334
|
const job = store.createJob({
|
|
278
335
|
job_id: jobId,
|
|
279
336
|
repo_id: repoIdentity.repoId,
|
|
@@ -316,7 +373,7 @@ async function runWriteSwarm(parsed, objective, context) {
|
|
|
316
373
|
});
|
|
317
374
|
throw classified;
|
|
318
375
|
}
|
|
319
|
-
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, {
|
|
320
377
|
spawnCwd: worktreePath,
|
|
321
378
|
workspaceRoot: worktreePath,
|
|
322
379
|
onPatchCaptureFailure: () => {
|
|
@@ -405,8 +462,8 @@ writeMode, executionCwd) {
|
|
|
405
462
|
store.close();
|
|
406
463
|
throw new RuntimeError("JOB_NOT_FOUND", `Swarm job ${jobId} was not found.`, "swarm.worker");
|
|
407
464
|
}
|
|
408
|
-
// Both modes
|
|
409
|
-
// 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
|
|
410
467
|
// worktree. Fail closed before spawning.
|
|
411
468
|
if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
|
|
412
469
|
const installStatus = await verifyHookInstalled(context.env);
|
|
@@ -414,8 +471,7 @@ writeMode, executionCwd) {
|
|
|
414
471
|
maybeWarnHookMissing(installStatus, "swarm", context.stderr);
|
|
415
472
|
const classified = new RuntimeError("SWARM_HOOK_NOT_INSTALLED", [
|
|
416
473
|
"/kimi:swarm refuses to run without the kimi-plugin-cc PreToolUse hook.",
|
|
417
|
-
"
|
|
418
|
-
"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.",
|
|
419
475
|
`Hook check failed: ${installStatus.reason ?? "unknown"}.`,
|
|
420
476
|
"Repair by running Claude Code /kimi:setup or Codex $kimi-setup, then retry.",
|
|
421
477
|
hookRefusalRetryProtocol(context.env),
|
|
@@ -462,6 +518,11 @@ writeMode, executionCwd) {
|
|
|
462
518
|
};
|
|
463
519
|
try {
|
|
464
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.
|
|
465
526
|
if (requiresSwarmPreactivation(executionPlan.kimiVersion)) {
|
|
466
527
|
const owner = await probeProcessIdentity(process.pid);
|
|
467
528
|
recovery = { schema: 1, jobId: job.job_id, ownerPid: process.pid, owner: owner.identity ?? null,
|
|
@@ -484,7 +545,7 @@ writeMode, executionCwd) {
|
|
|
484
545
|
expectedVersion: executionPlan.kimiVersion ?? undefined,
|
|
485
546
|
onRecoveryEvent: recovery ? (event) => recordRecoveryEvent(store, recovery, event) : undefined,
|
|
486
547
|
};
|
|
487
|
-
if (
|
|
548
|
+
if (needsPreactivation) {
|
|
488
549
|
store.updateRunningJob(job.job_id, { phase: "turn-running" });
|
|
489
550
|
const activationController = new AbortController();
|
|
490
551
|
const onParentAbort = () => activationController.abort();
|
|
@@ -572,6 +633,12 @@ writeMode, executionCwd) {
|
|
|
572
633
|
recordRecoveryEvent(store, recovery, { kind: "print-processes", identities: probe.identity ? [probe.identity] : [], complete: probe.complete });
|
|
573
634
|
}
|
|
574
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,
|
|
575
642
|
signal: handlers.signal,
|
|
576
643
|
}, promptBudgetMs, "swarm.prompt");
|
|
577
644
|
if (recovery)
|
|
@@ -671,8 +738,14 @@ writeMode, executionCwd) {
|
|
|
671
738
|
writeMode?.onPatchCaptureFailure?.();
|
|
672
739
|
context.stderr.write(`[kimi-plugin-cc] swarm session cleanup also failed: ${cleanupFailure.message}\n`);
|
|
673
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
|
+
}
|
|
674
747
|
let captureFailed = writeMode !== undefined && error instanceof RuntimeError && error.code === "SWARM_PATCH_CAPTURE_FAILED";
|
|
675
|
-
if (writeMode && !(error instanceof RuntimeError && error.code === "SWARM_PATCH_CAPTURE_FAILED")) {
|
|
748
|
+
if (writeMode && !patchCaptureSkipped && !(error instanceof RuntimeError && error.code === "SWARM_PATCH_CAPTURE_FAILED")) {
|
|
676
749
|
const captured = await capturePatchArtifact(paths, job.job_id, writeMode.workspaceRoot, context.stderr, writeMode.onPatchCaptureFailure);
|
|
677
750
|
captureFailed = captured === null;
|
|
678
751
|
if (recovery && captured)
|
|
@@ -685,7 +758,9 @@ writeMode, executionCwd) {
|
|
|
685
758
|
...(error instanceof RuntimeError && typeof error.details.exit_code === "number"
|
|
686
759
|
? { exit_code: error.details.exit_code }
|
|
687
760
|
: {}),
|
|
688
|
-
...((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 } : {}),
|
|
689
764
|
...(cleanupFailure
|
|
690
765
|
? {
|
|
691
766
|
cleanup_error: {
|
|
@@ -702,9 +777,11 @@ writeMode, executionCwd) {
|
|
|
702
777
|
const cancellationCause = classifyManagedCommandFailure(error, writeMode ? "rescue" : "review", job.job_id, {
|
|
703
778
|
preserveStage: true,
|
|
704
779
|
});
|
|
705
|
-
const cancelledError = new RuntimeError("SWARM_CANCELLED",
|
|
706
|
-
? `Swarm cancelled; patch
|
|
707
|
-
:
|
|
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", {
|
|
708
785
|
...(error instanceof Error ? { cause: error } : {}),
|
|
709
786
|
details: {
|
|
710
787
|
...(cancellationCause instanceof RuntimeError ? cancellationCause.details : {}),
|
|
@@ -721,13 +798,13 @@ writeMode, executionCwd) {
|
|
|
721
798
|
const classified = classifyManagedCommandFailure(error, writeMode ? "rescue" : "review", job.job_id, {
|
|
722
799
|
preserveStage: true,
|
|
723
800
|
});
|
|
724
|
-
const withRecovery = captureFailed || cleanupFailure
|
|
801
|
+
const withRecovery = captureFailed || cleanupFailure || processCleanupUnverified
|
|
725
802
|
? classified instanceof RuntimeError
|
|
726
803
|
? new RuntimeError(classified.code, classified.message, classified.stage, {
|
|
727
804
|
cause: classified,
|
|
728
805
|
details: { ...classified.details, ...recoveryDetails },
|
|
729
806
|
})
|
|
730
|
-
: 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 })
|
|
731
808
|
: classified;
|
|
732
809
|
return await markJobFailed(store, paths, job, withRecovery, "Swarm failed.", { phase: "failed" });
|
|
733
810
|
}
|
|
@@ -751,6 +828,18 @@ writeMode, executionCwd) {
|
|
|
751
828
|
}
|
|
752
829
|
}
|
|
753
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
|
+
}
|
|
754
843
|
function shorten(text, max) {
|
|
755
844
|
const normalized = text.replace(/\s+/g, " ").trim();
|
|
756
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/2.6.3 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), 2.6.0 (740d6c0b),
|
|
600
|
-
// (6a8493df): the additive events and HookDefSchema are
|
|
601
|
-
// schema acceptance does not certify swarm operations.
|
|
599
|
+
// 2.5.2 (1c142a00), 2.5.3 (5af9942e), 2.6.0 (740d6c0b), 2.6.2
|
|
600
|
+
// (6a8493df), and 2.6.3 (b0de2fbd): the additive events and HookDefSchema are
|
|
601
|
+
// unchanged. Exact 2.6.x 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) ||
|
|
@@ -617,7 +617,8 @@ function validateVersionSensitiveEvents(events, version) {
|
|
|
617
617
|
(version.version === "2.5.2" && version.patch === 2) ||
|
|
618
618
|
(version.version === "2.5.3" && version.patch === 3))) ||
|
|
619
619
|
(version.minor === 6 && ((version.version === "2.6.0" && version.patch === 0) ||
|
|
620
|
-
(version.version === "2.6.2" && version.patch === 2)
|
|
620
|
+
(version.version === "2.6.2" && version.patch === 2) ||
|
|
621
|
+
(version.version === "2.6.3" && version.patch === 3))))) {
|
|
621
622
|
return { valid: true };
|
|
622
623
|
}
|
|
623
624
|
if (version.major !== 0) {
|
|
@@ -49,13 +49,16 @@ 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",
|
|
53
|
+
"2.6.3",
|
|
52
54
|
]);
|
|
53
55
|
/**
|
|
54
56
|
* Exact releases certified only for review, challenge, ask, rescue, review_gate
|
|
55
57
|
* and pursue. Their upstream rate-limit recovery can exceed AgentSwarm's
|
|
56
|
-
* configured maximum,
|
|
58
|
+
* configured maximum, and these releases lack a certified plugin admission
|
|
59
|
+
* construction, so both swarm operations refuse before model spawn.
|
|
57
60
|
*/
|
|
58
|
-
export const NATIVE_V2_NON_SWARM_VERSIONS = Object.freeze(["2.6.0"
|
|
61
|
+
export const NATIVE_V2_NON_SWARM_VERSIONS = Object.freeze(["2.6.0"]);
|
|
59
62
|
/**
|
|
60
63
|
* Any-operation union used by setup and engine selection. The older
|
|
61
64
|
* NATIVE_V2_CERTIFIED_VERSIONS export stays all-operation-only for consumers
|
|
@@ -64,7 +67,7 @@ export const NATIVE_V2_NON_SWARM_VERSIONS = Object.freeze(["2.6.0", "2.6.2"]);
|
|
|
64
67
|
export const NATIVE_V2_ANY_OPERATION_VERSIONS = Object.freeze([
|
|
65
68
|
...NATIVE_V2_CERTIFIED_VERSIONS,
|
|
66
69
|
...NATIVE_V2_NON_SWARM_VERSIONS,
|
|
67
|
-
]);
|
|
70
|
+
].sort((left, right) => left.localeCompare(right, "en", { numeric: true })));
|
|
68
71
|
/** Per-operation native-v2 certification. One green operation never certifies another. */
|
|
69
72
|
export const NATIVE_V2_CERTIFIED = new Map([
|
|
70
73
|
["review", NATIVE_V2_ANY_OPERATION_VERSIONS],
|
|
@@ -567,7 +570,7 @@ function nativeV2NotCertified(operationKind, version) {
|
|
|
567
570
|
if (normalized !== undefined &&
|
|
568
571
|
NATIVE_V2_NON_SWARM_VERSIONS.includes(normalized) &&
|
|
569
572
|
(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
|
|
573
|
+
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 or 2.6.3 for this plugin's certified bounded waves and single-worker path, or use a non-swarm operation on ${normalized}.`, "kimi-engine.capability", {
|
|
571
574
|
details: {
|
|
572
575
|
refusal_kind: "v2-swarm-not-certified",
|
|
573
576
|
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/2.6.3 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/2.6.3: one runs directly; larger values bound each native swarm wave. Older certified versions limit normal launches only and recovery can exceed it. Distinct from the soft total cap.",
|
|
69
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 = []) {
|