kimi-plugin-cc 3.0.0 → 3.1.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 +2 -2
- package/.claude-plugin/plugin.json +3 -14
- package/README.md +428 -572
- package/assets/logo.svg +6 -0
- package/cordis.patch.yml +18 -0
- package/dist/background-spawn.js +4 -2
- package/dist/cli-client.js +105 -66
- package/dist/commands/ask.js +27 -12
- package/dist/commands/cancel.js +4 -13
- package/dist/commands/cli-helpers.js +1 -1
- package/dist/commands/pursue.js +3 -2
- package/dist/commands/registry.js +7 -26
- package/dist/commands/repair-sessions.js +7 -4
- package/dist/commands/replay.js +4 -3
- package/dist/commands/rescue.js +17 -5
- package/dist/commands/review.js +18 -5
- package/dist/commands/setup.js +277 -262
- package/dist/commands/swarm.js +20 -7
- package/dist/companion.js +142 -18
- package/dist/help.js +11 -7
- package/dist/hook-escape.js +7 -16
- package/dist/hooks/approval-hook.js +1762 -124
- package/dist/hooks/approval-policy.js +15 -10
- package/dist/hooks/config-safety.js +15 -24
- package/dist/hooks/hook-timing.js +1 -1
- package/dist/hooks/install-paths.js +179 -107
- package/dist/hooks/install.js +44 -166
- package/dist/hooks/managed-block.js +44 -95
- package/dist/job-store.js +117 -49
- package/dist/jobs.js +53 -1
- package/dist/kimi-engine.js +68 -92
- package/dist/kimi-errors.js +1 -1
- package/dist/kimi-journal.js +3 -2
- package/dist/kimi-releases.js +28 -49
- package/dist/kimi-timeouts.js +1 -15
- package/dist/kimi-version-probe.js +24 -72
- package/dist/logging.js +12 -7
- package/dist/mcp/binding.js +13 -4
- package/dist/mcp/job-control.js +386 -89
- package/dist/mcp/launcher.js +1 -1
- package/dist/mcp/operations.js +387 -193
- package/dist/mcp/protocol.js +116 -27
- package/dist/mcp/skills.js +130 -0
- package/dist/mcp/stdio.js +15 -2
- package/dist/native-v2-preflight.js +127 -35
- package/dist/parsing.js +45 -11
- package/dist/paths.js +20 -10
- package/dist/plugin-data.js +28 -83
- package/dist/read-scope.js +2 -2
- package/dist/render.js +13 -38
- package/dist/session-references.js +216 -0
- package/dist/session-title.js +1 -1
- package/dist/surface-routing.js +92 -5
- package/dist/swarm-activation.js +26 -137
- package/dist/version.js +1 -1
- package/docs/migration.md +45 -227
- package/docs/models.md +24 -66
- package/docs/safety.md +195 -400
- package/docs/session-visibility.md +24 -14
- package/docs/swarm-recovery.md +26 -20
- package/dsh/index.json +54 -0
- package/mcp_config.json +10 -0
- package/package.json +23 -82
- package/plugin.json +19 -0
- package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
- package/plugins/kimi-codex/.mcp.json +2 -3
- package/plugins/kimi-codex/dist/background-spawn.js +4 -2
- package/plugins/kimi-codex/dist/cli-client.js +105 -66
- package/plugins/kimi-codex/dist/commands/ask.js +27 -12
- package/plugins/kimi-codex/dist/commands/cancel.js +4 -13
- package/plugins/kimi-codex/dist/commands/cli-helpers.js +1 -1
- package/plugins/kimi-codex/dist/commands/pursue.js +3 -2
- package/plugins/kimi-codex/dist/commands/registry.js +7 -26
- package/plugins/kimi-codex/dist/commands/repair-sessions.js +7 -4
- package/plugins/kimi-codex/dist/commands/replay.js +4 -3
- package/plugins/kimi-codex/dist/commands/rescue.js +17 -5
- package/plugins/kimi-codex/dist/commands/review.js +18 -5
- package/plugins/kimi-codex/dist/commands/setup.js +277 -262
- package/plugins/kimi-codex/dist/commands/swarm.js +20 -7
- package/plugins/kimi-codex/dist/companion.js +142 -18
- package/plugins/kimi-codex/dist/help.js +11 -7
- package/plugins/kimi-codex/dist/hook-escape.js +7 -16
- package/plugins/kimi-codex/dist/hooks/approval-hook.js +1762 -124
- package/plugins/kimi-codex/dist/hooks/approval-policy.js +15 -10
- package/plugins/kimi-codex/dist/hooks/config-safety.js +15 -24
- package/plugins/kimi-codex/dist/hooks/hook-timing.js +1 -1
- package/plugins/kimi-codex/dist/hooks/install-paths.js +179 -107
- package/plugins/kimi-codex/dist/hooks/install.js +44 -166
- package/plugins/kimi-codex/dist/hooks/managed-block.js +44 -95
- package/plugins/kimi-codex/dist/job-store.js +117 -49
- package/plugins/kimi-codex/dist/jobs.js +53 -1
- package/plugins/kimi-codex/dist/kimi-engine.js +68 -92
- package/plugins/kimi-codex/dist/kimi-errors.js +1 -1
- package/plugins/kimi-codex/dist/kimi-journal.js +3 -2
- package/plugins/kimi-codex/dist/kimi-releases.js +28 -49
- package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -15
- package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -72
- package/plugins/kimi-codex/dist/logging.js +12 -7
- package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
- package/plugins/kimi-codex/dist/mcp/job-control.js +386 -89
- package/plugins/kimi-codex/dist/mcp/launcher.js +1 -1
- package/plugins/kimi-codex/dist/mcp/operations.js +387 -193
- package/plugins/kimi-codex/dist/mcp/protocol.js +116 -27
- package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
- package/plugins/kimi-codex/dist/mcp/stdio.js +15 -2
- package/plugins/kimi-codex/dist/native-v2-preflight.js +127 -35
- package/plugins/kimi-codex/dist/parsing.js +45 -11
- package/plugins/kimi-codex/dist/paths.js +20 -10
- package/plugins/kimi-codex/dist/plugin-data.js +28 -83
- package/plugins/kimi-codex/dist/read-scope.js +2 -2
- package/plugins/kimi-codex/dist/render.js +13 -38
- package/plugins/kimi-codex/dist/session-references.js +216 -0
- package/plugins/kimi-codex/dist/session-title.js +1 -1
- package/plugins/kimi-codex/dist/surface-routing.js +92 -5
- package/plugins/kimi-codex/dist/swarm-activation.js +26 -137
- package/plugins/kimi-codex/dist/version.js +1 -1
- package/plugins/kimi-codex/scripts/companion.sh +4 -15
- package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
- package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
- package/scripts/companion.sh +4 -15
- package/skills/kimi/SKILL.md +77 -0
- package/skills/kimi/agents/openai.yaml +6 -0
- package/CHANGELOG.md +0 -1402
- package/agents/kimi-pursue.md +0 -93
- package/agents/kimi-review.md +0 -86
- package/agents/kimi-swarm.md +0 -88
- package/agents/kimi-task.md +0 -93
- package/commands/README.md +0 -14
- package/commands/cancel.md +0 -17
- package/commands/pursue.md +0 -41
- package/commands/replay.md +0 -13
- package/commands/result.md +0 -13
- package/commands/review.md +0 -40
- package/commands/setup.md +0 -25
- package/commands/status.md +0 -13
- package/commands/swarm.md +0 -45
- package/commands/task.md +0 -40
- package/dist/commands/review-gate.js +0 -391
- package/dist/config.js +0 -22
- package/dist/dsh/companion.js +0 -177
- package/dist/dsh/index.js +0 -167
- package/dist/hooks/review-gate-stop.js +0 -19
- package/dist/schemas/review-gate-output.js +0 -41
- package/docs/registry-releases.md +0 -228
- package/docs/upstream-2.4.1-certification.md +0 -54
- package/docs/upstream-2.5.0-certification.md +0 -52
- package/docs/upstream-2.5.1-certification.md +0 -47
- package/docs/upstream-2.5.2-certification.md +0 -40
- package/docs/upstream-2.5.3-certification.md +0 -73
- package/docs/upstream-2.6.0-certification.md +0 -65
- package/docs/upstream-2.6.2-certification.md +0 -144
- package/docs/upstream-2.6.3-certification.md +0 -100
- package/docs/upstream-2.7.2-certification.md +0 -113
- package/docs/upstream-2.7.3-certification.md +0 -95
- package/docs/windows-validation.md +0 -39
- package/hooks/README.md +0 -9
- package/hooks/hooks.json +0 -16
- package/plugins/kimi-codex/dist/commands/review-gate.js +0 -391
- package/plugins/kimi-codex/dist/config.js +0 -22
- package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
- package/plugins/kimi-codex/dist/dsh/index.js +0 -167
- package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -41
- package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
- package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
- package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -37
- package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-task/SKILL.md +0 -37
- package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +0 -6
- package/plugins/kimi-dsh/LICENSE +0 -201
- package/plugins/kimi-dsh/README.md +0 -84
- package/plugins/kimi-dsh/cordis.patch.yml +0 -45
- package/plugins/kimi-dsh/dist/background-spawn.js +0 -209
- package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
- package/plugins/kimi-dsh/dist/cli-client.js +0 -1097
- package/plugins/kimi-dsh/dist/commands/ask.js +0 -269
- package/plugins/kimi-dsh/dist/commands/cancel.js +0 -177
- package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -302
- package/plugins/kimi-dsh/dist/commands/models.js +0 -139
- package/plugins/kimi-dsh/dist/commands/pursue.js +0 -293
- package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
- package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
- package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -266
- package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
- package/plugins/kimi-dsh/dist/commands/rescue.js +0 -277
- package/plugins/kimi-dsh/dist/commands/result.js +0 -72
- package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -391
- package/plugins/kimi-dsh/dist/commands/review.js +0 -217
- package/plugins/kimi-dsh/dist/commands/setup.js +0 -1465
- package/plugins/kimi-dsh/dist/commands/status.js +0 -27
- package/plugins/kimi-dsh/dist/commands/swarm.js +0 -823
- package/plugins/kimi-dsh/dist/commands/worker.js +0 -24
- package/plugins/kimi-dsh/dist/companion.js +0 -99
- package/plugins/kimi-dsh/dist/config.js +0 -22
- package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
- package/plugins/kimi-dsh/dist/dsh/index.js +0 -167
- package/plugins/kimi-dsh/dist/errors.js +0 -40
- package/plugins/kimi-dsh/dist/git.js +0 -216
- package/plugins/kimi-dsh/dist/help.js +0 -43
- package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
- package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -145
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -295
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -641
- package/plugins/kimi-dsh/dist/hooks/hook-timing.js +0 -48
- package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
- package/plugins/kimi-dsh/dist/hooks/install.js +0 -405
- package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -729
- package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-dsh/dist/job-id.js +0 -12
- package/plugins/kimi-dsh/dist/job-store.js +0 -631
- package/plugins/kimi-dsh/dist/jobs.js +0 -212
- package/plugins/kimi-dsh/dist/kimi-command.js +0 -144
- package/plugins/kimi-dsh/dist/kimi-engine.js +0 -770
- package/plugins/kimi-dsh/dist/kimi-errors.js +0 -205
- package/plugins/kimi-dsh/dist/kimi-home.js +0 -15
- package/plugins/kimi-dsh/dist/kimi-journal.js +0 -41
- package/plugins/kimi-dsh/dist/kimi-releases.js +0 -144
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
- package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -198
- package/plugins/kimi-dsh/dist/logging.js +0 -22
- package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
- package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -343
- package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -263
- package/plugins/kimi-dsh/dist/mcp/operations.js +0 -333
- package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -277
- package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
- package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -79
- package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
- package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
- package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
- package/plugins/kimi-dsh/dist/model-command.js +0 -34
- package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -596
- package/plugins/kimi-dsh/dist/package.json +0 -1
- package/plugins/kimi-dsh/dist/parsing.js +0 -554
- package/plugins/kimi-dsh/dist/paths.js +0 -35
- package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
- package/plugins/kimi-dsh/dist/process-tree.js +0 -597
- package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
- package/plugins/kimi-dsh/dist/read-scope.js +0 -435
- package/plugins/kimi-dsh/dist/render.js +0 -214
- package/plugins/kimi-dsh/dist/rescue-approval.js +0 -1242
- package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -41
- package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
- package/plugins/kimi-dsh/dist/session-title.js +0 -313
- package/plugins/kimi-dsh/dist/stream-json.js +0 -344
- package/plugins/kimi-dsh/dist/surface-routing.js +0 -21
- package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1194
- package/plugins/kimi-dsh/dist/swarm-policy.js +0 -74
- package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -166
- package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
- package/plugins/kimi-dsh/dist/types.js +0 -1
- package/plugins/kimi-dsh/dist/util.js +0 -28
- package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
- package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
- package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
- package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
- package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
- package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
- package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
- package/plugins/kimi-dsh/dist/version.js +0 -7
- package/plugins/kimi-dsh/package.json +0 -78
- package/plugins/kimi-dsh/scripts/companion.sh +0 -37
- package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
- package/scripts/review-gate-hook.sh +0 -32
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { constants as fsConstants, existsSync } from "node:fs";
|
|
2
|
-
import { access,
|
|
2
|
+
import { access, readFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { validateKimiHookSetForEnvironment } from "./config-safety.js";
|
|
5
|
-
import { countCleanEntriesInFile,
|
|
6
|
-
import {
|
|
6
|
+
import { countCleanEntriesInFile, evaluateInstalled, findShortHookTimeout, } from "./managed-block.js";
|
|
7
|
+
import { tryBuildExpectedHookCommand, verifyManagedHookArtifact, } from "./install-paths.js";
|
|
7
8
|
import { RuntimeError } from "../errors.js";
|
|
8
9
|
import { resolveKimiCodeConfigPath } from "../kimi-home.js";
|
|
9
|
-
import { KIMI_PLUGIN_CC_VERSION } from "../version.js";
|
|
10
10
|
export async function verifyHookInstalled(env, options = {}) {
|
|
11
11
|
const configPath = resolveKimiCodeConfigPath(env);
|
|
12
12
|
if (env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK === "1") {
|
|
@@ -53,12 +53,7 @@ export async function verifyHookInstalled(env, options = {}) {
|
|
|
53
53
|
hookSetInvalid: true,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
// Classify command mismatches into actionable drift reasons without changing
|
|
57
|
-
// the installed=false decision. hostId isolates this host's block in the
|
|
58
|
-
// shared config.
|
|
59
|
-
const hostId = resolveHostId(env, expected.hookScriptPath);
|
|
60
56
|
const check = evaluateInstalled(raw, expected.command, {
|
|
61
|
-
hostId,
|
|
62
57
|
nodeExists: (binPath) => existsSync(binPath),
|
|
63
58
|
});
|
|
64
59
|
// Markers are bookkeeping, not the security boundary. At job time a
|
|
@@ -86,40 +81,37 @@ export async function verifyHookInstalled(env, options = {}) {
|
|
|
86
81
|
...(check.drift !== undefined ? { drift: check.drift } : {}),
|
|
87
82
|
};
|
|
88
83
|
}
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
const artifact = await verifyManagedHookArtifact(env, expected.hookScriptPath);
|
|
85
|
+
if (!artifact.ok) {
|
|
86
|
+
if (artifact.kind === "sha256-mismatch") {
|
|
87
|
+
return {
|
|
88
|
+
installed: false,
|
|
89
|
+
reason: artifact.reason,
|
|
90
|
+
configPath,
|
|
91
|
+
drift: {
|
|
92
|
+
axis: "hook-script",
|
|
93
|
+
installedCommand: expected.command,
|
|
94
|
+
expectedCommand: expected.command,
|
|
95
|
+
nodeInterpreterUnchanged: true,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
installed: false,
|
|
101
|
+
reason: artifact.reason,
|
|
102
|
+
configPath,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
91
105
|
try {
|
|
92
106
|
await access(expected.hookScriptPath, fsConstants.R_OK);
|
|
93
107
|
}
|
|
94
108
|
catch {
|
|
95
109
|
return {
|
|
96
110
|
installed: false,
|
|
97
|
-
reason: `hook script ${expected.hookScriptPath} is missing or unreadable — run /
|
|
111
|
+
reason: `hook script ${expected.hookScriptPath} is missing or unreadable — run \`kimi_setup\` (action "install") or \`scripts/companion.sh setup\` to reinstall`,
|
|
98
112
|
configPath,
|
|
99
113
|
};
|
|
100
114
|
}
|
|
101
|
-
// Confirm the pinned interpreter with a NARROW X_OK backstop. Interpreter
|
|
102
|
-
// moves that change the recomputed command are already refused as drift; this
|
|
103
|
-
// check covers only unchanged command bytes whose Node token fails X_OK now:
|
|
104
|
-
//
|
|
105
|
-
// 1. An absolute KIMI_PLUGIN_CC_NODE_BIN override names a dead interpreter
|
|
106
|
-
// other than the running process, so launch never proved it executable.
|
|
107
|
-
// 2. The interpreter is chmodded after launch. realpathSync still resolves
|
|
108
|
-
// it, the preferred path and command bytes stay unchanged, but X_OK fails.
|
|
109
|
-
// 3. The pathname is removed after launch. realpathSync throws, and the
|
|
110
|
-
// execPath fallback can retain the same spelling, so equality still passes
|
|
111
|
-
// while the pinned path is gone.
|
|
112
|
-
//
|
|
113
|
-
// Refusing these cases matters because a failed hook spawn is ALLOW upstream.
|
|
114
|
-
// This per-spawn check also catches degradation since setup's last execution
|
|
115
|
-
// probe. It proves only the exec bit, not a working Node, architecture, or
|
|
116
|
-
// version; setup's shell probe executes the byte-identical command instead.
|
|
117
|
-
//
|
|
118
|
-
// Fail closed on EVERY access error. Do not harmonize this with spawning code
|
|
119
|
-
// that ignores selected errnos: a security verifier cannot "try and see".
|
|
120
|
-
//
|
|
121
|
-
// This refusal carries no drift and therefore no retryable_after_setup field:
|
|
122
|
-
// setup cannot repair a broken Node installation.
|
|
123
115
|
try {
|
|
124
116
|
await access(expected.nodeBin, fsConstants.X_OK);
|
|
125
117
|
}
|
|
@@ -128,135 +120,23 @@ export async function verifyHookInstalled(env, options = {}) {
|
|
|
128
120
|
installed: false,
|
|
129
121
|
reason: `hook interpreter ${expected.nodeBin} is missing or not executable, so the PreToolUse hook ` +
|
|
130
122
|
`cannot spawn (kimi-code reads a failed hook as ALLOW). Repair the Node install, or set ` +
|
|
131
|
-
`KIMI_PLUGIN_CC_NODE_BIN to a valid Node >=22.5 executable and run
|
|
123
|
+
`KIMI_PLUGIN_CC_NODE_BIN to a valid Node >=22.5 executable and run \`kimi_setup\` (action "install").`,
|
|
132
124
|
configPath,
|
|
133
125
|
refusalKind: "node-bin-not-executable",
|
|
134
126
|
nodeBin: expected.nodeBin,
|
|
135
127
|
};
|
|
136
128
|
}
|
|
137
|
-
// Channel W notice: an older host hook still applies its own rules here.
|
|
138
|
-
warnings.push(...await olderHostHookWarnings(raw, hostId, expected.command));
|
|
139
129
|
return warnings.length > 0 ? { installed: true, configPath, warnings } : { installed: true, configPath };
|
|
140
130
|
}
|
|
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;
|
|
180
|
-
}
|
|
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
|
-
}
|
|
249
|
-
}
|
|
250
131
|
/**
|
|
251
132
|
* Caller-facing repair protocol shared by every hook-refusal surface. Re-pin
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
* the skip-check environment variable as a repair.
|
|
133
|
+
* cleanly, retry ONCE only when `retryable_after_setup` is literally true and
|
|
134
|
+
* setup exits zero, and never use the skip-check environment variable as a repair.
|
|
255
135
|
*/
|
|
256
|
-
export function hookRefusalRetryProtocol(
|
|
257
|
-
const
|
|
136
|
+
export function hookRefusalRetryProtocol(_env) {
|
|
137
|
+
const hereRoot = path.resolve(fileURLToPath(new URL("../..", import.meta.url)));
|
|
258
138
|
return (`If details shows retryable_after_setup:true (routine after a plugin update — the ` +
|
|
259
|
-
`
|
|
139
|
+
`hook script or node path moved), run \`${hereRoot}/scripts/companion.sh setup\` and, only ` +
|
|
260
140
|
`if it exits 0, retry the refused command once. Anything else — or a second refusal — ` +
|
|
261
141
|
`surface the refusal instead of retrying.`);
|
|
262
142
|
}
|
|
@@ -286,14 +166,14 @@ export function hookRefusalDetails(status) {
|
|
|
286
166
|
: {}),
|
|
287
167
|
};
|
|
288
168
|
}
|
|
289
|
-
/** Repair sentences of the read-only (ask, review, challenge
|
|
169
|
+
/** Repair sentences of the read-only (ask, review, challenge) hook refusal. */
|
|
290
170
|
export const READ_ONLY_HOOK_REPAIR = [
|
|
291
|
-
"Run
|
|
171
|
+
"Run `kimi_setup` (action \"install\") or `scripts/companion.sh setup` to install or repair the canonical managed block.",
|
|
292
172
|
"Set KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 only if you intentionally accept un-enforced execution.",
|
|
293
173
|
];
|
|
294
174
|
/** Repair sentences of the write-capable (rescue, pursue) hook refusal. */
|
|
295
175
|
export const WRITE_HOOK_REPAIR = [
|
|
296
|
-
"Repair by running
|
|
176
|
+
"Repair by running `kimi_setup` (action \"install\") or `scripts/companion.sh setup`, then retry.",
|
|
297
177
|
"KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 is only for deliberate tests or diagnostics.",
|
|
298
178
|
];
|
|
299
179
|
function readOnlyGate(name, code) {
|
|
@@ -310,10 +190,10 @@ const SWARM_GATE = {
|
|
|
310
190
|
stage: "swarm.hook-check",
|
|
311
191
|
warnLabel: "swarm",
|
|
312
192
|
intro: [
|
|
313
|
-
"
|
|
193
|
+
"swarm refuses to run without the kimi-plugin-cc PreToolUse hook.",
|
|
314
194
|
"The hook enforces each worker's tool permissions, write confinement, and delegation limits.",
|
|
315
195
|
],
|
|
316
|
-
repair: ["Repair by running
|
|
196
|
+
repair: ["Repair by running `kimi_setup` (action \"install\") or `scripts/companion.sh setup`, then retry."],
|
|
317
197
|
};
|
|
318
198
|
/**
|
|
319
199
|
* The refusal each operation's hook gate raises. The command gates and the
|
|
@@ -324,7 +204,6 @@ const HOOK_GATES = {
|
|
|
324
204
|
ask: readOnlyGate("ask", "ASK_HOOK_NOT_INSTALLED"),
|
|
325
205
|
review: readOnlyGate("review", "REVIEW_HOOK_NOT_INSTALLED"),
|
|
326
206
|
challenge: readOnlyGate("challenge", "CHALLENGE_HOOK_NOT_INSTALLED"),
|
|
327
|
-
review_gate: readOnlyGate("review_gate", "REVIEW_GATE_HOOK_NOT_INSTALLED"),
|
|
328
207
|
rescue: {
|
|
329
208
|
code: "RESCUE_HOOK_NOT_INSTALLED",
|
|
330
209
|
stage: "rescue.hook-check",
|
|
@@ -336,7 +215,7 @@ const HOOK_GATES = {
|
|
|
336
215
|
code: "PURSUE_HOOK_NOT_INSTALLED",
|
|
337
216
|
stage: "pursue.hook-check",
|
|
338
217
|
warnLabel: "rescue",
|
|
339
|
-
intro: ["
|
|
218
|
+
intro: ["pursue refuses to run without the kimi-plugin-cc PreToolUse hook."],
|
|
340
219
|
repair: WRITE_HOOK_REPAIR,
|
|
341
220
|
},
|
|
342
221
|
swarm: SWARM_GATE,
|
|
@@ -369,14 +248,13 @@ export function formatHookMissingWarning(status, commandLabel) {
|
|
|
369
248
|
" documented as read-only.",
|
|
370
249
|
"",
|
|
371
250
|
" This command will not start a Kimi model run until enforcement is",
|
|
372
|
-
" repaired
|
|
251
|
+
" repaired.",
|
|
373
252
|
"",
|
|
374
|
-
" Fix: run
|
|
375
|
-
" or repair
|
|
376
|
-
"
|
|
377
|
-
"
|
|
378
|
-
"
|
|
379
|
-
" the previously-installed block by design. See docs/safety.md.",
|
|
253
|
+
" Fix: run `kimi_setup` (action \"install\") or `scripts/companion.sh setup`",
|
|
254
|
+
" to install or repair the canonical managed block in ~/.kimi-code/config.toml.",
|
|
255
|
+
" If you use nvm, asdf, mise, or fnm, re-run setup after any Node version",
|
|
256
|
+
" switch — the verifier pins the absolute Node binary path and a switch",
|
|
257
|
+
" invalidates the previously-installed block by design. See docs/safety.md.",
|
|
380
258
|
"",
|
|
381
259
|
" KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 explicitly bypasses hook-verification",
|
|
382
260
|
" refusals and restores un-enforced `permission: auto` execution. It does",
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
// Shared parser for the kimi-plugin-cc managed block in
|
|
1
|
+
// Shared parser for the canonical kimi-plugin-cc managed block in
|
|
2
2
|
// ~/.kimi-code/config.toml. Setup and the verifier use this one grammar;
|
|
3
3
|
// install-paths.ts separately owns the canonical command bytes and drift
|
|
4
4
|
// classification used here after a mismatch.
|
|
5
5
|
//
|
|
6
|
-
// Claude Code and Codex share the config but install to different paths. The
|
|
7
|
-
// marker's `:<host-id>` suffix makes each host own and verify only its block.
|
|
8
|
-
// An un-suffixed legacy block can be adopted by the current host on install.
|
|
9
|
-
//
|
|
10
6
|
// A valid block has this line-oriented shape:
|
|
11
7
|
//
|
|
12
|
-
// # === BEGIN kimi-plugin-cc-managed
|
|
8
|
+
// # === BEGIN kimi-plugin-cc-managed (vX.Y.Z) ===
|
|
13
9
|
// ... optional comments ...
|
|
14
10
|
// [[hooks]]
|
|
15
11
|
// event = "PreToolUse"
|
|
16
12
|
// command = "'/abs/path/to/node' '/abs/path/to/approval-hook.js'"
|
|
17
13
|
// timeout = <integer>
|
|
18
|
-
// # === END kimi-plugin-cc-managed
|
|
14
|
+
// # === END kimi-plugin-cc-managed ===
|
|
19
15
|
//
|
|
20
16
|
// Critical rules:
|
|
21
17
|
//
|
|
@@ -26,15 +22,10 @@
|
|
|
26
22
|
// - Every PreToolUse entry with that command needs an effective timeout of at
|
|
27
23
|
// least HOOK_TIMEOUT_S (checked on the whole-file parse).
|
|
28
24
|
import { parse as parseToml } from "../vendor/smol-toml/parse.js";
|
|
29
|
-
import { classifyHookCommandDrift, describeHookCommandDrift,
|
|
25
|
+
import { classifyHookCommandDrift, describeHookCommandDrift, isOurApprovalHookCommand, } from "./install-paths.js";
|
|
30
26
|
import { HOOK_TIMEOUT_S, hookTimeoutEnforces } from "./hook-timing.js";
|
|
31
27
|
const MARKER_TAG = "kimi-plugin-cc-managed";
|
|
32
|
-
|
|
33
|
-
* Plain install removes unpaired marker comments for every host and leaves each
|
|
34
|
-
* host's hook table in place. A scoped uninstall removes only this host's
|
|
35
|
-
* markers, so it would disarm a healthy block and keep another host's orphan.
|
|
36
|
-
*/
|
|
37
|
-
export const ORPHAN_MARKER_REMEDY = "Run /kimi:setup (without --uninstall or --check) to repair: install removes orphaned managed marker comments for every host and keeps each host's hook table. A scoped --uninstall does not remove another host's orphan marker. Another tool rewriting ~/.kimi-code/config.toml usually causes this.";
|
|
28
|
+
export const ORPHAN_MARKER_REMEDY = "Run `kimi_setup` (with action \"install\") or `scripts/companion.sh setup` (without --uninstall or --check) to repair orphaned managed marker comments while preserving existing hook tables.";
|
|
38
29
|
/**
|
|
39
30
|
* Strict BEGIN matcher. Accepts `# === BEGIN kimi-plugin-cc-managed`
|
|
40
31
|
* with an optional `:<host-id>` suffix, an optional ` (vX.Y.Z)` suffix,
|
|
@@ -56,7 +47,7 @@ const TIMEOUT_LINE_RE = /^timeout\s*=\s*\d+\s*$/;
|
|
|
56
47
|
const HOOKS_TABLE_RE = /^\[\[hooks\]\]\s*$/;
|
|
57
48
|
// Recognize comment lines lexically, not text inside TOML string values.
|
|
58
49
|
// Whole-document parsing remains the authority for TOML validity.
|
|
59
|
-
function scanTomlLines(contents) {
|
|
50
|
+
export function scanTomlLines(contents) {
|
|
60
51
|
const markers = new Set();
|
|
61
52
|
const tables = new Set();
|
|
62
53
|
let state = "plain";
|
|
@@ -205,12 +196,12 @@ function validateBlockBody(rawBody) {
|
|
|
205
196
|
// canonical command). Binding the block to exactly one [[hooks]] table
|
|
206
197
|
// keeps the verifier from blessing a command-less hook.
|
|
207
198
|
invalidReason =
|
|
208
|
-
"block contains an unexpected TOML table — only a single [[hooks]] table is allowed. Reinstall with
|
|
199
|
+
"block contains an unexpected TOML table — only a single [[hooks]] table is allowed. Reinstall with setup to repair.";
|
|
209
200
|
break;
|
|
210
201
|
}
|
|
211
202
|
if (MATCHER_LINE_RE.test(line)) {
|
|
212
203
|
invalidReason =
|
|
213
|
-
'block contains a `matcher = ...` line — kimi-code compiles matchers as JS regex (`new RegExp("*")` throws and disables the hook). Reinstall with
|
|
204
|
+
'block contains a `matcher = ...` line — kimi-code compiles matchers as JS regex (`new RegExp("*")` throws and disables the hook). Reinstall with setup to repair.';
|
|
214
205
|
break;
|
|
215
206
|
}
|
|
216
207
|
if (EVENT_LINE_RE.test(line)) {
|
|
@@ -257,59 +248,40 @@ function validateBlockBody(rawBody) {
|
|
|
257
248
|
Object.prototype.hasOwnProperty.call(entry, "matcher"));
|
|
258
249
|
if (hasMatcher) {
|
|
259
250
|
invalidReason =
|
|
260
|
-
"block contains a `matcher` key (in a quoted or dotted spelling the line scanner misses) — kimi-code compiles matchers as JS regex and disables the hook. Reinstall with
|
|
251
|
+
"block contains a `matcher` key (in a quoted or dotted spelling the line scanner misses) — kimi-code compiles matchers as JS regex and disables the hook. Reinstall with setup to repair.";
|
|
261
252
|
}
|
|
262
253
|
}
|
|
263
254
|
catch {
|
|
264
255
|
invalidReason =
|
|
265
|
-
"block body is not valid TOML in isolation — cannot confirm it carries no hook-disabling matcher. Reinstall with
|
|
256
|
+
"block body is not valid TOML in isolation — cannot confirm it carries no hook-disabling matcher. Reinstall with setup to repair.";
|
|
266
257
|
}
|
|
267
258
|
}
|
|
268
259
|
return { valid: invalidReason === undefined, invalidReason, commandPath };
|
|
269
260
|
}
|
|
270
261
|
/**
|
|
271
|
-
* Parse the supplied kimi-code config text and resolve the
|
|
272
|
-
* state
|
|
273
|
-
*
|
|
274
|
-
* Host resolution: the current host's own suffixed block is authoritative if
|
|
275
|
-
* present; otherwise a lone LEGACY (un-suffixed) block is adoptable and is
|
|
276
|
-
* returned as the found block (the current host will convert it on install).
|
|
277
|
-
* Other hosts' suffixed blocks are ignored for this host's state (that is the
|
|
278
|
-
* whole point of host scoping — they coexist).
|
|
279
|
-
*
|
|
280
|
-
* Only a trailing `\r` is removed from each line for CRLF safety; other line
|
|
281
|
-
* whitespace is preserved here and trimmed only by the relevant matchers.
|
|
262
|
+
* Parse the supplied kimi-code config text and resolve the canonical
|
|
263
|
+
* managed-block state (accepting either the canonical un-suffixed block or a
|
|
264
|
+
* single legacy `:<host-id>` block from an older install).
|
|
282
265
|
*/
|
|
283
|
-
export function parseManagedBlock(contents,
|
|
266
|
+
export function parseManagedBlock(contents, _hostId) {
|
|
284
267
|
const rawLines = contents.split("\n");
|
|
285
268
|
const lines = rawLines.map((line) => line.replace(/\r$/, ""));
|
|
286
269
|
const { blocks, orphans } = pairBlocks(lines);
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
// hook-set validation, and the real-parser cleanliness check. Legacy and own
|
|
290
|
-
// orphans stay fail-closed because they may be this host's damaged block.
|
|
291
|
-
const ownOrphan = orphans.find((o) => o.hostId === null || o.hostId === hostId);
|
|
292
|
-
const foreignOrphans = orphans.filter((o) => o.hostId !== null && o.hostId !== hostId);
|
|
293
|
-
if (ownOrphan !== undefined) {
|
|
294
|
-
return { state: { kind: "orphan", detail: ownOrphan.detail }, blocks: [], lines, foreignOrphans };
|
|
270
|
+
if (orphans.length > 0) {
|
|
271
|
+
return { state: { kind: "orphan", detail: orphans[0].detail }, blocks: [], lines, orphans };
|
|
295
272
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
// legacy command is claimable by the next installer; a command attributed to
|
|
299
|
-
// another host is ignored so its block remains untouched.
|
|
300
|
-
const relevant = blocks.filter((b) => effectiveHost(b, hostId) === hostId);
|
|
301
|
-
if (relevant.length === 0) {
|
|
302
|
-
return { state: { kind: "absent" }, blocks, lines, foreignOrphans };
|
|
273
|
+
if (blocks.length === 0) {
|
|
274
|
+
return { state: { kind: "absent" }, blocks, lines, orphans };
|
|
303
275
|
}
|
|
304
|
-
if (
|
|
276
|
+
if (blocks.length > 1) {
|
|
305
277
|
return {
|
|
306
|
-
state: { kind: "duplicate", beginLines:
|
|
278
|
+
state: { kind: "duplicate", beginLines: blocks.map((b) => b.beginLine) },
|
|
307
279
|
blocks,
|
|
308
280
|
lines,
|
|
309
|
-
|
|
281
|
+
orphans,
|
|
310
282
|
};
|
|
311
283
|
}
|
|
312
|
-
const block =
|
|
284
|
+
const block = blocks[0];
|
|
313
285
|
return {
|
|
314
286
|
state: {
|
|
315
287
|
kind: "found",
|
|
@@ -322,20 +294,9 @@ export function parseManagedBlock(contents, hostId) {
|
|
|
322
294
|
},
|
|
323
295
|
blocks,
|
|
324
296
|
lines,
|
|
325
|
-
|
|
297
|
+
orphans,
|
|
326
298
|
};
|
|
327
299
|
}
|
|
328
|
-
/**
|
|
329
|
-
* The host a managed block belongs to: its marker suffix when present,
|
|
330
|
-
* otherwise the host derived from its command path (a legacy un-suffixed
|
|
331
|
-
* block), falling back to `currentHost` when the command can't be attributed
|
|
332
|
-
* (a stale/bare legacy command — claimable by whoever installs next).
|
|
333
|
-
*/
|
|
334
|
-
export function effectiveHost(block, currentHost) {
|
|
335
|
-
if (block.hostId !== null)
|
|
336
|
-
return block.hostId;
|
|
337
|
-
return hostIdFromHookCommand(block.commandPath) ?? currentHost;
|
|
338
|
-
}
|
|
339
300
|
/**
|
|
340
301
|
* Decode the `command = "..."` (or `'...'`) value from a single trimmed TOML
|
|
341
302
|
* line, or `null` if the line isn't a command assignment. Exported so the
|
|
@@ -431,7 +392,7 @@ export function describeHookTimeout(timeout) {
|
|
|
431
392
|
return `timeout = ${shown}`;
|
|
432
393
|
}
|
|
433
394
|
export function hookTimeoutReason(timeout) {
|
|
434
|
-
return `
|
|
395
|
+
return `the managed hook entry has ${describeHookTimeout(timeout)}; kimi-code reads a hook that runs past its timeout as allow, so the entry needs a timeout of at least ${HOOK_TIMEOUT_S} seconds. Run kimi_setup (or scripts/companion.sh setup) to rewrite it; setup leaves the config unchanged and names any copy it cannot rewrite.`;
|
|
435
396
|
}
|
|
436
397
|
/**
|
|
437
398
|
* Parser-based fallback used only in the absent state. Parse the WHOLE file
|
|
@@ -462,8 +423,8 @@ export function hasCleanEnforcingHookEntry(contents, expectedCommand) {
|
|
|
462
423
|
function foundHookEntryIsClean(contents, expectedCommand) {
|
|
463
424
|
return countCleanEntriesInFile(contents, expectedCommand) > 0;
|
|
464
425
|
}
|
|
465
|
-
export function evaluateInstalled(contents, expectedCommand, opts) {
|
|
466
|
-
const { state } = parseManagedBlock(contents
|
|
426
|
+
export function evaluateInstalled(contents, expectedCommand, opts = {}) {
|
|
427
|
+
const { state, blocks } = parseManagedBlock(contents);
|
|
467
428
|
const shortTimeout = findShortHookTimeout(contents, expectedCommand);
|
|
468
429
|
const timeoutRefusal = () => ({
|
|
469
430
|
installed: false,
|
|
@@ -475,23 +436,18 @@ export function evaluateInstalled(contents, expectedCommand, opts) {
|
|
|
475
436
|
if (shortTimeout !== null)
|
|
476
437
|
return timeoutRefusal();
|
|
477
438
|
// kimi-code config rewrites drop comments but leave hook tables intact. In
|
|
478
|
-
// the absent state only, accept a marker-less table that is exactly
|
|
479
|
-
//
|
|
480
|
-
// byte-exact command is.
|
|
481
|
-
// across blank lines, quoted spellings, and multiline values.
|
|
439
|
+
// the absent state only, accept a marker-less table that is exactly our
|
|
440
|
+
// clean enforcing hook: markers are not the security boundary, the
|
|
441
|
+
// byte-exact command is.
|
|
482
442
|
if (hasCleanEnforcingHookEntry(contents, expectedCommand)) {
|
|
483
443
|
return {
|
|
484
444
|
installed: true,
|
|
485
445
|
via: "bare-table",
|
|
486
|
-
note: "
|
|
446
|
+
note: "managed-block markers are missing (kimi-code rewrites its config on login/settings changes and strips all comments), but the hook table with the exact canonical command is present and enforcing. Run `kimi_setup` or `scripts/companion.sh setup` to re-adorn the markers.",
|
|
487
447
|
state,
|
|
488
448
|
};
|
|
489
449
|
}
|
|
490
|
-
|
|
491
|
-
// stale table so the caller gets an actionable axis.
|
|
492
|
-
const staleOwn = findBareApprovalHookTables(contents).find((table) => table.command !== expectedCommand &&
|
|
493
|
-
isOurApprovalHookCommand(table.command) &&
|
|
494
|
-
hostIdFromHookCommand(table.command) === opts.hostId);
|
|
450
|
+
const staleOwn = findBareApprovalHookTables(contents).find((table) => table.command !== expectedCommand && isOurApprovalHookCommand(table.command));
|
|
495
451
|
return {
|
|
496
452
|
installed: false,
|
|
497
453
|
reason: "managed block is not present",
|
|
@@ -502,11 +458,16 @@ export function evaluateInstalled(contents, expectedCommand, opts) {
|
|
|
502
458
|
};
|
|
503
459
|
}
|
|
504
460
|
if (state.kind === "duplicate") {
|
|
461
|
+
const hasLegacyBlock = blocks.some((entry) => entry.hostId !== null);
|
|
505
462
|
return {
|
|
506
463
|
installed: false,
|
|
507
|
-
reason:
|
|
508
|
-
|
|
509
|
-
|
|
464
|
+
reason: hasLegacyBlock
|
|
465
|
+
? `duplicate managed blocks detected at lines ${state.beginLines
|
|
466
|
+
.map((line) => line + 1)
|
|
467
|
+
.join(", ")} (including legacy host-scoped block(s)). Run \`kimi_setup\` (action "install") or \`scripts/companion.sh setup\` to consolidate them into one canonical block.`
|
|
468
|
+
: `duplicate managed blocks detected at lines ${state.beginLines
|
|
469
|
+
.map((line) => line + 1)
|
|
470
|
+
.join(", ")}. Run \`scripts/companion.sh setup --uninstall\`, then setup again.`,
|
|
510
471
|
state,
|
|
511
472
|
};
|
|
512
473
|
}
|
|
@@ -531,7 +492,7 @@ export function evaluateInstalled(contents, expectedCommand, opts) {
|
|
|
531
492
|
return {
|
|
532
493
|
installed: false,
|
|
533
494
|
reason: classified ??
|
|
534
|
-
`installed block's command does not match the canonical command this companion would write. Run
|
|
495
|
+
`installed block's command does not match the canonical command this companion would write. Run setup to refresh. expected ${expectedCommand}; got ${state.commandPath}.`,
|
|
535
496
|
state,
|
|
536
497
|
drift: classifyHookCommandDrift(state.commandPath, expectedCommand),
|
|
537
498
|
};
|
|
@@ -541,7 +502,7 @@ export function evaluateInstalled(contents, expectedCommand, opts) {
|
|
|
541
502
|
if (!foundHookEntryIsClean(contents, expectedCommand)) {
|
|
542
503
|
return {
|
|
543
504
|
installed: false,
|
|
544
|
-
reason: "the managed block's hook table carries a matcher or an unexpected key OUTSIDE the marked body (e.g. after the END marker) — kimi-code would load it and disable the hook. Run /
|
|
505
|
+
reason: "the managed block's hook table carries a matcher or an unexpected key OUTSIDE the marked body (e.g. after the END marker) — kimi-code would load it and disable the hook. Run `scripts/companion.sh setup --uninstall`, then setup to repair.",
|
|
545
506
|
state,
|
|
546
507
|
};
|
|
547
508
|
}
|
|
@@ -645,25 +606,13 @@ export function findBareApprovalHookTables(contents) {
|
|
|
645
606
|
}
|
|
646
607
|
/**
|
|
647
608
|
* Find marker-less canonical approval-hook tables outside managed blocks.
|
|
648
|
-
*
|
|
649
|
-
* required for scoped pruning: another host's marker-less table may be its live
|
|
650
|
-
* hook after a config rewrite. Omit `ownedBy` only for the explicit every-host
|
|
651
|
-
* `/kimi:setup --uninstall --all` sweep. Non-canonical and hand-rolled hooks are
|
|
652
|
-
* not claimed.
|
|
609
|
+
* Non-canonical and hand-rolled hooks are never matched.
|
|
653
610
|
*/
|
|
654
|
-
export function findUnmanagedApprovalHookBlocks(contents,
|
|
611
|
+
export function findUnmanagedApprovalHookBlocks(contents, alsoMatchCommand) {
|
|
655
612
|
return findBareApprovalHookTables(contents).filter((table) => {
|
|
656
|
-
// Exact current command bytes are the strongest ownership signal and win
|
|
657
|
-
// even when a host-id override disagrees with path derivation. This does
|
|
658
|
-
// not widen the prune: another host's or a hand-rolled hook has different
|
|
659
|
-
// command bytes.
|
|
660
613
|
if (alsoMatchCommand !== undefined && table.command === alsoMatchCommand)
|
|
661
614
|
return true;
|
|
662
|
-
|
|
663
|
-
return false;
|
|
664
|
-
if (ownedBy === undefined)
|
|
665
|
-
return true;
|
|
666
|
-
return hostIdFromHookCommand(table.command) === ownedBy;
|
|
615
|
+
return isOurApprovalHookCommand(table.command);
|
|
667
616
|
});
|
|
668
617
|
}
|
|
669
618
|
export const MARKERS = {
|