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
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { link, lstat, mkdir, open, realpath, unlink } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { RuntimeError } from "./errors.js";
|
|
6
|
+
const POLICY_CONTENT = `${JSON.stringify({ disabledTools: ["TaskStop"] })}\n`;
|
|
7
|
+
const POLICY_MAX_BYTES = 4096;
|
|
8
|
+
const SAFE_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,255}$/;
|
|
9
|
+
/**
|
|
10
|
+
* Called only for our fresh, stopped, journal-proven session before its first
|
|
11
|
+
* print turn. TaskStop is already denied by the managed hook; disabling it in
|
|
12
|
+
* native policy also makes Bash's allowBackground false for every child,
|
|
13
|
+
* including its automatic foreground-timeout detachment path.
|
|
14
|
+
*/
|
|
15
|
+
export async function installBoundedSwarmToolPolicy(kimiHome, identity, signal) {
|
|
16
|
+
const directories = [];
|
|
17
|
+
let candidatePath;
|
|
18
|
+
let candidateIdentity;
|
|
19
|
+
try {
|
|
20
|
+
checkSignal(signal);
|
|
21
|
+
if (!SAFE_ID.test(identity.sessionId) || !SAFE_ID.test(identity.workspaceId)) {
|
|
22
|
+
throw policyFailure("invalid-session-identity");
|
|
23
|
+
}
|
|
24
|
+
const canonicalHome = await realpath(kimiHome);
|
|
25
|
+
let current = canonicalHome;
|
|
26
|
+
for (const segment of [undefined, "sessions", identity.workspaceId, identity.sessionId]) {
|
|
27
|
+
if (segment !== undefined)
|
|
28
|
+
current = path.join(current, segment);
|
|
29
|
+
directories.push(await directoryIdentity(current));
|
|
30
|
+
checkSignal(signal);
|
|
31
|
+
}
|
|
32
|
+
const policyDir = path.join(current, "tool-policy");
|
|
33
|
+
await assertDirectoriesUnchanged(directories);
|
|
34
|
+
await mkdir(policyDir, { mode: 0o700 }).catch((error) => {
|
|
35
|
+
if (error.code !== "EEXIST")
|
|
36
|
+
throw error;
|
|
37
|
+
});
|
|
38
|
+
directories.push(await directoryIdentity(policyDir));
|
|
39
|
+
const statePath = path.join(policyDir, "state.json");
|
|
40
|
+
// No merge or replacement: this is a fresh-session construction, not an
|
|
41
|
+
// operator-policy editor. link() below closes this absence-check race.
|
|
42
|
+
const existing = await lstat(statePath).catch((error) => {
|
|
43
|
+
if (error.code === "ENOENT")
|
|
44
|
+
return undefined;
|
|
45
|
+
throw error;
|
|
46
|
+
});
|
|
47
|
+
if (existing !== undefined)
|
|
48
|
+
throw policyFailure("policy-already-exists");
|
|
49
|
+
checkSignal(signal);
|
|
50
|
+
await assertDirectoriesUnchanged(directories);
|
|
51
|
+
candidatePath = path.join(policyDir, `.state.${process.pid}.${randomUUID()}.tmp`);
|
|
52
|
+
const candidate = await open(candidatePath, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
|
|
53
|
+
try {
|
|
54
|
+
const stats = await candidate.stat({ bigint: true });
|
|
55
|
+
candidateIdentity = { dev: stats.dev, ino: stats.ino };
|
|
56
|
+
if (!stats.isFile())
|
|
57
|
+
throw policyFailure("candidate-not-regular");
|
|
58
|
+
if (process.platform !== "win32")
|
|
59
|
+
await candidate.chmod(0o600);
|
|
60
|
+
await candidate.writeFile(POLICY_CONTENT, "utf8");
|
|
61
|
+
await candidate.sync();
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
await candidate.close();
|
|
65
|
+
}
|
|
66
|
+
checkSignal(signal);
|
|
67
|
+
await assertDirectoriesUnchanged(directories);
|
|
68
|
+
// A hard link publishes the complete synced inode atomically and refuses
|
|
69
|
+
// an existing destination, unlike rename(), which could replace policy.
|
|
70
|
+
await link(candidatePath, statePath);
|
|
71
|
+
await verifyPublishedPolicy(statePath, candidateIdentity);
|
|
72
|
+
await assertDirectoriesUnchanged(directories);
|
|
73
|
+
checkSignal(signal);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (signal?.aborted)
|
|
77
|
+
throw policyFailure("cancelled", true);
|
|
78
|
+
if (error instanceof RuntimeError)
|
|
79
|
+
throw error;
|
|
80
|
+
throw policyFailure("policy-installation-failed");
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
// Never unlink a replacement or follow a replaced ancestor while cleaning
|
|
84
|
+
// up our private candidate. An uncertain path remains as failure evidence.
|
|
85
|
+
if (candidatePath !== undefined && candidateIdentity !== undefined) {
|
|
86
|
+
try {
|
|
87
|
+
await assertDirectoriesUnchanged(directories);
|
|
88
|
+
const stats = await lstat(candidatePath, { bigint: true });
|
|
89
|
+
if (stats.isFile() && sameIdentity(stats, candidateIdentity))
|
|
90
|
+
await unlink(candidatePath);
|
|
91
|
+
}
|
|
92
|
+
catch { /* Preserve uncertain paths. */ }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function directoryIdentity(directory) {
|
|
97
|
+
const stats = await lstat(directory, { bigint: true });
|
|
98
|
+
if (!stats.isDirectory() || stats.isSymbolicLink() || await realpath(directory) !== directory) {
|
|
99
|
+
throw policyFailure("unsafe-session-directory");
|
|
100
|
+
}
|
|
101
|
+
return { path: directory, dev: stats.dev, ino: stats.ino };
|
|
102
|
+
}
|
|
103
|
+
async function assertDirectoriesUnchanged(directories) {
|
|
104
|
+
for (const directory of directories) {
|
|
105
|
+
const current = await directoryIdentity(directory.path);
|
|
106
|
+
if (!sameIdentity(current, directory))
|
|
107
|
+
throw policyFailure("session-directory-changed");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function verifyPublishedPolicy(statePath, expected) {
|
|
111
|
+
const file = await open(statePath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
112
|
+
try {
|
|
113
|
+
const before = await file.stat({ bigint: true });
|
|
114
|
+
if (!before.isFile() || before.size > BigInt(POLICY_MAX_BYTES) || !sameIdentity(before, expected)) {
|
|
115
|
+
throw policyFailure("published-policy-invalid");
|
|
116
|
+
}
|
|
117
|
+
const bytes = Buffer.alloc(Number(before.size));
|
|
118
|
+
let offset = 0;
|
|
119
|
+
while (offset < bytes.length) {
|
|
120
|
+
const { bytesRead } = await file.read(bytes, offset, bytes.length - offset, offset);
|
|
121
|
+
if (bytesRead === 0)
|
|
122
|
+
break;
|
|
123
|
+
offset += bytesRead;
|
|
124
|
+
}
|
|
125
|
+
const after = await file.stat({ bigint: true });
|
|
126
|
+
const named = await lstat(statePath, { bigint: true });
|
|
127
|
+
if (offset !== bytes.length || bytes.toString("utf8") !== POLICY_CONTENT ||
|
|
128
|
+
before.size !== after.size || !sameIdentity(after, expected) ||
|
|
129
|
+
!named.isFile() || !sameIdentity(named, expected)) {
|
|
130
|
+
throw policyFailure("published-policy-changed");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
await file.close();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function sameIdentity(a, b) {
|
|
138
|
+
return a.dev === b.dev && a.ino === b.ino;
|
|
139
|
+
}
|
|
140
|
+
function checkSignal(signal) {
|
|
141
|
+
if (signal?.aborted)
|
|
142
|
+
throw policyFailure("cancelled", true);
|
|
143
|
+
}
|
|
144
|
+
function policyFailure(reason, cancelled = false) {
|
|
145
|
+
return new RuntimeError("SWARM_ACTIVATION_FAILED", "The fresh swarm session could not install its native tool restriction; refusing the model turn.", "swarm-activation.tool-policy", { details: { reason, ...(cancelled ? { cancelled: true } : {}) } });
|
|
146
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kimi-plugin-cc",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.3",
|
|
4
4
|
"description": "Kimi Code subagents for DeepSeek Harness: all seven ask, review, challenge, rescue, pursue, swarm, and swarm-write operations through the kimi-plugin-cc companion runtime.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/dsh/index.js",
|