kimi-plugin-cc 2.7.2 → 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 +78 -1
- 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 +6 -5
- 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 -42
- 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 -74
- 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 +74 -77
- 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 +27 -6
- package/docs/models.md +2 -2
- package/docs/registry-releases.md +3 -1
- package/docs/safety.md +131 -81
- package/docs/session-visibility.md +5 -3
- package/docs/swarm-recovery.md +4 -4
- package/docs/upstream-2.7.2-certification.md +16 -2
- package/docs/upstream-2.7.3-certification.md +95 -0
- package/package.json +2 -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 -42
- 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 -74
- 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 +74 -77
- 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 -42
- 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 -74
- 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 +74 -77
- 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,13 +1,14 @@
|
|
|
1
|
+
import { evaluateScopedRead, isAllowedFetchUrl, parseScopeEnvironment, SCOPED_READ_TOOLS, } from "../read-scope.js";
|
|
1
2
|
import { BOUNDED_SWARM_POLICY, evaluateSwarmWaveInput } from "../swarm-policy.js";
|
|
2
3
|
/**
|
|
3
4
|
* Tools considered read-only across review/challenge/review_gate/rescue.
|
|
4
5
|
*
|
|
5
6
|
* Includes kimi-code's own local-read defaults (`Read`, `Grep`, `Glob`)
|
|
6
7
|
* plus a few additional read-safe tools the runtime auto-allows
|
|
7
|
-
* (`ReadMediaFile`, `TaskList`, `TaskOutput`).
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* (`ReadMediaFile`, `TaskList`, `TaskOutput`). Network tools
|
|
9
|
+
* (`WebSearch`, `FetchURL`) are excluded; read-only labels allow them only
|
|
10
|
+
* for a call started with --network, which also confines these reads to the
|
|
11
|
+
* plugin-exported read roots (runtime/read-scope.ts).
|
|
11
12
|
*/
|
|
12
13
|
export const READ_ONLY_TOOLS = new Set([
|
|
13
14
|
"Read",
|
|
@@ -17,6 +18,8 @@ export const READ_ONLY_TOOLS = new Set([
|
|
|
17
18
|
"TaskList",
|
|
18
19
|
"TaskOutput",
|
|
19
20
|
]);
|
|
21
|
+
/** Web tools: denied unless the plugin exported KIMI_PLUGIN_CC_NETWORK=1 with read roots. */
|
|
22
|
+
const WEB_TOOLS = new Set(["WebSearch", "FetchURL"]);
|
|
20
23
|
/**
|
|
21
24
|
* Exact tool name for kimi-code's parallel fan-out. Every spawned subagent
|
|
22
25
|
* inherits KIMI_PLUGIN_CC_CMD. On native v2, each agent has its own eager
|
|
@@ -55,6 +58,9 @@ export async function decideHookOutcome(input, ctx) {
|
|
|
55
58
|
if (!("evaluator" in result))
|
|
56
59
|
return result;
|
|
57
60
|
const toolName = typeof input.tool_name === "string" ? input.tool_name : "";
|
|
61
|
+
if (result.evaluator === "read-scope") {
|
|
62
|
+
return await evaluateScopedRead(toolName, input.tool_input, result.roots);
|
|
63
|
+
}
|
|
58
64
|
if (ctx.rescueEvaluator !== undefined) {
|
|
59
65
|
return await ctx.rescueEvaluator(result.workspaceRoot, toolName, input.tool_input);
|
|
60
66
|
}
|
|
@@ -134,8 +140,10 @@ export function decideHookOutcomePure(input, ctx) {
|
|
|
134
140
|
// non-interactive subprocesses, so interactive tool prompts cannot
|
|
135
141
|
// substitute for this allowlist.
|
|
136
142
|
if (READ_ONLY_TOOLS.has(toolName)) {
|
|
137
|
-
return
|
|
143
|
+
return readToolDecision(toolName, scopeOf(ctx));
|
|
138
144
|
}
|
|
145
|
+
if (WEB_TOOLS.has(toolName))
|
|
146
|
+
return webToolDecision(label, toolName, input.tool_input, scopeOf(ctx));
|
|
139
147
|
return {
|
|
140
148
|
decision: "deny",
|
|
141
149
|
reason: denyReadOnlyMessage(label, toolName),
|
|
@@ -146,12 +154,15 @@ export function decideHookOutcomePure(input, ctx) {
|
|
|
146
154
|
// AgentSwarm are allowed and the singular Agent stays denied. This adds
|
|
147
155
|
// no direct tool-write permission within the repository/Git trust
|
|
148
156
|
// boundary: read-only Git context commands still trust repository Git
|
|
149
|
-
// configuration and can execute configured helpers.
|
|
157
|
+
// configuration and can execute configured helpers. Bounded-swarm waves
|
|
150
158
|
// pass the admission guard above; fresh children cannot activate swarm
|
|
151
159
|
// mode. Older paths retain their inherited scheduler limitations.
|
|
152
|
-
if (
|
|
160
|
+
if (toolName === AGENT_SWARM_TOOL)
|
|
153
161
|
return { decision: "allow" };
|
|
154
|
-
|
|
162
|
+
if (READ_ONLY_TOOLS.has(toolName))
|
|
163
|
+
return readToolDecision(toolName, scopeOf(ctx));
|
|
164
|
+
if (WEB_TOOLS.has(toolName))
|
|
165
|
+
return webToolDecision(label, toolName, input.tool_input, scopeOf(ctx));
|
|
155
166
|
return {
|
|
156
167
|
decision: "deny",
|
|
157
168
|
reason: denySwarmMessage(toolName, ctx.swarmPolicy === BOUNDED_SWARM_POLICY && ctx.swarmWaveSize === "1"),
|
|
@@ -163,6 +174,9 @@ export function decideHookOutcomePure(input, ctx) {
|
|
|
163
174
|
// KIMI_PLUGIN_CC_WORKSPACE_ROOT, never the payload cwd, so an in-process
|
|
164
175
|
// subagent cannot move the trust boundary or forge its root. A missing
|
|
165
176
|
// root fails closed for writes.
|
|
177
|
+
const slashed = backslashRootDenial(ctx.trustedWorkspaceRoot, toolName);
|
|
178
|
+
if (slashed !== undefined)
|
|
179
|
+
return slashed;
|
|
166
180
|
if (READ_ONLY_TOOLS.has(toolName) || toolName === AGENT_SWARM_TOOL) {
|
|
167
181
|
return { decision: "allow" };
|
|
168
182
|
}
|
|
@@ -177,6 +191,9 @@ export function decideHookOutcomePure(input, ctx) {
|
|
|
177
191
|
return { evaluator: "rescue", workspaceRoot };
|
|
178
192
|
}
|
|
179
193
|
case "rescue": {
|
|
194
|
+
const slashed = backslashRootDenial(ctx.trustedWorkspaceRoot, toolName);
|
|
195
|
+
if (slashed !== undefined)
|
|
196
|
+
return slashed;
|
|
180
197
|
const workspaceRoot = typeof ctx.trustedWorkspaceRoot === "string" ? ctx.trustedWorkspaceRoot : "";
|
|
181
198
|
if (workspaceRoot.length === 0) {
|
|
182
199
|
if (READ_ONLY_TOOLS.has(toolName))
|
|
@@ -198,7 +215,7 @@ export function decideHookOutcomePure(input, ctx) {
|
|
|
198
215
|
}
|
|
199
216
|
// Unknown label: fail closed to READ_ONLY_TOOLS only.
|
|
200
217
|
if (READ_ONLY_TOOLS.has(toolName)) {
|
|
201
|
-
return
|
|
218
|
+
return readToolDecision(toolName, scopeOf(ctx));
|
|
202
219
|
}
|
|
203
220
|
return {
|
|
204
221
|
decision: "deny",
|
|
@@ -206,12 +223,57 @@ export function decideHookOutcomePure(input, ctx) {
|
|
|
206
223
|
};
|
|
207
224
|
}
|
|
208
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* kimi-code resolves its work dir with `pathe`, which reads a literal `\` as a
|
|
228
|
+
* separator, so a write-label root holding one names a different directory to
|
|
229
|
+
* kimi than to this hook. Every tool is denied; the launcher refuses such a
|
|
230
|
+
* root before spawn, so reaching here means the environment was altered.
|
|
231
|
+
*/
|
|
232
|
+
function backslashRootDenial(root, toolName) {
|
|
233
|
+
if (process.platform === "win32" || typeof root !== "string" || !root.includes("\\"))
|
|
234
|
+
return undefined;
|
|
235
|
+
return {
|
|
236
|
+
decision: "deny",
|
|
237
|
+
reason: `kimi-plugin-cc safety hook: writes cannot be confined to ${root}: it contains a backslash, ` +
|
|
238
|
+
`which kimi-code reads as a path separator; tool "${toolName}" denied.`,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
function scopeOf(ctx) {
|
|
242
|
+
return parseScopeEnvironment(ctx.readRoots, ctx.network);
|
|
243
|
+
}
|
|
244
|
+
function readToolDecision(toolName, scope) {
|
|
245
|
+
if (scope.confined && SCOPED_READ_TOOLS.has(toolName))
|
|
246
|
+
return { evaluator: "read-scope", roots: scope.roots };
|
|
247
|
+
return { decision: "allow" };
|
|
248
|
+
}
|
|
249
|
+
function webToolDecision(label, toolName, toolInput, scope) {
|
|
250
|
+
if (!scope.network) {
|
|
251
|
+
return {
|
|
252
|
+
decision: "deny",
|
|
253
|
+
reason: `kimi-plugin-cc safety hook: ${label} has no network access; tool "${toolName}" is denied. ` +
|
|
254
|
+
"The caller can allow WebSearch and FetchURL for one call with --network, which also confines reads to the workspace and any --read-root.",
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
if (toolName === "WebSearch")
|
|
258
|
+
return { decision: "allow" };
|
|
259
|
+
const url = typeof toolInput === "object" && toolInput !== null && !Array.isArray(toolInput)
|
|
260
|
+
? toolInput.url
|
|
261
|
+
: undefined;
|
|
262
|
+
if (isAllowedFetchUrl(url))
|
|
263
|
+
return { decision: "allow" };
|
|
264
|
+
return {
|
|
265
|
+
decision: "deny",
|
|
266
|
+
reason: "kimi-plugin-cc safety hook: FetchURL accepts only http:// and https:// URLs without embedded credentials " +
|
|
267
|
+
"whose host is a public name or a canonical global unicast IP address; localhost, .local and .internal names, " +
|
|
268
|
+
"numerically encoded hosts, and private, loopback, link-local, documentation, multicast, reserved, 6to4 and Teredo addresses are denied.",
|
|
269
|
+
};
|
|
270
|
+
}
|
|
209
271
|
function denyReadOnlyMessage(label, toolName) {
|
|
210
272
|
const tool = toolName.length > 0 ? toolName : "<unspecified>";
|
|
211
273
|
return [
|
|
212
274
|
`kimi-plugin-cc safety hook: ${label} is read-only.`,
|
|
213
275
|
`Tool "${tool}" is denied — use Read, Grep, or Glob to inspect the workspace instead.`,
|
|
214
|
-
"If you need to mutate state, the user must invoke /kimi:
|
|
276
|
+
"If you need to mutate state, the user must invoke /kimi:task --write (write-capable) rather than this command.",
|
|
215
277
|
].join(" ");
|
|
216
278
|
}
|
|
217
279
|
function denySwarmMessage(toolName, singleWorker) {
|
|
@@ -3,7 +3,10 @@ import { constants as fsConstants } from "node:fs";
|
|
|
3
3
|
import { link, lstat, mkdir, open, rename, unlink } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { RuntimeError } from "../errors.js";
|
|
6
|
+
import { selectKimiBinary } from "../kimi-command.js";
|
|
7
|
+
import { kimiReleaseHas } from "../kimi-releases.js";
|
|
6
8
|
import { probeKimiVersion } from "../kimi-version-probe.js";
|
|
9
|
+
import { sleep, tomlErrorLocation } from "../util.js";
|
|
7
10
|
import { extractValue } from "../vendor/smol-toml/extract.js";
|
|
8
11
|
import { parse as parseToml } from "../vendor/smol-toml/parse.js";
|
|
9
12
|
import { parseKey } from "../vendor/smol-toml/struct.js";
|
|
@@ -122,9 +125,6 @@ async function createPrivateLockFile(lockPath, owner) {
|
|
|
122
125
|
const stats = await handle.stat({ bigint: true });
|
|
123
126
|
candidateIdentity = lockIdentity(stats.dev, stats.ino);
|
|
124
127
|
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
128
128
|
finally {
|
|
129
129
|
await handle.close().catch(() => undefined);
|
|
130
130
|
}
|
|
@@ -271,10 +271,7 @@ async function tryRecoverStaleLock(lockPath, observed, staleMs) {
|
|
|
271
271
|
try {
|
|
272
272
|
await assertOwnedLock(recoveryPath, recoverySnapshot, recoveryOwner.token);
|
|
273
273
|
const current = await readLockSnapshot(lockPath);
|
|
274
|
-
if (current !== null &&
|
|
275
|
-
current.identity === observed.identity &&
|
|
276
|
-
current.owner?.token === observed.owner?.token &&
|
|
277
|
-
isStaleLock(current, staleMs)) {
|
|
274
|
+
if (current !== null && sameObservedLock(current, observed) && isStaleLock(current, staleMs)) {
|
|
278
275
|
// The per-identity recovery lock above ensures only one observer of this
|
|
279
276
|
// inode can claim it. Rename is the atomic removal from the public path;
|
|
280
277
|
// verification happens on the claimed inode before its unique name is
|
|
@@ -370,9 +367,6 @@ async function releaseOwnedLock(lockPath, acquired, token) {
|
|
|
370
367
|
}
|
|
371
368
|
await unlink(releasePath);
|
|
372
369
|
}
|
|
373
|
-
function sleep(ms) {
|
|
374
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
375
|
-
}
|
|
376
370
|
/**
|
|
377
371
|
* Convert a validated top-level inline `hooks = [...]` assignment to canonical
|
|
378
372
|
* `[[hooks]]` tables so setup can append its own array-table entry without
|
|
@@ -490,14 +484,18 @@ export function validateKimiHookSet(contents, version) {
|
|
|
490
484
|
return inspection.validation;
|
|
491
485
|
return validateVersionSensitiveEvents(inspection.versionSensitiveEvents, version);
|
|
492
486
|
}
|
|
493
|
-
/**
|
|
494
|
-
|
|
487
|
+
/**
|
|
488
|
+
* Probe `kimi --version` only when the config uses an additive hook event.
|
|
489
|
+
* A job's execution plan passes its own exact probe as `knownVersion`, so the
|
|
490
|
+
* hook set is judged against the release the job runs and nothing is spawned.
|
|
491
|
+
*/
|
|
492
|
+
export async function validateKimiHookSetForEnvironment(contents, env, knownVersion) {
|
|
495
493
|
const inspection = inspectKimiHookSet(contents);
|
|
496
494
|
if (!inspection.validation.valid || inspection.versionSensitiveEvents.length === 0) {
|
|
497
495
|
return inspection.validation;
|
|
498
496
|
}
|
|
499
|
-
const probe = await probeKimiVersion({
|
|
500
|
-
kimiBin: env.
|
|
497
|
+
const probe = knownVersion ?? await probeKimiVersion({
|
|
498
|
+
kimiBin: selectKimiBinary(env).command,
|
|
501
499
|
env,
|
|
502
500
|
});
|
|
503
501
|
const first = inspection.versionSensitiveEvents[0];
|
|
@@ -514,7 +512,7 @@ function inspectKimiHookSet(contents) {
|
|
|
514
512
|
catch (error) {
|
|
515
513
|
const line = tomlErrorLine(error);
|
|
516
514
|
return {
|
|
517
|
-
validation: invalidHookSet(`TOML parse failed: ${
|
|
515
|
+
validation: invalidHookSet(`TOML parse failed: ${tomlErrorLocation(error)}`, 0, line, "parse"),
|
|
518
516
|
versionSensitiveEvents: [],
|
|
519
517
|
};
|
|
520
518
|
}
|
|
@@ -592,34 +590,13 @@ function validateVersionSensitiveEvents(events, version) {
|
|
|
592
590
|
if (version === undefined) {
|
|
593
591
|
return invalidHookSet(`version-sensitive event ${JSON.stringify(first.event)} requires a verified kimi-code version`, first.entry, first.line);
|
|
594
592
|
}
|
|
595
|
-
//
|
|
596
|
-
//
|
|
597
|
-
//
|
|
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), 2.6.2
|
|
600
|
-
// (6a8493df), 2.6.3 (b0de2fbd), and 2.7.2 (56145f84): the additive events
|
|
601
|
-
// and HookDefSchema are unchanged. Schema acceptance does not certify operations.
|
|
593
|
+
// The additive events and HookDefSchema are unchanged at every release whose
|
|
594
|
+
// row in kimi-releases.ts carries "hook-schema" (each row names the reviewed
|
|
595
|
+
// commit). Schema acceptance does not certify operations.
|
|
602
596
|
// Require the full version string AND matching components; no inferred 2.x compatibility.
|
|
603
|
-
if (version.major === 2 &&
|
|
604
|
-
|
|
605
|
-
(version.version
|
|
606
|
-
(version.minor === 1 && ((version.version === "2.1.0" && version.patch === 0) ||
|
|
607
|
-
(version.version === "2.1.1" && version.patch === 1))) ||
|
|
608
|
-
(version.minor === 2 && ((version.version === "2.2.0" && version.patch === 0))) ||
|
|
609
|
-
(version.minor === 3 && ((version.version === "2.3.0" && version.patch === 0) ||
|
|
610
|
-
(version.version === "2.3.1" && version.patch === 1) ||
|
|
611
|
-
(version.version === "2.3.2" && version.patch === 2) ||
|
|
612
|
-
(version.version === "2.3.3" && version.patch === 3))) ||
|
|
613
|
-
(version.minor === 4 && ((version.version === "2.4.0" && version.patch === 0) ||
|
|
614
|
-
(version.version === "2.4.1" && version.patch === 1))) ||
|
|
615
|
-
(version.minor === 5 && ((version.version === "2.5.0" && version.patch === 0) ||
|
|
616
|
-
(version.version === "2.5.1" && version.patch === 1) ||
|
|
617
|
-
(version.version === "2.5.2" && version.patch === 2) ||
|
|
618
|
-
(version.version === "2.5.3" && version.patch === 3))) ||
|
|
619
|
-
(version.minor === 6 && ((version.version === "2.6.0" && version.patch === 0) ||
|
|
620
|
-
(version.version === "2.6.2" && version.patch === 2) ||
|
|
621
|
-
(version.version === "2.6.3" && version.patch === 3))) ||
|
|
622
|
-
(version.minor === 7 && version.version === "2.7.2" && version.patch === 2))) {
|
|
597
|
+
if (version.major === 2 &&
|
|
598
|
+
version.version === `${version.major}.${version.minor}.${version.patch}` &&
|
|
599
|
+
kimiReleaseHas(version.version, "hook-schema")) {
|
|
623
600
|
return { valid: true };
|
|
624
601
|
}
|
|
625
602
|
if (version.major !== 0) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Timing shared by the installed managed block and the hook entry script.
|
|
2
|
+
//
|
|
3
|
+
// kimi-code reads a hook that times out as ALLOW, so the hook must decide (or
|
|
4
|
+
// deny) before kimi-code's timeout expires. The installed timeout, the shortest
|
|
5
|
+
// timeout an entry may have and still count as enforcing, and the decision
|
|
6
|
+
// deadline all derive from HOOK_TIMEOUT_S so they cannot drift.
|
|
7
|
+
/** `timeout` (seconds) written into every managed PreToolUse block. */
|
|
8
|
+
export const HOOK_TIMEOUT_S = 15;
|
|
9
|
+
/**
|
|
10
|
+
* Fail-closed deadline for a labelled call, counted from hook start and
|
|
11
|
+
* covering stdin read plus policy evaluation. The margin absorbs Node startup
|
|
12
|
+
* and module load, which kimi-code's timeout counts but this timer does not.
|
|
13
|
+
*/
|
|
14
|
+
export const HOOK_DECISION_DEADLINE_MS = HOOK_TIMEOUT_S * 1000 - 5_000;
|
|
15
|
+
/**
|
|
16
|
+
* kimi-code's timeout (seconds) for a [[hooks]] entry with no `timeout` key:
|
|
17
|
+
* `DEFAULT_HOOK_TIMEOUT_SECONDS` in agent-core-v2 `externalHooks/internal/
|
|
18
|
+
* matchHooks.ts`, 30 in every certified source through 2.7.3. Each compat
|
|
19
|
+
* audit re-verifies it.
|
|
20
|
+
*/
|
|
21
|
+
export const UPSTREAM_DEFAULT_HOOK_TIMEOUT_S = 30;
|
|
22
|
+
/**
|
|
23
|
+
* The timeout kimi-code applies to an entry's raw `timeout` value: the
|
|
24
|
+
* upstream default when absent, the integer itself within upstream's 1-600
|
|
25
|
+
* schema, otherwise `null` (not provably enforcing).
|
|
26
|
+
*/
|
|
27
|
+
export function effectiveHookTimeoutS(value) {
|
|
28
|
+
if (value === undefined)
|
|
29
|
+
return UPSTREAM_DEFAULT_HOOK_TIMEOUT_S;
|
|
30
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > 600)
|
|
31
|
+
return null;
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* True when kimi-code waits at least `HOOK_TIMEOUT_S` for the hook, so the
|
|
36
|
+
* fail-closed deadline below fires before upstream's timeout-as-allow.
|
|
37
|
+
*/
|
|
38
|
+
export function hookTimeoutEnforces(value) {
|
|
39
|
+
const effective = effectiveHookTimeoutS(value);
|
|
40
|
+
return effective !== null && effective >= HOOK_TIMEOUT_S;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Test-only delay before the policy decision (milliseconds, or `hang` for a
|
|
44
|
+
* promise that never settles). It can only push a decision into the
|
|
45
|
+
* fail-closed deadline, and buildKimiCliEnvironment deletes it on every spawn,
|
|
46
|
+
* so it never reaches a job's hook.
|
|
47
|
+
*/
|
|
48
|
+
export const HOOK_TEST_DELAY_ENV = "KIMI_PLUGIN_CC_HOOK_TEST_DELAY_MS";
|
package/dist/hooks/install.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { constants as fsConstants, existsSync } from "node:fs";
|
|
2
|
-
import { access, readFile } from "node:fs/promises";
|
|
2
|
+
import { access, open, readFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { validateKimiHookSetForEnvironment } from "./config-safety.js";
|
|
5
|
-
import { evaluateInstalled } from "./managed-block.js";
|
|
6
|
-
import { resolveHostId, tryBuildExpectedHookCommand } from "./install-paths.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
5
|
+
import { countCleanEntriesInFile, effectiveHost, evaluateInstalled, findShortHookTimeout, findUnmanagedApprovalHookBlocks, parseManagedBlock, } from "./managed-block.js";
|
|
6
|
+
import { hostIdFromHookCommand, parseHookShellCommand, resolveHostId, tryBuildExpectedHookCommand, } from "./install-paths.js";
|
|
7
|
+
import { RuntimeError } from "../errors.js";
|
|
8
|
+
import { resolveKimiCodeConfigPath } from "../kimi-home.js";
|
|
9
|
+
import { KIMI_PLUGIN_CC_VERSION } from "../version.js";
|
|
10
|
+
export async function verifyHookInstalled(env, options = {}) {
|
|
9
11
|
const configPath = resolveKimiCodeConfigPath(env);
|
|
10
12
|
if (env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK === "1") {
|
|
11
13
|
return { installed: true, configPath };
|
|
@@ -42,22 +44,37 @@ export async function verifyHookInstalled(env) {
|
|
|
42
44
|
configPath,
|
|
43
45
|
};
|
|
44
46
|
}
|
|
45
|
-
const hookSet = await validateKimiHookSetForEnvironment(raw, env);
|
|
47
|
+
const hookSet = await validateKimiHookSetForEnvironment(raw, env, options.kimiVersion);
|
|
46
48
|
if (!hookSet.valid) {
|
|
47
49
|
return {
|
|
48
50
|
installed: false,
|
|
49
51
|
reason: hookSet.reason ?? "configured hooks failed whole-array validation",
|
|
50
52
|
configPath,
|
|
53
|
+
hookSetInvalid: true,
|
|
51
54
|
};
|
|
52
55
|
}
|
|
53
56
|
// Classify command mismatches into actionable drift reasons without changing
|
|
54
57
|
// the installed=false decision. hostId isolates this host's block in the
|
|
55
58
|
// shared config.
|
|
59
|
+
const hostId = resolveHostId(env, expected.hookScriptPath);
|
|
56
60
|
const check = evaluateInstalled(raw, expected.command, {
|
|
57
|
-
hostId
|
|
61
|
+
hostId,
|
|
58
62
|
nodeExists: (binPath) => existsSync(binPath),
|
|
59
63
|
});
|
|
60
|
-
|
|
64
|
+
// Markers are bookkeeping, not the security boundary. At job time a
|
|
65
|
+
// duplicate or orphan marker is tolerated when the real parser finds a clean,
|
|
66
|
+
// unconditional PreToolUse entry with the byte-exact command (the whole hook
|
|
67
|
+
// set already validated above), and the job records the setup remedy. setup
|
|
68
|
+
// and setup --check use evaluateInstalled directly and keep failing.
|
|
69
|
+
const warnings = [];
|
|
70
|
+
if (!check.installed &&
|
|
71
|
+
(check.state.kind === "duplicate" || check.state.kind === "orphan") &&
|
|
72
|
+
countCleanEntriesInFile(raw, expected.command) >= 1 &&
|
|
73
|
+
// A short-timeout copy of the command can be the one kimi-code runs.
|
|
74
|
+
findShortHookTimeout(raw, expected.command) === null) {
|
|
75
|
+
warnings.push(`The managed kimi-code PreToolUse hook is installed and enforcing, but its config markers need repair: ${check.reason}`);
|
|
76
|
+
}
|
|
77
|
+
else if (!check.installed) {
|
|
61
78
|
return {
|
|
62
79
|
installed: false,
|
|
63
80
|
reason: check.reason,
|
|
@@ -117,10 +134,118 @@ export async function verifyHookInstalled(env) {
|
|
|
117
134
|
nodeBin: expected.nodeBin,
|
|
118
135
|
};
|
|
119
136
|
}
|
|
120
|
-
|
|
137
|
+
// Channel W notice: an older host hook still applies its own rules here.
|
|
138
|
+
warnings.push(...await olderHostHookWarnings(raw, hostId, expected.command));
|
|
139
|
+
return warnings.length > 0 ? { installed: true, configPath, warnings } : { installed: true, configPath };
|
|
140
|
+
}
|
|
141
|
+
const MANIFEST_WALK_LEVELS = 4;
|
|
142
|
+
const MANIFEST_MAX_BYTES = 64 * 1024;
|
|
143
|
+
const SEMVER_RE = /^(\d+)\.(\d+)\.(\d+)(-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
144
|
+
/**
|
|
145
|
+
* One launch warning per other host's kimi-plugin-cc hook from an older plugin
|
|
146
|
+
* version than this one (or whose version cannot be read). kimi-code runs every
|
|
147
|
+
* host's hook for every tool call and any deny wins, so that hook's older rules
|
|
148
|
+
* still apply to this job. Covers other hosts' managed blocks and their
|
|
149
|
+
* marker-less tables left by a config rewrite. Reads manifests only; never
|
|
150
|
+
* executes anything and never refuses.
|
|
151
|
+
*/
|
|
152
|
+
export async function olderHostHookWarnings(contents, ownHostId, ownCommand) {
|
|
153
|
+
const ownDerived = hostIdFromHookCommand(ownCommand);
|
|
154
|
+
const ownIds = new Set([ownHostId, ...(ownDerived !== null ? [ownDerived] : [])]);
|
|
155
|
+
const others = new Map();
|
|
156
|
+
for (const block of parseManagedBlock(contents, ownHostId).blocks) {
|
|
157
|
+
const host = effectiveHost(block, ownHostId);
|
|
158
|
+
if (ownIds.has(host) || block.commandPath.length === 0 || block.commandPath === ownCommand)
|
|
159
|
+
continue;
|
|
160
|
+
if (!others.has(block.commandPath))
|
|
161
|
+
others.set(block.commandPath, host);
|
|
162
|
+
}
|
|
163
|
+
for (const table of findUnmanagedApprovalHookBlocks(contents)) {
|
|
164
|
+
const host = hostIdFromHookCommand(table.command);
|
|
165
|
+
if (host === null || ownIds.has(host) || table.command === ownCommand)
|
|
166
|
+
continue;
|
|
167
|
+
if (!others.has(table.command))
|
|
168
|
+
others.set(table.command, host);
|
|
169
|
+
}
|
|
170
|
+
const warnings = [];
|
|
171
|
+
for (const [command, host] of others) {
|
|
172
|
+
const version = await hookPluginVersion(command);
|
|
173
|
+
if (version !== undefined && !pluginVersionIsOlder(version))
|
|
174
|
+
continue;
|
|
175
|
+
warnings.push(`The ${host} host's kimi-plugin-cc hook (${version === undefined ? "an unknown version" : `version ${version}`}) ` +
|
|
176
|
+
`also checks this job with its older rules; it can deny what this version allows. ` +
|
|
177
|
+
`Update the plugin in ${host} and run its setup.`);
|
|
178
|
+
}
|
|
179
|
+
return warnings;
|
|
121
180
|
}
|
|
122
|
-
|
|
123
|
-
|
|
181
|
+
/**
|
|
182
|
+
* The plugin version behind a canonical hook command: walk up a few levels
|
|
183
|
+
* from the hook script to the nearest named `package.json` (it must be
|
|
184
|
+
* `kimi-plugin-cc`) or a Codex install's `.codex-plugin/plugin.json` (name
|
|
185
|
+
* `kimi`; that root has no package.json). Nameless `{"type":"module"}`
|
|
186
|
+
* markers under dist/ are skipped. Undefined when nothing trustworthy is found.
|
|
187
|
+
*/
|
|
188
|
+
export async function hookPluginVersion(command) {
|
|
189
|
+
const parsed = parseHookShellCommand(command);
|
|
190
|
+
if (parsed === null || !path.isAbsolute(parsed.hookScript))
|
|
191
|
+
return undefined;
|
|
192
|
+
let dir = path.dirname(path.resolve(parsed.hookScript));
|
|
193
|
+
for (let level = 0; level <= MANIFEST_WALK_LEVELS; level += 1) {
|
|
194
|
+
const pkg = await readSmallJsonObject(path.join(dir, "package.json"));
|
|
195
|
+
if (pkg !== undefined && typeof pkg.name === "string") {
|
|
196
|
+
return pkg.name === "kimi-plugin-cc" ? semverOrUndefined(pkg.version) : undefined;
|
|
197
|
+
}
|
|
198
|
+
const codex = await readSmallJsonObject(path.join(dir, ".codex-plugin", "plugin.json"));
|
|
199
|
+
if (codex !== undefined && typeof codex.name === "string") {
|
|
200
|
+
return codex.name === "kimi" ? semverOrUndefined(codex.version) : undefined;
|
|
201
|
+
}
|
|
202
|
+
const parent = path.dirname(dir);
|
|
203
|
+
if (parent === dir)
|
|
204
|
+
break;
|
|
205
|
+
dir = parent;
|
|
206
|
+
}
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* True when `version` is older than `current` (this plugin by default). Any
|
|
211
|
+
* prerelease other than `current` itself, and any unparseable value, counts as
|
|
212
|
+
* older.
|
|
213
|
+
*/
|
|
214
|
+
export function pluginVersionIsOlder(version, current = KIMI_PLUGIN_CC_VERSION) {
|
|
215
|
+
if (version === current)
|
|
216
|
+
return false;
|
|
217
|
+
const have = SEMVER_RE.exec(version);
|
|
218
|
+
const want = SEMVER_RE.exec(current);
|
|
219
|
+
if (have === null || want === null || have[4] !== undefined)
|
|
220
|
+
return true;
|
|
221
|
+
for (let i = 1; i <= 3; i += 1) {
|
|
222
|
+
const diff = Number(have[i]) - Number(want[i]);
|
|
223
|
+
if (diff !== 0)
|
|
224
|
+
return diff < 0;
|
|
225
|
+
}
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
function semverOrUndefined(value) {
|
|
229
|
+
return typeof value === "string" && SEMVER_RE.test(value) ? value : undefined;
|
|
230
|
+
}
|
|
231
|
+
async function readSmallJsonObject(file) {
|
|
232
|
+
let handle;
|
|
233
|
+
try {
|
|
234
|
+
handle = await open(file, fsConstants.O_RDONLY | fsConstants.O_NONBLOCK);
|
|
235
|
+
const stat = await handle.stat();
|
|
236
|
+
if (!stat.isFile() || stat.size > MANIFEST_MAX_BYTES)
|
|
237
|
+
return undefined;
|
|
238
|
+
const value = JSON.parse(await handle.readFile("utf8"));
|
|
239
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
240
|
+
? value
|
|
241
|
+
: undefined;
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
finally {
|
|
247
|
+
await handle?.close().catch(() => undefined);
|
|
248
|
+
}
|
|
124
249
|
}
|
|
125
250
|
/**
|
|
126
251
|
* Caller-facing repair protocol shared by every hook-refusal surface. Re-pin
|
|
@@ -161,6 +286,76 @@ export function hookRefusalDetails(status) {
|
|
|
161
286
|
: {}),
|
|
162
287
|
};
|
|
163
288
|
}
|
|
289
|
+
/** Repair sentences of the read-only (ask, review, challenge, review gate) hook refusal. */
|
|
290
|
+
export const READ_ONLY_HOOK_REPAIR = [
|
|
291
|
+
"Run /kimi:setup or $kimi-setup to install or repair this host's managed block.",
|
|
292
|
+
"Set KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 only if you intentionally accept un-enforced execution.",
|
|
293
|
+
];
|
|
294
|
+
/** Repair sentences of the write-capable (rescue, pursue) hook refusal. */
|
|
295
|
+
export const WRITE_HOOK_REPAIR = [
|
|
296
|
+
"Repair by running Claude Code /kimi:setup or Codex $kimi-setup, then retry.",
|
|
297
|
+
"KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 is only for deliberate tests or diagnostics.",
|
|
298
|
+
];
|
|
299
|
+
function readOnlyGate(name, code) {
|
|
300
|
+
return {
|
|
301
|
+
code,
|
|
302
|
+
stage: `${name}.hook-check`,
|
|
303
|
+
warnLabel: name,
|
|
304
|
+
intro: [`${name} refuses to run without the canonical kimi-plugin-cc PreToolUse hook.`],
|
|
305
|
+
repair: READ_ONLY_HOOK_REPAIR,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
const SWARM_GATE = {
|
|
309
|
+
code: "SWARM_HOOK_NOT_INSTALLED",
|
|
310
|
+
stage: "swarm.hook-check",
|
|
311
|
+
warnLabel: "swarm",
|
|
312
|
+
intro: [
|
|
313
|
+
"/kimi:swarm refuses to run without the kimi-plugin-cc PreToolUse hook.",
|
|
314
|
+
"The hook enforces each worker's tool permissions, write confinement, and delegation limits.",
|
|
315
|
+
],
|
|
316
|
+
repair: ["Repair by running Claude Code /kimi:setup or Codex $kimi-setup, then retry."],
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* The refusal each operation's hook gate raises. The command gates and the
|
|
320
|
+
* job-time check in prepareKimiExecutionPlan share it, so a definite negative
|
|
321
|
+
* reads the same whichever check sees it.
|
|
322
|
+
*/
|
|
323
|
+
const HOOK_GATES = {
|
|
324
|
+
ask: readOnlyGate("ask", "ASK_HOOK_NOT_INSTALLED"),
|
|
325
|
+
review: readOnlyGate("review", "REVIEW_HOOK_NOT_INSTALLED"),
|
|
326
|
+
challenge: readOnlyGate("challenge", "CHALLENGE_HOOK_NOT_INSTALLED"),
|
|
327
|
+
review_gate: readOnlyGate("review_gate", "REVIEW_GATE_HOOK_NOT_INSTALLED"),
|
|
328
|
+
rescue: {
|
|
329
|
+
code: "RESCUE_HOOK_NOT_INSTALLED",
|
|
330
|
+
stage: "rescue.hook-check",
|
|
331
|
+
warnLabel: "rescue",
|
|
332
|
+
intro: ["rescue refuses to run without the kimi-plugin-cc PreToolUse hook."],
|
|
333
|
+
repair: WRITE_HOOK_REPAIR,
|
|
334
|
+
},
|
|
335
|
+
pursue: {
|
|
336
|
+
code: "PURSUE_HOOK_NOT_INSTALLED",
|
|
337
|
+
stage: "pursue.hook-check",
|
|
338
|
+
warnLabel: "rescue",
|
|
339
|
+
intro: ["/kimi:pursue refuses to run without the kimi-plugin-cc PreToolUse hook."],
|
|
340
|
+
repair: WRITE_HOOK_REPAIR,
|
|
341
|
+
},
|
|
342
|
+
swarm: SWARM_GATE,
|
|
343
|
+
"swarm-write": SWARM_GATE,
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* Warn once on stderr and build `operation`'s hook refusal for a status whose
|
|
347
|
+
* `installed` is false.
|
|
348
|
+
*/
|
|
349
|
+
export function hookGateRefusal(operation, status, env, stderr = process.stderr) {
|
|
350
|
+
const gate = HOOK_GATES[operation];
|
|
351
|
+
maybeWarnHookMissing(status, gate.warnLabel, stderr);
|
|
352
|
+
return new RuntimeError(gate.code, [
|
|
353
|
+
...gate.intro,
|
|
354
|
+
`Hook check failed: ${status.reason ?? "unknown"}.`,
|
|
355
|
+
...gate.repair,
|
|
356
|
+
hookRefusalRetryProtocol(env),
|
|
357
|
+
].join(" "), gate.stage, { details: hookRefusalDetails(status) });
|
|
358
|
+
}
|
|
164
359
|
export function formatHookMissingWarning(status, commandLabel) {
|
|
165
360
|
return [
|
|
166
361
|
"",
|